uvd-x402-sdk 2.85.0 → 2.86.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.d.mts CHANGED
@@ -4,7 +4,7 @@ export { A as AlgorandPaymentPayload, q as CAIP2_IDENTIFIERS, r as CAIP2_TO_CHAI
4
4
  import { S as SigningWalletAdapter } from './wallet-w7BnImDG.mjs';
5
5
  export { a as EIP3009Authorization, E as EIP3009Params } from './wallet-w7BnImDG.mjs';
6
6
  export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-Z9v4GxOZ.mjs';
7
- export { AMBIGUOUS_LEASE_REASONS, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, FacilitatorClient, FacilitatorClientOptions, FacilitatorErrorInfo, FacilitatorFailureFields, FacilitatorFetchOptions, HonoMiddlewareOptions, MAX_RETRY_AFTER_SECONDS, ParsedFacilitatorErrorBody, PaymentAcceptance, PaymentMiddlewareOptions, PaymentPayloadV2, PaymentRequirementsV2, REPLAYABLE_LEASE_REASONS, ResourceInfoV2, SETTLEMENT_UNCONFIRMED, SettleRequestV2, VerifiedPaymentState, VerifyRequestV2, WRITER_LEASE_REASONS, WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, create402Response, createHonoMiddleware, createPaymentMiddleware, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, isAmbiguousLeaseReason, isReplayableLeaseReason, isSettlementUnconfirmed, parseFacilitatorErrorBody, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, toPaymentRequirementsV2, toResourceInfoV2 } from './backend/index.mjs';
7
+ export { A as AMBIGUOUS_LEASE_REASONS, B as BuildLifecycleAuthParams, D as DEFAULT_FACILITATOR_RETRIES, a as DEFAULT_RETRY_AFTER_SECONDS, F as FacilitatorClient, b as FacilitatorClientOptions, c as FacilitatorErrorInfo, d as FacilitatorFailureFields, e as FacilitatorFetchOptions, H as HonoMiddlewareOptions, L as LIFECYCLE_ACTIONS, f as LIFECYCLE_DEFAULT_DEADLINE_SECS, g as LIFECYCLE_DOMAIN_NAME, h as LIFECYCLE_DOMAIN_VERSION, i as LIFECYCLE_MAX_DEADLINE_SECS, j as LIFECYCLE_ORDER_TYPES, k as LifecycleAction, l as LifecycleAuth, m as LifecyclePaymentInfo, n as LifecycleSigner, o as LifecycleTypedDataParams, M as MAX_RETRY_AFTER_SECONDS, P as ParsedFacilitatorErrorBody, p as PaymentAcceptance, q as PaymentMiddlewareOptions, r as PaymentPayloadV2, s as PaymentRequirementsV2, R as REPLAYABLE_LEASE_REASONS, t as ResourceInfoV2, S as SETTLEMENT_UNCONFIRMED, u as SettleRequestV2, V as VerifiedPaymentState, v as VerifyRequestV2, W as WRITER_LEASE_REASONS, w as WagmiLifecycleWalletClient, x as WriterLeaseReason, X as X402_CORS_HEADERS, y as X402_HEADER_NAMES, z as buildLifecycleAuth, C as buildLifecycleTypedData, E as buildPaymentRequirements, G as buildSettleRequest, I as buildSettleRequestForVersion, J as buildSettleRequestV2, K as buildVerifyRequest, N as buildVerifyRequestForVersion, O as buildVerifyRequestV2, Q as create402Response, T as createHonoMiddleware, U as createPaymentMiddleware, Y as extractPaymentFromHeaders, Z as facilitatorFetch, _ as getCorsHeaders, $ as isAmbiguousLeaseReason, a0 as isReplayableLeaseReason, a1 as isSettlementUnconfirmed, a2 as parseFacilitatorErrorBody, a3 as parseRetryAfterSeconds, a4 as readFacilitatorError, a5 as resolveEnvelopeVersion, a6 as toPaymentRequirementsV2, a7 as toResourceInfoV2, a8 as wagmiLifecycleSigner } from './index-De03nksW.mjs';
8
8
 
9
9
  /**
10
10
  * DX402 `durable-evidence`: recover a paid response after the fact.
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { A as AlgorandPaymentPayload, q as CAIP2_IDENTIFIERS, r as CAIP2_TO_CHAI
4
4
  import { S as SigningWalletAdapter } from './wallet-w7BnImDG.js';
5
5
  export { a as EIP3009Authorization, E as EIP3009Params } from './wallet-w7BnImDG.js';
6
6
  export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-C-KmORG9.js';
7
- export { AMBIGUOUS_LEASE_REASONS, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, FacilitatorClient, FacilitatorClientOptions, FacilitatorErrorInfo, FacilitatorFailureFields, FacilitatorFetchOptions, HonoMiddlewareOptions, MAX_RETRY_AFTER_SECONDS, ParsedFacilitatorErrorBody, PaymentAcceptance, PaymentMiddlewareOptions, PaymentPayloadV2, PaymentRequirementsV2, REPLAYABLE_LEASE_REASONS, ResourceInfoV2, SETTLEMENT_UNCONFIRMED, SettleRequestV2, VerifiedPaymentState, VerifyRequestV2, WRITER_LEASE_REASONS, WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, create402Response, createHonoMiddleware, createPaymentMiddleware, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, isAmbiguousLeaseReason, isReplayableLeaseReason, isSettlementUnconfirmed, parseFacilitatorErrorBody, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, toPaymentRequirementsV2, toResourceInfoV2 } from './backend/index.js';
7
+ export { A as AMBIGUOUS_LEASE_REASONS, B as BuildLifecycleAuthParams, D as DEFAULT_FACILITATOR_RETRIES, a as DEFAULT_RETRY_AFTER_SECONDS, F as FacilitatorClient, b as FacilitatorClientOptions, c as FacilitatorErrorInfo, d as FacilitatorFailureFields, e as FacilitatorFetchOptions, H as HonoMiddlewareOptions, L as LIFECYCLE_ACTIONS, f as LIFECYCLE_DEFAULT_DEADLINE_SECS, g as LIFECYCLE_DOMAIN_NAME, h as LIFECYCLE_DOMAIN_VERSION, i as LIFECYCLE_MAX_DEADLINE_SECS, j as LIFECYCLE_ORDER_TYPES, k as LifecycleAction, l as LifecycleAuth, m as LifecyclePaymentInfo, n as LifecycleSigner, o as LifecycleTypedDataParams, M as MAX_RETRY_AFTER_SECONDS, P as ParsedFacilitatorErrorBody, p as PaymentAcceptance, q as PaymentMiddlewareOptions, r as PaymentPayloadV2, s as PaymentRequirementsV2, R as REPLAYABLE_LEASE_REASONS, t as ResourceInfoV2, S as SETTLEMENT_UNCONFIRMED, u as SettleRequestV2, V as VerifiedPaymentState, v as VerifyRequestV2, W as WRITER_LEASE_REASONS, w as WagmiLifecycleWalletClient, x as WriterLeaseReason, X as X402_CORS_HEADERS, y as X402_HEADER_NAMES, z as buildLifecycleAuth, C as buildLifecycleTypedData, E as buildPaymentRequirements, G as buildSettleRequest, I as buildSettleRequestForVersion, J as buildSettleRequestV2, K as buildVerifyRequest, N as buildVerifyRequestForVersion, O as buildVerifyRequestV2, Q as create402Response, T as createHonoMiddleware, U as createPaymentMiddleware, Y as extractPaymentFromHeaders, Z as facilitatorFetch, _ as getCorsHeaders, $ as isAmbiguousLeaseReason, a0 as isReplayableLeaseReason, a1 as isSettlementUnconfirmed, a2 as parseFacilitatorErrorBody, a3 as parseRetryAfterSeconds, a4 as readFacilitatorError, a5 as resolveEnvelopeVersion, a6 as toPaymentRequirementsV2, a7 as toResourceInfoV2, a8 as wagmiLifecycleSigner } from './index-4_LWWlyF.js';
8
8
 
9
9
  /**
10
10
  * DX402 `durable-evidence`: recover a paid response after the fact.
package/dist/index.js CHANGED
@@ -4469,6 +4469,214 @@ async function buildEscrowPreAuth(wallet, params) {
4469
4469
  });
4470
4470
  }
4471
4471
 
4472
+ // src/lifecycle-auth.ts
4473
+ init_types();
4474
+ var LIFECYCLE_DOMAIN_NAME = "x402 escrow lifecycle";
4475
+ var LIFECYCLE_DOMAIN_VERSION = "1";
4476
+ var LIFECYCLE_MAX_DEADLINE_SECS = 900;
4477
+ var LIFECYCLE_DEFAULT_DEADLINE_SECS = 600;
4478
+ var LIFECYCLE_ACTIONS = ["release", "refundInEscrow"];
4479
+ var LIFECYCLE_ORDER_TYPES = {
4480
+ LifecycleOrder: [
4481
+ { name: "action", type: "string" },
4482
+ { name: "amount", type: "uint256" },
4483
+ { name: "deadline", type: "uint256" },
4484
+ { name: "nonce", type: "bytes32" },
4485
+ { name: "paymentInfo", type: "PaymentInfo" }
4486
+ ],
4487
+ PaymentInfo: [
4488
+ { name: "operator", type: "address" },
4489
+ { name: "payer", type: "address" },
4490
+ { name: "receiver", type: "address" },
4491
+ { name: "token", type: "address" },
4492
+ { name: "maxAmount", type: "uint120" },
4493
+ { name: "preApprovalExpiry", type: "uint48" },
4494
+ { name: "authorizationExpiry", type: "uint48" },
4495
+ { name: "refundExpiry", type: "uint48" },
4496
+ { name: "minFeeBps", type: "uint16" },
4497
+ { name: "maxFeeBps", type: "uint16" },
4498
+ { name: "feeReceiver", type: "address" },
4499
+ { name: "salt", type: "uint256" }
4500
+ ]
4501
+ };
4502
+ var LIFECYCLE_PI_KEYS = [
4503
+ "operator",
4504
+ "receiver",
4505
+ "token",
4506
+ "maxAmount",
4507
+ "preApprovalExpiry",
4508
+ "authorizationExpiry",
4509
+ "refundExpiry",
4510
+ "minFeeBps",
4511
+ "maxFeeBps",
4512
+ "feeReceiver",
4513
+ "salt"
4514
+ ];
4515
+ function saltToBigInt(salt) {
4516
+ if (typeof salt === "bigint") return salt;
4517
+ if (typeof salt === "number") {
4518
+ if (!Number.isInteger(salt) || salt < 0) {
4519
+ throw new exports.X402Error(`paymentInfo.salt invalid: ${String(salt)}`, "INVALID_CONFIG");
4520
+ }
4521
+ return BigInt(salt);
4522
+ }
4523
+ if (typeof salt === "string") {
4524
+ const trimmed = salt.trim();
4525
+ const hex = trimmed.startsWith("0x") || trimmed.startsWith("0X") ? trimmed : `0x${trimmed}`;
4526
+ try {
4527
+ return BigInt(hex);
4528
+ } catch {
4529
+ throw new exports.X402Error(`paymentInfo.salt invalid: ${salt}`, "INVALID_CONFIG");
4530
+ }
4531
+ }
4532
+ throw new exports.X402Error(`paymentInfo.salt invalid: ${String(salt)}`, "INVALID_CONFIG");
4533
+ }
4534
+ function nonceToBytes32(nonce) {
4535
+ if (typeof nonce !== "string") {
4536
+ throw new exports.X402Error(`lifecycleAuth.nonce invalid: ${String(nonce)}`, "INVALID_CONFIG");
4537
+ }
4538
+ const raw = nonce.startsWith("0x") || nonce.startsWith("0X") ? nonce.slice(2) : nonce;
4539
+ if (!/^[0-9a-fA-F]*$/.test(raw)) {
4540
+ throw new exports.X402Error(`lifecycleAuth.nonce is not hex: ${nonce}`, "INVALID_CONFIG");
4541
+ }
4542
+ if (raw.length !== 64) {
4543
+ throw new exports.X402Error(
4544
+ `lifecycleAuth.nonce must be 32 bytes, got ${raw.length / 2}`,
4545
+ "INVALID_CONFIG"
4546
+ );
4547
+ }
4548
+ return `0x${raw.toLowerCase()}`;
4549
+ }
4550
+ function randomNonce() {
4551
+ const webCrypto = globalThis.crypto;
4552
+ if (webCrypto?.getRandomValues) {
4553
+ const bytes = new Uint8Array(32);
4554
+ webCrypto.getRandomValues(bytes);
4555
+ return ethers.ethers.hexlify(bytes);
4556
+ }
4557
+ return ethers.ethers.hexlify(ethers.ethers.randomBytes(32));
4558
+ }
4559
+ function toUintString(value, field) {
4560
+ let n;
4561
+ try {
4562
+ n = typeof value === "bigint" ? value : BigInt(value);
4563
+ } catch {
4564
+ throw new exports.X402Error(`${field} must be a non-negative integer, got ${String(value)}`, "INVALID_CONFIG");
4565
+ }
4566
+ if (n < 0n) {
4567
+ throw new exports.X402Error(`${field} must be a non-negative integer, got ${String(value)}`, "INVALID_CONFIG");
4568
+ }
4569
+ return n.toString();
4570
+ }
4571
+ function buildLifecycleTypedData(params) {
4572
+ const { action, paymentInfo, payer, amount, chainId, deadline, nonce } = params;
4573
+ if (!LIFECYCLE_ACTIONS.includes(action)) {
4574
+ throw new exports.X402Error(
4575
+ `unknown lifecycle action ${String(action)}; the facilitator only signs ${LIFECYCLE_ACTIONS.join(", ")}`,
4576
+ "INVALID_CONFIG"
4577
+ );
4578
+ }
4579
+ let amountBig;
4580
+ try {
4581
+ amountBig = typeof amount === "bigint" ? amount : BigInt(amount);
4582
+ } catch {
4583
+ throw new exports.X402Error(`amount must be an integer >= 0, got ${String(amount)}`, "INVALID_AMOUNT");
4584
+ }
4585
+ if (amountBig < 0n) {
4586
+ throw new exports.X402Error(`amount must be an integer >= 0, got ${String(amount)}`, "INVALID_AMOUNT");
4587
+ }
4588
+ const pi = paymentInfo ?? {};
4589
+ const missing = LIFECYCLE_PI_KEYS.filter((k) => pi[k] === void 0);
4590
+ if (missing.length > 0) {
4591
+ throw new exports.X402Error(
4592
+ `paymentInfo is missing fields that enter the signature: ${missing.join(", ")}. The paymentInfo that is SENT is the one that is signed; defaulting a field would sign a different struct than the one that reaches the facilitator.`,
4593
+ "INVALID_CONFIG"
4594
+ );
4595
+ }
4596
+ return {
4597
+ domain: {
4598
+ name: LIFECYCLE_DOMAIN_NAME,
4599
+ version: LIFECYCLE_DOMAIN_VERSION,
4600
+ chainId: Number(chainId)
4601
+ },
4602
+ types: LIFECYCLE_ORDER_TYPES,
4603
+ primaryType: "LifecycleOrder",
4604
+ message: {
4605
+ action,
4606
+ amount: amountBig.toString(),
4607
+ deadline: toUintString(deadline, "deadline"),
4608
+ nonce: nonceToBytes32(nonce),
4609
+ paymentInfo: {
4610
+ operator: ethers.ethers.getAddress(paymentInfo.operator),
4611
+ payer: ethers.ethers.getAddress(payer),
4612
+ receiver: ethers.ethers.getAddress(paymentInfo.receiver),
4613
+ token: ethers.ethers.getAddress(paymentInfo.token),
4614
+ maxAmount: toUintString(paymentInfo.maxAmount, "paymentInfo.maxAmount"),
4615
+ preApprovalExpiry: toUintString(paymentInfo.preApprovalExpiry, "paymentInfo.preApprovalExpiry"),
4616
+ authorizationExpiry: toUintString(
4617
+ paymentInfo.authorizationExpiry,
4618
+ "paymentInfo.authorizationExpiry"
4619
+ ),
4620
+ refundExpiry: toUintString(paymentInfo.refundExpiry, "paymentInfo.refundExpiry"),
4621
+ minFeeBps: toUintString(paymentInfo.minFeeBps, "paymentInfo.minFeeBps"),
4622
+ maxFeeBps: toUintString(paymentInfo.maxFeeBps, "paymentInfo.maxFeeBps"),
4623
+ feeReceiver: ethers.ethers.getAddress(paymentInfo.feeReceiver),
4624
+ // uint256 in the signature, bytes32 on the wire — see saltToBigInt.
4625
+ salt: saltToBigInt(paymentInfo.salt).toString()
4626
+ }
4627
+ }
4628
+ };
4629
+ }
4630
+ async function buildLifecycleAuth(params) {
4631
+ const { wallet, deadline, nonce, now, ...rest } = params;
4632
+ const nowSec = now === void 0 ? Math.floor(Date.now() / 1e3) : Math.floor(now);
4633
+ const dl = deadline === void 0 ? nowSec + LIFECYCLE_DEFAULT_DEADLINE_SECS : Math.floor(deadline);
4634
+ const nonceHex = nonce === void 0 ? randomNonce() : nonce;
4635
+ if (dl < nowSec) {
4636
+ throw new exports.X402Error(
4637
+ `deadline ${dl} is in the past (now ${nowSec}): the facilitator discards it as \`expired\``,
4638
+ "INVALID_CONFIG"
4639
+ );
4640
+ }
4641
+ if (dl - nowSec > LIFECYCLE_MAX_DEADLINE_SECS) {
4642
+ throw new exports.X402Error(
4643
+ `deadline ${dl} is ${dl - nowSec} s ahead and the facilitator's ceiling is ${LIFECYCLE_MAX_DEADLINE_SECS} s (\`deadline_too_far\`): a leaked order cannot be a standing permission`,
4644
+ "INVALID_CONFIG"
4645
+ );
4646
+ }
4647
+ const typed = buildLifecycleTypedData({ ...rest, deadline: dl, nonce: nonceHex });
4648
+ const signed = await wallet.signTypedData(JSON.stringify(typed));
4649
+ return {
4650
+ signer: wallet.getAddress(),
4651
+ deadline: dl,
4652
+ nonce: nonceToBytes32(nonceHex),
4653
+ signature: signed.signature
4654
+ };
4655
+ }
4656
+ function wagmiLifecycleSigner(walletClient, address) {
4657
+ const account = address ?? walletClient.account?.address;
4658
+ if (!account) {
4659
+ throw new exports.X402Error(
4660
+ "wagmiLifecycleSigner needs an account: pass one, or connect the wallet client first",
4661
+ "INVALID_CONFIG"
4662
+ );
4663
+ }
4664
+ const checksummed = ethers.ethers.getAddress(account);
4665
+ return {
4666
+ getAddress: () => checksummed,
4667
+ async signTypedData(typedData) {
4668
+ const parsed = JSON.parse(typedData);
4669
+ const signature = await walletClient.signTypedData({
4670
+ domain: parsed.domain,
4671
+ types: parsed.types,
4672
+ primaryType: parsed.primaryType,
4673
+ message: parsed.message
4674
+ });
4675
+ return { signature };
4676
+ }
4677
+ };
4678
+ }
4679
+
4472
4680
  // src/backend/index.ts
4473
4681
  init_utils();
4474
4682
  init_chains();
@@ -5581,6 +5789,12 @@ exports.EvidenceSkipped = EvidenceSkipped;
5581
5789
  exports.FACILITATOR_ADDRESSES = FACILITATOR_ADDRESSES;
5582
5790
  exports.FacilitatorClient = FacilitatorClient;
5583
5791
  exports.KEEPALIVE_INTERVAL_MS = KEEPALIVE_INTERVAL_MS;
5792
+ exports.LIFECYCLE_ACTIONS = LIFECYCLE_ACTIONS;
5793
+ exports.LIFECYCLE_DEFAULT_DEADLINE_SECS = LIFECYCLE_DEFAULT_DEADLINE_SECS;
5794
+ exports.LIFECYCLE_DOMAIN_NAME = LIFECYCLE_DOMAIN_NAME;
5795
+ exports.LIFECYCLE_DOMAIN_VERSION = LIFECYCLE_DOMAIN_VERSION;
5796
+ exports.LIFECYCLE_MAX_DEADLINE_SECS = LIFECYCLE_MAX_DEADLINE_SECS;
5797
+ exports.LIFECYCLE_ORDER_TYPES = LIFECYCLE_ORDER_TYPES;
5584
5798
  exports.MAX_PROTOCOL_FEE_BPS = MAX_PROTOCOL_FEE_BPS;
5585
5799
  exports.MAX_RETRY_AFTER_SECONDS = MAX_RETRY_AFTER_SECONDS;
5586
5800
  exports.OPERATOR_FEE_BPS = OPERATOR_FEE_BPS;
@@ -5599,6 +5813,8 @@ exports.anchorDigest = anchorDigest;
5599
5813
  exports.anchorEvidence = anchorEvidence;
5600
5814
  exports.availableBackends = availableBackends;
5601
5815
  exports.buildEscrowPreAuth = buildEscrowPreAuth;
5816
+ exports.buildLifecycleAuth = buildLifecycleAuth;
5817
+ exports.buildLifecycleTypedData = buildLifecycleTypedData;
5602
5818
  exports.buildPaymentRequirements = buildPaymentRequirements;
5603
5819
  exports.buildSettleRequest = buildSettleRequest;
5604
5820
  exports.buildSettleRequestForVersion = buildSettleRequestForVersion;
@@ -5701,6 +5917,7 @@ exports.toResourceInfoV2 = toResourceInfoV2;
5701
5917
  exports.unseal = unseal;
5702
5918
  exports.validateAmount = validateAmount;
5703
5919
  exports.validateRecipient = validateRecipient;
5920
+ exports.wagmiLifecycleSigner = wagmiLifecycleSigner;
5704
5921
  exports.wrapSignature = wrapSignature;
5705
5922
  //# sourceMappingURL=index.js.map
5706
5923
  //# sourceMappingURL=index.js.map