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