@agent-score/commerce 2.0.1 → 2.1.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 (116) hide show
  1. package/README.md +26 -11
  2. package/dist/_core-kI7FRAiZ.d.mts +10 -0
  3. package/dist/_core-kI7FRAiZ.d.ts +10 -0
  4. package/dist/challenge/index.d.mts +3 -3
  5. package/dist/challenge/index.d.ts +3 -3
  6. package/dist/challenge/index.js +21 -14
  7. package/dist/challenge/index.js.map +1 -1
  8. package/dist/challenge/index.mjs +21 -14
  9. package/dist/challenge/index.mjs.map +1 -1
  10. package/dist/{checkout-B1JuEcbx.d.ts → checkout-BH-I_Ns8.d.ts} +19 -12
  11. package/dist/{checkout-BN5i1Fi7.d.mts → checkout-Bd_4aQ6c.d.mts} +19 -12
  12. package/dist/core.js +1 -1
  13. package/dist/core.js.map +1 -1
  14. package/dist/core.mjs +1 -1
  15. package/dist/core.mjs.map +1 -1
  16. package/dist/default_rails-BWAquZeu.d.mts +188 -0
  17. package/dist/default_rails-BxBzcCA1.d.ts +188 -0
  18. package/dist/discovery/index.d.mts +5 -5
  19. package/dist/discovery/index.d.ts +5 -5
  20. package/dist/discovery/index.js +14 -1
  21. package/dist/discovery/index.js.map +1 -1
  22. package/dist/discovery/index.mjs +14 -1
  23. package/dist/discovery/index.mjs.map +1 -1
  24. package/dist/identity/express.d.mts +7 -3
  25. package/dist/identity/express.d.ts +7 -3
  26. package/dist/identity/express.js +39 -96
  27. package/dist/identity/express.js.map +1 -1
  28. package/dist/identity/express.mjs +37 -87
  29. package/dist/identity/express.mjs.map +1 -1
  30. package/dist/identity/fastify.d.mts +4 -4
  31. package/dist/identity/fastify.d.ts +4 -4
  32. package/dist/identity/fastify.js +60 -96
  33. package/dist/identity/fastify.js.map +1 -1
  34. package/dist/identity/fastify.mjs +58 -87
  35. package/dist/identity/fastify.mjs.map +1 -1
  36. package/dist/identity/hono.d.mts +11 -3
  37. package/dist/identity/hono.d.ts +11 -3
  38. package/dist/identity/hono.js +39 -93
  39. package/dist/identity/hono.js.map +1 -1
  40. package/dist/identity/hono.mjs +37 -84
  41. package/dist/identity/hono.mjs.map +1 -1
  42. package/dist/identity/nextjs.d.mts +10 -3
  43. package/dist/identity/nextjs.d.ts +10 -3
  44. package/dist/identity/nextjs.js +49 -93
  45. package/dist/identity/nextjs.js.map +1 -1
  46. package/dist/identity/nextjs.mjs +46 -84
  47. package/dist/identity/nextjs.mjs.map +1 -1
  48. package/dist/identity/policy.js +220 -129
  49. package/dist/identity/policy.js.map +1 -1
  50. package/dist/identity/policy.mjs +222 -131
  51. package/dist/identity/policy.mjs.map +1 -1
  52. package/dist/identity/web.d.mts +9 -3
  53. package/dist/identity/web.d.ts +9 -3
  54. package/dist/identity/web.js +45 -93
  55. package/dist/identity/web.js.map +1 -1
  56. package/dist/identity/web.mjs +42 -84
  57. package/dist/identity/web.mjs.map +1 -1
  58. package/dist/index.d.mts +554 -90
  59. package/dist/index.d.ts +554 -90
  60. package/dist/index.js +951 -152
  61. package/dist/index.js.map +1 -1
  62. package/dist/index.mjs +939 -152
  63. package/dist/index.mjs.map +1 -1
  64. package/dist/middleware/express.d.mts +10 -0
  65. package/dist/middleware/express.d.ts +10 -0
  66. package/dist/middleware/express.js +128 -0
  67. package/dist/middleware/express.js.map +1 -0
  68. package/dist/middleware/express.mjs +91 -0
  69. package/dist/middleware/express.mjs.map +1 -0
  70. package/dist/middleware/fastify.d.mts +10 -0
  71. package/dist/middleware/fastify.d.ts +10 -0
  72. package/dist/middleware/fastify.js +127 -0
  73. package/dist/middleware/fastify.js.map +1 -0
  74. package/dist/middleware/fastify.mjs +90 -0
  75. package/dist/middleware/fastify.mjs.map +1 -0
  76. package/dist/middleware/hono.d.mts +10 -0
  77. package/dist/middleware/hono.d.ts +10 -0
  78. package/dist/middleware/hono.js +122 -0
  79. package/dist/middleware/hono.js.map +1 -0
  80. package/dist/middleware/hono.mjs +85 -0
  81. package/dist/middleware/hono.mjs.map +1 -0
  82. package/dist/middleware/nextjs.d.mts +22 -0
  83. package/dist/middleware/nextjs.d.ts +22 -0
  84. package/dist/middleware/nextjs.js +143 -0
  85. package/dist/middleware/nextjs.js.map +1 -0
  86. package/dist/middleware/nextjs.mjs +105 -0
  87. package/dist/middleware/nextjs.mjs.map +1 -0
  88. package/dist/middleware/web.d.mts +25 -0
  89. package/dist/middleware/web.d.ts +25 -0
  90. package/dist/middleware/web.js +128 -0
  91. package/dist/middleware/web.js.map +1 -0
  92. package/dist/middleware/web.mjs +91 -0
  93. package/dist/middleware/web.mjs.map +1 -0
  94. package/dist/payment/index.d.mts +21 -6
  95. package/dist/payment/index.d.ts +21 -6
  96. package/dist/payment/index.js +136 -9
  97. package/dist/payment/index.js.map +1 -1
  98. package/dist/payment/index.mjs +127 -9
  99. package/dist/payment/index.mjs.map +1 -1
  100. package/dist/{pricing-CxzwyiO6.d.mts → pricing-4n5Ota0D.d.mts} +14 -4
  101. package/dist/{pricing-CQ9DIFaw.d.ts → pricing-DHfH3ogG.d.ts} +14 -4
  102. package/dist/{rail_spec-XP0wKgJV.d.mts → rail_spec-D6qzh3J0.d.mts} +1 -1
  103. package/dist/{rail_spec-XP0wKgJV.d.ts → rail_spec-D6qzh3J0.d.ts} +1 -1
  104. package/dist/stripe-multichain/index.d.mts +150 -47
  105. package/dist/stripe-multichain/index.d.ts +150 -47
  106. package/dist/stripe-multichain/index.js +19749 -42
  107. package/dist/stripe-multichain/index.js.map +1 -1
  108. package/dist/stripe-multichain/index.mjs +19758 -27
  109. package/dist/stripe-multichain/index.mjs.map +1 -1
  110. package/dist/{x402_server-hgQzWQwB.d.mts → x402_server-Ciz2mls2.d.mts} +1 -1
  111. package/dist/{x402_server-hgQzWQwB.d.ts → x402_server-Ciz2mls2.d.ts} +1 -1
  112. package/package.json +43 -5
  113. package/dist/_response-BFYN3b6i.d.mts +0 -142
  114. package/dist/_response-_iPD5AIj.d.ts +0 -142
  115. package/dist/solana-Cds87OTu.d.mts +0 -67
  116. package/dist/solana-Cds87OTu.d.ts +0 -67
