@wtflabs/x402 0.0.1-beta.5 → 0.0.1-beta.6

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.
@@ -1895,6 +1895,264 @@ var import_compute_budget2 = require("@solana-program/compute-budget");
1895
1895
  // src/schemes/exact/index.ts
1896
1896
  var SCHEME = "exact";
1897
1897
 
1898
+ // src/types/shared/evm/permitProxyABI.ts
1899
+ var permitProxyContractABI = [
1900
+ // settleWithPermit - 使用 EIP-2612 Permit 进行结算
1901
+ {
1902
+ inputs: [
1903
+ {
1904
+ internalType: "address",
1905
+ name: "token",
1906
+ type: "address"
1907
+ },
1908
+ {
1909
+ internalType: "address",
1910
+ name: "payer",
1911
+ type: "address"
1912
+ },
1913
+ {
1914
+ internalType: "address",
1915
+ name: "seller",
1916
+ type: "address"
1917
+ },
1918
+ {
1919
+ internalType: "uint256",
1920
+ name: "amount",
1921
+ type: "uint256"
1922
+ },
1923
+ {
1924
+ internalType: "uint256",
1925
+ name: "deadline",
1926
+ type: "uint256"
1927
+ },
1928
+ {
1929
+ internalType: "uint8",
1930
+ name: "v",
1931
+ type: "uint8"
1932
+ },
1933
+ {
1934
+ internalType: "bytes32",
1935
+ name: "r",
1936
+ type: "bytes32"
1937
+ },
1938
+ {
1939
+ internalType: "bytes32",
1940
+ name: "s",
1941
+ type: "bytes32"
1942
+ }
1943
+ ],
1944
+ name: "settleWithPermit",
1945
+ outputs: [],
1946
+ stateMutability: "nonpayable",
1947
+ type: "function"
1948
+ },
1949
+ // settleWithERC3009 - 使用 EIP-3009 TransferWithAuthorization 进行结算
1950
+ {
1951
+ inputs: [
1952
+ {
1953
+ internalType: "address",
1954
+ name: "token",
1955
+ type: "address"
1956
+ },
1957
+ {
1958
+ internalType: "address",
1959
+ name: "payer",
1960
+ type: "address"
1961
+ },
1962
+ {
1963
+ internalType: "address",
1964
+ name: "seller",
1965
+ type: "address"
1966
+ },
1967
+ {
1968
+ internalType: "uint256",
1969
+ name: "amount",
1970
+ type: "uint256"
1971
+ },
1972
+ {
1973
+ internalType: "uint256",
1974
+ name: "validAfter",
1975
+ type: "uint256"
1976
+ },
1977
+ {
1978
+ internalType: "uint256",
1979
+ name: "validBefore",
1980
+ type: "uint256"
1981
+ },
1982
+ {
1983
+ internalType: "bytes32",
1984
+ name: "nonce",
1985
+ type: "bytes32"
1986
+ },
1987
+ {
1988
+ internalType: "uint8",
1989
+ name: "v",
1990
+ type: "uint8"
1991
+ },
1992
+ {
1993
+ internalType: "bytes32",
1994
+ name: "r",
1995
+ type: "bytes32"
1996
+ },
1997
+ {
1998
+ internalType: "bytes32",
1999
+ name: "s",
2000
+ type: "bytes32"
2001
+ }
2002
+ ],
2003
+ name: "settleWithERC3009",
2004
+ outputs: [],
2005
+ stateMutability: "nonpayable",
2006
+ type: "function"
2007
+ },
2008
+ // settleWithERC3009Direct - 直接结算(无手续费)
2009
+ {
2010
+ inputs: [
2011
+ {
2012
+ internalType: "address",
2013
+ name: "token",
2014
+ type: "address"
2015
+ },
2016
+ {
2017
+ internalType: "address",
2018
+ name: "payer",
2019
+ type: "address"
2020
+ },
2021
+ {
2022
+ internalType: "address",
2023
+ name: "seller",
2024
+ type: "address"
2025
+ },
2026
+ {
2027
+ internalType: "uint256",
2028
+ name: "amount",
2029
+ type: "uint256"
2030
+ },
2031
+ {
2032
+ internalType: "uint256",
2033
+ name: "validAfter",
2034
+ type: "uint256"
2035
+ },
2036
+ {
2037
+ internalType: "uint256",
2038
+ name: "validBefore",
2039
+ type: "uint256"
2040
+ },
2041
+ {
2042
+ internalType: "bytes32",
2043
+ name: "nonce",
2044
+ type: "bytes32"
2045
+ },
2046
+ {
2047
+ internalType: "uint8",
2048
+ name: "v",
2049
+ type: "uint8"
2050
+ },
2051
+ {
2052
+ internalType: "bytes32",
2053
+ name: "r",
2054
+ type: "bytes32"
2055
+ },
2056
+ {
2057
+ internalType: "bytes32",
2058
+ name: "s",
2059
+ type: "bytes32"
2060
+ }
2061
+ ],
2062
+ name: "settleWithERC3009Direct",
2063
+ outputs: [],
2064
+ stateMutability: "nonpayable",
2065
+ type: "function"
2066
+ },
2067
+ // Events
2068
+ {
2069
+ anonymous: false,
2070
+ inputs: [
2071
+ {
2072
+ indexed: true,
2073
+ internalType: "address",
2074
+ name: "token",
2075
+ type: "address"
2076
+ },
2077
+ {
2078
+ indexed: true,
2079
+ internalType: "address",
2080
+ name: "payer",
2081
+ type: "address"
2082
+ },
2083
+ {
2084
+ indexed: true,
2085
+ internalType: "address",
2086
+ name: "seller",
2087
+ type: "address"
2088
+ },
2089
+ {
2090
+ indexed: false,
2091
+ internalType: "uint256",
2092
+ name: "amount",
2093
+ type: "uint256"
2094
+ },
2095
+ {
2096
+ indexed: false,
2097
+ internalType: "uint256",
2098
+ name: "sellerAmount",
2099
+ type: "uint256"
2100
+ },
2101
+ {
2102
+ indexed: false,
2103
+ internalType: "uint256",
2104
+ name: "feeAmount",
2105
+ type: "uint256"
2106
+ },
2107
+ {
2108
+ indexed: false,
2109
+ internalType: "string",
2110
+ name: "path",
2111
+ type: "string"
2112
+ }
2113
+ ],
2114
+ name: "SettledSplit",
2115
+ type: "event"
2116
+ },
2117
+ {
2118
+ anonymous: false,
2119
+ inputs: [
2120
+ {
2121
+ indexed: true,
2122
+ internalType: "address",
2123
+ name: "token",
2124
+ type: "address"
2125
+ },
2126
+ {
2127
+ indexed: true,
2128
+ internalType: "address",
2129
+ name: "payer",
2130
+ type: "address"
2131
+ },
2132
+ {
2133
+ indexed: true,
2134
+ internalType: "address",
2135
+ name: "seller",
2136
+ type: "address"
2137
+ },
2138
+ {
2139
+ indexed: false,
2140
+ internalType: "uint256",
2141
+ name: "amount",
2142
+ type: "uint256"
2143
+ },
2144
+ {
2145
+ indexed: false,
2146
+ internalType: "string",
2147
+ name: "path",
2148
+ type: "string"
2149
+ }
2150
+ ],
2151
+ name: "SettledDirect",
2152
+ type: "event"
2153
+ }
2154
+ ];
2155
+
1898
2156
  // src/schemes/exact/evm/eip3009/facilitator.ts
