uvd-x402-sdk 2.86.0 → 2.87.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/dist/backend/index.d.mts +1 -1
- package/dist/backend/index.d.ts +1 -1
- package/dist/backend/index.js +44 -17
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +44 -17
- package/dist/backend/index.mjs.map +1 -1
- package/dist/{index-De03nksW.d.mts → index-BHfYxpzI.d.mts} +136 -27
- package/dist/{index-4_LWWlyF.d.ts → index-D67eNxY8.d.ts} +136 -27
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +62 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backend/index.ts +87 -27
- package/src/index.ts +2 -0
- package/src/lifecycle-auth.ts +209 -32
|
@@ -21,6 +21,19 @@ import { X as X402Version, i as X402Header, j as X402PayloadData } from './index
|
|
|
21
21
|
* KMS. In H2A/H2H the PAYER signs in their own browser with the same wallet
|
|
22
22
|
* they paid with, and the marketplace merely transports the block.
|
|
23
23
|
*
|
|
24
|
+
* >>> TWO SHAPES, ONE ORDER <<<
|
|
25
|
+
* `buildLifecycleAuth` does the whole ceremony in one call: it mints the
|
|
26
|
+
* nonce and the deadline, signs through the injected adapter, and returns the
|
|
27
|
+
* block. That is the server and the `wagmi` paths.
|
|
28
|
+
*
|
|
29
|
+
* A publisher's browser cannot use it. There the backend assembles the
|
|
30
|
+
* document — nonce and deadline included — the browser signs whatever it was
|
|
31
|
+
* handed, and gives back a signature and nothing else. That is
|
|
32
|
+
* {@link buildLifecycleTypedData} on one side and
|
|
33
|
+
* {@link lifecycleAuthFromSignature} on the other, and it produces the SAME
|
|
34
|
+
* bytes as the one-call path for the same nonce and deadline, pinned in
|
|
35
|
+
* `src/lifecycle-auth.test.ts`.
|
|
36
|
+
*
|
|
24
37
|
* Source of truth for the format is the facilitator, `x402-rs`
|
|
25
38
|
* `src/payment_operator/lifecycle_auth.rs` (PR #21). The Python twin is
|
|
26
39
|
* `uvd_x402_sdk.escrow_signing.build_lifecycle_auth` (0.78.0); the two must
|
|
@@ -136,41 +149,29 @@ interface LifecycleTypedDataParams {
|
|
|
136
149
|
amount: string | number | bigint;
|
|
137
150
|
/** EVM chain id of the payment network. */
|
|
138
151
|
chainId: number;
|
|
139
|
-
/** Unix seconds after which the order is dead. */
|
|
140
|
-
deadline: number;
|
|
141
|
-
/** 32 bytes, hex. */
|
|
142
|
-
nonce: string;
|
|
143
|
-
}
|
|
144
|
-
interface BuildLifecycleAuthParams extends Omit<LifecycleTypedDataParams, 'deadline' | 'nonce'> {
|
|
145
152
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
153
|
+
* Unix seconds after which the order is dead. Default: `now + 600`, which
|
|
154
|
+
* leaves 300 s of headroom under the facilitator's 900 s ceiling.
|
|
148
155
|
*/
|
|
149
|
-
wallet: LifecycleSigner;
|
|
150
|
-
/** Unix seconds. Default: `now + 600`. */
|
|
151
156
|
deadline?: number;
|
|
152
157
|
/**
|
|
153
|
-
* 32 bytes
|
|
154
|
-
* facilitator consumes it on acceptance
|
|
155
|
-
* one per delta).
|
|
158
|
+
* 32 bytes, hex. Default: a fresh random one. Distinct PER ORDER — the
|
|
159
|
+
* facilitator consumes it on acceptance.
|
|
156
160
|
*/
|
|
157
161
|
nonce?: string;
|
|
158
|
-
/** Unix seconds, for tests. Default: the clock. */
|
|
162
|
+
/** Unix seconds, for the `deadline` default and for tests. Default: the clock. */
|
|
159
163
|
now?: number;
|
|
160
164
|
}
|
|
161
165
|
/**
|
|
162
|
-
* The
|
|
166
|
+
* The EIP-712 document itself: what {@link buildLifecycleTypedData} returns and
|
|
167
|
+
* what {@link lifecycleAuthFromSignature} reads back.
|
|
163
168
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* @throws {X402Error} `INVALID_CONFIG` on an unknown action or a paymentInfo
|
|
169
|
-
* missing a field; `INVALID_AMOUNT` on a negative amount. Nothing is
|
|
170
|
-
* defaulted: an invented field is a signature over a different struct than
|
|
171
|
-
* the one that is sent, i.e. a rejection the caller cannot diagnose.
|
|
169
|
+
* Named because it is a WIRE type in the split flow: a backend builds it,
|
|
170
|
+
* ships it to a browser as JSON, and the browser hands it to `signTypedData`.
|
|
171
|
+
* `types` carries no `EIP712Domain` entry — ethers and viem both derive that
|
|
172
|
+
* one, and including it makes ethers throw `ambiguous primary types`.
|
|
172
173
|
*/
|
|
173
|
-
|
|
174
|
+
interface LifecycleTypedData {
|
|
174
175
|
domain: {
|
|
175
176
|
name: string;
|
|
176
177
|
version: string;
|
|
@@ -182,7 +183,50 @@ declare function buildLifecycleTypedData(params: LifecycleTypedDataParams): {
|
|
|
182
183
|
}>>;
|
|
183
184
|
primaryType: 'LifecycleOrder';
|
|
184
185
|
message: Record<string, unknown>;
|
|
185
|
-
}
|
|
186
|
+
}
|
|
187
|
+
interface BuildLifecycleAuthParams extends LifecycleTypedDataParams {
|
|
188
|
+
/**
|
|
189
|
+
* The signer. Must be the payer, the receiver or the operator owner
|
|
190
|
+
* depending on the action — see the table in the module docblock.
|
|
191
|
+
*/
|
|
192
|
+
wallet: LifecycleSigner;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The exact EIP-712 document a lifecycle order signs.
|
|
196
|
+
*
|
|
197
|
+
* Kept separate from {@link buildLifecycleAuth} because it is the useful
|
|
198
|
+
* seam: it is what the Python twin mirrors, what a test can poke field by
|
|
199
|
+
* field to confirm the signature stops verifying, and — the reason it is
|
|
200
|
+
* PUBLIC — what a backend hands to a browser that signs.
|
|
201
|
+
*
|
|
202
|
+
* {@link buildLifecycleAuth} cannot serve that browser: it takes an injected
|
|
203
|
+
* `WalletAdapter` and mints its own nonce and deadline, while a publisher
|
|
204
|
+
* signs a document the backend already assembled and hands back only a
|
|
205
|
+
* signature. Build it here, ship it, and reassemble the wire block with
|
|
206
|
+
* {@link lifecycleAuthFromSignature} — which reads `deadline` and `nonce`
|
|
207
|
+
* back out of this same document, so the two cannot disagree.
|
|
208
|
+
*
|
|
209
|
+
* @example The split flow, backend half
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const typedData = buildLifecycleTypedData({
|
|
212
|
+
* action: 'release',
|
|
213
|
+
* paymentInfo: pi, // the SAME object that will be sent
|
|
214
|
+
* payer, // payload.payer
|
|
215
|
+
* amount, // the SAME as payload.amount
|
|
216
|
+
* chainId: 8453,
|
|
217
|
+
* }); // deadline -> now + 600, nonce -> 32 fresh bytes
|
|
218
|
+
* // -> res.json({ typedData }) ... the browser signs it and posts back a signature
|
|
219
|
+
* const lifecycleAuth = lifecycleAuthFromSignature(typedData, signature, payer);
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @throws {X402Error} `INVALID_CONFIG` on an unknown action or a paymentInfo
|
|
223
|
+
* missing a field; `INVALID_AMOUNT` on a negative amount. Nothing IN THE
|
|
224
|
+
* SIGNED STRUCT is defaulted: an invented field is a signature over a
|
|
225
|
+
* different struct than the one that is sent, i.e. a rejection the caller
|
|
226
|
+
* cannot diagnose. `deadline` and `nonce` are the exception because they
|
|
227
|
+
* exist nowhere else — they are born here and read back from the document.
|
|
228
|
+
*/
|
|
229
|
+
declare function buildLifecycleTypedData(params: LifecycleTypedDataParams): LifecycleTypedData;
|
|
186
230
|
/**
|
|
187
231
|
* Sign the order and return the complete `payload.lifecycleAuth` block.
|
|
188
232
|
*
|
|
@@ -199,6 +243,48 @@ declare function buildLifecycleTypedData(params: LifecycleTypedDataParams): {
|
|
|
199
243
|
* `enforce` is stuck money, and the caller has no log to see it in.
|
|
200
244
|
*/
|
|
201
245
|
declare function buildLifecycleAuth(params: BuildLifecycleAuthParams): Promise<LifecycleAuth>;
|
|
246
|
+
/**
|
|
247
|
+
* Reassemble `payload.lifecycleAuth` from a document that was signed
|
|
248
|
+
* ELSEWHERE — the other half of the split flow.
|
|
249
|
+
*
|
|
250
|
+
* `buildLifecycleAuth` owns the whole ceremony: it mints the nonce and the
|
|
251
|
+
* deadline, signs, and returns the block. A publisher's browser owns none of
|
|
252
|
+
* that. It receives a document the backend already assembled and gives back
|
|
253
|
+
* one string. This is the seam where that string becomes a wire block.
|
|
254
|
+
*
|
|
255
|
+
* `deadline` and `nonce` are NOT parameters: they are read out of
|
|
256
|
+
* `typedData.message`, which is the document that was actually hashed. Taking
|
|
257
|
+
* them from the caller would let the block claim a nonce the signature never
|
|
258
|
+
* committed to — a `bad_signature` the caller cannot see, because both halves
|
|
259
|
+
* look right on their own.
|
|
260
|
+
*
|
|
261
|
+
* The signature is NOT recovered here. This SDK's payers include ERC-7702
|
|
262
|
+
* delegated accounts and contract wallets that validate through ERC-1271
|
|
263
|
+
* (`src/erc7702.ts:8`), whose signatures do not ecrecover to their address;
|
|
264
|
+
* `ethers.verifyTypedData` would reject the good ones. Recovery — and the
|
|
265
|
+
* role check that goes with it — is the facilitator's, against the chain.
|
|
266
|
+
*
|
|
267
|
+
* @param typedData - what {@link buildLifecycleTypedData} returned, unmodified.
|
|
268
|
+
* @param signature - the 0x-hex the wallet gave back (`signTypedData`).
|
|
269
|
+
* @param signer - the address that signed, claimed in the block and checked
|
|
270
|
+
* against the recovered one by the facilitator.
|
|
271
|
+
*
|
|
272
|
+
* @throws {X402Error} `INVALID_CONFIG` if the document is not a
|
|
273
|
+
* `LifecycleOrder` for this domain, if the signature is not hex, or if the
|
|
274
|
+
* signer is not an address.
|
|
275
|
+
*
|
|
276
|
+
* @example The browser half
|
|
277
|
+
* ```typescript
|
|
278
|
+
* const signature = await walletClient.signTypedData({
|
|
279
|
+
* domain: typedData.domain,
|
|
280
|
+
* types: typedData.types,
|
|
281
|
+
* primaryType: typedData.primaryType,
|
|
282
|
+
* message: typedData.message,
|
|
283
|
+
* });
|
|
284
|
+
* const lifecycleAuth = lifecycleAuthFromSignature(typedData, signature, address);
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
declare function lifecycleAuthFromSignature(typedData: LifecycleTypedData, signature: string, signer: string): LifecycleAuth;
|
|
202
288
|
/**
|
|
203
289
|
* Minimal wagmi/viem wallet client: what {@link wagmiLifecycleSigner} needs.
|
|
204
290
|
*
|
|
@@ -3326,9 +3412,25 @@ interface LifecycleAuthOptions {
|
|
|
3326
3412
|
lifecycleSigner?: LifecycleSigner;
|
|
3327
3413
|
/**
|
|
3328
3414
|
* Unix seconds. Default: `now + 600`, which leaves 300 s of headroom under
|
|
3329
|
-
* the facilitator's 900 s ceiling.
|
|
3415
|
+
* the facilitator's 900 s ceiling. Only read alongside `lifecycleSigner` —
|
|
3416
|
+
* a `lifecycleAuth` already carries the deadline it was signed with.
|
|
3330
3417
|
*/
|
|
3331
3418
|
lifecycleDeadline?: number;
|
|
3419
|
+
/**
|
|
3420
|
+
* An order that was ALREADY SIGNED somewhere else — the publisher's browser
|
|
3421
|
+
* — and that this backend only transports.
|
|
3422
|
+
*
|
|
3423
|
+
* The signing side builds the document with `buildLifecycleTypedData`, the
|
|
3424
|
+
* browser signs it, and `lifecycleAuthFromSignature` turns the signature
|
|
3425
|
+
* back into this block. Nothing is re-derived here: the `paymentInfo`, the
|
|
3426
|
+
* `payer` and the `amount` this call sends must be the ones the order
|
|
3427
|
+
* committed to, or the facilitator reads `bad_signature`.
|
|
3428
|
+
*
|
|
3429
|
+
* MUTUALLY EXCLUSIVE with `lifecycleSigner`. Passing both is not a
|
|
3430
|
+
* preference to resolve — it means the caller believes two different orders
|
|
3431
|
+
* are about to travel, and only one can. It throws.
|
|
3432
|
+
*/
|
|
3433
|
+
lifecycleAuth?: LifecycleAuth;
|
|
3332
3434
|
}
|
|
3333
3435
|
/**
|
|
3334
3436
|
* Result of an AUTHORIZE operation.
|
|
@@ -3633,6 +3735,13 @@ declare class AdvancedEscrowClient {
|
|
|
3633
3735
|
* lifecycleSigner: payerWallet, // EnvKeyAdapter, OWS, wagmiLifecycleSigner(...)
|
|
3634
3736
|
* });
|
|
3635
3737
|
* ```
|
|
3738
|
+
*
|
|
3739
|
+
* @example Transporting an order the publisher signed in their browser
|
|
3740
|
+
* ```typescript
|
|
3741
|
+
* // The browser sent back a signature over a document THIS backend built.
|
|
3742
|
+
* const lifecycleAuth = lifecycleAuthFromSignature(typedData, signature, payer);
|
|
3743
|
+
* await client.releaseViaFacilitator(pi, amount, { lifecycleAuth });
|
|
3744
|
+
* ```
|
|
3636
3745
|
*/
|
|
3637
3746
|
releaseViaFacilitator(paymentInfo: AdvancedPaymentInfo, amount?: string, options?: LifecycleAuthOptions): Promise<AdvancedTransactionResult>;
|
|
3638
3747
|
/**
|
|
@@ -3753,4 +3862,4 @@ declare class AdvancedEscrowClient {
|
|
|
3753
3862
|
private sendViaAdapter;
|
|
3754
3863
|
}
|
|
3755
3864
|
|
|
3756
|
-
export {
|
|
3865
|
+
export { getCorsHeaders as $, AMBIGUOUS_LEASE_REASONS as A, type BuildLifecycleAuthParams as B, buildLifecycleAuth as C, DEFAULT_FACILITATOR_RETRIES as D, buildLifecycleTypedData as E, FacilitatorClient as F, buildPaymentRequirements as G, type HonoMiddlewareOptions as H, buildSettleRequest as I, buildSettleRequestForVersion as J, buildSettleRequestV2 as K, LIFECYCLE_ACTIONS as L, MAX_RETRY_AFTER_SECONDS as M, buildVerifyRequest as N, buildVerifyRequestForVersion as O, type ParsedFacilitatorErrorBody as P, buildVerifyRequestV2 as Q, REPLAYABLE_LEASE_REASONS as R, SETTLEMENT_UNCONFIRMED as S, create402Response as T, createHonoMiddleware as U, type VerifiedPaymentState as V, WRITER_LEASE_REASONS as W, X402_CORS_HEADERS as X, createPaymentMiddleware as Y, extractPaymentFromHeaders as Z, facilitatorFetch as _, DEFAULT_RETRY_AFTER_SECONDS as a, type FeedbackResponse as a$, isAmbiguousLeaseReason as a0, isReplayableLeaseReason as a1, isSettlementUnconfirmed as a2, lifecycleAuthFromSignature as a3, parseFacilitatorErrorBody as a4, parseRetryAfterSeconds as a5, readFacilitatorError as a6, resolveEnvelopeVersion as a7, toPaymentRequirementsV2 as a8, toResourceInfoV2 as a9, type DiscoveryHealthStatus as aA, type DiscoveryListOptions as aB, type DiscoveryPagination as aC, type DiscoveryRegisterOptions as aD, type DiscoveryResource as aE, type DiscoveryResponse as aF, type DiscoverySource as aG, type DiscoveryStats as aH, type DiscoveryTier as aI, type Dispute as aJ, type DisputeOutcome as aK, ERC8004_CONTRACTS as aL, ERC8004_EXTENSION_ID as aM, ESCROW_CONTRACTS as aN, ESCROW_TIMEOUT_MS as aO, Erc8004Client as aP, type Erc8004ClientOptions as aQ, Erc8004LookupError as aR, type Erc8004Network as aS, EscrowClient as aT, type EscrowClientOptions as aU, type EscrowPayment as aV, type EscrowStateResponse as aW, type EscrowStatus as aX, type FeedbackEntry as aY, type FeedbackParams as aZ, type FeedbackRequest as a_, wagmiLifecycleSigner as aa, type AdvancedAuthorizationResult as ab, AdvancedEscrowClient as ac, type AdvancedEscrowClientOptions as ad, type AdvancedEscrowContracts as ae, type AdvancedEscrowTaskTier as af, type AdvancedPaymentInfo as ag, type AdvancedTransactionResult as ah, type AgentId as ai, type AgentIdentity as aj, type AgentRegistration as ak, type AgentRegistrationFile as al, type AgentService as am, type AtomStats as an, BASE_MAINNET_CONTRACTS as ao, BazaarClient as ap, type BazaarClientOptions as aq, type BazaarDiscoverOptions as ar, type BazaarDiscoverResponse as as, type BazaarRegisterOptions as at, type BazaarResource as au, type CreateEscrowOptions as av, DEPOSIT_LIMIT_USDC as aw, type DiscoveryAccepts as ax, type DiscoveryCuration as ay, type DiscoveryHealth as az, type FacilitatorClientOptions as b, HEALTH_FILTERS as b0, type IdentityByOwnerResponse as b1, type IdentityMetadataResponse as b2, type IdentityTotalSupplyResponse as b3, type LifecycleAuthOptions as b4, MAX_SEARCH_LEN as b5, type MetadataEntryParam as b6, OPERATOR_ABI as b7, OPERATOR_ABI_CREATE3 as b8, PAYMENT_INFO_TYPEHASH as b9, USDC_DOMAIN_NAME as bA, type UnavailableBody as bB, type UnavailableResponse as bC, type VerifyRequest as bD, type VerifyResponse as bE, ZERO_ADDRESS as bF, buildErc8004PaymentRequirements as bG, buildUnavailableResponse as bH, canRefundEscrow as bI, canReleaseEscrow as bJ, carryFailureFields as bK, epochToDate as bL, escrowTimeRemaining as bM, getEscrowContractsByChainId as bN, getEscrowSupportedChainIds as bO, isAlive as bP, isEscrowExpired as bQ, isEscrowSupportedOnChain as bR, isRegisterJobTerminal as bS, parsePaymentHeader as bT, supportsRelayedFeedback as bU, wireNetwork as bV, type PaymentRequirementResolver as ba, type PaymentRequirements as bb, type PaymentRequirementsOptions as bc, type PrepareRelayFeedbackRequest as bd, type PrepareRelayFeedbackResponse as be, type PrepareRelayResponseRequest as bf, type ProofOfPayment as bg, RELAYED_FEEDBACK_NETWORKS as bh, type RefundRequest as bi, type RefundStatus as bj, type RegisterAgentRequest as bk, type RegisterAgentResponse as bl, type RegisterJobResponse as bm, type RegisterJobStatus as bn, RegistrationPendingError as bo, type RelayAuthorizationParams as bp, type ReputationResponse as bq, type ReputationSummary as br, type RequestRefundOptions as bs, type SettleRequest as bt, type SettleResponse as bu, type SettleResponseWithProof as bv, type SubmitRelayFeedbackRequest as bw, type SubmitRelayResponseRequest as bx, TIER_FILTERS as by, TIER_TIMINGS as bz, type FacilitatorErrorInfo as c, type FacilitatorFailureFields as d, type FacilitatorFetchOptions as e, LIFECYCLE_DEFAULT_DEADLINE_SECS as f, LIFECYCLE_DOMAIN_NAME as g, LIFECYCLE_DOMAIN_VERSION as h, LIFECYCLE_MAX_DEADLINE_SECS as i, LIFECYCLE_ORDER_TYPES as j, type LifecycleAction as k, type LifecycleAuth as l, type LifecyclePaymentInfo as m, type LifecycleSigner as n, type LifecycleTypedData as o, type LifecycleTypedDataParams as p, type PaymentAcceptance as q, type PaymentMiddlewareOptions as r, type PaymentPayloadV2 as s, type PaymentRequirementsV2 as t, type ResourceInfoV2 as u, type SettleRequestV2 as v, type VerifyRequestV2 as w, type WagmiLifecycleWalletClient as x, type WriterLeaseReason as y, X402_HEADER_NAMES as z };
|
|
@@ -21,6 +21,19 @@ import { X as X402Version, i as X402Header, j as X402PayloadData } from './index
|
|
|
21
21
|
* KMS. In H2A/H2H the PAYER signs in their own browser with the same wallet
|
|
22
22
|
* they paid with, and the marketplace merely transports the block.
|
|
23
23
|
*
|
|
24
|
+
* >>> TWO SHAPES, ONE ORDER <<<
|
|
25
|
+
* `buildLifecycleAuth` does the whole ceremony in one call: it mints the
|
|
26
|
+
* nonce and the deadline, signs through the injected adapter, and returns the
|
|
27
|
+
* block. That is the server and the `wagmi` paths.
|
|
28
|
+
*
|
|
29
|
+
* A publisher's browser cannot use it. There the backend assembles the
|
|
30
|
+
* document — nonce and deadline included — the browser signs whatever it was
|
|
31
|
+
* handed, and gives back a signature and nothing else. That is
|
|
32
|
+
* {@link buildLifecycleTypedData} on one side and
|
|
33
|
+
* {@link lifecycleAuthFromSignature} on the other, and it produces the SAME
|
|
34
|
+
* bytes as the one-call path for the same nonce and deadline, pinned in
|
|
35
|
+
* `src/lifecycle-auth.test.ts`.
|
|
36
|
+
*
|
|
24
37
|
* Source of truth for the format is the facilitator, `x402-rs`
|
|
25
38
|
* `src/payment_operator/lifecycle_auth.rs` (PR #21). The Python twin is
|
|
26
39
|
* `uvd_x402_sdk.escrow_signing.build_lifecycle_auth` (0.78.0); the two must
|
|
@@ -136,41 +149,29 @@ interface LifecycleTypedDataParams {
|
|
|
136
149
|
amount: string | number | bigint;
|
|
137
150
|
/** EVM chain id of the payment network. */
|
|
138
151
|
chainId: number;
|
|
139
|
-
/** Unix seconds after which the order is dead. */
|
|
140
|
-
deadline: number;
|
|
141
|
-
/** 32 bytes, hex. */
|
|
142
|
-
nonce: string;
|
|
143
|
-
}
|
|
144
|
-
interface BuildLifecycleAuthParams extends Omit<LifecycleTypedDataParams, 'deadline' | 'nonce'> {
|
|
145
152
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
153
|
+
* Unix seconds after which the order is dead. Default: `now + 600`, which
|
|
154
|
+
* leaves 300 s of headroom under the facilitator's 900 s ceiling.
|
|
148
155
|
*/
|
|
149
|
-
wallet: LifecycleSigner;
|
|
150
|
-
/** Unix seconds. Default: `now + 600`. */
|
|
151
156
|
deadline?: number;
|
|
152
157
|
/**
|
|
153
|
-
* 32 bytes
|
|
154
|
-
* facilitator consumes it on acceptance
|
|
155
|
-
* one per delta).
|
|
158
|
+
* 32 bytes, hex. Default: a fresh random one. Distinct PER ORDER — the
|
|
159
|
+
* facilitator consumes it on acceptance.
|
|
156
160
|
*/
|
|
157
161
|
nonce?: string;
|
|
158
|
-
/** Unix seconds, for tests. Default: the clock. */
|
|
162
|
+
/** Unix seconds, for the `deadline` default and for tests. Default: the clock. */
|
|
159
163
|
now?: number;
|
|
160
164
|
}
|
|
161
165
|
/**
|
|
162
|
-
* The
|
|
166
|
+
* The EIP-712 document itself: what {@link buildLifecycleTypedData} returns and
|
|
167
|
+
* what {@link lifecycleAuthFromSignature} reads back.
|
|
163
168
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* @throws {X402Error} `INVALID_CONFIG` on an unknown action or a paymentInfo
|
|
169
|
-
* missing a field; `INVALID_AMOUNT` on a negative amount. Nothing is
|
|
170
|
-
* defaulted: an invented field is a signature over a different struct than
|
|
171
|
-
* the one that is sent, i.e. a rejection the caller cannot diagnose.
|
|
169
|
+
* Named because it is a WIRE type in the split flow: a backend builds it,
|
|
170
|
+
* ships it to a browser as JSON, and the browser hands it to `signTypedData`.
|
|
171
|
+
* `types` carries no `EIP712Domain` entry — ethers and viem both derive that
|
|
172
|
+
* one, and including it makes ethers throw `ambiguous primary types`.
|
|
172
173
|
*/
|
|
173
|
-
|
|
174
|
+
interface LifecycleTypedData {
|
|
174
175
|
domain: {
|
|
175
176
|
name: string;
|
|
176
177
|
version: string;
|
|
@@ -182,7 +183,50 @@ declare function buildLifecycleTypedData(params: LifecycleTypedDataParams): {
|
|
|
182
183
|
}>>;
|
|
183
184
|
primaryType: 'LifecycleOrder';
|
|
184
185
|
message: Record<string, unknown>;
|
|
185
|
-
}
|
|
186
|
+
}
|
|
187
|
+
interface BuildLifecycleAuthParams extends LifecycleTypedDataParams {
|
|
188
|
+
/**
|
|
189
|
+
* The signer. Must be the payer, the receiver or the operator owner
|
|
190
|
+
* depending on the action — see the table in the module docblock.
|
|
191
|
+
*/
|
|
192
|
+
wallet: LifecycleSigner;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The exact EIP-712 document a lifecycle order signs.
|
|
196
|
+
*
|
|
197
|
+
* Kept separate from {@link buildLifecycleAuth} because it is the useful
|
|
198
|
+
* seam: it is what the Python twin mirrors, what a test can poke field by
|
|
199
|
+
* field to confirm the signature stops verifying, and — the reason it is
|
|
200
|
+
* PUBLIC — what a backend hands to a browser that signs.
|
|
201
|
+
*
|
|
202
|
+
* {@link buildLifecycleAuth} cannot serve that browser: it takes an injected
|
|
203
|
+
* `WalletAdapter` and mints its own nonce and deadline, while a publisher
|
|
204
|
+
* signs a document the backend already assembled and hands back only a
|
|
205
|
+
* signature. Build it here, ship it, and reassemble the wire block with
|
|
206
|
+
* {@link lifecycleAuthFromSignature} — which reads `deadline` and `nonce`
|
|
207
|
+
* back out of this same document, so the two cannot disagree.
|
|
208
|
+
*
|
|
209
|
+
* @example The split flow, backend half
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const typedData = buildLifecycleTypedData({
|
|
212
|
+
* action: 'release',
|
|
213
|
+
* paymentInfo: pi, // the SAME object that will be sent
|
|
214
|
+
* payer, // payload.payer
|
|
215
|
+
* amount, // the SAME as payload.amount
|
|
216
|
+
* chainId: 8453,
|
|
217
|
+
* }); // deadline -> now + 600, nonce -> 32 fresh bytes
|
|
218
|
+
* // -> res.json({ typedData }) ... the browser signs it and posts back a signature
|
|
219
|
+
* const lifecycleAuth = lifecycleAuthFromSignature(typedData, signature, payer);
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @throws {X402Error} `INVALID_CONFIG` on an unknown action or a paymentInfo
|
|
223
|
+
* missing a field; `INVALID_AMOUNT` on a negative amount. Nothing IN THE
|
|
224
|
+
* SIGNED STRUCT is defaulted: an invented field is a signature over a
|
|
225
|
+
* different struct than the one that is sent, i.e. a rejection the caller
|
|
226
|
+
* cannot diagnose. `deadline` and `nonce` are the exception because they
|
|
227
|
+
* exist nowhere else — they are born here and read back from the document.
|
|
228
|
+
*/
|
|
229
|
+
declare function buildLifecycleTypedData(params: LifecycleTypedDataParams): LifecycleTypedData;
|
|
186
230
|
/**
|
|
187
231
|
* Sign the order and return the complete `payload.lifecycleAuth` block.
|
|
188
232
|
*
|
|
@@ -199,6 +243,48 @@ declare function buildLifecycleTypedData(params: LifecycleTypedDataParams): {
|
|
|
199
243
|
* `enforce` is stuck money, and the caller has no log to see it in.
|
|
200
244
|
*/
|
|
201
245
|
declare function buildLifecycleAuth(params: BuildLifecycleAuthParams): Promise<LifecycleAuth>;
|
|
246
|
+
/**
|
|
247
|
+
* Reassemble `payload.lifecycleAuth` from a document that was signed
|
|
248
|
+
* ELSEWHERE — the other half of the split flow.
|
|
249
|
+
*
|
|
250
|
+
* `buildLifecycleAuth` owns the whole ceremony: it mints the nonce and the
|
|
251
|
+
* deadline, signs, and returns the block. A publisher's browser owns none of
|
|
252
|
+
* that. It receives a document the backend already assembled and gives back
|
|
253
|
+
* one string. This is the seam where that string becomes a wire block.
|
|
254
|
+
*
|
|
255
|
+
* `deadline` and `nonce` are NOT parameters: they are read out of
|
|
256
|
+
* `typedData.message`, which is the document that was actually hashed. Taking
|
|
257
|
+
* them from the caller would let the block claim a nonce the signature never
|
|
258
|
+
* committed to — a `bad_signature` the caller cannot see, because both halves
|
|
259
|
+
* look right on their own.
|
|
260
|
+
*
|
|
261
|
+
* The signature is NOT recovered here. This SDK's payers include ERC-7702
|
|
262
|
+
* delegated accounts and contract wallets that validate through ERC-1271
|
|
263
|
+
* (`src/erc7702.ts:8`), whose signatures do not ecrecover to their address;
|
|
264
|
+
* `ethers.verifyTypedData` would reject the good ones. Recovery — and the
|
|
265
|
+
* role check that goes with it — is the facilitator's, against the chain.
|
|
266
|
+
*
|
|
267
|
+
* @param typedData - what {@link buildLifecycleTypedData} returned, unmodified.
|
|
268
|
+
* @param signature - the 0x-hex the wallet gave back (`signTypedData`).
|
|
269
|
+
* @param signer - the address that signed, claimed in the block and checked
|
|
270
|
+
* against the recovered one by the facilitator.
|
|
271
|
+
*
|
|
272
|
+
* @throws {X402Error} `INVALID_CONFIG` if the document is not a
|
|
273
|
+
* `LifecycleOrder` for this domain, if the signature is not hex, or if the
|
|
274
|
+
* signer is not an address.
|
|
275
|
+
*
|
|
276
|
+
* @example The browser half
|
|
277
|
+
* ```typescript
|
|
278
|
+
* const signature = await walletClient.signTypedData({
|
|
279
|
+
* domain: typedData.domain,
|
|
280
|
+
* types: typedData.types,
|
|
281
|
+
* primaryType: typedData.primaryType,
|
|
282
|
+
* message: typedData.message,
|
|
283
|
+
* });
|
|
284
|
+
* const lifecycleAuth = lifecycleAuthFromSignature(typedData, signature, address);
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
declare function lifecycleAuthFromSignature(typedData: LifecycleTypedData, signature: string, signer: string): LifecycleAuth;
|
|
202
288
|
/**
|
|
203
289
|
* Minimal wagmi/viem wallet client: what {@link wagmiLifecycleSigner} needs.
|
|
204
290
|
*
|
|
@@ -3326,9 +3412,25 @@ interface LifecycleAuthOptions {
|
|
|
3326
3412
|
lifecycleSigner?: LifecycleSigner;
|
|
3327
3413
|
/**
|
|
3328
3414
|
* Unix seconds. Default: `now + 600`, which leaves 300 s of headroom under
|
|
3329
|
-
* the facilitator's 900 s ceiling.
|
|
3415
|
+
* the facilitator's 900 s ceiling. Only read alongside `lifecycleSigner` —
|
|
3416
|
+
* a `lifecycleAuth` already carries the deadline it was signed with.
|
|
3330
3417
|
*/
|
|
3331
3418
|
lifecycleDeadline?: number;
|
|
3419
|
+
/**
|
|
3420
|
+
* An order that was ALREADY SIGNED somewhere else — the publisher's browser
|
|
3421
|
+
* — and that this backend only transports.
|
|
3422
|
+
*
|
|
3423
|
+
* The signing side builds the document with `buildLifecycleTypedData`, the
|
|
3424
|
+
* browser signs it, and `lifecycleAuthFromSignature` turns the signature
|
|
3425
|
+
* back into this block. Nothing is re-derived here: the `paymentInfo`, the
|
|
3426
|
+
* `payer` and the `amount` this call sends must be the ones the order
|
|
3427
|
+
* committed to, or the facilitator reads `bad_signature`.
|
|
3428
|
+
*
|
|
3429
|
+
* MUTUALLY EXCLUSIVE with `lifecycleSigner`. Passing both is not a
|
|
3430
|
+
* preference to resolve — it means the caller believes two different orders
|
|
3431
|
+
* are about to travel, and only one can. It throws.
|
|
3432
|
+
*/
|
|
3433
|
+
lifecycleAuth?: LifecycleAuth;
|
|
3332
3434
|
}
|
|
3333
3435
|
/**
|
|
3334
3436
|
* Result of an AUTHORIZE operation.
|
|
@@ -3633,6 +3735,13 @@ declare class AdvancedEscrowClient {
|
|
|
3633
3735
|
* lifecycleSigner: payerWallet, // EnvKeyAdapter, OWS, wagmiLifecycleSigner(...)
|
|
3634
3736
|
* });
|
|
3635
3737
|
* ```
|
|
3738
|
+
*
|
|
3739
|
+
* @example Transporting an order the publisher signed in their browser
|
|
3740
|
+
* ```typescript
|
|
3741
|
+
* // The browser sent back a signature over a document THIS backend built.
|
|
3742
|
+
* const lifecycleAuth = lifecycleAuthFromSignature(typedData, signature, payer);
|
|
3743
|
+
* await client.releaseViaFacilitator(pi, amount, { lifecycleAuth });
|
|
3744
|
+
* ```
|
|
3636
3745
|
*/
|
|
3637
3746
|
releaseViaFacilitator(paymentInfo: AdvancedPaymentInfo, amount?: string, options?: LifecycleAuthOptions): Promise<AdvancedTransactionResult>;
|
|
3638
3747
|
/**
|
|
@@ -3753,4 +3862,4 @@ declare class AdvancedEscrowClient {
|
|
|
3753
3862
|
private sendViaAdapter;
|
|
3754
3863
|
}
|
|
3755
3864
|
|
|
3756
|
-
export {
|
|
3865
|
+
export { getCorsHeaders as $, AMBIGUOUS_LEASE_REASONS as A, type BuildLifecycleAuthParams as B, buildLifecycleAuth as C, DEFAULT_FACILITATOR_RETRIES as D, buildLifecycleTypedData as E, FacilitatorClient as F, buildPaymentRequirements as G, type HonoMiddlewareOptions as H, buildSettleRequest as I, buildSettleRequestForVersion as J, buildSettleRequestV2 as K, LIFECYCLE_ACTIONS as L, MAX_RETRY_AFTER_SECONDS as M, buildVerifyRequest as N, buildVerifyRequestForVersion as O, type ParsedFacilitatorErrorBody as P, buildVerifyRequestV2 as Q, REPLAYABLE_LEASE_REASONS as R, SETTLEMENT_UNCONFIRMED as S, create402Response as T, createHonoMiddleware as U, type VerifiedPaymentState as V, WRITER_LEASE_REASONS as W, X402_CORS_HEADERS as X, createPaymentMiddleware as Y, extractPaymentFromHeaders as Z, facilitatorFetch as _, DEFAULT_RETRY_AFTER_SECONDS as a, type FeedbackResponse as a$, isAmbiguousLeaseReason as a0, isReplayableLeaseReason as a1, isSettlementUnconfirmed as a2, lifecycleAuthFromSignature as a3, parseFacilitatorErrorBody as a4, parseRetryAfterSeconds as a5, readFacilitatorError as a6, resolveEnvelopeVersion as a7, toPaymentRequirementsV2 as a8, toResourceInfoV2 as a9, type DiscoveryHealthStatus as aA, type DiscoveryListOptions as aB, type DiscoveryPagination as aC, type DiscoveryRegisterOptions as aD, type DiscoveryResource as aE, type DiscoveryResponse as aF, type DiscoverySource as aG, type DiscoveryStats as aH, type DiscoveryTier as aI, type Dispute as aJ, type DisputeOutcome as aK, ERC8004_CONTRACTS as aL, ERC8004_EXTENSION_ID as aM, ESCROW_CONTRACTS as aN, ESCROW_TIMEOUT_MS as aO, Erc8004Client as aP, type Erc8004ClientOptions as aQ, Erc8004LookupError as aR, type Erc8004Network as aS, EscrowClient as aT, type EscrowClientOptions as aU, type EscrowPayment as aV, type EscrowStateResponse as aW, type EscrowStatus as aX, type FeedbackEntry as aY, type FeedbackParams as aZ, type FeedbackRequest as a_, wagmiLifecycleSigner as aa, type AdvancedAuthorizationResult as ab, AdvancedEscrowClient as ac, type AdvancedEscrowClientOptions as ad, type AdvancedEscrowContracts as ae, type AdvancedEscrowTaskTier as af, type AdvancedPaymentInfo as ag, type AdvancedTransactionResult as ah, type AgentId as ai, type AgentIdentity as aj, type AgentRegistration as ak, type AgentRegistrationFile as al, type AgentService as am, type AtomStats as an, BASE_MAINNET_CONTRACTS as ao, BazaarClient as ap, type BazaarClientOptions as aq, type BazaarDiscoverOptions as ar, type BazaarDiscoverResponse as as, type BazaarRegisterOptions as at, type BazaarResource as au, type CreateEscrowOptions as av, DEPOSIT_LIMIT_USDC as aw, type DiscoveryAccepts as ax, type DiscoveryCuration as ay, type DiscoveryHealth as az, type FacilitatorClientOptions as b, HEALTH_FILTERS as b0, type IdentityByOwnerResponse as b1, type IdentityMetadataResponse as b2, type IdentityTotalSupplyResponse as b3, type LifecycleAuthOptions as b4, MAX_SEARCH_LEN as b5, type MetadataEntryParam as b6, OPERATOR_ABI as b7, OPERATOR_ABI_CREATE3 as b8, PAYMENT_INFO_TYPEHASH as b9, USDC_DOMAIN_NAME as bA, type UnavailableBody as bB, type UnavailableResponse as bC, type VerifyRequest as bD, type VerifyResponse as bE, ZERO_ADDRESS as bF, buildErc8004PaymentRequirements as bG, buildUnavailableResponse as bH, canRefundEscrow as bI, canReleaseEscrow as bJ, carryFailureFields as bK, epochToDate as bL, escrowTimeRemaining as bM, getEscrowContractsByChainId as bN, getEscrowSupportedChainIds as bO, isAlive as bP, isEscrowExpired as bQ, isEscrowSupportedOnChain as bR, isRegisterJobTerminal as bS, parsePaymentHeader as bT, supportsRelayedFeedback as bU, wireNetwork as bV, type PaymentRequirementResolver as ba, type PaymentRequirements as bb, type PaymentRequirementsOptions as bc, type PrepareRelayFeedbackRequest as bd, type PrepareRelayFeedbackResponse as be, type PrepareRelayResponseRequest as bf, type ProofOfPayment as bg, RELAYED_FEEDBACK_NETWORKS as bh, type RefundRequest as bi, type RefundStatus as bj, type RegisterAgentRequest as bk, type RegisterAgentResponse as bl, type RegisterJobResponse as bm, type RegisterJobStatus as bn, RegistrationPendingError as bo, type RelayAuthorizationParams as bp, type ReputationResponse as bq, type ReputationSummary as br, type RequestRefundOptions as bs, type SettleRequest as bt, type SettleResponse as bu, type SettleResponseWithProof as bv, type SubmitRelayFeedbackRequest as bw, type SubmitRelayResponseRequest as bx, TIER_FILTERS as by, TIER_TIMINGS as bz, type FacilitatorErrorInfo as c, type FacilitatorFailureFields as d, type FacilitatorFetchOptions as e, LIFECYCLE_DEFAULT_DEADLINE_SECS as f, LIFECYCLE_DOMAIN_NAME as g, LIFECYCLE_DOMAIN_VERSION as h, LIFECYCLE_MAX_DEADLINE_SECS as i, LIFECYCLE_ORDER_TYPES as j, type LifecycleAction as k, type LifecycleAuth as l, type LifecyclePaymentInfo as m, type LifecycleSigner as n, type LifecycleTypedData as o, type LifecycleTypedDataParams as p, type PaymentAcceptance as q, type PaymentMiddlewareOptions as r, type PaymentPayloadV2 as s, type PaymentRequirementsV2 as t, type ResourceInfoV2 as u, type SettleRequestV2 as v, type VerifyRequestV2 as w, type WagmiLifecycleWalletClient as x, type WriterLeaseReason as y, X402_HEADER_NAMES as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ export { A as AlgorandPaymentPayload, q as CAIP2_IDENTIFIERS, r as CAIP2_TO_CHAI
|
|
|
4
4
|
import { S as SigningWalletAdapter } from './wallet-w7BnImDG.mjs';
|
|
5
5
|
export { a as EIP3009Authorization, E as EIP3009Params } from './wallet-w7BnImDG.mjs';
|
|
6
6
|
export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-Z9v4GxOZ.mjs';
|
|
7
|
-
export { A as AMBIGUOUS_LEASE_REASONS, B as BuildLifecycleAuthParams, D as DEFAULT_FACILITATOR_RETRIES, a as DEFAULT_RETRY_AFTER_SECONDS, F as FacilitatorClient, b as FacilitatorClientOptions, c as FacilitatorErrorInfo, d as FacilitatorFailureFields, e as FacilitatorFetchOptions, H as HonoMiddlewareOptions, L as LIFECYCLE_ACTIONS, f as LIFECYCLE_DEFAULT_DEADLINE_SECS, g as LIFECYCLE_DOMAIN_NAME, h as LIFECYCLE_DOMAIN_VERSION, i as LIFECYCLE_MAX_DEADLINE_SECS, j as LIFECYCLE_ORDER_TYPES, k as LifecycleAction, l as LifecycleAuth, m as LifecyclePaymentInfo, n as LifecycleSigner, o as LifecycleTypedDataParams, M as MAX_RETRY_AFTER_SECONDS, P as ParsedFacilitatorErrorBody,
|
|
7
|
+
export { A as AMBIGUOUS_LEASE_REASONS, B as BuildLifecycleAuthParams, D as DEFAULT_FACILITATOR_RETRIES, a as DEFAULT_RETRY_AFTER_SECONDS, F as FacilitatorClient, b as FacilitatorClientOptions, c as FacilitatorErrorInfo, d as FacilitatorFailureFields, e as FacilitatorFetchOptions, H as HonoMiddlewareOptions, L as LIFECYCLE_ACTIONS, f as LIFECYCLE_DEFAULT_DEADLINE_SECS, g as LIFECYCLE_DOMAIN_NAME, h as LIFECYCLE_DOMAIN_VERSION, i as LIFECYCLE_MAX_DEADLINE_SECS, j as LIFECYCLE_ORDER_TYPES, k as LifecycleAction, l as LifecycleAuth, m as LifecyclePaymentInfo, n as LifecycleSigner, o as LifecycleTypedData, p as LifecycleTypedDataParams, M as MAX_RETRY_AFTER_SECONDS, P as ParsedFacilitatorErrorBody, q as PaymentAcceptance, r as PaymentMiddlewareOptions, s as PaymentPayloadV2, t as PaymentRequirementsV2, R as REPLAYABLE_LEASE_REASONS, u as ResourceInfoV2, S as SETTLEMENT_UNCONFIRMED, v as SettleRequestV2, V as VerifiedPaymentState, w as VerifyRequestV2, W as WRITER_LEASE_REASONS, x as WagmiLifecycleWalletClient, y as WriterLeaseReason, X as X402_CORS_HEADERS, z as X402_HEADER_NAMES, C as buildLifecycleAuth, E as buildLifecycleTypedData, G as buildPaymentRequirements, I as buildSettleRequest, J as buildSettleRequestForVersion, K as buildSettleRequestV2, N as buildVerifyRequest, O as buildVerifyRequestForVersion, Q as buildVerifyRequestV2, T as create402Response, U as createHonoMiddleware, Y as createPaymentMiddleware, Z as extractPaymentFromHeaders, _ as facilitatorFetch, $ as getCorsHeaders, a0 as isAmbiguousLeaseReason, a1 as isReplayableLeaseReason, a2 as isSettlementUnconfirmed, a3 as lifecycleAuthFromSignature, a4 as parseFacilitatorErrorBody, a5 as parseRetryAfterSeconds, a6 as readFacilitatorError, a7 as resolveEnvelopeVersion, a8 as toPaymentRequirementsV2, a9 as toResourceInfoV2, aa as wagmiLifecycleSigner } from './index-BHfYxpzI.mjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* DX402 `durable-evidence`: recover a paid response after the fact.
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { A as AlgorandPaymentPayload, q as CAIP2_IDENTIFIERS, r as CAIP2_TO_CHAI
|
|
|
4
4
|
import { S as SigningWalletAdapter } from './wallet-w7BnImDG.js';
|
|
5
5
|
export { a as EIP3009Authorization, E as EIP3009Params } from './wallet-w7BnImDG.js';
|
|
6
6
|
export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-C-KmORG9.js';
|
|
7
|
-
export { A as AMBIGUOUS_LEASE_REASONS, B as BuildLifecycleAuthParams, D as DEFAULT_FACILITATOR_RETRIES, a as DEFAULT_RETRY_AFTER_SECONDS, F as FacilitatorClient, b as FacilitatorClientOptions, c as FacilitatorErrorInfo, d as FacilitatorFailureFields, e as FacilitatorFetchOptions, H as HonoMiddlewareOptions, L as LIFECYCLE_ACTIONS, f as LIFECYCLE_DEFAULT_DEADLINE_SECS, g as LIFECYCLE_DOMAIN_NAME, h as LIFECYCLE_DOMAIN_VERSION, i as LIFECYCLE_MAX_DEADLINE_SECS, j as LIFECYCLE_ORDER_TYPES, k as LifecycleAction, l as LifecycleAuth, m as LifecyclePaymentInfo, n as LifecycleSigner, o as LifecycleTypedDataParams, M as MAX_RETRY_AFTER_SECONDS, P as ParsedFacilitatorErrorBody,
|
|
7
|
+
export { A as AMBIGUOUS_LEASE_REASONS, B as BuildLifecycleAuthParams, D as DEFAULT_FACILITATOR_RETRIES, a as DEFAULT_RETRY_AFTER_SECONDS, F as FacilitatorClient, b as FacilitatorClientOptions, c as FacilitatorErrorInfo, d as FacilitatorFailureFields, e as FacilitatorFetchOptions, H as HonoMiddlewareOptions, L as LIFECYCLE_ACTIONS, f as LIFECYCLE_DEFAULT_DEADLINE_SECS, g as LIFECYCLE_DOMAIN_NAME, h as LIFECYCLE_DOMAIN_VERSION, i as LIFECYCLE_MAX_DEADLINE_SECS, j as LIFECYCLE_ORDER_TYPES, k as LifecycleAction, l as LifecycleAuth, m as LifecyclePaymentInfo, n as LifecycleSigner, o as LifecycleTypedData, p as LifecycleTypedDataParams, M as MAX_RETRY_AFTER_SECONDS, P as ParsedFacilitatorErrorBody, q as PaymentAcceptance, r as PaymentMiddlewareOptions, s as PaymentPayloadV2, t as PaymentRequirementsV2, R as REPLAYABLE_LEASE_REASONS, u as ResourceInfoV2, S as SETTLEMENT_UNCONFIRMED, v as SettleRequestV2, V as VerifiedPaymentState, w as VerifyRequestV2, W as WRITER_LEASE_REASONS, x as WagmiLifecycleWalletClient, y as WriterLeaseReason, X as X402_CORS_HEADERS, z as X402_HEADER_NAMES, C as buildLifecycleAuth, E as buildLifecycleTypedData, G as buildPaymentRequirements, I as buildSettleRequest, J as buildSettleRequestForVersion, K as buildSettleRequestV2, N as buildVerifyRequest, O as buildVerifyRequestForVersion, Q as buildVerifyRequestV2, T as create402Response, U as createHonoMiddleware, Y as createPaymentMiddleware, Z as extractPaymentFromHeaders, _ as facilitatorFetch, $ as getCorsHeaders, a0 as isAmbiguousLeaseReason, a1 as isReplayableLeaseReason, a2 as isSettlementUnconfirmed, a3 as lifecycleAuthFromSignature, a4 as parseFacilitatorErrorBody, a5 as parseRetryAfterSeconds, a6 as readFacilitatorError, a7 as resolveEnvelopeVersion, a8 as toPaymentRequirementsV2, a9 as toResourceInfoV2, aa as wagmiLifecycleSigner } from './index-D67eNxY8.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* DX402 `durable-evidence`: recover a paid response after the fact.
|
package/dist/index.js
CHANGED
|
@@ -4556,6 +4556,14 @@ function randomNonce() {
|
|
|
4556
4556
|
}
|
|
4557
4557
|
return ethers.ethers.hexlify(ethers.ethers.randomBytes(32));
|
|
4558
4558
|
}
|
|
4559
|
+
function resolveOrderTiming(params) {
|
|
4560
|
+
const nowSec = params.now === void 0 ? Math.floor(Date.now() / 1e3) : Math.floor(params.now);
|
|
4561
|
+
return {
|
|
4562
|
+
nowSec,
|
|
4563
|
+
deadline: params.deadline === void 0 ? nowSec + LIFECYCLE_DEFAULT_DEADLINE_SECS : Math.floor(params.deadline),
|
|
4564
|
+
nonce: params.nonce === void 0 ? randomNonce() : params.nonce
|
|
4565
|
+
};
|
|
4566
|
+
}
|
|
4559
4567
|
function toUintString(value, field) {
|
|
4560
4568
|
let n;
|
|
4561
4569
|
try {
|
|
@@ -4569,7 +4577,8 @@ function toUintString(value, field) {
|
|
|
4569
4577
|
return n.toString();
|
|
4570
4578
|
}
|
|
4571
4579
|
function buildLifecycleTypedData(params) {
|
|
4572
|
-
const { action, paymentInfo, payer, amount, chainId
|
|
4580
|
+
const { action, paymentInfo, payer, amount, chainId } = params;
|
|
4581
|
+
const { deadline, nonce } = resolveOrderTiming(params);
|
|
4573
4582
|
if (!LIFECYCLE_ACTIONS.includes(action)) {
|
|
4574
4583
|
throw new exports.X402Error(
|
|
4575
4584
|
`unknown lifecycle action ${String(action)}; the facilitator only signs ${LIFECYCLE_ACTIONS.join(", ")}`,
|
|
@@ -4628,10 +4637,8 @@ function buildLifecycleTypedData(params) {
|
|
|
4628
4637
|
};
|
|
4629
4638
|
}
|
|
4630
4639
|
async function buildLifecycleAuth(params) {
|
|
4631
|
-
const { wallet,
|
|
4632
|
-
const nowSec
|
|
4633
|
-
const dl = deadline === void 0 ? nowSec + LIFECYCLE_DEFAULT_DEADLINE_SECS : Math.floor(deadline);
|
|
4634
|
-
const nonceHex = nonce === void 0 ? randomNonce() : nonce;
|
|
4640
|
+
const { wallet, ...rest } = params;
|
|
4641
|
+
const { nowSec, deadline: dl, nonce: nonceHex } = resolveOrderTiming(params);
|
|
4635
4642
|
if (dl < nowSec) {
|
|
4636
4643
|
throw new exports.X402Error(
|
|
4637
4644
|
`deadline ${dl} is in the past (now ${nowSec}): the facilitator discards it as \`expired\``,
|
|
@@ -4653,6 +4660,54 @@ async function buildLifecycleAuth(params) {
|
|
|
4653
4660
|
signature: signed.signature
|
|
4654
4661
|
};
|
|
4655
4662
|
}
|
|
4663
|
+
function lifecycleAuthFromSignature(typedData, signature, signer) {
|
|
4664
|
+
const td = typedData ?? {};
|
|
4665
|
+
const message = td.message ?? {};
|
|
4666
|
+
if (td.primaryType !== "LifecycleOrder") {
|
|
4667
|
+
throw new exports.X402Error(
|
|
4668
|
+
`typedData.primaryType must be LifecycleOrder, got ${String(td.primaryType)}: pass the document buildLifecycleTypedData returned, unmodified`,
|
|
4669
|
+
"INVALID_CONFIG"
|
|
4670
|
+
);
|
|
4671
|
+
}
|
|
4672
|
+
const domain = td.domain ?? {};
|
|
4673
|
+
if (domain.name !== LIFECYCLE_DOMAIN_NAME || String(domain.version) !== LIFECYCLE_DOMAIN_VERSION) {
|
|
4674
|
+
throw new exports.X402Error(
|
|
4675
|
+
`typedData.domain must be ${LIFECYCLE_DOMAIN_NAME} v${LIFECYCLE_DOMAIN_VERSION}, got ${String(domain.name)} v${String(domain.version)}`,
|
|
4676
|
+
"INVALID_CONFIG"
|
|
4677
|
+
);
|
|
4678
|
+
}
|
|
4679
|
+
if (message.deadline === void 0 || message.nonce === void 0) {
|
|
4680
|
+
throw new exports.X402Error(
|
|
4681
|
+
"typedData.message carries no deadline/nonce: the wire block reads them from the document that was signed, it does not invent them",
|
|
4682
|
+
"INVALID_CONFIG"
|
|
4683
|
+
);
|
|
4684
|
+
}
|
|
4685
|
+
const deadlineBig = BigInt(toUintString(message.deadline, "typedData.message.deadline"));
|
|
4686
|
+
if (deadlineBig > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
4687
|
+
throw new exports.X402Error(
|
|
4688
|
+
`typedData.message.deadline ${deadlineBig} does not fit a JSON number`,
|
|
4689
|
+
"INVALID_CONFIG"
|
|
4690
|
+
);
|
|
4691
|
+
}
|
|
4692
|
+
if (typeof signature !== "string" || !/^0x[0-9a-fA-F]+$/.test(signature) || signature.length % 2 !== 0) {
|
|
4693
|
+
throw new exports.X402Error(
|
|
4694
|
+
`signature must be 0x-prefixed hex, got ${String(signature)}`,
|
|
4695
|
+
"INVALID_CONFIG"
|
|
4696
|
+
);
|
|
4697
|
+
}
|
|
4698
|
+
let checksummed;
|
|
4699
|
+
try {
|
|
4700
|
+
checksummed = ethers.ethers.getAddress(signer);
|
|
4701
|
+
} catch {
|
|
4702
|
+
throw new exports.X402Error(`signer is not an EVM address: ${String(signer)}`, "INVALID_CONFIG");
|
|
4703
|
+
}
|
|
4704
|
+
return {
|
|
4705
|
+
signer: checksummed,
|
|
4706
|
+
deadline: Number(deadlineBig),
|
|
4707
|
+
nonce: nonceToBytes32(message.nonce),
|
|
4708
|
+
signature
|
|
4709
|
+
};
|
|
4710
|
+
}
|
|
4656
4711
|
function wagmiLifecycleSigner(walletClient, address) {
|
|
4657
4712
|
const account = address ?? walletClient.account?.address;
|
|
4658
4713
|
if (!account) {
|
|
@@ -4679,6 +4734,7 @@ function wagmiLifecycleSigner(walletClient, address) {
|
|
|
4679
4734
|
|
|
4680
4735
|
// src/backend/index.ts
|
|
4681
4736
|
init_utils();
|
|
4737
|
+
init_types();
|
|
4682
4738
|
init_chains();
|
|
4683
4739
|
|
|
4684
4740
|
// src/backend/facilitator-error.ts
|
|
@@ -5885,6 +5941,7 @@ exports.isSettlementUnconfirmed = isSettlementUnconfirmed;
|
|
|
5885
5941
|
exports.isSuiChain = isSuiChain;
|
|
5886
5942
|
exports.isTokenSupported = isTokenSupported;
|
|
5887
5943
|
exports.isXRPLChain = isXRPLChain;
|
|
5944
|
+
exports.lifecycleAuthFromSignature = lifecycleAuthFromSignature;
|
|
5888
5945
|
exports.matchesFilters = matchesFilters;
|
|
5889
5946
|
exports.needsAccountWrap = needsAccountWrap;
|
|
5890
5947
|
exports.parseEvidenceHeader = parseEvidenceHeader;
|