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

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 (81) hide show
  1. package/dist/entitlement/index.d.ts +92 -0
  2. package/dist/entitlement/index.d.ts.map +1 -0
  3. package/dist/entitlement/index.js +93 -0
  4. package/dist/entitlement/index.js.map +1 -0
  5. package/dist/entitlement/voucher.d.ts +78 -0
  6. package/dist/entitlement/voucher.d.ts.map +1 -0
  7. package/dist/entitlement/voucher.js +102 -0
  8. package/dist/entitlement/voucher.js.map +1 -0
  9. package/dist/index.d.ts +23 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +20 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/mandate-sign.d.ts +173 -0
  14. package/dist/mandate-sign.d.ts.map +1 -0
  15. package/dist/mandate-sign.js +147 -0
  16. package/dist/mandate-sign.js.map +1 -0
  17. package/dist/mandate.d.ts +33 -0
  18. package/dist/mandate.d.ts.map +1 -0
  19. package/dist/mandate.js +40 -0
  20. package/dist/mandate.js.map +1 -0
  21. package/dist/ops.d.ts +55 -0
  22. package/dist/ops.d.ts.map +1 -0
  23. package/dist/ops.js +66 -0
  24. package/dist/ops.js.map +1 -0
  25. package/dist/rails/escrow.d.ts +143 -0
  26. package/dist/rails/escrow.d.ts.map +1 -0
  27. package/dist/rails/escrow.js +90 -0
  28. package/dist/rails/escrow.js.map +1 -0
  29. package/dist/rails/invoice.d.ts +65 -0
  30. package/dist/rails/invoice.d.ts.map +1 -0
  31. package/dist/rails/invoice.js +57 -0
  32. package/dist/rails/invoice.js.map +1 -0
  33. package/dist/rails/recurring.d.ts +56 -0
  34. package/dist/rails/recurring.d.ts.map +1 -0
  35. package/dist/rails/recurring.js +58 -0
  36. package/dist/rails/recurring.js.map +1 -0
  37. package/dist/rails/wallet.d.ts +16 -0
  38. package/dist/rails/wallet.d.ts.map +1 -0
  39. package/dist/rails/wallet.js +20 -0
  40. package/dist/rails/wallet.js.map +1 -0
  41. package/dist/rails/x402/executor.d.ts +109 -0
  42. package/dist/rails/x402/executor.d.ts.map +1 -0
  43. package/dist/rails/x402/executor.js +222 -0
  44. package/dist/rails/x402/executor.js.map +1 -0
  45. package/dist/rails/x402/index.d.ts +11 -0
  46. package/dist/rails/x402/index.d.ts.map +1 -0
  47. package/dist/rails/x402/index.js +8 -0
  48. package/dist/rails/x402/index.js.map +1 -0
  49. package/dist/rails/x402/nonce-store.d.ts +30 -0
  50. package/dist/rails/x402/nonce-store.d.ts.map +1 -0
  51. package/dist/rails/x402/nonce-store.js +35 -0
  52. package/dist/rails/x402/nonce-store.js.map +1 -0
  53. package/dist/rails/x402/quote.d.ts +41 -0
  54. package/dist/rails/x402/quote.d.ts.map +1 -0
  55. package/dist/rails/x402/quote.js +84 -0
  56. package/dist/rails/x402/quote.js.map +1 -0
  57. package/dist/rails/x402/resource.d.ts +42 -0
  58. package/dist/rails/x402/resource.d.ts.map +1 -0
  59. package/dist/rails/x402/resource.js +71 -0
  60. package/dist/rails/x402/resource.js.map +1 -0
  61. package/dist/rails/x402/wire.d.ts +81 -0
  62. package/dist/rails/x402/wire.d.ts.map +1 -0
  63. package/dist/rails/x402/wire.js +125 -0
  64. package/dist/rails/x402/wire.js.map +1 -0
  65. package/dist/receipt.d.ts +36 -0
  66. package/dist/receipt.d.ts.map +1 -0
  67. package/dist/receipt.js +50 -0
  68. package/dist/receipt.js.map +1 -0
  69. package/dist/refund.d.ts +29 -0
  70. package/dist/refund.d.ts.map +1 -0
  71. package/dist/refund.js +19 -0
  72. package/dist/refund.js.map +1 -0
  73. package/dist/split.d.ts +27 -0
  74. package/dist/split.d.ts.map +1 -0
  75. package/dist/split.js +33 -0
  76. package/dist/split.js.map +1 -0
  77. package/dist/transfer.d.ts +51 -0
  78. package/dist/transfer.d.ts.map +1 -0
  79. package/dist/transfer.js +54 -0
  80. package/dist/transfer.js.map +1 -0
  81. package/package.json +6 -5
