@agent-score/commerce 2.3.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.
- package/README.md +6 -6
- package/dist/challenge/index.d.mts +4 -4
- package/dist/challenge/index.d.ts +4 -4
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/{checkout-ChyOi7aU.d.ts → checkout-B-MIzYzW.d.ts} +8 -11
- package/dist/{checkout-Ceo1_rVJ.d.mts → checkout-Bn7ZKIBD.d.mts} +8 -11
- package/dist/core.d.mts +4 -6
- package/dist/core.d.ts +4 -6
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/discovery/index.d.mts +10 -9
- package/dist/discovery/index.d.ts +10 -9
- package/dist/discovery/index.js +44 -6
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +44 -6
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/identity/express.js +13 -13
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +13 -13
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.js +13 -13
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +13 -13
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.js +13 -13
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +13 -13
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.js +13 -13
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +13 -13
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.js +13 -13
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +13 -13
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +12 -13
- package/dist/index.d.ts +12 -13
- package/dist/index.js +86 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -65
- package/dist/index.mjs.map +1 -1
- package/dist/{default_rails-DtR_E9N9.d.ts → network_kind-BIJM2peR.d.ts} +22 -8
- package/dist/{default_rails-K25PtWrL.d.mts → network_kind-C0EMkdzz.d.mts} +22 -8
- package/dist/payment/index.d.mts +16 -26
- package/dist/payment/index.d.ts +16 -26
- package/dist/payment/index.js +62 -57
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +62 -57
- package/dist/payment/index.mjs.map +1 -1
- package/dist/{pricing-B3-aKxSz.d.ts → pricing-CytRwhC2.d.ts} +1 -1
- package/dist/{pricing-BReyZiqN.d.mts → pricing-KHDqMLd7.d.mts} +1 -1
- package/dist/{rail_spec-B1239jPp.d.mts → rail_spec-BFZmW9RN.d.mts} +3 -4
- package/dist/{rail_spec-B1239jPp.d.ts → rail_spec-BFZmW9RN.d.ts} +3 -4
- package/dist/stripe-multichain/index.d.mts +2 -9
- package/dist/stripe-multichain/index.d.ts +2 -9
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/dist/{wwwauthenticate-D_FMnPgU.d.mts → wwwauthenticate-CVaGUMjU.d.mts} +8 -6
- package/dist/{wwwauthenticate-D_FMnPgU.d.ts → wwwauthenticate-CVaGUMjU.d.ts} +8 -6
- package/package.json +9 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as RecipientLike, T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-
|
|
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
|
|
44
|
-
* rounding boundary
|
|
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
|
|
48
|
-
*
|
|
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
|
|
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
|
-
|
|
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-
|
|
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
|
|
44
|
-
* rounding boundary
|
|
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
|
|
48
|
-
*
|
|
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
|
|
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
|
-
|
|
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 };
|
package/dist/payment/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { T as TempoRailSpec, S as SolanaMppRailSpec, c as TempoSessionRailSpec, b as StripeRailSpec, X as X402BaseRailSpec } from '../rail_spec-
|
|
2
|
-
export { R as RAIL_SPEC_DEFAULTS, a as RecipientLike, r as resolveRecipient } from '../rail_spec-
|
|
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-
|
|
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 '../
|
|
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
|
-
|
|
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
|
|
800
|
-
*
|
|
801
|
-
*
|
|
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
|
-
|
|
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 };
|
package/dist/payment/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { T as TempoRailSpec, S as SolanaMppRailSpec, c as TempoSessionRailSpec, b as StripeRailSpec, X as X402BaseRailSpec } from '../rail_spec-
|
|
2
|
-
export { R as RAIL_SPEC_DEFAULTS, a as RecipientLike, r as resolveRecipient } from '../rail_spec-
|
|
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-
|
|
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 '../
|
|
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
|
-
|
|
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
|
|
800
|
-
*
|
|
801
|
-
*
|
|
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
|
-
|
|
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 };
|
package/dist/payment/index.js
CHANGED
|
@@ -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
|
|
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 = {};
|
|
@@ -1073,6 +1114,18 @@ async function extractSolanaSignerFromCredential(credential) {
|
|
|
1073
1114
|
}
|
|
1074
1115
|
}
|
|
1075
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
|
+
}
|
|
1076
1129
|
const authHeader = request.headers.get("authorization");
|
|
1077
1130
|
if (authHeader) {
|
|
1078
1131
|
try {
|
|
@@ -1092,18 +1145,6 @@ async function extractPaymentSigner(request, x402PaymentHeader) {
|
|
|
1092
1145
|
console.warn("[gate] MPP signer extraction failed:", err instanceof Error ? err.message : err);
|
|
1093
1146
|
}
|
|
1094
1147
|
}
|
|
1095
|
-
if (x402PaymentHeader) {
|
|
1096
|
-
try {
|
|
1097
|
-
const decoded = atob(x402PaymentHeader);
|
|
1098
|
-
const parsed = JSON.parse(decoded);
|
|
1099
|
-
const from = parsed?.payload?.authorization?.from;
|
|
1100
|
-
if (typeof from === "string" && /^0x[0-9a-fA-F]{40}$/.test(from)) {
|
|
1101
|
-
return { address: from.toLowerCase(), network: "evm" };
|
|
1102
|
-
}
|
|
1103
|
-
} catch (err) {
|
|
1104
|
-
console.warn("[gate] x402 signer extraction failed:", err instanceof Error ? err.message : err);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
1148
|
return null;
|
|
1108
1149
|
}
|
|
1109
1150
|
async function extractPaymentSignerFromAuth(authHeader, x402PaymentHeader) {
|
|
@@ -1135,48 +1176,6 @@ function settlementOverrideHeader(overrides) {
|
|
|
1135
1176
|
return { name: SETTLEMENT_OVERRIDES_HEADER, value: JSON.stringify(overrides) };
|
|
1136
1177
|
}
|
|
1137
1178
|
|
|
1138
|
-
// src/payment/amounts.ts
|
|
1139
|
-
function usdToAtomic(usd, opts) {
|
|
1140
|
-
const { decimals } = opts;
|
|
1141
|
-
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
1142
|
-
throw new RangeError(`decimals must be a non-negative integer, got ${decimals}`);
|
|
1143
|
-
}
|
|
1144
|
-
if (typeof usd === "number") {
|
|
1145
|
-
if (!Number.isFinite(usd)) {
|
|
1146
|
-
throw new RangeError(`usd must be finite, got ${usd}`);
|
|
1147
|
-
}
|
|
1148
|
-
if (usd < 0) {
|
|
1149
|
-
throw new RangeError(`usd must be non-negative, got ${usd}`);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
const s = (typeof usd === "number" ? usd.toString() : usd).trim();
|
|
1153
|
-
if (s.startsWith("-")) {
|
|
1154
|
-
throw new RangeError(`usd must be non-negative, got ${s}`);
|
|
1155
|
-
}
|
|
1156
|
-
if (s === "NaN" || s === "Infinity") {
|
|
1157
|
-
throw new RangeError(`usd must be finite, got ${s}`);
|
|
1158
|
-
}
|
|
1159
|
-
const match = /^(\d*)(?:\.(\d*))?$/.exec(s);
|
|
1160
|
-
if (!match || match[1] === "" && (match[2] === void 0 || match[2] === "")) {
|
|
1161
|
-
throw new SyntaxError(`invalid usd value: ${JSON.stringify(usd)}`);
|
|
1162
|
-
}
|
|
1163
|
-
const intPart = match[1] || "0";
|
|
1164
|
-
const fracPart = match[2] ?? "";
|
|
1165
|
-
if (fracPart.length <= decimals) {
|
|
1166
|
-
return BigInt(intPart + fracPart.padEnd(decimals, "0"));
|
|
1167
|
-
}
|
|
1168
|
-
const kept = fracPart.slice(0, decimals);
|
|
1169
|
-
const roundDigit = fracPart[decimals];
|
|
1170
|
-
let result = BigInt(intPart + kept);
|
|
1171
|
-
if (roundDigit >= "5") {
|
|
1172
|
-
result += 1n;
|
|
1173
|
-
}
|
|
1174
|
-
return result;
|
|
1175
|
-
}
|
|
1176
|
-
function formatUsdCents(cents, decimals = 2) {
|
|
1177
|
-
return (cents / 100).toFixed(decimals);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
1179
|
// src/payment/zero-settle.ts
|
|
1181
1180
|
var EVM_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
1182
1181
|
var SOLANA_BASE58_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
@@ -1356,7 +1355,13 @@ function buildMppxComposeRails(opts) {
|
|
|
1356
1355
|
function buildDefaultCheckoutRails(opts) {
|
|
1357
1356
|
const out = {};
|
|
1358
1357
|
if (opts.tempo) {
|
|
1359
|
-
|
|
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;
|
|
1360
1365
|
}
|
|
1361
1366
|
if (opts.x402Base) {
|
|
1362
1367
|
const merged = { recipient: "", ...RAIL_SPEC_DEFAULTS.x402Base, ...opts.x402Base };
|