@scopeblind/passport 0.3.0

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/dist/index.js ADDED
@@ -0,0 +1,630 @@
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 index_exports = {};
22
+ __export(index_exports, {
23
+ base58Encode: () => base58Encode,
24
+ buildPublicKeyEndpoint: () => buildPublicKeyEndpoint,
25
+ canonicalHash: () => canonicalHash,
26
+ canonicalize: () => canonicalize,
27
+ createAgentManifest: () => createAgentManifest,
28
+ createArenaBattleReceipt: () => createArenaBattleReceipt,
29
+ createCoachContribution: () => createCoachContribution,
30
+ createCoachManifest: () => createCoachManifest,
31
+ createCoachUpliftReceipt: () => createCoachUpliftReceipt,
32
+ createFormalDebateReceipt: () => createFormalDebateReceipt,
33
+ createOwnershipAttestation: () => createOwnershipAttestation,
34
+ createPassportAuditBundle: () => createPassportAuditBundle,
35
+ createStatusRecord: () => createStatusRecord,
36
+ deriveIssuerFromSeed: () => deriveIssuerFromSeed,
37
+ derivePassportId: () => derivePassportId,
38
+ exportPassportBundle: () => exportPassportBundle,
39
+ formatKidLabeled: () => formatKidLabeled,
40
+ formatKidShort: () => formatKidShort,
41
+ generateIssuerKey: () => generateIssuerKey,
42
+ generatePassportKey: () => generatePassportKey,
43
+ getAgentSummary: () => getAgentSummary,
44
+ getCoachSummary: () => getCoachSummary,
45
+ getSigningKey: () => getSigningKey,
46
+ getVerifyKey: () => getVerifyKey,
47
+ hashString: () => hashString,
48
+ importPassportBundle: () => importPassportBundle,
49
+ isAgentManifest: () => isAgentManifest,
50
+ isCoachManifest: () => isCoachManifest,
51
+ passportBatchToArtifacts: () => passportBatchToArtifacts,
52
+ passportToArtifact: () => passportToArtifact,
53
+ serializeBundle: () => serializeBundle,
54
+ signPayload: () => signPayload,
55
+ signReceipt: () => signReceipt,
56
+ verifyEnvelope: () => verifyEnvelope,
57
+ verifyManifest: () => verifyManifest,
58
+ verifyOwnership: () => verifyOwnership
59
+ });
60
+ module.exports = __toCommonJS(index_exports);
61
+
62
+ // src/keys.ts
63
+ var import_ed25519 = require("@noble/curves/ed25519");
64
+ var import_sha256 = require("@noble/hashes/sha256");
65
+ var import_utils = require("@noble/hashes/utils");
66
+ var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
67
+ function base58Encode(bytes) {
68
+ let num = BigInt("0x" + (0, import_utils.bytesToHex)(bytes));
69
+ const chars = [];
70
+ while (num > 0n) {
71
+ const remainder = Number(num % 58n);
72
+ chars.unshift(BASE58_ALPHABET[remainder]);
73
+ num = num / 58n;
74
+ }
75
+ for (const b of bytes) {
76
+ if (b === 0) chars.unshift("1");
77
+ else break;
78
+ }
79
+ return chars.join("") || "1";
80
+ }
81
+ function derivePassportId(publicKey, role) {
82
+ const fingerprint = base58Encode(publicKey).slice(0, 12);
83
+ return `sb:${role}:${fingerprint}`;
84
+ }
85
+ function generatePassportKey(role) {
86
+ const secretKeyRaw = import_ed25519.ed25519.utils.randomPrivateKey();
87
+ const publicKey = import_ed25519.ed25519.getPublicKey(secretKeyRaw);
88
+ const secretKey = new Uint8Array(64);
89
+ secretKey.set(secretKeyRaw, 0);
90
+ secretKey.set(publicKey, 32);
91
+ const kid = derivePassportId(publicKey, role);
92
+ return {
93
+ publicKey,
94
+ secretKey,
95
+ kid,
96
+ role,
97
+ created_at: (/* @__PURE__ */ new Date()).toISOString()
98
+ };
99
+ }
100
+ function getSigningKey(keyPair) {
101
+ return (0, import_utils.bytesToHex)(keyPair.secretKey.slice(0, 32));
102
+ }
103
+ function getVerifyKey(keyPair) {
104
+ return (0, import_utils.bytesToHex)(keyPair.publicKey);
105
+ }
106
+ function hashString(value) {
107
+ const encoder = new TextEncoder();
108
+ return (0, import_utils.bytesToHex)((0, import_sha256.sha256)(encoder.encode(value)));
109
+ }
110
+
111
+ // src/manifest.ts
112
+ var import_ed255192 = require("@noble/curves/ed25519");
113
+ var import_sha2562 = require("@noble/hashes/sha256");
114
+ var import_utils2 = require("@noble/hashes/utils");
115
+ function canonicalize(obj) {
116
+ return JSON.stringify(obj, (_key, value) => {
117
+ if (value && typeof value === "object" && !Array.isArray(value)) {
118
+ const sorted = {};
119
+ for (const k of Object.keys(value).sort()) {
120
+ sorted[k] = value[k];
121
+ }
122
+ return sorted;
123
+ }
124
+ return value;
125
+ });
126
+ }
127
+ function canonicalHash(obj) {
128
+ return (0, import_utils2.bytesToHex)((0, import_sha2562.sha256)((0, import_utils2.utf8ToBytes)(canonicalize(obj))));
129
+ }
130
+ function signPayload(payload, keyPair) {
131
+ const message = (0, import_utils2.utf8ToBytes)(canonicalize(payload));
132
+ const sigBytes = import_ed255192.ed25519.sign(message, keyPair.secretKey.slice(0, 32));
133
+ return {
134
+ payload,
135
+ signature: {
136
+ alg: "EdDSA",
137
+ kid: keyPair.kid,
138
+ sig: (0, import_utils2.bytesToHex)(sigBytes)
139
+ }
140
+ };
141
+ }
142
+ function createCoachManifest(keyPair, input, previousVersion, version) {
143
+ const manifest = {
144
+ type: "scopeblind:coach-manifest",
145
+ id: keyPair.kid,
146
+ version: version || "1.0.0",
147
+ previous_version: previousVersion ?? null,
148
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
149
+ public_key: base58Encode(keyPair.publicKey),
150
+ display_name: input.display_name.trim().slice(0, 32)
151
+ };
152
+ return signPayload(manifest, keyPair);
153
+ }
154
+ function createAgentManifest(keyPair, input, previousVersion, version) {
155
+ const promptHash = hashString(input.configuration_attestations.system_prompt);
156
+ const manifest = {
157
+ type: "scopeblind:agent-manifest",
158
+ id: keyPair.kid,
159
+ version: version || "1.0.0",
160
+ previous_version: previousVersion ?? null,
161
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
162
+ public_key: base58Encode(keyPair.publicKey),
163
+ public_profile: input.public_profile,
164
+ configuration_attestations: {
165
+ model_family_hash: input.configuration_attestations.model_family_hash,
166
+ memory_mode: input.configuration_attestations.memory_mode,
167
+ prompt_hash: promptHash
168
+ },
169
+ capability_declarations: input.capability_declarations,
170
+ evidence_pointers: input.evidence_pointers || {}
171
+ };
172
+ return signPayload(manifest, keyPair);
173
+ }
174
+ function createOwnershipAttestation(coachKeyPair, agentId, agentManifestVersion) {
175
+ const attestation = {
176
+ type: "scopeblind:ownership-attestation",
177
+ coach_id: coachKeyPair.kid,
178
+ agent_id: agentId,
179
+ agent_manifest_version: agentManifestVersion,
180
+ granted_at: (/* @__PURE__ */ new Date()).toISOString()
181
+ };
182
+ return signPayload(attestation, coachKeyPair);
183
+ }
184
+ function createStatusRecord(signerKeyPair, targetId, status, reason) {
185
+ const record = {
186
+ type: "scopeblind:status-record",
187
+ target_id: targetId,
188
+ status,
189
+ changed_at: (/* @__PURE__ */ new Date()).toISOString(),
190
+ issuer_id: signerKeyPair.kid,
191
+ ...reason ? { reason } : {}
192
+ };
193
+ return signPayload(record, signerKeyPair);
194
+ }
195
+ function createCoachContribution(coachKeyPair, battleId, coachedSide, noteHash, noteLength, upliftVerdict) {
196
+ const contribution = {
197
+ type: "scopeblind:coach-contribution",
198
+ battle_id: battleId,
199
+ coach_id: coachKeyPair.kid,
200
+ coached_side: coachedSide,
201
+ note_hash: noteHash,
202
+ note_length: noteLength,
203
+ ...upliftVerdict ? { uplift_verdict: upliftVerdict } : {}
204
+ };
205
+ return signPayload(contribution, coachKeyPair);
206
+ }
207
+
208
+ // src/verify.ts
209
+ var import_ed255193 = require("@noble/curves/ed25519");
210
+ var import_utils3 = require("@noble/hashes/utils");
211
+ function verifyEnvelope(envelope, expectedPublicKey) {
212
+ try {
213
+ if (!envelope.signature?.sig || !envelope.signature?.kid) {
214
+ return { valid: false, error: "missing_signature" };
215
+ }
216
+ const message = (0, import_utils3.utf8ToBytes)(canonicalize(envelope.payload));
217
+ const hash = canonicalHash(envelope.payload);
218
+ const payload = envelope.payload;
219
+ let publicKeyBytes;
220
+ if (expectedPublicKey) {
221
+ publicKeyBytes = expectedPublicKey;
222
+ } else if (typeof payload.public_key === "string") {
223
+ publicKeyBytes = base58Decode(payload.public_key);
224
+ } else {
225
+ return { valid: false, error: "no_public_key_available" };
226
+ }
227
+ if (expectedPublicKey) {
228
+ const expectedKid = base58Encode(expectedPublicKey);
229
+ const signerFingerprint = envelope.signature.kid.split(":")[2];
230
+ const expectedFingerprint = expectedKid.slice(0, 12);
231
+ if (signerFingerprint !== expectedFingerprint) {
232
+ return { valid: false, hash, error: "kid_mismatch" };
233
+ }
234
+ }
235
+ const valid = import_ed255193.ed25519.verify(
236
+ (0, import_utils3.hexToBytes)(envelope.signature.sig),
237
+ message,
238
+ publicKeyBytes
239
+ );
240
+ return valid ? { valid: true, hash } : { valid: false, hash, error: "invalid_signature" };
241
+ } catch (err) {
242
+ return {
243
+ valid: false,
244
+ error: `verification_error: ${err instanceof Error ? err.message : "unknown"}`
245
+ };
246
+ }
247
+ }
248
+ function verifyManifest(envelope) {
249
+ return verifyEnvelope(envelope);
250
+ }
251
+ function verifyOwnership(attestation, coachPublicKey) {
252
+ const result = verifyEnvelope(attestation, coachPublicKey);
253
+ if (!result.valid) return result;
254
+ return result;
255
+ }
256
+ function base58Decode(str) {
257
+ const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
258
+ let num = 0n;
259
+ for (const char of str) {
260
+ const idx = ALPHABET.indexOf(char);
261
+ if (idx === -1) throw new Error(`Invalid base58 character: ${char}`);
262
+ num = num * 58n + BigInt(idx);
263
+ }
264
+ const hex = num.toString(16).padStart(64, "0");
265
+ const bytes = new Uint8Array(32);
266
+ for (let i = 0; i < 32; i++) {
267
+ bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
268
+ }
269
+ return bytes;
270
+ }
271
+
272
+ // src/display.ts
273
+ function formatKidShort(kid) {
274
+ const parts = kid.split(":");
275
+ const fingerprint = parts[2] || kid;
276
+ if (fingerprint.length <= 8) return fingerprint;
277
+ return `${fingerprint.slice(0, 4)}\u2026${fingerprint.slice(-4)}`;
278
+ }
279
+ function formatKidLabeled(kid) {
280
+ const parts = kid.split(":");
281
+ const role = parts[1] === "coach" ? "Coach" : parts[1] === "agent" ? "Agent" : "Unknown";
282
+ return `${role} ${formatKidShort(kid)}`;
283
+ }
284
+ function getCoachSummary(envelope) {
285
+ const m = envelope.payload;
286
+ return {
287
+ kid: m.id,
288
+ displayName: m.display_name,
289
+ shortId: formatKidShort(m.id),
290
+ version: m.version,
291
+ createdAt: m.created_at
292
+ };
293
+ }
294
+ function getAgentSummary(envelope) {
295
+ const m = envelope.payload;
296
+ return {
297
+ kid: m.id,
298
+ name: m.public_profile.name,
299
+ shortId: formatKidShort(m.id),
300
+ version: m.version,
301
+ domainLanes: m.public_profile.domain_lanes,
302
+ createdAt: m.created_at
303
+ };
304
+ }
305
+ function isCoachManifest(manifest) {
306
+ return manifest.type === "scopeblind:coach-manifest";
307
+ }
308
+ function isAgentManifest(manifest) {
309
+ return manifest.type === "scopeblind:agent-manifest";
310
+ }
311
+
312
+ // src/issuer.ts
313
+ var import_ed255194 = require("@noble/curves/ed25519");
314
+ var import_utils4 = require("@noble/hashes/utils");
315
+ function generateIssuerKey() {
316
+ const secretKeyRaw = import_ed255194.ed25519.utils.randomPrivateKey();
317
+ const publicKey = import_ed255194.ed25519.getPublicKey(secretKeyRaw);
318
+ const fingerprint = base58Encode(publicKey).slice(0, 12);
319
+ return {
320
+ publicKeyHex: (0, import_utils4.bytesToHex)(publicKey),
321
+ secretKeyHex: (0, import_utils4.bytesToHex)(secretKeyRaw),
322
+ issuerId: `sb:issuer:${fingerprint}`
323
+ };
324
+ }
325
+ function signReceipt(payload, issuerSecretKeyHex, issuerId) {
326
+ const message = (0, import_utils4.utf8ToBytes)(canonicalize(payload));
327
+ const sigBytes = import_ed255194.ed25519.sign(message, (0, import_utils4.hexToBytes)(issuerSecretKeyHex));
328
+ return {
329
+ payload,
330
+ signature: {
331
+ alg: "EdDSA",
332
+ kid: issuerId,
333
+ sig: (0, import_utils4.bytesToHex)(sigBytes)
334
+ }
335
+ };
336
+ }
337
+ function createArenaBattleReceipt(input, issuerSecretKeyHex, issuerId) {
338
+ const receipt = {
339
+ type: "blindllm:arena-battle",
340
+ battle_id: input.battleId,
341
+ lane_id: input.laneId,
342
+ agent_a: input.agentA,
343
+ agent_b: input.agentB,
344
+ winner: input.winner,
345
+ issued_at: (/* @__PURE__ */ new Date()).toISOString(),
346
+ issuer_id: issuerId,
347
+ ...input.coach ? { coach: input.coach } : {}
348
+ };
349
+ return signReceipt(receipt, issuerSecretKeyHex, issuerId);
350
+ }
351
+ function createCoachUpliftReceipt(input, issuerSecretKeyHex, issuerId) {
352
+ const receipt = {
353
+ type: "blindllm:coach-uplift",
354
+ battle_id: input.battleId,
355
+ coach_id: input.coachId,
356
+ coached_side: input.coachedSide,
357
+ uplift_verdict: input.upliftVerdict,
358
+ issued_at: (/* @__PURE__ */ new Date()).toISOString(),
359
+ issuer_id: issuerId
360
+ };
361
+ return signReceipt(receipt, issuerSecretKeyHex, issuerId);
362
+ }
363
+ function createFormalDebateReceipt(input, issuerSecretKeyHex, issuerId) {
364
+ const receipt = {
365
+ type: "blindllm:formal-debate",
366
+ debate_id: input.debateId,
367
+ spec_id: input.specId,
368
+ lane_id: input.laneId,
369
+ artifact_hash: input.artifactHash,
370
+ resolution_hash: input.resolutionHash,
371
+ pro: input.pro,
372
+ con: input.con,
373
+ audience_winner: input.audienceWinner,
374
+ judge_winner: input.judgeWinner,
375
+ restraint_result: input.restraintResult,
376
+ issued_at: (/* @__PURE__ */ new Date()).toISOString(),
377
+ issuer_id: issuerId
378
+ };
379
+ return signReceipt(receipt, issuerSecretKeyHex, issuerId);
380
+ }
381
+ function hexToBase64url(hex) {
382
+ const bytes = (0, import_utils4.hexToBytes)(hex);
383
+ const binary = String.fromCharCode(...bytes);
384
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
385
+ }
386
+ function buildPublicKeyEndpoint(issuerPublicKeyHex, issuerId) {
387
+ return {
388
+ keys: [{
389
+ kty: "OKP",
390
+ crv: "Ed25519",
391
+ kid: issuerId,
392
+ x: hexToBase64url(issuerPublicKeyHex),
393
+ use: "sig"
394
+ }],
395
+ issuer: "blindllm",
396
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
397
+ };
398
+ }
399
+ function deriveIssuerFromSeed(secretKeyHex) {
400
+ const secretKeyBytes = (0, import_utils4.hexToBytes)(secretKeyHex);
401
+ const publicKey = import_ed255194.ed25519.getPublicKey(secretKeyBytes);
402
+ const fingerprint = base58Encode(publicKey).slice(0, 12);
403
+ return {
404
+ publicKeyHex: (0, import_utils4.bytesToHex)(publicKey),
405
+ secretKeyHex,
406
+ issuerId: `sb:issuer:${fingerprint}`
407
+ };
408
+ }
409
+
410
+ // src/portable.ts
411
+ var import_utils5 = require("@noble/hashes/utils");
412
+ var import_ed255195 = require("@noble/curves/ed25519");
413
+ function exportPassportBundle(bundle) {
414
+ return {
415
+ v: 1,
416
+ exported_at: (/* @__PURE__ */ new Date()).toISOString(),
417
+ passport: {
418
+ kid: bundle.key.kid,
419
+ role: bundle.key.role,
420
+ created_at: bundle.key.created_at,
421
+ publicKeyHex: (0, import_utils5.bytesToHex)(bundle.key.publicKey),
422
+ secretKeyHex: (0, import_utils5.bytesToHex)(bundle.key.secretKey)
423
+ },
424
+ manifests: bundle.manifests,
425
+ ownership_attestations: bundle.ownership_attestations,
426
+ status_records: bundle.status_records
427
+ };
428
+ }
429
+ function serializeBundle(bundle) {
430
+ return JSON.stringify(bundle, null, 2);
431
+ }
432
+ function importPassportBundle(json) {
433
+ const errors = [];
434
+ const warnings = [];
435
+ let raw;
436
+ try {
437
+ raw = JSON.parse(json);
438
+ } catch {
439
+ return { valid: false, errors: ["Invalid JSON"], warnings };
440
+ }
441
+ const data = raw;
442
+ if (data.v !== 1) {
443
+ errors.push(`Unsupported bundle version: ${data.v}`);
444
+ return { valid: false, errors, warnings };
445
+ }
446
+ const passport = data.passport;
447
+ if (!passport) {
448
+ errors.push("Missing passport field");
449
+ return { valid: false, errors, warnings };
450
+ }
451
+ if (typeof passport.publicKeyHex !== "string" || typeof passport.secretKeyHex !== "string") {
452
+ errors.push("Missing or invalid key hex values");
453
+ return { valid: false, errors, warnings };
454
+ }
455
+ if (typeof passport.kid !== "string" || !passport.kid.startsWith("sb:")) {
456
+ errors.push("Invalid passport kid format");
457
+ return { valid: false, errors, warnings };
458
+ }
459
+ const role = passport.role;
460
+ if (role !== "coach" && role !== "agent") {
461
+ errors.push(`Invalid role: ${role}`);
462
+ return { valid: false, errors, warnings };
463
+ }
464
+ let publicKey;
465
+ let secretKey;
466
+ try {
467
+ publicKey = (0, import_utils5.hexToBytes)(passport.publicKeyHex);
468
+ secretKey = (0, import_utils5.hexToBytes)(passport.secretKeyHex);
469
+ } catch {
470
+ errors.push("Failed to decode key hex values");
471
+ return { valid: false, errors, warnings };
472
+ }
473
+ if (publicKey.length !== 32) {
474
+ errors.push(`Invalid public key length: ${publicKey.length} (expected 32)`);
475
+ return { valid: false, errors, warnings };
476
+ }
477
+ if (secretKey.length !== 64) {
478
+ errors.push(`Invalid secret key length: ${secretKey.length} (expected 64)`);
479
+ return { valid: false, errors, warnings };
480
+ }
481
+ const seed = secretKey.slice(0, 32);
482
+ let derivedPublicKey;
483
+ try {
484
+ derivedPublicKey = import_ed255195.ed25519.getPublicKey(seed);
485
+ } catch {
486
+ errors.push("Secret key seed is not a valid Ed25519 private key");
487
+ return { valid: false, errors, warnings };
488
+ }
489
+ if ((0, import_utils5.bytesToHex)(derivedPublicKey) !== (0, import_utils5.bytesToHex)(publicKey)) {
490
+ errors.push("Key coherence failure: secret key does not derive to the claimed public key");
491
+ return { valid: false, errors, warnings };
492
+ }
493
+ const expectedKid = derivePassportId(publicKey, role);
494
+ if (passport.kid !== expectedKid) {
495
+ errors.push(`Kid mismatch: bundle claims ${passport.kid} but public key derives to ${expectedKid}`);
496
+ return { valid: false, errors, warnings };
497
+ }
498
+ const key = {
499
+ publicKey,
500
+ secretKey,
501
+ kid: passport.kid,
502
+ role,
503
+ created_at: passport.created_at || (/* @__PURE__ */ new Date()).toISOString()
504
+ };
505
+ const rawManifests = Array.isArray(data.manifests) ? data.manifests : [];
506
+ const validManifests = [];
507
+ for (const m of rawManifests) {
508
+ const result = verifyManifest(m);
509
+ if (!result.valid) {
510
+ errors.push(`Manifest ${m.payload?.id || "unknown"} has invalid signature: ${result.error}`);
511
+ continue;
512
+ }
513
+ if (m.payload?.id && m.payload.id !== key.kid) {
514
+ warnings.push(`Dropped manifest ${m.payload.id}: does not belong to passport ${key.kid}`);
515
+ continue;
516
+ }
517
+ validManifests.push(m);
518
+ }
519
+ const bundle = {
520
+ key,
521
+ manifests: validManifests,
522
+ ownership_attestations: Array.isArray(data.ownership_attestations) ? data.ownership_attestations : [],
523
+ status_records: Array.isArray(data.status_records) ? data.status_records : []
524
+ };
525
+ return {
526
+ valid: errors.length === 0,
527
+ bundle,
528
+ errors,
529
+ warnings
530
+ };
531
+ }
532
+
533
+ // src/artifact-bridge.ts
534
+ function passportToArtifact(envelope, options) {
535
+ return {
536
+ version: "2.0",
537
+ format: options?.format || inferFormat(envelope),
538
+ payload: envelope.payload,
539
+ signature: {
540
+ alg: envelope.signature.alg || "EdDSA",
541
+ kid: envelope.signature.kid,
542
+ sig: envelope.signature.sig,
543
+ ...envelope.signature.pub && { pub: envelope.signature.pub }
544
+ },
545
+ meta: {
546
+ issuer: options?.issuer || "blindllm.com",
547
+ source: "passport",
548
+ timestamp: extractTimestamp(envelope.payload)
549
+ }
550
+ };
551
+ }
552
+ function passportBatchToArtifacts(envelopes, options) {
553
+ return envelopes.map((e) => passportToArtifact(e, options));
554
+ }
555
+ function createPassportAuditBundle(envelopes, keys, options) {
556
+ const artifacts = passportBatchToArtifacts(envelopes, options);
557
+ return {
558
+ version: "1.0",
559
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
560
+ issuer: options?.issuer || "blindllm.com",
561
+ receipts: artifacts,
562
+ keys: Object.fromEntries(
563
+ Object.entries(keys).map(([kid, k]) => [kid, { alg: "EdDSA", pub: k.pub, issuer: k.issuer }])
564
+ ),
565
+ summary: {
566
+ total_receipts: artifacts.length,
567
+ time_range: {
568
+ first: Math.min(...artifacts.map((a) => a.meta?.timestamp || 0)),
569
+ last: Math.max(...artifacts.map((a) => a.meta?.timestamp || 0))
570
+ }
571
+ }
572
+ };
573
+ }
574
+ function inferFormat(envelope) {
575
+ const payload = envelope.payload;
576
+ if (payload.type === "arena-battle-receipt") return "passport-battle-v1";
577
+ if (payload.type === "coach-uplift-receipt") return "passport-coach-uplift-v1";
578
+ if (payload.type === "formal-debate-receipt") return "passport-debate-v1";
579
+ if (payload.type === "agent-manifest") return "passport-manifest-v1";
580
+ if (payload.type === "coach-contribution") return "passport-contribution-v1";
581
+ return "passport-generic-v1";
582
+ }
583
+ function extractTimestamp(payload) {
584
+ if (typeof payload === "object" && payload !== null) {
585
+ const p = payload;
586
+ if (typeof p.timestamp === "number") return p.timestamp;
587
+ if (typeof p.created_at === "string") return new Date(p.created_at).getTime();
588
+ if (typeof p.iat === "number") return p.iat * 1e3;
589
+ }
590
+ return Date.now();
591
+ }
592
+ // Annotate the CommonJS export names for ESM import in node:
593
+ 0 && (module.exports = {
594
+ base58Encode,
595
+ buildPublicKeyEndpoint,
596
+ canonicalHash,
597
+ canonicalize,
598
+ createAgentManifest,
599
+ createArenaBattleReceipt,
600
+ createCoachContribution,
601
+ createCoachManifest,
602
+ createCoachUpliftReceipt,
603
+ createFormalDebateReceipt,
604
+ createOwnershipAttestation,
605
+ createPassportAuditBundle,
606
+ createStatusRecord,
607
+ deriveIssuerFromSeed,
608
+ derivePassportId,
609
+ exportPassportBundle,
610
+ formatKidLabeled,
611
+ formatKidShort,
612
+ generateIssuerKey,
613
+ generatePassportKey,
614
+ getAgentSummary,
615
+ getCoachSummary,
616
+ getSigningKey,
617
+ getVerifyKey,
618
+ hashString,
619
+ importPassportBundle,
620
+ isAgentManifest,
621
+ isCoachManifest,
622
+ passportBatchToArtifacts,
623
+ passportToArtifact,
624
+ serializeBundle,
625
+ signPayload,
626
+ signReceipt,
627
+ verifyEnvelope,
628
+ verifyManifest,
629
+ verifyOwnership
630
+ });