@agenticprimitives/payments 0.0.0-alpha.3 → 0.0.0-alpha.30

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 (82) hide show
  1. package/README.md +2 -0
  2. package/dist/entitlement/index.d.ts +125 -0
  3. package/dist/entitlement/index.d.ts.map +1 -0
  4. package/dist/entitlement/index.js +128 -0
  5. package/dist/entitlement/index.js.map +1 -0
  6. package/dist/entitlement/voucher.d.ts +85 -0
  7. package/dist/entitlement/voucher.d.ts.map +1 -0
  8. package/dist/entitlement/voucher.js +109 -0
  9. package/dist/entitlement/voucher.js.map +1 -0
  10. package/dist/index.d.ts +24 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +20 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/mandate-sign.d.ts +190 -0
  15. package/dist/mandate-sign.d.ts.map +1 -0
  16. package/dist/mandate-sign.js +202 -0
  17. package/dist/mandate-sign.js.map +1 -0
  18. package/dist/mandate.d.ts +34 -0
  19. package/dist/mandate.d.ts.map +1 -0
  20. package/dist/mandate.js +40 -0
  21. package/dist/mandate.js.map +1 -0
  22. package/dist/ops.d.ts +55 -0
  23. package/dist/ops.d.ts.map +1 -0
  24. package/dist/ops.js +66 -0
  25. package/dist/ops.js.map +1 -0
  26. package/dist/rails/escrow.d.ts +156 -0
  27. package/dist/rails/escrow.d.ts.map +1 -0
  28. package/dist/rails/escrow.js +88 -0
  29. package/dist/rails/escrow.js.map +1 -0
  30. package/dist/rails/invoice.d.ts +65 -0
  31. package/dist/rails/invoice.d.ts.map +1 -0
  32. package/dist/rails/invoice.js +57 -0
  33. package/dist/rails/invoice.js.map +1 -0
  34. package/dist/rails/recurring.d.ts +56 -0
  35. package/dist/rails/recurring.d.ts.map +1 -0
  36. package/dist/rails/recurring.js +58 -0
  37. package/dist/rails/recurring.js.map +1 -0
  38. package/dist/rails/wallet.d.ts +16 -0
  39. package/dist/rails/wallet.d.ts.map +1 -0
  40. package/dist/rails/wallet.js +20 -0
  41. package/dist/rails/wallet.js.map +1 -0
  42. package/dist/rails/x402/executor.d.ts +118 -0
  43. package/dist/rails/x402/executor.d.ts.map +1 -0
  44. package/dist/rails/x402/executor.js +243 -0
  45. package/dist/rails/x402/executor.js.map +1 -0
  46. package/dist/rails/x402/index.d.ts +11 -0
  47. package/dist/rails/x402/index.d.ts.map +1 -0
  48. package/dist/rails/x402/index.js +8 -0
  49. package/dist/rails/x402/index.js.map +1 -0
  50. package/dist/rails/x402/nonce-store.d.ts +30 -0
  51. package/dist/rails/x402/nonce-store.d.ts.map +1 -0
  52. package/dist/rails/x402/nonce-store.js +35 -0
  53. package/dist/rails/x402/nonce-store.js.map +1 -0
  54. package/dist/rails/x402/quote.d.ts +41 -0
  55. package/dist/rails/x402/quote.d.ts.map +1 -0
  56. package/dist/rails/x402/quote.js +84 -0
  57. package/dist/rails/x402/quote.js.map +1 -0
  58. package/dist/rails/x402/resource.d.ts +42 -0
  59. package/dist/rails/x402/resource.d.ts.map +1 -0
  60. package/dist/rails/x402/resource.js +71 -0
  61. package/dist/rails/x402/resource.js.map +1 -0
  62. package/dist/rails/x402/wire.d.ts +81 -0
  63. package/dist/rails/x402/wire.d.ts.map +1 -0
  64. package/dist/rails/x402/wire.js +125 -0
  65. package/dist/rails/x402/wire.js.map +1 -0
  66. package/dist/receipt.d.ts +36 -0
  67. package/dist/receipt.d.ts.map +1 -0
  68. package/dist/receipt.js +50 -0
  69. package/dist/receipt.js.map +1 -0
  70. package/dist/refund.d.ts +29 -0
  71. package/dist/refund.d.ts.map +1 -0
  72. package/dist/refund.js +19 -0
  73. package/dist/refund.js.map +1 -0
  74. package/dist/split.d.ts +27 -0
  75. package/dist/split.d.ts.map +1 -0
  76. package/dist/split.js +33 -0
  77. package/dist/split.js.map +1 -0
  78. package/dist/transfer.d.ts +51 -0
  79. package/dist/transfer.d.ts.map +1 -0
  80. package/dist/transfer.js +54 -0
  81. package/dist/transfer.js.map +1 -0
  82. package/package.json +21 -11
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @agenticprimitives/payments
2
2
 
