agent-passport-system 2.3.0-alpha → 2.5.0-alpha

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.
Files changed (126) hide show
  1. package/README.md +22 -4
  2. package/dist/src/index.d.ts +4 -0
  3. package/dist/src/index.d.ts.map +1 -1
  4. package/dist/src/index.js +8 -0
  5. package/dist/src/index.js.map +1 -1
  6. package/dist/src/v2/accountability/__tests__/action.test.d.ts +2 -0
  7. package/dist/src/v2/accountability/__tests__/action.test.d.ts.map +1 -0
  8. package/dist/src/v2/accountability/__tests__/action.test.js +101 -0
  9. package/dist/src/v2/accountability/__tests__/action.test.js.map +1 -0
  10. package/dist/src/v2/accountability/__tests__/authority-boundary.test.d.ts +2 -0
  11. package/dist/src/v2/accountability/__tests__/authority-boundary.test.d.ts.map +1 -0
  12. package/dist/src/v2/accountability/__tests__/authority-boundary.test.js +79 -0
  13. package/dist/src/v2/accountability/__tests__/authority-boundary.test.js.map +1 -0
  14. package/dist/src/v2/accountability/__tests__/bundle.test.d.ts +2 -0
  15. package/dist/src/v2/accountability/__tests__/bundle.test.d.ts.map +1 -0
  16. package/dist/src/v2/accountability/__tests__/bundle.test.js +122 -0
  17. package/dist/src/v2/accountability/__tests__/bundle.test.js.map +1 -0
  18. package/dist/src/v2/accountability/__tests__/contestability.test.d.ts +2 -0
  19. package/dist/src/v2/accountability/__tests__/contestability.test.d.ts.map +1 -0
  20. package/dist/src/v2/accountability/__tests__/contestability.test.js +205 -0
  21. package/dist/src/v2/accountability/__tests__/contestability.test.js.map +1 -0
  22. package/dist/src/v2/accountability/__tests__/custody.test.d.ts +2 -0
  23. package/dist/src/v2/accountability/__tests__/custody.test.d.ts.map +1 -0
  24. package/dist/src/v2/accountability/__tests__/custody.test.js +155 -0
  25. package/dist/src/v2/accountability/__tests__/custody.test.js.map +1 -0
  26. package/dist/src/v2/accountability/__tests__/fixtures.test.d.ts +2 -0
  27. package/dist/src/v2/accountability/__tests__/fixtures.test.d.ts.map +1 -0
  28. package/dist/src/v2/accountability/__tests__/fixtures.test.js +48 -0
  29. package/dist/src/v2/accountability/__tests__/fixtures.test.js.map +1 -0
  30. package/dist/src/v2/accountability/construct/action.d.ts +7 -0
  31. package/dist/src/v2/accountability/construct/action.d.ts.map +1 -0
  32. package/dist/src/v2/accountability/construct/action.js +46 -0
  33. package/dist/src/v2/accountability/construct/action.js.map +1 -0
  34. package/dist/src/v2/accountability/construct/authority-boundary.d.ts +7 -0
  35. package/dist/src/v2/accountability/construct/authority-boundary.d.ts.map +1 -0
  36. package/dist/src/v2/accountability/construct/authority-boundary.js +34 -0
  37. package/dist/src/v2/accountability/construct/authority-boundary.js.map +1 -0
  38. package/dist/src/v2/accountability/construct/bundle.d.ts +19 -0
  39. package/dist/src/v2/accountability/construct/bundle.d.ts.map +1 -0
  40. package/dist/src/v2/accountability/construct/bundle.js +63 -0
  41. package/dist/src/v2/accountability/construct/bundle.js.map +1 -0
  42. package/dist/src/v2/accountability/construct/contestability.d.ts +9 -0
  43. package/dist/src/v2/accountability/construct/contestability.d.ts.map +1 -0
  44. package/dist/src/v2/accountability/construct/contestability.js +62 -0
  45. package/dist/src/v2/accountability/construct/contestability.js.map +1 -0
  46. package/dist/src/v2/accountability/construct/custody.d.ts +7 -0
  47. package/dist/src/v2/accountability/construct/custody.d.ts.map +1 -0
  48. package/dist/src/v2/accountability/construct/custody.js +41 -0
  49. package/dist/src/v2/accountability/construct/custody.js.map +1 -0
  50. package/dist/src/v2/accountability/index.d.ts +12 -0
  51. package/dist/src/v2/accountability/index.d.ts.map +1 -0
  52. package/dist/src/v2/accountability/index.js +37 -0
  53. package/dist/src/v2/accountability/index.js.map +1 -0
  54. package/dist/src/v2/accountability/types/action.d.ts +24 -0
  55. package/dist/src/v2/accountability/types/action.d.ts.map +1 -0
  56. package/dist/src/v2/accountability/types/action.js +11 -0
  57. package/dist/src/v2/accountability/types/action.js.map +1 -0
  58. package/dist/src/v2/accountability/types/authority-boundary.d.ts +16 -0
  59. package/dist/src/v2/accountability/types/authority-boundary.d.ts.map +1 -0
  60. package/dist/src/v2/accountability/types/authority-boundary.js +12 -0
  61. package/dist/src/v2/accountability/types/authority-boundary.js.map +1 -0
  62. package/dist/src/v2/accountability/types/base.d.ts +35 -0
  63. package/dist/src/v2/accountability/types/base.d.ts.map +1 -0
  64. package/dist/src/v2/accountability/types/base.js +10 -0
  65. package/dist/src/v2/accountability/types/base.js.map +1 -0
  66. package/dist/src/v2/accountability/types/bundle.d.ts +23 -0
  67. package/dist/src/v2/accountability/types/bundle.d.ts.map +1 -0
  68. package/dist/src/v2/accountability/types/bundle.js +12 -0
  69. package/dist/src/v2/accountability/types/bundle.js.map +1 -0
  70. package/dist/src/v2/accountability/types/contestability.d.ts +31 -0
  71. package/dist/src/v2/accountability/types/contestability.d.ts.map +1 -0
  72. package/dist/src/v2/accountability/types/contestability.js +18 -0
  73. package/dist/src/v2/accountability/types/contestability.js.map +1 -0
  74. package/dist/src/v2/accountability/types/custody.d.ts +18 -0
  75. package/dist/src/v2/accountability/types/custody.d.ts.map +1 -0
  76. package/dist/src/v2/accountability/types/custody.js +14 -0
  77. package/dist/src/v2/accountability/types/custody.js.map +1 -0
  78. package/dist/src/v2/accountability/types/index.d.ts +7 -0
  79. package/dist/src/v2/accountability/types/index.d.ts.map +1 -0
  80. package/dist/src/v2/accountability/types/index.js +7 -0
  81. package/dist/src/v2/accountability/types/index.js.map +1 -0
  82. package/dist/src/v2/accountability/verify/action.d.ts +8 -0
  83. package/dist/src/v2/accountability/verify/action.d.ts.map +1 -0
  84. package/dist/src/v2/accountability/verify/action.js +33 -0
  85. package/dist/src/v2/accountability/verify/action.js.map +1 -0
  86. package/dist/src/v2/accountability/verify/authority-boundary.d.ts +8 -0
  87. package/dist/src/v2/accountability/verify/authority-boundary.d.ts.map +1 -0
  88. package/dist/src/v2/accountability/verify/authority-boundary.js +26 -0
  89. package/dist/src/v2/accountability/verify/authority-boundary.js.map +1 -0
  90. package/dist/src/v2/accountability/verify/bundle.d.ts +8 -0
  91. package/dist/src/v2/accountability/verify/bundle.d.ts.map +1 -0
  92. package/dist/src/v2/accountability/verify/bundle.js +31 -0
  93. package/dist/src/v2/accountability/verify/bundle.js.map +1 -0
  94. package/dist/src/v2/accountability/verify/contestability.d.ts +8 -0
  95. package/dist/src/v2/accountability/verify/contestability.d.ts.map +1 -0
  96. package/dist/src/v2/accountability/verify/contestability.js +107 -0
  97. package/dist/src/v2/accountability/verify/contestability.js.map +1 -0
  98. package/dist/src/v2/accountability/verify/custody.d.ts +8 -0
  99. package/dist/src/v2/accountability/verify/custody.d.ts.map +1 -0
  100. package/dist/src/v2/accountability/verify/custody.js +58 -0
  101. package/dist/src/v2/accountability/verify/custody.js.map +1 -0
  102. package/dist/src/v2/index.d.ts +2 -0
  103. package/dist/src/v2/index.d.ts.map +1 -1
  104. package/dist/src/v2/index.js +4 -0
  105. package/dist/src/v2/index.js.map +1 -1
  106. package/dist/src/v2/instruction-provenance/canonicalize.d.ts +50 -0
  107. package/dist/src/v2/instruction-provenance/canonicalize.d.ts.map +1 -0
  108. package/dist/src/v2/instruction-provenance/canonicalize.js +128 -0
  109. package/dist/src/v2/instruction-provenance/canonicalize.js.map +1 -0
  110. package/dist/src/v2/instruction-provenance/envelope.d.ts +22 -0
  111. package/dist/src/v2/instruction-provenance/envelope.d.ts.map +1 -0
  112. package/dist/src/v2/instruction-provenance/envelope.js +107 -0
  113. package/dist/src/v2/instruction-provenance/envelope.js.map +1 -0
  114. package/dist/src/v2/instruction-provenance/index.d.ts +5 -0
  115. package/dist/src/v2/instruction-provenance/index.d.ts.map +1 -0
  116. package/dist/src/v2/instruction-provenance/index.js +11 -0
  117. package/dist/src/v2/instruction-provenance/index.js.map +1 -0
  118. package/dist/src/v2/instruction-provenance/types.d.ts +133 -0
  119. package/dist/src/v2/instruction-provenance/types.d.ts.map +1 -0
  120. package/dist/src/v2/instruction-provenance/types.js +11 -0
  121. package/dist/src/v2/instruction-provenance/types.js.map +1 -0
  122. package/dist/src/v2/instruction-provenance/verify.d.ts +28 -0
  123. package/dist/src/v2/instruction-provenance/verify.d.ts.map +1 -0
  124. package/dist/src/v2/instruction-provenance/verify.js +311 -0
  125. package/dist/src/v2/instruction-provenance/verify.js.map +1 -0
  126. package/package.json +3 -3
