@agent-score/commerce 2.2.0 → 2.4.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 (68) hide show
  1. package/README.md +7 -7
  2. package/dist/challenge/index.d.mts +4 -4
  3. package/dist/challenge/index.d.ts +4 -4
  4. package/dist/challenge/index.js.map +1 -1
  5. package/dist/challenge/index.mjs.map +1 -1
  6. package/dist/{checkout-CfgxgPZL.d.ts → checkout-B-MIzYzW.d.ts} +8 -11
  7. package/dist/{checkout-CKQE2QpJ.d.mts → checkout-Bn7ZKIBD.d.mts} +8 -11
  8. package/dist/core.d.mts +4 -6
  9. package/dist/core.d.ts +4 -6
  10. package/dist/core.js +1 -1
  11. package/dist/core.js.map +1 -1
  12. package/dist/core.mjs +1 -1
  13. package/dist/core.mjs.map +1 -1
  14. package/dist/discovery/index.d.mts +10 -9
  15. package/dist/discovery/index.d.ts +10 -9
  16. package/dist/discovery/index.js +44 -6
  17. package/dist/discovery/index.js.map +1 -1
  18. package/dist/discovery/index.mjs +44 -6
  19. package/dist/discovery/index.mjs.map +1 -1
  20. package/dist/identity/express.js +13 -13
  21. package/dist/identity/express.js.map +1 -1
  22. package/dist/identity/express.mjs +13 -13
  23. package/dist/identity/express.mjs.map +1 -1
  24. package/dist/identity/fastify.js +13 -13
  25. package/dist/identity/fastify.js.map +1 -1
  26. package/dist/identity/fastify.mjs +13 -13
  27. package/dist/identity/fastify.mjs.map +1 -1
  28. package/dist/identity/hono.js +13 -13
  29. package/dist/identity/hono.js.map +1 -1
  30. package/dist/identity/hono.mjs +13 -13
  31. package/dist/identity/hono.mjs.map +1 -1
  32. package/dist/identity/nextjs.js +13 -13
  33. package/dist/identity/nextjs.js.map +1 -1
  34. package/dist/identity/nextjs.mjs +13 -13
  35. package/dist/identity/nextjs.mjs.map +1 -1
  36. package/dist/identity/policy.js.map +1 -1
  37. package/dist/identity/policy.mjs.map +1 -1
  38. package/dist/identity/web.js +13 -13
  39. package/dist/identity/web.js.map +1 -1
  40. package/dist/identity/web.mjs +13 -13
  41. package/dist/identity/web.mjs.map +1 -1
  42. package/dist/index.d.mts +12 -13
  43. package/dist/index.d.ts +12 -13
  44. package/dist/index.js +88 -65
  45. package/dist/index.js.map +1 -1
  46. package/dist/index.mjs +86 -65
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/{default_rails-C5gKZJMI.d.ts → network_kind-BIJM2peR.d.ts} +22 -8
  49. package/dist/{default_rails-XFCuRddA.d.mts → network_kind-C0EMkdzz.d.mts} +22 -8
  50. package/dist/payment/index.d.mts +16 -26
  51. package/dist/payment/index.d.ts +16 -26
  52. package/dist/payment/index.js +64 -57
  53. package/dist/payment/index.js.map +1 -1
  54. package/dist/payment/index.mjs +64 -57
  55. package/dist/payment/index.mjs.map +1 -1
  56. package/dist/{pricing-uFGRNoGl.d.ts → pricing-CytRwhC2.d.ts} +1 -1
  57. package/dist/{pricing-dSI3ePmE.d.mts → pricing-KHDqMLd7.d.mts} +1 -1
  58. package/dist/{rail_spec-D6qzh3J0.d.mts → rail_spec-BFZmW9RN.d.mts} +28 -4
  59. package/dist/{rail_spec-D6qzh3J0.d.ts → rail_spec-BFZmW9RN.d.ts} +28 -4
  60. package/dist/stripe-multichain/index.d.mts +61 -18
  61. package/dist/stripe-multichain/index.d.ts +61 -18
  62. package/dist/stripe-multichain/index.js +82 -42
  63. package/dist/stripe-multichain/index.js.map +1 -1
  64. package/dist/stripe-multichain/index.mjs +81 -42
  65. package/dist/stripe-multichain/index.mjs.map +1 -1
  66. package/dist/{wwwauthenticate-D_FMnPgU.d.mts → wwwauthenticate-CVaGUMjU.d.mts} +8 -6
  67. package/dist/{wwwauthenticate-D_FMnPgU.d.ts → wwwauthenticate-CVaGUMjU.d.ts} +8 -6
  68. package/package.json +12 -11