3
+ > Part of **[Agentic Primitives](https://agenticprimitives.dev)** — the open-source trust substrate for agentic applications: identity that can sign, authority checked at act time, evidence the owner carries. [Developer kit](https://github.com/agentictrustlabs/agentic-primitives) · [All packages](https://agenticprimitives.dev/developers)
4
+
3
5
  > **Status: STUB** (Wave 0.5 of the W1 implementation wave). Typed primitives and invariant guards ship today; the EIP-712 mandate signer and the three W1 rails land in Wave 6 per the [w1 implementation wave plan](../../docs/architecture/w1-implementation-wave-plan.md). A recent self-audit flagged this package's docs for overclaiming ([NEW-PMT-1](../../docs/audits/findings.yaml)); this README is written to the actual surface.
4
6
 
5
7
  Machine payments arrived. x402 made HTTP-native pay-per-request real; Google's AP2 defined mandates for agent-initiated spend. What neither ships — what nobody ships — is machine payments scoped by the *same* delegation, custody, and audit substrate that governs everything else the agent does. "This agent may spend up to this amount, for this task, on this rail, until Friday — signed by a smart account, bound to the work it pays for, receipted into an attestation registry" is the combination the agent economy actually needs, and it only exists when payments are a layer of one system rather than a bolted-on rail.
@@ -0,0 +1,125 @@
1
+ /**
2
+ * spec 272 §10 — entitlements: pay-once-then-access.
3
+ *
4
+ * A successful settlement mints an `EntitlementRecord`. Later access reads CONSUME
5
+ * the entitlement (decrement `usesLeft`) with NO new settlement — one access lane
6
+ * (X402-D8): a request is served against {a fresh charge} OR {a live entitlement},
7
+ * never both. **Prepaid credits = an entitlement with `maxUses: N`** — same machinery.
8
+ *
9
+ * Two bindings:
10
+ * - `'sa'` — held by a specific SA; the presenter MUST be that SA.
11
+ * - `'bearer'`— held by whoever presents the matching voucher (tier A3, unlinkable);
12
+ * this module gates on `voucherId`, the voucher crypto lives in `./voucher`.
13
+ *
14
+ * Fail-closed: an unknown binding, scope mismatch, expiry, or exhausted uses all DENY.
15
+ * Pure (no store): `consumeEntitlement` returns the decremented record; the app persists — single-writer
16
+ * only. For a shared/persisted entitlement use `EntitlementStore.claimUse` (atomic conditional decrement,
17
+ * the ARCH-H3 sibling) so two concurrent redemptions can't double-spend a prepaid credit.
18
+ */
19
+ import { type Address } from 'viem';
20
+ import type { Hex32 } from '../index.js';
21
+ export * as voucher from './voucher.js';
22
+ export type EntitlementBinding = 'sa' | 'bearer';
23
+ export interface EntitlementRecord {
24
+ entitlementId: Hex32;
25
+ binding: EntitlementBinding;
26
+ /** what this grants access to (e.g. keccak of the resource/skill scope) */
27
+ scopeHash: Hex32;
28
+ /** for `'sa'` binding — the SA that may present it */
29
+ subject?: Address;
30
+ /** for `'bearer'` binding — the voucher this entitlement is tied to */
31
+ voucherId?: Hex32;
32
+ /** expiry (unix seconds) */
33
+ ttl: number;
34
+ maxUses: number;
35
+ usesLeft: number;
36
+ provenance: {
37
+ mandateId: Hex32;
38
+ settlementHash: Hex32;
39
+ };
40
+ }
41
+ export interface MintEntitlementInput {
42
+ binding: EntitlementBinding;
43
+ scopeHash: Hex32;
44
+ ttl: number;
45
+ maxUses: number;
46
+ mandateId: Hex32;
47
+ settlementHash: Hex32;
48
+ /** required for `'sa'` binding */
49
+ subject?: Address;
50
+ /** required for `'bearer'` binding */
51
+ voucherId?: Hex32;
52
+ }
53
+ /** Mint an entitlement from a settled payment. Throws if the binding's required handle is missing. */
54
+ export declare function mintEntitlementOnPayment(input: MintEntitlementInput): EntitlementRecord;
55
+ /** Prepaid credit pack = an SA-bound entitlement with `maxUses = count`. */
56
+ export declare function mintCredits(input: Omit<MintEntitlementInput, 'binding' | 'maxUses'> & {
57
+ subject: Address;
58
+ count: number;
59
+ }): EntitlementRecord;
60
+ export interface EntitlementContext {
61
+ scopeHash: Hex32;
62
+ now: number;
63
+ /** the SA presenting (required to match an `'sa'` binding) */
64
+ presenter?: Address;
65
+ /** the voucher id presented (required to match a `'bearer'` binding) */
66
+ voucherId?: Hex32;
67
+ }
68
+ export type EntitlementCheck = {
69
+ ok: true;
70
+ } | {
71
+ ok: false;
72
+ reason: string;
73
+ };
74
+ /** Fail-closed validity check (does NOT consume). */
75
+ export declare function checkEntitlement(record: EntitlementRecord, ctx: EntitlementContext): EntitlementCheck;
76
+ export interface ConsumptionReceipt {
77
+ entitlementId: Hex32;
78
+ scopeHash: Hex32;
79
+ usesLeftAfter: number;
80
+ at: number;
81
+ }
82
+ export type ConsumeResult = {
83
+ ok: true;
84
+ record: EntitlementRecord;
85
+ consumption: ConsumptionReceipt;
86
+ } | {
87
+ ok: false;
88
+ reason: string;
89
+ };
90
+ /**
91
+ * Validate + decrement (PURE — returns the updated record; does NOT persist).
92
+ *
93
+ * entitlement-consume-toctou-no-atomic-claim (2026-07-04 self-audit): on its own this is a TOCTOU seam.
94
+ * A caller that does `checkEntitlement()` (or `consumeEntitlement()`) and THEN persists `record.usesLeft`
95
+ * has a read→decrement→write window: two concurrent redemptions of a prepaid `usesLeft:1` credit can both
96
+ * read 1 and both write 0, double-spending a money-equivalent pack. Use this only in-process/single-writer.
97
+ * For a shared/persisted entitlement, go through {@link EntitlementStore.claimUse}, whose atomic conditional
98
+ * decrement is the ARCH-H3 sibling of `SpentSet.claim`.
99
+ */
100
+ export declare function consumeEntitlement(record: EntitlementRecord, ctx: EntitlementContext): ConsumeResult;
101
+ export interface EntitlementStore {
102
+ /**
103
+ * entitlement-consume-toctou / ARCH-H3 sibling: ATOMIC validate + single-use decrement of a STORED
104
+ * entitlement. Returns ok ONLY if this call claimed a use — the record exists, matches `ctx` (scope +
105
+ * binding + presenter/voucher), is unexpired, and had `usesLeft > 0` at the instant of decrement. Two
106
+ * concurrent redemptions of a `usesLeft:1` credit: exactly one gets ok, the other `entitlement exhausted`.
107
+ * A distributed backend MUST implement the decrement as a conditional write so atomicity lives in the
108
+ * interface, not each caller: D1 `UPDATE … SET usesLeft = usesLeft - 1 WHERE entitlementId = ? AND
109
+ * usesLeft > 0 RETURNING usesLeft` (rows-affected == 1 is the claim), a Durable Object transaction, or a
110
+ * conditional put. Mirrors `SpentSet.claim` / x402 `NonceReservationStore.reserve`.
111
+ */
112
+ claimUse(entitlementId: Hex32, ctx: EntitlementContext): ConsumeResult | Promise<ConsumeResult>;
113
+ }
114
+ /**
115
+ * Reference in-memory {@link EntitlementStore}. In-process JS is single-threaded, so the validate +
116
+ * decrement below is naturally atomic — the interface demands the same guarantee of every (distributed)
117
+ * implementer. Seed it with the minted records; `claimUse` mutates `usesLeft` in place under the claim.
118
+ */
119
+ export declare function createMemoryEntitlementStore(records?: Iterable<EntitlementRecord>): EntitlementStore & {
120
+ put(record: EntitlementRecord): void;
121
+ get(id: Hex32): EntitlementRecord | undefined;
122
+ };
123
+ /** Convenience: keccak of a resource/skill scope string → `scopeHash`. */
124
+ export declare function scopeHashOf(scope: string): Hex32;
125
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entitlement/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAA2C,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,QAAQ,CAAC;AAEjD,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,KAAK,CAAC;IACrB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,2EAA2E;IAC3E,SAAS,EAAE,KAAK,CAAC;IACjB,sDAAsD;IACtD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uEAAuE;IACvE,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,4BAA4B;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE;QAAE,SAAS,EAAE,KAAK,CAAC;QAAC,cAAc,EAAE,KAAK,CAAA;KAAE,CAA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,GACrB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAC;IAAC,WAAW,EAAE,kBAAkB,CAAA;CAAE,GACxE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,kBAAkB,GAAG,aAAa,CASpG;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;OASG;IACH,QAAQ,CAAC,aAAa,EAAE,KAAK,EAAE,GAAG,EAAE,kBAAkB,GAAG,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CACjG;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,GAAE,QAAQ,CAAC,iBAAiB,CAAM,GAAG,gBAAgB,GAAG;IAC1G,GAAG,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACrC,GAAG,CAAC,EAAE,EAAE,KAAK,GAAG,iBAAiB,GAAG,SAAS,CAAC;CAC/C,CAeA;AAED,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAEhD"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * spec 272 §10 — entitlements: pay-once-then-access.
3
+ *
4
+ * A successful settlement mints an `EntitlementRecord`. Later access reads CONSUME
5
+ * the entitlement (decrement `usesLeft`) with NO new settlement — one access lane
6
+ * (X402-D8): a request is served against {a fresh charge} OR {a live entitlement},
7
+ * never both. **Prepaid credits = an entitlement with `maxUses: N`** — same machinery.
8
+ *
9
+ * Two bindings:
10
+ * - `'sa'` — held by a specific SA; the presenter MUST be that SA.
11
+ * - `'bearer'`— held by whoever presents the matching voucher (tier A3, unlinkable);
12
+ * this module gates on `voucherId`, the voucher crypto lives in `./voucher`.
13
+ *
14
+ * Fail-closed: an unknown binding, scope mismatch, expiry, or exhausted uses all DENY.
15
+ * Pure (no store): `consumeEntitlement` returns the decremented record; the app persists — single-writer
16
+ * only. For a shared/persisted entitlement use `EntitlementStore.claimUse` (atomic conditional decrement,
17
+ * the ARCH-H3 sibling) so two concurrent redemptions can't double-spend a prepaid credit.
18
+ */
19
+ import { keccak256, encodeAbiParameters, toBytes } from 'viem';
20
+ // tier A3 — blind bearer vouchers (Privacy Pass / VOPRF).
21
+ export * as voucher from './voucher.js';
22
+ const ZERO32 = ('0x' + '00'.repeat(32));
23
+ function entitlementId(args) {
24
+ return keccak256(encodeAbiParameters([{ type: 'string' }, { type: 'bytes32' }, { type: 'bytes32' }, { type: 'bytes32' }], [
25
+ args.binding,
26
+ args.scopeHash,
27
+ args.binding === 'sa'
28
+ ? keccak256(toBytes(args.subject ?? '0x'))
29
+ : (args.voucherId ?? ZERO32),
30
+ args.mandateId,
31
+ ]));
32
+ }
33
+ /** Mint an entitlement from a settled payment. Throws if the binding's required handle is missing. */
34
+ export function mintEntitlementOnPayment(input) {
35
+ if (input.binding === 'sa' && !input.subject)
36
+ throw new Error("[entitlement] 'sa' binding requires subject");
37
+ if (input.binding === 'bearer' && !input.voucherId)
38
+ throw new Error("[entitlement] 'bearer' binding requires voucherId");
39
+ if (input.maxUses < 1)
40
+ throw new Error('[entitlement] maxUses must be >= 1');
41
+ return {
42
+ entitlementId: entitlementId(input),
43
+ binding: input.binding,
44
+ scopeHash: input.scopeHash,
45
+ subject: input.subject,
46
+ voucherId: input.voucherId,
47
+ ttl: input.ttl,
48
+ maxUses: input.maxUses,
49
+ usesLeft: input.maxUses,
50
+ provenance: { mandateId: input.mandateId, settlementHash: input.settlementHash },
51
+ };
52
+ }
53
+ /** Prepaid credit pack = an SA-bound entitlement with `maxUses = count`. */
54
+ export function mintCredits(input) {
55
+ return mintEntitlementOnPayment({ ...input, binding: 'sa', maxUses: input.count });
56
+ }
57
+ /** Fail-closed validity check (does NOT consume). */
58
+ export function checkEntitlement(record, ctx) {
59
+ if (record.binding !== 'sa' && record.binding !== 'bearer')
60
+ return { ok: false, reason: 'unknown entitlement binding' };
61
+ if (record.scopeHash.toLowerCase() !== ctx.scopeHash.toLowerCase())
62
+ return { ok: false, reason: 'scope mismatch' };
63
+ if (ctx.now >= record.ttl)
64
+ return { ok: false, reason: 'entitlement expired' };
65
+ if (record.usesLeft <= 0)
66
+ return { ok: false, reason: 'entitlement exhausted' };
67
+ if (record.binding === 'sa') {
68
+ if (!ctx.presenter || !record.subject || ctx.presenter.toLowerCase() !== record.subject.toLowerCase()) {
69
+ return { ok: false, reason: 'presenter is not the entitlement subject' };
70
+ }
71
+ }
72
+ else {
73
+ if (!ctx.voucherId || !record.voucherId || ctx.voucherId.toLowerCase() !== record.voucherId.toLowerCase()) {
74
+ return { ok: false, reason: 'voucher mismatch' };
75
+ }
76
+ }
77
+ return { ok: true };
78
+ }
79
+ /**
80
+ * Validate + decrement (PURE — returns the updated record; does NOT persist).
81
+ *
82
+ * entitlement-consume-toctou-no-atomic-claim (2026-07-04 self-audit): on its own this is a TOCTOU seam.
83
+ * A caller that does `checkEntitlement()` (or `consumeEntitlement()`) and THEN persists `record.usesLeft`
84
+ * has a read→decrement→write window: two concurrent redemptions of a prepaid `usesLeft:1` credit can both
85
+ * read 1 and both write 0, double-spending a money-equivalent pack. Use this only in-process/single-writer.
86
+ * For a shared/persisted entitlement, go through {@link EntitlementStore.claimUse}, whose atomic conditional
87
+ * decrement is the ARCH-H3 sibling of `SpentSet.claim`.
88
+ */
89
+ export function consumeEntitlement(record, ctx) {
90
+ const v = checkEntitlement(record, ctx);
91
+ if (!v.ok)
92
+ return v;
93
+ const updated = { ...record, usesLeft: record.usesLeft - 1 };
94
+ return {
95
+ ok: true,
96
+ record: updated,
97
+ consumption: { entitlementId: record.entitlementId, scopeHash: record.scopeHash, usesLeftAfter: updated.usesLeft, at: ctx.now },
98
+ };
99
+ }
100
+ /**
101
+ * Reference in-memory {@link EntitlementStore}. In-process JS is single-threaded, so the validate +
102
+ * decrement below is naturally atomic — the interface demands the same guarantee of every (distributed)
103
+ * implementer. Seed it with the minted records; `claimUse` mutates `usesLeft` in place under the claim.
104
+ */
105
+ export function createMemoryEntitlementStore(records = []) {
106
+ const byId = new Map();
107
+ for (const r of records)
108
+ byId.set(r.entitlementId.toLowerCase(), { ...r });
109
+ return {
110
+ put: (r) => byId.set(r.entitlementId.toLowerCase(), { ...r }),
111
+ get: (id) => byId.get(id.toLowerCase()),
112
+ claimUse: (id, ctx) => {
113
+ const record = byId.get(id.toLowerCase());
114
+ if (!record)
115
+ return { ok: false, reason: 'entitlement not found' };
116
+ const result = consumeEntitlement(record, ctx);
117
+ if (!result.ok)
118
+ return result;
119
+ byId.set(id.toLowerCase(), result.record); // commit the decrement under the same synchronous claim
120
+ return result;
121
+ },
122
+ };
123
+ }
124
+ /** Convenience: keccak of a resource/skill scope string → `scopeHash`. */
125
+ export function scopeHashOf(scope) {
126
+ return keccak256(toBytes(`entitlement-scope:${scope}`));
127
+ }
128
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entitlement/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAG7E,0DAA0D;AAC1D,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAoBxC,MAAM,MAAM,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAU,CAAC;AAEjD,SAAS,aAAa,CAAC,IAMtB;IACC,OAAO,SAAS,CACd,mBAAmB,CACjB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EACnF;QACE,IAAI,CAAC,OAAO;QACZ,IA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IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;YAC1C,IAAI,CAAC,MAAM;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;YACnE,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAC/C,IAAI,CAAC,MAAM,CAAC,EAAE;gBAAE,OAAO,MAAM,CAAC;YAC9B,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,wDAAwD;YACnG,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,SAAS,CAAC,OAAO,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAU,CAAC;AACnE,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * spec 272 §10 tier A3 — blind bearer vouchers (Privacy Pass / RFC 9497 VOPRF).
3
+ *
4
+ * Pay once → receive a pack of UNLINKABLE one-use vouchers → redeem each from a
5
+ * separate context with no link back to the purchase. Built on ristretto255 VOPRF
6
+ * (`@noble/curves`) — the issuer never sees the unblinded token at issuance, so the
7
+ * blinded request it signs and the token presented at redemption cannot be linked.
8
+ *
9
+ * Flow:
10
+ * client blindVoucherRequest() → { request(blinded), secret(tokenId,blind,blinded) }
11
+ * issuer issueVoucher(key, request) → { evaluated, proof } (VOPRF blind-evaluate)
12
+ * client unblindVoucher(secret, issued, pubKey) → Voucher (verifies the issuer proof)
13
+ * issuer redeemVoucher(key, voucher, spentSet) → ok | reason (VOPRF verify + double-spend)
14
+ *
15
+ * One-use is enforced by the spent-set keyed on `voucherId = keccak(tokenId)`.
16
+ */
17
+ import type { Hex } from '@agenticprimitives/types';
18
+ import type { Hex32 } from '../index.js';
19
+ export interface VoucherIssuerKey {
20
+ secretKey: Hex;
21
+ publicKey: Hex;
22
+ }
23
+ export interface BlindedVoucherRequest {
24
+ blinded: Hex;
25
+ }
26
+ /** The client's unblinding state — kept private until `unblindVoucher`. */
27
+ export interface VoucherSecret {
28
+ tokenId: Hex;
29
+ blind: Hex;
30
+ blinded: Hex;
31
+ }
32
+ export interface IssuedVoucher {
33
+ evaluated: Hex;
34
+ proof: Hex;
35
+ }
36
+ /** A redeemable one-use bearer token. */
37
+ export interface Voucher {
38
+ voucherId: Hex32;
39
+ tokenId: Hex;
40
+ output: Hex;
41
+ }
42
+ export declare function generateVoucherIssuerKey(): VoucherIssuerKey;
43
+ /** Deterministic issuer key from a 32-byte seed (stable across processes). */
44
+ export declare function deriveVoucherIssuerKey(seed: Hex, info?: string): VoucherIssuerKey;
45
+ /** `voucherId` — the public, spent-set key derived from the token (no link to the blinded request). */
46
+ export declare function voucherIdOf(tokenId: Hex): Hex32;
47
+ /** Client: blind a fresh random token (or a supplied one) for issuance. */
48
+ export declare function blindVoucherRequest(tokenId?: Hex): {
49
+ request: BlindedVoucherRequest;
50
+ secret: VoucherSecret;
51
+ };
52
+ /** Issuer: blind-evaluate one request (VOPRF — issuer learns nothing about the token). */
53
+ export declare function issueVoucher(key: VoucherIssuerKey, request: BlindedVoucherRequest): IssuedVoucher;
54
+ /** Issuer: issue a whole pack. */
55
+ export declare function issueVouchers(key: VoucherIssuerKey, requests: BlindedVoucherRequest[]): IssuedVoucher[];
56
+ /**
57
+ * Client: unblind into a finished voucher. Throws if the issuer's VOPRF proof fails
58
+ * (a malicious issuer using the wrong key is detected here — verifiability).
59
+ */
60
+ export declare function unblindVoucher(secret: VoucherSecret, issued: IssuedVoucher, issuerPublicKey: Hex): Voucher;
61
+ /** Issuer: VOPRF validity of a presented voucher (does NOT check double-spend). Fail-closed. */
62
+ export declare function verifyVoucher(key: VoucherIssuerKey, voucher: Voucher): {
63
+ ok: boolean;
64
+ reason?: string;
65
+ };
66
+ export interface SpentSet {
67
+ /**
68
+ * ARCH-H3 (seam audit): ATOMIC claim of a one-use id. Returns `true` if THIS call claimed the id
69
+ * (it was fresh), `false` if it was already spent. Replaces the former TOCTOU `has()` + `add()` pair —
70
+ * a check-then-add across an `await` let two concurrent redemptions of a money-equivalent one-use
71
+ * voucher BOTH succeed. A distributed backend MUST implement this as an insert-if-absent (D1 `INSERT
72
+ * ... ON CONFLICT DO NOTHING` + rows-affected, a Durable Object transaction, or a conditional put) so
73
+ * the atomicity lives in the interface, not in each caller. Mirrors x402 `NonceReservationStore.reserve`.
74
+ */
75
+ claim(id: Hex32): boolean | Promise<boolean>;
76
+ }
77
+ export declare function createMemorySpentSet(): SpentSet & {
78
+ size(): number;
79
+ };
80
+ /** Issuer: verify + one-shot redeem. Rejects an invalid voucher and a replayed one. */
81
+ export declare function redeemVoucher(key: VoucherIssuerKey, voucher: Voucher, spent: SpentSet): Promise<{
82
+ ok: boolean;
83
+ reason?: string;
84
+ }>;
85
+ //# sourceMappingURL=voucher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voucher.d.ts","sourceRoot":"","sources":["../../src/entitlement/voucher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAezC,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,GAAG,CAAC;CAChB;AACD,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,GAAG,CAAC;CACd;AACD,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,GAAG,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,GAAG,CAAC;CACd;AACD,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,GAAG,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;CACZ;AACD,yCAA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ED,uFAAuF;AACvF,wBAAsB,aAAa,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAMvI"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * spec 272 §10 tier A3 — blind bearer vouchers (Privacy Pass / RFC 9497 VOPRF).
3
+ *
4
+ * Pay once → receive a pack of UNLINKABLE one-use vouchers → redeem each from a
5
+ * separate context with no link back to the purchase. Built on ristretto255 VOPRF
6
+ * (`@noble/curves`) — the issuer never sees the unblinded token at issuance, so the
7
+ * blinded request it signs and the token presented at redemption cannot be linked.
8
+ *
9
+ * Flow:
10
+ * client blindVoucherRequest() → { request(blinded), secret(tokenId,blind,blinded) }
11
+ * issuer issueVoucher(key, request) → { evaluated, proof } (VOPRF blind-evaluate)
12
+ * client unblindVoucher(secret, issued, pubKey) → Voucher (verifies the issuer proof)
13
+ * issuer redeemVoucher(key, voucher, spentSet) → ok | reason (VOPRF verify + double-spend)
14
+ *
15
+ * One-use is enforced by the spent-set keyed on `voucherId = keccak(tokenId)`.
16
+ */
17
+ import { ristretto255_oprf } from '@noble/curves/ed25519.js';
18
+ import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';
19
+ import { keccak256 } from 'viem';
20
+ const voprf = ristretto255_oprf.voprf;
21
+ const enc = new TextEncoder();
22
+ // @noble bytesToHex returns NO `0x` prefix; add it so values are real `Hex` and `.slice(2)` strips it.
23
+ const hx = (b) => ('0x' + bytesToHex(b));
24
+ export function generateVoucherIssuerKey() {
25
+ const kp = voprf.generateKeyPair();
26
+ return { secretKey: hx(kp.secretKey), publicKey: hx(kp.publicKey) };
27
+ }
28
+ /** Deterministic issuer key from a 32-byte seed (stable across processes). */
29
+ export function deriveVoucherIssuerKey(seed, info = 'agentic-voucher-issuer') {
30
+ const kp = voprf.deriveKeyPair(hexToBytes(seed.slice(2)), enc.encode(info));
31
+ return { secretKey: hx(kp.secretKey), publicKey: hx(kp.publicKey) };
32
+ }
33
+ /** `voucherId` — the public, spent-set key derived from the token (no link to the blinded request). */
34
+ export function voucherIdOf(tokenId) {
35
+ return keccak256(tokenId);
36
+ }
37
+ /** Client: blind a fresh random token (or a supplied one) for issuance. */
38
+ export function blindVoucherRequest(tokenId) {
39
+ const tok = tokenId ? hexToBytes(tokenId.slice(2)) : globalThis.crypto.getRandomValues(new Uint8Array(32));
40
+ const { blind, blinded } = voprf.blind(tok);
41
+ return {
42
+ request: { blinded: hx(blinded) },
43
+ secret: { tokenId: hx(tok), blind: hx(blind), blinded: hx(blinded) },
44
+ };
45
+ }
46
+ /** Issuer: blind-evaluate one request (VOPRF — issuer learns nothing about the token). */
47
+ export function issueVoucher(key, request) {
48
+ const be = voprf.blindEvaluate(hexToBytes(key.secretKey.slice(2)), hexToBytes(key.publicKey.slice(2)), hexToBytes(request.blinded.slice(2)));
49
+ return { evaluated: hx(be.evaluated), proof: hx(be.proof) };
50
+ }
51
+ /** Issuer: issue a whole pack. */
52
+ export function issueVouchers(key, requests) {
53
+ return requests.map((r) => issueVoucher(key, r));
54
+ }
55
+ /**
56
+ * Client: unblind into a finished voucher. Throws if the issuer's VOPRF proof fails
57
+ * (a malicious issuer using the wrong key is detected here — verifiability).
58
+ */
59
+ export function unblindVoucher(secret, issued, issuerPublicKey) {
60
+ const output = voprf.finalize(hexToBytes(secret.tokenId.slice(2)), hexToBytes(secret.blind.slice(2)), hexToBytes(issued.evaluated.slice(2)), hexToBytes(secret.blinded.slice(2)), hexToBytes(issuerPublicKey.slice(2)), hexToBytes(issued.proof.slice(2)));
61
+ return { voucherId: voucherIdOf(secret.tokenId), tokenId: secret.tokenId, output: hx(output) };
62
+ }
63
+ function ctEqual(a, b) {
64
+ if (a.length !== b.length)
65
+ return false;
66
+ let d = 0;
67
+ for (let i = 0; i < a.length; i++)
68
+ d |= a[i] ^ b[i];
69
+ return d === 0;
70
+ }
71
+ /** Issuer: VOPRF validity of a presented voucher (does NOT check double-spend). Fail-closed. */
72
+ export function verifyVoucher(key, voucher) {
73
+ try {
74
+ if (voucher.voucherId.toLowerCase() !== voucherIdOf(voucher.tokenId).toLowerCase()) {
75
+ return { ok: false, reason: 'voucherId does not match tokenId' };
76
+ }
77
+ const expected = voprf.evaluate(hexToBytes(key.secretKey.slice(2)), hexToBytes(voucher.tokenId.slice(2)));
78
+ return ctEqual(expected, hexToBytes(voucher.output.slice(2))) ? { ok: true } : { ok: false, reason: 'invalid voucher' };
79
+ }
80
+ catch {
81
+ return { ok: false, reason: 'malformed voucher' };
82
+ }
83
+ }
84
+ export function createMemorySpentSet() {
85
+ const set = new Set();
86
+ return {
87
+ // In-process JS is single-threaded, so test-and-set here is naturally atomic; the interface demands
88
+ // the same guarantee of every (distributed) implementer.
89
+ claim: (id) => {
90
+ const k = id.toLowerCase();
91
+ if (set.has(k))
92
+ return false;
93
+ set.add(k);
94
+ return true;
95
+ },
96
+ size: () => set.size,
97
+ };
98
+ }
99
+ /** Issuer: verify + one-shot redeem. Rejects an invalid voucher and a replayed one. */
100
+ export async function redeemVoucher(key, voucher, spent) {
101
+ const v = verifyVoucher(key, voucher);
102
+ if (!v.ok)
103
+ return v;
104
+ // ARCH-H3: atomic claim — no check-then-add window. Two concurrent redemptions can't both win.
105
+ if (!(await spent.claim(voucher.voucherId)))
106
+ return { ok: false, reason: 'voucher already spent' };
107
+ return { ok: true };
108
+ }
109
+ //# sourceMappingURL=voucher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voucher.js","sourceRoot":"","sources":["../../src/entitlement/voucher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,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AC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;IACnG,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -52,7 +52,12 @@ export interface ContextBinding {
52
52
  method: string;
53
53
  url: string;
54
54
  requestBodyHash: Hex32;
55
+ salt?: Hex32;
55
56
  };
