@piprail/sdk 2.15.0 → 2.16.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 (35) hide show
  1. package/CHANGELOG.md +260 -0
  2. package/README.md +2 -2
  3. package/dist/{algorand-CSEUTWNW.js → algorand-25FMBCT3.js} +13 -4
  4. package/dist/{algorand-I2O24RSM.cjs → algorand-Q3TUQLPK.cjs} +49 -40
  5. package/dist/{aptos-J7QGCWNW.js → aptos-SBV6SGDP.js} +3 -3
  6. package/dist/{aptos-GA5AEYYL.cjs → aptos-VBJONBFY.cjs} +36 -36
  7. package/dist/chunk-2CX7XRZK.js +649 -0
  8. package/dist/chunk-C52H5TYB.js +474 -0
  9. package/dist/chunk-OXEFPLZA.cjs +474 -0
  10. package/dist/{chunk-3FR22M3O.cjs → chunk-QONQSZHJ.cjs} +2 -2
  11. package/dist/{chunk-3ZWM3DKM.js → chunk-QU25LSVS.js} +2 -2
  12. package/dist/chunk-V2IJ5HUW.cjs +649 -0
  13. package/dist/index.cjs +507 -1347
  14. package/dist/index.d.cts +39 -6
  15. package/dist/index.d.ts +39 -6
  16. package/dist/index.js +192 -1032
  17. package/dist/{ledger-uFtXlIHY.d.cts → ledger-Crc1bZox.d.cts} +164 -10
  18. package/dist/{ledger-uFtXlIHY.d.ts → ledger-Crc1bZox.d.ts} +164 -10
  19. package/dist/{near-NDQLGI4U.cjs → near-5LTTDU6G.cjs} +27 -27
  20. package/dist/{near-YA4Y4IGC.js → near-OLKCMTBI.js} +1 -1
  21. package/dist/node.d.cts +2 -2
  22. package/dist/node.d.ts +2 -2
  23. package/dist/{solana-OU6IUMQM.cjs → solana-AI2G7V33.cjs} +73 -52
  24. package/dist/{solana-MB6G3OA5.js → solana-HTKDRTD3.js} +32 -11
  25. package/dist/{stellar-RSNVOIKL.cjs → stellar-E2KWEV2E.cjs} +20 -20
  26. package/dist/{stellar-WDWSYOED.js → stellar-EUFZLX6J.js} +1 -1
  27. package/dist/{sui-GVSFNNJX.js → sui-KCIITCYH.js} +6 -2
  28. package/dist/{sui-MVC46BFJ.cjs → sui-Q3NJOJZS.cjs} +21 -17
  29. package/dist/{ton-MYOI3U3H.cjs → ton-J7TQWRN4.cjs} +16 -16
  30. package/dist/{ton-EJMGM3YI.js → ton-WH2JVQOO.js} +1 -1
  31. package/dist/{tron-VAPVMGJK.js → tron-FXBXDNEY.js} +1 -1
  32. package/dist/{tron-42X5N4GQ.cjs → tron-HIPMOX7S.cjs} +25 -25
  33. package/dist/{xrpl-Q2UWPCTJ.js → xrpl-RUOB37QH.js} +283 -5
  34. package/dist/{xrpl-MGUBUNSZ.cjs → xrpl-SVVS445B.cjs} +312 -34
  35. package/package.json +1 -1
