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/index.mjs CHANGED
@@ -4554,6 +4554,14 @@ function randomNonce() {
4554
4554
  }
4555
4555
  return ethers.hexlify(ethers.randomBytes(32));
4556
4556
  }
4557
+ function resolveOrderTiming(params) {
4558
+ const nowSec = params.now === void 0 ? Math.floor(Date.now() / 1e3) : Math.floor(params.now);
4559
+ return {
4560
+ nowSec,
4561
+ deadline: params.deadline === void 0 ? nowSec + LIFECYCLE_DEFAULT_DEADLINE_SECS : Math.floor(params.deadline),
4562
+ nonce: params.nonce === void 0 ? randomNonce() : params.nonce
4563
+ };
4564
+ }
4557
4565
  function toUintString(value, field) {
4558
4566
  let n;
4559
4567
  try {
@@ -4567,7 +4575,8 @@ function toUintString(value, field) {
4567
4575
  return n.toString();
4568
4576
  }
4569
4577
  function buildLifecycleTypedData(params) {
4570
- const { action, paymentInfo, payer, amount, chainId, deadline, nonce } = params;
4578
+ const { action, paymentInfo, payer, amount, chainId } = params;
4579
+ const { deadline, nonce } = resolveOrderTiming(params);
4571
4580
  if (!LIFECYCLE_ACTIONS.includes(action)) {
4572
4581
  throw new X402Error(
4573
4582
  `unknown lifecycle action ${String(action)}; the facilitator only signs ${LIFECYCLE_ACTIONS.join(", ")}`,
@@ -4626,10 +4635,8 @@ function buildLifecycleTypedData(params) {
4626
4635
  };
4627
4636
  }
4628
4637
  async function buildLifecycleAuth(params) {
4629
- const { wallet, deadline, nonce, now, ...rest } = params;
4630
- const nowSec = now === void 0 ? Math.floor(Date.now() / 1e3) : Math.floor(now);
4631
- const dl = deadline === void 0 ? nowSec + LIFECYCLE_DEFAULT_DEADLINE_SECS : Math.floor(deadline);
4632
- const nonceHex = nonce === void 0 ? randomNonce() : nonce;
4638
+ const { wallet, ...rest } = params;
4639
+ const { nowSec, deadline: dl, nonce: nonceHex } = resolveOrderTiming(params);
4633
4640
  if (dl < nowSec) {
4634
4641
  throw new X402Error(
4635
4642
  `deadline ${dl} is in the past (now ${nowSec}): the facilitator discards it as \`expired\``,
@@ -4651,6 +4658,54 @@ async function buildLifecycleAuth(params) {
4651
4658
  signature: signed.signature
4652
4659
  };
4653
4660
  }
4661
+ function lifecycleAuthFromSignature(typedData, signature, signer) {
4662
+ const td = typedData ?? {};
4663
+ const message = td.message ?? {};
4664
+ if (td.primaryType !== "LifecycleOrder") {
4665
+ throw new X402Error(
4666
+ `typedData.primaryType must be LifecycleOrder, got ${String(td.primaryType)}: pass the document buildLifecycleTypedData returned, unmodified`,
4667
+ "INVALID_CONFIG"
4668
+ );
4669
+ }
4670
+ const domain = td.domain ?? {};
4671
+ if (domain.name !== LIFECYCLE_DOMAIN_NAME || String(domain.version) !== LIFECYCLE_DOMAIN_VERSION) {
4672
+ throw new X402Error(
4673
+ `typedData.domain must be ${LIFECYCLE_DOMAIN_NAME} v${LIFECYCLE_DOMAIN_VERSION}, got ${String(domain.name)} v${String(domain.version)}`,
4674
+ "INVALID_CONFIG"
4675
+ );
4676
+ }
4677
+ if (message.deadline === void 0 || message.nonce === void 0) {
4678
+ throw new X402Error(
4679
+ "typedData.message carries no deadline/nonce: the wire block reads them from the document that was signed, it does not invent them",
4680
+ "INVALID_CONFIG"
4681
+ );
4682
+ }
4683
+ const deadlineBig = BigInt(toUintString(message.deadline, "typedData.message.deadline"));
4684
+ if (deadlineBig > BigInt(Number.MAX_SAFE_INTEGER)) {
4685
+ throw new X402Error(
4686
+ `typedData.message.deadline ${deadlineBig} does not fit a JSON number`,
4687
+ "INVALID_CONFIG"
4688
+ );
4689
+ }
4690
+ if (typeof signature !== "string" || !/^0x[0-9a-fA-F]+$/.test(signature) || signature.length % 2 !== 0) {
4691
+ throw new X402Error(
4692
+ `signature must be 0x-prefixed hex, got ${String(signature)}`,
4693
+ "INVALID_CONFIG"
4694
+ );
4695
+ }
4696
+ let checksummed;
4697
+ try {
4698
+ checksummed = ethers.getAddress(signer);
4699
+ } catch {
4700
+ throw new X402Error(`signer is not an EVM address: ${String(signer)}`, "INVALID_CONFIG");
4701
+ }
4702
+ return {
4703
+ signer: checksummed,
4704
+ deadline: Number(deadlineBig),
4705
+ nonce: nonceToBytes32(message.nonce),
4706
+ signature
4707
+ };
4708
+ }
4654
4709
  function wagmiLifecycleSigner(walletClient, address) {
4655
4710
  const account = address ?? walletClient.account?.address;
4656
4711
  if (!account) {
@@ -4677,6 +4732,7 @@ function wagmiLifecycleSigner(walletClient, address) {
4677
4732
 
4678
4733
  // src/backend/index.ts
4679
4734
  init_utils();
4735
+ init_types();
4680
4736
  init_chains();
4681
4737
 
4682
4738
  // src/backend/facilitator-error.ts
@@ -5769,6 +5825,6 @@ var ESCROW_TIMEOUT_MS = {
5769
5825
  // Monad: 90s
5770
5826
  };
5771
5827
 
5772
- export { AMBIGUOUS_LEASE_REASONS, ANCHOR_MAX_REQUEST_BYTES, CAIP2_IDENTIFIERS, CAIP2_TO_CHAIN, ContentHashMismatch, DEFAULT_CHAIN, DEFAULT_CONFIG, DEFAULT_FACILITATOR_RETRIES, DEFAULT_FACILITATOR_URL, DEFAULT_MAX_FEE_BPS, DEFAULT_MIN_FEE_BPS, DEFAULT_PAYMENT_HEADER, DEFAULT_RETRY_AFTER_SECONDS, DELEGATE_PREFIX, DX402Error, ESCROW_DEPOSIT_LIMIT_USD, ESCROW_TIER_WINDOWS, EVENT_KINDS, EVIDENCE_HEADER, EnvKeyAdapter, EvidenceSkipped, FACILITATOR_ADDRESSES, FacilitatorClient, KEEPALIVE_INTERVAL_MS, LIFECYCLE_ACTIONS, LIFECYCLE_DEFAULT_DEADLINE_SECS, LIFECYCLE_DOMAIN_NAME, LIFECYCLE_DOMAIN_VERSION, LIFECYCLE_MAX_DEADLINE_SECS, LIFECYCLE_ORDER_TYPES, MAX_PROTOCOL_FEE_BPS, MAX_RETRY_AFTER_SECONDS, OPERATOR_FEE_BPS, OWSWalletAdapter, PAYMENT_HEADER_NAMES, REPLAYABLE_LEASE_REASONS, SETTLEMENT_UNCONFIRMED, SMA_WRAP_TARGETS, SSEParser, SUPPORTED_CHAINS, TrafficStreamError, WRITER_LEASE_REASONS, X402Client, X402Error, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, anchorDigest, anchorEvidence, availableBackends, buildEscrowPreAuth, buildLifecycleAuth, buildLifecycleTypedData, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildSignatureBase, buildSignatureParams, buildTokenMetadata, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, caip2ToChain, chainToCAIP2, computeEscrowNonce, contentHash, convertX402Header, create402Response, createHonoMiddleware, createPaymentHeaders, createPaymentMiddleware, createSignedFetch, createX402Header, createX402V1Header, createX402V2Header, decodeBase64Utf8, decodeX402Header, delegateTarget, dereferencePointer, detectX402Version, paymentId as dx402PaymentId, ed25519ToX25519, encodeBase64Json, encodeBase64Utf8, encodeX402Header, evidenceFromHeaders, evidenceHeader, extractPaymentFromHeaders, facilitatorFetch, fetchNonce, generatePaymentOptions, getAlgorandChains, getChainById, getChainByName, getChainsByNetworkType, getChainsByToken, getCorsHeaders, getEVMChainIds, getEnabledChains, getExplorerAddressUrl, getExplorerTxUrl, getFacilitatorAddress, getNetworkType, getPaymentHeader, getSVMChains, getSuiChains, getSupportedTokens, getTokenByAddress, getTokenConfig, getXRPLChains, isAlgorandChain, isAmbiguousLeaseReason, isCAIP2Format, isChainSupported, isDelegated, isEndToEnd, isReplayableLeaseReason, isSVMChain, isSettlementUnconfirmed, isSuiChain, isTokenSupported, isXRPLChain, matchesFilters, needsAccountWrap, parseEvidenceHeader, parseFacilitatorErrorBody, parseNetworkIdentifier, parseRetryAfterSeconds, parseSealed, parseTrafficEvent, payerKeyFromEvmSignature, payerKeyFromSolanaAddress, paymentChallengeFrom, readFacilitatorError, recoverEvidence, replaySafeTypedData, resolveDelegation, resolveEnvelopeVersion, rpcDelegationResolver, sealEvidence, sealEvidenceTo, sealedRoles, sellerDigestFor, signAnchorEd25519, signAnchorEvm, signRequest, signRequestWithSigner, signRequestWithWallet, streamTrafficEvents, toPaymentRequirementsV2, toResourceInfoV2, unseal, validateAmount, validateRecipient, wagmiLifecycleSigner, wrapSignature };
5828
+ export { AMBIGUOUS_LEASE_REASONS, ANCHOR_MAX_REQUEST_BYTES, CAIP2_IDENTIFIERS, CAIP2_TO_CHAIN, ContentHashMismatch, DEFAULT_CHAIN, DEFAULT_CONFIG, DEFAULT_FACILITATOR_RETRIES, DEFAULT_FACILITATOR_URL, DEFAULT_MAX_FEE_BPS, DEFAULT_MIN_FEE_BPS, DEFAULT_PAYMENT_HEADER, DEFAULT_RETRY_AFTER_SECONDS, DELEGATE_PREFIX, DX402Error, ESCROW_DEPOSIT_LIMIT_USD, ESCROW_TIER_WINDOWS, EVENT_KINDS, EVIDENCE_HEADER, EnvKeyAdapter, EvidenceSkipped, FACILITATOR_ADDRESSES, FacilitatorClient, KEEPALIVE_INTERVAL_MS, LIFECYCLE_ACTIONS, LIFECYCLE_DEFAULT_DEADLINE_SECS, LIFECYCLE_DOMAIN_NAME, LIFECYCLE_DOMAIN_VERSION, LIFECYCLE_MAX_DEADLINE_SECS, LIFECYCLE_ORDER_TYPES, MAX_PROTOCOL_FEE_BPS, MAX_RETRY_AFTER_SECONDS, OPERATOR_FEE_BPS, OWSWalletAdapter, PAYMENT_HEADER_NAMES, REPLAYABLE_LEASE_REASONS, SETTLEMENT_UNCONFIRMED, SMA_WRAP_TARGETS, SSEParser, SUPPORTED_CHAINS, TrafficStreamError, WRITER_LEASE_REASONS, X402Client, X402Error, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, anchorDigest, anchorEvidence, availableBackends, buildEscrowPreAuth, buildLifecycleAuth, buildLifecycleTypedData, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildSignatureBase, buildSignatureParams, buildTokenMetadata, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, caip2ToChain, chainToCAIP2, computeEscrowNonce, contentHash, convertX402Header, create402Response, createHonoMiddleware, createPaymentHeaders, createPaymentMiddleware, createSignedFetch, createX402Header, createX402V1Header, createX402V2Header, decodeBase64Utf8, decodeX402Header, delegateTarget, dereferencePointer, detectX402Version, paymentId as dx402PaymentId, ed25519ToX25519, encodeBase64Json, encodeBase64Utf8, encodeX402Header, evidenceFromHeaders, evidenceHeader, extractPaymentFromHeaders, facilitatorFetch, fetchNonce, generatePaymentOptions, getAlgorandChains, getChainById, getChainByName, getChainsByNetworkType, getChainsByToken, getCorsHeaders, getEVMChainIds, getEnabledChains, getExplorerAddressUrl, getExplorerTxUrl, getFacilitatorAddress, getNetworkType, getPaymentHeader, getSVMChains, getSuiChains, getSupportedTokens, getTokenByAddress, getTokenConfig, getXRPLChains, isAlgorandChain, isAmbiguousLeaseReason, isCAIP2Format, isChainSupported, isDelegated, isEndToEnd, isReplayableLeaseReason, isSVMChain, isSettlementUnconfirmed, isSuiChain, isTokenSupported, isXRPLChain, lifecycleAuthFromSignature, matchesFilters, needsAccountWrap, parseEvidenceHeader, parseFacilitatorErrorBody, parseNetworkIdentifier, parseRetryAfterSeconds, parseSealed, parseTrafficEvent, payerKeyFromEvmSignature, payerKeyFromSolanaAddress, paymentChallengeFrom, readFacilitatorError, recoverEvidence, replaySafeTypedData, resolveDelegation, resolveEnvelopeVersion, rpcDelegationResolver, sealEvidence, sealEvidenceTo, sealedRoles, sellerDigestFor, signAnchorEd25519, signAnchorEvm, signRequest, signRequestWithSigner, signRequestWithWallet, streamTrafficEvents, toPaymentRequirementsV2, toResourceInfoV2, unseal, validateAmount, validateRecipient, wagmiLifecycleSigner, wrapSignature };
5773
5829
  //# sourceMappingURL=index.mjs.map
5774
5830
  //# sourceMappingURL=index.mjs.map