1899
2157
  async function verify2(client, payload, paymentRequirements) {
1900
2158
  const exactEvmPayload = payload.payload;
@@ -1959,7 +2217,7 @@ async function verify2(client, payload, paymentRequirements) {
1959
2217
  payer: exactEvmPayload.authorization.from
1960
2218
  };
1961
2219
  }
1962
- if ((0, import_viem2.getAddress)(exactEvmPayload.authorization.to) !== (0, import_viem2.getAddress)(paymentRequirements.payTo)) {
2220
+ if ((0, import_viem2.getAddress)(exactEvmPayload.authorization.to) !== (0, import_viem2.getAddress)(paymentRequirements.payTo) && (0, import_viem2.getAddress)(exactEvmPayload.authorization.to) !== (0, import_viem2.getAddress)(paymentRequirements.extra?.relayer)) {
1963
2221
  return {
1964
2222
  isValid: false,
1965
2223
  invalidReason: "invalid_exact_evm_payload_recipient_mismatch",
@@ -2032,21 +2290,57 @@ async function settle2(wallet, paymentPayload, paymentRequirements) {
2032
2290
  };
2033
2291
  }
2034
2292
  const { signature } = (0, import_viem2.parseErc6492Signature)(payload.signature);
2035
- const tx = await wallet.writeContract({
2036
- address: paymentRequirements.asset,
2037
- abi: usdcABI,
2038
- functionName: "transferWithAuthorization",
2039
- args: [
2040
- payload.authorization.from,
2041
- payload.authorization.to,
2042
- BigInt(payload.authorization.value),
2043
- BigInt(payload.authorization.validAfter),
2044
- BigInt(payload.authorization.validBefore),
2045
- payload.authorization.nonce,
2046
- signature
2047
- ],
2048
- chain: wallet.chain
2049
- });
2293
+ let tx;
2294
+ if (paymentRequirements.extra?.relayer) {
2295
+ const sig = (0, import_viem2.hexToSignature)(signature);
2296
+ const v = Number(sig.v);
2297
+ const r = sig.r;
2298
+ const s = sig.s;
2299
+ tx = await wallet.writeContract({
2300
+ address: paymentRequirements.extra.relayer,
2301
+ abi: permitProxyContractABI,
2302
+ functionName: "settleWithERC3009",
2303
+ args: [
2304
+ paymentRequirements.asset,
2305
+ // token
2306
+ payload.authorization.from,
2307
+ // payer
2308
+ payload.authorization.to,
2309
+ // seller
2310
+ BigInt(payload.authorization.value),
2311
+ // amount
2312
+ BigInt(payload.authorization.validAfter),
2313
+ // validAfter
2314
+ BigInt(payload.authorization.validBefore),
2315
+ // validBefore
2316
+ payload.authorization.nonce,
2317
+ // nonce
2318
+ v,
2319
+ // v (uint8)
2320
+ r,
2321
+ // r (bytes32)
2322
+ s
2323
+ // s (bytes32)
2324
+ ],
2325
+ chain: wallet.chain
2326
+ });
2327
+ } else {
2328
+ tx = await wallet.writeContract({
2329
+ address: paymentRequirements.asset,
2330
+ abi: usdcABI,
2331
+ functionName: "transferWithAuthorization",
2332
+ args: [
2333
+ payload.authorization.from,
2334
+ payload.authorization.to,
2335
+ BigInt(payload.authorization.value),
2336
+ BigInt(payload.authorization.validAfter),
2337
+ BigInt(payload.authorization.validBefore),
2338
+ payload.authorization.nonce,
2339
+ signature
2340
+ ],
2341
+ chain: wallet.chain
2342
+ });
2343
+ }
2050
2344
  const receipt = await wallet.waitForTransactionReceipt({ hash: tx });
2051
2345
  if (receipt.status !== "success") {
2052
2346
  return {
@@ -2082,63 +2376,6 @@ function splitSignature(signature) {
2082
2376
  return { v, r, s };
2083
2377
  }
2084
2378
 
2085
- // src/types/shared/evm/permitProxyABI.ts
2086
- var permitProxyContractABI = [
2087
- {
2088
- inputs: [
2089
- {
2090
- internalType: "address",
2091
- name: "token",
2092
- type: "address"
2093
- },
2094
- {
2095
- internalType: "address",
2096
- name: "owner",
2097
- type: "address"
2098
- },
2099
- {
2100
- internalType: "address",
2101
- name: "spender",
2102
- type: "address"
2103
- },
2104
- {
2105
- internalType: "uint256",
2106
- name: "value",
2107
- type: "uint256"
2108
- },
2109
- {
2110
- internalType: "uint256",
2111
- name: "deadline",
2112
- type: "uint256"
2113
- },
2114
- {
2115
- internalType: "uint8",
2116
- name: "v",
2117
- type: "uint8"
2118
- },
2119
- {
2120
- internalType: "bytes32",
2121
- name: "r",
2122
- type: "bytes32"
2123
- },
2124
- {
2125
- internalType: "bytes32",
2126
- name: "s",
2127
- type: "bytes32"
2128
- },
2129
- {
2130
- internalType: "address",
2131
- name: "to",
2132
- type: "address"
2133
- }
2134
- ],
2135
- name: "permitAndTransfer",
2136
- outputs: [],
2137
- stateMutability: "nonpayable",
2138
- type: "function"
2139
- }
2140
- ];
2141
-
2142
2379
  // src/schemes/exact/evm/permit/facilitator.ts
2143
2380
  async function verify3(client, payload, paymentRequirements) {
2144
2381
  if (payload.payload.authorizationType !== "permit" || payload.scheme !== SCHEME || paymentRequirements.scheme !== SCHEME) {
@@ -2206,8 +2443,8 @@ async function verify3(client, payload, paymentRequirements) {
2206
2443
  payer: owner
2207
2444
  };
2208
2445
  }
2209
- if (paymentRequirements.extra?.proxyAddress) {
2210
- if ((0, import_viem4.getAddress)(spender) !== (0, import_viem4.getAddress)(paymentRequirements.extra?.proxyAddress)) {
2446
+ if (paymentRequirements.extra?.relayer) {
2447
+ if ((0, import_viem4.getAddress)(spender) !== (0, import_viem4.getAddress)(paymentRequirements.extra?.relayer)) {
2211
2448
  return {
2212
2449
  isValid: false,
2213
2450
  invalidReason: "invalid_spender_address",
@@ -2271,21 +2508,28 @@ async function settle3(wallet, paymentPayload, paymentRequirements) {
2271
2508
  address: wallet.account.address
2272
2509
  });
2273
2510
  let transactionHash;
2274
- if (paymentRequirements.extra?.proxyAddress) {
2511
+ if (paymentRequirements.extra?.relayer) {
2275
2512
  transactionHash = await wallet.writeContract({
2276
- address: paymentRequirements.extra.proxyAddress,
2513
+ address: paymentRequirements.extra.relayer,
2277
2514
  abi: permitProxyContractABI,
2278
- functionName: "permitAndTransfer",
2515
+ functionName: "settleWithPermit",
2279
2516
  args: [
2280
2517
  tokenAddress,
2518
+ // token
2281
2519
  owner,
2282
- spender,
2520
+ // payer
2521
+ paymentRequirements.payTo,
2522
+ // seller
2283
2523
  BigInt(value),
2524
+ // amount
2284
2525
  BigInt(deadline),
2526
+ // deadline
2285
2527
  v,
2528
+ // v
2286
2529
  r,
2287
- s,
2288
- paymentRequirements.payTo
2530
+ // r
2531
+ s
2532
+ // s
2289
2533
  ],
2290
2534
  chain: wallet.chain,
2291
2535
  nonce: txNonce