uvd-x402-sdk 2.31.1 → 2.32.2

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 CHANGED
@@ -48,7 +48,85 @@ npm install @mysten/sui
48
48
 
49
49
  ## Quick Start
50
50
 
51
- ### EVM Chains
51
+ ### Server + Client (Private Key)
52
+
53
+ The fastest way to get up and running. No browser wallet needed — works in Node.js, scripts, and agents.
54
+
55
+ **.env**
56
+
57
+ ```bash
58
+ RECEIVING_ADDRESS=0xYourWalletAddress
59
+ PRIVATE_KEY=0xYourPrivateKey
60
+ ```
61
+
62
+ **Server (Hono)**
63
+
64
+ ```bash
65
+ npm install hono @hono/node-server uvd-x402-sdk dotenv
66
+ ```
67
+
68
+ ```typescript
69
+ import { Hono } from 'hono';
70
+ import { serve } from '@hono/node-server';
71
+ import { createHonoMiddleware } from 'uvd-x402-sdk';
72
+ import 'dotenv/config';
73
+
74
+ const app = new Hono();
75
+ const receiver = process.env.RECEIVING_ADDRESS as string;
76
+
77
+ // x402 payment middleware — handles 402, verify, and settle automatically
78
+ const paywall = createHonoMiddleware({
79
+ accepts: [{
80
+ network: 'skale-base',
81
+ asset: '0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20',
82
+ amount: '1000000', // $1.00 USDC.e (6 decimals)
83
+ payTo: receiver,
84
+ extra: {
85
+ name: 'Bridged USDC (SKALE Bridge)',
86
+ version: '2',
87
+ },
88
+ }],
89
+ });
90
+
91
+ app.get('/api/free', (c) => c.json({ message: 'This endpoint is free!' }));
92
+
93
+ app.get('/api/premium', paywall, (c) => {
94
+ return c.json({ message: 'Payment verified and settled!', timestamp: new Date().toISOString() });
95
+ });
96
+
97
+ serve({ fetch: app.fetch, port: 3000 });
98
+ console.log('Server running on http://localhost:3000');
99
+ ```
100
+
101
+ **Client (Private Key)**
102
+
103
+ ```bash
104
+ npm install uvd-x402-sdk ethers dotenv
105
+ ```
106
+
107
+ ```typescript
108
+ import { X402Client } from 'uvd-x402-sdk';
109
+ import 'dotenv/config';
110
+
111
+ const client = new X402Client({ defaultChain: 'skale-base' });
112
+ await client.connectWithPrivateKey(process.env.PRIVATE_KEY as string);
113
+
114
+ const result = await client.createPayment({
115
+ recipient: process.env.RECEIVING_ADDRESS as string,
116
+ amount: '1.00',
117
+ });
118
+
119
+ const response = await fetch('http://localhost:3000/api/premium', {
120
+ headers: { 'X-PAYMENT': result.paymentHeader },
121
+ });
122
+
123
+ const data = await response.json();
124
+ console.log('Response:', data);
125
+ ```
126
+
127
+ This example uses SKALE Base (zero gas costs). Replace `network`, `asset`, and `extra` to use any supported chain — see [Supported Networks](#supported-networks).
128
+
129
+ ### EVM Chains (Browser Wallet)
52
130
 
53
131
  ```typescript
54
132
  import { X402Client } from 'uvd-x402-sdk';
@@ -1937,6 +1937,11 @@ interface AdvancedEscrowClientOptions {
1937
1937
  * (AUTHORIZE goes through the facilitator, not directly on-chain)
1938
1938
  */
1939
1939
  declare const OPERATOR_ABI: string[];
1940
+ /**
1941
+ * CREATE3-deployed operators (SKALE, future chains) use updated ABI with extra `bytes data` param
1942
+ * on release() and refundInEscrow(). Pass empty bytes (0x) for the data parameter.
1943
+ */
1944
+ declare const OPERATOR_ABI_CREATE3: string[];
1940
1945
  /**
1941
1946
  * AdvancedEscrowClient provides the 5 Advanced Escrow flows via the
1942
1947
  * PaymentOperator contract on 9 supported EVM networks.
@@ -2133,4 +2138,4 @@ declare class AdvancedEscrowClient {
2133
2138
  refundPostEscrow(paymentInfo: AdvancedPaymentInfo, amount?: string, tokenCollector?: string, collectorData?: string): Promise<AdvancedTransactionResult>;
2134
2139
  }
2135
2140
 
2136
- export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, BASE_MAINNET_CONTRACTS, type BazaarCategory, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarNetwork, type BazaarRegisterOptions, type BazaarResource, type BazaarToken, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, type HonoMiddlewareOptions, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, type MetadataEntryParam, OPERATOR_ABI, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type SettleRequest, type SettleResponse, type SettleResponseWithProof, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, canRefundEscrow, canReleaseEscrow, create402Response, createHonoMiddleware, createPaymentMiddleware, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
2141
+ export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, BASE_MAINNET_CONTRACTS, type BazaarCategory, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarNetwork, type BazaarRegisterOptions, type BazaarResource, type BazaarToken, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, type HonoMiddlewareOptions, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type SettleRequest, type SettleResponse, type SettleResponseWithProof, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, canRefundEscrow, canReleaseEscrow, create402Response, createHonoMiddleware, createPaymentMiddleware, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
@@ -1937,6 +1937,11 @@ interface AdvancedEscrowClientOptions {
1937
1937
  * (AUTHORIZE goes through the facilitator, not directly on-chain)
1938
1938
  */
1939
1939
  declare const OPERATOR_ABI: string[];
1940
+ /**
1941
+ * CREATE3-deployed operators (SKALE, future chains) use updated ABI with extra `bytes data` param
1942
+ * on release() and refundInEscrow(). Pass empty bytes (0x) for the data parameter.
1943
+ */
1944
+ declare const OPERATOR_ABI_CREATE3: string[];
1940
1945
  /**
1941
1946
  * AdvancedEscrowClient provides the 5 Advanced Escrow flows via the
1942
1947
  * PaymentOperator contract on 9 supported EVM networks.
@@ -2133,4 +2138,4 @@ declare class AdvancedEscrowClient {
2133
2138
  refundPostEscrow(paymentInfo: AdvancedPaymentInfo, amount?: string, tokenCollector?: string, collectorData?: string): Promise<AdvancedTransactionResult>;
2134
2139
  }
2135
2140
 
2136
- export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, BASE_MAINNET_CONTRACTS, type BazaarCategory, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarNetwork, type BazaarRegisterOptions, type BazaarResource, type BazaarToken, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, type HonoMiddlewareOptions, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, type MetadataEntryParam, OPERATOR_ABI, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type SettleRequest, type SettleResponse, type SettleResponseWithProof, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, canRefundEscrow, canReleaseEscrow, create402Response, createHonoMiddleware, createPaymentMiddleware, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
2141
+ export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, BASE_MAINNET_CONTRACTS, type BazaarCategory, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarNetwork, type BazaarRegisterOptions, type BazaarResource, type BazaarToken, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, type HonoMiddlewareOptions, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type SettleRequest, type SettleResponse, type SettleResponseWithProof, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, canRefundEscrow, canReleaseEscrow, create402Response, createHonoMiddleware, createPaymentMiddleware, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
@@ -3099,6 +3099,15 @@ var ESCROW_CONTRACTS = {
3099
3099
  protocolFeeConfig: "0xD979dBfBdA5f4b16AAF60Eaab32A44f352076838",
3100
3100
  refundRequest: "0xc1256Bb30bd0cdDa07D8C8Cf67a59105f2EA1b98",
3101
3101
  usdc: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85"
3102
+ },
3103
+ // SKALE Base (chain 1187947933) - CREATE3 deployment, operator via factory
3104
+ 1187947933: {
3105
+ operator: "0x28c23AE8f55aDe5Ea10a5353FC40418D0c1B3d33",
3106
+ escrow: "0xBC151792f80C0EB1973d56b0235e6bee2A60e245",
3107
+ tokenCollector: "0x9A12A116a44636F55c9e135189A1321Abcfe2f30",
3108
+ protocolFeeConfig: "0xf62788834C99B2E85a6891C0b46D1EB996f8f596",
3109
+ refundRequest: "0x69e9BF2b40Ed472b55E47e9D4205d93Ed673093F",
3110
+ usdc: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20"
3102
3111
  }
3103
3112
  };
3104
3113
  var BASE_MAINNET_CONTRACTS = ESCROW_CONTRACTS[8453];
@@ -3123,6 +3132,13 @@ var OPERATOR_ABI = [
3123
3132
  "function charge(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount, address tokenCollector, bytes collectorData)",
3124
3133
  "function refundPostEscrow(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount, address tokenCollector, bytes collectorData)"
3125
3134
  ];
3135
+ var OPERATOR_ABI_CREATE3 = [
3136
+ "function release(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount, bytes data)",
3137
+ "function refundInEscrow(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint120 amount, bytes data)",
3138
+ "function charge(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount, address tokenCollector, bytes collectorData)",
3139
+ "function refundPostEscrow(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount, address tokenCollector, bytes collectorData)"
3140
+ ];
3141
+ var CREATE3_CHAIN_IDS = /* @__PURE__ */ new Set([1187947933]);
3126
3142
  var AdvancedEscrowClient = class {
3127
3143
  facilitatorUrl;
3128
3144
  chainId;
@@ -3371,10 +3387,12 @@ var AdvancedEscrowClient = class {
3371
3387
  if (!this.payerAddress) await this.init();
3372
3388
  try {
3373
3389
  const { ethers } = await import('ethers');
3374
- const contract = new ethers.Contract(this.contracts.operator, OPERATOR_ABI, this.signer);
3390
+ const isCreate3 = CREATE3_CHAIN_IDS.has(this.chainId);
3391
+ const abi = isCreate3 ? OPERATOR_ABI_CREATE3 : OPERATOR_ABI;
3392
+ const contract = new ethers.Contract(this.contracts.operator, abi, this.signer);
3375
3393
  const amt = amount || paymentInfo.maxAmount;
3376
3394
  const tuple = this.buildTuple(paymentInfo);
3377
- const tx = await contract.release(tuple, amt, { gasLimit: this.gasLimit });
3395
+ const tx = isCreate3 ? await contract.release(tuple, amt, "0x", { gasLimit: this.gasLimit }) : await contract.release(tuple, amt, { gasLimit: this.gasLimit });
3378
3396
  const receipt = await tx.wait();
3379
3397
  return {
3380
3398
  success: receipt.status === 1,
@@ -3398,10 +3416,12 @@ var AdvancedEscrowClient = class {
3398
3416
  if (!this.payerAddress) await this.init();
3399
3417
  try {
3400
3418
  const { ethers } = await import('ethers');
3401
- const contract = new ethers.Contract(this.contracts.operator, OPERATOR_ABI, this.signer);
3419
+ const isCreate3 = CREATE3_CHAIN_IDS.has(this.chainId);
3420
+ const abi = isCreate3 ? OPERATOR_ABI_CREATE3 : OPERATOR_ABI;
3421
+ const contract = new ethers.Contract(this.contracts.operator, abi, this.signer);
3402
3422
  const amt = amount || paymentInfo.maxAmount;
3403
3423
  const tuple = this.buildTuple(paymentInfo);
3404
- const tx = await contract.refundInEscrow(tuple, amt, { gasLimit: this.gasLimit });
3424
+ const tx = isCreate3 ? await contract.refundInEscrow(tuple, amt, "0x", { gasLimit: this.gasLimit }) : await contract.refundInEscrow(tuple, amt, { gasLimit: this.gasLimit });
3405
3425
  const receipt = await tx.wait();
3406
3426
  return {
3407
3427
  success: receipt.status === 1,
@@ -3755,6 +3775,7 @@ exports.Erc8004Client = Erc8004Client;
3755
3775
  exports.EscrowClient = EscrowClient;
3756
3776
  exports.FacilitatorClient = FacilitatorClient;
3757
3777
  exports.OPERATOR_ABI = OPERATOR_ABI;
3778
+ exports.OPERATOR_ABI_CREATE3 = OPERATOR_ABI_CREATE3;
3758
3779
  exports.PAYMENT_INFO_TYPEHASH = PAYMENT_INFO_TYPEHASH;
3759
3780
  exports.TIER_TIMINGS = TIER_TIMINGS;
3760
3781
  exports.USDC_DOMAIN_NAME = USDC_DOMAIN_NAME;