@agenticprimitives/payments 0.0.0-alpha.4 → 0.0.0-alpha.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/entitlement/index.d.ts +125 -0
- package/dist/entitlement/index.d.ts.map +1 -0
- package/dist/entitlement/index.js +128 -0
- package/dist/entitlement/index.js.map +1 -0
- package/dist/entitlement/voucher.d.ts +85 -0
- package/dist/entitlement/voucher.d.ts.map +1 -0
- package/dist/entitlement/voucher.js +109 -0
- package/dist/entitlement/voucher.js.map +1 -0
- package/dist/external-checkout.d.ts +40 -0
- package/dist/external-checkout.d.ts.map +1 -0
- package/dist/external-checkout.js +70 -0
- package/dist/external-checkout.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/dist/mandate-sign.d.ts +190 -0
- package/dist/mandate-sign.d.ts.map +1 -0
- package/dist/mandate-sign.js +202 -0
- package/dist/mandate-sign.js.map +1 -0
- package/dist/mandate.d.ts +34 -0
- package/dist/mandate.d.ts.map +1 -0
- package/dist/mandate.js +40 -0
- package/dist/mandate.js.map +1 -0
- package/dist/ops.d.ts +55 -0
- package/dist/ops.d.ts.map +1 -0
- package/dist/ops.js +66 -0
- package/dist/ops.js.map +1 -0
- package/dist/rails/escrow.d.ts +156 -0
- package/dist/rails/escrow.d.ts.map +1 -0
- package/dist/rails/escrow.js +88 -0
- package/dist/rails/escrow.js.map +1 -0
- package/dist/rails/invoice.d.ts +65 -0
- package/dist/rails/invoice.d.ts.map +1 -0
- package/dist/rails/invoice.js +57 -0
- package/dist/rails/invoice.js.map +1 -0
- package/dist/rails/recurring.d.ts +56 -0
- package/dist/rails/recurring.d.ts.map +1 -0
- package/dist/rails/recurring.js +58 -0
- package/dist/rails/recurring.js.map +1 -0
- package/dist/rails/wallet.d.ts +16 -0
- package/dist/rails/wallet.d.ts.map +1 -0
- package/dist/rails/wallet.js +20 -0
- package/dist/rails/wallet.js.map +1 -0
- package/dist/rails/x402/executor.d.ts +26 -1
- package/dist/rails/x402/executor.d.ts.map +1 -1
- package/dist/rails/x402/executor.js +45 -2
- package/dist/rails/x402/executor.js.map +1 -1
- package/dist/receipt.d.ts +36 -0
- package/dist/receipt.d.ts.map +1 -0
- package/dist/receipt.js +50 -0
- package/dist/receipt.js.map +1 -0
- package/dist/refund.d.ts +29 -0
- package/dist/refund.d.ts.map +1 -0
- package/dist/refund.js +19 -0
- package/dist/refund.js.map +1 -0
- package/dist/split.d.ts +27 -0
- package/dist/split.d.ts.map +1 -0
- package/dist/split.js +33 -0
- package/dist/split.js.map +1 -0
- package/dist/transfer.d.ts +51 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.js +54 -0
- package/dist/transfer.js.map +1 -0
- package/package.json +21 -11
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,5 +114,24 @@ 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';
|
|
112
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 { validateExternalPaymentCredentialRef, validateAp2MandateEnvelopeRef, paymentCredentialCovers, looksLikeRawPaymentCredential, type ExternalPaymentCredentialRefV1, type Ap2MandateEnvelopeRefV1, type Ap2MandateKind, } from './external-checkout.js';
|
|
127
|
+
export type { ClosedMandateInput } from './mandate.js';
|
|
128
|
+
export * as wallet from './rails/wallet.js';
|
|
129
|
+
export * as invoice from './rails/invoice.js';
|
|
130
|
+
export * as escrow from './rails/escrow.js';
|
|
131
|
+
export * as recurring from './rails/recurring.js';
|
|
132
|
+
export { buildRefund } from './refund.js';
|
|
133
|
+
export type { RefundInput, RefundPlan } from './refund.js';
|
|
134
|
+
export { buildSplitPayout, BPS_DENOMINATOR } from './split.js';
|
|
135
|
+
export type { SplitRecipient, SplitLeg } from './split.js';
|
|
136
|
+
export * as ops from './ops.js';
|
|
113
137
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAA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AwB,CAAC;AAChC,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,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,6 +37,27 @@ 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';
|
|
40
44
|
// Spec 272 — the x402 rail (staged executor + v2 wire + nonce store + resource binding).
|
|
41
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 442 §10 — payments at the company's door, TYPES ONLY: a payment credential by reference (the ExecutionCredential
|
|
52
|
+
// discipline: bound to one operation, expiring, single-use) and our mandate in AP2's VC-JWS envelope. Fiat rails are Ring 1.
|
|
53
|
+
export { validateExternalPaymentCredentialRef, validateAp2MandateEnvelopeRef, paymentCredentialCovers, looksLikeRawPaymentCredential, } from './external-checkout.js';
|
|
54
|
+
// Spec 243 §5.5 — general-purpose rails + profiles + payout legs.
|
|
55
|
+
export * as wallet from './rails/wallet.js';
|
|
56
|
+
export * as invoice from './rails/invoice.js';
|
|
57
|
+
export * as escrow from './rails/escrow.js';
|
|
58
|
+
export * as recurring from './rails/recurring.js';
|
|
59
|
+
export { buildRefund } from './refund.js';
|
|
60
|
+
export { buildSplitPayout, BPS_DENOMINATOR } from './split.js';
|
|
61
|
+
// Spec 243 §5.5 — ops core (idempotent event log + reconciliation + export).
|
|
62
|
+
export * as ops from './ops.js';
|
|
42
63
|
//# 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;
|
|
1
|
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AC9C,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG/D,6EAA6E;AAC7E,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/** ERC-1271 magic value. Re-exported under this package's established name (the protocol constant
|
|
2
|
+
* itself lives in \ — it was declared in eight places, and \ could not reach
|
|
3
|
+
* \ for it without creating a cycle). */
|
|
4
|
+
export declare const ERC1271_MAGIC: "0x1626ba7e";
|
|
5
|
+
/**
|
|
6
|
+
* PMT-INV-02 / PMT-INV-12 — EIP-712 mandate signing + ERC-1271 verification.
|
|
7
|
+
*
|
|
8
|
+
* The payer SA signs an EIP-712 typed-data digest of the mandate. The signed
|
|
9
|
+
* struct flattens the load-bearing fields and folds the entire `ContextBinding`
|
|
10
|
+
* into one `contextBindingHash` — so no field can be stripped or substituted
|
|
11
|
+
* after signing (PMT-INV-02 / INV-07 / INV-08), and verification is one
|
|
12
|
+
* ERC-1271 call against the payer SA (PMT-INV-12 — no raw EOA signatures).
|
|
13
|
+
*
|
|
14
|
+
* Pure crypto only (viem) — the actual ERC-1271 read is injected so the package
|
|
15
|
+
* stays transport-agnostic (no hard publicClient dependency).
|
|
16
|
+
*/
|
|
17
|
+
import { type Address, type Hex } from 'viem';
|
|
18
|
+
import type { PaymentMandate, ContextBinding, Hex32 } from './index.js';
|
|
19
|
+
export declare const PAYMENT_MANDATE_DOMAIN_NAME = "AgenticPaymentMandate";
|
|
20
|
+
export declare const PAYMENT_MANDATE_DOMAIN_VERSION = "1";
|
|
21
|
+
/** ERC-1271 magic value for a valid signature. */
|
|
22
|
+
export declare const PAYMENT_MANDATE_EIP712_TYPES: {
|
|
23
|
+
readonly PaymentMandate: readonly [{
|
|
24
|
+
readonly name: "mandateId";
|
|
25
|
+
readonly type: "bytes32";
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "payer";
|
|
28
|
+
readonly type: "address";
|
|
29
|
+
}, {
|
|
30
|
+
readonly name: "payee";
|
|
31
|
+
readonly type: "address";
|
|
32
|
+
}, {
|
|
33
|
+
readonly name: "granter";
|
|
34
|
+
readonly type: "address";
|
|
35
|
+
}, {
|
|
36
|
+
readonly name: "asset";
|
|
37
|
+
readonly type: "address";
|
|
38
|
+
}, {
|
|
39
|
+
readonly name: "amount";
|
|
40
|
+
readonly type: "uint256";
|
|
41
|
+
}, {
|
|
42
|
+
readonly name: "nonce";
|
|
43
|
+
readonly type: "uint256";
|
|
44
|
+
}, {
|
|
45
|
+
readonly name: "maxRedemptions";
|
|
46
|
+
readonly type: "uint256";
|
|
47
|
+
}, {
|
|
48
|
+
readonly name: "validFrom";
|
|
49
|
+
readonly type: "uint256";
|
|
50
|
+
}, {
|
|
51
|
+
readonly name: "expiresAt";
|
|
52
|
+
readonly type: "uint256";
|
|
53
|
+
}, {
|
|
54
|
+
readonly name: "mode";
|
|
55
|
+
readonly type: "string";
|
|
56
|
+
}, {
|
|
57
|
+
readonly name: "rail";
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
}, {
|
|
60
|
+
readonly name: "reasonHash";
|
|
61
|
+
readonly type: "bytes32";
|
|
62
|
+
}, {
|
|
63
|
+
readonly name: "contextBindingHash";
|
|
64
|
+
readonly type: "bytes32";
|
|
65
|
+
}, {
|
|
66
|
+
readonly name: "bindingHash";
|
|
67
|
+
readonly type: "bytes32";
|
|
68
|
+
}];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* EXT-PMT-2 — fold the mandate's binding fields the core typed-data omitted into one committed hash:
|
|
72
|
+
* railConfig (the x402 quote binding: quoteId + resourceHash), mandateConstraints (aggregate scope),
|
|
73
|
+
* delegationRef, and the requiresClosedMandateForFinalCharge flag. Absent fields hash to a stable
|
|
74
|
+
* sentinel, so adding/removing one changes the digest.
|
|
75
|
+
*/
|
|
76
|
+
export declare function hashMandateBindings(mandate: PaymentMandate): Hex32;
|
|
77
|
+
/** The charge amount carried by the mandate (exact → amount; range/formula → maxAmount). */
|
|
78
|
+
export declare function mandateAmount(mandate: PaymentMandate): bigint;
|
|
79
|
+
/**
|
|
80
|
+
* Canonical hash of the ENTIRE context binding (PMT-INV-02). Every field is
|
|
81
|
+
* folded in; absent fields hash to zero, so adding/removing one changes the hash.
|
|
82
|
+
*/
|
|
83
|
+
export declare function hashContextBinding(cb: ContextBinding): Hex32;
|
|
84
|
+
export interface MandateDomainOpts {
|
|
85
|
+
chainId: number;
|
|
86
|
+
/** Optional binding to a specific contract (e.g. the PaymentEnforcer). Omit for a chain-scoped mandate. */
|
|
87
|
+
verifyingContract?: Address;
|
|
88
|
+
}
|
|
89
|
+
export declare function paymentMandateDomain(opts: MandateDomainOpts): {
|
|
90
|
+
readonly verifyingContract?: `0x${string}` | undefined;
|
|
91
|
+
readonly name: "AgenticPaymentMandate";
|
|
92
|
+
readonly version: "1";
|
|
93
|
+
readonly chainId: number;
|
|
94
|
+
};
|
|
95
|
+
/** The full EIP-712 typed-data object (domain + types + message) for a mandate. */
|
|
96
|
+
export declare function buildPaymentMandateTypedData(mandate: PaymentMandate, opts: MandateDomainOpts): {
|
|
97
|
+
domain: {
|
|
98
|
+
readonly verifyingContract?: `0x${string}` | undefined;
|
|
99
|
+
readonly name: "AgenticPaymentMandate";
|
|
100
|
+
readonly version: "1";
|
|
101
|
+
readonly chainId: number;
|
|
102
|
+
};
|
|
103
|
+
types: {
|
|
104
|
+
readonly PaymentMandate: readonly [{
|
|
105
|
+
readonly name: "mandateId";
|
|
106
|
+
readonly type: "bytes32";
|
|
107
|
+
}, {
|
|
108
|
+
readonly name: "payer";
|
|
109
|
+
readonly type: "address";
|
|
110
|
+
}, {
|
|
111
|
+
readonly name: "payee";
|
|
112
|
+
readonly type: "address";
|
|
113
|
+
}, {
|
|
114
|
+
readonly name: "granter";
|
|
115
|
+
readonly type: "address";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "asset";
|
|
118
|
+
readonly type: "address";
|
|
119
|
+
}, {
|
|
120
|
+
readonly name: "amount";
|
|
121
|
+
readonly type: "uint256";
|
|
122
|
+
}, {
|
|
123
|
+
readonly name: "nonce";
|
|
124
|
+
readonly type: "uint256";
|
|
125
|
+
}, {
|
|
126
|
+
readonly name: "maxRedemptions";
|
|
127
|
+
readonly type: "uint256";
|
|
128
|
+
}, {
|
|
129
|
+
readonly name: "validFrom";
|
|
130
|
+
readonly type: "uint256";
|
|
131
|
+
}, {
|
|
132
|
+
readonly name: "expiresAt";
|
|
133
|
+
readonly type: "uint256";
|
|
134
|
+
}, {
|
|
135
|
+
readonly name: "mode";
|
|
136
|
+
readonly type: "string";
|
|
137
|
+
}, {
|
|
138
|
+
readonly name: "rail";
|
|
139
|
+
readonly type: "string";
|
|
140
|
+
}, {
|
|
141
|
+
readonly name: "reasonHash";
|
|
142
|
+
readonly type: "bytes32";
|
|
143
|
+
}, {
|
|
144
|
+
readonly name: "contextBindingHash";
|
|
145
|
+
readonly type: "bytes32";
|
|
146
|
+
}, {
|
|
147
|
+
readonly name: "bindingHash";
|
|
148
|
+
readonly type: "bytes32";
|
|
149
|
+
}];
|
|
150
|
+
};
|
|
151
|
+
primaryType: "PaymentMandate";
|
|
152
|
+
message: {
|
|
153
|
+
readonly mandateId: `0x${string}`;
|
|
154
|
+
readonly payer: `0x${string}`;
|
|
155
|
+
readonly payee: `0x${string}`;
|
|
156
|
+
readonly granter: `0x${string}`;
|
|
157
|
+
readonly asset: Address;
|
|
158
|
+
readonly amount: bigint;
|
|
159
|
+
readonly nonce: bigint;
|
|
160
|
+
readonly maxRedemptions: bigint;
|
|
161
|
+
readonly validFrom: bigint;
|
|
162
|
+
readonly expiresAt: bigint;
|
|
163
|
+
readonly mode: import("./index.js").PaymentMandateMode;
|
|
164
|
+
readonly rail: import("./index.js").PaymentRail;
|
|
165
|
+
readonly reasonHash: `0x${string}`;
|
|
166
|
+
readonly contextBindingHash: `0x${string}`;
|
|
167
|
+
readonly bindingHash: `0x${string}`;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
/** The 32-byte EIP-712 digest the payer SA's ERC-1271 validates over. */
|
|
171
|
+
export declare function paymentMandateDigest(mandate: PaymentMandate, opts: MandateDomainOpts): Hex32;
|
|
172
|
+
/** Signer surface — an SA signer that produces an ERC-1271-validatable signature over typed data. */
|
|
173
|
+
export interface MandateSigner {
|
|
174
|
+
signTypedData(args: {
|
|
175
|
+
domain: Record<string, unknown>;
|
|
176
|
+
types: typeof PAYMENT_MANDATE_EIP712_TYPES;
|
|
177
|
+
primaryType: 'PaymentMandate';
|
|
178
|
+
message: Record<string, unknown>;
|
|
179
|
+
}): Promise<Hex>;
|
|
180
|
+
}
|
|
181
|
+
/** Sign an unsigned mandate (`signature: '0x'`) → a fully-populated mandate. */
|
|
182
|
+
export declare function signPaymentMandate(mandate: PaymentMandate, signer: MandateSigner, opts: MandateDomainOpts): Promise<PaymentMandate>;
|
|
183
|
+
/** Injected ERC-1271 read: returns the 4-byte magic from `payer.isValidSignature(digest, signature)`. */
|
|
184
|
+
export type Erc1271Reader = (account: Address, digest: Hex32, signature: Hex) => Promise<Hex>;
|
|
185
|
+
/**
|
|
186
|
+
* PMT-INV-12 — verify the mandate's signature via the payer SA's ERC-1271. Fail-closed: any read
|
|
187
|
+
* error or non-magic result is `false` (never throws on a bad signature).
|
|
188
|
+
*/
|
|
189
|
+
export declare function verifyPaymentMandateSignature(mandate: PaymentMandate, opts: MandateDomainOpts, read1271: Erc1271Reader): Promise<boolean>;
|
|
190
|
+
//# sourceMappingURL=mandate-sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate-sign.d.ts","sourceRoot":"","sources":["../src/mandate-sign.ts"],"names":[],"mappings":"AAEA;;0CAE0C;AAC1C,eAAO,MAAM,aAAa,cA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EAAE,OAAO,4BAA4B,CAAC;QAC3C,WAAW,EAAE,gBAAgB,CAAC;QAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAClC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CAClB;AAED,gFAAgF;AAChF,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,cAAc,CAAC,CASzB;AAED,yGAAyG;AACzG,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAE9F;;;GAGG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,iBAAiB,EACvB,QAAQ,EAAE,aAAa,GACtB,OAAO,CAAC,OAAO,CAAC,CASlB"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { ERC1271_MAGIC_VALUE } from '@agenticprimitives/types';
|
|
2
|
+
/** ERC-1271 magic value. Re-exported under this package's established name (the protocol constant
|
|
3
|
+
* itself lives in \ — it was declared in eight places, and \ could not reach
|
|
4
|
+
* \ for it without creating a cycle). */
|
|
5
|
+
export const ERC1271_MAGIC = ERC1271_MAGIC_VALUE;
|
|
6
|
+
/**
|
|
7
|
+
* PMT-INV-02 / PMT-INV-12 — EIP-712 mandate signing + ERC-1271 verification.
|
|
8
|
+
*
|
|
9
|
+
* The payer SA signs an EIP-712 typed-data digest of the mandate. The signed
|
|
10
|
+
* struct flattens the load-bearing fields and folds the entire `ContextBinding`
|
|
11
|
+
* into one `contextBindingHash` — so no field can be stripped or substituted
|
|
12
|
+
* after signing (PMT-INV-02 / INV-07 / INV-08), and verification is one
|
|
13
|
+
* ERC-1271 call against the payer SA (PMT-INV-12 — no raw EOA signatures).
|
|
14
|
+
*
|
|
15
|
+
* Pure crypto only (viem) — the actual ERC-1271 read is injected so the package
|
|
16
|
+
* stays transport-agnostic (no hard publicClient dependency).
|
|
17
|
+
*/
|
|
18
|
+
import { hashTypedData, keccak256, encodeAbiParameters, toHex, toBytes, } from 'viem';
|
|
19
|
+
export const PAYMENT_MANDATE_DOMAIN_NAME = 'AgenticPaymentMandate';
|
|
20
|
+
export const PAYMENT_MANDATE_DOMAIN_VERSION = '1';
|
|
21
|
+
/** ERC-1271 magic value for a valid signature. */
|
|
22
|
+
export const PAYMENT_MANDATE_EIP712_TYPES = {
|
|
23
|
+
PaymentMandate: [
|
|
24
|
+
{ name: 'mandateId', type: 'bytes32' },
|
|
25
|
+
{ name: 'payer', type: 'address' },
|
|
26
|
+
{ name: 'payee', type: 'address' },
|
|
27
|
+
{ name: 'granter', type: 'address' },
|
|
28
|
+
{ name: 'asset', type: 'address' },
|
|
29
|
+
{ name: 'amount', type: 'uint256' },
|
|
30
|
+
{ name: 'nonce', type: 'uint256' },
|
|
31
|
+
{ name: 'maxRedemptions', type: 'uint256' },
|
|
32
|
+
{ name: 'validFrom', type: 'uint256' },
|
|
33
|
+
{ name: 'expiresAt', type: 'uint256' },
|
|
34
|
+
{ name: 'mode', type: 'string' },
|
|
35
|
+
{ name: 'rail', type: 'string' },
|
|
36
|
+
{ name: 'reasonHash', type: 'bytes32' },
|
|
37
|
+
{ name: 'contextBindingHash', type: 'bytes32' },
|
|
38
|
+
// EXT-PMT-2: commit the previously-unsigned binding fields — railConfig (the quote binding,
|
|
39
|
+
// quoteId/resourceHash), delegationRef, mandateConstraints, and requiresClosedMandateForFinalCharge —
|
|
40
|
+
// so a signature can't be replayed against a different quote / delegation / constraint set.
|
|
41
|
+
{ name: 'bindingHash', type: 'bytes32' },
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
const ZERO32 = ('0x' + '00'.repeat(32));
|
|
45
|
+
const hashStr = (s) => (s ? keccak256(toBytes(s)) : ZERO32);
|
|
46
|
+
/**
|
|
47
|
+
* DELIBERATELY NOT `types.canonicalizeJson`. Do not "deduplicate" this.
|
|
48
|
+
*
|
|
49
|
+
* It serialises `bigint` as a decimal string. `canonicalizeJson` uses `JSON.stringify`, which THROWS
|
|
50
|
+
* on bigint — and payment amounts are bigint. It also maps `undefined` to `null` rather than
|
|
51
|
+
* dropping the key.
|
|
52
|
+
*
|
|
53
|
+
* A mechanical dedup pass will flag this file as a duplicate of `types.canonicalizeJson`. It is not:
|
|
54
|
+
* the difference above is the whole reason this function exists, and collapsing it would silently
|
|
55
|
+
* change bytes that are hashed and signed.
|
|
56
|
+
*/
|
|
57
|
+
/** Deterministic serialization (sorted keys, bigint→decimal, undefined dropped) for the loose
|
|
58
|
+
* railConfig / mandateConstraints objects so their hash is stable across key order. */
|
|
59
|
+
function canonicalJson(v) {
|
|
60
|
+
if (v === null || v === undefined)
|
|
61
|
+
return 'null';
|
|
62
|
+
if (typeof v === 'bigint')
|
|
63
|
+
return v.toString();
|
|
64
|
+
if (typeof v !== 'object')
|
|
65
|
+
return JSON.stringify(v);
|
|
66
|
+
if (Array.isArray(v))
|
|
67
|
+
return `[${v.map(canonicalJson).join(',')}]`;
|
|
68
|
+
const o = v;
|
|
69
|
+
return `{${Object.keys(o).sort().filter((k) => o[k] !== undefined).map((k) => `${JSON.stringify(k)}:${canonicalJson(o[k])}`).join(',')}}`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* EXT-PMT-2 — fold the mandate's binding fields the core typed-data omitted into one committed hash:
|
|
73
|
+
* railConfig (the x402 quote binding: quoteId + resourceHash), mandateConstraints (aggregate scope),
|
|
74
|
+
* delegationRef, and the requiresClosedMandateForFinalCharge flag. Absent fields hash to a stable
|
|
75
|
+
* sentinel, so adding/removing one changes the digest.
|
|
76
|
+
*/
|
|
77
|
+
export function hashMandateBindings(mandate) {
|
|
78
|
+
const railConfigHash = hashStr(canonicalJson(mandate.railConfig ?? null));
|
|
79
|
+
const constraintsHash = hashStr(canonicalJson(mandate.mandateConstraints ?? null));
|
|
80
|
+
return keccak256(encodeAbiParameters([{ type: 'bytes32' }, { type: 'bytes32' }, { type: 'bytes32' }, { type: 'bool' }], [railConfigHash, constraintsHash, mandate.delegationRef ?? ZERO32, !!mandate.requiresClosedMandateForFinalCharge]));
|
|
81
|
+
}
|
|
82
|
+
/** The charge amount carried by the mandate (exact → amount; range/formula → maxAmount). */
|
|
83
|
+
export function mandateAmount(mandate) {
|
|
84
|
+
const ap = mandate.amountPolicy;
|
|
85
|
+
return ap.kind === 'exact' ? ap.amount : ap.maxAmount;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Canonical hash of the ENTIRE context binding (PMT-INV-02). Every field is
|
|
89
|
+
* folded in; absent fields hash to zero, so adding/removing one changes the hash.
|
|
90
|
+
*/
|
|
91
|
+
export function hashContextBinding(cb) {
|
|
92
|
+
// Spec 302 W3 — `resourceHash` lands on-chain (PaymentCharged /
|
|
93
|
+
// PaymentReceiptRegistry events). method+url are LOW-ENTROPY: a bare hash
|
|
94
|
+
// is dictionary-reversible, turning the public spend ledger into
|
|
95
|
+
// "which resource did this person pay for". When `salt` is present (a
|
|
96
|
+
// random 32-byte value minted with the x402 quote and shared payer<->payee
|
|
97
|
+
// off-chain), it is folded in — the on-chain value becomes an opaque
|
|
98
|
+
// commitment only the transacting parties can open. Absent salt keeps the
|
|
99
|
+
// legacy public shape (accepted Mode-1 disclosure for public resources).
|
|
100
|
+
const resourceHash = cb.resource
|
|
101
|
+
? keccak256(cb.resource.salt
|
|
102
|
+
? encodeAbiParameters([{ type: 'string' }, { type: 'string' }, { type: 'bytes32' }, { type: 'bytes32' }], [cb.resource.method, cb.resource.url, cb.resource.requestBodyHash, cb.resource.salt])
|
|
103
|
+
: encodeAbiParameters([{ type: 'string' }, { type: 'string' }, { type: 'bytes32' }], [cb.resource.method, cb.resource.url, cb.resource.requestBodyHash]))
|
|
104
|
+
: ZERO32;
|
|
105
|
+
return keccak256(encodeAbiParameters([
|
|
106
|
+
{ type: 'bytes32' }, // intentIdHash
|
|
107
|
+
{ type: 'bytes32' }, // agreementCommitment
|
|
108
|
+
{ type: 'bytes32' }, // taskId
|
|
109
|
+
{ type: 'bytes32' }, // artifactHash
|
|
110
|
+
{ type: 'bytes32' }, // resourceHash
|
|
111
|
+
{ type: 'bytes32' }, // orderHash
|
|
112
|
+
{ type: 'bytes32' }, // legId
|
|
113
|
+
{ type: 'uint256' }, // chain
|
|
114
|
+
{ type: 'address' }, // asset
|
|
115
|
+
{ type: 'uint256' }, // nonce
|
|
116
|
+
{ type: 'uint256' }, // validFrom
|
|
117
|
+
{ type: 'uint256' }, // expiresAt
|
|
118
|
+
], [
|
|
119
|
+
hashStr(cb.intentId),
|
|
120
|
+
cb.agreementCommitment ?? ZERO32,
|
|
121
|
+
cb.taskId ?? ZERO32,
|
|
122
|
+
cb.artifactHash ?? ZERO32,
|
|
123
|
+
resourceHash,
|
|
124
|
+
cb.orderHash ?? ZERO32,
|
|
125
|
+
cb.legId ?? ZERO32,
|
|
126
|
+
BigInt(cb.chain),
|
|
127
|
+
cb.asset.id,
|
|
128
|
+
cb.nonce,
|
|
129
|
+
BigInt(cb.validFrom),
|
|
130
|
+
BigInt(cb.expiresAt),
|
|
131
|
+
]));
|
|
132
|
+
}
|
|
133
|
+
export function paymentMandateDomain(opts) {
|
|
134
|
+
return {
|
|
135
|
+
name: PAYMENT_MANDATE_DOMAIN_NAME,
|
|
136
|
+
version: PAYMENT_MANDATE_DOMAIN_VERSION,
|
|
137
|
+
chainId: opts.chainId,
|
|
138
|
+
...(opts.verifyingContract ? { verifyingContract: opts.verifyingContract } : {}),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function mandateMessage(mandate) {
|
|
142
|
+
return {
|
|
143
|
+
mandateId: mandate.mandateId,
|
|
144
|
+
payer: mandate.payer,
|
|
145
|
+
payee: mandate.payee,
|
|
146
|
+
granter: mandate.granter,
|
|
147
|
+
asset: mandate.amountPolicy.asset.id,
|
|
148
|
+
amount: mandateAmount(mandate),
|
|
149
|
+
nonce: mandate.nonce,
|
|
150
|
+
maxRedemptions: BigInt(mandate.maxRedemptions),
|
|
151
|
+
validFrom: BigInt(mandate.validFrom),
|
|
152
|
+
expiresAt: BigInt(mandate.expiresAt),
|
|
153
|
+
mode: mandate.mode,
|
|
154
|
+
rail: mandate.rail,
|
|
155
|
+
reasonHash: mandate.reasonHash,
|
|
156
|
+
contextBindingHash: hashContextBinding(mandate.contextBinding),
|
|
157
|
+
bindingHash: hashMandateBindings(mandate),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/** The full EIP-712 typed-data object (domain + types + message) for a mandate. */
|
|
161
|
+
export function buildPaymentMandateTypedData(mandate, opts) {
|
|
162
|
+
return {
|
|
163
|
+
domain: paymentMandateDomain(opts),
|
|
164
|
+
types: PAYMENT_MANDATE_EIP712_TYPES,
|
|
165
|
+
primaryType: 'PaymentMandate',
|
|
166
|
+
message: mandateMessage(mandate),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** The 32-byte EIP-712 digest the payer SA's ERC-1271 validates over. */
|
|
170
|
+
export function paymentMandateDigest(mandate, opts) {
|
|
171
|
+
const td = buildPaymentMandateTypedData(mandate, opts);
|
|
172
|
+
return hashTypedData(td);
|
|
173
|
+
}
|
|
174
|
+
/** Sign an unsigned mandate (`signature: '0x'`) → a fully-populated mandate. */
|
|
175
|
+
export async function signPaymentMandate(mandate, signer, opts) {
|
|
176
|
+
const td = buildPaymentMandateTypedData(mandate, opts);
|
|
177
|
+
const signature = await signer.signTypedData({
|
|
178
|
+
domain: td.domain,
|
|
179
|
+
types: td.types,
|
|
180
|
+
primaryType: td.primaryType,
|
|
181
|
+
message: td.message,
|
|
182
|
+
});
|
|
183
|
+
return { ...mandate, signature };
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* PMT-INV-12 — verify the mandate's signature via the payer SA's ERC-1271. Fail-closed: any read
|
|
187
|
+
* error or non-magic result is `false` (never throws on a bad signature).
|
|
188
|
+
*/
|
|
189
|
+
export async function verifyPaymentMandateSignature(mandate, opts, read1271) {
|
|
190
|
+
if (!mandate.signature || mandate.signature === '0x')
|
|
191
|
+
return false;
|
|
192
|
+
const digest = paymentMandateDigest(mandate, opts);
|
|
193
|
+
try {
|
|
194
|
+
const res = await read1271(mandate.payer, digest, mandate.signature);
|
|
195
|
+
return typeof res === 'string' && res.slice(0, 10).toLowerCase() === ERC1271_MAGIC;
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
void toHex; // reserved for future debug helpers
|
|
202
|
+
//# sourceMappingURL=mandate-sign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate-sign.js","sourceRoot":"","sources":["../src/mandate-sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;0CAE0C;AAC1C,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AACjD;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,KAAK,EACL,OAAO,GAGR,MAAM,MAAM,CAAC;AAGd,MAAM,CAAC,MAAM,2BAA2B,GAAG,uBAAuB,CAAC;AACnE,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAElD,kDAAkD;AAElD,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,cAAc,EAAE;QACd,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;QAClC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;QAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;QACpC,EAAE,IAAI,EAAE,OAAO,E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UAAU,kBAAkB,CACtC,OAAuB,EACvB,MAAqB,EACrB,IAAuB;IAEvB,MAAM,EAAE,GAAG,4BAA4B,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC;QAC3C,MAAM,EAAE,EAAE,CAAC,MAAM;QACjB,KAAK,EAAE,EAAE,CAAC,KAAK;QACf,WAAW,EAAE,EAAE,CAAC,WAAW;QAC3B,OAAO,EAAE,EAAE,CAAC,OAAkC;KAC/C,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC;AACnC,CAAC;AAKD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,OAAuB,EACvB,IAAuB,EACvB,QAAuB;IAEvB,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACnE,MAAM,MAAM,GAAG,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACnD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACrE,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,aAAa,CAAC;IACrF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,KAAK,KAAK,CAAC,CAAC,oCAAoC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `buildClosedMandate` — construct an unsigned closed (one-shot) PaymentMandate.
|
|
3
|
+
*
|
|
4
|
+
* The wallet + invoice rails (and the demo) build a closed mandate, sign it via
|
|
5
|
+
* `signPaymentMandate`, then settle it with a single transfer. Closed + one-shot per
|
|
6
|
+
* PMT-10 / PMT-INV-14. `orderHash`/`legId` (EXC-R2) bind the leg to an ExchangeOrder.
|
|
7
|
+
*/
|
|
8
|
+
import type { Address } from '@agenticprimitives/types';
|
|
9
|
+
import { type PaymentMandate, type PaymentRail, type AssetRef, type Hex32 } from './index.js';
|
|
10
|
+
export interface ClosedMandateInput {
|
|
11
|
+
payer: Address;
|
|
12
|
+
payee: Address;
|
|
13
|
+
asset: AssetRef;
|
|
14
|
+
amount: bigint;
|
|
15
|
+
chain: number;
|
|
16
|
+
rail: PaymentRail;
|
|
17
|
+
nonce: bigint;
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
validFrom?: number;
|
|
20
|
+
granter?: Address;
|
|
21
|
+
orderHash?: Hex32;
|
|
22
|
+
legId?: Hex32;
|
|
23
|
+
reasonHash?: Hex32;
|
|
24
|
+
resource?: {
|
|
25
|
+
method: string;
|
|
26
|
+
url: string;
|
|
27
|
+
requestBodyHash: Hex32;
|
|
28
|
+
salt?: Hex32;
|
|
29
|
+
};
|
|
30
|
+
delegationRef?: Hex32;
|
|
31
|
+
}
|
|
32
|
+
/** Build the unsigned closed mandate (signature `'0x'`); sign with `signPaymentMandate`. */
|
|
33
|
+
export declare function buildClosedMandate(input: ClosedMandateInput): PaymentMandate;
|
|
34
|
+
//# sourceMappingURL=mandate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate.d.ts","sourceRoot":"","sources":["../src/mandate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAoB,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAIhH,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,KAAK,CAAC;QAAC,IAAI,CAAC,EAAE,KAAK,CAAA;KAAE,CAAC;IACjF,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB;AAED,4FAA4F;AAC5F,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,cAAc,CA4B5E"}
|
package/dist/mandate.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `buildClosedMandate` — construct an unsigned closed (one-shot) PaymentMandate.
|
|
3
|
+
*
|
|
4
|
+
* The wallet + invoice rails (and the demo) build a closed mandate, sign it via
|
|
5
|
+
* `signPaymentMandate`, then settle it with a single transfer. Closed + one-shot per
|
|
6
|
+
* PMT-10 / PMT-INV-14. `orderHash`/`legId` (EXC-R2) bind the leg to an ExchangeOrder.
|
|
7
|
+
*/
|
|
8
|
+
import { computeMandateId } from './index.js';
|
|
9
|
+
const ZERO32 = ('0x' + '00'.repeat(32));
|
|
10
|
+
/** Build the unsigned closed mandate (signature `'0x'`); sign with `signPaymentMandate`. */
|
|
11
|
+
export function buildClosedMandate(input) {
|
|
12
|
+
const validFrom = input.validFrom ?? 0;
|
|
13
|
+
return {
|
|
14
|
+
mandateId: computeMandateId({ payer: input.payer, nonce: input.nonce, rail: input.rail, chain: input.chain }),
|
|
15
|
+
payer: input.payer,
|
|
16
|
+
payee: input.payee,
|
|
17
|
+
granter: input.granter ?? input.payer,
|
|
18
|
+
rail: input.rail,
|
|
19
|
+
amountPolicy: { kind: 'exact', amount: input.amount, asset: input.asset, chain: input.chain },
|
|
20
|
+
nonce: input.nonce,
|
|
21
|
+
maxRedemptions: 1,
|
|
22
|
+
validFrom,
|
|
23
|
+
expiresAt: input.expiresAt,
|
|
24
|
+
contextBinding: {
|
|
25
|
+
...(input.resource ? { resource: input.resource } : {}),
|
|
26
|
+
orderHash: input.orderHash,
|
|
27
|
+
legId: input.legId,
|
|
28
|
+
chain: input.chain,
|
|
29
|
+
asset: input.asset,
|
|
30
|
+
nonce: input.nonce,
|
|
31
|
+
validFrom,
|
|
32
|
+
expiresAt: input.expiresAt,
|
|
33
|
+
},
|
|
34
|
+
delegationRef: input.delegationRef,
|
|
35
|
+
mode: 'closed',
|
|
36
|
+
reasonHash: input.reasonHash ?? ZERO32,
|
|
37
|
+
signature: '0x',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=mandate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate.js","sourceRoot":"","sources":["../src/mandate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,gBAAgB,EAAoE,MAAM,YAAY,CAAC;AAEhH,MAAM,MAAM,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAU,CAAC;AAoBjD,4FAA4F;AAC5F,MAAM,UAAU,kBAAkB,CAAC,KAAyB;IAC1D,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,CAAC,CAAC;IACvC,OAAO;QACL,SAAS,EAAE,gBAAgB,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAC7G,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,KAAK;QACrC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,YAAY,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;QAC7F,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,cAAc,EAAE,CAAC;QACjB,SAAS;QACT,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,cAAc,EAAE;YACd,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvD,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,SAAS;YACT,SAAS,EAAE,KAAK,CAAC,SAAS;SAC3B;QACD,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,MAAM;QACtC,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC"}
|
package/dist/ops.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment ops core (spec 243 §5.5) — the plumbing every mature payment stack needs:
|
|
3
|
+
* an idempotent event model + webhook-style subscribers, reconciliation/payment-detection,
|
|
4
|
+
* and receipt export. In-process for W1 (the app delivers webhooks later). Pure — no I/O.
|
|
5
|
+
*/
|
|
6
|
+
import type { Address } from '@agenticprimitives/types';
|
|
7
|
+
import type { Hex32 } from './index.js';
|
|
8
|
+
export type PaymentEventType = 'payment.created' | 'payment.reserved' | 'payment.settling' | 'payment.settled' | 'payment.failed' | 'payment.refunded' | 'payment.expired' | 'payment.disputed' | 'entitlement.issued' | 'entitlement.consumed';
|
|
9
|
+
export interface PaymentEvent {
|
|
10
|
+
/** dedupe key — re-emitting the same key is a no-op (at-least-once producers, exactly-once consumers) */
|
|
11
|
+
idempotencyKey: string;
|
|
12
|
+
type: PaymentEventType;
|
|
13
|
+
at: number;
|
|
14
|
+
orderHash?: Hex32;
|
|
15
|
+
mandateId?: Hex32;
|
|
16
|
+
data?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
export interface PaymentEventLog {
|
|
19
|
+
/** Returns `{ accepted: false }` when `idempotencyKey` was already seen (no re-emit, no re-notify). */
|
|
20
|
+
emit(event: PaymentEvent): {
|
|
21
|
+
accepted: boolean;
|
|
22
|
+
};
|
|
23
|
+
list(): PaymentEvent[];
|
|
24
|
+
byType(type: PaymentEventType): PaymentEvent[];
|
|
25
|
+
byOrder(orderHash: Hex32): PaymentEvent[];
|
|
26
|
+
/** Webhook-style subscriber — invoked once per ACCEPTED event. Returns an unsubscribe fn. */
|
|
27
|
+
subscribe(fn: (event: PaymentEvent) => void): () => void;
|
|
28
|
+
}
|
|
29
|
+
export declare function createPaymentEventLog(): PaymentEventLog;
|
|
30
|
+
export interface ReceiptRow {
|
|
31
|
+
mandateId: Hex32;
|
|
32
|
+
payer: Address;
|
|
33
|
+
payee: Address;
|
|
34
|
+
asset: Address;
|
|
35
|
+
amount: bigint;
|
|
36
|
+
settlementHash: Hex32;
|
|
37
|
+
at: number;
|
|
38
|
+
orderHash?: Hex32;
|
|
39
|
+
/** set on a refund leg — the original charge it reverses */
|
|
40
|
+
refunds?: Hex32;
|
|
41
|
+
}
|
|
42
|
+
export interface ReceiptFilter {
|
|
43
|
+
payer?: Address;
|
|
44
|
+
payee?: Address;
|
|
45
|
+
orderHash?: Hex32;
|
|
46
|
+
asset?: Address;
|
|
47
|
+
}
|
|
48
|
+
export declare function listReceiptsBy(receipts: ReceiptRow[], filter: ReceiptFilter): ReceiptRow[];
|
|
49
|
+
/** Net balance change for `account` across the receipt set (incoming as payee − outgoing as payer). */
|
|
50
|
+
export declare function balanceDelta(receipts: ReceiptRow[], account: Address): bigint;
|
|
51
|
+
/** Payment detection: is `orderHash` paid (optionally to ≥ `expectedAmount`)? From receipts, not logs. */
|
|
52
|
+
export declare function isOrderPaid(receipts: ReceiptRow[], orderHash: Hex32, expectedAmount?: bigint): boolean;
|
|
53
|
+
export declare function exportReceiptsJSON(receipts: ReceiptRow[]): string;
|
|
54
|
+
export declare function exportReceiptsCSV(receipts: ReceiptRow[]): string;
|
|
55
|
+
//# sourceMappingURL=ops.d.ts.map
|