@@ -1,4 +1,4 @@
1
- import { a as RecipientLike, T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-D6qzh3J0.js';
1
+ import { a as RecipientLike, T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-BFZmW9RN.js';
2
2
 
3
3
  /** Detects whether a request is a "settle leg" (carries a payment credential)
4
4
  * vs a "discovery leg" (no payment credential, expects a 402).
@@ -40,12 +40,12 @@ declare function hasMppxHeader(input: Request | HeadersLike): boolean;
40
40
  *
41
41
  * `usdToAtomic(usd, { decimals: 6 })` returns the bigint atomic value of a USD
42
42
  * amount for a token with `decimals` places of precision (USDC is 6). String
43
- * parsing + bigint arithmetic so the result is exact; ROUND_HALF_UP at the
44
- * rounding boundary matches the cross-language Python sibling.
43
+ * parsing + bigint arithmetic so the result is exact, with ROUND_HALF_UP at the
44
+ * rounding boundary.
45
45
  *
46
46
  * Rejects negative, NaN, infinite, and unparseable inputs. Fixed-notation only;
47
- * scientific notation (e.g. `"1e6"`) is not parsed (mirrors the locked cross-
48
- * language fixture corpus, which uses fixed notation exclusively).
47
+ * scientific notation (e.g. `"1e6"`) is not parsed, so the encoded amount is
48
+ * unambiguous on the wire.
49
49
  */
50
50
  /**
51
51
  * Convert a USD amount to atomic units for a token with `decimals` places.
@@ -110,8 +110,7 @@ declare function loadSolanaFeePayer(opts: {
110
110
 
111
111
  /** Builder for the `compose(...intents)` array passed to mppx in a merchant's
112
112
  * custom `composeMppx` hook. Replaces the hand-rolled `composeRails`
113
- * assembly that recurs verbatim across every multi-rail merchant (sayer,
114
- * martin, sandbox).
113
+ * assembly common to multi-rail merchants.
115
114
  *
116
115
  * The intent shape is mppx-protocol-shaped; this helper just spares callers
117
116
  * from re-typing the same atomic-conversion + per-rail object literal.
@@ -195,4 +194,19 @@ type DefaultRails = {
195
194
  * must populate real values at request time. */
196
195
  declare function buildDefaultCheckoutRails(opts: BuildDefaultCheckoutRailsOptions): DefaultRails;
197
196
 
198
- export { type BuildDefaultCheckoutRailsOptions as B, type HeadersLike as H, type BuildMppxComposeRailsOptions as a, asHeaders as b, buildDefaultCheckoutRails as c, buildMppxComposeRails as d, hasPaymentHeader as e, formatUsdCents as f, hasX402Header as g, hasMppxHeader as h, loadSolanaFeePayer as l, readHeader as r, usdToAtomic as u };
197
+ /** CAIP-2 prefix discriminators. Replaces the ad-hoc `startsWith('eip155:')` /
198
+ * `startsWith('solana:')` calls scattered across `checkout`, `checkout_compute_first`,
199
+ * `payment/lazy`, and `identity/ucp` so the prefix strings live in one place.
200
+ *
201
+ * Accepts the bare network spec `'eip155:8453'` or a rail-spec object with a
202
+ * `network` field. Pure functions; no peer-dep imports.
203
+ */
204
+ type NetworkLike = string | object | null | undefined;
205
+ /** True when the network is a CAIP-2 EVM chain (`eip155:<chainId>`). */
206
+ declare function isEvmNetwork(input: NetworkLike): boolean;
207
+ /** True when the network is a CAIP-2 Solana chain (`solana:<genesis-hash>`).
208
+ * Note: `'solana'` bare (no `:`) is the mppx-internal label, NOT a CAIP-2
209
+ * network spec — this helper treats it as false. */
210
+ declare function isSolanaNetwork(input: NetworkLike): boolean;
211
+
212
+ export { type BuildDefaultCheckoutRailsOptions as B, type HeadersLike as H, type BuildMppxComposeRailsOptions as a, asHeaders as b, buildDefaultCheckoutRails as c, buildMppxComposeRails as d, hasPaymentHeader as e, formatUsdCents as f, hasX402Header as g, hasMppxHeader as h, isEvmNetwork as i, isSolanaNetwork as j, loadSolanaFeePayer as l, readHeader as r, usdToAtomic as u };
@@ -1,4 +1,4 @@
1
- import { a as RecipientLike, T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-D6qzh3J0.mjs';
1
+ import { a as RecipientLike, T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-BFZmW9RN.mjs';
2
2
 
3
3
  /** Detects whether a request is a "settle leg" (carries a payment credential)
4
4
  * vs a "discovery leg" (no payment credential, expects a 402).
@@ -40,12 +40,12 @@ declare function hasMppxHeader(input: Request | HeadersLike): boolean;
40
40
  *
41
41
  * `usdToAtomic(usd, { decimals: 6 })` returns the bigint atomic value of a USD
42
42
  * amount for a token with `decimals` places of precision (USDC is 6). String
43
- * parsing + bigint arithmetic so the result is exact; ROUND_HALF_UP at the
44
- * rounding boundary matches the cross-language Python sibling.
43
+ * parsing + bigint arithmetic so the result is exact, with ROUND_HALF_UP at the
44
+ * rounding boundary.
45
45
  *
46
46
  * Rejects negative, NaN, infinite, and unparseable inputs. Fixed-notation only;
47
- * scientific notation (e.g. `"1e6"`) is not parsed (mirrors the locked cross-
48
- * language fixture corpus, which uses fixed notation exclusively).
47
+ * scientific notation (e.g. `"1e6"`) is not parsed, so the encoded amount is
48
+ * unambiguous on the wire.
49
49
  */
50
50
  /**
51
51
  * Convert a USD amount to atomic units for a token with `decimals` places.
@@ -110,8 +110,7 @@ declare function loadSolanaFeePayer(opts: {
110
110
 
111
111
  /** Builder for the `compose(...intents)` array passed to mppx in a merchant's
112
112
  * custom `composeMppx` hook. Replaces the hand-rolled `composeRails`
113
- * assembly that recurs verbatim across every multi-rail merchant (sayer,
114
- * martin, sandbox).
113
+ * assembly common to multi-rail merchants.
115
114
  *
116
115
  * The intent shape is mppx-protocol-shaped; this helper just spares callers
117
116
  * from re-typing the same atomic-conversion + per-rail object literal.
@@ -195,4 +194,19 @@ type DefaultRails = {
195
194
  * must populate real values at request time. */
196
195
  declare function buildDefaultCheckoutRails(opts: BuildDefaultCheckoutRailsOptions): DefaultRails;
197
196
 
198
- export { type BuildDefaultCheckoutRailsOptions as B, type HeadersLike as H, type BuildMppxComposeRailsOptions as a, asHeaders as b, buildDefaultCheckoutRails as c, buildMppxComposeRails as d, hasPaymentHeader as e, formatUsdCents as f, hasX402Header as g, hasMppxHeader as h, loadSolanaFeePayer as l, readHeader as r, usdToAtomic as u };
197
+ /** CAIP-2 prefix discriminators. Replaces the ad-hoc `startsWith('eip155:')` /
198
+ * `startsWith('solana:')` calls scattered across `checkout`, `checkout_compute_first`,
199
+ * `payment/lazy`, and `identity/ucp` so the prefix strings live in one place.
200
+ *
201
+ * Accepts the bare network spec `'eip155:8453'` or a rail-spec object with a
202
+ * `network` field. Pure functions; no peer-dep imports.
203
+ */
204
+ type NetworkLike = string | object | null | undefined;
205
+ /** True when the network is a CAIP-2 EVM chain (`eip155:<chainId>`). */
206
+ declare function isEvmNetwork(input: NetworkLike): boolean;
207
+ /** True when the network is a CAIP-2 Solana chain (`solana:<genesis-hash>`).
208
+ * Note: `'solana'` bare (no `:`) is the mppx-internal label, NOT a CAIP-2
209
+ * network spec — this helper treats it as false. */
210
+ declare function isSolanaNetwork(input: NetworkLike): boolean;
211
+
212
+ export { type BuildDefaultCheckoutRailsOptions as B, type HeadersLike as H, type BuildMppxComposeRailsOptions as a, asHeaders as b, buildDefaultCheckoutRails as c, buildMppxComposeRails as d, hasPaymentHeader as e, formatUsdCents as f, hasX402Header as g, hasMppxHeader as h, isEvmNetwork as i, isSolanaNetwork as j, loadSolanaFeePayer as l, readHeader as r, usdToAtomic as u };
@@ -1,11 +1,11 @@
1
- import { T as TempoRailSpec, S as SolanaMppRailSpec, c as TempoSessionRailSpec, b as StripeRailSpec, X as X402BaseRailSpec } from '../rail_spec-D6qzh3J0.mjs';
2
- export { R as RAIL_SPEC_DEFAULTS, a as RecipientLike, r as resolveRecipient } from '../rail_spec-D6qzh3J0.mjs';
1
+ import { T as TempoRailSpec, S as SolanaMppRailSpec, c as TempoSessionRailSpec, b as StripeRailSpec, X as X402BaseRailSpec } from '../rail_spec-BFZmW9RN.mjs';
2
+ export { R as RAIL_SPEC_DEFAULTS, a as RecipientLike, r as resolveRecipient } from '../rail_spec-BFZmW9RN.mjs';
3
3
  import { a as X402Server } from '../x402_server-Ciz2mls2.mjs';
4
4
  export { B as BuildX402AcceptsForOptions, C as CreateX402ServerOptions, X as X402FacilitatorChoice, b as X402SymbolicRail, c as buildX402AcceptsFor402, d as createX402Server } from '../x402_server-Ciz2mls2.mjs';
5
- export { a as aliasAmountFields, p as paymentRequiredHeader, w as wwwAuthenticateHeader } from '../wwwauthenticate-D_FMnPgU.mjs';
5
+ export { a as aliasAmountFields, p as paymentRequiredHeader, w as wwwAuthenticateHeader } from '../wwwauthenticate-CVaGUMjU.mjs';
6
6
  import { S as SignerNetwork } from '../signer-3FAit11j.mjs';
7
7
  export { P as PaymentSigner, e as extractPaymentSigner, a as extractPaymentSignerFromAuth, b as extractSignerForPrecheck, r as readX402PaymentHeader } from '../signer-3FAit11j.mjs';
8
- export { B as BuildDefaultCheckoutRailsOptions, a as BuildMppxComposeRailsOptions, H as HeadersLike, b as asHeaders, c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, l as loadSolanaFeePayer, r as readHeader, u as usdToAtomic } from '../default_rails-XFCuRddA.mjs';
8
+ export { B as BuildDefaultCheckoutRailsOptions, a as BuildMppxComposeRailsOptions, H as HeadersLike, b as asHeaders, c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, i as isEvmNetwork, j as isSolanaNetwork, l as loadSolanaFeePayer, r as readHeader, u as usdToAtomic } from '../network_kind-C0EMkdzz.mjs';
9
9
 
10
10
  /**
11
11
  * Build the base64-encoded `request` blob for an MPP Payment directive (per the
@@ -275,7 +275,8 @@ declare function registerX402SchemesV1V2(server: X402ServerLike, network: string
275
275
  * map the tagged result to a recommended HTTP response.
276
276
  */
277
277
 
278
- type ProcessX402SettleResult = {
278
+ /** Success result of `processX402Settle`: both verify and settle passed. */
279
+ interface ProcessX402SettleSuccess {
279
280
  success: true;
280
281
  /** The matched requirement passed to `settlePayment`. */
281
282
  matchedRequirement: unknown;
@@ -292,12 +293,16 @@ type ProcessX402SettleResult = {
292
293
  [key: string]: unknown;
293
294
  };
294
295
  }
296
+ /** Failure result of `processX402Settle`, discriminated by `phase`. Map to a controlled HTTP
297
+ * response via `classifyX402SettleResult`; keep raw `error` / `verifyResult` / `reason`
298
+ * server-side rather than serializing them to the consumer. */
299
+ type ProcessX402SettleFailure =
295
300
  /** No-requirements branch: `buildPaymentRequirements` returned an empty array, so
296
301
  * there is nothing to verify against. Indicates a merchant-side misconfiguration
297
302
  * (resource config doesn't match any registered scheme/network).
298
303
  * Recommended response: log `reason` server-side; map to a controlled 500 to the
299
304
  * consumer via `classifyX402SettleResult`. */
300
- | {
305
+ {
301
306
  success: false;
302
307
  phase: 'no_requirements';
303
308
  reason: string;
@@ -337,6 +342,7 @@ type ProcessX402SettleResult = {
337
342
  step: 'build_requirements' | 'enrich_extensions' | 'verify_payment';
338
343
  error: unknown;
339
344
  };
345
+ type ProcessX402SettleResult = ProcessX402SettleSuccess | ProcessX402SettleFailure;
340
346
  /**
341
347
  * The merchant-shaped response for a non-success `ProcessX402SettleResult`.
342
348
  *
@@ -796,10 +802,9 @@ declare function settlementOverrideHeader(overrides: SettlementOverrides): {
796
802
  * is single-use; nothing on-chain to verify.
797
803
  *
798
804
  * The MPP path uses inline base64+JSON parsing (no `mppx` dependency at
799
- * runtime) so the cross-language byte-parity fixtures with the Python
800
- * sibling resolve to identical results. The full `extractPaymentSigner`
801
- * path is still mppx-backed for production traffic where the credential
802
- * is a real mppx-shaped object.
805
+ * runtime) so the zero-settle path stays dependency-free. The full
806
+ * `extractPaymentSigner` path is still mppx-backed for production traffic
807
+ * where the credential is a real mppx-shaped object.
803
808
  */
804
809
 
805
810
  type ZeroSettleRail = 'x402-base' | 'tempo' | 'solana';
@@ -875,19 +880,4 @@ declare function lazyMppxServer(opts: {
875
880
  secretKey: string;
876
881
  }): () => Promise<unknown>;
877
882
 
878
- /** CAIP-2 prefix discriminators. Replaces the ad-hoc `startsWith('eip155:')` /
879
- * `startsWith('solana:')` calls scattered across `checkout`, `checkout_compute_first`,
880
- * `payment/lazy`, and `identity/ucp` so the prefix strings live in one place.
881
- *
882
- * Accepts the bare network spec `'eip155:8453'` or a rail-spec object with a
883
- * `network` field. Pure functions; no peer-dep imports.
884
- */
885
- type NetworkLike = string | object | null | undefined;
886
- /** True when the network is a CAIP-2 EVM chain (`eip155:<chainId>`). */
887
- declare function isEvmNetwork(input: NetworkLike): boolean;
888
- /** True when the network is a CAIP-2 Solana chain (`solana:<genesis-hash>`).
889
- * Note: `'solana'` bare (no `:`) is the mppx-internal label, NOT a CAIP-2
890
- * network spec — this helper treats it as false. */
891
- declare function isSolanaNetwork(input: NetworkLike): boolean;
892
-
893
- export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleResult, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, isEvmNetwork, isSolanaNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, runWithMppxFailureCapture, settlementOverrideHeader, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
883
+ export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleFailure, type ProcessX402SettleResult, type ProcessX402SettleSuccess, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, runWithMppxFailureCapture, settlementOverrideHeader, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
@@ -1,11 +1,11 @@
1
- import { T as TempoRailSpec, S as SolanaMppRailSpec, c as TempoSessionRailSpec, b as StripeRailSpec, X as X402BaseRailSpec } from '../rail_spec-D6qzh3J0.js';
2
- export { R as RAIL_SPEC_DEFAULTS, a as RecipientLike, r as resolveRecipient } from '../rail_spec-D6qzh3J0.js';
1
+ import { T as TempoRailSpec, S as SolanaMppRailSpec, c as TempoSessionRailSpec, b as StripeRailSpec, X as X402BaseRailSpec } from '../rail_spec-BFZmW9RN.js';
2
+ export { R as RAIL_SPEC_DEFAULTS, a as RecipientLike, r as resolveRecipient } from '../rail_spec-BFZmW9RN.js';
3
3
  import { a as X402Server } from '../x402_server-Ciz2mls2.js';
4
4
  export { B as BuildX402AcceptsForOptions, C as CreateX402ServerOptions, X as X402FacilitatorChoice, b as X402SymbolicRail, c as buildX402AcceptsFor402, d as createX402Server } from '../x402_server-Ciz2mls2.js';
5
- export { a as aliasAmountFields, p as paymentRequiredHeader, w as wwwAuthenticateHeader } from '../wwwauthenticate-D_FMnPgU.js';
5
+ export { a as aliasAmountFields, p as paymentRequiredHeader, w as wwwAuthenticateHeader } from '../wwwauthenticate-CVaGUMjU.js';
6
6
  import { S as SignerNetwork } from '../signer-3FAit11j.js';
7
7
  export { P as PaymentSigner, e as extractPaymentSigner, a as extractPaymentSignerFromAuth, b as extractSignerForPrecheck, r as readX402PaymentHeader } from '../signer-3FAit11j.js';
8
- export { B as BuildDefaultCheckoutRailsOptions, a as BuildMppxComposeRailsOptions, H as HeadersLike, b as asHeaders, c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, l as loadSolanaFeePayer, r as readHeader, u as usdToAtomic } from '../default_rails-C5gKZJMI.js';
8
+ export { B as BuildDefaultCheckoutRailsOptions, a as BuildMppxComposeRailsOptions, H as HeadersLike, b as asHeaders, c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, i as isEvmNetwork, j as isSolanaNetwork, l as loadSolanaFeePayer, r as readHeader, u as usdToAtomic } from '../network_kind-BIJM2peR.js';
9
9
 
10
10
  /**
11
11
  * Build the base64-encoded `request` blob for an MPP Payment directive (per the
@@ -275,7 +275,8 @@ declare function registerX402SchemesV1V2(server: X402ServerLike, network: string
275
275
  * map the tagged result to a recommended HTTP response.
276
276
  */
277
277
 
278
- type ProcessX402SettleResult = {
278
+ /** Success result of `processX402Settle`: both verify and settle passed. */
279
+ interface ProcessX402SettleSuccess {
279
280
  success: true;
280
281
  /** The matched requirement passed to `settlePayment`. */
281
282
  matchedRequirement: unknown;
@@ -292,12 +293,16 @@ type ProcessX402SettleResult = {
292
293
  [key: string]: unknown;
293
294
  };
294
295
  }
296
+ /** Failure result of `processX402Settle`, discriminated by `phase`. Map to a controlled HTTP
297
+ * response via `classifyX402SettleResult`; keep raw `error` / `verifyResult` / `reason`
298
+ * server-side rather than serializing them to the consumer. */
299
+ type ProcessX402SettleFailure =
295
300
  /** No-requirements branch: `buildPaymentRequirements` returned an empty array, so
296
301
  * there is nothing to verify against. Indicates a merchant-side misconfiguration
297
302
  * (resource config doesn't match any registered scheme/network).
298
303
  * Recommended response: log `reason` server-side; map to a controlled 500 to the
299
304
  * consumer via `classifyX402SettleResult`. */
300
- | {
305
+ {
301
306
  success: false;
302
307
  phase: 'no_requirements';
303
308
  reason: string;
@@ -337,6 +342,7 @@ type ProcessX402SettleResult = {
337
342
  step: 'build_requirements' | 'enrich_extensions' | 'verify_payment';
338
343
  error: unknown;
339
344
  };
345
+ type ProcessX402SettleResult = ProcessX402SettleSuccess | ProcessX402SettleFailure;
340
346
  /**
341
347
  * The merchant-shaped response for a non-success `ProcessX402SettleResult`.
342
348
  *
@@ -796,10 +802,9 @@ declare function settlementOverrideHeader(overrides: SettlementOverrides): {
796
802
  * is single-use; nothing on-chain to verify.
797
803
  *
798
804
  * The MPP path uses inline base64+JSON parsing (no `mppx` dependency at
799
- * runtime) so the cross-language byte-parity fixtures with the Python
800
- * sibling resolve to identical results. The full `extractPaymentSigner`
801
- * path is still mppx-backed for production traffic where the credential
802
- * is a real mppx-shaped object.
805
+ * runtime) so the zero-settle path stays dependency-free. The full
806
+ * `extractPaymentSigner` path is still mppx-backed for production traffic
807
+ * where the credential is a real mppx-shaped object.
803
808
  */
804
809
 
805
810
  type ZeroSettleRail = 'x402-base' | 'tempo' | 'solana';
@@ -875,19 +880,4 @@ declare function lazyMppxServer(opts: {
875
880
  secretKey: string;
876
881
  }): () => Promise<unknown>;
877
882
 
878
- /** CAIP-2 prefix discriminators. Replaces the ad-hoc `startsWith('eip155:')` /
879
- * `startsWith('solana:')` calls scattered across `checkout`, `checkout_compute_first`,
880
- * `payment/lazy`, and `identity/ucp` so the prefix strings live in one place.
881
- *
882
- * Accepts the bare network spec `'eip155:8453'` or a rail-spec object with a
883
- * `network` field. Pure functions; no peer-dep imports.
884
- */
885
- type NetworkLike = string | object | null | undefined;
886
- /** True when the network is a CAIP-2 EVM chain (`eip155:<chainId>`). */
887
- declare function isEvmNetwork(input: NetworkLike): boolean;
888
- /** True when the network is a CAIP-2 Solana chain (`solana:<genesis-hash>`).
889
- * Note: `'solana'` bare (no `:`) is the mppx-internal label, NOT a CAIP-2
890
- * network spec — this helper treats it as false. */
891
- declare function isSolanaNetwork(input: NetworkLike): boolean;
892
-
893
- export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleResult, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, isEvmNetwork, isSolanaNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, runWithMppxFailureCapture, settlementOverrideHeader, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
883
+ export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleFailure, type ProcessX402SettleResult, type ProcessX402SettleSuccess, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, runWithMppxFailureCapture, settlementOverrideHeader, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
@@ -75,6 +75,48 @@ __export(payment_exports, {
75
75
  });
76
76
  module.exports = __toCommonJS(payment_exports);
77
77
 
78
+ // src/payment/amounts.ts
79
+ function usdToAtomic(usd, opts) {
80
+ const { decimals } = opts;
81
+ if (!Number.isInteger(decimals) || decimals < 0) {
82
+ throw new RangeError(`decimals must be a non-negative integer, got ${decimals}`);
83
+ }
84
+ if (typeof usd === "number") {
85
+ if (!Number.isFinite(usd)) {
86
+ throw new RangeError(`usd must be finite, got ${usd}`);
87
+ }
88
+ if (usd < 0) {
89
+ throw new RangeError(`usd must be non-negative, got ${usd}`);
90
+ }
91
+ }
92
+ const s = (typeof usd === "number" ? usd.toString() : usd).trim();
93
+ if (s.startsWith("-")) {
94
+ throw new RangeError(`usd must be non-negative, got ${s}`);
95
+ }
96
+ if (s === "NaN" || s === "Infinity") {
97
+ throw new RangeError(`usd must be finite, got ${s}`);
98
+ }
99
+ const match = /^(\d*)(?:\.(\d*))?$/.exec(s);
100
+ if (!match || match[1] === "" && (match[2] === void 0 || match[2] === "")) {
101
+ throw new SyntaxError(`invalid usd value: ${JSON.stringify(usd)}`);
102
+ }
103
+ const intPart = match[1] || "0";
104
+ const fracPart = match[2] ?? "";
105
+ if (fracPart.length <= decimals) {
106
+ return BigInt(intPart + fracPart.padEnd(decimals, "0"));
107
+ }
108
+ const kept = fracPart.slice(0, decimals);
109
+ const roundDigit = fracPart[decimals];
110
+ let result = BigInt(intPart + kept);
111
+ if (roundDigit >= "5") {
112
+ result += 1n;
113
+ }
114
+ return result;
115
+ }
116
+ function formatUsdCents(cents, decimals = 2) {
117
+ return (cents / 100).toFixed(decimals);
118
+ }
119
+
78
120
  // src/payment/networks.ts
79
121
  var networks = {
80
122
  base: {
@@ -205,8 +247,7 @@ function buildPaymentRequestBlob({
205
247
  const decimalsResolved = decimals ?? railDef?.decimals ?? 6;
206
248
  const currencyResolved = currency ?? railDef?.currency ?? "usd";
207
249
  const chainIdResolved = chainId ?? railDef?.chainId;
208
- const amountNum = typeof amountUsd === "string" ? Number(amountUsd) : amountUsd;
209
- const amountRaw = BigInt(Math.round(amountNum * 10 ** decimalsResolved)).toString();
250
+ const amountRaw = usdToAtomic(amountUsd, { decimals: decimalsResolved }).toString();
210
251
  const blob = { amount: amountRaw, currency: currencyResolved, decimals: decimalsResolved };
211
252
  if (recipient) blob.recipient = recipient;
212
253
  const methodDetails = {};
@@ -762,11 +803,13 @@ async function registerSolana(spec) {
762
803
  "createMppxServer: SolanaMppRailSpec requires a string recipient (per-order factories not supported here)."
763
804
  );
764
805
  }
806
+ const ataCreationRequired = spec.ataCreationRequired !== false;
765
807
  const baseMethod = solanaMpp.charge({
766
808
  recipient: spec.recipient,
767
809
  currency: spec.token ?? defaultMint,
768
810
  decimals: spec.decimals ?? defaultDecimals,
769
811
  network,
812
+ ...ataCreationRequired ? { splits: [{ recipient: spec.recipient, amount: "0", ataCreationRequired: true }] } : {},
770
813
  ...spec.rpcUrl ? { rpcUrl: spec.rpcUrl } : {},
771
814
  ...spec.signer ? { signer: spec.signer } : {},
772
815
  ...spec.tokenProgram ? { tokenProgram: spec.tokenProgram } : {}
@@ -1071,6 +1114,18 @@ async function extractSolanaSignerFromCredential(credential) {
1071
1114
  }
1072
1115
  }
1073
1116
  async function extractPaymentSigner(request, x402PaymentHeader) {
1117
+ if (x402PaymentHeader) {
1118
+ try {
1119
+ const decoded = atob(x402PaymentHeader);
1120
+ const parsed = JSON.parse(decoded);
1121
+ const from = parsed?.payload?.authorization?.from;
1122
+ if (typeof from === "string" && /^0x[0-9a-fA-F]{40}$/.test(from)) {
1123
+ return { address: from.toLowerCase(), network: "evm" };
1124
+ }
1125
+ } catch (err) {
1126
+ console.warn("[gate] x402 signer extraction failed:", err instanceof Error ? err.message : err);
1127
+ }
1128
+ }
1074
1129
  const authHeader = request.headers.get("authorization");
1075
1130
  if (authHeader) {
1076
1131
  try {
@@ -1090,18 +1145,6 @@ async function extractPaymentSigner(request, x402PaymentHeader) {
1090
1145
  console.warn("[gate] MPP signer extraction failed:", err instanceof Error ? err.message : err);
1091
1146
  }
1092
1147
  }
1093
- if (x402PaymentHeader) {
1094
- try {
1095
- const decoded = atob(x402PaymentHeader);
1096
- const parsed = JSON.parse(decoded);
1097
- const from = parsed?.payload?.authorization?.from;
1098
- if (typeof from === "string" && /^0x[0-9a-fA-F]{40}$/.test(from)) {
1099
- return { address: from.toLowerCase(), network: "evm" };
1100
- }
1101
- } catch (err) {
1102
- console.warn("[gate] x402 signer extraction failed:", err instanceof Error ? err.message : err);
1103
- }
1104
- }
1105
1148
  return null;
1106
1149
  }
1107
1150
  async function extractPaymentSignerFromAuth(authHeader, x402PaymentHeader) {
@@ -1133,48 +1176,6 @@ function settlementOverrideHeader(overrides) {
1133
1176
  return { name: SETTLEMENT_OVERRIDES_HEADER, value: JSON.stringify(overrides) };
1134
1177
  }
1135
1178
 
1136
- // src/payment/amounts.ts
1137
- function usdToAtomic(usd, opts) {
1138
- const { decimals } = opts;
1139
- if (!Number.isInteger(decimals) || decimals < 0) {
1140
- throw new RangeError(`decimals must be a non-negative integer, got ${decimals}`);
1141
- }
1142
- if (typeof usd === "number") {
1143
- if (!Number.isFinite(usd)) {
1144
- throw new RangeError(`usd must be finite, got ${usd}`);
1145
- }
1146
- if (usd < 0) {
1147
- throw new RangeError(`usd must be non-negative, got ${usd}`);
1148
- }
1149
- }
1150
- const s = (typeof usd === "number" ? usd.toString() : usd).trim();
1151
- if (s.startsWith("-")) {
1152
- throw new RangeError(`usd must be non-negative, got ${s}`);
1153
- }
1154
- if (s === "NaN" || s === "Infinity") {
1155
- throw new RangeError(`usd must be finite, got ${s}`);
1156
- }
1157
- const match = /^(\d*)(?:\.(\d*))?$/.exec(s);
1158
- if (!match || match[1] === "" && (match[2] === void 0 || match[2] === "")) {
1159
- throw new SyntaxError(`invalid usd value: ${JSON.stringify(usd)}`);
1160
- }
1161
- const intPart = match[1] || "0";
1162
- const fracPart = match[2] ?? "";
1163
- if (fracPart.length <= decimals) {
1164
- return BigInt(intPart + fracPart.padEnd(decimals, "0"));
1165
- }
1166
- const kept = fracPart.slice(0, decimals);
1167
- const roundDigit = fracPart[decimals];
1168
- let result = BigInt(intPart + kept);
1169
- if (roundDigit >= "5") {
1170
- result += 1n;
1171
- }
1172
- return result;
1173
- }
1174
- function formatUsdCents(cents, decimals = 2) {
1175
- return (cents / 100).toFixed(decimals);
1176
- }
1177
-
1178
1179
  // src/payment/zero-settle.ts
1179
1180
  var EVM_RE = /^0x[0-9a-fA-F]{40}$/;
1180
1181
  var SOLANA_BASE58_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
@@ -1354,7 +1355,13 @@ function buildMppxComposeRails(opts) {
1354
1355
  function buildDefaultCheckoutRails(opts) {
1355
1356
  const out = {};
1356
1357
  if (opts.tempo) {
1357
- out.tempo = { recipient: "", ...RAIL_SPEC_DEFAULTS.tempo, ...opts.tempo };
1358
+ const merged = { recipient: "", ...RAIL_SPEC_DEFAULTS.tempo, ...opts.tempo };
1359
+ if (merged.testnet) {
1360
+ if (opts.tempo.network === void 0) merged.network = "tempo-testnet";
1361
+ if (opts.tempo.chainId === void 0) merged.chainId = 42431;
1362
+ if (opts.tempo.token === void 0) merged.token = USDC.tempo.testnet.address;
1363
+ }
1364
+ out.tempo = merged;
1358
1365
  }
1359
1366
  if (opts.x402Base) {
1360
1367
  const merged = { recipient: "", ...RAIL_SPEC_DEFAULTS.x402Base, ...opts.x402Base };