uvd-x402-sdk 2.16.2 → 2.17.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.
Files changed (57) hide show
  1. package/README.md +70 -5
  2. package/dist/adapters/index.js +103 -0
  3. package/dist/adapters/index.js.map +1 -1
  4. package/dist/adapters/index.mjs +103 -0
  5. package/dist/adapters/index.mjs.map +1 -1
  6. package/dist/backend/index.d.mts +392 -2
  7. package/dist/backend/index.d.ts +392 -2
  8. package/dist/backend/index.js +448 -0
  9. package/dist/backend/index.js.map +1 -1
  10. package/dist/backend/index.mjs +445 -1
  11. package/dist/backend/index.mjs.map +1 -1
  12. package/dist/{index-oE4dj05k.d.mts → index-BDLgm-Sg.d.mts} +3 -2
  13. package/dist/{index-B2cQzyKa.d.ts → index-DDrvK4em.d.ts} +3 -2
  14. package/dist/index.d.mts +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +103 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +103 -0
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/providers/algorand/index.js +103 -0
  21. package/dist/providers/algorand/index.js.map +1 -1
  22. package/dist/providers/algorand/index.mjs +103 -0
  23. package/dist/providers/algorand/index.mjs.map +1 -1
  24. package/dist/providers/evm/index.js +103 -0
  25. package/dist/providers/evm/index.js.map +1 -1
  26. package/dist/providers/evm/index.mjs +103 -0
  27. package/dist/providers/evm/index.mjs.map +1 -1
  28. package/dist/providers/near/index.js +103 -0
  29. package/dist/providers/near/index.js.map +1 -1
  30. package/dist/providers/near/index.mjs +103 -0
  31. package/dist/providers/near/index.mjs.map +1 -1
  32. package/dist/providers/solana/index.js +103 -0
  33. package/dist/providers/solana/index.js.map +1 -1
  34. package/dist/providers/solana/index.mjs +103 -0
  35. package/dist/providers/solana/index.mjs.map +1 -1
  36. package/dist/providers/stellar/index.js +103 -0
  37. package/dist/providers/stellar/index.js.map +1 -1
  38. package/dist/providers/stellar/index.mjs +103 -0
  39. package/dist/providers/stellar/index.mjs.map +1 -1
  40. package/dist/providers/sui/index.js +103 -0
  41. package/dist/providers/sui/index.js.map +1 -1
  42. package/dist/providers/sui/index.mjs +103 -0
  43. package/dist/providers/sui/index.mjs.map +1 -1
  44. package/dist/react/index.d.mts +1 -1
  45. package/dist/react/index.d.ts +1 -1
  46. package/dist/react/index.js +103 -0
  47. package/dist/react/index.js.map +1 -1
  48. package/dist/react/index.mjs +103 -0
  49. package/dist/react/index.mjs.map +1 -1
  50. package/dist/utils/index.js +103 -0
  51. package/dist/utils/index.js.map +1 -1
  52. package/dist/utils/index.mjs +103 -0
  53. package/dist/utils/index.mjs.map +1 -1
  54. package/package.json +9 -3
  55. package/src/backend/index.ts +695 -1
  56. package/src/chains/index.ts +102 -2
  57. package/src/types/index.ts +3 -0
@@ -13,6 +13,9 @@ var CAIP2_IDENTIFIERS = {
13
13
  hyperevm: "eip155:999",
14
14
  unichain: "eip155:130",
15
15
  monad: "eip155:143",
16
+ scroll: "eip155:534352",
17
+ skale: "eip155:1187947933",
18
+ "skale-testnet": "eip155:324705682",
16
19
  // SVM chains
17
20
  solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
18
21
  fogo: "svm:fogo",
@@ -438,6 +441,106 @@ var SUPPORTED_CHAINS = {
438
441
  enabled: true
439
442
  }
440
443
  },