@@ -0,0 +1,22 @@
1
+ import type { CreateIPRInput, InstructionProvenanceReceipt } from './types.js';
2
+ /** Typed error for IPR construction failures. */
3
+ export declare class IPRConstructionError extends Error {
4
+ readonly code: string;
5
+ constructor(code: string, message: string);
6
+ }
7
+ /**
8
+ * Build, sign, and return a complete InstructionProvenanceReceipt envelope.
9
+ * Performs all v0.2 invariants:
10
+ * - tier locked to 'self-asserted'
11
+ * - discovery_patterns non-empty
12
+ * - every instruction_files[].path canonicalized
13
+ * - instruction_files sorted in canonical order
14
+ * - context_root derived from sorted files
15
+ * - receipt_id = sha256(canonical envelope bytes)
16
+ * - signature = Ed25519 over canonical envelope bytes
17
+ */
18
+ export declare function createInstructionProvenanceReceipt(input: CreateIPRInput): InstructionProvenanceReceipt;
19
+ /** Ed25519 sign using the same PKCS8-prefix construction as the bilateral
20
+ * fixture generator. Returns hex (128 chars). */
21
+ export declare function signEd25519(message: string | Uint8Array, privateKeyHex: string): string;
22
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../../src/v2/instruction-provenance/envelope.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,cAAc,EAEd,4BAA4B,EAC7B,MAAM,YAAY,CAAA;AAInB,iDAAiD;AACjD,qBAAa,oBAAqB,SAAQ,KAAK;aACjB,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI1D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,cAAc,GACpB,4BAA4B,CAgF9B;AAED;kDACkD;AAClD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAOvF"}
@@ -0,0 +1,107 @@
1
+ // Copyright 2024-2026 Tymofii Pidlisnyi. Apache-2.0 license. See LICENSE.
2
+ // ══════════════════════════════════════════════════════════════════
3
+ // IPR — envelope construction (createInstructionProvenanceReceipt)
4
+ // ══════════════════════════════════════════════════════════════════
5
+ // Tier-locked to 'self-asserted' in v0.2 per spec §4.1. Throws on attempts
6
+ // to construct 'witnessed' or 'verified' envelopes (reserved for v0.3+).
7
+ // ══════════════════════════════════════════════════════════════════
8
+ import { createPrivateKey, sign as cryptoSign } from 'node:crypto';
9
+ import { canonicalizeEnvelope, canonicalizePath, computeContextRoot, sha256Hex, sortInstructionFiles, } from './canonicalize.js';
10
+ const PKCS8_ED25519_PREFIX = Buffer.from('302e020100300506032b657004220420', 'hex');
11
+ /** Typed error for IPR construction failures. */
12
+ export class IPRConstructionError extends Error {
13
+ code;
14
+ constructor(code, message) {
15
+ super(`${code}: ${message}`);
16
+ this.code = code;
17
+ this.name = 'IPRConstructionError';
18
+ }
19
+ }
20
+ /**
21
+ * Build, sign, and return a complete InstructionProvenanceReceipt envelope.
22
+ * Performs all v0.2 invariants:
23
+ * - tier locked to 'self-asserted'
24
+ * - discovery_patterns non-empty
25
+ * - every instruction_files[].path canonicalized
26
+ * - instruction_files sorted in canonical order
27
+ * - context_root derived from sorted files
28
+ * - receipt_id = sha256(canonical envelope bytes)
29
+ * - signature = Ed25519 over canonical envelope bytes
30
+ */
31
+ export function createInstructionProvenanceReceipt(input) {
32
+ // Tier lock — v0.2 only emits 'self-asserted'.
33
+ if (input.attestation_tier !== undefined && input.attestation_tier !== 'self-asserted') {
34
+ throw new IPRConstructionError('TIER_RESERVED', `attestation_tier '${String(input.attestation_tier)}' reserved for v0.3+; v0.2 only emits 'self-asserted'`);
35
+ }
36
+ if (!Array.isArray(input.discovery_patterns) || input.discovery_patterns.length === 0) {
37
+ throw new IPRConstructionError('EMPTY_PATTERNS', 'discovery_patterns must be a non-empty array');
38
+ }
39
+ if (!input.working_root.startsWith('/')) {
40
+ throw new IPRConstructionError('WORKING_ROOT_NOT_ABSOLUTE', `working_root must be absolute POSIX: ${input.working_root}`);
41
+ }
42
+ if (!/^[0-9a-f]{64}$/.test(input.delegation_chain_root)) {
43
+ throw new IPRConstructionError('BAD_DELEGATION_ROOT', 'delegation_chain_root must be 64-char lowercase hex');
44
+ }
45
+ if (!/^[0-9a-f]{64}$/.test(input.publicKeyHex)) {
46
+ throw new IPRConstructionError('BAD_PUBLIC_KEY', 'publicKeyHex must be 64-char lowercase hex');
47
+ }
48
+ if (!/^[0-9a-f]{64}$/.test(input.privateKeyHex)) {
49
+ throw new IPRConstructionError('BAD_PRIVATE_KEY', 'privateKeyHex must be 64-char lowercase hex (Ed25519 seed)');
50
+ }
51
+ // Canonicalize each path; rejects symlink dereferencing, traversal, etc.
52
+ const canonicalFiles = input.instruction_files.map(f => ({
53
+ ...f,
54
+ path: canonicalizePath(f.path, {
55
+ workingRoot: input.working_root,
56
+ filesystemMode: input.filesystem_mode,
57
+ }),
58
+ }));
59
+ // Validate digest format on every file.
60
+ for (const f of canonicalFiles) {
61
+ if (!/^[0-9a-f]{64}$/.test(f.digest)) {
62
+ throw new IPRConstructionError('BAD_DIGEST', `instruction_files entry has malformed digest: ${f.path}`);
63
+ }
64
+ if (f.is_symlink && !f.symlink_target) {
65
+ throw new IPRConstructionError('SYMLINK_MISSING_TARGET', `instruction_files entry is_symlink=true but symlink_target is missing: ${f.path}`);
66
+ }
67
+ }
68
+ const sortedFiles = sortInstructionFiles(canonicalFiles);
69
+ const contextRoot = computeContextRoot(sortedFiles);
70
+ const issuedAt = input.issued_at ?? new Date().toISOString();
71
+ const signingKeyId = `ed25519:${input.publicKeyHex.slice(0, 16)}`;
72
+ // Build the unsigned envelope (signature + receipt_id absent).
73
+ const unsigned = {
74
+ delegation_chain_root: input.delegation_chain_root,
75
+ agent_did: input.agent_did,
76
+ discovery_patterns: input.discovery_patterns,
77
+ working_root: input.working_root,
78
+ filesystem_mode: input.filesystem_mode,
79
+ instruction_files: sortedFiles,
80
+ context_root: contextRoot,
81
+ attestation_tier: 'self-asserted',
82
+ recompute_at_action: input.recompute_at_action ?? false,
83
+ issued_at: issuedAt,
84
+ ...(input.expires_at !== undefined ? { expires_at: input.expires_at } : {}),
85
+ bound_to: input.bound_to,
86
+ signing_key_id: signingKeyId,
87
+ };
88
+ const canonicalBytes = canonicalizeEnvelope(unsigned);
89
+ const receiptId = sha256Hex(canonicalBytes);
90
+ const signatureHex = signEd25519(canonicalBytes, input.privateKeyHex);
91
+ return {
92
+ receipt_id: receiptId,
93
+ ...unsigned,
94
+ signature: signatureHex,
95
+ };
96
+ }
97
+ /** Ed25519 sign using the same PKCS8-prefix construction as the bilateral
98
+ * fixture generator. Returns hex (128 chars). */
99
+ export function signEd25519(message, privateKeyHex) {
100
+ const seed = Buffer.from(privateKeyHex, 'hex');
101
+ const derKey = Buffer.concat([PKCS8_ED25519_PREFIX, seed]);
102
+ const keyObj = createPrivateKey({ key: derKey, format: 'der', type: 'pkcs8' });
103
+ const msg = typeof message === 'string' ? Buffer.from(message, 'utf8') : Buffer.from(message);
104
+ const sig = cryptoSign(null, msg, keyObj);
105
+ return Buffer.from(sig).toString('hex');
106
+ }
107
+ //# sourceMappingURL=envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../../src/v2/instruction-provenance/envelope.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qEAAqE;AACrE,mEAAmE;AACnE,qEAAqE;AACrE,2EAA2E;AAC3E,yEAAyE;AACzE,qEAAqE;AAErE,OAAO,EAAE,gBAAgB,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,oBAAoB,GACrB,MAAM,m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GAAG,gBAAgB,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;IAC9E,MAAM,GAAG,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC7F,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACzC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACzC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { createInstructionProvenanceReceipt, IPRConstructionError, signEd25519 } from './envelope.js';
2
+ export { verifyInstructionProvenanceReceipt, verifyActionTimeContextRoot, matchesAnyPattern } from './verify.js';
3
+ export { IPRPathError, canonicalizePath, canonicalizeEnvelope, computeContextRoot, sortInstructionFiles, sha256Hex, } from './canonicalize.js';
4
+ export type { AttestationTier, FilesystemMode, InstructionRole, InstructionFile, InstructionProvenanceReceipt, InstructionProvenanceReceiptBoundTo, CanonicalizationResult, VerificationResult, CreateIPRInput, VerifyIPRInput, ActionTimeContextRootInput, } from './types.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/v2/instruction-provenance/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,kCAAkC,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACrG,OAAO,EAAE,kCAAkC,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAChH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,GACV,MAAM,mBAAmB,CAAA;AAE1B,YAAY,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,eAAe,EACf,4BAA4B,EAC5B,mCAAmC,EACnC,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,0BAA0B,GAC3B,MAAM,YAAY,CAAA"}
@@ -0,0 +1,11 @@
1
+ // Copyright 2024-2026 Tymofii Pidlisnyi. Apache-2.0 license. See LICENSE.
2
+ // ══════════════════════════════════════════════════════════════════
3
+ // InstructionProvenanceReceipt — public barrel
4
+ // ══════════════════════════════════════════════════════════════════
5
+ // Spec: ~/aeoess_web/specs/INSTRUCTION-PROVENANCE-RECEIPT-DRAFT-v0.2.md
6
+ // Tier scope this version: 'self-asserted' only.
7
+ // ══════════════════════════════════════════════════════════════════
8
+ export { createInstructionProvenanceReceipt, IPRConstructionError, signEd25519 } from './envelope.js';
9
+ export { verifyInstructionProvenanceReceipt, verifyActionTimeContextRoot, matchesAnyPattern } from './verify.js';
10
+ export { IPRPathError, canonicalizePath, canonicalizeEnvelope, computeContextRoot, sortInstructionFiles, sha256Hex, } from './canonicalize.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v2/instruction-provenance/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qEAAqE;AACrE,+CAA+C;AAC/C,qEAAqE;AACrE,wEAAwE;AACxE,iDAAiD;AACjD,qEAAqE;AAErE,OAAO,EAAE,kCAAkC,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACrG,OAAO,EAAE,kCAAkC,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAChH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,GACV,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,133 @@
1
+ /** v0.2 envelopes ship 'self-asserted'. v0.3 unlocks 'witnessed' and 'verified'. */
2
+ export type AttestationTier = 'self-asserted' | 'witnessed' | 'verified';
3
+ export type FilesystemMode = 'case-sensitive' | 'case-insensitive';
4
+ export type InstructionRole = 'system_prompt' | 'agent_md' | 'user_md' | 'memory' | 'rules' | 'other';
5
+ export interface InstructionFile {
6
+ /** Canonicalized relative POSIX path, per spec §5.1. Symlinks are separate
7
+ * entries with `is_symlink: true`; the link target appears as a distinct
8
+ * file. */
9
+ path: string;
10
+ /** Hex sha256 of file contents. Lowercase, 64 chars. */
11
+ digest: string;
12
+ /** Byte length of the file at issuance time. */
13
+ bytes: number;
14
+ /** Role classification. `'other'` for files matched by patterns but not
15
+ * fitting a named role. */
16
+ role: InstructionRole;
17
+ /** True iff this entry represents a symlink, not a regular file. The
18
+ * symlink's target file appears as its own entry. */
19
+ is_symlink?: boolean;
20
+ /** Target path of the symlink (only present when is_symlink=true). */
21
+ symlink_target?: string;
22
+ }
23
+ export interface InstructionProvenanceReceiptBoundTo {
24
+ type: 'session' | 'action' | 'window';
25
+ /** Reference to the bound entity. Format depends on `type`:
26
+ * - session: session_id
27
+ * - action: action_ref hex sha256 (Module 37 / A2A#1672)
28
+ * - window: ISO 8601 timestamp interval `<start>/<end>` */
29
+ ref: string;
30
+ }
31
+ export interface InstructionProvenanceReceipt {
32
+ /** sha256 of the canonical-JCS serialization of this object minus
33
+ * `signature` and `receipt_id`. */
34
+ receipt_id: string;
35
+ /** Existing APS field. Links IPR to its delegation root.
36
+ * Format: hex sha256 of canonical delegation chain. */
37
+ delegation_chain_root: string;
38
+ /** Acting agent DID. */
39
+ agent_did: string;
40
+ /** Glob patterns the agent claims to have walked, in arbitrary order.
41
+ * Must be non-empty. POSIX globs relative to `working_root`. */
42
+ discovery_patterns: string[];
43
+ /** Working root for path resolution. Absolute POSIX path. The agent's
44
+ * `instruction_files[].path` values are relative to this root. */
45
+ working_root: string;
46
+ /** Filesystem case mode for the working_root. Affects path comparison. */
47
+ filesystem_mode: FilesystemMode;
48
+ /** Files matched by `discovery_patterns`. Exhaustiveness contract: this
49
+ * array MUST contain every regular file matched by any pattern in
50
+ * `discovery_patterns`, in canonical sorted order by `path`. */
51
+ instruction_files: InstructionFile[];
52
+ /** sha256 of the canonical-JCS serialization of `instruction_files` only.
53
+ * The hash that changes when any file content or path changes. */
54
+ context_root: string;
55
+ /** Attestation tier per ENFORCEMENT-TRUST-ANCHOR Component 4. v0.2
56
+ * envelopes MUST carry `'self-asserted'`. */
57
+ attestation_tier: AttestationTier;
58
+ /** When true, action receipts emitted under this IPR MUST re-hash the
59
+ * files matching `discovery_patterns` immediately before action
60
+ * execution and inline the fresh `context_root` into the action receipt.
61
+ * Default false. Mandatory true at tier >= 2 in v2.4. */
62
+ recompute_at_action: boolean;
63
+ /** Issuance timestamp, ISO 8601 with millisecond precision and Z suffix. */
64
+ issued_at: string;
65
+ /** Optional expiry. Verifiers SHOULD treat absent as session-bound. */
66
+ expires_at?: string;
67
+ /** Binding scope. */
68
+ bound_to: InstructionProvenanceReceiptBoundTo;
69
+ /** Ed25519 signing key fingerprint: `ed25519:<first-16-hex-of-public-key>`. */
70
+ signing_key_id: string;
71
+ /** Ed25519 over the JCS canonicalization of this object minus
72
+ * `signature` and `receipt_id`. Hex, 128 chars. */
73
+ signature: string;
74
+ }
75
+ /** Result of `canonicalizePath`. Either a canonical relative POSIX string or
76
+ * a typed error explaining the rejection (callers throw `IPRPathError`). */
77
+ export interface CanonicalizationResult {
78
+ canonical: string;
79
+ }
80
+ /** Verification outcome from `verifyInstructionProvenanceReceipt`. */
81
+ export interface VerificationResult {
82
+ valid: boolean;
83
+ errors: string[];
84
+ /** Surfaced for callers that want to gate on tier even when valid=true. */
85
+ tier?: AttestationTier;
86
+ /** Surfaced for caller convenience; equals envelope.context_root when
87
+ * recomputation matched, otherwise the recomputed value. */
88
+ contextRoot?: string;
89
+ }
90
+ /** Inputs for createInstructionProvenanceReceipt. */
91
+ export interface CreateIPRInput {
92
+ delegation_chain_root: string;
93
+ agent_did: string;
94
+ discovery_patterns: string[];
95
+ working_root: string;
96
+ filesystem_mode: FilesystemMode;
97
+ instruction_files: InstructionFile[];
98
+ recompute_at_action?: boolean;
99
+ issued_at?: string;
100
+ expires_at?: string;
101
+ bound_to: InstructionProvenanceReceiptBoundTo;
102
+ /** Ed25519 private key (hex seed, 64 chars). */
103
+ privateKeyHex: string;
104
+ /** Ed25519 public key (hex, 64 chars) used to derive `signing_key_id`. */
105
+ publicKeyHex: string;
106
+ /** Tier override is not allowed in v0.2; envelope is always 'self-asserted'.
107
+ * Future-flagged here so v0.3 can wire 'witnessed' / 'verified'. */
108
+ attestation_tier?: 'self-asserted';
109
+ }
110
+ /** Verification options. */
111
+ export interface VerifyIPRInput {
112
+ envelope: InstructionProvenanceReceipt;
113
+ /** Ed25519 public key (hex, 64 chars) used to verify `signature`. */
114
+ publicKeyHex: string;
115
+ /** When provided, performs §6.3 step 10/11 exhaustiveness check by
116
+ * re-walking the working root with `discovery_patterns`. When omitted,
117
+ * the verifier skips filesystem checks (signature + schema only). */
118
+ filesystemCheck?: boolean;
119
+ /** Verifier clock for §6.4 step 12/13 (default: Date.now()). */
120
+ now?: Date;
121
+ /** Allowable clock skew in milliseconds for `issued_at` future check
122
+ * (default: 5 minutes). */
123
+ clockSkewMs?: number;
124
+ }
125
+ /** Action-receipt context-root verification input. */
126
+ export interface ActionTimeContextRootInput {
127
+ /** The IPR the action receipt is bound to. */
128
+ envelope: InstructionProvenanceReceipt;
129
+ /** Action-receipt-side fresh `context_root` computed immediately before
130
+ * action execution. Hex sha256, 64 chars. */
131
+ context_root_at_action_time: string;
132
+ }
133
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/v2/instruction-provenance/types.ts"],"names":[],"mappings":"AAUA,oFAAoF;AACpF,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG,WAAW,GAAG,UAAU,CAAA;AAExE,M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ACtD,MAAM,WAAW,0BAA0B;IACzC,8CAA8C;IAC9C,QAAQ,EAAE,4BAA4B,CAAA;IACtC;kDAC8C;IAC9C,2BAA2B,EAAE,MAAM,CAAA;CACpC"}
@@ -0,0 +1,11 @@
1
+ // Copyright 2024-2026 Tymofii Pidlisnyi. Apache-2.0 license. See LICENSE.
2
+ // ══════════════════════════════════════════════════════════════════
3
+ // InstructionProvenanceReceipt — types
4
+ // ══════════════════════════════════════════════════════════════════
5
+ // Spec: ~/aeoess_web/specs/INSTRUCTION-PROVENANCE-RECEIPT-DRAFT-v0.2.md
6
+ // Tier scope this version: 'self-asserted' only. 'witnessed' and 'verified'
7
+ // are reserved schema values; verifiers MUST reject envelopes carrying them
8
+ // per ENFORCEMENT-TRUST-ANCHOR Component 4 (§§141-149).
9
+ // ══════════════════════════════════════════════════════════════════
10
+ export {};
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/v2/instruction-provenance/types.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qEAAqE;AACrE,uCAAuC;AACvC,qEAAqE;AACrE,wEAAwE;AACxE,4EAA4E;AAC5E,4EAA4E;AAC5E,wDAAwD;AACxD,qEAAqE"}
@@ -0,0 +1,28 @@
1
+ import type { ActionTimeContextRootInput, VerificationResult, VerifyIPRInput } from './types.js';
2
+ /**
3
+ * Verify an InstructionProvenanceReceipt envelope per spec §6.
4
+ *
5
+ * Pipeline:
6
+ * §6.1 schema + signature
7
+ * §6.2 delegation linkage (signature key matches signing_key_id)
8
+ * §6.3 path canonicalization, sort order, context_root, exhaustiveness
9
+ * §6.4 issued_at + expires_at + bound_to consistency
10
+ *
11
+ * Filesystem-side checks (§6.3 step 10/11 cross-walk vs disk) only run
12
+ * when `filesystemCheck: true` AND `working_root` exists on this host.
13
+ */
14
+ export declare function verifyInstructionProvenanceReceipt(input: VerifyIPRInput): VerificationResult;
15
+ /**
16
+ * §6.5 — when an IPR carries `recompute_at_action: true`, every action
17
+ * receipt under its binding scope MUST include `context_root_at_action_time`
18
+ * computed by re-walking discovery_patterns. This helper compares.
19
+ */
20
+ export declare function verifyActionTimeContextRoot(input: ActionTimeContextRootInput): VerificationResult;
21
+ /**
22
+ * Tiny POSIX-glob matcher. Supports `*`, `?`, `**`, character literals.
23
+ * Patterns are matched against canonical relative paths (no leading `/`,
24
+ * forward-slash separators). Patterns may start with `./` (stripped) or
25
+ * `**` for recursive match.
26
+ */
27
+ export declare function matchesAnyPattern(path: string, patterns: readonly string[]): boolean;
28
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../../src/v2/instruction-provenance/verify.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,0BAA0B,EAG1B,kBAAkB,EAClB,cAAc,EACf,MAAM,YAAY,CAAA;AAOnB;;;;;;;;;;;GAWG;AACH,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,cAAc,GAAG,kBAAkB,CA4I5F;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,0BAA0B,GAAG,kBAAkB,CAiBjG;AAwBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAMpF"}