@hlos-ai/schemas 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +148 -0
- package/dist/chunk-RQP6MVT3.js +40 -0
- package/dist/chunk-RQP6MVT3.js.map +1 -0
- package/dist/ids.cjs +66 -0
- package/dist/ids.cjs.map +1 -0
- package/dist/ids.d.cts +69 -0
- package/dist/ids.d.ts +69 -0
- package/dist/ids.js +27 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.cjs +1081 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1830 -0
- package/dist/index.d.ts +1830 -0
- package/dist/index.js +965 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1081 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
AgentListItemSchema: () => AgentListItemSchema,
|
|
24
|
+
AgentPassportStubResponseSchema: () => AgentPassportStubResponseSchema,
|
|
25
|
+
AgentStatusSchema: () => AgentStatusSchema,
|
|
26
|
+
AgentTypeSchema: () => AgentTypeSchema,
|
|
27
|
+
AgentsListResponseSchema: () => AgentsListResponseSchema,
|
|
28
|
+
ArtifactRefSchema: () => ArtifactRefSchema,
|
|
29
|
+
AvailabilityTypeSchema: () => AvailabilityTypeSchema,
|
|
30
|
+
BASE64URL_SHA256_REGEX: () => BASE64URL_SHA256_REGEX,
|
|
31
|
+
Base64urlEd25519SigSchema: () => Base64urlEd25519SigSchema,
|
|
32
|
+
Base64urlSha256Schema: () => Base64urlSha256Schema,
|
|
33
|
+
CONTENT_HASH_LENGTH: () => CONTENT_HASH_LENGTH,
|
|
34
|
+
CorrelationIdSchema: () => CorrelationIdSchema,
|
|
35
|
+
CredentialSourceSchema: () => CredentialSourceSchema,
|
|
36
|
+
CrossingHashInputV0Schema: () => CrossingHashInputV0Schema,
|
|
37
|
+
CrossingIdFormatSchema: () => CrossingIdFormatSchema,
|
|
38
|
+
CrossingIdSchema: () => CrossingIdSchema,
|
|
39
|
+
CrossingSettledReceiptSchema: () => CrossingSettledReceiptSchema,
|
|
40
|
+
CrossingSnapshotV0Schema: () => CrossingSnapshotV0Schema,
|
|
41
|
+
ERROR_CODE_STATUS: () => ERROR_CODE_STATUS,
|
|
42
|
+
ErrorResponseSchema: () => ErrorResponseSchema,
|
|
43
|
+
FINALITY_GOLDEN_FIXTURES: () => FINALITY_GOLDEN_FIXTURES,
|
|
44
|
+
FinalityLevel: () => FinalityLevel,
|
|
45
|
+
FundingSourceSchema: () => FundingSourceSchema,
|
|
46
|
+
GOLDEN_FIXTURES: () => GOLDEN_FIXTURES,
|
|
47
|
+
IdempotencyKeySchema: () => IdempotencyKeySchema,
|
|
48
|
+
KernelErrorCodeSchema: () => KernelErrorCodeSchema2,
|
|
49
|
+
KernelErrorSchema: () => KernelErrorSchema,
|
|
50
|
+
KernelOkSchema: () => KernelOkSchema,
|
|
51
|
+
LogInclusionProofSchema: () => LogInclusionProofSchema,
|
|
52
|
+
NA_ID_PREFIX: () => NA_ID_PREFIX,
|
|
53
|
+
NotarizeResponseSchema: () => NotarizeResponseSchema,
|
|
54
|
+
NotarizeStatusSchema: () => NotarizeStatusSchema,
|
|
55
|
+
NotaryAttestationIdFormatSchema: () => NotaryAttestationIdFormatSchema,
|
|
56
|
+
NotaryAttestationSchema: () => NotaryAttestationSchema,
|
|
57
|
+
NotaryRequestSchema: () => NotaryRequestSchema,
|
|
58
|
+
PassportIdFormatSchema: () => PassportIdFormatSchema,
|
|
59
|
+
PassportIdSchema: () => PassportIdSchema,
|
|
60
|
+
ProviderRoleSchema: () => ProviderRoleSchema,
|
|
61
|
+
RECEIPT_HASH_GOLDEN_FIXTURE: () => RECEIPT_HASH_GOLDEN_FIXTURE,
|
|
62
|
+
RECEIPT_TYPE_URI: () => RECEIPT_TYPE_URI,
|
|
63
|
+
RECEIPT_VERSION: () => RECEIPT_VERSION,
|
|
64
|
+
RPIDSchema: () => RPIDSchema,
|
|
65
|
+
ReceiptHashSchema: () => ReceiptHashSchema,
|
|
66
|
+
ReceiptIdFormatSchema: () => ReceiptIdFormatSchema,
|
|
67
|
+
ReceiptIdSchema: () => ReceiptIdSchema,
|
|
68
|
+
RelyingPartyIdSchema: () => RelyingPartyIdSchema,
|
|
69
|
+
RotationEpochSchema: () => RotationEpochSchema,
|
|
70
|
+
SETTLEMENT_AUTHORITY: () => SETTLEMENT_AUTHORITY,
|
|
71
|
+
SIGNATURE_LENGTH: () => SIGNATURE_LENGTH,
|
|
72
|
+
SURFACES: () => SURFACES,
|
|
73
|
+
SignedReceiptV0LooseSchema: () => SignedReceiptV0LooseSchema,
|
|
74
|
+
SignedReceiptV0Schema: () => SignedReceiptV0Schema,
|
|
75
|
+
StackConnectionSchema: () => StackConnectionSchema,
|
|
76
|
+
StackProviderSchema: () => StackProviderSchema,
|
|
77
|
+
StackSchema: () => StackSchema,
|
|
78
|
+
SuccessResponseSchema: () => SuccessResponseSchema,
|
|
79
|
+
SurfaceSchema: () => SurfaceSchema,
|
|
80
|
+
TransactionContextHashSchema: () => TransactionContextHashSchema,
|
|
81
|
+
TransactionContextSchema: () => TransactionContextSchema,
|
|
82
|
+
W_GOLDEN_FIXTURES: () => W_GOLDEN_FIXTURES,
|
|
83
|
+
W_RPID_DOMAIN: () => W_RPID_DOMAIN,
|
|
84
|
+
W_TXCTX_DOMAIN: () => W_TXCTX_DOMAIN,
|
|
85
|
+
WalletIdFormatSchema: () => WalletIdFormatSchema,
|
|
86
|
+
WalletIdSchema: () => WalletIdSchema,
|
|
87
|
+
base64urlToBytes: () => base64urlToBytes,
|
|
88
|
+
bytesToBase64url: () => bytesToBase64url,
|
|
89
|
+
computeContentHash: () => computeContentHash,
|
|
90
|
+
computeReceiptHash: () => computeReceiptHash,
|
|
91
|
+
deriveFundingSource: () => deriveFundingSource,
|
|
92
|
+
encodeEpoch: () => encodeEpoch,
|
|
93
|
+
error: () => error,
|
|
94
|
+
generateCrossingId: () => generateCrossingId,
|
|
95
|
+
generateId: () => generateId,
|
|
96
|
+
generatePassportId: () => generatePassportId,
|
|
97
|
+
generateReceiptId: () => generateReceiptId,
|
|
98
|
+
generateWalletId: () => generateWalletId,
|
|
99
|
+
isCrossingHashInputV0: () => isCrossingHashInputV0,
|
|
100
|
+
isCrossingSettledReceipt: () => isCrossingSettledReceipt,
|
|
101
|
+
isNotaryAttestation: () => isNotaryAttestation,
|
|
102
|
+
isNotaryRequest: () => isNotaryRequest,
|
|
103
|
+
isSignedReceiptV0: () => isSignedReceiptV0,
|
|
104
|
+
jcsCanonicalize: () => jcsCanonicalize,
|
|
105
|
+
kernelError: () => kernelError,
|
|
106
|
+
kernelOk: () => kernelOk,
|
|
107
|
+
success: () => success,
|
|
108
|
+
validateTimeWindow: () => validateTimeWindow
|
|
109
|
+
});
|
|
110
|
+
module.exports = __toCommonJS(src_exports);
|
|
111
|
+
|
|
112
|
+
// src/surface.ts
|
|
113
|
+
var import_zod = require("zod");
|
|
114
|
+
var SurfaceSchema = import_zod.z.enum([
|
|
115
|
+
"mcp",
|
|
116
|
+
// Model Context Protocol servers
|
|
117
|
+
"x402",
|
|
118
|
+
// x402 micropayment protocol
|
|
119
|
+
"events",
|
|
120
|
+
// events.hlos.ai
|
|
121
|
+
"cli",
|
|
122
|
+
// HLOS CLI
|
|
123
|
+
"web",
|
|
124
|
+
// hlos.ai web app
|
|
125
|
+
"acp",
|
|
126
|
+
// Agent Commerce Protocol
|
|
127
|
+
"api"
|
|
128
|
+
// Direct API calls (default for unspecified)
|
|
129
|
+
]);
|
|
130
|
+
var SURFACES = SurfaceSchema.options;
|
|
131
|
+
|
|
132
|
+
// src/response.ts
|
|
133
|
+
var import_zod3 = require("zod");
|
|
134
|
+
|
|
135
|
+
// src/error-codes.ts
|
|
136
|
+
var import_zod2 = require("zod");
|
|
137
|
+
var KernelErrorCodeSchema = import_zod2.z.enum([
|
|
138
|
+
// 4xx Client Errors
|
|
139
|
+
"INVALID_REQUEST",
|
|
140
|
+
// 400 - Malformed request body
|
|
141
|
+
"UNAUTHORIZED",
|
|
142
|
+
// 401 - Missing/invalid auth
|
|
143
|
+
"FORBIDDEN",
|
|
144
|
+
// 403 - Insufficient permissions
|
|
145
|
+
"NOT_FOUND",
|
|
146
|
+
// 404 - Resource doesn't exist
|
|
147
|
+
"CONFLICT",
|
|
148
|
+
// 409 - General conflict
|
|
149
|
+
"IDEMPOTENCY_CONFLICT",
|
|
150
|
+
// 409 - Same idem_key, different request
|
|
151
|
+
"INSUFFICIENT_BALANCE",
|
|
152
|
+
// 402 - Wallet lacks funds
|
|
153
|
+
"SPEND_CAP_EXCEEDED",
|
|
154
|
+
// 402 - Spend cap hit
|
|
155
|
+
"RATE_LIMITED",
|
|
156
|
+
// 429 - Too many requests
|
|
157
|
+
// 5xx Server Errors
|
|
158
|
+
"INTERNAL_ERROR",
|
|
159
|
+
// 500 - Server error
|
|
160
|
+
"SERVICE_UNAVAILABLE"
|
|
161
|
+
// 503 - Temporarily unavailable
|
|
162
|
+
]);
|
|
163
|
+
|
|
164
|
+
// src/response.ts
|
|
165
|
+
function success(data, correlationId, requestId) {
|
|
166
|
+
return {
|
|
167
|
+
success: true,
|
|
168
|
+
data,
|
|
169
|
+
meta: {
|
|
170
|
+
correlation_id: correlationId,
|
|
171
|
+
...requestId && { request_id: requestId }
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function error(code, message, correlationId, details) {
|
|
176
|
+
return {
|
|
177
|
+
success: false,
|
|
178
|
+
error: {
|
|
179
|
+
code,
|
|
180
|
+
message,
|
|
181
|
+
correlation_id: correlationId,
|
|
182
|
+
...details !== void 0 && { details }
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
var SuccessResponseSchema = (dataSchema) => import_zod3.z.object({
|
|
187
|
+
success: import_zod3.z.literal(true),
|
|
188
|
+
data: dataSchema,
|
|
189
|
+
meta: import_zod3.z.object({
|
|
190
|
+
request_id: import_zod3.z.string().optional(),
|
|
191
|
+
correlation_id: import_zod3.z.string()
|
|
192
|
+
}).optional()
|
|
193
|
+
});
|
|
194
|
+
var ErrorResponseSchema = import_zod3.z.object({
|
|
195
|
+
success: import_zod3.z.literal(false),
|
|
196
|
+
error: import_zod3.z.object({
|
|
197
|
+
code: KernelErrorCodeSchema,
|
|
198
|
+
message: import_zod3.z.string(),
|
|
199
|
+
details: import_zod3.z.unknown().optional(),
|
|
200
|
+
correlation_id: import_zod3.z.string()
|
|
201
|
+
})
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// src/receipt-v0.ts
|
|
205
|
+
var import_zod4 = require("zod");
|
|
206
|
+
var RECEIPT_TYPE_URI = "https://hlos.ai/schema/SignedReceiptV0";
|
|
207
|
+
var RECEIPT_VERSION = 0;
|
|
208
|
+
var CONTENT_HASH_LENGTH = 43;
|
|
209
|
+
var SIGNATURE_LENGTH = 86;
|
|
210
|
+
var SignedReceiptV0Schema = (contentSchema) => import_zod4.z.object({
|
|
211
|
+
"@type": import_zod4.z.literal(RECEIPT_TYPE_URI),
|
|
212
|
+
version: import_zod4.z.literal(RECEIPT_VERSION),
|
|
213
|
+
receipt_id: import_zod4.z.string(),
|
|
214
|
+
content: contentSchema,
|
|
215
|
+
// SHA-256 digest (32 bytes) = exactly 43 chars base64url
|
|
216
|
+
content_hash: import_zod4.z.string().regex(
|
|
217
|
+
/^[A-Za-z0-9_-]{43}$/,
|
|
218
|
+
"content_hash must be 43-char base64url (32-byte SHA-256)"
|
|
219
|
+
),
|
|
220
|
+
// Ed25519 signature (64 bytes) = exactly 86 chars base64url
|
|
221
|
+
signature: import_zod4.z.string().regex(
|
|
222
|
+
/^[A-Za-z0-9_-]{86}$/,
|
|
223
|
+
"signature must be 86-char base64url (64-byte Ed25519)"
|
|
224
|
+
),
|
|
225
|
+
key_id: import_zod4.z.string().min(1),
|
|
226
|
+
issued_at: import_zod4.z.string().datetime()
|
|
227
|
+
});
|
|
228
|
+
var SignedReceiptV0LooseSchema = SignedReceiptV0Schema(import_zod4.z.unknown());
|
|
229
|
+
function isSignedReceiptV0(value) {
|
|
230
|
+
if (typeof value !== "object" || value === null) return false;
|
|
231
|
+
const obj = value;
|
|
232
|
+
return obj["@type"] === RECEIPT_TYPE_URI && obj["version"] === RECEIPT_VERSION && typeof obj["receipt_id"] === "string" && typeof obj["content_hash"] === "string" && typeof obj["signature"] === "string" && typeof obj["key_id"] === "string" && typeof obj["issued_at"] === "string";
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/ids.ts
|
|
236
|
+
var import_zod5 = require("zod");
|
|
237
|
+
var WalletIdSchema = import_zod5.z.string().regex(/^wallet_[a-z0-9]{20,}$/i, "Invalid WalletId format").transform((s) => s);
|
|
238
|
+
var PassportIdSchema = import_zod5.z.string().regex(/^passport_[a-z0-9]{20,}$/i, "Invalid PassportId format").transform((s) => s);
|
|
239
|
+
var ReceiptIdSchema = import_zod5.z.string().regex(/^rcpt_[0-9A-HJKMNP-TV-Z]{26}$/i, "Invalid ReceiptId format").transform((s) => s);
|
|
240
|
+
var CorrelationIdSchema = import_zod5.z.string().min(8).max(128).transform((s) => s);
|
|
241
|
+
var IdempotencyKeySchema = import_zod5.z.string().min(1).max(256).regex(/^[\x20-\x7E]+$/, "IdempotencyKey must be printable ASCII").transform((s) => s);
|
|
242
|
+
var CrossingIdSchema = import_zod5.z.string().regex(/^cross_[a-z0-9]{20,}$/i, "Invalid CrossingId format").transform((s) => s);
|
|
243
|
+
function generateId(prefix) {
|
|
244
|
+
const timestamp = Date.now().toString(36);
|
|
245
|
+
const random = crypto.randomUUID().replace(/-/g, "").slice(0, 16);
|
|
246
|
+
return `${prefix}_${timestamp}${random}`;
|
|
247
|
+
}
|
|
248
|
+
var generateWalletId = () => generateId("wallet");
|
|
249
|
+
var generatePassportId = () => generateId("passport");
|
|
250
|
+
var generateReceiptId = () => generateId("rcpt");
|
|
251
|
+
var generateCrossingId = () => generateId("cross");
|
|
252
|
+
|
|
253
|
+
// src/shared-contract.ts
|
|
254
|
+
var import_zod6 = require("zod");
|
|
255
|
+
var KernelErrorCodeSchema2 = import_zod6.z.enum([
|
|
256
|
+
// Validation / Request errors
|
|
257
|
+
"VALIDATION_ERROR",
|
|
258
|
+
// 400 - Input validation failed
|
|
259
|
+
"INVALID_REQUEST",
|
|
260
|
+
// 400 - Malformed request
|
|
261
|
+
// Auth errors
|
|
262
|
+
"UNAUTHORIZED",
|
|
263
|
+
// 401 - Missing/invalid auth
|
|
264
|
+
"FORBIDDEN",
|
|
265
|
+
// 403 - Insufficient permissions
|
|
266
|
+
// Resource errors
|
|
267
|
+
"NOT_FOUND",
|
|
268
|
+
// 404 - Generic not found
|
|
269
|
+
"CROSSING_NOT_FOUND",
|
|
270
|
+
// 404 - Crossing not found
|
|
271
|
+
"STACK_NOT_FOUND",
|
|
272
|
+
// 404 - Stack not found
|
|
273
|
+
"STACK_CONNECTION_NOT_FOUND",
|
|
274
|
+
// 404 - Stack connection not found
|
|
275
|
+
// Conflict errors
|
|
276
|
+
"CONFLICT",
|
|
277
|
+
// 409 - Generic conflict
|
|
278
|
+
"INVALID_STATE_TRANSITION",
|
|
279
|
+
// 409 - State machine violation
|
|
280
|
+
"CROSSING_ALREADY_SETTLED",
|
|
281
|
+
// 409 - Crossing already settled
|
|
282
|
+
"IDEMPOTENCY_CONFLICT",
|
|
283
|
+
// 409 - Same key, different request
|
|
284
|
+
// Payment errors
|
|
285
|
+
"INSUFFICIENT_BALANCE",
|
|
286
|
+
// 402 - Wallet lacks funds
|
|
287
|
+
"SPEND_CAP_EXCEEDED",
|
|
288
|
+
// 402 - Spend cap hit
|
|
289
|
+
// Rate limiting
|
|
290
|
+
"RATE_LIMITED",
|
|
291
|
+
// 429 - Too many requests
|
|
292
|
+
// Server errors
|
|
293
|
+
"INTERNAL_ERROR",
|
|
294
|
+
// 500 - Server error
|
|
295
|
+
"SERVICE_UNAVAILABLE"
|
|
296
|
+
// 503 - Temporarily unavailable
|
|
297
|
+
]);
|
|
298
|
+
var ERROR_CODE_STATUS = {
|
|
299
|
+
VALIDATION_ERROR: 400,
|
|
300
|
+
INVALID_REQUEST: 400,
|
|
301
|
+
UNAUTHORIZED: 401,
|
|
302
|
+
FORBIDDEN: 403,
|
|
303
|
+
NOT_FOUND: 404,
|
|
304
|
+
CROSSING_NOT_FOUND: 404,
|
|
305
|
+
STACK_NOT_FOUND: 404,
|
|
306
|
+
STACK_CONNECTION_NOT_FOUND: 404,
|
|
307
|
+
CONFLICT: 409,
|
|
308
|
+
INVALID_STATE_TRANSITION: 409,
|
|
309
|
+
CROSSING_ALREADY_SETTLED: 409,
|
|
310
|
+
IDEMPOTENCY_CONFLICT: 409,
|
|
311
|
+
INSUFFICIENT_BALANCE: 402,
|
|
312
|
+
SPEND_CAP_EXCEEDED: 402,
|
|
313
|
+
RATE_LIMITED: 429,
|
|
314
|
+
INTERNAL_ERROR: 500,
|
|
315
|
+
SERVICE_UNAVAILABLE: 503
|
|
316
|
+
};
|
|
317
|
+
var KernelOkSchema = (dataSchema) => import_zod6.z.object({
|
|
318
|
+
ok: import_zod6.z.literal(true),
|
|
319
|
+
status: import_zod6.z.union([
|
|
320
|
+
import_zod6.z.number().int().min(200).max(299),
|
|
321
|
+
import_zod6.z.literal(304)
|
|
322
|
+
]),
|
|
323
|
+
data: dataSchema
|
|
324
|
+
});
|
|
325
|
+
var KernelErrorSchema = import_zod6.z.object({
|
|
326
|
+
ok: import_zod6.z.literal(false),
|
|
327
|
+
status: import_zod6.z.number().int().min(400).max(599),
|
|
328
|
+
error: import_zod6.z.object({
|
|
329
|
+
code: KernelErrorCodeSchema2,
|
|
330
|
+
// P0 FIX: was z.string()
|
|
331
|
+
message: import_zod6.z.string(),
|
|
332
|
+
details: import_zod6.z.record(import_zod6.z.unknown()).optional()
|
|
333
|
+
})
|
|
334
|
+
});
|
|
335
|
+
var CrossingIdFormatSchema = import_zod6.z.string().regex(/^cross_[a-z0-9]{20,}$/i, "Invalid CrossingId format (expected: cross_...)");
|
|
336
|
+
var ReceiptIdFormatSchema = import_zod6.z.string().regex(/^rcpt_[0-9A-HJKMNP-TV-Z]{26}$/i, "Invalid ReceiptId format (expected: rcpt_...)");
|
|
337
|
+
var PassportIdFormatSchema = import_zod6.z.string().regex(/^passport_[a-z0-9]{20,}$/i, "Invalid PassportId format (expected: passport_...)");
|
|
338
|
+
var WalletIdFormatSchema = import_zod6.z.string().regex(/^wallet_[a-z0-9]{20,}$/i, "Invalid WalletId format (expected: wallet_...)");
|
|
339
|
+
var FundingSourceSchema = import_zod6.z.enum(["SPONSOR", "PLATFORM", "USER"]);
|
|
340
|
+
var CredentialSourceSchema = import_zod6.z.enum([
|
|
341
|
+
"SPONSOR_KEY",
|
|
342
|
+
// Sponsor-provisioned key
|
|
343
|
+
"BYOK",
|
|
344
|
+
// Bring Your Own Key (user-provided)
|
|
345
|
+
"HLOS_FALLBACK"
|
|
346
|
+
// Platform fallback credential
|
|
347
|
+
]);
|
|
348
|
+
function deriveFundingSource(credentialSource) {
|
|
349
|
+
switch (credentialSource) {
|
|
350
|
+
case "SPONSOR_KEY":
|
|
351
|
+
return "SPONSOR";
|
|
352
|
+
case "BYOK":
|
|
353
|
+
return "USER";
|
|
354
|
+
case "HLOS_FALLBACK":
|
|
355
|
+
return "PLATFORM";
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
var CrossingSnapshotV0Schema = import_zod6.z.object({
|
|
359
|
+
crossingId: CrossingIdFormatSchema,
|
|
360
|
+
capabilityId: import_zod6.z.string(),
|
|
361
|
+
passportId: PassportIdFormatSchema,
|
|
362
|
+
// Scoping
|
|
363
|
+
event_id: import_zod6.z.string().nullable(),
|
|
364
|
+
access_window_id: import_zod6.z.string().nullable(),
|
|
365
|
+
access_grant_id: import_zod6.z.string().nullable(),
|
|
366
|
+
// Attribution
|
|
367
|
+
attribution_org_id: import_zod6.z.string().nullable(),
|
|
368
|
+
funding_source: FundingSourceSchema.nullable(),
|
|
369
|
+
credential_source: CredentialSourceSchema
|
|
370
|
+
});
|
|
371
|
+
var CrossingHashInputV0Schema = import_zod6.z.object({
|
|
372
|
+
v: import_zod6.z.literal(0),
|
|
373
|
+
snapshot: CrossingSnapshotV0Schema,
|
|
374
|
+
attested_receipt_id: ReceiptIdFormatSchema
|
|
375
|
+
});
|
|
376
|
+
var SETTLEMENT_AUTHORITY = "hlos.ai";
|
|
377
|
+
var CrossingSettledReceiptSchema = import_zod6.z.object({
|
|
378
|
+
type: import_zod6.z.literal("CrossingSettled"),
|
|
379
|
+
crossingId: CrossingIdFormatSchema,
|
|
380
|
+
// Scoping (powers adoption + ROI views)
|
|
381
|
+
event_id: import_zod6.z.string().nullable(),
|
|
382
|
+
access_window_id: import_zod6.z.string().nullable(),
|
|
383
|
+
access_grant_id: import_zod6.z.string().nullable(),
|
|
384
|
+
// Attribution
|
|
385
|
+
attribution_org_id: import_zod6.z.string().nullable(),
|
|
386
|
+
funding_source: FundingSourceSchema.nullable(),
|
|
387
|
+
credential_source: CredentialSourceSchema,
|
|
388
|
+
// Authority (LITERAL)
|
|
389
|
+
settlement_authority: import_zod6.z.literal(SETTLEMENT_AUTHORITY),
|
|
390
|
+
// Binding
|
|
391
|
+
crossing_hash: import_zod6.z.string(),
|
|
392
|
+
// sha256 base64url of CrossingHashInputV0
|
|
393
|
+
attested_receipt_id: import_zod6.z.string(),
|
|
394
|
+
// Timestamp
|
|
395
|
+
settled_at: import_zod6.z.string().datetime()
|
|
396
|
+
});
|
|
397
|
+
var AvailabilityTypeSchema = import_zod6.z.enum([
|
|
398
|
+
"EVENT_SPONSOR",
|
|
399
|
+
// Sponsor-funded for specific event
|
|
400
|
+
"EVERGREEN",
|
|
401
|
+
// Always available platform credit
|
|
402
|
+
"CATALOG"
|
|
403
|
+
// User-paid from catalog
|
|
404
|
+
]);
|
|
405
|
+
var ProviderRoleSchema = import_zod6.z.enum([
|
|
406
|
+
"AI",
|
|
407
|
+
// AI/LLM providers (Gemini, GPT, Claude)
|
|
408
|
+
"DATABASE",
|
|
409
|
+
// Database providers (MongoDB, Supabase)
|
|
410
|
+
"AUTH",
|
|
411
|
+
// Auth providers (Clerk, Auth0)
|
|
412
|
+
"DEPLOY",
|
|
413
|
+
// Deployment providers (Vercel, Cloudflare)
|
|
414
|
+
"STORAGE",
|
|
415
|
+
// Storage providers (S3, R2)
|
|
416
|
+
"SEARCH",
|
|
417
|
+
// Search providers (Algolia, Pinecone)
|
|
418
|
+
"PAYMENTS",
|
|
419
|
+
// Payment providers (Stripe)
|
|
420
|
+
"COMPUTE",
|
|
421
|
+
// Compute providers (Modal, Replicate)
|
|
422
|
+
"OTHER"
|
|
423
|
+
// Catch-all for new categories
|
|
424
|
+
]);
|
|
425
|
+
var StackProviderSchema = import_zod6.z.object({
|
|
426
|
+
provider_id: import_zod6.z.string(),
|
|
427
|
+
role: ProviderRoleSchema,
|
|
428
|
+
// P1: Now a constrained enum
|
|
429
|
+
display_name: import_zod6.z.string(),
|
|
430
|
+
budget_allocation: import_zod6.z.number().nonnegative(),
|
|
431
|
+
sku_ids: import_zod6.z.array(import_zod6.z.string()),
|
|
432
|
+
availability_type: AvailabilityTypeSchema
|
|
433
|
+
});
|
|
434
|
+
var StackSchema = import_zod6.z.object({
|
|
435
|
+
id: import_zod6.z.string(),
|
|
436
|
+
slug: import_zod6.z.string(),
|
|
437
|
+
name: import_zod6.z.string(),
|
|
438
|
+
tagline: import_zod6.z.string(),
|
|
439
|
+
icon: import_zod6.z.string(),
|
|
440
|
+
providers: import_zod6.z.array(StackProviderSchema),
|
|
441
|
+
github_template: import_zod6.z.string().nullable(),
|
|
442
|
+
total_budget: import_zod6.z.number().nonnegative(),
|
|
443
|
+
event_id: import_zod6.z.string().nullable()
|
|
444
|
+
// null = evergreen
|
|
445
|
+
});
|
|
446
|
+
var StackConnectionSchema = import_zod6.z.object({
|
|
447
|
+
id: import_zod6.z.string(),
|
|
448
|
+
stack_id: import_zod6.z.string(),
|
|
449
|
+
passport_id: import_zod6.z.string(),
|
|
450
|
+
team_id: import_zod6.z.string().nullable(),
|
|
451
|
+
environment_id: import_zod6.z.string(),
|
|
452
|
+
connected_at: import_zod6.z.string().datetime(),
|
|
453
|
+
connected_providers: import_zod6.z.array(import_zod6.z.string())
|
|
454
|
+
});
|
|
455
|
+
function kernelOk(data, status = 200) {
|
|
456
|
+
return { ok: true, status, data };
|
|
457
|
+
}
|
|
458
|
+
function kernelError(code, message, status, details) {
|
|
459
|
+
return {
|
|
460
|
+
ok: false,
|
|
461
|
+
status: status ?? ERROR_CODE_STATUS[code],
|
|
462
|
+
error: {
|
|
463
|
+
code,
|
|
464
|
+
message,
|
|
465
|
+
...details && { details }
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
var GOLDEN_FIXTURES = {
|
|
470
|
+
/**
|
|
471
|
+
* Sample CrossingHashInputV0 for hash conformance.
|
|
472
|
+
*/
|
|
473
|
+
crossingHashInput: {
|
|
474
|
+
v: 0,
|
|
475
|
+
snapshot: {
|
|
476
|
+
crossingId: "cross_test123abc456def789ghi",
|
|
477
|
+
capabilityId: "gemini.generate.v1",
|
|
478
|
+
passportId: "passport_user123abc456def789g",
|
|
479
|
+
event_id: "evt_hackathon2026",
|
|
480
|
+
access_window_id: "aw_sponsor_mongodb",
|
|
481
|
+
access_grant_id: "ag_team_001",
|
|
482
|
+
attribution_org_id: "mongodb",
|
|
483
|
+
funding_source: "SPONSOR",
|
|
484
|
+
credential_source: "SPONSOR_KEY"
|
|
485
|
+
},
|
|
486
|
+
attested_receipt_id: "rcpt_01HZABCDEF1234567890ABCDEF"
|
|
487
|
+
},
|
|
488
|
+
/**
|
|
489
|
+
* Expected crossing_hash for the above input (FROZEN).
|
|
490
|
+
* Compute: JCS canonicalize → SHA-256 → base64url (no padding)
|
|
491
|
+
*
|
|
492
|
+
* This is the golden vector. If your hash differs, your implementation
|
|
493
|
+
* is not conformant. DO NOT CHANGE unless crossingHashInput changes.
|
|
494
|
+
*/
|
|
495
|
+
expectedCrossingHash_base64url_sha256_jcs_v0: "z8A2kCNck4rPL4ugNe-Fbxputdi3PkjkVpSrIBhojU0",
|
|
496
|
+
/**
|
|
497
|
+
* Sample CrossingSettledReceipt.
|
|
498
|
+
*/
|
|
499
|
+
crossingSettledReceipt: {
|
|
500
|
+
type: "CrossingSettled",
|
|
501
|
+
crossingId: "cross_test123abc456def789ghi",
|
|
502
|
+
event_id: "evt_hackathon2026",
|
|
503
|
+
access_window_id: "aw_sponsor_mongodb",
|
|
504
|
+
access_grant_id: "ag_team_001",
|
|
505
|
+
attribution_org_id: "mongodb",
|
|
506
|
+
funding_source: "SPONSOR",
|
|
507
|
+
credential_source: "SPONSOR_KEY",
|
|
508
|
+
settlement_authority: "hlos.ai",
|
|
509
|
+
crossing_hash: "z8A2kCNck4rPL4ugNe-Fbxputdi3PkjkVpSrIBhojU0",
|
|
510
|
+
attested_receipt_id: "rcpt_01HZABCDEF1234567890ABCDEF",
|
|
511
|
+
settled_at: "2026-01-24T12:00:00.000Z"
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
function isCrossingHashInputV0(value) {
|
|
515
|
+
return CrossingHashInputV0Schema.safeParse(value).success;
|
|
516
|
+
}
|
|
517
|
+
function isCrossingSettledReceipt(value) {
|
|
518
|
+
return CrossingSettledReceiptSchema.safeParse(value).success;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/w.ts
|
|
522
|
+
var import_zod7 = require("zod");
|
|
523
|
+
var W_RPID_DOMAIN = new TextEncoder().encode("W:RPID:v1");
|
|
524
|
+
var W_TXCTX_DOMAIN = new TextEncoder().encode("W:TXCTX:v1");
|
|
525
|
+
var RFC3339_CAPTURING = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.(\d{1,9}))?(Z|([+-])(\d{2}):(\d{2}))$/;
|
|
526
|
+
function isLeapYear(year) {
|
|
527
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
528
|
+
}
|
|
529
|
+
function daysInMonth(year, month) {
|
|
530
|
+
const days = [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
531
|
+
return days[month - 1] ?? 0;
|
|
532
|
+
}
|
|
533
|
+
function parseRfc3339StrictToMs(value) {
|
|
534
|
+
const match = RFC3339_CAPTURING.exec(value);
|
|
535
|
+
if (!match) {
|
|
536
|
+
throw new Error(
|
|
537
|
+
`Invalid epoch: "${value}" is not a valid RFC3339 datetime (requires time and timezone)`
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
const year = Number(match[1]);
|
|
541
|
+
const month = Number(match[2]);
|
|
542
|
+
const day = Number(match[3]);
|
|
543
|
+
const hour = Number(match[4]);
|
|
544
|
+
const minute = Number(match[5]);
|
|
545
|
+
const second = Number(match[6]);
|
|
546
|
+
const fraction = match[8] ?? "";
|
|
547
|
+
const tz = match[9];
|
|
548
|
+
if (month < 1 || month > 12) {
|
|
549
|
+
throw new Error("Invalid epoch: month out of range");
|
|
550
|
+
}
|
|
551
|
+
const maxDay = daysInMonth(year, month);
|
|
552
|
+
if (day < 1 || day > maxDay) {
|
|
553
|
+
throw new Error("Invalid epoch: day out of range");
|
|
554
|
+
}
|
|
555
|
+
if (hour > 23) {
|
|
556
|
+
throw new Error("Invalid epoch: hour out of range");
|
|
557
|
+
}
|
|
558
|
+
if (minute > 59) {
|
|
559
|
+
throw new Error("Invalid epoch: minute out of range");
|
|
560
|
+
}
|
|
561
|
+
if (second > 59) {
|
|
562
|
+
throw new Error("Invalid epoch: second out of range");
|
|
563
|
+
}
|
|
564
|
+
const msFraction = fraction.length ? Number((fraction + "000").slice(0, 3)) : 0;
|
|
565
|
+
const utcMs = Date.UTC(year, month - 1, day, hour, minute, second, msFraction);
|
|
566
|
+
let offsetMs = 0;
|
|
567
|
+
if (tz !== "Z") {
|
|
568
|
+
const sign = match[10] === "-" ? -1 : 1;
|
|
569
|
+
const offsetHour = Number(match[11]);
|
|
570
|
+
const offsetMinute = Number(match[12]);
|
|
571
|
+
if (offsetHour > 23) {
|
|
572
|
+
throw new Error("Invalid epoch: tz hour out of range");
|
|
573
|
+
}
|
|
574
|
+
if (offsetMinute > 59) {
|
|
575
|
+
throw new Error("Invalid epoch: tz minute out of range");
|
|
576
|
+
}
|
|
577
|
+
offsetMs = sign * (offsetHour * 60 + offsetMinute) * 6e4;
|
|
578
|
+
}
|
|
579
|
+
const ms = utcMs - offsetMs;
|
|
580
|
+
if (!Number.isFinite(ms) || ms < 0) {
|
|
581
|
+
throw new Error("Invalid epoch: must be a non-negative timestamp");
|
|
582
|
+
}
|
|
583
|
+
return ms;
|
|
584
|
+
}
|
|
585
|
+
function encodeEpoch(epoch) {
|
|
586
|
+
let ms;
|
|
587
|
+
if (typeof epoch === "string") {
|
|
588
|
+
ms = parseRfc3339StrictToMs(epoch);
|
|
589
|
+
} else {
|
|
590
|
+
if (!Number.isInteger(epoch) || epoch < 0) {
|
|
591
|
+
throw new Error(`Invalid epoch: ${epoch} must be a non-negative integer`);
|
|
592
|
+
}
|
|
593
|
+
ms = epoch;
|
|
594
|
+
}
|
|
595
|
+
const buf = new ArrayBuffer(8);
|
|
596
|
+
const view = new DataView(buf);
|
|
597
|
+
view.setBigUint64(0, BigInt(ms), false);
|
|
598
|
+
return new Uint8Array(buf);
|
|
599
|
+
}
|
|
600
|
+
var RelyingPartyIdSchema = import_zod7.z.object({
|
|
601
|
+
/** RP domain (e.g., "merchant.example.com") */
|
|
602
|
+
domain: import_zod7.z.string().min(1).max(253),
|
|
603
|
+
/** Audience URI (e.g., "https://merchant.example.com/verify") */
|
|
604
|
+
audience_uri: import_zod7.z.string().url(),
|
|
605
|
+
/** SHA-256 hash of verifier's public key (hex, 64 chars) */
|
|
606
|
+
verifier_key_hash: import_zod7.z.string().regex(/^[a-f0-9]{64}$/, "Must be 64-char lowercase hex")
|
|
607
|
+
});
|
|
608
|
+
var RotationEpochSchema = import_zod7.z.union([
|
|
609
|
+
import_zod7.z.number().int().nonnegative(),
|
|
610
|
+
import_zod7.z.string().datetime({ offset: true })
|
|
611
|
+
// Requires timezone offset (RFC3339)
|
|
612
|
+
]);
|
|
613
|
+
var RPIDSchema = import_zod7.z.string().length(43, "RPID must be base64url-encoded 32 bytes (43 chars, no padding)").regex(/^[A-Za-z0-9_-]+$/, "Must be base64url (no padding)");
|
|
614
|
+
var TransactionContextSchema = import_zod7.z.object({
|
|
615
|
+
// Required core (stable)
|
|
616
|
+
relying_party_id: RelyingPartyIdSchema,
|
|
617
|
+
/** sha256(JCS({ intent, request })) — see computeOperationHash() */
|
|
618
|
+
operation_hash: import_zod7.z.string().regex(/^[a-f0-9]{64}$/, "Must be 64-char lowercase hex"),
|
|
619
|
+
/** Validity start (RFC3339) */
|
|
620
|
+
not_before: import_zod7.z.string().datetime({ offset: true }),
|
|
621
|
+
/** Validity end (RFC3339) */
|
|
622
|
+
not_after: import_zod7.z.string().datetime({ offset: true }),
|
|
623
|
+
// Optional (part of hash, must be consistent)
|
|
624
|
+
amount: import_zod7.z.number().nonnegative().optional(),
|
|
625
|
+
currency: import_zod7.z.string().length(3).optional(),
|
|
626
|
+
surface_id: import_zod7.z.string().optional(),
|
|
627
|
+
channel_id: import_zod7.z.string().optional()
|
|
628
|
+
});
|
|
629
|
+
var TransactionContextHashSchema = import_zod7.z.string().regex(/^[a-f0-9]{64}$/, "Must be 64-char lowercase hex");
|
|
630
|
+
var W_GOLDEN_FIXTURES = {
|
|
631
|
+
/**
|
|
632
|
+
* encodeEpoch(1706486400000) = 2024-01-29T00:00:00.000Z
|
|
633
|
+
* Expected: 8 bytes, u64 big-endian
|
|
634
|
+
*/
|
|
635
|
+
epochMs: 17064864e5,
|
|
636
|
+
expectedEpochBytes: new Uint8Array([0, 0, 1, 141, 82, 132, 4, 0]),
|
|
637
|
+
/**
|
|
638
|
+
* Sample RelyingPartyId for test vectors
|
|
639
|
+
*/
|
|
640
|
+
sampleRpId: {
|
|
641
|
+
domain: "merchant.example.com",
|
|
642
|
+
audience_uri: "https://merchant.example.com/verify",
|
|
643
|
+
verifier_key_hash: "a".repeat(64)
|
|
644
|
+
},
|
|
645
|
+
/**
|
|
646
|
+
* Sample TransactionContext for test vectors
|
|
647
|
+
*/
|
|
648
|
+
sampleTxContext: {
|
|
649
|
+
relying_party_id: {
|
|
650
|
+
domain: "merchant.example.com",
|
|
651
|
+
audience_uri: "https://merchant.example.com/verify",
|
|
652
|
+
verifier_key_hash: "a".repeat(64)
|
|
653
|
+
},
|
|
654
|
+
operation_hash: "b".repeat(64),
|
|
655
|
+
not_before: "2026-01-29T00:00:00Z",
|
|
656
|
+
not_after: "2026-01-29T00:05:00Z"
|
|
657
|
+
},
|
|
658
|
+
/**
|
|
659
|
+
* MAX_WINDOW_MS: Maximum allowed not_after - not_before (5 minutes)
|
|
660
|
+
*/
|
|
661
|
+
MAX_WINDOW_MS: 5 * 60 * 1e3
|
|
662
|
+
};
|
|
663
|
+
function validateTimeWindow(context) {
|
|
664
|
+
let notBefore;
|
|
665
|
+
let notAfter;
|
|
666
|
+
try {
|
|
667
|
+
notBefore = parseRfc3339StrictToMs(context.not_before);
|
|
668
|
+
notAfter = parseRfc3339StrictToMs(context.not_after);
|
|
669
|
+
} catch {
|
|
670
|
+
throw new Error("Invalid timestamp: not_before/not_after must be RFC3339 with timezone");
|
|
671
|
+
}
|
|
672
|
+
if (notAfter <= notBefore) {
|
|
673
|
+
throw new Error("not_after must be greater than not_before");
|
|
674
|
+
}
|
|
675
|
+
const windowMs = notAfter - notBefore;
|
|
676
|
+
if (windowMs > W_GOLDEN_FIXTURES.MAX_WINDOW_MS) {
|
|
677
|
+
throw new Error(
|
|
678
|
+
`Time window ${windowMs}ms exceeds MAX_WINDOW_MS (${W_GOLDEN_FIXTURES.MAX_WINDOW_MS}ms)`
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
return true;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// src/agents.ts
|
|
685
|
+
var import_zod8 = require("zod");
|
|
686
|
+
var AgentStatusSchema = import_zod8.z.enum(["ACTIVE", "PENDING", "SUSPENDED", "REVOKED"]).or(import_zod8.z.string().min(1));
|
|
687
|
+
var AgentTypeSchema = import_zod8.z.enum(["CUSTOM", "CLAUDE", "GPT", "GEMINI", "CURSOR", "COPILOT", "OTHER"]).or(import_zod8.z.string().min(1));
|
|
688
|
+
var AgentListItemSchema = import_zod8.z.object({
|
|
689
|
+
id: import_zod8.z.string().min(1),
|
|
690
|
+
external_id: import_zod8.z.string().min(1),
|
|
691
|
+
name: import_zod8.z.string().min(1),
|
|
692
|
+
status: AgentStatusSchema,
|
|
693
|
+
agent_type: AgentTypeSchema,
|
|
694
|
+
trust_score: import_zod8.z.number().int().min(0).max(1e3),
|
|
695
|
+
hosting_model: import_zod8.z.null(),
|
|
696
|
+
declared_tier: import_zod8.z.null(),
|
|
697
|
+
created_at: import_zod8.z.string().datetime()
|
|
698
|
+
}).passthrough();
|
|
699
|
+
var AgentsListResponseSchema = import_zod8.z.object({
|
|
700
|
+
agents: import_zod8.z.array(AgentListItemSchema),
|
|
701
|
+
_meta: import_zod8.z.object({
|
|
702
|
+
source: import_zod8.z.literal("hlos")
|
|
703
|
+
})
|
|
704
|
+
}).passthrough();
|
|
705
|
+
var AgentPassportStubResponseSchema = import_zod8.z.object({
|
|
706
|
+
passport_id: import_zod8.z.null(),
|
|
707
|
+
agent_id: import_zod8.z.string().min(1),
|
|
708
|
+
hosting_model: import_zod8.z.null(),
|
|
709
|
+
declared_tier: import_zod8.z.null(),
|
|
710
|
+
effective_tier: import_zod8.z.null(),
|
|
711
|
+
finality_level: import_zod8.z.null(),
|
|
712
|
+
graph: import_zod8.z.object({
|
|
713
|
+
incoming_edges: import_zod8.z.null(),
|
|
714
|
+
outgoing_edges: import_zod8.z.null(),
|
|
715
|
+
active_visas: import_zod8.z.null()
|
|
716
|
+
}).passthrough(),
|
|
717
|
+
links: import_zod8.z.object({
|
|
718
|
+
passport_url: import_zod8.z.string().startsWith("/agent-passport/agents/"),
|
|
719
|
+
docs_url: import_zod8.z.literal("/agents/passport")
|
|
720
|
+
}).passthrough(),
|
|
721
|
+
_meta: import_zod8.z.object({
|
|
722
|
+
source: import_zod8.z.literal("stub")
|
|
723
|
+
})
|
|
724
|
+
}).passthrough();
|
|
725
|
+
|
|
726
|
+
// src/encoding.ts
|
|
727
|
+
var import_zod9 = require("zod");
|
|
728
|
+
function bytesToBase64url(bytes) {
|
|
729
|
+
let binary = "";
|
|
730
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
731
|
+
binary += String.fromCharCode(bytes[i]);
|
|
732
|
+
}
|
|
733
|
+
const base64 = btoa(binary);
|
|
734
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
735
|
+
}
|
|
736
|
+
function base64urlToBytes(str) {
|
|
737
|
+
const base64 = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
738
|
+
const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
|
|
739
|
+
const binary = atob(padded);
|
|
740
|
+
const bytes = new Uint8Array(binary.length);
|
|
741
|
+
for (let i = 0; i < binary.length; i++) {
|
|
742
|
+
bytes[i] = binary.charCodeAt(i);
|
|
743
|
+
}
|
|
744
|
+
return bytes;
|
|
745
|
+
}
|
|
746
|
+
var BASE64URL_SHA256_REGEX = /^[A-Za-z0-9_-]{43}$/;
|
|
747
|
+
var Base64urlSha256Schema = import_zod9.z.string().regex(
|
|
748
|
+
BASE64URL_SHA256_REGEX,
|
|
749
|
+
"Must be 43-char base64url (32-byte SHA-256 digest)"
|
|
750
|
+
);
|
|
751
|
+
var Base64urlEd25519SigSchema = import_zod9.z.string().regex(
|
|
752
|
+
/^[A-Za-z0-9_-]{86}$/,
|
|
753
|
+
"Must be 86-char base64url (64-byte Ed25519 signature)"
|
|
754
|
+
);
|
|
755
|
+
|
|
756
|
+
// src/receipt-hash.ts
|
|
757
|
+
var import_meta = {};
|
|
758
|
+
var cachedSha256 = null;
|
|
759
|
+
function sortKeysDeep(value) {
|
|
760
|
+
if (Array.isArray(value)) return value.map(sortKeysDeep);
|
|
761
|
+
if (value !== null && typeof value === "object") {
|
|
762
|
+
const obj = value;
|
|
763
|
+
const out = {};
|
|
764
|
+
for (const key of Object.keys(obj).sort()) {
|
|
765
|
+
out[key] = sortKeysDeep(obj[key]);
|
|
766
|
+
}
|
|
767
|
+
return out;
|
|
768
|
+
}
|
|
769
|
+
return value;
|
|
770
|
+
}
|
|
771
|
+
function jcsCanonicalize(value) {
|
|
772
|
+
return JSON.stringify(sortKeysDeep(value), (_key, v) => {
|
|
773
|
+
if (v === void 0) throw new Error("JCS: undefined is not allowed");
|
|
774
|
+
if (typeof v === "function") throw new Error("JCS: function is not allowed");
|
|
775
|
+
if (typeof v === "symbol") throw new Error("JCS: symbol is not allowed");
|
|
776
|
+
if (typeof v === "bigint") throw new Error("JCS: bigint is not allowed");
|
|
777
|
+
if (typeof v === "number" && !Number.isFinite(v))
|
|
778
|
+
throw new Error("JCS: non-finite number is not allowed");
|
|
779
|
+
return v;
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
function computeReceiptHash(receipt) {
|
|
783
|
+
const sha256 = loadSha256();
|
|
784
|
+
const canonical = jcsCanonicalize(receipt);
|
|
785
|
+
const digest = sha256(new TextEncoder().encode(canonical));
|
|
786
|
+
return bytesToBase64url(digest);
|
|
787
|
+
}
|
|
788
|
+
function computeContentHash(content) {
|
|
789
|
+
const sha256 = loadSha256();
|
|
790
|
+
const canonical = jcsCanonicalize(content);
|
|
791
|
+
const digest = sha256(new TextEncoder().encode(canonical));
|
|
792
|
+
return bytesToBase64url(digest);
|
|
793
|
+
}
|
|
794
|
+
function loadSha256() {
|
|
795
|
+
if (cachedSha256) return cachedSha256;
|
|
796
|
+
let _require;
|
|
797
|
+
try {
|
|
798
|
+
const { createRequire } = require("module");
|
|
799
|
+
_require = createRequire(import_meta.url);
|
|
800
|
+
} catch {
|
|
801
|
+
_require = require;
|
|
802
|
+
}
|
|
803
|
+
let sha256;
|
|
804
|
+
try {
|
|
805
|
+
sha256 = _require("@noble/hashes/sha2.js").sha256;
|
|
806
|
+
} catch {
|
|
807
|
+
try {
|
|
808
|
+
sha256 = _require("@noble/hashes/sha2").sha256;
|
|
809
|
+
} catch {
|
|
810
|
+
throw new Error(
|
|
811
|
+
"computeReceiptHash/computeContentHash requires @noble/hashes as a peer dependency. Install it: npm install @noble/hashes"
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
cachedSha256 = sha256;
|
|
816
|
+
return sha256;
|
|
817
|
+
}
|
|
818
|
+
var ReceiptHashSchema = Base64urlSha256Schema.describe(
|
|
819
|
+
"receipt_hash: base64url(SHA-256(JCS(receipt)))"
|
|
820
|
+
);
|
|
821
|
+
var RECEIPT_HASH_GOLDEN_FIXTURE = {
|
|
822
|
+
receipt: {
|
|
823
|
+
"@type": "https://hlos.ai/schema/SignedReceiptV0",
|
|
824
|
+
version: 0,
|
|
825
|
+
receipt_id: "rcpt_01HZGOLDENTEST000000000000",
|
|
826
|
+
content: {
|
|
827
|
+
type: "CrossingSettled",
|
|
828
|
+
crossingId: "cross_test123abc456def789ghi",
|
|
829
|
+
settlement_authority: "hlos.ai"
|
|
830
|
+
},
|
|
831
|
+
// Placeholder bytes (NOT a valid cryptographic signature)
|
|
832
|
+
content_hash: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
|
833
|
+
signature: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
|
834
|
+
key_id: "hlos-v2-1",
|
|
835
|
+
issued_at: "2026-01-27T00:00:00.000Z"
|
|
836
|
+
},
|
|
837
|
+
/**
|
|
838
|
+
* Expected JCS canonical form of the receipt.
|
|
839
|
+
* Keys are lexicographically sorted at all levels.
|
|
840
|
+
*/
|
|
841
|
+
expectedJcs: '{"@type":"https://hlos.ai/schema/SignedReceiptV0","content":{"crossingId":"cross_test123abc456def789ghi","settlement_authority":"hlos.ai","type":"CrossingSettled"},"content_hash":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","issued_at":"2026-01-27T00:00:00.000Z","key_id":"hlos-v2-1","receipt_id":"rcpt_01HZGOLDENTEST000000000000","signature":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","version":0}',
|
|
842
|
+
/**
|
|
843
|
+
* Expected receipt_hash (FROZEN).
|
|
844
|
+
* Compute: JCS canonicalize receipt → SHA-256 → base64url (no padding)
|
|
845
|
+
*
|
|
846
|
+
* DO NOT CHANGE unless the receipt fixture above changes.
|
|
847
|
+
*/
|
|
848
|
+
expectedReceiptHash: "uLiQVUeVKcE35Rdje2fArZQfTcECDgwK6UbmQB_36Pg"
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
// src/finality.ts
|
|
852
|
+
var import_zod10 = require("zod");
|
|
853
|
+
var NA_ID_PREFIX = "na_";
|
|
854
|
+
var FinalityLevel = {
|
|
855
|
+
SOFT: "SOFT",
|
|
856
|
+
HARD: "HARD"
|
|
857
|
+
};
|
|
858
|
+
var NotaryAttestationIdFormatSchema = import_zod10.z.string().regex(
|
|
859
|
+
/^na_[a-zA-Z0-9]{20,}$/,
|
|
860
|
+
"NA ID must match na_[a-zA-Z0-9]{20,}"
|
|
861
|
+
);
|
|
862
|
+
var LogInclusionProofSchema = import_zod10.z.object({
|
|
863
|
+
/** Merkle root hash (base64url SHA-256) */
|
|
864
|
+
root: Base64urlSha256Schema,
|
|
865
|
+
/** Sibling hashes along the path (base64url SHA-256 each) */
|
|
866
|
+
proof: import_zod10.z.array(Base64urlSha256Schema),
|
|
867
|
+
/** Leaf index in the log */
|
|
868
|
+
index: import_zod10.z.number().int().nonnegative()
|
|
869
|
+
});
|
|
870
|
+
var NotaryAttestationSchema = import_zod10.z.object({
|
|
871
|
+
// --- Required ---
|
|
872
|
+
/** Unique NA identifier */
|
|
873
|
+
na_id: NotaryAttestationIdFormatSchema,
|
|
874
|
+
/** The receipt_hash this NA attests to */
|
|
875
|
+
receipt_hash: Base64urlSha256Schema,
|
|
876
|
+
/** Notary service identifier (e.g. "staampid") */
|
|
877
|
+
notary_id: import_zod10.z.string().min(1),
|
|
878
|
+
/** ISO 8601 timestamp when NA was issued */
|
|
879
|
+
issued_at: import_zod10.z.string().datetime(),
|
|
880
|
+
/** Notary's countersignature (base64url encoded) */
|
|
881
|
+
signature: import_zod10.z.string().min(1),
|
|
882
|
+
/** Signature algorithm (e.g. "EdDSA") */
|
|
883
|
+
signature_alg: import_zod10.z.string().min(1),
|
|
884
|
+
// --- Optional (future-proof) ---
|
|
885
|
+
/** Receipt type being attested */
|
|
886
|
+
receipt_type: import_zod10.z.string().optional(),
|
|
887
|
+
/** Receipt version being attested */
|
|
888
|
+
receipt_version: import_zod10.z.number().int().nonnegative().optional(),
|
|
889
|
+
/** Settlement authority that issued the receipt (cross-check) */
|
|
890
|
+
settlement_authority: import_zod10.z.string().optional(),
|
|
891
|
+
/** TTL in seconds for this attestation */
|
|
892
|
+
validity_window_seconds: import_zod10.z.number().int().positive().optional(),
|
|
893
|
+
/** ISO 8601 expiry (derived from issued_at + validity_window_seconds) */
|
|
894
|
+
expires_at: import_zod10.z.string().datetime().optional(),
|
|
895
|
+
/** Merkle proof for append-only log inclusion */
|
|
896
|
+
log_inclusion: LogInclusionProofSchema.optional()
|
|
897
|
+
});
|
|
898
|
+
var NotaryRequestSchema = import_zod10.z.object({
|
|
899
|
+
/** receipt_hash to be attested (base64url SHA-256) */
|
|
900
|
+
receipt_hash: Base64urlSha256Schema,
|
|
901
|
+
/** Must be literal 'hlos.ai' */
|
|
902
|
+
settlement_authority: import_zod10.z.literal(SETTLEMENT_AUTHORITY),
|
|
903
|
+
/** Crossing this receipt belongs to */
|
|
904
|
+
crossing_id: import_zod10.z.string().min(1),
|
|
905
|
+
/** Type of the receipt being attested */
|
|
906
|
+
receipt_type: import_zod10.z.string().min(1),
|
|
907
|
+
/** Version of the receipt being attested */
|
|
908
|
+
receipt_version: import_zod10.z.number().int().nonnegative(),
|
|
909
|
+
/** ISO 8601 timestamp of the request */
|
|
910
|
+
timestamp: import_zod10.z.string().datetime(),
|
|
911
|
+
/** Optional: requested validity window in seconds */
|
|
912
|
+
validity_window_seconds: import_zod10.z.number().int().positive().optional()
|
|
913
|
+
});
|
|
914
|
+
var NotarizeStatusSchema = import_zod10.z.enum([
|
|
915
|
+
"HARD",
|
|
916
|
+
// NA obtained, finality upgraded
|
|
917
|
+
"PENDING",
|
|
918
|
+
// Notarization in progress (async)
|
|
919
|
+
"FAILED",
|
|
920
|
+
// Notarization failed
|
|
921
|
+
"ALREADY_HARD"
|
|
922
|
+
// Receipt already has NA
|
|
923
|
+
]);
|
|
924
|
+
var NotarizeResponseSchema = import_zod10.z.object({
|
|
925
|
+
/** Finality status after this operation */
|
|
926
|
+
status: NotarizeStatusSchema,
|
|
927
|
+
/** The receipt_hash that was notarized */
|
|
928
|
+
receipt_hash: Base64urlSha256Schema,
|
|
929
|
+
/** Hash of the NA itself (optional, present when status is HARD) */
|
|
930
|
+
na_hash: Base64urlSha256Schema.optional(),
|
|
931
|
+
/** The full NA object (optional embed) */
|
|
932
|
+
na: NotaryAttestationSchema.optional(),
|
|
933
|
+
/** Notary service identifier */
|
|
934
|
+
notary: import_zod10.z.string().min(1).optional(),
|
|
935
|
+
/** NA ID for retrieval */
|
|
936
|
+
notary_receipt_id: import_zod10.z.string().optional(),
|
|
937
|
+
/** ISO 8601 timestamp */
|
|
938
|
+
timestamp: import_zod10.z.string().datetime(),
|
|
939
|
+
/** Error details (present when status is FAILED) */
|
|
940
|
+
error: import_zod10.z.string().optional()
|
|
941
|
+
});
|
|
942
|
+
function isNotaryAttestation(value) {
|
|
943
|
+
return NotaryAttestationSchema.safeParse(value).success;
|
|
944
|
+
}
|
|
945
|
+
function isNotaryRequest(value) {
|
|
946
|
+
return NotaryRequestSchema.safeParse(value).success;
|
|
947
|
+
}
|
|
948
|
+
var ArtifactRefSchema = import_zod10.z.object({
|
|
949
|
+
/** Artifact type */
|
|
950
|
+
type: import_zod10.z.enum(["CR", "LAT", "EGP", "SA", "SignedReceiptV0", "NA"]),
|
|
951
|
+
/** base64url SHA-256 hash of the artifact */
|
|
952
|
+
hash: Base64urlSha256Schema,
|
|
953
|
+
/** Issuer of the artifact */
|
|
954
|
+
issuer: import_zod10.z.string().min(1),
|
|
955
|
+
/** Schema version */
|
|
956
|
+
version: import_zod10.z.string().min(1),
|
|
957
|
+
/** Optional retrieval URI */
|
|
958
|
+
uri: import_zod10.z.string().url().optional()
|
|
959
|
+
});
|
|
960
|
+
var FINALITY_GOLDEN_FIXTURES = {
|
|
961
|
+
/** Sample NotaryAttestation */
|
|
962
|
+
notaryAttestation: {
|
|
963
|
+
na_id: "na_01HZGOLDENNATEST00000000",
|
|
964
|
+
receipt_hash: "uLiQVUeVKcE35Rdje2fArZQfTcECDgwK6UbmQB_36Pg",
|
|
965
|
+
notary_id: "staampid",
|
|
966
|
+
issued_at: "2026-01-27T00:01:00.000Z",
|
|
967
|
+
signature: "dGVzdF9ub3Rhcnlfc2lnbmF0dXJlXzY0X2J5dGVzX3BhZGRlZF90b19maWxsXzg2X2NoYXJhY3RlcnNf",
|
|
968
|
+
signature_alg: "EdDSA",
|
|
969
|
+
receipt_type: "SignedReceiptV0",
|
|
970
|
+
receipt_version: 0,
|
|
971
|
+
settlement_authority: "hlos.ai"
|
|
972
|
+
},
|
|
973
|
+
/** Sample NotaryRequest */
|
|
974
|
+
notaryRequest: {
|
|
975
|
+
receipt_hash: "uLiQVUeVKcE35Rdje2fArZQfTcECDgwK6UbmQB_36Pg",
|
|
976
|
+
settlement_authority: "hlos.ai",
|
|
977
|
+
crossing_id: "cross_test123abc456def789ghi",
|
|
978
|
+
receipt_type: "SignedReceiptV0",
|
|
979
|
+
receipt_version: 0,
|
|
980
|
+
timestamp: "2026-01-27T00:00:30.000Z"
|
|
981
|
+
},
|
|
982
|
+
/** Sample successful notarize response */
|
|
983
|
+
notarizeResponseHard: {
|
|
984
|
+
status: "HARD",
|
|
985
|
+
receipt_hash: "uLiQVUeVKcE35Rdje2fArZQfTcECDgwK6UbmQB_36Pg",
|
|
986
|
+
na_hash: "_rkedsyWZhokzye55M9NRAvIKFTxFCYTHVOPjg9cAfU",
|
|
987
|
+
notary: "staampid",
|
|
988
|
+
notary_receipt_id: "na_01HZGOLDENNATEST00000000",
|
|
989
|
+
timestamp: "2026-01-27T00:01:00.000Z"
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
993
|
+
0 && (module.exports = {
|
|
994
|
+
AgentListItemSchema,
|
|
995
|
+
AgentPassportStubResponseSchema,
|
|
996
|
+
AgentStatusSchema,
|
|
997
|
+
AgentTypeSchema,
|
|
998
|
+
AgentsListResponseSchema,
|
|
999
|
+
ArtifactRefSchema,
|
|
1000
|
+
AvailabilityTypeSchema,
|
|
1001
|
+
BASE64URL_SHA256_REGEX,
|
|
1002
|
+
Base64urlEd25519SigSchema,
|
|
1003
|
+
Base64urlSha256Schema,
|
|
1004
|
+
CONTENT_HASH_LENGTH,
|
|
1005
|
+
CorrelationIdSchema,
|
|
1006
|
+
CredentialSourceSchema,
|
|
1007
|
+
CrossingHashInputV0Schema,
|
|
1008
|
+
CrossingIdFormatSchema,
|
|
1009
|
+
CrossingIdSchema,
|
|
1010
|
+
CrossingSettledReceiptSchema,
|
|
1011
|
+
CrossingSnapshotV0Schema,
|
|
1012
|
+
ERROR_CODE_STATUS,
|
|
1013
|
+
ErrorResponseSchema,
|
|
1014
|
+
FINALITY_GOLDEN_FIXTURES,
|
|
1015
|
+
FinalityLevel,
|
|
1016
|
+
FundingSourceSchema,
|
|
1017
|
+
GOLDEN_FIXTURES,
|
|
1018
|
+
IdempotencyKeySchema,
|
|
1019
|
+
KernelErrorCodeSchema,
|
|
1020
|
+
KernelErrorSchema,
|
|
1021
|
+
KernelOkSchema,
|
|
1022
|
+
LogInclusionProofSchema,
|
|
1023
|
+
NA_ID_PREFIX,
|
|
1024
|
+
NotarizeResponseSchema,
|
|
1025
|
+
NotarizeStatusSchema,
|
|
1026
|
+
NotaryAttestationIdFormatSchema,
|
|
1027
|
+
NotaryAttestationSchema,
|
|
1028
|
+
NotaryRequestSchema,
|
|
1029
|
+
PassportIdFormatSchema,
|
|
1030
|
+
PassportIdSchema,
|
|
1031
|
+
ProviderRoleSchema,
|
|
1032
|
+
RECEIPT_HASH_GOLDEN_FIXTURE,
|
|
1033
|
+
RECEIPT_TYPE_URI,
|
|
1034
|
+
RECEIPT_VERSION,
|
|
1035
|
+
RPIDSchema,
|
|
1036
|
+
ReceiptHashSchema,
|
|
1037
|
+
ReceiptIdFormatSchema,
|
|
1038
|
+
ReceiptIdSchema,
|
|
1039
|
+
RelyingPartyIdSchema,
|
|
1040
|
+
RotationEpochSchema,
|
|
1041
|
+
SETTLEMENT_AUTHORITY,
|
|
1042
|
+
SIGNATURE_LENGTH,
|
|
1043
|
+
SURFACES,
|
|
1044
|
+
SignedReceiptV0LooseSchema,
|
|
1045
|
+
SignedReceiptV0Schema,
|
|
1046
|
+
StackConnectionSchema,
|
|
1047
|
+
StackProviderSchema,
|
|
1048
|
+
StackSchema,
|
|
1049
|
+
SuccessResponseSchema,
|
|
1050
|
+
SurfaceSchema,
|
|
1051
|
+
TransactionContextHashSchema,
|
|
1052
|
+
TransactionContextSchema,
|
|
1053
|
+
W_GOLDEN_FIXTURES,
|
|
1054
|
+
W_RPID_DOMAIN,
|
|
1055
|
+
W_TXCTX_DOMAIN,
|
|
1056
|
+
WalletIdFormatSchema,
|
|
1057
|
+
WalletIdSchema,
|
|
1058
|
+
base64urlToBytes,
|
|
1059
|
+
bytesToBase64url,
|
|
1060
|
+
computeContentHash,
|
|
1061
|
+
computeReceiptHash,
|
|
1062
|
+
deriveFundingSource,
|
|
1063
|
+
encodeEpoch,
|
|
1064
|
+
error,
|
|
1065
|
+
generateCrossingId,
|
|
1066
|
+
generateId,
|
|
1067
|
+
generatePassportId,
|
|
1068
|
+
generateReceiptId,
|
|
1069
|
+
generateWalletId,
|
|
1070
|
+
isCrossingHashInputV0,
|
|
1071
|
+
isCrossingSettledReceipt,
|
|
1072
|
+
isNotaryAttestation,
|
|
1073
|
+
isNotaryRequest,
|
|
1074
|
+
isSignedReceiptV0,
|
|
1075
|
+
jcsCanonicalize,
|
|
1076
|
+
kernelError,
|
|
1077
|
+
kernelOk,
|
|
1078
|
+
success,
|
|
1079
|
+
validateTimeWindow
|
|
1080
|
+
});
|
|
1081
|
+
//# sourceMappingURL=index.cjs.map
|