57
+ /** EXC-R2 — the ExchangeOrder this payment leg belongs to (273/274). x402 sets `orderHash = quoteId`. */
58
+ orderHash?: Hex32;
59
+ /** EXC-R2 — distinguishes legs within one order (charge / refund / split-out / escrow-release). */
60
+ legId?: Hex32;
56
61
  chain: number;
57
62
  asset: AssetRef;
58
63
  nonce: bigint;
@@ -109,4 +114,23 @@ export interface PaymentRailExecutor {
109
114
  }
110
115
  export declare function registerRail(executor: PaymentRailExecutor): void;
111
116
  export declare function getRail(rail: PaymentRail): PaymentRailExecutor | undefined;
117
+ export { PAYMENT_MANDATE_DOMAIN_NAME, PAYMENT_MANDATE_DOMAIN_VERSION, PAYMENT_MANDATE_EIP712_TYPES, ERC1271_MAGIC, mandateAmount, hashContextBinding, hashMandateBindings, paymentMandateDomain, buildPaymentMandateTypedData, paymentMandateDigest, signPaymentMandate, verifyPaymentMandateSignature, } from './mandate-sign.js';
118
+ export type { MandateDomainOpts, MandateSigner, Erc1271Reader } from './mandate-sign.js';
119
+ export { PAYMENT_RECEIPT_TYPE, settlementEpochBucket, buildPaymentReceiptCredential } from './receipt.js';
120
+ export type { PaymentReceiptInput } from './receipt.js';
121
+ export * as x402 from './rails/x402/index.js';
122
+ export * as entitlement from './entitlement/index.js';
123
+ export { ERC20_TRANSFER_ABI, ERC20_APPROVE_ABI, buildErc20Transfer, buildErc20Approve, buildNativeTransfer } from './transfer.js';
124
+ export type { TransferPlan } from './transfer.js';
125
+ export { buildClosedMandate } from './mandate.js';
126
+ export type { ClosedMandateInput } from './mandate.js';
127
+ export * as wallet from './rails/wallet.js';
128
+ export * as invoice from './rails/invoice.js';
129
+ export * as escrow from './rails/escrow.js';
130
+ export * as recurring from './rails/recurring.js';
131
+ export { buildRefund } from './refund.js';
132
+ export type { RefundInput, RefundPlan } from './refund.js';
133
+ export { buildSplitPayout, BPS_DENOMINATOR } from './split.js';
134
+ export type { SplitRecipient, SplitLeg } from './split.js';
135
+ export * as ops from './ops.js';
112
136
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE7D,eAAO,MAAM,YAAY,gCAAgC,CAAC;AAC1D,eAAO,MAAM,cAAc,EAAG,iBAA0B,CAAC;AACzD,eAAO,MAAM,QAAQ,0BAA0B,CAAC;AAEhD,MAAM,MAAM,KAAK,GAAG,KAAK,MAAM,EAAE,CAAC;AAElC,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,QAAQ,GACR,kBAAkB,GAClB,QAAQ,GACR,SAAS,GACT,oBAAoB,GACpB,oBAAoB,GACpB,2BAA2B,CAAC;AAEhC,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACvF;IAAE,IAAI,EAAE,SAAS,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,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3D,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -37,4 +37,24 @@ export function registerRail(executor) {
37
37
  export function getRail(rail) {
38
38
  return _rails.get(rail);
39
39
  }
40
+ // Spec 243 §4.2 / PMT-INV-02/12 — EIP-712 mandate signing + ERC-1271 verification.
41
+ export { PAYMENT_MANDATE_DOMAIN_NAME, PAYMENT_MANDATE_DOMAIN_VERSION, PAYMENT_MANDATE_EIP712_TYPES, ERC1271_MAGIC, mandateAmount, hashContextBinding, hashMandateBindings, paymentMandateDomain, buildPaymentMandateTypedData, paymentMandateDigest, signPaymentMandate, verifyPaymentMandateSignature, } from './mandate-sign.js';
42
+ // Spec 243 §7 / X402-D9.3 — PaymentReceipt verifiable credential.
43
+ export { PAYMENT_RECEIPT_TYPE, settlementEpochBucket, buildPaymentReceiptCredential } from './receipt.js';
44
+ // Spec 272 — the x402 rail (staged executor + v2 wire + nonce store + resource binding).
45
+ export * as x402 from './rails/x402/index.js';
46
+ // Spec 272 §10 — entitlements (pay-once-then-access; credits = maxUses:N).
47
+ export * as entitlement from './entitlement/index.js';
48
+ // Spec 243 §5.5 — shared transfer plumbing + closed-mandate builder.
49
+ export { ERC20_TRANSFER_ABI, ERC20_APPROVE_ABI, buildErc20Transfer, buildErc20Approve, buildNativeTransfer } from './transfer.js';
50
+ export { buildClosedMandate } from './mandate.js';
51
+ // Spec 243 §5.5 — general-purpose rails + profiles + payout legs.
52
+ export * as wallet from './rails/wallet.js';
53
+ export * as invoice from './rails/invoice.js';
54
+ export * as escrow from './rails/escrow.js';
55
+ export * as recurring from './rails/recurring.js';
56
+ export { buildRefund } from './refund.js';
57
+ export { buildSplitPayout, BPS_DENOMINATOR } from './split.js';
58
+ // Spec 243 §5.5 — ops core (idempotent event log + reconciliation + export).
59
+ export * as ops from './ops.js';
40
60
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,MAAM,CAAC,MAAM,YAAY,GAAG,6BAA6B,CAAC;AAC1D,MAAM,CAAC,MAAM,cAAc,GAAG,iBAA0B,CAAC;AACzD,MAAM,CAAC,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AAqEhD,sEAAsE;AACtE,MAAM,UAAU,yBAAyB,CAAC,EAAkB;IAC1D,MAAM,GAAG,GAAG,EAAE,CAAC,QAAQ,IAAI,EAAE,CAAC,mBAAmB,IAAI,EAAE,CAAC,MAAM,IAAI,EAAE,CAAC,YAAY,IAAI,EAAE,CAAC,QAAQ,CAAC;IACjG,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,mIAAmI,CACpI,CAAC;IACJ,CAAC;AACH,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,6BAA6B,CAAC,OAAuB;IACnE,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAKhC;IACC,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;IACpF,MAAM,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7C,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,K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