@devlab.group/agent-commerce 2.1.0 → 2.2.1
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 +35 -5
- package/dist/ap2.js +3 -3
- package/dist/{chunk-LZS5BL3W.js → chunk-2DAJAJI7.js} +23 -5
- package/dist/chunk-2DAJAJI7.js.map +1 -0
- package/dist/{chunk-UHMYRV3J.js → chunk-BNUD4RBN.js} +22 -7
- package/dist/chunk-BNUD4RBN.js.map +1 -0
- package/dist/{chunk-IFGRCXME.js → chunk-REBY2IEP.js} +24 -20
- package/dist/chunk-REBY2IEP.js.map +1 -0
- package/dist/{chunk-SY6GUYSQ.js → chunk-XYHDQ22D.js} +3 -3
- package/dist/{chunk-SY6GUYSQ.js.map → chunk-XYHDQ22D.js.map} +1 -1
- package/dist/cli/ap2-HLBIUSTK.js +678 -0
- package/dist/cli/ap2-HLBIUSTK.js.map +1 -0
- package/dist/cli/chunk-2LN5PO5I.js +1352 -0
- package/dist/cli/chunk-2LN5PO5I.js.map +1 -0
- package/dist/cli/chunk-3EQBCFZY.js +53 -0
- package/dist/cli/chunk-3EQBCFZY.js.map +1 -0
- package/dist/cli/chunk-3M6U7ILB.js +8 -0
- package/dist/cli/chunk-3M6U7ILB.js.map +1 -0
- package/dist/cli/chunk-3MGAJ5FX.js +70 -0
- package/dist/cli/chunk-3MGAJ5FX.js.map +1 -0
- package/dist/cli/chunk-5K4XEAZV.js +113 -0
- package/dist/cli/chunk-5K4XEAZV.js.map +1 -0
- package/dist/cli/chunk-AA3FIEAR.js +27 -0
- package/dist/cli/chunk-AA3FIEAR.js.map +1 -0
- package/dist/cli/chunk-FHCFR2GS.js +17 -0
- package/dist/cli/chunk-FHCFR2GS.js.map +1 -0
- package/dist/cli/chunk-ILUYEQSV.js +1744 -0
- package/dist/cli/chunk-ILUYEQSV.js.map +1 -0
- package/dist/cli/chunk-KTV52MCU.js +338 -0
- package/dist/cli/chunk-KTV52MCU.js.map +1 -0
- package/dist/cli/chunk-OSTCU6ZK.js +44 -0
- package/dist/cli/chunk-OSTCU6ZK.js.map +1 -0
- package/dist/cli/chunk-OZ4LAWBK.js +256 -0
- package/dist/cli/chunk-OZ4LAWBK.js.map +1 -0
- package/dist/cli/chunk-QQ3WY5L3.js +271 -0
- package/dist/cli/chunk-QQ3WY5L3.js.map +1 -0
- package/dist/cli/chunk-QY3K6PEQ.js +8 -0
- package/dist/cli/chunk-QY3K6PEQ.js.map +1 -0
- package/dist/cli/chunk-QZ6TOMX6.js +1413 -0
- package/dist/cli/chunk-QZ6TOMX6.js.map +1 -0
- package/dist/cli/chunk-SNM3OVCY.js +625 -0
- package/dist/cli/chunk-SNM3OVCY.js.map +1 -0
- package/dist/cli/chunk-SPAYKVUP.js +118 -0
- package/dist/cli/chunk-SPAYKVUP.js.map +1 -0
- package/dist/cli/chunk-TPC4EJLT.js +11 -0
- package/dist/cli/chunk-TPC4EJLT.js.map +1 -0
- package/dist/cli/config-VYAJGZXE.js +11 -0
- package/dist/cli/config-VYAJGZXE.js.map +1 -0
- package/dist/cli/index.js +150 -3627
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/mcp-HFD7ZNCQ.js +559 -0
- package/dist/cli/mcp-HFD7ZNCQ.js.map +1 -0
- package/dist/cli/near-5AY3HWYF.js +58 -0
- package/dist/cli/near-5AY3HWYF.js.map +1 -0
- package/dist/cli/provider-JV5HCQGR.js +396 -0
- package/dist/cli/provider-JV5HCQGR.js.map +1 -0
- package/dist/cli/run-WV44B62Y.js +7301 -0
- package/dist/cli/run-WV44B62Y.js.map +1 -0
- package/dist/cli/svm-3MMYFPC7.js +33 -0
- package/dist/cli/svm-3MMYFPC7.js.map +1 -0
- package/dist/cli/x402-NADFV5CD.js +96 -0
- package/dist/cli/x402-NADFV5CD.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +82 -11
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +6 -16
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.js +3 -3
- package/dist/{networks-olfflCI_.d.ts → networks-DTWRlj-K.d.ts} +2 -2
- package/dist/x402.d.ts +7 -2
- package/dist/x402.js +4 -4
- package/package.json +2 -2
- package/dist/chunk-IFGRCXME.js.map +0 -1
- package/dist/chunk-LZS5BL3W.js.map +0 -1
- package/dist/chunk-UHMYRV3J.js.map +0 -1
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { ANVIL_WELL_KNOWN_ACCOUNTS, requireX402Network, resolveDeploymentMode, LOCAL_CHAIN_ID, isBurnAddress, sameAddress, normalizeAddress } from './chunk-OZ4LAWBK.js';
|
|
2
|
+
import { CommerceError } from './chunk-QQ3WY5L3.js';
|
|
3
|
+
|
|
4
|
+
// src/payments/x402/dev-key-guard.ts
|
|
5
|
+
var WELL_KNOWN_DEV_KEYS = new Set(
|
|
6
|
+
ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.privateKey.toLowerCase())
|
|
7
|
+
);
|
|
8
|
+
var WELL_KNOWN_DEV_ADDRESSES = new Set(
|
|
9
|
+
ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.address.toLowerCase())
|
|
10
|
+
);
|
|
11
|
+
var PRIVATE_KEY_SHAPE = /^0x[0-9a-fA-F]{64}$/;
|
|
12
|
+
function isWellKnownDevKey(privateKey) {
|
|
13
|
+
return WELL_KNOWN_DEV_KEYS.has(privateKey.toLowerCase());
|
|
14
|
+
}
|
|
15
|
+
function isWellKnownDevAddress(address) {
|
|
16
|
+
return WELL_KNOWN_DEV_ADDRESSES.has(address.toLowerCase());
|
|
17
|
+
}
|
|
18
|
+
function isLikelyLocalOrPrivateHost(hostname) {
|
|
19
|
+
const h = hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
20
|
+
if (h === "localhost" || h === "::1") return true;
|
|
21
|
+
if (/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(h)) return true;
|
|
22
|
+
if (/^10\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(h)) return true;
|
|
23
|
+
if (/^192\.168\.\d{1,3}\.\d{1,3}$/.test(h)) return true;
|
|
24
|
+
if (/^172\.(1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}$/.test(h)) return true;
|
|
25
|
+
if (!h.includes(".") && !h.includes(":")) return true;
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function parseHostnameOrThrow(rpcUrl) {
|
|
29
|
+
try {
|
|
30
|
+
return new URL(rpcUrl).hostname;
|
|
31
|
+
} catch (cause) {
|
|
32
|
+
throw new CommerceError("CONFIG_INVALID", "x402 provider: rpcUrl is not a valid URL", {
|
|
33
|
+
cause
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function describeRpc(rpcUrl) {
|
|
38
|
+
try {
|
|
39
|
+
return new URL(rpcUrl).origin;
|
|
40
|
+
} catch {
|
|
41
|
+
return "[unparseable rpcUrl]";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function assertDevKeyIsLocalOnly(rpcUrl, signerPrivateKey) {
|
|
45
|
+
if (!PRIVATE_KEY_SHAPE.test(signerPrivateKey)) {
|
|
46
|
+
throw new CommerceError(
|
|
47
|
+
"CONFIG_INVALID",
|
|
48
|
+
'x402 provider: facilitator.signerPrivateKey is not a well-formed private key (expected "0x" followed by exactly 64 hex characters).'
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (!isWellKnownDevKey(signerPrivateKey)) return;
|
|
52
|
+
const hostname = parseHostnameOrThrow(rpcUrl);
|
|
53
|
+
if (!isLikelyLocalOrPrivateHost(hostname)) {
|
|
54
|
+
throw new CommerceError(
|
|
55
|
+
"CONFIG_INVALID",
|
|
56
|
+
`x402 provider: facilitator.signerPrivateKey is a well-known Anvil development key, but rpcUrl ${describeRpc(rpcUrl)} does not look like a local/private chain. A public dev key must never sign against a public network: it is instantly drainable and can grief real settlements via nonce exhaustion. Use a real facilitator key for any non-local RPC, or point rpcUrl at your local/dev chain.`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function assertPayToIsNotDevAddress(rpcUrl, payTo) {
|
|
61
|
+
if (!isWellKnownDevAddress(payTo)) return;
|
|
62
|
+
const hostname = parseHostnameOrThrow(rpcUrl);
|
|
63
|
+
if (!isLikelyLocalOrPrivateHost(hostname)) {
|
|
64
|
+
throw new CommerceError(
|
|
65
|
+
"CONFIG_INVALID",
|
|
66
|
+
`x402 provider: "payTo" (${payTo}) is a well-known Anvil development address, but rpcUrl ${describeRpc(rpcUrl)} does not look like a local/private chain. The private key behind that address is public knowledge, so any revenue settled to it is immediately spendable by anyone. Set "payTo" to your own merchant wallet for any non-local RPC, or point rpcUrl at your local/dev chain.`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/payments/x402/guardrails.ts
|
|
72
|
+
var BASE_SEPOLIA = "eip155:84532";
|
|
73
|
+
function invalid(message, path) {
|
|
74
|
+
return new CommerceError("CONFIG_INVALID", message, { details: { path } });
|
|
75
|
+
}
|
|
76
|
+
function resolveX402Deployment(input) {
|
|
77
|
+
const at = input.configPath ?? "payments.x402";
|
|
78
|
+
const payTo = input.payToField ?? "payTo";
|
|
79
|
+
const profile = requireX402Network(input.network, `${at}.network`, input.customNetworks);
|
|
80
|
+
const mode = resolveDeploymentMode(profile);
|
|
81
|
+
if (profile.kind === "mainnet" && input.facilitator.mode === "local") {
|
|
82
|
+
throw invalid(
|
|
83
|
+
`${at}: network "${profile.id}" (${profile.displayName}) is a mainnet and cannot be served by facilitator.mode "local". A mainnet deployment must settle through a remote facilitator.`,
|
|
84
|
+
`${at}.facilitator.mode`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (input.facilitator.mode === "local" && mode !== "local") {
|
|
88
|
+
throw invalid(
|
|
89
|
+
profile.id === BASE_SEPOLIA ? `${at}: the local Anvil chain is eip155:${LOCAL_CHAIN_ID}, Anvil's default chain id; "${BASE_SEPOLIA}" is public Base Sepolia. Set ${at}.network to eip155:${LOCAL_CHAIN_ID}, start Anvil with its default chain id and redeploy the local contracts (npm run chain:start, npm run chain:deploy).` : `${at}: facilitator.mode "local" serves the local Anvil chain (eip155:${LOCAL_CHAIN_ID}) only, not "${profile.id}" (${profile.displayName}). Use a remote facilitator.`,
|
|
90
|
+
`${at}.facilitator.mode`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (mode === "mainnet" && input.allowMainnet !== true) {
|
|
94
|
+
throw invalid(
|
|
95
|
+
`${at}: network "${profile.id}" (${profile.displayName}) settles real funds. Set ${at}.allowMainnet: true to acknowledge this explicitly - it is never the default.`,
|
|
96
|
+
`${at}.allowMainnet`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (input.facilitator.mode === "remote") {
|
|
100
|
+
assertFacilitatorUrlIsSafe(input.facilitator.url, mode, at);
|
|
101
|
+
if (input.facilitator.auth.type === "cdp" && !isCdpFacilitatorUrl(input.facilitator.url)) {
|
|
102
|
+
throw invalid(
|
|
103
|
+
`${at}: facilitator.auth.type "cdp" signs requests for ${CDP_FACILITATOR_URL} only, so facilitator ${describeOrigin(input.facilitator.url)} cannot accept its credential. Set facilitator.url to ${CDP_FACILITATOR_URL}, or use auth.type "bearer" or "none".`,
|
|
104
|
+
`${at}.facilitator.url`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (mode === "mainnet" && input.facilitator.auth.type === "none" && input.allowUnauthenticatedFacilitator !== true) {
|
|
108
|
+
throw invalid(
|
|
109
|
+
`${at}: no credential is configured for facilitator ${describeOrigin(input.facilitator.url)} on mainnet. Set ${at}.allowUnauthenticatedFacilitator: true to accept anonymous access and the facilitator's limits, or configure facilitator.auth.`,
|
|
110
|
+
`${at}.allowUnauthenticatedFacilitator`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
for (const [field, value] of credentialFields(input.facilitator.auth)) {
|
|
114
|
+
if (value.trim() === "") {
|
|
115
|
+
throw invalid(
|
|
116
|
+
`${at}: facilitator.auth.type is "${input.facilitator.auth.type}" but ${field} is empty. An empty credential is refused rather than sent.`,
|
|
117
|
+
`${at}.facilitator.auth.${field}`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (isBurnAddress(profile, input.payTo)) {
|
|
123
|
+
throw invalid(
|
|
124
|
+
`${at}: "${payTo}" is the zero address. Every payment settled there is destroyed.`,
|
|
125
|
+
`${at}.${payTo}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
if (mode !== "local" && isWellKnownDevAddress(input.payTo)) {
|
|
129
|
+
throw invalid(
|
|
130
|
+
`${at}: "${payTo}" (${input.payTo}) is a well-known Anvil development address and this is a ${mode} deployment. Anyone can spend what settles there. Set ${payTo} to your own merchant wallet.`,
|
|
131
|
+
`${at}.${payTo}`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const canonical = profile.canonicalAsset;
|
|
135
|
+
if (canonical) {
|
|
136
|
+
if (!sameAddress(profile, input.asset, canonical.address)) {
|
|
137
|
+
if (input.allowOtherEvmToken !== true || profile.family !== "evm") {
|
|
138
|
+
const rule = input.allowOtherEvmToken === true ? `Only an EVM network accepts another token; ${profile.displayName} settles only in its ${canonical.symbol}.` : `A built-in network settles only in its ${canonical.symbol}.`;
|
|
139
|
+
throw invalid(
|
|
140
|
+
`${at}: asset ${input.asset} is not ${canonical.symbol} on ${profile.displayName} (expected ${canonical.address}). ${rule}`,
|
|
141
|
+
`${at}.asset`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
const domain = "name" in canonical ? canonical : void 0;
|
|
146
|
+
if (domain && input.assetName !== void 0 && input.assetName !== domain.name) {
|
|
147
|
+
throw invalid(
|
|
148
|
+
`${at}: assetName "${input.assetName}" is not the EIP-712 domain name ${canonical.symbol} reports on ${profile.displayName} (expected "${domain.name}"). Every payment would be refused after the buyer signed.`,
|
|
149
|
+
`${at}.assetName`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (domain && input.assetVersion !== void 0 && input.assetVersion !== domain.version) {
|
|
153
|
+
throw invalid(
|
|
154
|
+
`${at}: assetVersion "${input.assetVersion}" is not the EIP-712 domain version ${canonical.symbol} reports on ${profile.displayName} (expected "${domain.version}").`,
|
|
155
|
+
`${at}.assetVersion`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return { profile, mode };
|
|
161
|
+
}
|
|
162
|
+
function assertFacilitatorUrlIsSafe(url, mode, at) {
|
|
163
|
+
let parsed;
|
|
164
|
+
try {
|
|
165
|
+
parsed = new URL(url);
|
|
166
|
+
} catch (cause) {
|
|
167
|
+
throw new CommerceError("CONFIG_INVALID", `${at}: facilitator.url is not a valid URL`, {
|
|
168
|
+
cause,
|
|
169
|
+
details: { path: `${at}.facilitator.url` }
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (parsed.protocol === "https:") return;
|
|
173
|
+
if (parsed.protocol !== "http:") {
|
|
174
|
+
throw invalid(
|
|
175
|
+
`${at}: facilitator ${describeOrigin(url)} must be reached over https (or http on a local/private host); got "${parsed.protocol}//"`,
|
|
176
|
+
`${at}.facilitator.url`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
if (mode !== "mainnet" && isLikelyLocalOrPrivateHost(parsed.hostname)) return;
|
|
180
|
+
throw invalid(
|
|
181
|
+
`${at}: facilitator ${describeOrigin(url)} is reached over plain HTTP. Payment authorizations and settlement results would travel unencrypted. Use https, or point at a local/private host on a non-mainnet deployment.`,
|
|
182
|
+
`${at}.facilitator.url`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
var CDP_FACILITATOR_URL = "https://api.cdp.coinbase.com/platform/v2/x402";
|
|
186
|
+
function isCdpFacilitatorUrl(url) {
|
|
187
|
+
try {
|
|
188
|
+
const parsed = new URL(url);
|
|
189
|
+
const expected = new URL(CDP_FACILITATOR_URL);
|
|
190
|
+
return parsed.origin === expected.origin && parsed.pathname.replace(/\/+$/, "") === expected.pathname && parsed.search === "";
|
|
191
|
+
} catch {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function describeOrigin(url) {
|
|
196
|
+
try {
|
|
197
|
+
return new URL(url).origin;
|
|
198
|
+
} catch {
|
|
199
|
+
return "[unparseable facilitator.url]";
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function credentialFields(auth) {
|
|
203
|
+
switch (auth.type) {
|
|
204
|
+
case "bearer":
|
|
205
|
+
return [["token", auth.token]];
|
|
206
|
+
case "cdp":
|
|
207
|
+
return [
|
|
208
|
+
["apiKeyId", auth.apiKeyId],
|
|
209
|
+
["apiKeySecret", auth.apiKeySecret]
|
|
210
|
+
];
|
|
211
|
+
default:
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/payments/x402/options.ts
|
|
217
|
+
function x402OfferName(offer) {
|
|
218
|
+
const evm = offer.network.startsWith("eip155:");
|
|
219
|
+
const address = (value) => evm ? value.toLowerCase() : value;
|
|
220
|
+
return `${offer.network} ${address(offer.asset)} ${address(offer.payTo)}`;
|
|
221
|
+
}
|
|
222
|
+
var FIELD_MEANINGS = {
|
|
223
|
+
assetName: "EIP-712 domain name",
|
|
224
|
+
assetVersion: "EIP-712 domain version",
|
|
225
|
+
assetDecimals: "decimals"
|
|
226
|
+
};
|
|
227
|
+
var ADDRESS_SHAPES = {
|
|
228
|
+
evm: '"0x" followed by 40 hex characters',
|
|
229
|
+
svm: "a base58 public key of 32 bytes",
|
|
230
|
+
near: 'a NEAR account ID: 2 to 64 lowercase characters, digits and single "-", "_" or "." separators'
|
|
231
|
+
};
|
|
232
|
+
function invalid2(message, path) {
|
|
233
|
+
return new CommerceError("CONFIG_INVALID", message, { details: { path } });
|
|
234
|
+
}
|
|
235
|
+
function resolveX402Option(input, path, custom) {
|
|
236
|
+
if (input.scheme !== void 0 && input.scheme !== "exact") {
|
|
237
|
+
throw invalid2(
|
|
238
|
+
`${path}.scheme: "${input.scheme}" is not supported; the only x402 scheme is "exact"`,
|
|
239
|
+
`${path}.scheme`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
const network = requireX402Network(input.network, `${path}.network`, custom);
|
|
243
|
+
const address = (field, value) => {
|
|
244
|
+
const wire = normalizeAddress(network, value);
|
|
245
|
+
if (wire === void 0) {
|
|
246
|
+
throw invalid2(
|
|
247
|
+
// The value is not echoed: a swapped variable could put a key here
|
|
248
|
+
`${path}.${field} is not a plausible address on ${network.displayName} (expected ${ADDRESS_SHAPES[network.family]})`,
|
|
249
|
+
`${path}.${field}`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
return wire;
|
|
253
|
+
};
|
|
254
|
+
const payTo = address("payTo", input.payTo);
|
|
255
|
+
if (isBurnAddress(network, payTo)) {
|
|
256
|
+
throw invalid2(
|
|
257
|
+
`${path}.payTo is the zero address of ${network.displayName}. Every payment settled there is destroyed.`,
|
|
258
|
+
`${path}.payTo`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
const method = input.assetTransferMethod ?? "eip3009";
|
|
262
|
+
if (method !== "eip3009" && method !== "permit2") {
|
|
263
|
+
throw invalid2(
|
|
264
|
+
`${path}.assetTransferMethod: "${method}" is not supported; use "eip3009" or "permit2"`,
|
|
265
|
+
`${path}.assetTransferMethod`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
if (network.family !== "evm" && input.assetTransferMethod !== void 0) {
|
|
269
|
+
throw invalid2(
|
|
270
|
+
`${path}.assetTransferMethod applies to EVM networks only, not to ${network.displayName}`,
|
|
271
|
+
`${path}.assetTransferMethod`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
if (network.family !== "evm") {
|
|
275
|
+
for (const field of ["assetName", "assetVersion"]) {
|
|
276
|
+
if (input[field] !== void 0) {
|
|
277
|
+
throw invalid2(
|
|
278
|
+
`${path}.${field}: an EIP-712 domain applies to EVM tokens only, not to ${network.displayName}`,
|
|
279
|
+
`${path}.${field}`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const canonical = network.canonicalAsset;
|
|
285
|
+
const domain = canonical && "name" in canonical ? canonical : void 0;
|
|
286
|
+
const asset = input.asset !== void 0 ? address("asset", input.asset) : void 0;
|
|
287
|
+
if (asset !== void 0 && isBurnAddress(network, asset)) {
|
|
288
|
+
throw invalid2(`${path}.asset must not be the zero address`, `${path}.asset`);
|
|
289
|
+
}
|
|
290
|
+
if (canonical && (asset === void 0 || sameAddress(network, asset, canonical.address))) {
|
|
291
|
+
const expected = {
|
|
292
|
+
assetName: domain?.name,
|
|
293
|
+
assetVersion: domain?.version,
|
|
294
|
+
assetDecimals: canonical.decimals
|
|
295
|
+
};
|
|
296
|
+
for (const field of ["assetName", "assetVersion", "assetDecimals"]) {
|
|
297
|
+
const given = input[field];
|
|
298
|
+
if (given !== void 0 && given !== expected[field]) {
|
|
299
|
+
throw invalid2(
|
|
300
|
+
`${path}.${field} does not match ${canonical.symbol} on ${network.displayName}, which reports ${FIELD_MEANINGS[field]} ${JSON.stringify(expected[field])}. Remove ${field}, or set asset to the token it describes.`,
|
|
301
|
+
`${path}.${field}`
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
scheme: "exact",
|
|
307
|
+
network,
|
|
308
|
+
payTo,
|
|
309
|
+
asset: asset ?? canonical.address,
|
|
310
|
+
...domain ? { assetName: domain.name, assetVersion: domain.version } : {},
|
|
311
|
+
assetDecimals: canonical.decimals,
|
|
312
|
+
defaultAssetSymbol: canonical.symbol,
|
|
313
|
+
assetTransferMethod: method
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
const required = network.family === "evm" && method === "eip3009" ? ["asset", "assetName", "assetVersion", "assetDecimals"] : ["asset", "assetDecimals"];
|
|
317
|
+
const missing = required.filter((field) => input[field] === void 0);
|
|
318
|
+
if (asset === void 0 || missing.length > 0) {
|
|
319
|
+
throw invalid2(
|
|
320
|
+
canonical ? `${path}: a token other than ${canonical.symbol} on ${network.displayName} needs ${missing.join(", ")}` : `${path}: ${network.displayName} has no default asset, so the option needs ${missing.join(", ")}`,
|
|
321
|
+
`${path}.${missing[0] ?? "asset"}`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
scheme: "exact",
|
|
326
|
+
network,
|
|
327
|
+
payTo,
|
|
328
|
+
asset,
|
|
329
|
+
...input.assetName !== void 0 ? { assetName: input.assetName } : {},
|
|
330
|
+
...input.assetVersion !== void 0 ? { assetVersion: input.assetVersion } : {},
|
|
331
|
+
assetDecimals: input.assetDecimals,
|
|
332
|
+
assetTransferMethod: method
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export { assertDevKeyIsLocalOnly, assertPayToIsNotDevAddress, describeRpc, resolveX402Deployment, resolveX402Option, x402OfferName };
|
|
337
|
+
//# sourceMappingURL=chunk-KTV52MCU.js.map
|
|
338
|
+
//# sourceMappingURL=chunk-KTV52MCU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/payments/x402/dev-key-guard.ts","../../src/payments/x402/guardrails.ts","../../src/payments/x402/options.ts"],"names":["invalid"],"mappings":";;;;AAWA,IAAM,sBAA2C,IAAI,GAAA;AAAA,EACnD,0BAA0B,GAAA,CAAI,CAAC,MAAM,CAAA,CAAE,UAAA,CAAW,aAAa;AACjE,CAAA;AAEA,IAAM,2BAAgD,IAAI,GAAA;AAAA,EACxD,0BAA0B,GAAA,CAAI,CAAC,MAAM,CAAA,CAAE,OAAA,CAAQ,aAAa;AAC9D,CAAA;AAGA,IAAM,iBAAA,GAAoB,qBAAA;AAEnB,SAAS,kBAAkB,UAAA,EAA6B;AAC7D,EA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R,OAAA;AAAA,IACA,KAAA;AAAA,IACA,KAAA;AAAA,IACA,GAAI,MAAM,SAAA,KAAc,MAAA,GAAY,EAAE,SAAA,EAAW,KAAA,CAAM,SAAA,EAAU,GAAI,EAAC;AAAA,IACtE,GAAI,MAAM,YAAA,KAAiB,MAAA,GAAY,EAAE,YAAA,EAAc,KAAA,CAAM,YAAA,EAAa,GAAI,EAAC;AAAA,IAC/E,eAAe,KAAA,CAAM,aAAA;AAAA,IACrB,mBAAA,EAAqB;AAAA,GACvB;AACF","file":"chunk-KTV52MCU.js","sourcesContent":["/**\n * Rejects well-known Anvil keys and payment destinations when the RPC host\n * does not look local or private. Their private keys are published, so anyone\n * can spend what such an address receives on a public chain.\n *\n * The check uses the RPC hostname because the local chain shares Base\n * Sepolia's chain id. Both guards run at provider construction.\n */\nimport { CommerceError } from '../../core';\nimport { ANVIL_WELL_KNOWN_ACCOUNTS } from './local-chain/accounts';\n\nconst WELL_KNOWN_DEV_KEYS: ReadonlySet<string> = new Set(\n ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.privateKey.toLowerCase()),\n);\n\nconst WELL_KNOWN_DEV_ADDRESSES: ReadonlySet<string> = new Set(\n ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.address.toLowerCase()),\n);\n\n// `0x` plus 64 hex characters, the only shape `privateKeyToAccount` accepts\nconst PRIVATE_KEY_SHAPE = /^0x[0-9a-fA-F]{64}$/;\n\nexport function isWellKnownDevKey(privateKey: string): boolean {\n return WELL_KNOWN_DEV_KEYS.has(privateKey.toLowerCase());\n}\n\nexport function isWellKnownDevAddress(address: string): boolean {\n return WELL_KNOWN_DEV_ADDRESSES.has(address.toLowerCase());\n}\n\n/**\n * True for loopback addresses, RFC 1918 private ranges, and bare (dot-free)\n * hostnames, such as the compose service name \"anvil\".\n *\n * Bare hostnames are treated as local without resolving them. Operators must\n * point them at a private chain.\n */\nexport function isLikelyLocalOrPrivateHost(hostname: string): boolean {\n const h = hostname.toLowerCase().replace(/^\\[|\\]$/g, '');\n if (h === 'localhost' || h === '::1') return true;\n if (/^127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^192\\.168\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^172\\.(1[6-9]|2\\d|3[01])\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (!h.includes('.') && !h.includes(':')) return true; // bare hostname\n return false;\n}\n\nfunction parseHostnameOrThrow(rpcUrl: string): string {\n try {\n return new URL(rpcUrl).hostname;\n } catch (cause) {\n // Never the URL itself: RPC providers commonly put an API key in the path,\n // and this message reaches startup output and CI logs\n throw new CommerceError('CONFIG_INVALID', 'x402 provider: rpcUrl is not a valid URL', {\n cause,\n });\n }\n}\n\n/** Origin only, for diagnostics: RPC URLs often carry an API key in the path or query */\nexport function describeRpc(rpcUrl: string): string {\n try {\n return new URL(rpcUrl).origin;\n } catch {\n return '[unparseable rpcUrl]';\n }\n}\n\n/**\n * Throws CONFIG_INVALID if `signerPrivateKey` is not shaped like a private key,\n * or if it is a well-known dev key and the RPC is not local.\n *\n * The shape check runs first, so a truncated key is reported as malformed\n * instead of passing as \"not a dev key\".\n */\nexport function assertDevKeyIsLocalOnly(rpcUrl: string, signerPrivateKey: string): void {\n if (!PRIVATE_KEY_SHAPE.test(signerPrivateKey)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: facilitator.signerPrivateKey is not a well-formed private key ' +\n '(expected \"0x\" followed by exactly 64 hex characters).',\n );\n }\n\n if (!isWellKnownDevKey(signerPrivateKey)) return; // the operator's own key\n\n const hostname = parseHostnameOrThrow(rpcUrl);\n\n if (!isLikelyLocalOrPrivateHost(hostname)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: facilitator.signerPrivateKey is a well-known Anvil development key, but rpcUrl ' +\n `${describeRpc(rpcUrl)} does not look like a local/private chain. A public dev key must never sign against ` +\n 'a public network: it is instantly drainable and can grief real settlements via nonce exhaustion. ' +\n 'Use a real facilitator key for any non-local RPC, or point rpcUrl at your local/dev chain.',\n );\n }\n}\n\n/**\n * Throws CONFIG_INVALID if `payTo` is a well-known Anvil address and `rpcUrl`\n * does not look local or private.\n *\n * Guards the receiving side, in every facilitator mode. `agent-commerce init`\n * defaults `payTo` to a well-known address for the local demo, and on a real\n * network that default sends every payment where anyone can sweep it.\n */\nexport function assertPayToIsNotDevAddress(rpcUrl: string, payTo: string): void {\n if (!isWellKnownDevAddress(payTo)) return;\n\n const hostname = parseHostnameOrThrow(rpcUrl);\n\n if (!isLikelyLocalOrPrivateHost(hostname)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `x402 provider: \"payTo\" (${payTo}) is a well-known Anvil development address, but rpcUrl ` +\n `${describeRpc(rpcUrl)} does not look like a local/private chain. The private key behind that address ` +\n 'is public knowledge, so any revenue settled to it is immediately spendable by anyone. Set ' +\n '\"payTo\" to your own merchant wallet for any non-local RPC, or point rpcUrl at your ' +\n 'local/dev chain.',\n );\n }\n}\n","/**\n * What must hold before this gateway may settle a payment on the configured\n * network. Two callers share these checks: the provider runs them at\n * construction, so a library consumer who skips our config loader still gets\n * them, and the config loader runs them, so `validate` and `doctor` report\n * them too.\n *\n * Both run before any request, because a failure found in `settle()` would\n * come after the pipeline reserved the buyer's replay key.\n *\n * Imports no peer (no viem, no `@x402/*`), so the CLI can load it.\n */\nimport { CommerceError } from '../../core';\nimport { isBurnAddress, sameAddress } from './addresses';\nimport { isLikelyLocalOrPrivateHost, isWellKnownDevAddress } from './dev-key-guard';\nimport {\n type CustomNetworks,\n type DeploymentMode,\n LOCAL_CHAIN_ID,\n requireX402Network,\n resolveDeploymentMode,\n type X402Network,\n} from './networks';\n\n/**\n * How the gateway authenticates to a remote facilitator.\n *\n * - `none`: send no credential; use it when the facilitator accepts\n * anonymous requests.\n * - `bearer`: send a static token; no extra peer package is needed.\n * - `cdp`: Coinbase Developer Platform. The optional peer `@coinbase/x402`,\n * imported only for this type, signs a fresh JWT per request.\n *\n * Any other auth type is refused at config load.\n */\nexport type FacilitatorAuth =\n | { readonly type: 'none' }\n | { readonly type: 'bearer'; readonly token: string }\n | { readonly type: 'cdp'; readonly apiKeyId: string; readonly apiKeySecret: string };\n\nexport type X402FacilitatorConfig =\n | { readonly mode: 'local'; readonly signerPrivateKey: string }\n | { readonly mode: 'remote'; readonly url: string; readonly auth: FacilitatorAuth };\n\nexport interface X402DeploymentInput {\n readonly network: string;\n readonly payTo: string;\n readonly asset: string;\n /** EIP-712 domain of the asset, as the token itself reports it */\n readonly assetName?: string;\n readonly assetVersion?: string;\n readonly facilitator: X402FacilitatorConfig;\n /** Must be `true` before anything settles on a mainnet */\n readonly allowMainnet?: boolean;\n /**\n * Must be `true` on mainnet when facilitator auth is `none`. A separate\n * decision from `allowMainnet`: it accepts settling without an account at\n * the facilitator, under its anonymous-access limits.\n */\n readonly allowUnauthenticatedFacilitator?: boolean;\n /**\n * Allow other tokens on built-in EVM networks with explicit metadata.\n * MPP config leaves this unset; Solana and NEAR still require USDC.\n */\n readonly allowOtherEvmToken?: boolean;\n /** Error-path prefix, `payments.x402` by default */\n readonly configPath?: string;\n /** Settlement-recipient field named in errors, `payTo` by default */\n readonly payToField?: string;\n /** EVM networks declared under `payments.x402.networks` */\n readonly customNetworks?: CustomNetworks;\n}\n\nexport interface X402Deployment {\n readonly profile: X402Network;\n readonly mode: DeploymentMode;\n}\n\nconst BASE_SEPOLIA = 'eip155:84532';\n\nfunction invalid(message: string, path: string): CommerceError {\n return new CommerceError('CONFIG_INVALID', message, { details: { path } });\n}\n\n/**\n * Resolves the deployment and refuses the combinations that could move real\n * money by accident. The network must resolve first; the other checks are\n * independent.\n */\nexport function resolveX402Deployment(input: X402DeploymentInput): X402Deployment {\n const at = input.configPath ?? 'payments.x402';\n const payTo = input.payToField ?? 'payTo';\n const profile = requireX402Network(input.network, `${at}.network`, input.customNetworks);\n const mode = resolveDeploymentMode(profile);\n\n // Local mode keeps a gas-paying key in the gateway process. A compromise\n // could expose that key, so mainnet requires a remote facilitator.\n if (profile.kind === 'mainnet' && input.facilitator.mode === 'local') {\n throw invalid(\n `${at}: network \"${profile.id}\" (${profile.displayName}) is a mainnet and cannot be served by facilitator.mode \"local\". A mainnet deployment must settle through a remote facilitator.`,\n `${at}.facilitator.mode`,\n );\n }\n // The in-process facilitator signs with a client built for the Anvil chain\n // id, so on any other chain every settlement would fail\n if (input.facilitator.mode === 'local' && mode !== 'local') {\n throw invalid(\n profile.id === BASE_SEPOLIA\n ? `${at}: the local Anvil chain is eip155:${LOCAL_CHAIN_ID}, Anvil's default chain id; \"${BASE_SEPOLIA}\" is public Base Sepolia. Set ${at}.network to eip155:${LOCAL_CHAIN_ID}, start Anvil with its default chain id and redeploy the local contracts (npm run chain:start, npm run chain:deploy).`\n : `${at}: facilitator.mode \"local\" serves the local Anvil chain (eip155:${LOCAL_CHAIN_ID}) only, not \"${profile.id}\" (${profile.displayName}). Use a remote facilitator.`,\n `${at}.facilitator.mode`,\n );\n }\n\n if (mode === 'mainnet' && input.allowMainnet !== true) {\n throw invalid(\n `${at}: network \"${profile.id}\" (${profile.displayName}) settles real funds. Set ${at}.allowMainnet: true to acknowledge this explicitly - it is never the default.`,\n `${at}.allowMainnet`,\n );\n }\n\n if (input.facilitator.mode === 'remote') {\n assertFacilitatorUrlIsSafe(input.facilitator.url, mode, at);\n // `@coinbase/x402` signs each request for CDP's own host and route,\n // whatever URL is configured, so no other facilitator can accept the credential\n if (input.facilitator.auth.type === 'cdp' && !isCdpFacilitatorUrl(input.facilitator.url)) {\n throw invalid(\n `${at}: facilitator.auth.type \"cdp\" signs requests for ${CDP_FACILITATOR_URL} only, so facilitator ${describeOrigin(input.facilitator.url)} cannot accept its credential. Set facilitator.url to ${CDP_FACILITATOR_URL}, or use auth.type \"bearer\" or \"none\".`,\n `${at}.facilitator.url`,\n );\n }\n // The authorization fixes recipient, amount and chain, so a facilitator\n // cannot redirect funds. A credential adds an account: rate limits, terms\n // and support. On mainnet, going without one is an explicit choice.\n if (\n mode === 'mainnet' &&\n input.facilitator.auth.type === 'none' &&\n input.allowUnauthenticatedFacilitator !== true\n ) {\n throw invalid(\n `${at}: no credential is configured for facilitator ${describeOrigin(input.facilitator.url)} on mainnet. Set ${at}.allowUnauthenticatedFacilitator: true to accept anonymous access and the facilitator's limits, or configure facilitator.auth.`,\n `${at}.allowUnauthenticatedFacilitator`,\n );\n }\n // A blank credential reaches the facilitator as \"unauthenticated\" and fails\n // every payment after the buyer signed. `${VAR:- }` resolving to whitespace\n // is the usual cause.\n for (const [field, value] of credentialFields(input.facilitator.auth)) {\n if (value.trim() === '') {\n throw invalid(\n `${at}: facilitator.auth.type is \"${input.facilitator.auth.type}\" but ${field} is empty. An empty credential is refused rather than sent.`,\n `${at}.facilitator.auth.${field}`,\n );\n }\n }\n }\n\n // The config loader's address check refuses this too; repeated here for a\n // library consumer who calls `createX402PaymentProvider` without it\n if (isBurnAddress(profile, input.payTo)) {\n throw invalid(\n `${at}: \"${payTo}\" is the zero address. Every payment settled there is destroyed.`,\n `${at}.${payTo}`,\n );\n }\n\n // Anyone can spend from a well-known Anvil address. `dev-key-guard` refuses\n // one behind a public RPC; this refuses one on any non-local deployment,\n // whose RPC host says nothing about where a remote facilitator settles.\n if (mode !== 'local' && isWellKnownDevAddress(input.payTo)) {\n throw invalid(\n `${at}: \"${payTo}\" (${input.payTo}) is a well-known Anvil development address and this is a ${mode} deployment. Anyone can spend what settles there. Set ${payTo} to your own merchant wallet.`,\n `${at}.${payTo}`,\n );\n }\n\n // Public built-ins require USDC unless the caller allows another EVM token.\n // Local and declared networks have no default asset.\n const canonical = profile.canonicalAsset;\n if (canonical) {\n if (!sameAddress(profile, input.asset, canonical.address)) {\n if (input.allowOtherEvmToken !== true || profile.family !== 'evm') {\n const rule =\n input.allowOtherEvmToken === true\n ? `Only an EVM network accepts another token; ${profile.displayName} settles only in its ${canonical.symbol}.`\n : `A built-in network settles only in its ${canonical.symbol}.`;\n throw invalid(\n `${at}: asset ${input.asset} is not ${canonical.symbol} on ${profile.displayName} (expected ${canonical.address}). ${rule}`,\n `${at}.asset`,\n );\n }\n } else {\n // Catch USDC domain mismatches before accepting payments; a wrong name\n // can fail with `invalid_exact_evm_token_name_mismatch`\n const domain = 'name' in canonical ? canonical : undefined;\n if (domain && input.assetName !== undefined && input.assetName !== domain.name) {\n throw invalid(\n `${at}: assetName \"${input.assetName}\" is not the EIP-712 domain name ${canonical.symbol} reports on ${profile.displayName} (expected \"${domain.name}\"). Every payment would be refused after the buyer signed.`,\n `${at}.assetName`,\n );\n }\n if (domain && input.assetVersion !== undefined && input.assetVersion !== domain.version) {\n throw invalid(\n `${at}: assetVersion \"${input.assetVersion}\" is not the EIP-712 domain version ${canonical.symbol} reports on ${profile.displayName} (expected \"${domain.version}\").`,\n `${at}.assetVersion`,\n );\n }\n }\n }\n\n return { profile, mode };\n}\n\n/**\n * A facilitator sees every payment authorization this gateway handles. Plain\n * HTTP puts those on the wire in the clear and lets anyone in the path rewrite\n * a settlement result, so it is allowed only to a local or private host, and\n * never on a mainnet.\n */\nfunction assertFacilitatorUrlIsSafe(url: string, mode: DeploymentMode, at: string): void {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch (cause) {\n throw new CommerceError('CONFIG_INVALID', `${at}: facilitator.url is not a valid URL`, {\n cause,\n details: { path: `${at}.facilitator.url` },\n });\n }\n\n if (parsed.protocol === 'https:') return;\n if (parsed.protocol !== 'http:') {\n throw invalid(\n `${at}: facilitator ${describeOrigin(url)} must be reached over https (or http on a local/private host); got \"${parsed.protocol}//\"`,\n `${at}.facilitator.url`,\n );\n }\n if (mode !== 'mainnet' && isLikelyLocalOrPrivateHost(parsed.hostname)) return;\n\n // The origin, never the whole URL: the path can carry a tenant or an API\n // key, and this message reaches `validate`, `doctor`, startup output and CI logs\n throw invalid(\n `${at}: facilitator ${describeOrigin(url)} is reached over plain HTTP. Payment authorizations and settlement results would travel unencrypted. Use https, or point at a local/private host on a non-mainnet deployment.`,\n `${at}.facilitator.url`,\n );\n}\n\n/** The facilitator URL `@coinbase/x402` signs its JWTs for */\nexport const CDP_FACILITATOR_URL = 'https://api.cdp.coinbase.com/platform/v2/x402';\n\n// The SDK client strips trailing slashes before appending its route\nfunction isCdpFacilitatorUrl(url: string): boolean {\n try {\n const parsed = new URL(url);\n const expected = new URL(CDP_FACILITATOR_URL);\n return (\n parsed.origin === expected.origin &&\n parsed.pathname.replace(/\\/+$/, '') === expected.pathname &&\n parsed.search === ''\n );\n } catch {\n return false;\n }\n}\n\n// Origin only: a facilitator URL can carry a tenant path or an API key\nfunction describeOrigin(url: string): string {\n try {\n return new URL(url).origin;\n } catch {\n return '[unparseable facilitator.url]';\n }\n}\n\n// The secret-bearing fields of an auth block, for emptiness checks only. Never logged\nfunction credentialFields(auth: FacilitatorAuth): readonly (readonly [string, string])[] {\n switch (auth.type) {\n case 'bearer':\n return [['token', auth.token]];\n case 'cdp':\n return [\n ['apiKeyId', auth.apiKeyId],\n ['apiKeySecret', auth.apiKeySecret],\n ];\n default:\n return [];\n }\n}\n","/**\n * Resolves an x402 option into offer terms at config load, so `validate`\n * reports invalid options before startup. This module uses no SDK.\n *\n * Omitted assets use `canonicalAsset`. Overrides for the default token must\n * match its metadata; another token needs its own, including the EIP-712 domain\n * on EVM.\n */\nimport { CommerceError } from '../../core';\nimport { isBurnAddress, normalizeAddress, sameAddress } from './addresses';\nimport { type CustomNetworks, requireX402Network, type X402Network } from './networks';\n\nexport interface X402OptionInput {\n readonly scheme?: string;\n readonly network: string;\n readonly payTo: string;\n readonly asset?: string;\n readonly assetName?: string;\n readonly assetVersion?: string;\n readonly assetDecimals?: number;\n /** `eip3009` (the default) or `permit2`; EVM only */\n readonly assetTransferMethod?: string;\n}\n\nexport interface ResolvedX402Option {\n readonly scheme: 'exact';\n readonly network: X402Network;\n readonly payTo: string;\n readonly asset: string;\n /** EIP-712 domain; EVM only */\n readonly assetName?: string;\n readonly assetVersion?: string;\n readonly assetDecimals: number;\n /**\n * Default token symbol when `asset` is omitted; resource prices must use\n * this symbol or USD\n */\n readonly defaultAssetSymbol?: string;\n /** How the buyer authorizes the transfer; always `eip3009` off EVM */\n readonly assetTransferMethod: X402AssetTransferMethod;\n}\n\n/**\n * Names health components by network, asset and payee for discovery matching.\n * Lowercase EVM addresses so case variants identify the same offer.\n */\nexport function x402OfferName(offer: {\n readonly network: string;\n readonly asset: string;\n readonly payTo: string;\n}): string {\n const evm = offer.network.startsWith('eip155:');\n const address = (value: string) => (evm ? value.toLowerCase() : value);\n return `${offer.network} ${address(offer.asset)} ${address(offer.payTo)}`;\n}\n\n/** EIP-3009 `transferWithAuthorization`, or Permit2 with a prior token allowance */\nexport type X402AssetTransferMethod = 'eip3009' | 'permit2';\n\n// Incorrect EIP-712 domain values invalidate the buyer's signature\nconst FIELD_MEANINGS = {\n assetName: 'EIP-712 domain name',\n assetVersion: 'EIP-712 domain version',\n assetDecimals: 'decimals',\n} as const;\n\nconst ADDRESS_SHAPES = {\n evm: '\"0x\" followed by 40 hex characters',\n svm: 'a base58 public key of 32 bytes',\n near: 'a NEAR account ID: 2 to 64 lowercase characters, digits and single \"-\", \"_\" or \".\" separators',\n} as const;\n\nfunction invalid(message: string, path: string): CommerceError {\n return new CommerceError('CONFIG_INVALID', message, { details: { path } });\n}\n\nexport function resolveX402Option(\n input: X402OptionInput,\n path: string,\n custom?: CustomNetworks,\n): ResolvedX402Option {\n if (input.scheme !== undefined && input.scheme !== 'exact') {\n throw invalid(\n `${path}.scheme: \"${input.scheme}\" is not supported; the only x402 scheme is \"exact\"`,\n `${path}.scheme`,\n );\n }\n const network = requireX402Network(input.network, `${path}.network`, custom);\n const address = (field: 'payTo' | 'asset', value: string): string => {\n const wire = normalizeAddress(network, value);\n if (wire === undefined) {\n throw invalid(\n // The value is not echoed: a swapped variable could put a key here\n `${path}.${field} is not a plausible address on ${network.displayName} (expected ${ADDRESS_SHAPES[network.family]})`,\n `${path}.${field}`,\n );\n }\n return wire;\n };\n\n const payTo = address('payTo', input.payTo);\n if (isBurnAddress(network, payTo)) {\n throw invalid(\n `${path}.payTo is the zero address of ${network.displayName}. Every payment settled there is destroyed.`,\n `${path}.payTo`,\n );\n }\n\n const method = input.assetTransferMethod ?? 'eip3009';\n if (method !== 'eip3009' && method !== 'permit2') {\n throw invalid(\n `${path}.assetTransferMethod: \"${method}\" is not supported; use \"eip3009\" or \"permit2\"`,\n `${path}.assetTransferMethod`,\n );\n }\n if (network.family !== 'evm' && input.assetTransferMethod !== undefined) {\n throw invalid(\n `${path}.assetTransferMethod applies to EVM networks only, not to ${network.displayName}`,\n `${path}.assetTransferMethod`,\n );\n }\n\n if (network.family !== 'evm') {\n for (const field of ['assetName', 'assetVersion'] as const) {\n if (input[field] !== undefined) {\n throw invalid(\n `${path}.${field}: an EIP-712 domain applies to EVM tokens only, not to ${network.displayName}`,\n `${path}.${field}`,\n );\n }\n }\n }\n\n const canonical = network.canonicalAsset;\n const domain = canonical && 'name' in canonical ? canonical : undefined;\n\n const asset = input.asset !== undefined ? address('asset', input.asset) : undefined;\n if (asset !== undefined && isBurnAddress(network, asset)) {\n throw invalid(`${path}.asset must not be the zero address`, `${path}.asset`);\n }\n\n // The default asset applies when the option names none or names it exactly\n if (canonical && (asset === undefined || sameAddress(network, asset, canonical.address))) {\n const expected = {\n assetName: domain?.name,\n assetVersion: domain?.version,\n assetDecimals: canonical.decimals,\n };\n for (const field of ['assetName', 'assetVersion', 'assetDecimals'] as const) {\n const given = input[field];\n if (given !== undefined && given !== expected[field]) {\n throw invalid(\n `${path}.${field} does not match ${canonical.symbol} on ${network.displayName}, which reports ${FIELD_MEANINGS[field]} ${JSON.stringify(expected[field])}. Remove ${field}, or set asset to the token it describes.`,\n `${path}.${field}`,\n );\n }\n }\n return {\n scheme: 'exact',\n network,\n payTo,\n asset: asset ?? canonical.address,\n ...(domain ? { assetName: domain.name, assetVersion: domain.version } : {}),\n assetDecimals: canonical.decimals,\n defaultAssetSymbol: canonical.symbol,\n assetTransferMethod: method,\n };\n }\n\n // Another token: nothing about it can be borrowed from the default. The\n // token's EIP-712 domain matters to EIP-3009 only: a Permit2 buyer signs\n // Permit2's own domain.\n const required =\n network.family === 'evm' && method === 'eip3009'\n ? (['asset', 'assetName', 'assetVersion', 'assetDecimals'] as const)\n : (['asset', 'assetDecimals'] as const);\n const missing = required.filter((field) => input[field] === undefined);\n if (asset === undefined || missing.length > 0) {\n throw invalid(\n canonical\n ? `${path}: a token other than ${canonical.symbol} on ${network.displayName} needs ${missing.join(', ')}`\n : `${path}: ${network.displayName} has no default asset, so the option needs ${missing.join(', ')}`,\n `${path}.${missing[0] ?? 'asset'}`,\n );\n }\n return {\n scheme: 'exact',\n network,\n payTo,\n asset,\n ...(input.assetName !== undefined ? { assetName: input.assetName } : {}),\n ...(input.assetVersion !== undefined ? { assetVersion: input.assetVersion } : {}),\n assetDecimals: input.assetDecimals as number,\n assetTransferMethod: method,\n };\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { PERMIT2_ADDRESS } from '@x402/evm';
|
|
3
|
+
import { encodeAbiParameters, keccak256 } from 'viem';
|
|
4
|
+
|
|
5
|
+
// src/payments/x402/replay-key.ts
|
|
6
|
+
function computeReplayKey(input) {
|
|
7
|
+
const encoded = encodeAbiParameters(
|
|
8
|
+
[{ type: "uint256" }, { type: "address" }, { type: "address" }, { type: "bytes32" }],
|
|
9
|
+
[BigInt(input.chainId), input.asset, input.from, input.nonce]
|
|
10
|
+
);
|
|
11
|
+
return keccak256(encoded);
|
|
12
|
+
}
|
|
13
|
+
function computePermit2ReplayKey(input) {
|
|
14
|
+
return keccak256(
|
|
15
|
+
encodeAbiParameters(
|
|
16
|
+
[
|
|
17
|
+
{ type: "string" },
|
|
18
|
+
{ type: "uint256" },
|
|
19
|
+
{ type: "address" },
|
|
20
|
+
{ type: "address" },
|
|
21
|
+
{ type: "uint256" }
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
"x402/exact/permit2/v1",
|
|
25
|
+
BigInt(input.chainId),
|
|
26
|
+
PERMIT2_ADDRESS,
|
|
27
|
+
input.owner,
|
|
28
|
+
BigInt(input.nonce)
|
|
29
|
+
]
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
function computeSvmReplayKey(input) {
|
|
34
|
+
const digest = createHash("sha256").update("x402/exact/svm/v1\0").update(input.network).update("\0").update(Buffer.from(input.messageHash, "base64")).digest("hex");
|
|
35
|
+
return `0x${digest}`;
|
|
36
|
+
}
|
|
37
|
+
function computeNearReplayKey(input) {
|
|
38
|
+
const digest = createHash("sha256").update("x402/exact/near/v1\0").update(`${input.network}\0${input.senderId}\0${input.publicKey}\0${input.nonce.toString(10)}`).digest("hex");
|
|
39
|
+
return `0x${digest}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { computeNearReplayKey, computePermit2ReplayKey, computeReplayKey, computeSvmReplayKey };
|
|
43
|
+
//# sourceMappingURL=chunk-OSTCU6ZK.js.map
|
|
44
|
+
//# sourceMappingURL=chunk-OSTCU6ZK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/payments/x402/replay-key.ts"],"names":[],"mappings":";;;;;AAiBO,SAAS,iBAAiB,KAAA,EAA+B;AAC9D,EAAA,MAAM,OAAA,GAAU,mBAAA;AAAA,IACd,CAAC,EAAE,IAAA,EAAM,SAAA,EAAU,EAAG,EAAE,IAAA,EAAM,SAAA,EAAU,EAAG,EAAE,MAAM,SAAA,EAAU,EAAG,EAAE,IAAA,EAAM,WAAW,CAAA;AAAA,IACnF,CAAC,MAAA,CAAO,KAAA,CAAM,OAAO,CAAA,EAAG,MAAM,KAAA,EAAO,KAAA,CAAM,IAAA,EAAM,KAAA,CAAM,KAAK;AAAA,GAC9D;AACA,EAAA,OAAO,UAAU,OAA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Content":["/**\n * `PaymentResult.replayKey` is derived from the payment authorization alone,\n * never from the request id, so the same authorization replayed on another\n * request collides in the receipt store's reservation. The MPP provider uses\n * the EIP-3009 derivation.\n */\nimport { createHash } from 'node:crypto';\nimport { PERMIT2_ADDRESS } from '@x402/evm';\nimport { encodeAbiParameters, keccak256 } from 'viem';\n\nexport interface ReplayKeyInput {\n readonly chainId: number;\n readonly asset: `0x${string}`;\n readonly from: `0x${string}`;\n readonly nonce: `0x${string}`;\n}\n\nexport function computeReplayKey(input: ReplayKeyInput): string {\n const encoded = encodeAbiParameters(\n [{ type: 'uint256' }, { type: 'address' }, { type: 'address' }, { type: 'bytes32' }],\n [BigInt(input.chainId), input.asset, input.from, input.nonce],\n );\n return keccak256(encoded);\n}\n\n/**\n * Identifies a Permit2 authorization by chain, Permit2 contract, owner and\n * nonce. Nonces span all tokens and spenders, so asset and resource are excluded.\n * The tag separates these keys from EIP-3009 in the receipt store's unique column.\n */\nexport function computePermit2ReplayKey(input: {\n readonly chainId: number;\n readonly owner: `0x${string}`;\n readonly nonce: string;\n}): string {\n return keccak256(\n encodeAbiParameters(\n [\n { type: 'string' },\n { type: 'uint256' },\n { type: 'address' },\n { type: 'address' },\n { type: 'uint256' },\n ],\n [\n 'x402/exact/permit2/v1',\n BigInt(input.chainId),\n PERMIT2_ADDRESS,\n input.owner,\n BigInt(input.nonce),\n ],\n ),\n );\n}\n\n/**\n * Identifies a Solana `exact` payment by network and SHA-256 of the signed\n * message bytes. Excludes signatures, including the facilitator's fee payer\n * slot, so altered signatures keep the same key. `messageHash` is the SDK's\n * base64 `transactionMessageHash`.\n */\nexport function computeSvmReplayKey(input: {\n readonly network: string;\n readonly messageHash: string;\n}): string {\n const digest = createHash('sha256')\n .update('x402/exact/svm/v1\\0')\n .update(input.network)\n .update('\\0')\n .update(Buffer.from(input.messageHash, 'base64'))\n .digest('hex');\n return `0x${digest}`;\n}\n\n/**\n * Identifies a NEAR `exact` payment by network, sender, curve-prefixed public\n * key (`ed25519:...`) and delegate nonce. Nonces are scoped per access key,\n * excluding token, recipient, relayer and signature; another key of the same\n * sender has an independent nonce scope.\n */\nexport function computeNearReplayKey(input: {\n readonly network: string;\n readonly senderId: string;\n readonly publicKey: string;\n readonly nonce: bigint;\n}): string {\n const digest = createHash('sha256')\n .update('x402/exact/near/v1\\0')\n .update(`${input.network}\\0${input.senderId}\\0${input.publicKey}\\0${input.nonce.toString(10)}`)\n .digest('hex');\n return `0x${digest}`;\n}\n"]}
|