444
+ scroll: {
445
+ chainId: 534352,
446
+ chainIdHex: "0x82750",
447
+ name: "scroll",
448
+ displayName: "Scroll",
449
+ networkType: "evm",
450
+ rpcUrl: "https://rpc.scroll.io",
451
+ explorerUrl: "https://scrollscan.com",
452
+ nativeCurrency: {
453
+ name: "Ethereum",
454
+ symbol: "ETH",
455
+ decimals: 18
456
+ },
457
+ usdc: {
458
+ address: "0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4",
459
+ decimals: 6,
460
+ name: "USD Coin",
461
+ version: "2"
462
+ },
463
+ tokens: {
464
+ usdc: {
465
+ address: "0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4",
466
+ decimals: 6,
467
+ name: "USD Coin",
468
+ version: "2"
469
+ }
470
+ },
471
+ x402: {
472
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
473
+ enabled: true
474
+ }
475
+ },
476
+ skale: {
477
+ chainId: 1187947933,
478
+ chainIdHex: "0x46cea59d",
479
+ name: "skale",
480
+ displayName: "SKALE",
481
+ networkType: "evm",
482
+ rpcUrl: "https://mainnet.skalenodes.com/v1/honorable-steel-rasalhague",
483
+ explorerUrl: "https://honorable-steel-rasalhague.explorer.mainnet.skalenodes.com",
484
+ nativeCurrency: {
485
+ name: "sFUEL",
486
+ symbol: "sFUEL",
487
+ decimals: 18
488
+ },
489
+ usdc: {
490
+ address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
491
+ decimals: 6,
492
+ name: "USDC",
493
+ // SKALE uses "USDC"
494
+ version: "2"
495
+ },
496
+ tokens: {
497
+ usdc: {
498
+ address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
499
+ decimals: 6,
500
+ name: "USDC",
501
+ // SKALE uses "USDC"
502
+ version: "2"
503
+ }
504
+ },
505
+ x402: {
506
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
507
+ enabled: true
508
+ }
509
+ },
510
+ "skale-testnet": {
511
+ chainId: 324705682,
512
+ chainIdHex: "0x135a9d92",
513
+ name: "skale-testnet",
514
+ displayName: "SKALE Testnet",
515
+ networkType: "evm",
516
+ rpcUrl: "https://testnet.skalenodes.com/v1/lanky-ill-funny-testnet",
517
+ explorerUrl: "https://lanky-ill-funny-testnet.explorer.testnet.skalenodes.com",
518
+ nativeCurrency: {
519
+ name: "sFUEL",
520
+ symbol: "sFUEL",
521
+ decimals: 18
522
+ },
523
+ usdc: {
524
+ address: "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
525
+ decimals: 6,
526
+ name: "USDC",
527
+ // SKALE testnet uses "USDC"
528
+ version: "2"
529
+ },
530
+ tokens: {
531
+ usdc: {
532
+ address: "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
533
+ decimals: 6,
534
+ name: "USDC",
535
+ // SKALE testnet uses "USDC"
536
+ version: "2"
537
+ }
538
+ },
539
+ x402: {
540
+ facilitatorUrl: DEFAULT_FACILITATOR_URL,
541
+ enabled: true
542
+ }
543
+ },
441
544
  // ============================================================================
442
545
  // SVM CHAINS (2 networks) - Solana Virtual Machine
443
546
  // ============================================================================
