uvd-x402-sdk 2.77.0 → 2.79.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 +44 -0
- package/dist/backend/index.d.mts +133 -6
- package/dist/backend/index.d.ts +133 -6
- package/dist/backend/index.js +97 -4
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +93 -5
- package/dist/backend/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +97 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backend/index.ts +289 -8
- package/src/index.ts +7 -0
package/README.md
CHANGED
|
@@ -1351,6 +1351,50 @@ const body = buildVerifyRequestV2(
|
|
|
1351
1351
|
> error that names no field. If you see it, check the envelope shape first, not
|
|
1352
1352
|
> the fields inside it.
|
|
1353
1353
|
|
|
1354
|
+
### The top-level `x402Version` names the ENVELOPE
|
|
1355
|
+
|
|
1356
|
+
`VerifyRequest.x402Version` is typed `1`, not `1 | 2`: it says which of the two
|
|
1357
|
+
shapes above the body has, and `VerifyRequest` **is** the v1 shape. The payer's
|
|
1358
|
+
own version stays where the payer put it, in `paymentPayload.x402Version`, and
|
|
1359
|
+
the SDK never rewrites it.
|
|
1360
|
+
|
|
1361
|
+
```typescript
|
|
1362
|
+
// A buyer that declares v2 while carrying plain network names — legal, and what
|
|
1363
|
+
// a 402 advertising CAIP-2 invites.
|
|
1364
|
+
const body = buildVerifyRequest({ x402Version: 2, scheme: 'exact', network: 'base', payload }, reqs);
|
|
1365
|
+
|
|
1366
|
+
body.x402Version; // 1 — the envelope is v1
|
|
1367
|
+
body.paymentPayload.x402Version; // 2 — the payer's marker, untouched
|
|
1368
|
+
```
|
|
1369
|
+
|
|
1370
|
+
`resolveEnvelopeVersion` (and therefore the `'auto'` default) accepts a **v2
|
|
1371
|
+
payload** as well as a v1 header. A v2 payload has no top-level `network` at all
|
|
1372
|
+
— v2 moved the chain id into `accepted` — so `auto` reads it from there. Before
|
|
1373
|
+
**2.79.0** it read only the top level and threw
|
|
1374
|
+
`Cannot read properties of undefined` on exactly that shape, which is why
|
|
1375
|
+
integrators were pinning `x402Version` instead of using the default.
|
|
1376
|
+
|
|
1377
|
+
A network with **no CAIP-2 form** cannot travel in a v2 body at all, so pinning
|
|
1378
|
+
version 2 on one throws instead of building it — `xrpl-mainnet` is the case: its
|
|
1379
|
+
v1 string *is* its network id. `auto` leaves those on v1, where they work, so
|
|
1380
|
+
you only reach the throw by pinning. It names the network and the escape, which
|
|
1381
|
+
the facilitator's `400` (`data did not match any variant of untagged enum`) does
|
|
1382
|
+
not.
|
|
1383
|
+
|
|
1384
|
+
Until **2.79.0** the top level inherited `paymentHeader.x402Version`, so that
|
|
1385
|
+
call emitted a body declaring `2` around a `paymentRequirements` — a v1 shape.
|
|
1386
|
+
It was served correctly then and it is served correctly now: the facilitator's
|
|
1387
|
+
envelope enum is untagged and matches on shape. But the facilitator already
|
|
1388
|
+
reads that marker for one thing — choosing the hint in its `400`:
|
|
1389
|
+
|
|
1390
|
+
> `This body declares `x402Version: 2`. x402 v2 is a JSON object with
|
|
1391
|
+
> `paymentPayload`, `resource` and `accepted`…`
|
|
1392
|
+
|
|
1393
|
+
So the first time such a body failed for an unrelated reason, the diagnosis sent
|
|
1394
|
+
you to fix the wrong shape. If you were constructing a `VerifyRequest` by hand
|
|
1395
|
+
with a `1 | 2` variable, that no longer type-checks — write `1`, or use
|
|
1396
|
+
`buildVerifyRequestForVersion` and let it pick.
|
|
1397
|
+
|
|
1354
1398
|
## Metrics and history (`getStats` / `getTransactions`)
|
|
1355
1399
|
|
|
1356
1400
|
```typescript
|
package/dist/backend/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { S as SigningWalletAdapter } from '../wallet-0cX9Pw2F.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { Q as X402Version, x as X402Header, G as X402PayloadData } from '../index-ZH10otHE.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Reading a facilitator refusal as DATA instead of prose.
|
|
@@ -234,18 +234,30 @@ interface PaymentRequirements {
|
|
|
234
234
|
extra?: unknown;
|
|
235
235
|
}
|
|
236
236
|
/**
|
|
237
|
-
* Verify request body for the facilitator /verify endpoint
|
|
237
|
+
* Verify request body for the facilitator /verify endpoint -- the **v1**
|
|
238
|
+
* envelope. {@link VerifyRequestV2} is the other one.
|
|
238
239
|
*/
|
|
239
240
|
interface VerifyRequest {
|
|
240
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Always `1`: this marker names the ENVELOPE, and this envelope is v1.
|
|
243
|
+
*
|
|
244
|
+
* Narrowed from `X402Version` on 2026-09-04. A `VerifyRequest` carrying `2`
|
|
245
|
+
* was always an uninhabitable value -- a body declaring v2 while shaped as
|
|
246
|
+
* v1 -- and typing it as `1 | 2` is what let the payer's marker be copied in
|
|
247
|
+
* here. The payer's version lives in `paymentPayload.x402Version`, which is
|
|
248
|
+
* still the full union.
|
|
249
|
+
*/
|
|
250
|
+
x402Version: 1;
|
|
241
251
|
paymentPayload: X402Header;
|
|
242
252
|
paymentRequirements: PaymentRequirements;
|
|
243
253
|
}
|
|
244
254
|
/**
|
|
245
|
-
* Settle request body for the facilitator /settle endpoint
|
|
255
|
+
* Settle request body for the facilitator /settle endpoint -- the **v1**
|
|
256
|
+
* envelope. {@link SettleRequestV2} is the other one.
|
|
246
257
|
*/
|
|
247
258
|
interface SettleRequest {
|
|
248
|
-
x402Version
|
|
259
|
+
/** Always `1` -- see {@link VerifyRequest.x402Version}. */
|
|
260
|
+
x402Version: 1;
|
|
249
261
|
paymentPayload: X402Header;
|
|
250
262
|
paymentRequirements: PaymentRequirements;
|
|
251
263
|
}
|
|
@@ -527,6 +539,110 @@ declare function buildVerifyRequestV2(payload: X402PayloadData, resource: Resour
|
|
|
527
539
|
*/
|
|
528
540
|
declare function buildSettleRequestV2(payload: X402PayloadData, resource: ResourceInfoV2, accepted: PaymentRequirementsV2): SettleRequestV2;
|
|
529
541
|
declare function buildSettleRequest(paymentHeader: X402Header, requirements: PaymentRequirements): SettleRequest;
|
|
542
|
+
/**
|
|
543
|
+
* Derive the v2 `resource` object from v1-shaped requirements.
|
|
544
|
+
*
|
|
545
|
+
* v2 moved `resource` / `description` / `mimeType` out of the requirements and
|
|
546
|
+
* into an object of their own, and the facilitator requires ALL THREE keys:
|
|
547
|
+
* measured 2026-09-03, a `resource` carrying only `url` is a 400.
|
|
548
|
+
*
|
|
549
|
+
* The `??` defaults are not decoration. `PaymentRequirements` types these as
|
|
550
|
+
* required, but a JavaScript caller can still hand over an object without them,
|
|
551
|
+
* and a missing key does not fail with "description is missing" -- it fails with
|
|
552
|
+
* `data did not match any variant of untagged enum VerifyRequestEnvelope`, which
|
|
553
|
+
* names no field. That error is what cost two teams a day.
|
|
554
|
+
*/
|
|
555
|
+
declare function toResourceInfoV2(requirements: PaymentRequirements): ResourceInfoV2;
|
|
556
|
+
/**
|
|
557
|
+
* Derive v2 `accepted` requirements from v1-shaped requirements.
|
|
558
|
+
*
|
|
559
|
+
* Two renames do the damage, and neither is reported by name when it is wrong:
|
|
560
|
+
* - `maxAmountRequired` is spelled `amount` in v2.
|
|
561
|
+
* - `network` must be CAIP-2; a plain name inside a v2 body is a 400.
|
|
562
|
+
*
|
|
563
|
+
* `extra` is carried through when present -- it is where the EIP-712 domain
|
|
564
|
+
* `name`/`version` live for tokens the facilitator does not know by address, so
|
|
565
|
+
* dropping it breaks EURC and the bridged USDCs.
|
|
566
|
+
*
|
|
567
|
+
* @throws If `requirements.network` has NO CAIP-2 form. `chainToCAIP2` answers
|
|
568
|
+
* with the name unchanged when it does not know a chain, and XRPL maps to
|
|
569
|
+
* itself on purpose -- its v1 string IS its network id. Passing that through
|
|
570
|
+
* would put a plain name inside a v2 body, which is a measured 400 (the same
|
|
571
|
+
* `no variant matched` that names no field). Only reachable by PINNING version
|
|
572
|
+
* 2 on such a network; `auto` leaves them on v1, where they work. Failing here
|
|
573
|
+
* names the network and the fix, which a 400 from the facilitator does not.
|
|
574
|
+
*/
|
|
575
|
+
declare function toPaymentRequirementsV2(requirements: PaymentRequirements): PaymentRequirementsV2;
|
|
576
|
+
/**
|
|
577
|
+
* Decide which envelope this (payment, requirements) pair has to travel in.
|
|
578
|
+
*
|
|
579
|
+
* `requested` wins when it names a version; `'auto'` (the default) reads the
|
|
580
|
+
* wire.
|
|
581
|
+
*
|
|
582
|
+
* **Auto keys off CAIP-2, NOT off `paymentHeader.x402Version`,** and that is a
|
|
583
|
+
* measured decision rather than a stylistic one. The facilitator's envelope enum
|
|
584
|
+
* is untagged: it matches on SHAPE and ignores the version marker.
|
|
585
|
+
*
|
|
586
|
+
* Re-measured against `https://facilitator.ultravioletadao.xyz/verify` on
|
|
587
|
+
* **2026-09-04** with a fabricated signature. The signature never verifies, so
|
|
588
|
+
* every row is an HTTP 400 and the STATUS discriminates nothing -- what does is
|
|
589
|
+
* the error code. `invalid_request_body` means the facilitator could not
|
|
590
|
+
* deserialize the body; `contract_call_failed` means it read the body, resolved
|
|
591
|
+
* the chain and got as far as the on-chain call, i.e. the envelope was fine.
|
|
592
|
+
*
|
|
593
|
+
* | payload network | requirements network | v1 envelope today |
|
|
594
|
+
* |-----------------|----------------------|-------------------|
|
|
595
|
+
* | `base` | `base` | understood |
|
|
596
|
+
* | `base` (header says `x402Version: 2`) | `base` | understood |
|
|
597
|
+
* | `eip155:8453` | `base` | understood |
|
|
598
|
+
* | `base` | `eip155:8453` | understood |
|
|
599
|
+
* | `eip155:8453` | `eip155:8453` | understood |
|
|
600
|
+
*
|
|
601
|
+
* **The last three rows used to be a hard 400** (`unknown variant
|
|
602
|
+
* \`eip155:8453\``) when this function was written on 2026-09-03. The
|
|
603
|
+
* facilitator has since taught the v1 envelope to read CAIP-2, so the original
|
|
604
|
+
* argument for this rule -- "every CAIP-2 combination is already a 400, so
|
|
605
|
+
* upgrading them cannot regress anyone" -- **is no longer true**. The rule is
|
|
606
|
+
* unchanged; three other reasons hold it up:
|
|
607
|
+
*
|
|
608
|
+
* 1. A CAIP-2 network on the wire means the 402 that produced it advertised v2.
|
|
609
|
+
* Answering in v2 is speaking the protocol the seller announced.
|
|
610
|
+
* 2. v2-with-CAIP-2 is the only shape BOTH generations of the facilitator
|
|
611
|
+
* accept. v1-with-CAIP-2 is a hard 400 on any build older than 2026-09-04,
|
|
612
|
+
* so choosing v1 there is what breaks against a self-hosted or pinned one.
|
|
613
|
+
* 3. The Python SDK resolves the identical rule, so the same wire produces the
|
|
614
|
+
* same body in both SDKs -- pinned by phase 6 of `npm run test:xlang`.
|
|
615
|
+
*
|
|
616
|
+
* And the marker still decides nothing: row 2 above is served correctly today,
|
|
617
|
+
* so upgrading on the strength of it would change a call that works.
|
|
618
|
+
*
|
|
619
|
+
* The negative half of that measurement, without which "understood" proves
|
|
620
|
+
* nothing -- the same run, bodies broken on purpose, all three
|
|
621
|
+
* `invalid_request_body`: a v2 body carrying a plain network name, one with
|
|
622
|
+
* `resource` as a bare string, and one with `accepted` removed. A well-formed
|
|
623
|
+
* v2 body with CAIP-2 reached `contract_call_failed` like the rows above.
|
|
624
|
+
*/
|
|
625
|
+
declare function resolveEnvelopeVersion(paymentHeader: X402Header | PaymentPayloadV2, requirements: PaymentRequirements, requested?: X402Version | 'auto'): X402Version;
|
|
626
|
+
/**
|
|
627
|
+
* Build a `/verify` body in whichever envelope `version` names.
|
|
628
|
+
*
|
|
629
|
+
* The v1 return is byte-for-byte what {@link buildVerifyRequest} produces, so
|
|
630
|
+
* pinning `1` is exactly today's behaviour.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```ts
|
|
634
|
+
* const version = resolveEnvelopeVersion(payment, requirements);
|
|
635
|
+
* const body = buildVerifyRequestForVersion(payment, requirements, version);
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
declare function buildVerifyRequestForVersion(paymentHeader: X402Header, requirements: PaymentRequirements, version: X402Version): VerifyRequest | VerifyRequestV2;
|
|
639
|
+
/**
|
|
640
|
+
* Build a `/settle` body in whichever envelope `version` names.
|
|
641
|
+
*
|
|
642
|
+
* See {@link buildVerifyRequestForVersion} -- `/settle` takes the same body as
|
|
643
|
+
* `/verify` in both versions.
|
|
644
|
+
*/
|
|
645
|
+
declare function buildSettleRequestForVersion(paymentHeader: X402Header, requirements: PaymentRequirements, version: X402Version): SettleRequest | SettleRequestV2;
|
|
530
646
|
/**
|
|
531
647
|
* Recommended CORS headers for x402 payment APIs
|
|
532
648
|
*
|
|
@@ -585,6 +701,16 @@ interface FacilitatorClientOptions {
|
|
|
585
701
|
* -- is never replayed here, at any setting.
|
|
586
702
|
*/
|
|
587
703
|
retries?: number;
|
|
704
|
+
/**
|
|
705
|
+
* Which envelope to send to `/verify` and `/settle`. Default `'auto'`.
|
|
706
|
+
*
|
|
707
|
+
* `'auto'` reads the wire: CAIP-2 networks get the v2 envelope, plain names
|
|
708
|
+
* get v1. See {@link resolveEnvelopeVersion} for the measurements behind that
|
|
709
|
+
* rule. Pin `1` or `2` to take the decision yourself -- a pin is honoured
|
|
710
|
+
* even when it contradicts the wire, because choosing the version is the
|
|
711
|
+
* point of the option.
|
|
712
|
+
*/
|
|
713
|
+
x402Version?: X402Version | 'auto';
|
|
588
714
|
}
|
|
589
715
|
/**
|
|
590
716
|
* Client for interacting with the x402 facilitator API
|
|
@@ -611,6 +737,7 @@ declare class FacilitatorClient {
|
|
|
611
737
|
private readonly timeout;
|
|
612
738
|
private readonly explicitTimeout;
|
|
613
739
|
private readonly retries;
|
|
740
|
+
private readonly x402Version;
|
|
614
741
|
constructor(options?: FacilitatorClientOptions);
|
|
615
742
|
/**
|
|
616
743
|
* Get timeout for a specific network, using per-chain defaults when no explicit timeout was set.
|
|
@@ -3134,4 +3261,4 @@ declare class AdvancedEscrowClient {
|
|
|
3134
3261
|
private sendViaAdapter;
|
|
3135
3262
|
}
|
|
3136
3263
|
|
|
3137
|
-
export { AMBIGUOUS_LEASE_REASONS, type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FacilitatorErrorInfo, type FacilitatorFailureFields, type FacilitatorFetchOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type PrepareRelayFeedbackRequest, type PrepareRelayFeedbackResponse, type PrepareRelayResponseRequest, type ProofOfPayment, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, RegistrationPendingError, type RelayAuthorizationParams, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, type SubmitRelayFeedbackRequest, type SubmitRelayResponseRequest, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, WRITER_LEASE_REASONS, type WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, carryFailureFields, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isAmbiguousLeaseReason, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, supportsRelayedFeedback, wireNetwork };
|
|
3264
|
+
export { AMBIGUOUS_LEASE_REASONS, type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FacilitatorErrorInfo, type FacilitatorFailureFields, type FacilitatorFetchOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type PrepareRelayFeedbackRequest, type PrepareRelayFeedbackResponse, type PrepareRelayResponseRequest, type ProofOfPayment, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, RegistrationPendingError, type RelayAuthorizationParams, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, type SubmitRelayFeedbackRequest, type SubmitRelayResponseRequest, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, WRITER_LEASE_REASONS, type WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, carryFailureFields, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isAmbiguousLeaseReason, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, supportsRelayedFeedback, toPaymentRequirementsV2, toResourceInfoV2, wireNetwork };
|
package/dist/backend/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { S as SigningWalletAdapter } from '../wallet-0cX9Pw2F.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Q as X402Version, x as X402Header, G as X402PayloadData } from '../index-ZH10otHE.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Reading a facilitator refusal as DATA instead of prose.
|
|
@@ -234,18 +234,30 @@ interface PaymentRequirements {
|
|
|
234
234
|
extra?: unknown;
|
|
235
235
|
}
|
|
236
236
|
/**
|
|
237
|
-
* Verify request body for the facilitator /verify endpoint
|
|
237
|
+
* Verify request body for the facilitator /verify endpoint -- the **v1**
|
|
238
|
+
* envelope. {@link VerifyRequestV2} is the other one.
|
|
238
239
|
*/
|
|
239
240
|
interface VerifyRequest {
|
|
240
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Always `1`: this marker names the ENVELOPE, and this envelope is v1.
|
|
243
|
+
*
|
|
244
|
+
* Narrowed from `X402Version` on 2026-09-04. A `VerifyRequest` carrying `2`
|
|
245
|
+
* was always an uninhabitable value -- a body declaring v2 while shaped as
|
|
246
|
+
* v1 -- and typing it as `1 | 2` is what let the payer's marker be copied in
|
|
247
|
+
* here. The payer's version lives in `paymentPayload.x402Version`, which is
|
|
248
|
+
* still the full union.
|
|
249
|
+
*/
|
|
250
|
+
x402Version: 1;
|
|
241
251
|
paymentPayload: X402Header;
|
|
242
252
|
paymentRequirements: PaymentRequirements;
|
|
243
253
|
}
|
|
244
254
|
/**
|
|
245
|
-
* Settle request body for the facilitator /settle endpoint
|
|
255
|
+
* Settle request body for the facilitator /settle endpoint -- the **v1**
|
|
256
|
+
* envelope. {@link SettleRequestV2} is the other one.
|
|
246
257
|
*/
|
|
247
258
|
interface SettleRequest {
|
|
248
|
-
x402Version
|
|
259
|
+
/** Always `1` -- see {@link VerifyRequest.x402Version}. */
|
|
260
|
+
x402Version: 1;
|
|
249
261
|
paymentPayload: X402Header;
|
|
250
262
|
paymentRequirements: PaymentRequirements;
|
|
251
263
|
}
|
|
@@ -527,6 +539,110 @@ declare function buildVerifyRequestV2(payload: X402PayloadData, resource: Resour
|
|
|
527
539
|
*/
|
|
528
540
|
declare function buildSettleRequestV2(payload: X402PayloadData, resource: ResourceInfoV2, accepted: PaymentRequirementsV2): SettleRequestV2;
|
|
529
541
|
declare function buildSettleRequest(paymentHeader: X402Header, requirements: PaymentRequirements): SettleRequest;
|
|
542
|
+
/**
|
|
543
|
+
* Derive the v2 `resource` object from v1-shaped requirements.
|
|
544
|
+
*
|
|
545
|
+
* v2 moved `resource` / `description` / `mimeType` out of the requirements and
|
|
546
|
+
* into an object of their own, and the facilitator requires ALL THREE keys:
|
|
547
|
+
* measured 2026-09-03, a `resource` carrying only `url` is a 400.
|
|
548
|
+
*
|
|
549
|
+
* The `??` defaults are not decoration. `PaymentRequirements` types these as
|
|
550
|
+
* required, but a JavaScript caller can still hand over an object without them,
|
|
551
|
+
* and a missing key does not fail with "description is missing" -- it fails with
|
|
552
|
+
* `data did not match any variant of untagged enum VerifyRequestEnvelope`, which
|
|
553
|
+
* names no field. That error is what cost two teams a day.
|
|
554
|
+
*/
|
|
555
|
+
declare function toResourceInfoV2(requirements: PaymentRequirements): ResourceInfoV2;
|
|
556
|
+
/**
|
|
557
|
+
* Derive v2 `accepted` requirements from v1-shaped requirements.
|
|
558
|
+
*
|
|
559
|
+
* Two renames do the damage, and neither is reported by name when it is wrong:
|
|
560
|
+
* - `maxAmountRequired` is spelled `amount` in v2.
|
|
561
|
+
* - `network` must be CAIP-2; a plain name inside a v2 body is a 400.
|
|
562
|
+
*
|
|
563
|
+
* `extra` is carried through when present -- it is where the EIP-712 domain
|
|
564
|
+
* `name`/`version` live for tokens the facilitator does not know by address, so
|
|
565
|
+
* dropping it breaks EURC and the bridged USDCs.
|
|
566
|
+
*
|
|
567
|
+
* @throws If `requirements.network` has NO CAIP-2 form. `chainToCAIP2` answers
|
|
568
|
+
* with the name unchanged when it does not know a chain, and XRPL maps to
|
|
569
|
+
* itself on purpose -- its v1 string IS its network id. Passing that through
|
|
570
|
+
* would put a plain name inside a v2 body, which is a measured 400 (the same
|
|
571
|
+
* `no variant matched` that names no field). Only reachable by PINNING version
|
|
572
|
+
* 2 on such a network; `auto` leaves them on v1, where they work. Failing here
|
|
573
|
+
* names the network and the fix, which a 400 from the facilitator does not.
|
|
574
|
+
*/
|
|
575
|
+
declare function toPaymentRequirementsV2(requirements: PaymentRequirements): PaymentRequirementsV2;
|
|
576
|
+
/**
|
|
577
|
+
* Decide which envelope this (payment, requirements) pair has to travel in.
|
|
578
|
+
*
|
|
579
|
+
* `requested` wins when it names a version; `'auto'` (the default) reads the
|
|
580
|
+
* wire.
|
|
581
|
+
*
|
|
582
|
+
* **Auto keys off CAIP-2, NOT off `paymentHeader.x402Version`,** and that is a
|
|
583
|
+
* measured decision rather than a stylistic one. The facilitator's envelope enum
|
|
584
|
+
* is untagged: it matches on SHAPE and ignores the version marker.
|
|
585
|
+
*
|
|
586
|
+
* Re-measured against `https://facilitator.ultravioletadao.xyz/verify` on
|
|
587
|
+
* **2026-09-04** with a fabricated signature. The signature never verifies, so
|
|
588
|
+
* every row is an HTTP 400 and the STATUS discriminates nothing -- what does is
|
|
589
|
+
* the error code. `invalid_request_body` means the facilitator could not
|
|
590
|
+
* deserialize the body; `contract_call_failed` means it read the body, resolved
|
|
591
|
+
* the chain and got as far as the on-chain call, i.e. the envelope was fine.
|
|
592
|
+
*
|
|
593
|
+
* | payload network | requirements network | v1 envelope today |
|
|
594
|
+
* |-----------------|----------------------|-------------------|
|
|
595
|
+
* | `base` | `base` | understood |
|
|
596
|
+
* | `base` (header says `x402Version: 2`) | `base` | understood |
|
|
597
|
+
* | `eip155:8453` | `base` | understood |
|
|
598
|
+
* | `base` | `eip155:8453` | understood |
|
|
599
|
+
* | `eip155:8453` | `eip155:8453` | understood |
|
|
600
|
+
*
|
|
601
|
+
* **The last three rows used to be a hard 400** (`unknown variant
|
|
602
|
+
* \`eip155:8453\``) when this function was written on 2026-09-03. The
|
|
603
|
+
* facilitator has since taught the v1 envelope to read CAIP-2, so the original
|
|
604
|
+
* argument for this rule -- "every CAIP-2 combination is already a 400, so
|
|
605
|
+
* upgrading them cannot regress anyone" -- **is no longer true**. The rule is
|
|
606
|
+
* unchanged; three other reasons hold it up:
|
|
607
|
+
*
|
|
608
|
+
* 1. A CAIP-2 network on the wire means the 402 that produced it advertised v2.
|
|
609
|
+
* Answering in v2 is speaking the protocol the seller announced.
|
|
610
|
+
* 2. v2-with-CAIP-2 is the only shape BOTH generations of the facilitator
|
|
611
|
+
* accept. v1-with-CAIP-2 is a hard 400 on any build older than 2026-09-04,
|
|
612
|
+
* so choosing v1 there is what breaks against a self-hosted or pinned one.
|
|
613
|
+
* 3. The Python SDK resolves the identical rule, so the same wire produces the
|
|
614
|
+
* same body in both SDKs -- pinned by phase 6 of `npm run test:xlang`.
|
|
615
|
+
*
|
|
616
|
+
* And the marker still decides nothing: row 2 above is served correctly today,
|
|
617
|
+
* so upgrading on the strength of it would change a call that works.
|
|
618
|
+
*
|
|
619
|
+
* The negative half of that measurement, without which "understood" proves
|
|
620
|
+
* nothing -- the same run, bodies broken on purpose, all three
|
|
621
|
+
* `invalid_request_body`: a v2 body carrying a plain network name, one with
|
|
622
|
+
* `resource` as a bare string, and one with `accepted` removed. A well-formed
|
|
623
|
+
* v2 body with CAIP-2 reached `contract_call_failed` like the rows above.
|
|
624
|
+
*/
|
|
625
|
+
declare function resolveEnvelopeVersion(paymentHeader: X402Header | PaymentPayloadV2, requirements: PaymentRequirements, requested?: X402Version | 'auto'): X402Version;
|
|
626
|
+
/**
|
|
627
|
+
* Build a `/verify` body in whichever envelope `version` names.
|
|
628
|
+
*
|
|
629
|
+
* The v1 return is byte-for-byte what {@link buildVerifyRequest} produces, so
|
|
630
|
+
* pinning `1` is exactly today's behaviour.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```ts
|
|
634
|
+
* const version = resolveEnvelopeVersion(payment, requirements);
|
|
635
|
+
* const body = buildVerifyRequestForVersion(payment, requirements, version);
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
declare function buildVerifyRequestForVersion(paymentHeader: X402Header, requirements: PaymentRequirements, version: X402Version): VerifyRequest | VerifyRequestV2;
|
|
639
|
+
/**
|
|
640
|
+
* Build a `/settle` body in whichever envelope `version` names.
|
|
641
|
+
*
|
|
642
|
+
* See {@link buildVerifyRequestForVersion} -- `/settle` takes the same body as
|
|
643
|
+
* `/verify` in both versions.
|
|
644
|
+
*/
|
|
645
|
+
declare function buildSettleRequestForVersion(paymentHeader: X402Header, requirements: PaymentRequirements, version: X402Version): SettleRequest | SettleRequestV2;
|
|
530
646
|
/**
|
|
531
647
|
* Recommended CORS headers for x402 payment APIs
|
|
532
648
|
*
|
|
@@ -585,6 +701,16 @@ interface FacilitatorClientOptions {
|
|
|
585
701
|
* -- is never replayed here, at any setting.
|
|
586
702
|
*/
|
|
587
703
|
retries?: number;
|
|
704
|
+
/**
|
|
705
|
+
* Which envelope to send to `/verify` and `/settle`. Default `'auto'`.
|
|
706
|
+
*
|
|
707
|
+
* `'auto'` reads the wire: CAIP-2 networks get the v2 envelope, plain names
|
|
708
|
+
* get v1. See {@link resolveEnvelopeVersion} for the measurements behind that
|
|
709
|
+
* rule. Pin `1` or `2` to take the decision yourself -- a pin is honoured
|
|
710
|
+
* even when it contradicts the wire, because choosing the version is the
|
|
711
|
+
* point of the option.
|
|
712
|
+
*/
|
|
713
|
+
x402Version?: X402Version | 'auto';
|
|
588
714
|
}
|
|
589
715
|
/**
|
|
590
716
|
* Client for interacting with the x402 facilitator API
|
|
@@ -611,6 +737,7 @@ declare class FacilitatorClient {
|
|
|
611
737
|
private readonly timeout;
|
|
612
738
|
private readonly explicitTimeout;
|
|
613
739
|
private readonly retries;
|
|
740
|
+
private readonly x402Version;
|
|
614
741
|
constructor(options?: FacilitatorClientOptions);
|
|
615
742
|
/**
|
|
616
743
|
* Get timeout for a specific network, using per-chain defaults when no explicit timeout was set.
|
|
@@ -3134,4 +3261,4 @@ declare class AdvancedEscrowClient {
|
|
|
3134
3261
|
private sendViaAdapter;
|
|
3135
3262
|
}
|
|
3136
3263
|
|
|
3137
|
-
export { AMBIGUOUS_LEASE_REASONS, type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FacilitatorErrorInfo, type FacilitatorFailureFields, type FacilitatorFetchOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type PrepareRelayFeedbackRequest, type PrepareRelayFeedbackResponse, type PrepareRelayResponseRequest, type ProofOfPayment, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, RegistrationPendingError, type RelayAuthorizationParams, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, type SubmitRelayFeedbackRequest, type SubmitRelayResponseRequest, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, WRITER_LEASE_REASONS, type WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, carryFailureFields, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isAmbiguousLeaseReason, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, supportsRelayedFeedback, wireNetwork };
|
|
3264
|
+
export { AMBIGUOUS_LEASE_REASONS, type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FacilitatorErrorInfo, type FacilitatorFailureFields, type FacilitatorFetchOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type PrepareRelayFeedbackRequest, type PrepareRelayFeedbackResponse, type PrepareRelayResponseRequest, type ProofOfPayment, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, RegistrationPendingError, type RelayAuthorizationParams, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, type SubmitRelayFeedbackRequest, type SubmitRelayResponseRequest, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, WRITER_LEASE_REASONS, type WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, carryFailureFields, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isAmbiguousLeaseReason, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, supportsRelayedFeedback, toPaymentRequirementsV2, toResourceInfoV2, wireNetwork };
|
package/dist/backend/index.js
CHANGED
|
@@ -1261,7 +1261,23 @@ function buildPaymentRequirements(options) {
|
|
|
1261
1261
|
}
|
|
1262
1262
|
function buildVerifyRequest(paymentHeader, requirements) {
|
|
1263
1263
|
return {
|
|
1264
|
-
|
|
1264
|
+
// The literal `1` names THIS ENVELOPE, not the payer's header. Echoing
|
|
1265
|
+
// `paymentHeader.x402Version` here -- what this did until 2026-09-04 --
|
|
1266
|
+
// let a buyer who declared `2` produce a body that says "2" while carrying
|
|
1267
|
+
// `paymentRequirements`, which is the v1 shape. The facilitator serves it
|
|
1268
|
+
// anyway because its envelope enum is untagged and matches on shape, so
|
|
1269
|
+
// nothing broke; but it ALREADY picks the hint in its 400 off this marker:
|
|
1270
|
+
//
|
|
1271
|
+
// "This body declares `x402Version: 2`. x402 v2 is a JSON object with
|
|
1272
|
+
// `paymentPayload`, `resource` and `accepted`..."
|
|
1273
|
+
//
|
|
1274
|
+
// So the day that body fails for any other reason, the diagnosis sends the
|
|
1275
|
+
// integrator to document the wrong shape. That inversion -- being told to
|
|
1276
|
+
// fix the fields when the wrapper is what is wrong -- is what cost two
|
|
1277
|
+
// teams a day. The payer's own marker survives untouched inside
|
|
1278
|
+
// `paymentPayload`, where it belongs: it describes the payment, not the
|
|
1279
|
+
// envelope carrying it.
|
|
1280
|
+
x402Version: 1,
|
|
1265
1281
|
paymentPayload: paymentHeader,
|
|
1266
1282
|
paymentRequirements: requirements
|
|
1267
1283
|
};
|
|
@@ -1284,11 +1300,73 @@ function buildSettleRequestV2(payload, resource, accepted) {
|
|
|
1284
1300
|
}
|
|
1285
1301
|
function buildSettleRequest(paymentHeader, requirements) {
|
|
1286
1302
|
return {
|
|
1287
|
-
|
|
1303
|
+
// `1` for the same reason as {@link buildVerifyRequest}: it names the
|
|
1304
|
+
// envelope, and `/settle` takes the same body as `/verify`.
|
|
1305
|
+
x402Version: 1,
|
|
1288
1306
|
paymentPayload: paymentHeader,
|
|
1289
1307
|
paymentRequirements: requirements
|
|
1290
1308
|
};
|
|
1291
1309
|
}
|
|
1310
|
+
function isCaip2Network(network) {
|
|
1311
|
+
return typeof network === "string" && network.includes(":");
|
|
1312
|
+
}
|
|
1313
|
+
function networkOfPayload(payload) {
|
|
1314
|
+
const top = payload.network;
|
|
1315
|
+
if (typeof top === "string") return top;
|
|
1316
|
+
const accepted = payload.accepted;
|
|
1317
|
+
return typeof accepted?.network === "string" ? accepted.network : void 0;
|
|
1318
|
+
}
|
|
1319
|
+
function toResourceInfoV2(requirements) {
|
|
1320
|
+
return {
|
|
1321
|
+
url: requirements.resource,
|
|
1322
|
+
description: requirements.description ?? DEFAULT_PAYMENT_DESCRIPTION,
|
|
1323
|
+
mimeType: requirements.mimeType ?? DEFAULT_PAYMENT_MIME_TYPE
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
function toPaymentRequirementsV2(requirements) {
|
|
1327
|
+
const network = isCaip2Network(requirements.network) ? requirements.network : chainToCAIP2(requirements.network);
|
|
1328
|
+
if (!isCaip2Network(network)) {
|
|
1329
|
+
throw new Error(
|
|
1330
|
+
`Network '${requirements.network}' has no CAIP-2 form, so it cannot travel in the x402 v2 envelope. Use x402Version: 1 for this network.`
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1333
|
+
return {
|
|
1334
|
+
scheme: requirements.scheme,
|
|
1335
|
+
network,
|
|
1336
|
+
asset: requirements.asset,
|
|
1337
|
+
amount: requirements.maxAmountRequired,
|
|
1338
|
+
payTo: requirements.payTo,
|
|
1339
|
+
// Required by the facilitator: omitting it is a 400, measured the same day.
|
|
1340
|
+
maxTimeoutSeconds: requirements.maxTimeoutSeconds ?? DEFAULT_PAYMENT_TIMEOUT_SECONDS,
|
|
1341
|
+
...requirements.extra !== void 0 ? { extra: requirements.extra } : {}
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
function resolveEnvelopeVersion(paymentHeader, requirements, requested = "auto") {
|
|
1345
|
+
if (requested !== "auto") {
|
|
1346
|
+
return requested;
|
|
1347
|
+
}
|
|
1348
|
+
return isCaip2Network(networkOfPayload(paymentHeader)) || isCaip2Network(requirements.network) ? 2 : 1;
|
|
1349
|
+
}
|
|
1350
|
+
function buildVerifyRequestForVersion(paymentHeader, requirements, version) {
|
|
1351
|
+
if (version === 2) {
|
|
1352
|
+
return buildVerifyRequestV2(
|
|
1353
|
+
paymentHeader.payload,
|
|
1354
|
+
toResourceInfoV2(requirements),
|
|
1355
|
+
toPaymentRequirementsV2(requirements)
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
return buildVerifyRequest(paymentHeader, requirements);
|
|
1359
|
+
}
|
|
1360
|
+
function buildSettleRequestForVersion(paymentHeader, requirements, version) {
|
|
1361
|
+
if (version === 2) {
|
|
1362
|
+
return buildSettleRequestV2(
|
|
1363
|
+
paymentHeader.payload,
|
|
1364
|
+
toResourceInfoV2(requirements),
|
|
1365
|
+
toPaymentRequirementsV2(requirements)
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1368
|
+
return buildSettleRequest(paymentHeader, requirements);
|
|
1369
|
+
}
|
|
1292
1370
|
var X402_CORS_HEADERS = {
|
|
1293
1371
|
"Access-Control-Allow-Headers": "Content-Type, X-PAYMENT, PAYMENT-SIGNATURE, Authorization",
|
|
1294
1372
|
"Access-Control-Expose-Headers": "X-PAYMENT-RESPONSE, PAYMENT-RESPONSE, PAYMENT-REQUIRED",
|
|
@@ -1312,11 +1390,13 @@ var FacilitatorClient = class {
|
|
|
1312
1390
|
timeout;
|
|
1313
1391
|
explicitTimeout;
|
|
1314
1392
|
retries;
|
|
1393
|
+
x402Version;
|
|
1315
1394
|
constructor(options = {}) {
|
|
1316
1395
|
this.baseUrl = options.baseUrl || "https://facilitator.ultravioletadao.xyz";
|
|
1317
1396
|
this.explicitTimeout = options.timeout !== void 0;
|
|
1318
1397
|
this.timeout = options.timeout || 3e4;
|
|
1319
1398
|
this.retries = options.retries;
|
|
1399
|
+
this.x402Version = options.x402Version ?? "auto";
|
|
1320
1400
|
}
|
|
1321
1401
|
/**
|
|
1322
1402
|
* Get timeout for a specific network, using per-chain defaults when no explicit timeout was set.
|
|
@@ -1342,7 +1422,11 @@ var FacilitatorClient = class {
|
|
|
1342
1422
|
* @returns Verification result
|
|
1343
1423
|
*/
|
|
1344
1424
|
async verify(paymentHeader, requirements) {
|
|
1345
|
-
const body =
|
|
1425
|
+
const body = buildVerifyRequestForVersion(
|
|
1426
|
+
paymentHeader,
|
|
1427
|
+
requirements,
|
|
1428
|
+
resolveEnvelopeVersion(paymentHeader, requirements, this.x402Version)
|
|
1429
|
+
);
|
|
1346
1430
|
try {
|
|
1347
1431
|
const { response, error } = await facilitatorFetch(
|
|
1348
1432
|
`${this.baseUrl}/verify`,
|
|
@@ -1381,7 +1465,11 @@ var FacilitatorClient = class {
|
|
|
1381
1465
|
* @returns Settlement result with transaction hash
|
|
1382
1466
|
*/
|
|
1383
1467
|
async settle(paymentHeader, requirements) {
|
|
1384
|
-
const body =
|
|
1468
|
+
const body = buildSettleRequestForVersion(
|
|
1469
|
+
paymentHeader,
|
|
1470
|
+
requirements,
|
|
1471
|
+
resolveEnvelopeVersion(paymentHeader, requirements, this.x402Version)
|
|
1472
|
+
);
|
|
1385
1473
|
const settleTimeout = this.getTimeout(requirements.network);
|
|
1386
1474
|
try {
|
|
1387
1475
|
const { response, error } = await facilitatorFetch(
|
|
@@ -4719,8 +4807,10 @@ exports.ZERO_ADDRESS = ZERO_ADDRESS;
|
|
|
4719
4807
|
exports.buildErc8004PaymentRequirements = buildErc8004PaymentRequirements;
|
|
4720
4808
|
exports.buildPaymentRequirements = buildPaymentRequirements;
|
|
4721
4809
|
exports.buildSettleRequest = buildSettleRequest;
|
|
4810
|
+
exports.buildSettleRequestForVersion = buildSettleRequestForVersion;
|
|
4722
4811
|
exports.buildSettleRequestV2 = buildSettleRequestV2;
|
|
4723
4812
|
exports.buildVerifyRequest = buildVerifyRequest;
|
|
4813
|
+
exports.buildVerifyRequestForVersion = buildVerifyRequestForVersion;
|
|
4724
4814
|
exports.buildVerifyRequestV2 = buildVerifyRequestV2;
|
|
4725
4815
|
exports.canRefundEscrow = canRefundEscrow;
|
|
4726
4816
|
exports.canReleaseEscrow = canReleaseEscrow;
|
|
@@ -4744,7 +4834,10 @@ exports.isReplayableLeaseReason = isReplayableLeaseReason;
|
|
|
4744
4834
|
exports.parsePaymentHeader = parsePaymentHeader;
|
|
4745
4835
|
exports.parseRetryAfterSeconds = parseRetryAfterSeconds;
|
|
4746
4836
|
exports.readFacilitatorError = readFacilitatorError;
|
|
4837
|
+
exports.resolveEnvelopeVersion = resolveEnvelopeVersion;
|
|
4747
4838
|
exports.supportsRelayedFeedback = supportsRelayedFeedback;
|
|
4839
|
+
exports.toPaymentRequirementsV2 = toPaymentRequirementsV2;
|
|
4840
|
+
exports.toResourceInfoV2 = toResourceInfoV2;
|
|
4748
4841
|
exports.wireNetwork = wireNetwork;
|
|
4749
4842
|
//# sourceMappingURL=index.js.map
|
|
4750
4843
|
//# sourceMappingURL=index.js.map
|