@bosonprotocol/x402-core 0.1.0-alpha-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +26 -0
  3. package/dist/cjs/eip712/index.d.ts +142 -0
  4. package/dist/cjs/eip712/index.js +224 -0
  5. package/dist/cjs/eip712/index.js.map +1 -0
  6. package/dist/cjs/eip712/token-auth/index.d.ts +259 -0
  7. package/dist/cjs/eip712/token-auth/index.js +221 -0
  8. package/dist/cjs/eip712/token-auth/index.js.map +1 -0
  9. package/dist/cjs/index.d.ts +15 -0
  10. package/dist/cjs/index.js +8 -0
  11. package/dist/cjs/index.js.map +1 -0
  12. package/dist/cjs/package.json +3 -0
  13. package/dist/cjs/schemes/escrow/index.d.ts +1262 -0
  14. package/dist/cjs/schemes/escrow/index.js +228 -0
  15. package/dist/cjs/schemes/escrow/index.js.map +1 -0
  16. package/dist/cjs/state-machine/index.d.ts +86 -0
  17. package/dist/cjs/state-machine/index.js +146 -0
  18. package/dist/cjs/state-machine/index.js.map +1 -0
  19. package/dist/cjs/states-Q2FJASHh.d.ts +38 -0
  20. package/dist/esm/chunk-7IY3WEFZ.js +10 -0
  21. package/dist/esm/chunk-7IY3WEFZ.js.map +1 -0
  22. package/dist/esm/eip712/index.js +213 -0
  23. package/dist/esm/eip712/index.js.map +1 -0
  24. package/dist/esm/eip712/token-auth/index.js +189 -0
  25. package/dist/esm/eip712/token-auth/index.js.map +1 -0
  26. package/dist/esm/index.js +6 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/package.json +3 -0
  29. package/dist/esm/schemes/escrow/index.js +202 -0
  30. package/dist/esm/schemes/escrow/index.js.map +1 -0
  31. package/dist/esm/state-machine/index.js +127 -0
  32. package/dist/esm/state-machine/index.js.map +1 -0
  33. package/dist/schemas/next_actions.schema.json +87 -0
  34. package/dist/schemas/payment_payload.schema.json +156 -0
  35. package/dist/schemas/payment_requirements.schema.json +135 -0
  36. package/package.json +84 -0
