uvd-x402-sdk 2.77.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.
@@ -1287,6 +1287,54 @@ function buildSettleRequest(paymentHeader, requirements) {
1287
1287
  paymentRequirements: requirements
1288
1288
  };
1289
1289
  }
1290
+ function isCaip2Network(network) {
1291
+ return network.includes(":");
1292
+ }
1293
+ function toResourceInfoV2(requirements) {
1294
+ return {
1295
+ url: requirements.resource,
1296
+ description: requirements.description ?? DEFAULT_PAYMENT_DESCRIPTION,
1297
+ mimeType: requirements.mimeType ?? DEFAULT_PAYMENT_MIME_TYPE
1298
+ };
1299
+ }
1300
+ function toPaymentRequirementsV2(requirements) {
1301
+ return {
1302
+ scheme: requirements.scheme,
1303
+ network: isCaip2Network(requirements.network) ? requirements.network : chainToCAIP2(requirements.network),
1304
+ asset: requirements.asset,
1305
+ amount: requirements.maxAmountRequired,
1306
+ payTo: requirements.payTo,
1307
+ // Required by the facilitator: omitting it is a 400, measured the same day.
1308
+ maxTimeoutSeconds: requirements.maxTimeoutSeconds ?? DEFAULT_PAYMENT_TIMEOUT_SECONDS,
1309
+ ...requirements.extra !== void 0 ? { extra: requirements.extra } : {}
1310
+ };
1311
+ }
1312
+ function resolveEnvelopeVersion(paymentHeader, requirements, requested = "auto") {
1313
+ if (requested !== "auto") {
1314
+ return requested;
1315
+ }
1316
+ return isCaip2Network(paymentHeader.network) || isCaip2Network(requirements.network) ? 2 : 1;
1317
+ }
1318
+ function buildVerifyRequestForVersion(paymentHeader, requirements, version) {
1319
+ if (version === 2) {
1320
+ return buildVerifyRequestV2(
1321
+ paymentHeader.payload,
1322
+ toResourceInfoV2(requirements),
1323
+ toPaymentRequirementsV2(requirements)
1324
+ );
1325
+ }
1326
+ return buildVerifyRequest(paymentHeader, requirements);
1327
+ }
1328
+ function buildSettleRequestForVersion(paymentHeader, requirements, version) {
1329
+ if (version === 2) {
1330
+ return buildSettleRequestV2(
1331
+ paymentHeader.payload,
1332
+ toResourceInfoV2(requirements),
1333
+ toPaymentRequirementsV2(requirements)
1334
+ );
1335
+ }
1336
+ return buildSettleRequest(paymentHeader, requirements);
1337
+ }
1290
1338
  var X402_CORS_HEADERS = {
1291
1339
  "Access-Control-Allow-Headers": "Content-Type, X-PAYMENT, PAYMENT-SIGNATURE, Authorization",
1292
1340
  "Access-Control-Expose-Headers": "X-PAYMENT-RESPONSE, PAYMENT-RESPONSE, PAYMENT-REQUIRED",
@@ -1310,11 +1358,13 @@ var FacilitatorClient = class {
1310
1358
  timeout;
1311
1359
  explicitTimeout;
1312
1360
  retries;
1361
+ x402Version;
1313
1362
  constructor(options = {}) {
1314
1363
  this.baseUrl = options.baseUrl || "https://facilitator.ultravioletadao.xyz";
1315
1364
  this.explicitTimeout = options.timeout !== void 0;
1316
1365
  this.timeout = options.timeout || 3e4;
1317
1366
  this.retries = options.retries;
1367
+ this.x402Version = options.x402Version ?? "auto";
1318
1368
  }
1319
1369
  /**
1320
1370
  * Get timeout for a specific network, using per-chain defaults when no explicit timeout was set.
@@ -1340,7 +1390,11 @@ var FacilitatorClient = class {
1340
1390
  * @returns Verification result
1341
1391
  */
1342
1392
  async verify(paymentHeader, requirements) {
1343
- const body = buildVerifyRequest(paymentHeader, requirements);
1393
+ const body = buildVerifyRequestForVersion(
1394
+ paymentHeader,
1395
+ requirements,
1396
+ resolveEnvelopeVersion(paymentHeader, requirements, this.x402Version)
1397
+ );
1344
1398
  try {
1345
1399
  const { response, error } = await facilitatorFetch(
1346
1400
  `${this.baseUrl}/verify`,
@@ -1379,7 +1433,11 @@ var FacilitatorClient = class {
1379
1433
  * @returns Settlement result with transaction hash
1380
1434
  */
1381
1435
  async settle(paymentHeader, requirements) {
1382
- const body = buildSettleRequest(paymentHeader, requirements);
1436
+ const body = buildSettleRequestForVersion(
1437
+ paymentHeader,
1438
+ requirements,
1439
+ resolveEnvelopeVersion(paymentHeader, requirements, this.x402Version)
1440
+ );
1383
1441
  const settleTimeout = this.getTimeout(requirements.network);
1384
1442
  try {
1385
1443
  const { response, error } = await facilitatorFetch(
@@ -4683,6 +4741,6 @@ var AdvancedEscrowClient = class {
4683
4741
  }
4684
4742
  };
4685
4743
 
4686
- export { AMBIGUOUS_LEASE_REASONS, AdvancedEscrowClient, BASE_MAINNET_CONTRACTS, BazaarClient, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, Erc8004LookupError, EscrowClient, FacilitatorClient, HEALTH_FILTERS, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, RegistrationPendingError, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, WRITER_LEASE_REASONS, 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 };
4744
+ export { AMBIGUOUS_LEASE_REASONS, AdvancedEscrowClient, BASE_MAINNET_CONTRACTS, BazaarClient, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, Erc8004LookupError, EscrowClient, FacilitatorClient, HEALTH_FILTERS, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, RegistrationPendingError, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, WRITER_LEASE_REASONS, 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 };
4687
4745
  //# sourceMappingURL=index.mjs.map
4688
4746
  //# sourceMappingURL=index.mjs.map