@@ -0,0 +1,188 @@
1
+ import { a as RecipientLike, T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-D6qzh3J0.js';
2
+
3
+ /** Detects whether a request is a "settle leg" (carries a payment credential)
4
+ * vs a "discovery leg" (no payment credential, expects a 402).
5
+ *
6
+ * Used by the gate-conditional mount pattern documented in CLAUDE.md: mount
7
+ * `agentscoreGate` on a route only when payment is being attempted, so the
8
+ * discovery leg flows through unauthenticated and gets a 402 with all rails.
9
+ *
10
+ * Three credential channels are checked:
11
+ * - `Payment-Signature` — MPP credentials (Tempo, Solana, Stripe SPT)
12
+ * - `X-Payment` — x402 v1 EIP-3009 credentials
13
+ * - `Authorization: Payment <jwt>` — x402 v2 / paymentauth.org credentials
14
+ */
15
+ type WebHeaders = {
16
+ get(name: string): string | null;
17
+ };
18
+ type RecordHeaders = Record<string, string | string[] | undefined>;
19
+ type HeadersLike = WebHeaders | RecordHeaders | Headers;
20
+ declare function readHeader(headers: HeadersLike, name: string): string | null;
21
+ declare function asHeaders(input: Request | HeadersLike): HeadersLike;
22
+ /** True when the request carries any of the payment-credential headers we
23
+ * recognize. Accepts a Web Fetch `Headers`, a Web Fetch `Request` (uses
24
+ * `request.headers`), or a plain header record (Express/Fastify-shaped).
25
+ *
26
+ * Use this to gate the `agentscoreGate` middleware so anonymous discovery
27
+ * legs flow through and get a 402 with all rails. See CLAUDE.md
28
+ * "Anonymous discovery" pattern.
29
+ */
30
+ declare function hasPaymentHeader(input: Request | HeadersLike): boolean;
31
+ /** True when the request carries an x402 payment credential (`X-Payment` or
32
+ * `Payment-Signature`). Use to dispatch to the x402 settle path. */
33
+ declare function hasX402Header(input: Request | HeadersLike): boolean;
34
+ /** True when the request carries an mppx payment credential
35
+ * (`Authorization: Payment <jwt>`). Use to dispatch to the MPP settle path. */
36
+ declare function hasMppxHeader(input: Request | HeadersLike): boolean;
37
+
38
+ /**
39
+ * USD ↔ atomic-unit conversion for token amounts.
40
+ *
41
+ * `usdToAtomic(usd, { decimals: 6 })` returns the bigint atomic value of a USD
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.
45
+ *
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).
49
+ */
50
+ /**
51
+ * Convert a USD amount to atomic units for a token with `decimals` places.
52
+ *
53
+ * @param usd USD amount. Strings (`"1.23"`) and `number`s (`1.23`) are accepted.
54
+ * `number` is converted via `String(usd)` before parsing, so JS float precision
55
+ * limits apply when the float can't represent the value exactly.
56
+ * @param opts.decimals Number of decimal places in the atomic unit (6 for USDC,
57
+ * 18 for ETH, etc.). Must be a non-negative integer.
58
+ *
59
+ * @returns Integer atomic units as a `bigint`. `"1.23"` with `decimals: 6`
60
+ * returns `1_230_000n`.
61
+ *
62
+ * @throws RangeError when `usd` is negative, NaN, infinite, or `decimals` is
63
+ * not a non-negative integer.
64
+ * @throws SyntaxError when `usd` cannot be parsed as a fixed-notation decimal.
65
+ */
66
+ declare function usdToAtomic(usd: string | number, opts: {
67
+ decimals: number;
68
+ }): bigint;
69
+ /**
70
+ * Format an integer cent amount as a fixed-2-decimal USD string.
71
+ *
72
+ * `formatUsdCents(500)` returns `"5.00"`. Negative values are formatted with a
73
+ * leading minus. Use everywhere a merchant emits `(cents / 100).toFixed(2)`;
74
+ * consistent formatting across catalog rows, order responses, and 402 bodies
75
+ * prevents agent-side string-comparison flakiness.
76
+ *
77
+ * `decimals` controls the dollar-precision of the output and defaults to `2`
78
+ * (canonical USD cents). Raise it for sub-cent unit pricing — e.g.
79
+ * `formatUsdCents(0.05, 4)` returns `"0.0005"` for a half-of-one-millicent
80
+ * amount. The `cents` input is allowed to be fractional so per-token /
81
+ * per-byte pricing models can compute `priceCents = unitPriceCents × n`
82
+ * without rounding before reaching the formatter.
83
+ */
84
+ declare function formatUsdCents(cents: number, decimals?: number): string;
85
+
86
+ /**
87
+ * Solana MPP fee-payer signer loader.
88
+ *
89
+ * Buyers paying via Solana MPP USDC don't typically carry SOL for transaction
90
+ * fees, so merchants commonly co-sign the buyer's `solana/charge` tx as the
91
+ * fee payer (~5000 lamports per tx; negligible vs the USDC value moved).
92
+ *
93
+ * `loadSolanaFeePayer({ privateKey })` accepts a Solana keypair in any of the
94
+ * three forms agents commonly export it as:
95
+ *
96
+ * - **base58** (Phantom export format) — 64-byte secret+public, or 32-byte
97
+ * secret-only
98
+ * - **hex** — 128-char string (64 bytes hex: 32-byte secret + 32-byte public)
99
+ *
100
+ * Returns a `KeyPairSigner` from `@solana/kit` ready to pass as the `signer`
101
+ * field on a `SolanaMppRailSpec`. Returns `undefined` when `privateKey` is
102
+ * empty / absent (so consumers can use `process.env.X` directly without
103
+ * null-checks).
104
+ *
105
+ * Requires the `@solana/kit` peer dependency.
106
+ */
107
+ declare function loadSolanaFeePayer(opts: {
108
+ privateKey: string | undefined;
109
+ }): Promise<unknown | undefined>;
110
+
111
+ /** Builder for the `compose(...intents)` array passed to mppx in a merchant's
112
+ * custom `composeMppx` hook. Replaces the hand-rolled `composeRails`
113
+ * assembly that recurs verbatim across every multi-rail merchant (sayer,
114
+ * martin, sandbox).
115
+ *
116
+ * The intent shape is mppx-protocol-shaped; this helper just spares callers
117
+ * from re-typing the same atomic-conversion + per-rail object literal.
118
+ */
119
+ interface BuildMppxComposeRailsOptions {
120
+ /** USD price string (e.g. `'1.50'`). Tempo + Stripe consume it verbatim;
121
+ * Solana converts to atomic units (`bigint`) per its scheme. */
122
+ amountUsd: string;
123
+ /** Tempo recipient address. When omitted, the `tempo/charge` intent is
124
+ * not emitted (e.g., merchant with no Tempo rail configured). */
125
+ tempoRecipient?: string;
126
+ /** Tempo USDC contract address. Defaults to USDC.tempo.mainnet.address. */
127
+ tempoTokenAddress?: string;
128
+ /** Solana recipient address. When omitted, the `solana/charge` intent is
129
+ * not emitted (e.g., per-order Stripe-multichain merchant that didn't
130
+ * mint a Solana deposit address). */
131
+ solanaRecipient?: string;
132
+ /** Solana USDC mint. Defaults to USDC.solana.mainnet.mint. */
133
+ solanaTokenMint?: string;
134
+ /** Solana CAIP-2 network. Defaults to mainnet-beta. */
135
+ solanaNetwork?: string;
136
+ /** Include the `stripe/charge` intent (Stripe SPT rail). Default `true`. */
137
+ includeStripe?: boolean;
138
+ }
139
+ /** Build the `compose(...intents)` argument array. Order matches mppx's
140
+ * preferred ordering: tempo first (cheapest), then solana, then stripe.
141
+ *
142
+ * Throws when Solana is requested but `amountUsd` can't convert to atomic
143
+ * (e.g., empty string, NaN); merchants should catch and return `{status: 402}`
144
+ * to drop the rail rather than crash the request.
145
+ */
146
+ declare function buildMppxComposeRails(opts: BuildMppxComposeRailsOptions): unknown[];
147
+
148
+ /** Boilerplate-reducer for the `rails` config passed to `Checkout` /
149
+ * `computeFirstCheckout`. Merchants supplying a chain set always rebuild the
150
+ * same constants (`recipient: ''` sentinel, network/chainId/token defaults);
151
+ * this helper folds those defaults in so the merchant config only specifies
152
+ * the merchant-specific overrides.
153
+ *
154
+ * Per-order recipient minting (Stripe-multichain) is wired via the Checkout's
155
+ * `mintRecipients` hook, so the `recipient: ''` sentinel here is the expected
156
+ * shape — `mintRecipients` overrides it at request time.
157
+ */
158
+
159
+ interface BuildDefaultCheckoutRailsOptions {
160
+ /** Tempo MPP rail. Pass `{}` to accept all defaults; pass overrides
161
+ * (`network`, `chainId`, `token`, ...) to customize. Omit to skip. */
162
+ tempo?: {
163
+ recipient?: RecipientLike;
164
+ } & Partial<Omit<TempoRailSpec, 'recipient'>>;
165
+ /** x402 EVM (Base) rail. Same opt-in semantics. */
166
+ x402Base?: {
167
+ recipient?: RecipientLike;
168
+ } & Partial<Omit<X402BaseRailSpec, 'recipient'>>;
169
+ /** Solana MPP rail. Same opt-in semantics. */
170
+ solanaMpp?: {
171
+ recipient?: RecipientLike;
172
+ } & Partial<Omit<SolanaMppRailSpec, 'recipient'>>;
173
+ /** Stripe SPT rail. No recipient (Stripe owns the deposit address). */
174
+ stripe?: Partial<StripeRailSpec>;
175
+ }
176
+ type DefaultRails = {
177
+ tempo?: TempoRailSpec;
178
+ x402_base?: X402BaseRailSpec;
179
+ solana_mpp?: SolanaMppRailSpec;
180
+ stripe?: StripeRailSpec;
181
+ };
182
+ /** Build the canonical four-rail `rails` dict. Keys match the convention used
183
+ * across consumer codebases (`tempo`, `x402_base`, `solana_mpp`, `stripe`).
184
+ * Empty-string recipients are placeholders — Checkout's `mintRecipients` hook
185
+ * must populate real values at request time. */
186
+ declare function buildDefaultCheckoutRails(opts: BuildDefaultCheckoutRailsOptions): DefaultRails;
187
+
188
+ 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 };
@@ -1,10 +1,10 @@
1
- import { R as RailKey, C as CompatibleClients } from '../pricing-CxzwyiO6.mjs';
2
- export { g as compatibleClientsByRails } from '../pricing-CxzwyiO6.mjs';
3
- import { C as Checkout, r as UCPServiceBinding, b as AgentScoreGatePolicy } from '../checkout-BN5i1Fi7.mjs';
4
- import '../rail_spec-XP0wKgJV.mjs';
1
+ import { R as RailKey, C as CompatibleClients } from '../pricing-4n5Ota0D.mjs';
2
+ export { g as compatibleClientsByRails } from '../pricing-4n5Ota0D.mjs';
3
+ import { C as Checkout, q as UCPServiceBinding, a as AgentScoreGatePolicy } from '../checkout-Bd_4aQ6c.mjs';
4
+ import '../rail_spec-D6qzh3J0.mjs';
5
5
  import '../core.mjs';