@@ -0,0 +1,109 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ import type { Delegation } from '@agenticprimitives/delegation';
3
+ import { type PaymentMandate } from '../../index.js';
4
+ import type { Hex32 } from './resource.js';
5
+ import type { PaymentQuote } from './quote.js';
6
+ import type { NonceReservationStore } from './nonce-store.js';
7
+ /** x402-specific bits the mandate carries (PaymentMandate.railConfig). Binds the mandate to its quote. */
8
+ export interface X402RailConfig {
9
+ quoteId: Hex32;
10
+ resourceHash: Hex32;
11
+ }
12
+ /** PAY-RAIL-4 — the rail-scoped replay nullifier. */
13
+ export declare function computeNullifier(args: {
14
+ rail: string;
15
+ chainId: number;
16
+ payer: Address;
17
+ payee: Address;
18
+ asset: Address;
19
+ mandateId: Hex32;
20
+ nonce: bigint;
21
+ resourceHash: Hex32;
22
+ }): Hex32;
23
+ /**
24
+ * PAY-RAIL-1 — synchronous mandate verification against its persisted quote. Returns the first failure
25
+ * reason (or null). The async checks (revocation, nonce-unused) run in the rail's settle() flow.
26
+ */
27
+ export declare function verifyMandate(mandate: PaymentMandate, quote: PaymentQuote, opts: {
28
+ now: number;
29
+ }): {
30
+ valid: true;
31
+ } | {
32
+ valid: false;
33
+ reason: string;
34
+ };
35
+ /**
36
+ * PAY-RAIL-2 — build the redemption plan: DelegationManager.redeemDelegation(paymentDelegation,
37
+ * USDC.transfer(treasury, amount)) with the PaymentEnforcer caveat's `args` filled with the mandate's
38
+ * (mandateId, nonce, resourceHash) at REDEMPTION time. The caller submits `{to, value, data}` from the
39
+ * service relayer as a sponsored UserOp.
40
+ */
41
+ export declare function buildRedemptionCalldata(args: {
42
+ mandate: PaymentMandate;
43
+ delegation: Delegation;
44
+ delegationManager: Address;
45
+ paymentEnforcer: Address;
46
+ asset: Address;
47
+ resourceHash: Hex32;
48
+ }): {
49
+ to: Address;
50
+ value: bigint;
51
+ data: Hex;
52
+ };
53
+ export interface X402RailDeps {
54
+ chainId: number;
55
+ delegationManager: Address;
56
+ paymentEnforcer: Address;
57
+ asset: Address;
58
+ nonceStore: NonceReservationStore;
59
+ /** Off-chain revocation read (the app wires `delegation.isRevoked`). Checked BEFORE settling; the DM
60
+ * also enforces revocation on-chain (PAY-DEL-3). */
61
+ isRevoked: (delegationHash: Hex32) => Promise<boolean>;
62
+ /** Submit the redemption (a sponsored UserOp from the service relayer, X402-D4). Injected by the app /
63
+ * agent-account layer; returns the settlement tx hash. */
64
+ submitRedemption: (plan: {
65
+ to: Address;
66
+ value: bigint;
67
+ data: Hex;
68
+ }) => Promise<{
69
+ settlementHash: Hex32;
70
+ }>;
71
+ /** PAY-RAIL-6 — dry-run the redemption (eth_call / estimateGas) BEFORE the nonce is burned, so a
72
+ * reverting or griefing settlement is rejected without consuming the one-shot mandate. Injected by
73
+ * the app; omit to skip simulation. Returns ok + optional gas estimate. */
74
+ simulate?: (plan: {
75
+ to: Address;
76
+ value: bigint;
77
+ data: Hex;
78
+ }) => Promise<{
79
+ ok: boolean;
80
+ reason?: string;
81
+ gas?: bigint;
82
+ }>;
83
+ /** Anti-griefing: reject a settlement whose simulated gas exceeds this cap. */
84
+ maxGasPerSettlement?: bigint;
85
+ /** Anti-griefing: abort `submitRedemption` if it doesn't resolve within this many ms (settlement timeout). */
86
+ settlementTimeoutMs?: number;
87
+ now?: () => number;
88
+ }
89
+ export type SettleResult = {
90
+ ok: true;
91
+ settlementHash: Hex32;
92
+ mandateId: Hex32;
93
+ idempotent: boolean;
94
+ } | {
95
+ ok: false;
96
+ reason: string;
97
+ };
98
+ /** The staged x402 rail. `settle` runs verify → revoke → reserve(nullifier) → simulate → submit →
99
+ * receipt; a safe retry of an already-settled request returns the original receipt (idempotent). */
100
+ export declare function createX402Rail(deps: X402RailDeps): {
101
+ rail: "x402";
102
+ verifyMandate: typeof verifyMandate;
103
+ settle: (input: {
104
+ mandate: PaymentMandate;
105
+ delegation: Delegation;
106
+ quote: PaymentQuote;
107
+ }) => Promise<SettleResult>;
108
+ };
109
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0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E,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GAC1E;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AASlC;qGACqG;AACrG,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY;;;oBAGlB;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,UAAU,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,YAAY,CAAA;KAAE,KAAG,OAAO,CAAC,YAAY,CAAC;EAiE9H"}
@@ -0,0 +1,222 @@
1
+ // Spec 272 PAY-RAIL-1..6 — the staged x402 rail executor (verify → revoke-check → reserve → prepare →
2
+ // submit → receipt). Delegation-native settlement (X402-D2): the redemption is
3
+ // DelegationManager.redeemDelegation(paymentDelegation, USDC.transfer(treasury, amount)) gated by the
4
+ // on-chain PaymentEnforcer. This package owns the LOGIC; on-chain submission (a sponsored UserOp,
5
+ // X402-D4) + the revocation read are INJECTED (payments is type-only on delegation, forbids agent-account).
6
+ import { encodeAbiParameters, encodeFunctionData, keccak256, toHex } from 'viem';
7
+ import { assertContextBindingValid, assertClosedMandateInvariants } from '../../index.js';
8
+ import { fromCaip2 } from './quote.js';
9
+ const TRANSFER_ABI = [
10
+ {
11
+ type: 'function',
12
+ name: 'transfer',
13
+ stateMutability: 'nonpayable',
14
+ inputs: [
15
+ { name: 'to', type: 'address' },
16
+ { name: 'amount', type: 'uint256' },
17
+ ],
18
+ outputs: [{ type: 'bool' }],
19
+ },
20
+ ];
21
+ const DELEGATION_TUPLE = {
22
+ name: 'delegations',
23
+ type: 'tuple[]',
24
+ components: [
25
+ { name: 'delegator', type: 'address' },
26
+ { name: 'delegate', type: 'address' },
27
+ { name: 'authority', type: 'bytes32' },
28
+ {
29
+ name: 'caveats',
30
+ type: 'tuple[]',
31
+ components: [
32
+ { name: 'enforcer', type: 'address' },
33
+ { name: 'terms', type: 'bytes' },
34
+ { name: 'args', type: 'bytes' },
35
+ ],
36
+ },
37
+ { name: 'salt', type: 'uint256' },
38
+ { name: 'signature', type: 'bytes' },
39
+ ],
40
+ };
41
+ const REDEEM_ABI = [
42
+ {
43
+ type: 'function',
44
+ name: 'redeemDelegation',
45
+ stateMutability: 'nonpayable',
46
+ inputs: [
47
+ DELEGATION_TUPLE,
48
+ { name: 'target', type: 'address' },
49
+ { name: 'value', type: 'uint256' },
50
+ { name: 'data', type: 'bytes' },
51
+ ],
52
+ outputs: [],
53
+ },
54
+ ];
55
+ /** PAY-RAIL-4 — the rail-scoped replay nullifier. */
56
+ export function computeNullifier(args) {
57
+ return keccak256(encodeAbiParameters([
58
+ { type: 'string' },
59
+ { type: 'uint256' },
60
+ { type: 'address' },
61
+ { type: 'address' },
62
+ { type: 'address' },
63
+ { type: 'bytes32' },
64
+ { type: 'uint256' },
65
+ { type: 'bytes32' },
66
+ ], [args.rail, BigInt(args.chainId), args.payer, args.payee, args.asset, args.mandateId, args.nonce, args.resourceHash]));
67
+ }
68
+ /**
69
+ * PAY-RAIL-1 — synchronous mandate verification against its persisted quote. Returns the first failure
70
+ * reason (or null). The async checks (revocation, nonce-unused) run in the rail's settle() flow.
71
+ */
72
+ export function verifyMandate(mandate, quote, opts) {
73
+ try {
74
+ assertContextBindingValid(mandate.contextBinding);
75
+ assertClosedMandateInvariants(mandate);
76
+ }
77
+ catch (e) {
78
+ return { valid: false, reason: e instanceof Error ? e.message : 'invariant' };
79
+ }
80
+ if (mandate.mode !== 'closed')
81
+ return { valid: false, reason: 'final charge requires a closed mandate' };
82
+ if (mandate.maxRedemptions !== 1)
83
+ return { valid: false, reason: 'closed mandate must be one-shot' };
84
+ if (mandate.rail !== 'x402')
85
+ return { valid: false, reason: `wrong rail ${mandate.rail}` };
86
+ const rc = mandate.railConfig;
87
+ if (!rc?.quoteId || rc.quoteId !== quote.quoteId)
88
+ return { valid: false, reason: 'quote mismatch (quoteId)' };
89
+ if (rc.resourceHash !== quote.resourceHash)
90
+ return { valid: false, reason: 'quote mismatch (resourceHash)' };
91
+ if (mandate.payee.toLowerCase() !== quote.payTo.toLowerCase())
92
+ return { valid: false, reason: 'payee != treasury' };
93
+ if (mandate.amountPolicy.kind !== 'exact')
94
+ return { valid: false, reason: 'flat per-call requires exact amountPolicy' };
95
+ if (mandate.amountPolicy.amount !== quote.amount)
96
+ return { valid: false, reason: 'amount mismatch' };
97
+ if (mandate.amountPolicy.asset.id.toLowerCase() !== quote.asset.toLowerCase())
98
+ return { valid: false, reason: 'asset mismatch' };
99
+ if (mandate.amountPolicy.chain !== fromCaip2(quote.network))
100
+ return { valid: false, reason: 'chain mismatch' };
101
+ if (mandate.nonce !== quote.nonce)
102
+ return { valid: false, reason: 'nonce mismatch' };
103
+ if (mandate.expiresAt <= opts.now)
104
+ return { valid: false, reason: 'mandate expired' };
105
+ if (mandate.validFrom > opts.now)
106
+ return { valid: false, reason: 'mandate not yet valid' };
107
+ return { valid: true };
108
+ }
109
+ /**
110
+ * PAY-RAIL-2 — build the redemption plan: DelegationManager.redeemDelegation(paymentDelegation,
111
+ * USDC.transfer(treasury, amount)) with the PaymentEnforcer caveat's `args` filled with the mandate's
112
+ * (mandateId, nonce, resourceHash) at REDEMPTION time. The caller submits `{to, value, data}` from the
113
+ * service relayer as a sponsored UserOp.
114
+ */
115
+ export function buildRedemptionCalldata(args) {
116
+ const amount = args.mandate.amountPolicy.amount;
117
+ const transferData = encodeFunctionData({
118
+ abi: TRANSFER_ABI,
119
+ functionName: 'transfer',
120
+ args: [args.mandate.payee, amount],
121
+ });
122
+ // Fill the PaymentEnforcer caveat's redeem-time args = abi.encode(mandateId, nonce, resourceHash).
123
+ const enforcerArgs = encodeAbiParameters([{ type: 'bytes32' }, { type: 'bytes32' }, { type: 'bytes32' }], [args.mandate.mandateId, toHex(args.mandate.nonce, { size: 32 }), args.resourceHash]);
124
+ const pe = args.paymentEnforcer.toLowerCase();
125
+ const caveats = args.delegation.caveats.map((c) => c.enforcer.toLowerCase() === pe
126
+ ? { enforcer: c.enforcer, terms: c.terms, args: enforcerArgs }
127
+ : { enforcer: c.enforcer, terms: c.terms, args: c.args ?? '0x' });
128
+ const data = encodeFunctionData({
129
+ abi: REDEEM_ABI,
130
+ functionName: 'redeemDelegation',
131
+ args: [
132
+ [
133
+ {
134
+ delegator: args.delegation.delegator,
135
+ delegate: args.delegation.delegate,
136
+ authority: args.delegation.authority,
137
+ caveats,
138
+ salt: args.delegation.salt,
139
+ signature: args.delegation.signature,
140
+ },
141
+ ],
142
+ args.asset,
143
+ 0n,
144
+ transferData,
145
+ ],
146
+ });
147
+ return { to: args.delegationManager, value: 0n, data };
148
+ }
149
+ function withTimeout(p, ms) {
150
+ return new Promise((resolve, reject) => {
151
+ const t = setTimeout(() => reject(new Error(`settlement timed out after ${ms}ms`)), ms);
152
+ p.then((v) => { clearTimeout(t); resolve(v); }, (e) => { clearTimeout(t); reject(e); });
153
+ });
154
+ }
155
+ /** The staged x402 rail. `settle` runs verify → revoke → reserve(nullifier) → simulate → submit →
156
+ * receipt; a safe retry of an already-settled request returns the original receipt (idempotent). */
157
+ export function createX402Rail(deps) {
158
+ const now = deps.now ?? (() => Math.floor(Date.now() / 1000));
159
+ async function settle(input) {
160
+ const { mandate, delegation, quote } = input;
161
+ const v = verifyMandate(mandate, quote, { now: now() });
162
+ if (!v.valid)
163
+ return { ok: false, reason: v.reason };
164
+ const delegationHash = mandate.delegationRef;
165
+ if (delegationHash && (await deps.isRevoked(delegationHash)))
166
+ return { ok: false, reason: 'payment delegation revoked' };
167
+ const nullifier = computeNullifier({
168
+ rail: 'x402',
169
+ chainId: deps.chainId,
170
+ payer: mandate.payer,
171
+ payee: mandate.payee,
172
+ asset: deps.asset,
173
+ mandateId: mandate.mandateId,
174
+ nonce: mandate.nonce,
175
+ resourceHash: quote.resourceHash,
176
+ });
177
+ const reserved = await deps.nonceStore.reserve(nullifier);
178
+ if (!reserved.ok) {
179
+ if (reserved.state === 'settled' && reserved.receipt) {
180
+ return { ok: true, settlementHash: reserved.receipt.settlementHash, mandateId: reserved.receipt.mandateId, idempotent: true };
181
+ }
182
+ return { ok: false, reason: `duplicate settlement (${reserved.state})` };
183
+ }
184
+ const plan = buildRedemptionCalldata({
185
+ mandate,
186
+ delegation,
187
+ delegationManager: deps.delegationManager,
188
+ paymentEnforcer: deps.paymentEnforcer,
189
+ asset: deps.asset,
190
+ resourceHash: quote.resourceHash,
191
+ });
192
+ // PAY-RAIL-6 — simulate before burning the nonce: a reverting or over-gas settlement is
193
+ // rejected as RETRYABLE so the one-shot mandate survives for a corrected resubmit.
194
+ if (deps.simulate) {
195
+ const sim = await deps.simulate(plan);
196
+ if (!sim.ok) {
197
+ await deps.nonceStore.markFailed(nullifier, true);
198
+ return { ok: false, reason: `simulation reverted${sim.reason ? `: ${sim.reason}` : ''}` };
199
+ }
200
+ if (deps.maxGasPerSettlement !== undefined && sim.gas !== undefined && sim.gas > deps.maxGasPerSettlement) {
201
+ await deps.nonceStore.markFailed(nullifier, true);
202
+ return { ok: false, reason: `settlement gas ${sim.gas} exceeds cap ${deps.maxGasPerSettlement}` };
203
+ }
204
+ }
205
+ await deps.nonceStore.markSettling(nullifier);
206
+ try {
207
+ const submit = deps.submitRedemption(plan);
208
+ const { settlementHash } = deps.settlementTimeoutMs
209
+ ? await withTimeout(submit, deps.settlementTimeoutMs)
210
+ : await submit;
211
+ const receipt = { settlementHash, mandateId: mandate.mandateId };
212
+ await deps.nonceStore.markSettled(nullifier, receipt);
213
+ return { ok: true, settlementHash, mandateId: mandate.mandateId, idempotent: false };
214
+ }
215
+ catch (e) {
216
+ await deps.nonceStore.markFailed(nullifier, true);
217
+ return { ok: false, reason: e instanceof Error ? e.message : 'settlement failed' };
218
+ }
219
+ }
220
+ return { rail: 'x402', verifyMandate, settle };
221
+ }
222
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../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AM,MAAM,CAAC;YACjB,MAAM,OAAO,GAAmB,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;YACjF,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACtD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;QACvF,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAClD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC;QACrF,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAe,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,11 @@
1
+ export type { PaymentResource, Hex32 } from './resource.js';
2
+ export { ZERO_HASH, canonicalizePaymentResource, hashRequestBody, redactPaymentMetadata } from './resource.js';
3
+ export type { PaymentQuote } from './quote.js';
4
+ export { computeQuoteId, buildPaymentQuote, quoteMismatch, toCaip2, fromCaip2 } from './quote.js';
5
+ export type { PaymentRequirements, PaymentRequiredBody, SettlementResponse, PaymentSignaturePayload } from './wire.js';
6
+ export { X402_VERSION, HEADER_PAYMENT_REQUIRED, HEADER_PAYMENT_SIGNATURE, HEADER_PAYMENT_RESPONSE, ASSET_TRANSFER_METHOD, buildPaymentRequired, parsePaymentRequired, buildPaymentSignature, parsePaymentSignature, buildPaymentResponse, parsePaymentResponse, serializeMandate, deserializeMandate, } from './wire.js';
7
+ export type { NonceReservationStore, NonceState, SettledReceipt, ReserveResult } from './nonce-store.js';
8
+ export { createMemoryNonceStore } from './nonce-store.js';
9
+ export type { X402RailConfig, X402RailDeps, SettleResult } from './executor.js';
10
+ export { computeNullifier, verifyMandate, buildRedemptionCalldata, createX402Rail } from './executor.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rails/x402/index.ts"],"names":[],"mappings":"AAGA,YAAY,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,2BAA2B,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE/G,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAElG,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACvH,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAEnB,YAAY,EAAE,qBAAqB,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACzG,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,8 @@
1
+ // @agenticprimitives/payments — x402 rail (spec 272). HTTP-native pay-per-use over the spec-243
2
+ // PaymentMandate. Consumed as `import { x402 } from '@agenticprimitives/payments'`.
3
+ export { ZERO_HASH, canonicalizePaymentResource, hashRequestBody, redactPaymentMetadata } from './resource.js';
4
+ export { computeQuoteId, buildPaymentQuote, quoteMismatch, toCaip2, fromCaip2 } from './quote.js';
5
+ export { X402_VERSION, HEADER_PAYMENT_REQUIRED, HEADER_PAYMENT_SIGNATURE, HEADER_PAYMENT_RESPONSE, ASSET_TRANSFER_METHOD, buildPaymentRequired, parsePaymentRequired, buildPaymentSignature, parsePaymentSignature, buildPaymentResponse, parsePaymentResponse, serializeMandate, deserializeMandate, } from './wire.js';
6
+ export { createMemoryNonceStore } from './nonce-store.js';
7
+ export { computeNullifier, verifyMandate, buildRedemptionCalldata, createX402Rail } from './executor.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rails/x402/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,oFAAoF;AAGpF,OAAO,EAAE,SAAS,EAAE,2BAA2B,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG/G,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGlG,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { Hex32 } from './resource.js';
2
+ export type NonceState = 'unseen' | 'reserved' | 'settling' | 'settled' | 'failed_retryable' | 'failed_terminal';
3
+ export interface SettledReceipt {
4
+ settlementHash: Hex32;
5
+ mandateId: Hex32;
6
+ }
7
+ export type ReserveResult = {
8
+ ok: true;
9
+ } | {
10
+ ok: false;
11
+ state: Exclude<NonceState, 'unseen'>;
12
+ receipt?: SettledReceipt;
13
+ };
14
+ export interface NonceReservationStore {
15
+ /** Atomically claim the nullifier. `unseen`/`failed_retryable` → reserved (ok). `settled` → not-ok
16
+ * WITH the original receipt (safe-retry returns it). `reserved`/`settling`/`failed_terminal` →
17
+ * not-ok (concurrent duplicate / permanently failed). */
18
+ reserve(nullifier: Hex32): Promise<ReserveResult>;
19
+ markSettling(nullifier: Hex32): Promise<void>;
20
+ markSettled(nullifier: Hex32, receipt: SettledReceipt): Promise<void>;
21
+ markFailed(nullifier: Hex32, retryable: boolean): Promise<void>;
22
+ get(nullifier: Hex32): Promise<{
23
+ state: NonceState;
24
+ receipt?: SettledReceipt;
25
+ } | undefined>;
26
+ }
27
+ /** In-memory store (single-worker / tests). A durable adapter (KV / D1) implements the same interface;
28
+ * the reserve() must be ATOMIC there (compare-and-set) to actually block concurrent duplicates. */
29
+ export declare function createMemoryNonceStore(): NonceReservationStore;
30
+ //# sourceMappingURL=nonce-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nonce-store.d.ts","sourceRoot":"","sources":["../../../src/rails/x402/nonce-store.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;AAEjH,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,KAAK,CAAC;IACtB,SAAS,EAAE,KAAK,CAAC;CAClB;AAED,MAAM,MAAM,aAAa,GACrB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,CAAC;AAElF,MAAM,WAAW,qBAAqB;IACpC;;8DAE0D;IAC1D,OAAO,CAAC,SAAS,EAAE,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAClD,YAAY,CAAC,SAAS,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,WAAW,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,UAAU,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,GAAG,CAAC,SAAS,EAAE,KAAK,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,UAAU,CAAC;QAAC,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;CAC7F;AAOD;oGACoG;AACpG,wBAAgB,sBAAsB,IAAI,qBAAqB,CA0B9D"}
@@ -0,0 +1,35 @@
1
+ // Spec 272 PAY-RAIL-4/5 — the off-chain nullifier reservation store. A redeemed mandate/nonce cannot
2
+ // settle twice (the on-chain nonce is the durable guard; this blocks concurrent duplicates + caches the
3
+ // original receipt for safe retries). State machine: unseen → reserved → settling → settled |
4
+ // failed_retryable | failed_terminal.
5
+ /** In-memory store (single-worker / tests). A durable adapter (KV / D1) implements the same interface;
6
+ * the reserve() must be ATOMIC there (compare-and-set) to actually block concurrent duplicates. */
7
+ export function createMemoryNonceStore() {
8
+ const rows = new Map();
9
+ return {
10
+ async reserve(nullifier) {
11
+ const row = rows.get(nullifier);
12
+ if (!row || row.state === 'unseen' || row.state === 'failed_retryable') {
13
+ rows.set(nullifier, { state: 'reserved' });
14
+ return { ok: true };
15
+ }
16
+ if (row.state === 'settled')
17
+ return { ok: false, state: 'settled', receipt: row.receipt };
18
+ return { ok: false, state: row.state };
19
+ },
20
+ async markSettling(nullifier) {
21
+ const row = rows.get(nullifier) ?? { state: 'unseen' };
22
+ rows.set(nullifier, { ...row, state: 'settling' });
23
+ },
24
+ async markSettled(nullifier, receipt) {
25
+ rows.set(nullifier, { state: 'settled', receipt });
26
+ },
27
+ async markFailed(nullifier, retryable) {
28
+ rows.set(nullifier, { state: retryable ? 'failed_retryable' : 'failed_terminal' });
29
+ },
30
+ async get(nullifier) {
31
+ return rows.get(nullifier);
32
+ },
33
+ };
34
+ }
35
+ //# sourceMappingURL=nonce-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nonce-store.js","sourceRoot":"","sources":["../../../src/rails/x402/nonce-store.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,wGAAwG;AACxG,8FAA8F;AAC9F,sCAAsC;AA+BtC;oGACoG;AACpG,MAAM,UAAU,sBAAsB;IACpC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAe,CAAC;IACpC,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,SAAS;YACrB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAChC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,KAAK,KAAK,kBAAkB,EAAE,CAAC;gBACvE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;gBAC3C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;YACtB,CAAC;YACD,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;YAC1F,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;QACzC,CAAC;QACD,KAAK,CAAC,YAAY,CAAC,SAAS;YAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;YACvD,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO;YAClC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS;YACnC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC;QACrF,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,SAAS;YACjB,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { type Address } from 'viem';
2
+ import type { Hex32, PaymentResource } from './resource.js';
3
+ /** A priced, bound, expiring offer for one access. `quoteId` is derived from the binding so two quotes
4
+ * for the same request+price are identical and a tampered field changes the id (tamper-evident). */
5
+ export interface PaymentQuote {
6
+ quoteId: Hex32;
7
+ scheme: 'exact';
8
+ network: string;
9
+ asset: Address;
10
+ payTo: Address;
11
+ amount: bigint;
12
+ resource: PaymentResource;
13
+ resourceHash: Hex32;
14
+ nonce: bigint;
15
+ expiresAt: number;
16
+ maxTimeoutSeconds: number;
17
+ }
18
+ /** Deterministic quote id over the binding + price + payee + nonce + expiry. Same inputs → same id;
19
+ * any change (amount, payee, resource field, nonce, expiry) → different id (X402-D9 quote immutability). */
20
+ export declare function computeQuoteId(args: {
21
+ resourceHash: Hex32;
22
+ asset: Address;
23
+ payTo: Address;
24
+ amount: bigint;
25
+ network: string;
26
+ nonce: bigint;
27
+ expiresAt: number;
28
+ }): Hex32;
29
+ /** Build a fully-formed, self-consistent PaymentQuote from a resource + price. */
30
+ export declare function buildPaymentQuote(args: {
31
+ resource: PaymentResource;
32
+ network: string;
33
+ maxTimeoutSeconds?: number;
34
+ }): PaymentQuote;
35
+ /** X402-D9 quote immutability: a re-presented quote MUST match the persisted one on every field that
36
+ * prices or binds the charge. Returns the first mismatch (for telemetry) or null when identical. */
37
+ export declare function quoteMismatch(persisted: PaymentQuote, presented: PaymentQuote): string | null;
38
+ /** CAIP-2 helpers (X402-D6 — wire uses `eip155:<id>`, never a bare chain number). */
39
+ export declare function toCaip2(chainId: number): string;
40
+ export declare function fromCaip2(network: string): number;
41
+ //# sourceMappingURL=quote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote.d.ts","sourceRoot":"","sources":["../../../src/rails/x402/quote.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkC,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG5D;qGACqG;AACrG,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,eAAe,CAAC;IAC1B,YAAY,EAAE,KAAK,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;6GAC6G;AAC7G,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,YAAY,EAAE,KAAK,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,KAAK,CAuBR;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACtC,QAAQ,EAAE,eAAe,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GAAG,YAAY,CAyBf;AAED;qGACqG;AACrG,wBAAgB,aAAa,CAAC,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAU7F;AAED,qFAAqF;AACrF,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/C;AACD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIjD"}
@@ -0,0 +1,84 @@
1
+ // Spec 272 X402-D9.2 — the immutable PaymentQuote. The 402 carries it; the service persists
2
+ // (taskId → quoteId → resourceHash → amount → payee) and a retry MUST match it. No silent re-pricing.
3
+ import { encodeAbiParameters, keccak256 } from 'viem';
4
+ import { canonicalizePaymentResource } from './resource.js';
5
+ /** Deterministic quote id over the binding + price + payee + nonce + expiry. Same inputs → same id;
6
+ * any change (amount, payee, resource field, nonce, expiry) → different id (X402-D9 quote immutability). */
7
+ export function computeQuoteId(args) {
8
+ return keccak256(encodeAbiParameters([
9
+ { type: 'bytes32' },
10
+ { type: 'address' },
11
+ { type: 'address' },
12
+ { type: 'uint256' },
13
+ { type: 'string' },
14
+ { type: 'uint256' },
15
+ { type: 'uint256' },
16
+ ], [
17
+ args.resourceHash,
18
+ args.asset,
19
+ args.payTo,
20
+ args.amount,
21
+ args.network,
22
+ args.nonce,
23
+ BigInt(args.expiresAt),
24
+ ]));
25
+ }
26
+ /** Build a fully-formed, self-consistent PaymentQuote from a resource + price. */
27
+ export function buildPaymentQuote(args) {
28
+ const { resource } = args;
29
+ const resourceHash = canonicalizePaymentResource(resource);
30
+ const quoteId = computeQuoteId({
31
+ resourceHash,
32
+ asset: resource.asset,
33
+ payTo: resource.treasury,
34
+ amount: resource.amount,
35
+ network: args.network,
36
+ nonce: resource.nonce,
37
+ expiresAt: resource.expiresAt,
38
+ });
39
+ return {
40
+ quoteId,
41
+ scheme: 'exact',
42
+ network: args.network,
43
+ asset: resource.asset,
44
+ payTo: resource.treasury,
45
+ amount: resource.amount,
46
+ resource,
47
+ resourceHash,
48
+ nonce: resource.nonce,
49
+ expiresAt: resource.expiresAt,
50
+ maxTimeoutSeconds: args.maxTimeoutSeconds ?? 300,
51
+ };
52
+ }
53
+ /** X402-D9 quote immutability: a re-presented quote MUST match the persisted one on every field that
54
+ * prices or binds the charge. Returns the first mismatch (for telemetry) or null when identical. */
55
+ export function quoteMismatch(persisted, presented) {
56
+ if (persisted.quoteId !== presented.quoteId)
57
+ return 'quoteId';
58
+ if (persisted.resourceHash !== presented.resourceHash)
59
+ return 'resourceHash';
60
+ if (persisted.amount !== presented.amount)
61
+ return 'amount';
62
+ if (persisted.payTo.toLowerCase() !== presented.payTo.toLowerCase())
63
+ return 'payTo';
64
+ if (persisted.asset.toLowerCase() !== presented.asset.toLowerCase())
65
+ return 'asset';
66
+ if (persisted.network !== presented.network)
67
+ return 'network';
68
+ if (persisted.nonce !== presented.nonce)
69
+ return 'nonce';
70
+ if (persisted.expiresAt !== presented.expiresAt)
71
+ return 'expiresAt';
72
+ return null;
73
+ }
74
+ /** CAIP-2 helpers (X402-D6 — wire uses `eip155:<id>`, never a bare chain number). */
75
+ export function toCaip2(chainId) {
76
+ return `eip155:${chainId}`;
77
+ }
78
+ export function fromCaip2(network) {
79
+ const m = /^eip155:(\d+)$/.exec(network);
80
+ if (!m)
81
+ throw new Error(`[x402] unsupported network "${network}" (expected eip155:<chainId>)`);
82
+ return Number(m[1]);
83
+ }
84
+ //# sourceMappingURL=quote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/rails/x402/quote.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,sGAAsG;AAEtG,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAgB,MAAM,MAAM,CAAC;AAEpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAkB5D;6GAC6G;AAC7G,MAAM,UAAU,cAAc,CAAC,IAQ9B;IACC,OAAO,SAAS,CACd,mBAAmB,CACjB;QACE,EAAE,IAAI,EAAE,SAAS,EAAE;QACnB,EAAE,IAAI,EAAE,SAAS,EAAE;QACnB,EAAE,IAAI,EAAE,SAAS,EAAE;QACnB,EAAE,IAAI,EAAE,SAAS,EAAE;QACnB,EAAE,IAAI,EAAE,QAAQ,EAAE;QAClB,EAAE,IAAI,EAAE,SAAS,EAAE;QACnB,EAAE,IAAI,EAAE,SAAS,EAAE;KACpB,EACD;QACE,IAAI,CAAC,YAAY;QACjB,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,KAAK;QACV,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;KACvB,CACF,CACF,CAAC;AACJ,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,iBAAiB,CAAC,IAIjC;IACC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC1B,MAAM,YAAY,GAAG,2BAA2B,CAAC,QAAQ,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,cAAc,CAAC;QAC7B,YAAY;QACZ,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,KAAK,EAAE,QAAQ,CAAC,QAAQ;QACxB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAA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;QAAE,OAAO,WAAW,CAAC;IACpE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,OAAO,CAAC,OAAe;IACrC,OAAO,UAAU,OAAO,EAAE,CAAC;AAC7B,CAAC;AACD,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,MAAM,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,OAAO,+BAA+B,CAAC,CAAC;IAC/F,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { type Address } from 'viem';
2
+ export type Hex32 = `0x${string}`;
3
+ export declare const ZERO_HASH: Hex32;
4
+ /** The full set of fields a payment is bound to. Hashing ALL of them (not just amount) closes
5
+ * substitution/replay: a mandate signed for one (method,url,body,skill,treasury,asset,amount,chain,
6
+ * expiry,nonce) cannot be replayed against a different request. */
7
+ export interface PaymentResource {
8
+ protocol: 'http' | 'a2a';
9
+ method: string;
10
+ url: string;
11
+ bodyHash: Hex32;
12
+ serviceAgent: Address;
13
+ treasury: Address;
14
+ skillId: string;
15
+ taskId: Hex32;
16
+ asset: Address;
17
+ amount: bigint;
18
+ chainId: number;
19
+ expiresAt: number;
20
+ nonce: bigint;
21
+ }
22
+ /** keccak256 over an ABI-encoded canonical tuple of every binding field. Deterministic across HTTP +
23
+ * A2A. NOTE: `quoteId` is NOT an input here (it's derived FROM this hash — see quote.ts) to avoid a
24
+ * circular dependency. */
25
+ export declare function canonicalizePaymentResource(r: PaymentResource): Hex32;
26
+ /** keccak256 of a request body (or ZERO_HASH for empty). The ONLY way bodies enter a binding. */
27
+ export declare function hashRequestBody(body: Uint8Array | string | undefined): Hex32;
28
+ /**
29
+ * PAY-WIRE-6 — strip everything that must never leave the trust boundary in payment metadata (402
30
+ * bodies, receipts, on-chain events, accepts[] extras): licensed text, user queries, PII, full
31
+ * sensitive URLs. Returns a safe projection: the path WITHOUT query string + a hash of the full URL.
32
+ * A platform-level guarantee, not per-app discipline.
33
+ */
34
+ export declare function redactPaymentMetadata(input: {
35
+ url?: string;
36
+ description?: string;
37
+ }): {
38
+ safeRoute: string;
39
+ urlHash: Hex32;
40
+ description?: string;
41
+ };
42
+ //# sourceMappingURL=resource.d.ts.map