@@ -0,0 +1,259 @@
1
+ import { Address, Hex, PublicClient, TypedDataDomain } from 'viem';
2
+ export { createPermit2ApprovalTx, getPermit2AllowanceReadParams } from '@x402/evm/exact/client';
3
+
4
+ interface TokenEip712Domain {
5
+ /** Token's `EIP712Domain.name`, e.g. `"USD Coin"`. */
6
+ name: string;
7
+ /** Token's `EIP712Domain.version`, e.g. `"2"`. */
8
+ version: string;
9
+ chainId: number;
10
+ /** Token contract address. */
11
+ verifyingContract: Address;
12
+ /** Optional extra domain field some tokens publish. */
13
+ salt?: Hex;
14
+ }
15
+
16
+ /** EIP-712 type definition, keyed under the Boson-side primary type. */
17
+ declare const ERC3009_TYPES: {
18
+ readonly ReceiveWithAuthorization: readonly [{
19
+ readonly name: "from";
20
+ readonly type: "address";
21
+ }, {
22
+ readonly name: "to";
23
+ readonly type: "address";
24
+ }, {
25
+ readonly name: "value";
26
+ readonly type: "uint256";
27
+ }, {
28
+ readonly name: "validAfter";
29
+ readonly type: "uint256";
30
+ }, {
31
+ readonly name: "validBefore";
32
+ readonly type: "uint256";
33
+ }, {
34
+ readonly name: "nonce";
35
+ readonly type: "bytes32";
36
+ }];
37
+ };
38
+ declare const ERC3009_PRIMARY_TYPE: "ReceiveWithAuthorization";
39
+ interface Erc3009Message {
40
+ from: Address;
41
+ to: Address;
42
+ value: bigint;
43
+ validAfter: bigint;
44
+ validBefore: bigint;
45
+ /** 32-byte hex; should be cryptographically random per the ERC-3009 spec. */
46
+ nonce: Hex;
47
+ }
48
+ interface Erc3009TypedDataArgs {
49
+ /**
50
+ * The token contract's own EIP-712 domain. ERC-3009 requires
51
+ * `{ name, version, chainId, verifyingContract }` to match what the
52
+ * token recovers on-chain — see {@link TokenEip712Domain}.
53
+ */
54
+ domain: TokenEip712Domain;
55
+ message: Erc3009Message;
56
+ }
57
+ interface Erc3009TypedData {
58
+ domain: TokenEip712Domain;
59
+ types: typeof ERC3009_TYPES;
60
+ primaryType: typeof ERC3009_PRIMARY_TYPE;
61
+ message: Erc3009Message;
62
+ }
63
+ declare function erc3009TypedData({ domain, message }: Erc3009TypedDataArgs): Erc3009TypedData;
64
+ declare function hashErc3009Authorization(args: Erc3009TypedDataArgs): Hex;
65
+ declare function recoverErc3009Signer(args: Erc3009TypedDataArgs & {
66
+ signature: Hex;
67
+ }): Promise<Address>;
68
+
69
+ declare const EIP5267_ABI: readonly [{
70
+ readonly type: "function";
71
+ readonly name: "eip712Domain";
72
+ readonly stateMutability: "view";
73
+ readonly inputs: readonly [];
74
+ readonly outputs: readonly [{
75
+ readonly name: "fields";
76
+ readonly type: "bytes1";
77
+ }, {
78
+ readonly name: "name";
79
+ readonly type: "string";
80
+ }, {
81
+ readonly name: "version";
82
+ readonly type: "string";
83
+ }, {
84
+ readonly name: "chainId";
85
+ readonly type: "uint256";
86
+ }, {
87
+ readonly name: "verifyingContract";
88
+ readonly type: "address";
89
+ }, {
90
+ readonly name: "salt";
91
+ readonly type: "bytes32";
92
+ }, {
93
+ readonly name: "extensions";
94
+ readonly type: "uint256[]";
95
+ }];
96
+ }];
97
+ declare const NAME_ABI: readonly [{
98
+ readonly type: "function";
99
+ readonly name: "name";
100
+ readonly stateMutability: "view";
101
+ readonly inputs: readonly [];
102
+ readonly outputs: readonly [{
103
+ readonly type: "string";
104
+ }];
105
+ }];
106
+ declare const VERSION_ABI: readonly [{
107
+ readonly type: "function";
108
+ readonly name: "version";
109
+ readonly stateMutability: "view";
110
+ readonly inputs: readonly [];
111
+ readonly outputs: readonly [{
112
+ readonly type: "string";
113
+ }];
114
+ }];
115
+ /**
116
+ * Look up the token's EIP-712 domain. Tries EIP-5267 first (one call,
117
+ * canonical); falls back to `name()` + `version()` (with version
118
+ * defaulting to `"1"` per EIP-2612 if `version()` reverts).
119
+ *
120
+ * Error handling: only contract-level errors (any `ContractFunction*`
121
+ * class viem throws via `getContractError`) are treated as "method not
122
+ * implemented" and trigger the fallback. RPC / transport failures
123
+ * (HTTP timeouts, JSON-RPC errors) propagate as-is so the caller can
124
+ * distinguish them and surface a clear internal error rather than a
125
+ * silent fallback that fails again on the next call. `name()` is
126
+ * required by ERC-20 so any failure there is a real error and
127
+ * propagates.
128
+ *
129
+ * Both the facilitator (recovering a signature) and the browser paywall
130
+ * (about to sign one) call this against the same chain — keeping the
131
+ * lookup in one place keeps signer and verifier in lockstep.
132
+ */
133
+ declare function fetchTokenDomain(publicClient: PublicClient, token: Address, chainId: number): Promise<TokenEip712Domain>;
134
+
135
+ declare const PERMIT_TYPES: {
136
+ readonly Permit: readonly [{
137
+ readonly name: "owner";
138
+ readonly type: "address";
139
+ }, {
140
+ readonly name: "spender";
141
+ readonly type: "address";
142
+ }, {
143
+ readonly name: "value";
144
+ readonly type: "uint256";
145
+ }, {
146
+ readonly name: "nonce";
147
+ readonly type: "uint256";
148
+ }, {
149
+ readonly name: "deadline";
150
+ readonly type: "uint256";
151
+ }];
152
+ };
153
+ declare const PERMIT_PRIMARY_TYPE: "Permit";
154
+ interface PermitMessage {
155
+ owner: Address;
156
+ spender: Address;
157
+ value: bigint;
158
+ /** Token-internal sequential nonce — query via `IERC20Permit.nonces(owner)`. */
159
+ nonce: bigint;
160
+ deadline: bigint;
161
+ }
162
+ interface PermitTypedDataArgs {
163
+ /**
164
+ * The token contract's own EIP-712 domain. EIP-2612 requires
165
+ * `{ name, version, chainId, verifyingContract }` to produce the
166
+ * digest the token recovers on-chain — see {@link TokenEip712Domain}.
167
+ */
168
+ domain: TokenEip712Domain;
169
+ message: PermitMessage;
170
+ }
171
+ interface PermitTypedData {
172
+ domain: TokenEip712Domain;
173
+ types: typeof PERMIT_TYPES;
174
+ primaryType: typeof PERMIT_PRIMARY_TYPE;
175
+ message: PermitMessage;
176
+ }
177
+ declare function permitTypedData({ domain, message }: PermitTypedDataArgs): PermitTypedData;
178
+ declare function hashPermit(args: PermitTypedDataArgs): Hex;
179
+ declare function recoverPermitSigner(args: PermitTypedDataArgs & {
180
+ signature: Hex;
181
+ }): Promise<Address>;
182
+
183
+ /**
184
+ * Canonical Permit2 contract address. Same on every EVM chain via CREATE2
185
+ * deployment.
186
+ *
187
+ * @see https://github.com/Uniswap/permit2
188
+ */
189
+ declare const PERMIT2_ADDRESS: Address;
190
+ /** Permit2's EIP-712 `name` field. No `version`, no `salt`. */
191
+ declare const PERMIT2_DOMAIN_NAME: "Permit2";
192
+ declare const PERMIT2_TYPES: {
193
+ readonly PermitTransferFrom: readonly [{
194
+ readonly name: "permitted";
195
+ readonly type: "TokenPermissions";
196
+ }, {
197
+ readonly name: "spender";
198
+ readonly type: "address";
199
+ }, {
200
+ readonly name: "nonce";
201
+ readonly type: "uint256";
202
+ }, {
203
+ readonly name: "deadline";
204
+ readonly type: "uint256";
205
+ }];
206
+ readonly TokenPermissions: readonly [{
207
+ readonly name: "token";
208
+ readonly type: "address";
209
+ }, {
210
+ readonly name: "amount";
211
+ readonly type: "uint256";
212
+ }];
213
+ };
214
+ declare const PERMIT2_PRIMARY_TYPE: "PermitTransferFrom";
215
+ interface Permit2Message {
216
+ permitted: {
217
+ token: Address;
218
+ amount: bigint;
219
+ };
220
+ spender: Address;
221
+ /** Permit2 word-bitmap nonce. */
222
+ nonce: bigint;
223
+ deadline: bigint;
224
+ }
225
+ interface Permit2TypedDataArgs {
226
+ chainId: number;
227
+ message: Permit2Message;
228
+ }
229
+ interface Permit2TypedData {
230
+ domain: TypedDataDomain;
231
+ types: typeof PERMIT2_TYPES;
232
+ primaryType: typeof PERMIT2_PRIMARY_TYPE;
233
+ message: Permit2Message;
234
+ }
235
+ /** Permit2's EIP-712 domain on a given chain. The `verifyingContract` is the canonical Permit2 address. */
236
+ declare function permit2Domain(chainId: number): TypedDataDomain;
237
+ declare function permit2TypedData({ chainId, message }: Permit2TypedDataArgs): Permit2TypedData;
238
+ declare function hashPermit2(args: Permit2TypedDataArgs): Hex;
239
+ declare function recoverPermit2Signer(args: Permit2TypedDataArgs & {
240
+ signature: Hex;
241
+ }): Promise<Address>;
242
+
243
+ interface Erc20ApprovalArgs {
244
+ token: Address;
245
+ spender: Address;
246
+ amount: bigint;
247
+ }
248
+ /**
249
+ * Build calldata for an ERC-20 `approve(spender, amount)` call. Use with
250
+ * `walletClient.sendTransaction({ to: token, data })` or any equivalent
251
+ * signer to grant `spender` (the Boson escrow contract) the right to
252
+ * pull `amount` of `token`.
253
+ */
254
+ declare function createErc20ApprovalTx({ token, spender, amount }: Erc20ApprovalArgs): {
255
+ to: Address;
256
+ data: Hex;
257
+ };
258
+
259
+ export { EIP5267_ABI, ERC3009_PRIMARY_TYPE, ERC3009_TYPES, type Erc20ApprovalArgs, type Erc3009Message, type Erc3009TypedData, type Erc3009TypedDataArgs, NAME_ABI, PERMIT2_ADDRESS, PERMIT2_DOMAIN_NAME, PERMIT2_PRIMARY_TYPE, PERMIT2_TYPES, PERMIT_PRIMARY_TYPE, PERMIT_TYPES, type Permit2Message, type Permit2TypedData, type Permit2TypedDataArgs, type PermitMessage, type PermitTypedData, type PermitTypedDataArgs, type TokenEip712Domain, VERSION_ABI, createErc20ApprovalTx, erc3009TypedData, fetchTokenDomain, hashErc3009Authorization, hashPermit, hashPermit2, permit2Domain, permit2TypedData, permitTypedData, recoverErc3009Signer, recoverPermit2Signer, recoverPermitSigner };
@@ -0,0 +1,221 @@
1
+ 'use strict';
2
+
3
+ var viem = require('viem');
4
+ var client = require('@x402/evm/exact/client');
5
+
6
+ // src/eip712/token-auth/erc3009.ts
7
+ var ERC3009_TYPES = {
8
+ ReceiveWithAuthorization: [
9
+ { name: "from", type: "address" },
10
+ { name: "to", type: "address" },
11
+ { name: "value", type: "uint256" },
12
+ { name: "validAfter", type: "uint256" },
13
+ { name: "validBefore", type: "uint256" },
14
+ { name: "nonce", type: "bytes32" }
15
+ ]
16
+ };
17
+ var ERC3009_PRIMARY_TYPE = "ReceiveWithAuthorization";
18
+ function erc3009TypedData({ domain, message }) {
19
+ return { domain, types: ERC3009_TYPES, primaryType: ERC3009_PRIMARY_TYPE, message };
20
+ }
21
+ function hashErc3009Authorization(args) {
22
+ return viem.hashTypedData(erc3009TypedData(args));
23
+ }
24
+ async function recoverErc3009Signer(args) {
25
+ const { signature, ...rest } = args;
26
+ return viem.recoverTypedDataAddress({ ...erc3009TypedData(rest), signature });
27
+ }
28
+
29
+ // src/eip712/token-auth/fetch-token-domain.ts
30
+ var EIP5267_ABI = [
31
+ {
32
+ type: "function",
33
+ name: "eip712Domain",
34
+ stateMutability: "view",
35
+ inputs: [],
36
+ outputs: [
37
+ { name: "fields", type: "bytes1" },
38
+ { name: "name", type: "string" },
39
+ { name: "version", type: "string" },
40
+ { name: "chainId", type: "uint256" },
41
+ { name: "verifyingContract", type: "address" },
42
+ { name: "salt", type: "bytes32" },
43
+ { name: "extensions", type: "uint256[]" }
44
+ ]
45
+ }
46
+ ];
47
+ var NAME_ABI = [
48
+ {
49
+ type: "function",
50
+ name: "name",
51
+ stateMutability: "view",
52
+ inputs: [],
53
+ outputs: [{ type: "string" }]
54
+ }
55
+ ];
56
+ var VERSION_ABI = [
57
+ {
58
+ type: "function",
59
+ name: "version",
60
+ stateMutability: "view",
61
+ inputs: [],
62
+ outputs: [{ type: "string" }]
63
+ }
64
+ ];
65
+ var EIP5267_SALT_BIT = 16;
66
+ function isContractFunctionError(e) {
67
+ if (!(e instanceof Error)) return false;
68
+ return e.name.startsWith("ContractFunction");
69
+ }
70
+ async function fetchTokenDomain(publicClient, token, chainId) {
71
+ try {
72
+ const result = await publicClient.readContract({
73
+ address: token,
74
+ abi: EIP5267_ABI,
75
+ functionName: "eip712Domain"
76
+ });
77
+ const hasSalt = (Number(result[0]) & EIP5267_SALT_BIT) !== 0;
78
+ return {
79
+ name: result[1],
80
+ version: result[2],
81
+ chainId: Number(result[3]),
82
+ verifyingContract: result[4],
83
+ // Only attach `salt` when the bitmask says it's part of the domain
84
+ // — omit the key entirely rather than emitting `salt: undefined`,
85
+ // so the object shape matches the optional `salt?` type and
86
+ // downstream `in` / key checks don't see a phantom field.
87
+ ...hasSalt ? { salt: result[5] } : {}
88
+ };
89
+ } catch (e) {
90
+ if (!isContractFunctionError(e)) {
91
+ throw e;
92
+ }
93
+ }
94
+ const name = await publicClient.readContract({
95
+ address: token,
96
+ abi: NAME_ABI,
97
+ functionName: "name"
98
+ });
99
+ let version = "1";
100
+ try {
101
+ version = await publicClient.readContract({
102
+ address: token,
103
+ abi: VERSION_ABI,
104
+ functionName: "version"
105
+ });
106
+ } catch (e) {
107
+ if (!isContractFunctionError(e)) {
108
+ throw e;
109
+ }
110
+ }
111
+ return { name, version, chainId, verifyingContract: token };
112
+ }
113
+ var PERMIT_TYPES = {
114
+ Permit: [
115
+ { name: "owner", type: "address" },
116
+ { name: "spender", type: "address" },
117
+ { name: "value", type: "uint256" },
118
+ { name: "nonce", type: "uint256" },
119
+ { name: "deadline", type: "uint256" }
120
+ ]
121
+ };
122
+ var PERMIT_PRIMARY_TYPE = "Permit";
123
+ function permitTypedData({ domain, message }) {
124
+ return { domain, types: PERMIT_TYPES, primaryType: PERMIT_PRIMARY_TYPE, message };
125
+ }
126
+ function hashPermit(args) {
127
+ return viem.hashTypedData(permitTypedData(args));
128
+ }
129
+ async function recoverPermitSigner(args) {
130
+ const { signature, ...rest } = args;
131
+ return viem.recoverTypedDataAddress({ ...permitTypedData(rest), signature });
132
+ }
133
+ var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
134
+ var PERMIT2_DOMAIN_NAME = "Permit2";
135
+ var PERMIT2_TYPES = {
136
+ PermitTransferFrom: [
137
+ { name: "permitted", type: "TokenPermissions" },
138
+ { name: "spender", type: "address" },
139
+ { name: "nonce", type: "uint256" },
140
+ { name: "deadline", type: "uint256" }
141
+ ],
142
+ TokenPermissions: [
143
+ { name: "token", type: "address" },
144
+ { name: "amount", type: "uint256" }
145
+ ]
146
+ };
147
+ var PERMIT2_PRIMARY_TYPE = "PermitTransferFrom";
148
+ function permit2Domain(chainId) {
149
+ return { name: PERMIT2_DOMAIN_NAME, chainId, verifyingContract: PERMIT2_ADDRESS };
150
+ }
151
+ function permit2TypedData({ chainId, message }) {
152
+ return {
153
+ domain: permit2Domain(chainId),
154
+ types: PERMIT2_TYPES,
155
+ primaryType: PERMIT2_PRIMARY_TYPE,
156
+ message
157
+ };
158
+ }
159
+ function hashPermit2(args) {
160
+ return viem.hashTypedData(permit2TypedData(args));
161
+ }
162
+ async function recoverPermit2Signer(args) {
163
+ const { signature, ...rest } = args;
164
+ return viem.recoverTypedDataAddress({ ...permit2TypedData(rest), signature });
165
+ }
166
+ var ERC20_APPROVE_ABI = [
167
+ {
168
+ type: "function",
169
+ name: "approve",
170
+ stateMutability: "nonpayable",
171
+ inputs: [
172
+ { name: "spender", type: "address" },
173
+ { name: "amount", type: "uint256" }
174
+ ],
175
+ outputs: [{ type: "bool" }]
176
+ }
177
+ ];
178
+ function createErc20ApprovalTx({ token, spender, amount }) {
179
+ return {
180
+ to: token,
181
+ data: viem.encodeFunctionData({
182
+ abi: ERC20_APPROVE_ABI,
183
+ functionName: "approve",
184
+ args: [spender, amount]
185
+ })
186
+ };
187
+ }
188
+
189
+ Object.defineProperty(exports, "createPermit2ApprovalTx", {
190
+ enumerable: true,
191
+ get: function () { return client.createPermit2ApprovalTx; }
192
+ });
193
+ Object.defineProperty(exports, "getPermit2AllowanceReadParams", {
194
+ enumerable: true,
195
+ get: function () { return client.getPermit2AllowanceReadParams; }
196
+ });
197
+ exports.EIP5267_ABI = EIP5267_ABI;
198
+ exports.ERC3009_PRIMARY_TYPE = ERC3009_PRIMARY_TYPE;
199
+ exports.ERC3009_TYPES = ERC3009_TYPES;
200
+ exports.NAME_ABI = NAME_ABI;
201
+ exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS;
202
+ exports.PERMIT2_DOMAIN_NAME = PERMIT2_DOMAIN_NAME;
203
+ exports.PERMIT2_PRIMARY_TYPE = PERMIT2_PRIMARY_TYPE;
204
+ exports.PERMIT2_TYPES = PERMIT2_TYPES;
205
+ exports.PERMIT_PRIMARY_TYPE = PERMIT_PRIMARY_TYPE;
206
+ exports.PERMIT_TYPES = PERMIT_TYPES;
207
+ exports.VERSION_ABI = VERSION_ABI;
208
+ exports.createErc20ApprovalTx = createErc20ApprovalTx;
209
+ exports.erc3009TypedData = erc3009TypedData;
210
+ exports.fetchTokenDomain = fetchTokenDomain;
211
+ exports.hashErc3009Authorization = hashErc3009Authorization;
212
+ exports.hashPermit = hashPermit;
213
+ exports.hashPermit2 = hashPermit2;
214
+ exports.permit2Domain = permit2Domain;
215
+ exports.permit2TypedData = permit2TypedData;
216
+ exports.permitTypedData = permitTypedData;
217
+ exports.recoverErc3009Signer = recoverErc3009Signer;
218
+ exports.recoverPermit2Signer = recoverPermit2Signer;
219
+ exports.recoverPermitSigner = recoverPermitSigner;
220
+ //# sourceMappingURL=index.js.map
221
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/eip712/token-auth/erc3009.ts","../../../../src/eip712/token-auth/fetch-token-domain.ts","../../../../src/eip712/token-auth/permit.ts","../../../../src/eip712/token-auth/permit2.ts","../../../../src/eip712/token-auth/approve.ts"],"names":["hashTypedData","recoverTypedDataAddress","encodeFunctionData"],"mappings":";;;;;;AAsBO,IAAM,aAAA,GAAgB;AAAA,EAC3B,wBAAA,EAA0B;AAAA,IACxB,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,IAChC,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,SAAA,EAAU;AAAA,IAC9B,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,SAAA,EAAU;AAAA,IACtC,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,SAAA,EAAU;AAAA,IACvC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA;AAAU;AAErC;AAEO,IAAM,oBAAA,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;AAC3D,EAAA,OAAOD,kBAAAA,CAAc,gBAAA,CAAiB,IAAI,CAAC,CAAA;AAC7C;AAEA,eAAsB,qBACpB,IAAA,EACkB;AAClB,EAAA,MAAM,EAAE,SAAA,EAAW,GAAG,IAAA,EAAK,GAAI,IAAA;AAC/B,EAAA,OAAOC,6BAAwB,EAAE,GAAG,iBAAiB,IAAI,CAAA,EAAG,WAAW,CAAA;AACzE;AC1FA,IAAM,iBAAA,GAAoB;AAAA,EACxB;AAAA,IACE,IAAA,EAAM,UAAA;AAAA,IACN,IAAA,EAAM,SAAA;AAAA,IACN,eAAA,EAAiB,YAAA;AAAA,IACjB,MAAA,EAAQ;AAAA,MACN,EAAE,IAAA,EAAM,SAAA,EAAW,IAAA,EAAM,SAAA,EAAU;AAAA,MACnC,EAAE,IAAA,EAAM,QAAA,EAAU,IAAA,EAAM,SAAA;AAAU,KACpC;AAAA,IACA,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,QAAQ;AAAA;AAE9B,CAAA;AAcO,SAAS,qBAAA,CAAsB,EAAE,KAAA,EAAO,OAAA,EAAS,QAAO,EAG7D;AACA,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,KAAA;AAAA,IACJ,MAAMC,uBAAA,CAAmB;AAAA,MACvB,GAAA,EAAK,iBAAA;AAAA,MACL,YAAA,EAAc,SAAA;AAAA,MACd,IAAA,EAAM,CAAC,OAAA,EAAS,MAAM;AAAA,KACvB;AAAA,GACH;AACF","file":"index.js","sourcesContent":["// EIP-712 typed-data builder for ERC-3009 `ReceiveWithAuthorization`.\n//\n// Boson uses the receive variant per docs/boson-impl-01-escrow-scheme.md §4.3\n// because only the recipient (Boson escrow contract) can call\n// `receiveWithAuthorization`, eliminating relayer front-running. The struct\n// fields are identical to ERC-3009's `TransferWithAuthorization` — only the\n// on-chain function name and primary type differ. The shape is fixed by\n// EIP-3009 and hasn't changed since the standard was published.\n//\n// `@bosonprotocol/core-sdk` exposes the same type-list internally inside\n// `signReceiveWithErc3009Authorization` but auto-generates the `nonce`\n// before returning typed-data. The verification path needs a caller-supplied\n// nonce (so it can rebuild the digest the buyer signed), so this module\n// keeps a standalone typed-data builder. A KAT cross-validation test\n// (`sdk-parity.test.ts`) asserts the type-list matches the SDK's internal\n// one, catching drift if either side ever changes.\n\nimport { hashTypedData, recoverTypedDataAddress, type Address, type Hex } from \"viem\";\n\nimport type { TokenEip712Domain } from \"./domain.js\";\n\n/** EIP-712 type definition, keyed under the Boson-side primary type. */\nexport const ERC3009_TYPES = {\n ReceiveWithAuthorization: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n { name: \"nonce\", type: \"bytes32\" },\n ],\n} as const;\n\nexport const ERC3009_PRIMARY_TYPE = \"ReceiveWithAuthorization\" as const;\n\nexport interface Erc3009Message {\n from: Address;\n to: Address;\n value: bigint;\n validAfter: bigint;\n validBefore: bigint;\n /** 32-byte hex; should be cryptographically random per the ERC-3009 spec. */\n nonce: Hex;\n}\n\nexport interface Erc3009TypedDataArgs {\n /**\n * The token contract's own EIP-712 domain. ERC-3009 requires\n * `{ name, version, chainId, verifyingContract }` to match what the\n * token recovers on-chain — see {@link TokenEip712Domain}.\n */\n domain: TokenEip712Domain;\n message: Erc3009Message;\n}\n\nexport interface Erc3009TypedData {\n domain: TokenEip712Domain;\n types: typeof ERC3009_TYPES;\n primaryType: typeof ERC3009_PRIMARY_TYPE;\n message: Erc3009Message;\n}\n\nexport function erc3009TypedData({ domain, message }: Erc3009TypedDataArgs): Erc3009TypedData {\n return { domain, types: ERC3009_TYPES, primaryType: ERC3009_PRIMARY_TYPE, message };\n}\n\nexport function hashErc3009Authorization(args: Erc3009TypedDataArgs): Hex {\n return hashTypedData(erc3009TypedData(args));\n}\n\nexport async function recoverErc3009Signer(\n args: Erc3009TypedDataArgs & { signature: Hex },\n): Promise<Address> {\n const { signature, ...rest } = args;\n return recoverTypedDataAddress({ ...erc3009TypedData(rest), signature });\n}\n","// Shared resolver for a token contract's EIP-712 domain (`name`,\n// `version`). ERC-3009 (`ReceiveWithAuthorization`) and EIP-2612\n// (`Permit`) signers and the facilitator's verify path both need this\n// lookup — keeping it in a single place ensures signing and verification\n// stay in lock-step on one ABI surface and one fallback flow.\n//\n// Tries EIP-5267's canonical `eip712Domain()` view first; on a contract\n// that doesn't implement it, falls back to ERC-20 `name()` + EIP-2612\n// `version()` with `\"1\"` as the default if `version()` reverts (the\n// EIP-2612-specified default).\n//\n// Error handling: only `ContractFunctionExecutionError` is treated as\n// \"method not implemented\" and triggers a fallback. RPC / transport\n// failures propagate as-is so callers can distinguish them and surface a\n// clear failure rather than a silent fallback that fails again on the\n// next call. `name()` is required by ERC-20 so any failure there is a\n// real error and propagates.\n\nimport { type Address, type Hex, type PublicClient } from \"viem\";\n\nimport type { TokenEip712Domain } from \"./domain.js\";\n\nexport const EIP5267_ABI = [\n {\n type: \"function\",\n name: \"eip712Domain\",\n stateMutability: \"view\",\n inputs: [],\n outputs: [\n { name: \"fields\", type: \"bytes1\" },\n { name: \"name\", type: \"string\" },\n { name: \"version\", type: \"string\" },\n { name: \"chainId\", type: \"uint256\" },\n { name: \"verifyingContract\", type: \"address\" },\n { name: \"salt\", type: \"bytes32\" },\n { name: \"extensions\", type: \"uint256[]\" },\n ],\n },\n] as const;\n\nexport const NAME_ABI = [\n {\n type: \"function\",\n name: \"name\",\n stateMutability: \"view\",\n inputs: [],\n outputs: [{ type: \"string\" }],\n },\n] as const;\n\nexport const VERSION_ABI = [\n {\n type: \"function\",\n name: \"version\",\n stateMutability: \"view\",\n inputs: [],\n outputs: [{ type: \"string\" }],\n },\n] as const;\n\n// EIP-5267 `fields` bitmask: bit i (LSB-first) is set when domain field\n// i — in EIP-712's canonical field order (name, version, chainId,\n// verifyingContract, salt) — is present. We only need the `salt` bit:\n// tokens whose domain includes `salt` computed their domain separator\n// with it, so the signature won't recover unless we carry it through;\n// tokens that omit `salt` return a zero `bytes32` we must drop, or the\n// extra field corrupts the domain we hash against.\nconst EIP5267_SALT_BIT = 0x10;\n\n// Duck-type check for viem's `ContractFunctionExecutionError` (and the\n// other `ContractFunction*Error` subclasses it nests as a `cause`).\n// We compare by `.name` rather than `instanceof` because the paywall's\n// browser IIFE bundle ends up with multiple viem class instances\n// (esbuild inlines viem along several import chains —\n// `@bosonprotocol/x402-core`, `@bosonprotocol/x402-client-browser`,\n// wagmi, and direct paywall imports — and class identity is not\n// preserved across them). An `instanceof` check there would falsely\n// re-throw what's really a \"method not implemented\" revert. Name\n// strings are stable across bundles (viem sets them via\n// `Object.defineProperty(this, \"name\", ...)`) and plain `Error` from\n// transport failures still falls through to the rethrow path because\n// its `.name` is `\"Error\"`.\nfunction isContractFunctionError(e: unknown): boolean {\n if (!(e instanceof Error)) return false;\n return e.name.startsWith(\"ContractFunction\");\n}\n\n/**\n * Look up the token's EIP-712 domain. Tries EIP-5267 first (one call,\n * canonical); falls back to `name()` + `version()` (with version\n * defaulting to `\"1\"` per EIP-2612 if `version()` reverts).\n *\n * Error handling: only contract-level errors (any `ContractFunction*`\n * class viem throws via `getContractError`) are treated as \"method not\n * implemented\" and trigger the fallback. RPC / transport failures\n * (HTTP timeouts, JSON-RPC errors) propagate as-is so the caller can\n * distinguish them and surface a clear internal error rather than a\n * silent fallback that fails again on the next call. `name()` is\n * required by ERC-20 so any failure there is a real error and\n * propagates.\n *\n * Both the facilitator (recovering a signature) and the browser paywall\n * (about to sign one) call this against the same chain — keeping the\n * lookup in one place keeps signer and verifier in lockstep.\n */\nexport async function fetchTokenDomain(\n publicClient: PublicClient,\n token: Address,\n chainId: number,\n): Promise<TokenEip712Domain> {\n try {\n const result = (await publicClient.readContract({\n address: token,\n abi: EIP5267_ABI,\n functionName: \"eip712Domain\",\n })) as readonly [Hex, string, string, bigint, Address, Hex, readonly bigint[]];\n const hasSalt = (Number(result[0]) & EIP5267_SALT_BIT) !== 0;\n return {\n name: result[1],\n version: result[2],\n chainId: Number(result[3]),\n verifyingContract: result[4],\n // Only attach `salt` when the bitmask says it's part of the domain\n // — omit the key entirely rather than emitting `salt: undefined`,\n // so the object shape matches the optional `salt?` type and\n // downstream `in` / key checks don't see a phantom field.\n ...(hasSalt ? { salt: result[5] } : {}),\n };\n } catch (e) {\n if (!isContractFunctionError(e)) {\n throw e;\n }\n // EIP-5267 not implemented — fall back to name() + version().\n }\n const name = (await publicClient.readContract({\n address: token,\n abi: NAME_ABI,\n functionName: \"name\",\n })) as string;\n let version = \"1\";\n try {\n version = (await publicClient.readContract({\n address: token,\n abi: VERSION_ABI,\n functionName: \"version\",\n })) as string;\n } catch (e) {\n if (!isContractFunctionError(e)) {\n throw e;\n }\n // version() is optional per EIP-2612 — keep the default.\n }\n return { name, version, chainId, verifyingContract: token };\n}\n","// EIP-712 typed-data builder for EIP-2612 `Permit`.\n//\n// Hand-mirrors the standard 5-field shape\n// Permit(address owner, address spender, uint256 value, uint256 nonce, uint256 deadline)\n// which is identical across every well-implemented EIP-2612 token.\n//\n// `@bosonprotocol/core-sdk` exposes the same type-list internally inside\n// `signReceiveWithErc2612Permit` but auto-fetches the `nonce` from the token\n// via an on-chain `nonces(owner)` call before signing. The verification path\n// needs a caller-supplied nonce (so it can rebuild the digest the buyer\n// signed without going on-chain), so this module keeps a standalone\n// typed-data builder. A KAT cross-validation test (`sdk-parity.test.ts`)\n// asserts the type-list matches the SDK's internal one, catching drift if\n// either side ever changes.\n\nimport { hashTypedData, recoverTypedDataAddress, type Address, type Hex } from \"viem\";\n\nimport type { TokenEip712Domain } from \"./domain.js\";\n\nexport const PERMIT_TYPES = {\n Permit: [\n { name: \"owner\", type: \"address\" },\n { name: \"spender\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n} as const;\n\nexport const PERMIT_PRIMARY_TYPE = \"Permit\" as const;\n\nexport interface PermitMessage {\n owner: Address;\n spender: Address;\n value: bigint;\n /** Token-internal sequential nonce — query via `IERC20Permit.nonces(owner)`. */\n nonce: bigint;\n deadline: bigint;\n}\n\nexport interface PermitTypedDataArgs {\n /**\n * The token contract's own EIP-712 domain. EIP-2612 requires\n * `{ name, version, chainId, verifyingContract }` to produce the\n * digest the token recovers on-chain — see {@link TokenEip712Domain}.\n */\n domain: TokenEip712Domain;\n message: PermitMessage;\n}\n\nexport interface PermitTypedData {\n domain: TokenEip712Domain;\n types: typeof PERMIT_TYPES;\n primaryType: typeof PERMIT_PRIMARY_TYPE;\n message: PermitMessage;\n}\n\nexport function permitTypedData({ domain, message }: PermitTypedDataArgs): PermitTypedData {\n return { domain, types: PERMIT_TYPES, primaryType: PERMIT_PRIMARY_TYPE, message };\n}\n\nexport function hashPermit(args: PermitTypedDataArgs): Hex {\n return hashTypedData(permitTypedData(args));\n}\n\nexport async function recoverPermitSigner(\n args: PermitTypedDataArgs & { signature: Hex },\n): Promise<Address> {\n const { signature, ...rest } = args;\n return recoverTypedDataAddress({ ...permitTypedData(rest), signature });\n}\n","// EIP-712 typed-data builder for Uniswap Permit2 `PermitTransferFrom`.\n//\n// Boson uses the no-witness `PermitTransferFrom` flavor per\n// docs/boson-impl-01-escrow-scheme.md §4.3 (the witness-bearing\n// `PermitWitnessTransferFrom` variant is for x402's exact scheme, which\n// pins the recipient inside the witness — Boson doesn't need that since\n// the escrow contract is the only valid recipient anyway).\n//\n// `@bosonprotocol/core-sdk` exposes the same type-list internally inside\n// `signReceiveWithPermit2`, but routes the Permit2 contract address through\n// `_contracts.permit2` (or `overrides.permit2Address`) on the configured\n// SDK instance. The verification path needs a stable canonical address\n// without an SDK round-trip, and the type-list is fixed by Permit2's\n// deployed contract — so this module keeps the canonical address +\n// type-list hand-defined as Uniswap protocol constants. A KAT\n// cross-validation test (`sdk-parity.test.ts`) asserts the type-list\n// matches the SDK's internal one, catching drift.\n//\n// `@x402/evm`'s public `./exact/client` exposes `createPermit2ApprovalTx`\n// and `getPermit2AllowanceReadParams` (re-exported below).\n\nimport { createPermit2ApprovalTx, getPermit2AllowanceReadParams } from \"@x402/evm/exact/client\";\nimport {\n hashTypedData,\n recoverTypedDataAddress,\n type Address,\n type Hex,\n type TypedDataDomain,\n} from \"viem\";\n\nexport { createPermit2ApprovalTx, getPermit2AllowanceReadParams };\n\n/**\n * Canonical Permit2 contract address. Same on every EVM chain via CREATE2\n * deployment.\n *\n * @see https://github.com/Uniswap/permit2\n */\nexport const PERMIT2_ADDRESS: Address = \"0x000000000022D473030F116dDEE9F6B43aC78BA3\";\n\n/** Permit2's EIP-712 `name` field. No `version`, no `salt`. */\nexport const PERMIT2_DOMAIN_NAME = \"Permit2\" as const;\n\nexport const PERMIT2_TYPES = {\n PermitTransferFrom: [\n { name: \"permitted\", type: \"TokenPermissions\" },\n { name: \"spender\", type: \"address\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n TokenPermissions: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n} as const;\n\nexport const PERMIT2_PRIMARY_TYPE = \"PermitTransferFrom\" as const;\n\nexport interface Permit2Message {\n permitted: { token: Address; amount: bigint };\n spender: Address;\n /** Permit2 word-bitmap nonce. */\n nonce: bigint;\n deadline: bigint;\n}\n\nexport interface Permit2TypedDataArgs {\n chainId: number;\n message: Permit2Message;\n}\n\nexport interface Permit2TypedData {\n domain: TypedDataDomain;\n types: typeof PERMIT2_TYPES;\n primaryType: typeof PERMIT2_PRIMARY_TYPE;\n message: Permit2Message;\n}\n\n/** Permit2's EIP-712 domain on a given chain. The `verifyingContract` is the canonical Permit2 address. */\nexport function permit2Domain(chainId: number): TypedDataDomain {\n return { name: PERMIT2_DOMAIN_NAME, chainId, verifyingContract: PERMIT2_ADDRESS };\n}\n\nexport function permit2TypedData({ chainId, message }: Permit2TypedDataArgs): Permit2TypedData {\n return {\n domain: permit2Domain(chainId),\n types: PERMIT2_TYPES,\n primaryType: PERMIT2_PRIMARY_TYPE,\n message,\n };\n}\n\nexport function hashPermit2(args: Permit2TypedDataArgs): Hex {\n return hashTypedData(permit2TypedData(args));\n}\n\nexport async function recoverPermit2Signer(\n args: Permit2TypedDataArgs & { signature: Hex },\n): Promise<Address> {\n const { signature, ...rest } = args;\n return recoverTypedDataAddress({ ...permit2TypedData(rest), signature });\n}\n","// Helper for the `tokenAuthStrategy: \"none\"` flow (per\n// docs/boson-impl-01-escrow-scheme.md §4.3): the buyer must pre-approve\n// the Boson escrow contract to spend `amount` of `token` via the standard\n// ERC-20 `approve(spender, amount)` call.\n//\n// No EIP-712 typed-data is signed for this strategy; the buyer instead\n// sends a regular ERC-20 transaction. This module just builds the calldata\n// so callers can hand it to a wallet client.\n\nimport { encodeFunctionData, type Address, type Hex } from \"viem\";\n\nconst ERC20_APPROVE_ABI = [\n {\n type: \"function\",\n name: \"approve\",\n stateMutability: \"nonpayable\",\n inputs: [\n { name: \"spender\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n outputs: [{ type: \"bool\" }],\n },\n] as const;\n\nexport interface Erc20ApprovalArgs {\n token: Address;\n spender: Address;\n amount: bigint;\n}\n\n/**\n * Build calldata for an ERC-20 `approve(spender, amount)` call. Use with\n * `walletClient.sendTransaction({ to: token, data })` or any equivalent\n * signer to grant `spender` (the Boson escrow contract) the right to\n * pull `amount` of `token`.\n */\nexport function createErc20ApprovalTx({ token, spender, amount }: Erc20ApprovalArgs): {\n to: Address;\n data: Hex;\n} {\n return {\n to: token,\n data: encodeFunctionData({\n abi: ERC20_APPROVE_ABI,\n functionName: \"approve\",\n args: [spender, amount],\n }),\n };\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Custom header `@bosonprotocol/x402-client-fetch` stamps on both the
3
+ * initial request and the X-PAYMENT retry. Resource servers that scope
4
+ * their `FullOffer` cache per buyer flow key the cache off this id so
5
+ * the 402 challenge and the X-PAYMENT retry share one signed offer.
6
+ *
7
+ * The canonical value uses mixed case for header readability; HTTP
8
+ * header lookups are case-insensitive on both Node (`req.headers[…]`
9
+ * are already lowercased) and Express (`req.header(…)`), so importers
10
+ * can pass the constant verbatim regardless of which lookup style they
11
+ * use.
12
+ */
13
+ declare const SESSION_ID_HEADER = "X-X402-Boson-Session-Id";
14
+
15
+ export { SESSION_ID_HEADER };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ // src/headers.ts
4
+ var SESSION_ID_HEADER = "X-X402-Boson-Session-Id";
5
+
6
+ exports.SESSION_ID_HEADER = SESSION_ID_HEADER;
7
+ //# sourceMappingURL=index.js.map
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/headers.ts"],"names":[],"mappings":";;;AAiBO,IAAM,iBAAA,GAAoB","file":"index.js","sourcesContent":["// Shared HTTP header names that span the buyer-side fetch wrapper and\n// any resource server / facilitator implementing the x402B escrow\n// scheme. Centralising them here keeps the wire contract single-sourced\n// across packages.\n\n/**\n * Custom header `@bosonprotocol/x402-client-fetch` stamps on both the\n * initial request and the X-PAYMENT retry. Resource servers that scope\n * their `FullOffer` cache per buyer flow key the cache off this id so\n * the 402 challenge and the X-PAYMENT retry share one signed offer.\n *\n * The canonical value uses mixed case for header readability; HTTP\n * header lookups are case-insensitive on both Node (`req.headers[…]`\n * are already lowercased) and Express (`req.header(…)`), so importers\n * can pass the constant verbatim regardless of which lookup style they\n * use.\n */\nexport const SESSION_ID_HEADER = \"X-X402-Boson-Session-Id\";\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }