uvd-x402-sdk 2.76.0 → 2.78.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 +85 -2
- package/dist/backend/index.d.ts +85 -2
- package/dist/backend/index.js +65 -2
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +61 -3
- package/dist/backend/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +71 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backend/index.ts +187 -2
- package/src/dx402.ts +7 -2
- package/src/index.ts +7 -0
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.
|
|
@@ -527,6 +527,78 @@ declare function buildVerifyRequestV2(payload: X402PayloadData, resource: Resour
|
|
|
527
527
|
*/
|
|
528
528
|
declare function buildSettleRequestV2(payload: X402PayloadData, resource: ResourceInfoV2, accepted: PaymentRequirementsV2): SettleRequestV2;
|
|
529
529
|
declare function buildSettleRequest(paymentHeader: X402Header, requirements: PaymentRequirements): SettleRequest;
|
|
530
|
+
/**
|
|
531
|
+
* Derive the v2 `resource` object from v1-shaped requirements.
|
|
532
|
+
*
|
|
533
|
+
* v2 moved `resource` / `description` / `mimeType` out of the requirements and
|
|
534
|
+
* into an object of their own, and the facilitator requires ALL THREE keys:
|
|
535
|
+
* measured 2026-09-03, a `resource` carrying only `url` is a 400.
|
|
536
|
+
*
|
|
537
|
+
* The `??` defaults are not decoration. `PaymentRequirements` types these as
|
|
538
|
+
* required, but a JavaScript caller can still hand over an object without them,
|
|
539
|
+
* and a missing key does not fail with "description is missing" -- it fails with
|
|
540
|
+
* `data did not match any variant of untagged enum VerifyRequestEnvelope`, which
|
|
541
|
+
* names no field. That error is what cost two teams a day.
|
|
542
|
+
*/
|
|
543
|
+
declare function toResourceInfoV2(requirements: PaymentRequirements): ResourceInfoV2;
|
|
544
|
+
/**
|
|
545
|
+
* Derive v2 `accepted` requirements from v1-shaped requirements.
|
|
546
|
+
*
|
|
547
|
+
* Two renames do the damage, and neither is reported by name when it is wrong:
|
|
548
|
+
* - `maxAmountRequired` is spelled `amount` in v2.
|
|
549
|
+
* - `network` must be CAIP-2; a plain name inside a v2 body is a 400.
|
|
550
|
+
*
|
|
551
|
+
* `extra` is carried through when present -- it is where the EIP-712 domain
|
|
552
|
+
* `name`/`version` live for tokens the facilitator does not know by address, so
|
|
553
|
+
* dropping it breaks EURC and the bridged USDCs.
|
|
554
|
+
*/
|
|
555
|
+
declare function toPaymentRequirementsV2(requirements: PaymentRequirements): PaymentRequirementsV2;
|
|
556
|
+
/**
|
|
557
|
+
* Decide which envelope this (payment, requirements) pair has to travel in.
|
|
558
|
+
*
|
|
559
|
+
* `requested` wins when it names a version; `'auto'` (the default) reads the
|
|
560
|
+
* wire.
|
|
561
|
+
*
|
|
562
|
+
* **Auto keys off CAIP-2, NOT off `paymentHeader.x402Version`,** and that is a
|
|
563
|
+
* measured decision rather than a stylistic one. The facilitator's envelope enum
|
|
564
|
+
* is untagged: it matches on SHAPE and ignores the version marker. Measured
|
|
565
|
+
* against production on 2026-09-03:
|
|
566
|
+
*
|
|
567
|
+
* | payload network | requirements network | v1 envelope today |
|
|
568
|
+
* |-----------------|----------------------|-------------------|
|
|
569
|
+
* | `base` | `base` | **200** |
|
|
570
|
+
* | `base` (header says `x402Version: 2`) | `base` | **200** |
|
|
571
|
+
* | `eip155:8453` | `base` | 400 |
|
|
572
|
+
* | `base` | `eip155:8453` | 400 |
|
|
573
|
+
* | `eip155:8453` | `eip155:8453` | 400 (`unknown variant \`eip155:8453\``) |
|
|
574
|
+
*
|
|
575
|
+
* So a header that merely *declares* version 2 while carrying plain names is
|
|
576
|
+
* being served correctly today. Upgrading it on the strength of the marker would
|
|
577
|
+
* change a call that works -- the one thing this must not do. Every CAIP-2
|
|
578
|
+
* combination, by contrast, is already a hard 400, so switching those to v2
|
|
579
|
+
* cannot regress anyone: it can only turn a failure into a payment.
|
|
580
|
+
*/
|
|
581
|
+
declare function resolveEnvelopeVersion(paymentHeader: X402Header, requirements: PaymentRequirements, requested?: X402Version | 'auto'): X402Version;
|
|
582
|
+
/**
|
|
583
|
+
* Build a `/verify` body in whichever envelope `version` names.
|
|
584
|
+
*
|
|
585
|
+
* The v1 return is byte-for-byte what {@link buildVerifyRequest} produces, so
|
|
586
|
+
* pinning `1` is exactly today's behaviour.
|
|
587
|
+
*
|
|
588
|
+
* @example
|
|
589
|
+
* ```ts
|
|
590
|
+
* const version = resolveEnvelopeVersion(payment, requirements);
|
|
591
|
+
* const body = buildVerifyRequestForVersion(payment, requirements, version);
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
declare function buildVerifyRequestForVersion(paymentHeader: X402Header, requirements: PaymentRequirements, version: X402Version): VerifyRequest | VerifyRequestV2;
|
|
595
|
+
/**
|
|
596
|
+
* Build a `/settle` body in whichever envelope `version` names.
|
|
597
|
+
*
|
|
598
|
+
* See {@link buildVerifyRequestForVersion} -- `/settle` takes the same body as
|
|
599
|
+
* `/verify` in both versions.
|
|
600
|
+
*/
|
|
601
|
+
declare function buildSettleRequestForVersion(paymentHeader: X402Header, requirements: PaymentRequirements, version: X402Version): SettleRequest | SettleRequestV2;
|
|
530
602
|
/**
|
|
531
603
|
* Recommended CORS headers for x402 payment APIs
|
|
532
604
|
*
|
|
@@ -585,6 +657,16 @@ interface FacilitatorClientOptions {
|
|
|
585
657
|
* -- is never replayed here, at any setting.
|
|
586
658
|
*/
|
|
587
659
|
retries?: number;
|
|
660
|
+
/**
|
|
661
|
+
* Which envelope to send to `/verify` and `/settle`. Default `'auto'`.
|
|
662
|
+
*
|
|
663
|
+
* `'auto'` reads the wire: CAIP-2 networks get the v2 envelope, plain names
|
|
664
|
+
* get v1. See {@link resolveEnvelopeVersion} for the measurements behind that
|
|
665
|
+
* rule. Pin `1` or `2` to take the decision yourself -- a pin is honoured
|
|
666
|
+
* even when it contradicts the wire, because choosing the version is the
|
|
667
|
+
* point of the option.
|
|
668
|
+
*/
|
|
669
|
+
x402Version?: X402Version | 'auto';
|
|
588
670
|
}
|
|
589
671
|
/**
|
|
590
672
|
* Client for interacting with the x402 facilitator API
|
|
@@ -611,6 +693,7 @@ declare class FacilitatorClient {
|
|
|
611
693
|
private readonly timeout;
|
|
612
694
|
private readonly explicitTimeout;
|
|
613
695
|
private readonly retries;
|
|
696
|
+
private readonly x402Version;
|
|
614
697
|
constructor(options?: FacilitatorClientOptions);
|
|
615
698
|
/**
|
|
616
699
|
* Get timeout for a specific network, using per-chain defaults when no explicit timeout was set.
|
|
@@ -3134,4 +3217,4 @@ declare class AdvancedEscrowClient {
|
|
|
3134
3217
|
private sendViaAdapter;
|
|
3135
3218
|
}
|
|
3136
3219
|
|
|
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 };
|
|
3220
|
+
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.
|
|
@@ -527,6 +527,78 @@ declare function buildVerifyRequestV2(payload: X402PayloadData, resource: Resour
|
|
|
527
527
|
*/
|
|
528
528
|
declare function buildSettleRequestV2(payload: X402PayloadData, resource: ResourceInfoV2, accepted: PaymentRequirementsV2): SettleRequestV2;
|
|
529
529
|
declare function buildSettleRequest(paymentHeader: X402Header, requirements: PaymentRequirements): SettleRequest;
|
|
530
|
+
/**
|
|
531
|
+
* Derive the v2 `resource` object from v1-shaped requirements.
|
|
532
|
+
*
|
|
533
|
+
* v2 moved `resource` / `description` / `mimeType` out of the requirements and
|
|
534
|
+
* into an object of their own, and the facilitator requires ALL THREE keys:
|
|
535
|
+
* measured 2026-09-03, a `resource` carrying only `url` is a 400.
|
|
536
|
+
*
|
|
537
|
+
* The `??` defaults are not decoration. `PaymentRequirements` types these as
|
|
538
|
+
* required, but a JavaScript caller can still hand over an object without them,
|
|
539
|
+
* and a missing key does not fail with "description is missing" -- it fails with
|
|
540
|
+
* `data did not match any variant of untagged enum VerifyRequestEnvelope`, which
|
|
541
|
+
* names no field. That error is what cost two teams a day.
|
|
542
|
+
*/
|
|
543
|
+
declare function toResourceInfoV2(requirements: PaymentRequirements): ResourceInfoV2;
|
|
544
|
+
/**
|
|
545
|
+
* Derive v2 `accepted` requirements from v1-shaped requirements.
|
|
546
|
+
*
|
|
547
|
+
* Two renames do the damage, and neither is reported by name when it is wrong:
|
|
548
|
+
* - `maxAmountRequired` is spelled `amount` in v2.
|
|
549
|
+
* - `network` must be CAIP-2; a plain name inside a v2 body is a 400.
|
|
550
|
+
*
|
|
551
|
+
* `extra` is carried through when present -- it is where the EIP-712 domain
|
|
552
|
+
* `name`/`version` live for tokens the facilitator does not know by address, so
|
|
553
|
+
* dropping it breaks EURC and the bridged USDCs.
|
|
554
|
+
*/
|
|
555
|
+
declare function toPaymentRequirementsV2(requirements: PaymentRequirements): PaymentRequirementsV2;
|
|
556
|
+
/**
|
|
557
|
+
* Decide which envelope this (payment, requirements) pair has to travel in.
|
|
558
|
+
*
|
|
559
|
+
* `requested` wins when it names a version; `'auto'` (the default) reads the
|
|
560
|
+
* wire.
|
|
561
|
+
*
|
|
562
|
+
* **Auto keys off CAIP-2, NOT off `paymentHeader.x402Version`,** and that is a
|
|
563
|
+
* measured decision rather than a stylistic one. The facilitator's envelope enum
|
|
564
|
+
* is untagged: it matches on SHAPE and ignores the version marker. Measured
|
|
565
|
+
* against production on 2026-09-03:
|
|
566
|
+
*
|
|
567
|
+
* | payload network | requirements network | v1 envelope today |
|
|
568
|
+
* |-----------------|----------------------|-------------------|
|
|
569
|
+
* | `base` | `base` | **200** |
|
|
570
|
+
* | `base` (header says `x402Version: 2`) | `base` | **200** |
|
|
571
|
+
* | `eip155:8453` | `base` | 400 |
|
|
572
|
+
* | `base` | `eip155:8453` | 400 |
|
|
573
|
+
* | `eip155:8453` | `eip155:8453` | 400 (`unknown variant \`eip155:8453\``) |
|
|
574
|
+
*
|
|
575
|
+
* So a header that merely *declares* version 2 while carrying plain names is
|
|
576
|
+
* being served correctly today. Upgrading it on the strength of the marker would
|
|
577
|
+
* change a call that works -- the one thing this must not do. Every CAIP-2
|
|
578
|
+
* combination, by contrast, is already a hard 400, so switching those to v2
|
|
579
|
+
* cannot regress anyone: it can only turn a failure into a payment.
|
|
580
|
+
*/
|
|
581
|
+
declare function resolveEnvelopeVersion(paymentHeader: X402Header, requirements: PaymentRequirements, requested?: X402Version | 'auto'): X402Version;
|
|
582
|
+
/**
|
|
583
|
+
* Build a `/verify` body in whichever envelope `version` names.
|
|
584
|
+
*
|
|
585
|
+
* The v1 return is byte-for-byte what {@link buildVerifyRequest} produces, so
|
|
586
|
+
* pinning `1` is exactly today's behaviour.
|
|
587
|
+
*
|
|
588
|
+
* @example
|
|
589
|
+
* ```ts
|
|
590
|
+
* const version = resolveEnvelopeVersion(payment, requirements);
|
|
591
|
+
* const body = buildVerifyRequestForVersion(payment, requirements, version);
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
declare function buildVerifyRequestForVersion(paymentHeader: X402Header, requirements: PaymentRequirements, version: X402Version): VerifyRequest | VerifyRequestV2;
|
|
595
|
+
/**
|
|
596
|
+
* Build a `/settle` body in whichever envelope `version` names.
|
|
597
|
+
*
|
|
598
|
+
* See {@link buildVerifyRequestForVersion} -- `/settle` takes the same body as
|
|
599
|
+
* `/verify` in both versions.
|
|
600
|
+
*/
|
|
601
|
+
declare function buildSettleRequestForVersion(paymentHeader: X402Header, requirements: PaymentRequirements, version: X402Version): SettleRequest | SettleRequestV2;
|
|
530
602
|
/**
|
|
531
603
|
* Recommended CORS headers for x402 payment APIs
|
|
532
604
|
*
|
|
@@ -585,6 +657,16 @@ interface FacilitatorClientOptions {
|
|
|
585
657
|
* -- is never replayed here, at any setting.
|
|
586
658
|
*/
|
|
587
659
|
retries?: number;
|
|
660
|
+
/**
|
|
661
|
+
* Which envelope to send to `/verify` and `/settle`. Default `'auto'`.
|
|
662
|
+
*
|
|
663
|
+
* `'auto'` reads the wire: CAIP-2 networks get the v2 envelope, plain names
|
|
664
|
+
* get v1. See {@link resolveEnvelopeVersion} for the measurements behind that
|
|
665
|
+
* rule. Pin `1` or `2` to take the decision yourself -- a pin is honoured
|
|
666
|
+
* even when it contradicts the wire, because choosing the version is the
|
|
667
|
+
* point of the option.
|
|
668
|
+
*/
|
|
669
|
+
x402Version?: X402Version | 'auto';
|
|
588
670
|
}
|
|
589
671
|
/**
|
|
590
672
|
* Client for interacting with the x402 facilitator API
|
|
@@ -611,6 +693,7 @@ declare class FacilitatorClient {
|
|
|
611
693
|
private readonly timeout;
|
|
612
694
|
private readonly explicitTimeout;
|
|
613
695
|
private readonly retries;
|
|
696
|
+
private readonly x402Version;
|
|
614
697
|
constructor(options?: FacilitatorClientOptions);
|
|
615
698
|
/**
|
|
616
699
|
* Get timeout for a specific network, using per-chain defaults when no explicit timeout was set.
|
|
@@ -3134,4 +3217,4 @@ declare class AdvancedEscrowClient {
|
|
|
3134
3217
|
private sendViaAdapter;
|
|
3135
3218
|
}
|
|
3136
3219
|
|
|
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 };
|
|
3220
|
+
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
|
@@ -1289,6 +1289,54 @@ function buildSettleRequest(paymentHeader, requirements) {
|
|
|
1289
1289
|
paymentRequirements: requirements
|
|
1290
1290
|
};
|
|
1291
1291
|
}
|
|
1292
|
+
function isCaip2Network(network) {
|
|
1293
|
+
return network.includes(":");
|
|
1294
|
+
}
|
|
1295
|
+
function toResourceInfoV2(requirements) {
|
|
1296
|
+
return {
|
|
1297
|
+
url: requirements.resource,
|
|
1298
|
+
description: requirements.description ?? DEFAULT_PAYMENT_DESCRIPTION,
|
|
1299
|
+
mimeType: requirements.mimeType ?? DEFAULT_PAYMENT_MIME_TYPE
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
function toPaymentRequirementsV2(requirements) {
|
|
1303
|
+
return {
|
|
1304
|
+
scheme: requirements.scheme,
|
|
1305
|
+
network: isCaip2Network(requirements.network) ? requirements.network : chainToCAIP2(requirements.network),
|
|
1306
|
+
asset: requirements.asset,
|
|
1307
|
+
amount: requirements.maxAmountRequired,
|
|
1308
|
+
payTo: requirements.payTo,
|
|
1309
|
+
// Required by the facilitator: omitting it is a 400, measured the same day.
|
|
1310
|
+
maxTimeoutSeconds: requirements.maxTimeoutSeconds ?? DEFAULT_PAYMENT_TIMEOUT_SECONDS,
|
|
1311
|
+
...requirements.extra !== void 0 ? { extra: requirements.extra } : {}
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
function resolveEnvelopeVersion(paymentHeader, requirements, requested = "auto") {
|
|
1315
|
+
if (requested !== "auto") {
|
|
1316
|
+
return requested;
|
|
1317
|
+
}
|
|
1318
|
+
return isCaip2Network(paymentHeader.network) || isCaip2Network(requirements.network) ? 2 : 1;
|
|
1319
|
+
}
|
|
1320
|
+
function buildVerifyRequestForVersion(paymentHeader, requirements, version) {
|
|
1321
|
+
if (version === 2) {
|
|
1322
|
+
return buildVerifyRequestV2(
|
|
1323
|
+
paymentHeader.payload,
|
|
1324
|
+
toResourceInfoV2(requirements),
|
|
1325
|
+
toPaymentRequirementsV2(requirements)
|
|
1326
|
+
);
|
|
1327
|
+
}
|
|
1328
|
+
return buildVerifyRequest(paymentHeader, requirements);
|
|
1329
|
+
}
|
|
1330
|
+
function buildSettleRequestForVersion(paymentHeader, requirements, version) {
|
|
1331
|
+
if (version === 2) {
|
|
1332
|
+
return buildSettleRequestV2(
|
|
1333
|
+
paymentHeader.payload,
|
|
1334
|
+
toResourceInfoV2(requirements),
|
|
1335
|
+
toPaymentRequirementsV2(requirements)
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
return buildSettleRequest(paymentHeader, requirements);
|
|
1339
|
+
}
|
|
1292
1340
|
var X402_CORS_HEADERS = {
|
|
1293
1341
|
"Access-Control-Allow-Headers": "Content-Type, X-PAYMENT, PAYMENT-SIGNATURE, Authorization",
|
|
1294
1342
|
"Access-Control-Expose-Headers": "X-PAYMENT-RESPONSE, PAYMENT-RESPONSE, PAYMENT-REQUIRED",
|
|
@@ -1312,11 +1360,13 @@ var FacilitatorClient = class {
|
|
|
1312
1360
|
timeout;
|
|
1313
1361
|
explicitTimeout;
|
|
1314
1362
|
retries;
|
|
1363
|
+
x402Version;
|
|
1315
1364
|
constructor(options = {}) {
|
|
1316
1365
|
this.baseUrl = options.baseUrl || "https://facilitator.ultravioletadao.xyz";
|
|
1317
1366
|
this.explicitTimeout = options.timeout !== void 0;
|
|
1318
1367
|
this.timeout = options.timeout || 3e4;
|
|
1319
1368
|
this.retries = options.retries;
|
|
1369
|
+
this.x402Version = options.x402Version ?? "auto";
|
|
1320
1370
|
}
|
|
1321
1371
|
/**
|
|
1322
1372
|
* Get timeout for a specific network, using per-chain defaults when no explicit timeout was set.
|
|
@@ -1342,7 +1392,11 @@ var FacilitatorClient = class {
|
|
|
1342
1392
|
* @returns Verification result
|
|
1343
1393
|
*/
|
|
1344
1394
|
async verify(paymentHeader, requirements) {
|
|
1345
|
-
const body =
|
|
1395
|
+
const body = buildVerifyRequestForVersion(
|
|
1396
|
+
paymentHeader,
|
|
1397
|
+
requirements,
|
|
1398
|
+
resolveEnvelopeVersion(paymentHeader, requirements, this.x402Version)
|
|
1399
|
+
);
|
|
1346
1400
|
try {
|
|
1347
1401
|
const { response, error } = await facilitatorFetch(
|
|
1348
1402
|
`${this.baseUrl}/verify`,
|
|
@@ -1381,7 +1435,11 @@ var FacilitatorClient = class {
|
|
|
1381
1435
|
* @returns Settlement result with transaction hash
|
|
1382
1436
|
*/
|
|
1383
1437
|
async settle(paymentHeader, requirements) {
|
|
1384
|
-
const body =
|
|
1438
|
+
const body = buildSettleRequestForVersion(
|
|
1439
|
+
paymentHeader,
|
|
1440
|
+
requirements,
|
|
1441
|
+
resolveEnvelopeVersion(paymentHeader, requirements, this.x402Version)
|
|
1442
|
+
);
|
|
1385
1443
|
const settleTimeout = this.getTimeout(requirements.network);
|
|
1386
1444
|
try {
|
|
1387
1445
|
const { response, error } = await facilitatorFetch(
|
|
@@ -4719,8 +4777,10 @@ exports.ZERO_ADDRESS = ZERO_ADDRESS;
|
|
|
4719
4777
|
exports.buildErc8004PaymentRequirements = buildErc8004PaymentRequirements;
|
|
4720
4778
|
exports.buildPaymentRequirements = buildPaymentRequirements;
|
|
4721
4779
|
exports.buildSettleRequest = buildSettleRequest;
|
|
4780
|
+
exports.buildSettleRequestForVersion = buildSettleRequestForVersion;
|
|
4722
4781
|
exports.buildSettleRequestV2 = buildSettleRequestV2;
|
|
4723
4782
|
exports.buildVerifyRequest = buildVerifyRequest;
|
|
4783
|
+
exports.buildVerifyRequestForVersion = buildVerifyRequestForVersion;
|
|
4724
4784
|
exports.buildVerifyRequestV2 = buildVerifyRequestV2;
|
|
4725
4785
|
exports.canRefundEscrow = canRefundEscrow;
|
|
4726
4786
|
exports.canReleaseEscrow = canReleaseEscrow;
|
|
@@ -4744,7 +4804,10 @@ exports.isReplayableLeaseReason = isReplayableLeaseReason;
|
|
|
4744
4804
|
exports.parsePaymentHeader = parsePaymentHeader;
|
|
4745
4805
|
exports.parseRetryAfterSeconds = parseRetryAfterSeconds;
|
|
4746
4806
|
exports.readFacilitatorError = readFacilitatorError;
|
|
4807
|
+
exports.resolveEnvelopeVersion = resolveEnvelopeVersion;
|
|
4747
4808
|
exports.supportsRelayedFeedback = supportsRelayedFeedback;
|
|
4809
|
+
exports.toPaymentRequirementsV2 = toPaymentRequirementsV2;
|
|
4810
|
+
exports.toResourceInfoV2 = toResourceInfoV2;
|
|
4748
4811
|
exports.wireNetwork = wireNetwork;
|
|
4749
4812
|
//# sourceMappingURL=index.js.map
|
|
4750
4813
|
//# sourceMappingURL=index.js.map
|