6
6
  import '../signer-3FAit11j.mjs';
7
- import '../x402_server-hgQzWQwB.mjs';
7
+ import '../x402_server-Ciz2mls2.mjs';
8
8
 
9
9
  /**
10
10
  * Build a sample x402 accepts entry for a CAIP-2 network. Looks up the USDC asset
@@ -1,10 +1,10 @@
1
- import { R as RailKey, C as CompatibleClients } from '../pricing-CQ9DIFaw.js';
2
- export { g as compatibleClientsByRails } from '../pricing-CQ9DIFaw.js';
3
- import { C as Checkout, r as UCPServiceBinding, b as AgentScoreGatePolicy } from '../checkout-B1JuEcbx.js';
4
- import '../rail_spec-XP0wKgJV.js';
1
+ import { R as RailKey, C as CompatibleClients } from '../pricing-DHfH3ogG.js';
2
+ export { g as compatibleClientsByRails } from '../pricing-DHfH3ogG.js';
3
+ import { C as Checkout, q as UCPServiceBinding, a as AgentScoreGatePolicy } from '../checkout-BH-I_Ns8.js';
4
+ import '../rail_spec-D6qzh3J0.js';
5
5
  import '../core.js';
6
6
  import '../signer-3FAit11j.js';
7
- import '../x402_server-hgQzWQwB.js';
7
+ import '../x402_server-Ciz2mls2.js';
8
8
 
9
9
  /**
10
10
  * Build a sample x402 accepts entry for a CAIP-2 network. Looks up the USDC asset
@@ -1224,6 +1224,19 @@ ${bodyRulesSection}
1224
1224
  ${peerSection}`;
1225
1225
  }
1226
1226
 
1227
+ // src/payment/network_kind.ts
1228
+ function readNetwork(input) {
1229
+ if (typeof input === "string") return input;
1230
+ if (input && typeof input === "object") {
1231
+ const network = input.network;
1232
+ return typeof network === "string" ? network : "";
1233
+ }
1234
+ return "";
1235
+ }
1236
+ function isSolanaNetwork(input) {
1237
+ return readNetwork(input).startsWith("solana:");
1238
+ }
1239
+
1227
1240
  // src/identity/ucp.ts
1228
1241
  function ucpSigningKeyFromJWKImpl(jwk) {
1229
1242
  if (!jwk || typeof jwk !== "object") {
@@ -1390,7 +1403,7 @@ function isTempoSessionRailSpec(s) {
1390
1403
  }
1391
1404
  function mppRailToNetworkEntry(spec) {
1392
1405
  if (isTempoSessionRailSpec(spec)) return tempoSessionToNetworkEntry(spec);
1393
- if ("rpcUrl" in spec || "tokenProgram" in spec || (spec.network?.startsWith("solana:") ?? false)) {
1406
+ if ("rpcUrl" in spec || "tokenProgram" in spec || isSolanaNetwork(spec)) {
1394
1407
  return solanaMppToNetworkEntry(spec);
1395
1408
  }
1396
1409
  if (isTempoRailSpec(spec)) return tempoToNetworkEntry(spec);