@@ -0,0 +1,474 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkV2IJ5HUWcjs = require('./chunk-V2IJ5HUW.cjs');
4
+
5
+
6
+ var _chunkQONQSZHJcjs = require('./chunk-QONQSZHJ.cjs');
7
+
8
+ // src/x402.ts
9
+ var DEFAULT_EXACT_TRANSFER_METHOD = "eip3009";
10
+ var KNOWN_EXACT_TRANSFER_METHODS = /* @__PURE__ */ new Set([
11
+ "eip3009",
12
+ "permit2",
13
+ "permit2-exact",
14
+ // Binance b402's foreign-dialect alias for `permit2`
15
+ "svm",
16
+ "algorand",
17
+ "aptos",
18
+ "near",
19
+ // XRPL names the SEQUENCING strategy here, not a transfer mechanism — the ledger has exactly one
20
+ // way to move value (a `Payment`), so `scheme_exact_xrpl.md` spends the field on how the tx is
21
+ // ordered. `'sequence'` (the account sequence) is the scheme's DEFAULT and what all 1,732 live
22
+ // rails mean by omitting the field.
23
+ //
24
+ // `'ticketSequence'` is deliberately NOT here. It needs the payer to have pre-minted a Ticket on
25
+ // the ledger, which PipRail does not manage, so we cannot sign one. Leaving it out means such a
26
+ // rail is SKIPPED at gather — the X5 rule — instead of planning `payable` and then throwing at
27
+ // signing time. That plan-vs-pay break is exactly the bug `extra.decimals` caused on Solana; do
28
+ // not "fix" this by adding the literal until a driver can actually produce the transaction.
29
+ "sequence"
30
+ ]);
31
+ var DEFAULT_METHOD_BY_FAMILY = Object.freeze({
32
+ evm: "eip3009",
33
+ solana: "svm",
34
+ algorand: "algorand",
35
+ aptos: "aptos",
36
+ near: "near",
37
+ // XRPL is the only family whose scheme WRITES its default down (`"sequence"`), alongside EVM's
38
+ // `eip3009`. All 1,732 live XRPL rails omit the field, so this default is what we actually meet.
39
+ xrpl: "sequence"
40
+ });
41
+ function exactTransferMethod(accept, family) {
42
+ return _nullishCoalesce(_optionalChain([accept, 'access', _ => _.extra, 'optionalAccess', _2 => _2.assetTransferMethod]), () => ( (family ? _nullishCoalesce(DEFAULT_METHOD_BY_FAMILY[family], () => ( DEFAULT_EXACT_TRANSFER_METHOD)) : DEFAULT_EXACT_TRANSFER_METHOD)));
43
+ }
44
+ function isSettleableExactMethod(accept) {
45
+ return KNOWN_EXACT_TRANSFER_METHODS.has(exactTransferMethod(accept));
46
+ }
47
+ var HEADER_REQUIRED = "payment-required";
48
+ var HEADER_SIGNATURE = "payment-signature";
49
+ var HEADER_RESPONSE = "payment-response";
50
+ var HEADER_SIGNATURE_V1 = "x-payment";
51
+ var HEADER_RESPONSE_V1 = "x-payment-response";
52
+ function encodeBase64(str) {
53
+ if (typeof Buffer !== "undefined") return Buffer.from(str, "utf8").toString("base64");
54
+ if (typeof btoa === "function" && typeof TextEncoder !== "undefined") {
55
+ const bytes = new TextEncoder().encode(str);
56
+ let binary = "";
57
+ for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
58
+ return btoa(binary);
59
+ }
60
+ throw new Error("No base64 encoder available in this runtime.");
61
+ }
62
+ function decodeBase64(b64) {
63
+ if (typeof Buffer !== "undefined") return Buffer.from(b64, "base64").toString("utf8");
64
+ if (typeof atob === "function" && typeof TextDecoder !== "undefined") {
65
+ const binary = atob(b64);
66
+ const bytes = new Uint8Array(binary.length);
67
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
68
+ return new TextDecoder().decode(bytes);
69
+ }
70
+ throw new Error("No base64 decoder available in this runtime.");
71
+ }
72
+ function fromBase64Json(b64) {
73
+ try {
74
+ return JSON.parse(decodeBase64(b64));
75
+ } catch (e) {
76
+ return null;
77
+ }
78
+ }
79
+ function decodeBase64Json(value) {
80
+ return fromBase64Json(value);
81
+ }
82
+ function toBase64Json(value) {
83
+ let json;
84
+ try {
85
+ json = JSON.stringify(value);
86
+ } catch (cause) {
87
+ throw new (0, _chunkQONQSZHJcjs.InvalidConfigError)(
88
+ `x402: this payload cannot be serialised to JSON (${cause.message}). Amounts must be decimal STRINGS, not BigInt \u2014 pass '50000', not 50000n.`,
89
+ { cause }
90
+ );
91
+ }
92
+ return encodeBase64(json);
93
+ }
94
+ function networkForChain(chainId) {
95
+ return `eip155:${chainId}`;
96
+ }
97
+ function chainIdFromNetwork(network) {
98
+ const match = /^eip155:(\d+)$/.exec(network);
99
+ if (!match || !match[1]) return null;
100
+ const n = Number(match[1]);
101
+ return Number.isSafeInteger(n) && n > 0 ? n : null;
102
+ }
103
+ function buildChallengeHeader(challenge) {
104
+ return toBase64Json(challenge);
105
+ }
106
+ function buildReceiptHeader(receipt, extensions) {
107
+ return toBase64Json(extensions ? { ...receipt, extensions } : receipt);
108
+ }
109
+ var EXT_OFFER_RECEIPT = "offer-receipt";
110
+ function buildReceiptExtension(bundle) {
111
+ const info = { settlement: bundle.receipt, resource: bundle.resource };
112
+ if (typeof bundle.decimals === "number") info.decimals = bundle.decimals;
113
+ if (bundle.attestation) info.receipt = bundle.attestation;
114
+ return { [EXT_OFFER_RECEIPT]: { info } };
115
+ }
116
+ var EXT_PAYMENT_IDENTIFIER = "payment-identifier";
117
+ var PAYMENT_ID_MIN = 16;
118
+ var PAYMENT_ID_MAX = 128;
119
+ var PAYMENT_ID_RE = /^[A-Za-z0-9_-]+$/;
120
+ function buildPaymentIdentifierAdvertisement() {
121
+ return {
122
+ [EXT_PAYMENT_IDENTIFIER]: {
123
+ info: { required: false },
124
+ schema: { properties: { id: { type: "string", minLength: PAYMENT_ID_MIN, maxLength: PAYMENT_ID_MAX } } }
125
+ }
126
+ };
127
+ }
128
+ function readPaymentIdentifier(payload) {
129
+ if (typeof payload !== "object" || payload === null) return null;
130
+ const ext = payload.extensions;
131
+ if (typeof ext !== "object" || ext === null) return null;
132
+ const block = ext[EXT_PAYMENT_IDENTIFIER];
133
+ if (typeof block !== "object" || block === null) return null;
134
+ const info = block.info;
135
+ if (typeof info !== "object" || info === null) return null;
136
+ const id = info.id;
137
+ if (id === void 0) return null;
138
+ if (typeof id !== "string") return { invalid: "payment-identifier id must be a string" };
139
+ if (id.length < PAYMENT_ID_MIN || id.length > PAYMENT_ID_MAX) {
140
+ return { invalid: `payment-identifier id must be ${PAYMENT_ID_MIN}\u2013${PAYMENT_ID_MAX} chars (got ${id.length})` };
141
+ }
142
+ if (!PAYMENT_ID_RE.test(id)) {
143
+ return { invalid: "payment-identifier id must match [A-Za-z0-9_-]" };
144
+ }
145
+ return id;
146
+ }
147
+ function buildSignatureHeader(signature) {
148
+ if (!signature.accepted) return toBase64Json(signature);
149
+ return toBase64Json({ ...signature, accepted: withoutWireNetwork(signature.accepted) });
150
+ }
151
+ function withoutWireNetwork(accepted) {
152
+ if (accepted === null || typeof accepted !== "object") return accepted;
153
+ if (!("wireNetwork" in accepted)) return accepted;
154
+ const { wireNetwork: _wire, ...rest } = accepted;
155
+ return rest;
156
+ }
157
+ function buildExactSignatureHeader(input) {
158
+ return toBase64Json({
159
+ x402Version: 2,
160
+ accepted: withoutWireNetwork(input.accepted),
161
+ payload: input.payload
162
+ });
163
+ }
164
+ function buildUptoSignatureHeader(input) {
165
+ return toBase64Json({
166
+ x402Version: 2,
167
+ accepted: withoutWireNetwork(input.accepted),
168
+ payload: input.payload
169
+ });
170
+ }
171
+ function buildV1PaymentHeader(input) {
172
+ return toBase64Json({
173
+ x402Version: 1,
174
+ scheme: input.scheme,
175
+ network: input.network,
176
+ payload: input.payload
177
+ });
178
+ }
179
+ async function parseChallenge(response) {
180
+ const headerValue = response.headers.get(HEADER_REQUIRED);
181
+ if (headerValue) {
182
+ const parsed = fromBase64Json(headerValue);
183
+ if (isValidChallenge(parsed)) return parsed;
184
+ const v1 = normalizeV1Challenge(parsed);
185
+ if (v1) return v1;
186
+ }
187
+ try {
188
+ const body = await response.clone().json();
189
+ if (isValidChallenge(body)) return body;
190
+ return normalizeV1Challenge(body);
191
+ } catch (e2) {
192
+ }
193
+ return null;
194
+ }
195
+ function parseReceipt(response) {
196
+ const headerValue = _nullishCoalesce(response.headers.get(HEADER_RESPONSE), () => ( response.headers.get(HEADER_RESPONSE_V1)));
197
+ if (!headerValue) return null;
198
+ const parsed = fromBase64Json(headerValue);
199
+ if (!isValidReceipt(parsed)) return null;
200
+ const r = parsed;
201
+ if (typeof r.transaction !== "string" && typeof r.txHash === "string") r.transaction = r.txHash;
202
+ return r;
203
+ }
204
+ function parseReceiptExtension(response) {
205
+ const headerValue = _nullishCoalesce(response.headers.get(HEADER_RESPONSE), () => ( response.headers.get(HEADER_RESPONSE_V1)));
206
+ if (!headerValue) return null;
207
+ const parsed = fromBase64Json(headerValue);
208
+ if (!parsed || typeof parsed !== "object") return null;
209
+ const ext = parsed.extensions;
210
+ const block = _optionalChain([ext, 'optionalAccess', _3 => _3[EXT_OFFER_RECEIPT]]);
211
+ const info = _optionalChain([block, 'optionalAccess', _4 => _4.info]);
212
+ if (!info) return null;
213
+ const settlement = isValidReceipt(info.settlement) ? info.settlement : isValidReceipt(info.receipt) ? info.receipt : void 0;
214
+ if (!settlement) return null;
215
+ const attestation = info.receipt && info.receipt !== settlement ? info.receipt : void 0;
216
+ const res = info.resource;
217
+ return {
218
+ piprail: "1",
219
+ receipt: settlement,
220
+ resource: { url: res && typeof res.url === "string" ? res.url : "" },
221
+ ...typeof info.decimals === "number" ? { decimals: info.decimals } : {},
222
+ ...attestation ? { attestation } : {}
223
+ };
224
+ }
225
+ function parseSettleResponse(response) {
226
+ const headerValue = _nullishCoalesce(response.headers.get(HEADER_RESPONSE), () => ( response.headers.get(HEADER_RESPONSE_V1)));
227
+ if (!headerValue) return null;
228
+ const parsed = fromBase64Json(headerValue);
229
+ if (!parsed || typeof parsed !== "object" || typeof parsed.success !== "boolean") return null;
230
+ return {
231
+ success: parsed.success,
232
+ // Tolerate the legacy v1 `txHash` alias for `transaction` (mirrors isValidReceipt/parseReceipt).
233
+ ...typeof parsed.transaction === "string" ? { transaction: parsed.transaction } : typeof parsed.txHash === "string" ? { transaction: parsed.txHash } : {},
234
+ ...typeof parsed.network === "string" ? { network: parsed.network } : {},
235
+ ...typeof parsed.payer === "string" ? { payer: parsed.payer } : {},
236
+ ...typeof parsed.errorReason === "string" ? { errorReason: parsed.errorReason } : {},
237
+ // The upto SettleResponse's REQUIRED `amount` (actual settled atomic units) — string
238
+ // passthrough so the upto buyer records ACTUAL, not MAX. Absent on onchain-proof/exact.
239
+ ...typeof parsed.amount === "string" ? { amount: parsed.amount } : {}
240
+ };
241
+ }
242
+ function parseSignatureObject(parsed) {
243
+ if (!parsed || typeof parsed !== "object") return null;
244
+ const v = parsed;
245
+ const accepted = v.accepted;
246
+ const scheme = _nullishCoalesce(_optionalChain([accepted, 'optionalAccess', _5 => _5.scheme]), () => ( v.scheme));
247
+ if (scheme !== "onchain-proof") return null;
248
+ const payload = v.payload;
249
+ if (!payload || typeof payload.txHash !== "string" || typeof payload.nonce !== "string") {
250
+ return null;
251
+ }
252
+ if (!accepted) {
253
+ const synthesized = {
254
+ scheme: "onchain-proof",
255
+ ...typeof v.network === "string" ? { network: v.network } : {},
256
+ ...typeof v.asset === "string" ? { asset: v.asset } : {}
257
+ };
258
+ return { ...v, accepted: synthesized, payload };
259
+ }
260
+ return parsed;
261
+ }
262
+ function parseSignatureHeader(value) {
263
+ return parseSignatureObject(fromBase64Json(value));
264
+ }
265
+ function parseExactPaymentHeader(value) {
266
+ return parseExactObject(fromBase64Json(value));
267
+ }
268
+ function parseExactObject(parsed) {
269
+ if (!parsed || typeof parsed !== "object") return null;
270
+ const v = parsed;
271
+ const accepted = _nullishCoalesce(v.accepted, () => ( null));
272
+ const scheme = _nullishCoalesce(_optionalChain([accepted, 'optionalAccess', _6 => _6.scheme]), () => ( v.scheme));
273
+ if (scheme !== "exact") return null;
274
+ const network = _nullishCoalesce(_optionalChain([accepted, 'optionalAccess', _7 => _7.network]), () => ( v.network));
275
+ if (typeof network !== "string") return null;
276
+ const payload = v.payload;
277
+ if (!payload || typeof payload !== "object") return null;
278
+ const x402Version = typeof v.x402Version === "number" ? v.x402Version : 2;
279
+ const asset = accepted && typeof accepted.asset === "string" ? accepted.asset : void 0;
280
+ const base = { x402Version, network, ...asset ? { asset } : {}, raw: v };
281
+ if (typeof payload.signedDelegateAction === "string") {
282
+ return { ...base, method: "near", payload: { signedDelegateAction: payload.signedDelegateAction } };
283
+ }
284
+ if (typeof payload.signedTxBlob === "string") {
285
+ const claimed = _optionalChain([accepted, 'optionalAccess', _8 => _8.extra]);
286
+ const method = _optionalChain([claimed, 'optionalAccess', _9 => _9.assetTransferMethod]) === "ticketSequence" ? "ticketSequence" : "sequence";
287
+ return { ...base, method, payload: { signedTxBlob: payload.signedTxBlob } };
288
+ }
289
+ if (typeof payload.transaction === "string" && typeof payload.senderAuth === "string") {
290
+ return { ...base, method: "aptos", payload: { transaction: payload.transaction, senderAuth: payload.senderAuth } };
291
+ }
292
+ if (typeof payload.transaction === "string") {
293
+ return { ...base, method: "svm", payload: { transaction: payload.transaction } };
294
+ }
295
+ if (Array.isArray(payload.paymentGroup)) {
296
+ const group = payload.paymentGroup;
297
+ const index = payload.paymentIndex;
298
+ if (group.length === 0 || group.length > 16 || !group.every((t) => typeof t === "string") || typeof index !== "number" || !Number.isInteger(index) || index < 0 || index >= group.length) {
299
+ return null;
300
+ }
301
+ return {
302
+ ...base,
303
+ method: "algorand",
304
+ payload: { paymentIndex: index, paymentGroup: group }
305
+ };
306
+ }
307
+ const signature = payload.signature;
308
+ if (typeof signature !== "string") return null;
309
+ const authorization = payload.authorization;
310
+ if (authorization && typeof authorization === "object") {
311
+ for (const k of ["from", "to", "value", "validAfter", "validBefore", "nonce"]) {
312
+ if (typeof authorization[k] !== "string") return null;
313
+ }
314
+ return {
315
+ ...base,
316
+ method: "eip3009",
317
+ payload: { signature, authorization }
318
+ };
319
+ }
320
+ const p2 = payload.permit2Authorization;
321
+ if (p2 && typeof p2 === "object") {
322
+ const permitted = p2.permitted;
323
+ const witness = p2.witness;
324
+ if (!permitted || typeof permitted !== "object" || !witness || typeof witness !== "object") return null;
325
+ if (typeof permitted.token !== "string" || typeof permitted.amount !== "string") return null;
326
+ if (typeof witness.to !== "string" || typeof witness.validAfter !== "string") return null;
327
+ for (const k of ["from", "spender", "nonce", "deadline"]) {
328
+ if (typeof p2[k] !== "string") return null;
329
+ }
330
+ return {
331
+ ...base,
332
+ method: "permit2",
333
+ payload: { signature, permit2Authorization: p2 }
334
+ };
335
+ }
336
+ return null;
337
+ }
338
+ function parseUptoPaymentHeader(value) {
339
+ return parseUptoObject(fromBase64Json(value));
340
+ }
341
+ function parseUptoObject(parsed) {
342
+ if (!parsed || typeof parsed !== "object") return null;
343
+ const v = parsed;
344
+ const accepted = _nullishCoalesce(v.accepted, () => ( null));
345
+ const scheme = _nullishCoalesce(_optionalChain([accepted, 'optionalAccess', _10 => _10.scheme]), () => ( v.scheme));
346
+ if (scheme !== "upto") return null;
347
+ const network = _nullishCoalesce(_optionalChain([accepted, 'optionalAccess', _11 => _11.network]), () => ( v.network));
348
+ if (typeof network !== "string") return null;
349
+ const payload = v.payload;
350
+ if (!payload || typeof payload !== "object") return null;
351
+ const signature = payload.signature;
352
+ if (typeof signature !== "string") return null;
353
+ const p2 = payload.permit2Authorization;
354
+ if (!p2 || typeof p2 !== "object") return null;
355
+ const permitted = p2.permitted;
356
+ const witness = p2.witness;
357
+ if (!permitted || typeof permitted !== "object" || !witness || typeof witness !== "object") return null;
358
+ if (typeof permitted.token !== "string" || typeof permitted.amount !== "string") return null;
359
+ if (typeof witness.to !== "string" || typeof witness.facilitator !== "string" || typeof witness.validAfter !== "string") {
360
+ return null;
361
+ }
362
+ for (const k of ["from", "spender", "nonce", "deadline"]) {
363
+ if (typeof p2[k] !== "string") return null;
364
+ }
365
+ const x402Version = typeof v.x402Version === "number" ? v.x402Version : 2;
366
+ const asset = accepted && typeof accepted.asset === "string" ? accepted.asset : void 0;
367
+ const base = { x402Version, network, ...asset ? { asset } : {}, raw: v };
368
+ return {
369
+ ...base,
370
+ method: "permit2-upto",
371
+ payload: { signature, permit2Authorization: p2 }
372
+ };
373
+ }
374
+ function isValidChallenge(value) {
375
+ if (!value || typeof value !== "object") return false;
376
+ const v = value;
377
+ if (v.x402Version !== 2) return false;
378
+ if (!Array.isArray(v.accepts) || v.accepts.length === 0) return false;
379
+ if (!v.accepts.every((a) => a !== null && typeof a === "object")) return false;
380
+ if (!v.resource || typeof v.resource !== "object") return false;
381
+ return true;
382
+ }
383
+ function isValidV1Challenge(value) {
384
+ if (!value || typeof value !== "object") return false;
385
+ const v = value;
386
+ if (v.x402Version !== 1) return false;
387
+ if (!Array.isArray(v.accepts) || v.accepts.length === 0) return false;
388
+ if (!v.accepts.every((a) => a !== null && typeof a === "object")) return false;
389
+ return v.accepts.some((a) => typeof a.resource === "string");
390
+ }
391
+ function normalizeV1Challenge(body) {
392
+ if (!isValidV1Challenge(body)) return null;
393
+ const v = body;
394
+ const rawAccepts = v.accepts;
395
+ const accepts = rawAccepts.map((a) => {
396
+ const out = { ...a };
397
+ if (typeof out.amount !== "string" && typeof a.maxAmountRequired === "string") {
398
+ out.amount = a.maxAmountRequired;
399
+ }
400
+ if (typeof a.network === "string") {
401
+ const canonical = _chunkV2IJ5HUWcjs.normalizeNetwork.call(void 0, a.network);
402
+ if (canonical !== a.network) {
403
+ out.network = canonical;
404
+ out.wireNetwork = a.network;
405
+ }
406
+ }
407
+ delete out.resource;
408
+ return out;
409
+ });
410
+ const withResource = rawAccepts.find((a) => typeof a.resource === "string");
411
+ const resource = {
412
+ url: String(_nullishCoalesce(_optionalChain([withResource, 'optionalAccess', _12 => _12.resource]), () => ( ""))),
413
+ ...typeof _optionalChain([withResource, 'optionalAccess', _13 => _13.description]) === "string" ? { description: withResource.description } : {},
414
+ ...typeof _optionalChain([withResource, 'optionalAccess', _14 => _14.mimeType]) === "string" ? { mimeType: withResource.mimeType } : {}
415
+ };
416
+ return {
417
+ x402Version: 1,
418
+ ...typeof v.error === "string" ? { error: v.error } : {},
419
+ resource,
420
+ accepts
421
+ };
422
+ }
423
+ function isValidReceipt(value) {
424
+ if (!value || typeof value !== "object") return false;
425
+ const v = value;
426
+ if (v.scheme !== "onchain-proof" && v.scheme !== "exact" && v.scheme !== "upto") return false;
427
+ if (typeof v.transaction !== "string" && typeof v.txHash !== "string") return false;
428
+ if (typeof v.payer !== "string") return false;
429
+ return true;
430
+ }
431
+ function pickAccept(challenge, matches) {
432
+ for (const accept of challenge.accepts) {
433
+ if (accept.scheme === "onchain-proof" && matches(accept.network)) return accept;
434
+ }
435
+ return null;
436
+ }
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+ exports.DEFAULT_EXACT_TRANSFER_METHOD = DEFAULT_EXACT_TRANSFER_METHOD; exports.KNOWN_EXACT_TRANSFER_METHODS = KNOWN_EXACT_TRANSFER_METHODS; exports.exactTransferMethod = exactTransferMethod; exports.isSettleableExactMethod = isSettleableExactMethod; exports.HEADER_REQUIRED = HEADER_REQUIRED; exports.HEADER_SIGNATURE = HEADER_SIGNATURE; exports.HEADER_RESPONSE = HEADER_RESPONSE; exports.HEADER_SIGNATURE_V1 = HEADER_SIGNATURE_V1; exports.HEADER_RESPONSE_V1 = HEADER_RESPONSE_V1; exports.decodeBase64Json = decodeBase64Json; exports.networkForChain = networkForChain; exports.chainIdFromNetwork = chainIdFromNetwork; exports.buildChallengeHeader = buildChallengeHeader; exports.buildReceiptHeader = buildReceiptHeader; exports.EXT_OFFER_RECEIPT = EXT_OFFER_RECEIPT; exports.buildReceiptExtension = buildReceiptExtension; exports.EXT_PAYMENT_IDENTIFIER = EXT_PAYMENT_IDENTIFIER; exports.buildPaymentIdentifierAdvertisement = buildPaymentIdentifierAdvertisement; exports.readPaymentIdentifier = readPaymentIdentifier; exports.buildSignatureHeader = buildSignatureHeader; exports.buildExactSignatureHeader = buildExactSignatureHeader; exports.buildUptoSignatureHeader = buildUptoSignatureHeader; exports.buildV1PaymentHeader = buildV1PaymentHeader; exports.parseChallenge = parseChallenge; exports.parseReceipt = parseReceipt; exports.parseReceiptExtension = parseReceiptExtension; exports.parseSettleResponse = parseSettleResponse; exports.parseSignatureObject = parseSignatureObject; exports.parseSignatureHeader = parseSignatureHeader; exports.parseExactPaymentHeader = parseExactPaymentHeader; exports.parseExactObject = parseExactObject; exports.parseUptoPaymentHeader = parseUptoPaymentHeader; exports.parseUptoObject = parseUptoObject; exports.normalizeV1Challenge = normalizeV1Challenge; exports.pickAccept = pickAccept;
@@ -179,7 +179,7 @@ function parseUnits(value, decimals) {
179
179
  }