@@ -1797,12 +1900,357 @@ function isEscrowExpired(escrow) {
1797
1900
  function escrowTimeRemaining(escrow) {
1798
1901
  return new Date(escrow.expiresAt).getTime() - Date.now();
1799
1902
  }
1903
+ var ERC8004_EXTENSION_ID = "8004-reputation";
1904
+ var ERC8004_CONTRACTS = {
1905
+ ethereum: {
1906
+ identityRegistry: "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
1907
+ reputationRegistry: "0x8004BAa17C55a88189AE136b182e5fdA19dE9b63"
1908
+ },
1909
+ "ethereum-sepolia": {
1910
+ identityRegistry: "0x8004A818BFB912233c491871b3d84c89A494BD9e",
1911
+ reputationRegistry: "0x8004B663056A597Dffe9eCcC1965A193B7388713",
1912
+ validationRegistry: "0x8004Cb1BF31DAf7788923b405b754f57acEB4272"
1913
+ }
1914
+ };
1915
+ var Erc8004Client = class {
1916
+ baseUrl;
1917
+ timeout;
1918
+ constructor(options = {}) {
1919
+ this.baseUrl = options.baseUrl || "https://facilitator.ultravioletadao.xyz";
1920
+ this.timeout = options.timeout || 3e4;
1921
+ }
1922
+ /**
1923
+ * Get agent identity from the Identity Registry
1924
+ *
1925
+ * @param network - Network where agent is registered
1926
+ * @param agentId - Agent's tokenId
1927
+ * @returns Agent identity information
1928
+ */
1929
+ async getIdentity(network, agentId) {
1930
+ const url = `${this.baseUrl}/identity/${network}/${agentId}`;
1931
+ const controller = new AbortController();
1932
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
1933
+ try {
1934
+ const response = await fetch(url, {
1935
+ method: "GET",
1936
+ headers: { "Accept": "application/json" },
1937
+ signal: controller.signal
1938
+ });
1939
+ clearTimeout(timeoutId);
1940
+ if (!response.ok) {
1941
+ const errorText = await response.text();
1942
+ throw new Error(`ERC-8004 API error: ${response.status} - ${errorText}`);
1943
+ }
1944
+ return await response.json();
1945
+ } catch (error) {
1946
+ clearTimeout(timeoutId);
1947
+ throw error;
1948
+ }
1949
+ }
1950
+ /**
1951
+ * Resolve agent registration file from agentURI
1952
+ *
1953
+ * @param agentUri - URI pointing to agent registration file
1954
+ * @returns Resolved agent registration file
1955
+ */
1956
+ async resolveAgentUri(agentUri) {
1957
+ const controller = new AbortController();
1958
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
1959
+ try {
1960
+ let url = agentUri;
1961
+ if (agentUri.startsWith("ipfs://")) {
1962
+ const cid = agentUri.replace("ipfs://", "");
1963
+ url = `https://ipfs.io/ipfs/${cid}`;
1964
+ }
1965
+ const response = await fetch(url, {
1966
+ method: "GET",
1967
+ headers: { "Accept": "application/json" },
1968
+ signal: controller.signal
1969
+ });
1970
+ clearTimeout(timeoutId);
1971
+ if (!response.ok) {
1972
+ throw new Error(`Failed to resolve agentURI: ${response.status}`);
1973
+ }
1974
+ return await response.json();
1975
+ } catch (error) {
1976
+ clearTimeout(timeoutId);
1977
+ throw error;
1978
+ }
1979
+ }
1980
+ /**
1981
+ * Get agent reputation from the Reputation Registry
1982
+ *
1983
+ * @param network - Network where agent is registered
1984
+ * @param agentId - Agent's tokenId
1985
+ * @param options - Query options (tag filters, include individual feedback)
1986
+ * @returns Reputation summary and optionally individual feedback entries
1987
+ */
1988
+ async getReputation(network, agentId, options = {}) {
1989
+ const params = new URLSearchParams();
1990
+ if (options.tag1) params.set("tag1", options.tag1);
1991
+ if (options.tag2) params.set("tag2", options.tag2);
1992
+ if (options.includeFeedback) params.set("includeFeedback", "true");
1993
+ const url = `${this.baseUrl}/reputation/${network}/${agentId}${params.toString() ? `?${params}` : ""}`;
1994
+ const controller = new AbortController();
1995
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
1996
+ try {
1997
+ const response = await fetch(url, {
1998
+ method: "GET",
1999
+ headers: { "Accept": "application/json" },
2000
+ signal: controller.signal
2001
+ });
2002
+ clearTimeout(timeoutId);
2003
+ if (!response.ok) {
2004
+ const errorText = await response.text();
2005
+ throw new Error(`ERC-8004 API error: ${response.status} - ${errorText}`);
2006
+ }
2007
+ return await response.json();
2008
+ } catch (error) {
2009
+ clearTimeout(timeoutId);
2010
+ throw error;
2011
+ }
2012
+ }
2013
+ /**
2014
+ * Submit reputation feedback for an agent
2015
+ *
2016
+ * Requires proof of payment for authorized feedback submission.
2017
+ *
2018
+ * @param request - Feedback request with agent ID, value, and proof
2019
+ * @returns Feedback response with transaction hash
2020
+ *
2021
+ * @example
2022
+ * ```ts
2023
+ * // After settling a payment with ERC-8004 extension
2024
+ * const settleResult = await facilitator.settle(payment, {
2025
+ * ...requirements,
2026
+ * extra: { '8004-reputation': { includeProof: true } },
2027
+ * });
2028
+ *
2029
+ * // Submit feedback with proof of payment
2030
+ * const feedback = await erc8004.submitFeedback({
2031
+ * x402Version: 1,
2032
+ * network: 'ethereum',
2033
+ * feedback: {
2034
+ * agentId: 42,
2035
+ * value: 95, // 95/100
2036
+ * valueDecimals: 0,
2037
+ * tag1: 'quality',
2038
+ * tag2: 'response-time',
2039
+ * proof: settleResult.proofOfPayment,
2040
+ * },
2041
+ * });
2042
+ * ```
2043
+ */
2044
+ async submitFeedback(request) {
2045
+ const url = `${this.baseUrl}/feedback`;
2046
+ const controller = new AbortController();
2047
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
2048
+ try {
2049
+ const response = await fetch(url, {
2050
+ method: "POST",
2051
+ headers: {
2052
+ "Content-Type": "application/json",
2053
+ "Accept": "application/json"
2054
+ },
2055
+ body: JSON.stringify(request),
2056
+ signal: controller.signal
2057
+ });
2058
+ clearTimeout(timeoutId);
2059
+ if (!response.ok) {
2060
+ const errorText = await response.text();
2061
+ return {
2062
+ success: false,
2063
+ error: `Facilitator error: ${response.status} - ${errorText}`,
2064
+ network: request.network
2065
+ };
2066
+ }
2067
+ return await response.json();
2068
+ } catch (error) {
2069
+ clearTimeout(timeoutId);
2070
+ return {
2071
+ success: false,
2072
+ error: error instanceof Error ? error.message : "Unknown error",
2073
+ network: request.network
2074
+ };
2075
+ }
2076
+ }
2077
+ /**
2078
+ * Revoke previously submitted feedback
2079
+ *
2080
+ * Only the original submitter can revoke their feedback.
2081
+ *
2082
+ * @param network - Network where feedback was submitted
2083
+ * @param agentId - Agent ID
2084
+ * @param feedbackIndex - Index of feedback to revoke
2085
+ * @returns Revocation result
2086
+ */
2087
+ async revokeFeedback(network, agentId, feedbackIndex) {
2088
+ const url = `${this.baseUrl}/feedback/revoke`;
2089
+ const controller = new AbortController();
2090
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
2091
+ try {
2092
+ const response = await fetch(url, {
2093
+ method: "POST",
2094
+ headers: {
2095
+ "Content-Type": "application/json",
2096
+ "Accept": "application/json"
2097
+ },
2098
+ body: JSON.stringify({
2099
+ x402Version: 1,
2100
+ network,
2101
+ agentId,
2102
+ feedbackIndex
2103
+ }),
2104
+ signal: controller.signal
2105
+ });
2106
+ clearTimeout(timeoutId);
2107
+ if (!response.ok) {
2108
+ const errorText = await response.text();
2109
+ return {
2110
+ success: false,
2111
+ error: `Facilitator error: ${response.status} - ${errorText}`,
2112
+ network
2113
+ };
2114
+ }
2115
+ return await response.json();
2116
+ } catch (error) {
2117
+ clearTimeout(timeoutId);
2118
+ return {
2119
+ success: false,
2120
+ error: error instanceof Error ? error.message : "Unknown error",
2121
+ network
2122
+ };
2123
+ }
2124
+ }
2125
+ /**
2126
+ * Get ERC-8004 contract addresses for a network
2127
+ *
2128
+ * @param network - Network to get contracts for
2129
+ * @returns Contract addresses or undefined if not deployed
2130
+ */
2131
+ getContracts(network) {
2132
+ return ERC8004_CONTRACTS[network];
2133
+ }
2134
+ /**
2135
+ * Check if ERC-8004 is available on a network
2136
+ *
2137
+ * @param network - Network to check
2138
+ * @returns True if ERC-8004 contracts are deployed
2139
+ */
2140
+ isAvailable(network) {
2141
+ return network in ERC8004_CONTRACTS;
2142
+ }
2143
+ /**
2144
+ * Get feedback endpoint metadata
2145
+ *
2146
+ * @returns Endpoint information for /feedback
2147
+ */
2148
+ async getFeedbackMetadata() {
2149
+ const url = `${this.baseUrl}/feedback`;
2150
+ const controller = new AbortController();
2151
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
2152
+ try {
2153
+ const response = await fetch(url, {
2154
+ method: "GET",
2155
+ headers: { "Accept": "application/json" },
2156
+ signal: controller.signal
2157
+ });
2158
+ clearTimeout(timeoutId);
2159
+ if (!response.ok) {
2160
+ throw new Error(`Failed to get feedback metadata: ${response.status}`);
2161
+ }
2162
+ return await response.json();
2163
+ } catch (error) {
2164
+ clearTimeout(timeoutId);
2165
+ throw error;
2166
+ }
2167
+ }
2168
+ /**
2169
+ * Append a response to existing feedback
2170
+ *
2171
+ * Allows agents to respond to feedback they received.
2172
+ * Only the agent (identity owner) can append responses.
2173
+ *
2174
+ * @param network - Network where feedback was submitted
2175
+ * @param agentId - Agent ID
2176
+ * @param feedbackIndex - Index of feedback to respond to
2177
+ * @param response - Response content
2178
+ * @param responseUri - Optional URI to off-chain response file
2179
+ * @returns Response result
2180
+ *
2181
+ * @example
2182
+ * ```ts
2183
+ * // Agent responds to feedback
2184
+ * const result = await erc8004.appendResponse(
2185
+ * 'ethereum',
2186
+ * 42,
2187
+ * 1,
2188
+ * 'Thank you for your feedback! We have addressed the issue.',
2189
+ * );
2190
+ * ```
2191
+ */
2192
+ async appendResponse(network, agentId, feedbackIndex, response, responseUri) {
2193
+ const url = `${this.baseUrl}/feedback/response`;
2194
+ const controller = new AbortController();
2195
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
2196
+ try {
2197
+ const fetchResponse = await fetch(url, {
2198
+ method: "POST",
2199
+ headers: {
2200
+ "Content-Type": "application/json",
2201
+ "Accept": "application/json"
2202
+ },
2203
+ body: JSON.stringify({
2204
+ x402Version: 1,
2205
+ network,
2206
+ agentId,
2207
+ feedbackIndex,
2208
+ response,
2209
+ responseUri
2210
+ }),
2211
+ signal: controller.signal
2212
+ });
2213
+ clearTimeout(timeoutId);
2214
+ if (!fetchResponse.ok) {
2215
+ const errorText = await fetchResponse.text();
2216
+ return {
2217
+ success: false,
2218
+ error: `Facilitator error: ${fetchResponse.status} - ${errorText}`,
2219
+ network
2220
+ };
2221
+ }
2222
+ return await fetchResponse.json();
2223
+ } catch (error) {
2224
+ clearTimeout(timeoutId);
2225
+ return {
2226
+ success: false,
2227
+ error: error instanceof Error ? error.message : "Unknown error",
2228
+ network
2229
+ };
2230
+ }
2231
+ }
2232
+ };
2233
+ function buildErc8004PaymentRequirements(options) {
2234
+ const base = buildPaymentRequirements(options);
2235
+ return {
2236
+ ...base,
2237
+ extra: {
2238
+ [ERC8004_EXTENSION_ID]: {
2239
+ includeProof: true
2240
+ }
2241
+ }
2242
+ };
2243
+ }
1800
2244
 
1801
2245
  exports.BazaarClient = BazaarClient;
2246
+ exports.ERC8004_CONTRACTS = ERC8004_CONTRACTS;
2247
+ exports.ERC8004_EXTENSION_ID = ERC8004_EXTENSION_ID;
2248
+ exports.Erc8004Client = Erc8004Client;
1802
2249
  exports.EscrowClient = EscrowClient;
1803
2250
  exports.FacilitatorClient = FacilitatorClient;
1804
2251
  exports.X402_CORS_HEADERS = X402_CORS_HEADERS;
1805
2252
  exports.X402_HEADER_NAMES = X402_HEADER_NAMES;
2253
+ exports.buildErc8004PaymentRequirements = buildErc8004PaymentRequirements;
1806
2254
  exports.buildPaymentRequirements = buildPaymentRequirements;
1807
2255
  exports.buildSettleRequest = buildSettleRequest;
1808
2256
  exports.buildVerifyRequest = buildVerifyRequest;