180
180
  const [whole, frac = ""] = value.split(".");
181
181
  if (frac.length > decimals) {
182
- throw new Error(
182
+ throw new InvalidConfigError(
183
183
  `parseUnits: "${value}" has more than ${decimals} decimal places.`
184
184
  );
185
185
  }
@@ -190,7 +190,7 @@ function floorUnits(value, decimals) {
190
190
  assertValidDecimals(decimals, "floorUnits");
191
191
  value = expandScientific(value);
192
192
  if (!/^\d+(\.\d+)?$/.test(value)) {
193
- throw new Error(`floorUnits: "${value}" is not a non-negative decimal amount.`);
193
+ throw new InvalidConfigError(`floorUnits: "${value}" is not a non-negative decimal amount.`);
194
194
  }
195
195
  const [whole, frac = ""] = value.split(".");
196
196
  const fracTrunc = frac.slice(0, decimals).padEnd(decimals, "0");
@@ -179,7 +179,7 @@ function parseUnits(value, decimals) {
179
179
  }
180
180
  const [whole, frac = ""] = value.split(".");
181
181
  if (frac.length > decimals) {
182
- throw new Error(
182
+ throw new InvalidConfigError(
183
183
  `parseUnits: "${value}" has more than ${decimals} decimal places.`
184
184
  );
185
185
  }
@@ -190,7 +190,7 @@ function floorUnits(value, decimals) {
190
190
  assertValidDecimals(decimals, "floorUnits");
191
191
  value = expandScientific(value);
192
192
  if (!/^\d+(\.\d+)?$/.test(value)) {
193
- throw new Error(`floorUnits: "${value}" is not a non-negative decimal amount.`);
193
+ throw new InvalidConfigError(`floorUnits: "${value}" is not a non-negative decimal amount.`);
194
194
  }
195
195
  const [whole, frac = ""] = value.split(".");
196
196
  const fracTrunc = frac.slice(0, decimals).padEnd(decimals, "0");