@agirails/sdk 2.5.3 → 2.5.5

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 (169) hide show
  1. package/dist/ACTPClient.d.ts +18 -0
  2. package/dist/ACTPClient.d.ts.map +1 -1
  3. package/dist/ACTPClient.js +72 -23
  4. package/dist/ACTPClient.js.map +1 -1
  5. package/dist/adapters/BasicAdapter.d.ts +15 -0
  6. package/dist/adapters/BasicAdapter.d.ts.map +1 -1
  7. package/dist/adapters/BasicAdapter.js +33 -4
  8. package/dist/adapters/BasicAdapter.js.map +1 -1
  9. package/dist/adapters/StandardAdapter.d.ts +20 -3
  10. package/dist/adapters/StandardAdapter.d.ts.map +1 -1
  11. package/dist/adapters/StandardAdapter.js +90 -12
  12. package/dist/adapters/StandardAdapter.js.map +1 -1
  13. package/dist/cli/commands/publish.js +16 -4
  14. package/dist/cli/commands/publish.js.map +1 -1
  15. package/dist/cli/commands/register.js +16 -4
  16. package/dist/cli/commands/register.js.map +1 -1
  17. package/dist/cli/commands/tx.js +31 -3
  18. package/dist/cli/commands/tx.js.map +1 -1
  19. package/dist/config/networks.d.ts +10 -2
  20. package/dist/config/networks.d.ts.map +1 -1
  21. package/dist/config/networks.js +31 -22
  22. package/dist/config/networks.js.map +1 -1
  23. package/dist/level0/request.d.ts.map +1 -1
  24. package/dist/level0/request.js +2 -1
  25. package/dist/level0/request.js.map +1 -1
  26. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  27. package/dist/runtime/BlockchainRuntime.js +11 -5
  28. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  29. package/dist/utils/IPFSClient.d.ts +3 -1
  30. package/dist/utils/IPFSClient.d.ts.map +1 -1
  31. package/dist/utils/IPFSClient.js +27 -7
  32. package/dist/utils/IPFSClient.js.map +1 -1
  33. package/dist/wallet/AutoWalletProvider.d.ts +11 -1
  34. package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
  35. package/dist/wallet/AutoWalletProvider.js +84 -19
  36. package/dist/wallet/AutoWalletProvider.js.map +1 -1
  37. package/dist/wallet/IWalletProvider.d.ts +34 -0
  38. package/dist/wallet/IWalletProvider.d.ts.map +1 -1
  39. package/dist/wallet/SmartWalletRouter.d.ts +128 -0
  40. package/dist/wallet/SmartWalletRouter.d.ts.map +1 -0
  41. package/dist/wallet/SmartWalletRouter.js +248 -0
  42. package/dist/wallet/SmartWalletRouter.js.map +1 -0
  43. package/dist/wallet/aa/DualNonceManager.d.ts +26 -1
  44. package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
  45. package/dist/wallet/aa/DualNonceManager.js +140 -6
  46. package/dist/wallet/aa/DualNonceManager.js.map +1 -1
  47. package/package.json +3 -6
  48. package/src/ACTPClient.ts +0 -1579
  49. package/src/abi/ACTPKernel.json +0 -1356
  50. package/src/abi/AgentRegistry.json +0 -915
  51. package/src/abi/ERC20.json +0 -40
  52. package/src/abi/EscrowVault.json +0 -134
  53. package/src/abi/IdentityRegistry.json +0 -316
  54. package/src/adapters/AdapterRegistry.ts +0 -173
  55. package/src/adapters/AdapterRouter.ts +0 -416
  56. package/src/adapters/BaseAdapter.ts +0 -498
  57. package/src/adapters/BasicAdapter.ts +0 -514
  58. package/src/adapters/IAdapter.ts +0 -292
  59. package/src/adapters/StandardAdapter.ts +0 -555
  60. package/src/adapters/X402Adapter.ts +0 -731
  61. package/src/adapters/index.ts +0 -60
  62. package/src/builders/DeliveryProofBuilder.ts +0 -327
  63. package/src/builders/QuoteBuilder.ts +0 -483
  64. package/src/builders/index.ts +0 -17
  65. package/src/cli/commands/balance.ts +0 -110
  66. package/src/cli/commands/batch.ts +0 -487
  67. package/src/cli/commands/config.ts +0 -231
  68. package/src/cli/commands/deploy-check.ts +0 -364
  69. package/src/cli/commands/deploy-env.ts +0 -120
  70. package/src/cli/commands/diff.ts +0 -141
  71. package/src/cli/commands/init.ts +0 -469
  72. package/src/cli/commands/mint.ts +0 -116
  73. package/src/cli/commands/pay.ts +0 -113
  74. package/src/cli/commands/publish.ts +0 -475
  75. package/src/cli/commands/pull.ts +0 -124
  76. package/src/cli/commands/register.ts +0 -247
  77. package/src/cli/commands/simulate.ts +0 -345
  78. package/src/cli/commands/time.ts +0 -302
  79. package/src/cli/commands/tx.ts +0 -448
  80. package/src/cli/commands/watch.ts +0 -211
  81. package/src/cli/index.ts +0 -134
  82. package/src/cli/utils/client.ts +0 -252
  83. package/src/cli/utils/config.ts +0 -389
  84. package/src/cli/utils/output.ts +0 -465
  85. package/src/cli/utils/wallet.ts +0 -109
  86. package/src/config/agirailsmd.ts +0 -262
  87. package/src/config/networks.ts +0 -275
  88. package/src/config/pendingPublish.ts +0 -237
  89. package/src/config/publishPipeline.ts +0 -359
  90. package/src/config/syncOperations.ts +0 -279
  91. package/src/erc8004/ERC8004Bridge.ts +0 -462
  92. package/src/erc8004/ReputationReporter.ts +0 -468
  93. package/src/erc8004/index.ts +0 -61
  94. package/src/errors/index.ts +0 -427
  95. package/src/index.ts +0 -364
  96. package/src/level0/Provider.ts +0 -117
  97. package/src/level0/ServiceDirectory.ts +0 -131
  98. package/src/level0/index.ts +0 -10
  99. package/src/level0/provide.ts +0 -132
  100. package/src/level0/request.ts +0 -432
  101. package/src/level1/Agent.ts +0 -1426
  102. package/src/level1/index.ts +0 -10
  103. package/src/level1/pricing/PriceCalculator.ts +0 -255
  104. package/src/level1/pricing/PricingStrategy.ts +0 -198
  105. package/src/level1/types/Job.ts +0 -179
  106. package/src/level1/types/Options.ts +0 -291
  107. package/src/level1/types/index.ts +0 -8
  108. package/src/protocol/ACTPKernel.ts +0 -808
  109. package/src/protocol/AgentRegistry.ts +0 -559
  110. package/src/protocol/DIDManager.ts +0 -629
  111. package/src/protocol/DIDResolver.ts +0 -554
  112. package/src/protocol/EASHelper.ts +0 -378
  113. package/src/protocol/EscrowVault.ts +0 -255
  114. package/src/protocol/EventMonitor.ts +0 -204
  115. package/src/protocol/MessageSigner.ts +0 -510
  116. package/src/protocol/ProofGenerator.ts +0 -339
  117. package/src/protocol/QuoteBuilder.ts +0 -15
  118. package/src/registry/AgentRegistryClient.ts +0 -202
  119. package/src/runtime/BlockchainRuntime.ts +0 -1015
  120. package/src/runtime/IACTPRuntime.ts +0 -306
  121. package/src/runtime/MockRuntime.ts +0 -1298
  122. package/src/runtime/MockStateManager.ts +0 -577
  123. package/src/runtime/index.ts +0 -25
  124. package/src/runtime/types/MockState.ts +0 -237
  125. package/src/storage/ArchiveBundleBuilder.ts +0 -561
  126. package/src/storage/ArweaveClient.ts +0 -946
  127. package/src/storage/FilebaseClient.ts +0 -790
  128. package/src/storage/index.ts +0 -96
  129. package/src/storage/types.ts +0 -348
  130. package/src/types/adapter.ts +0 -310
  131. package/src/types/agent.ts +0 -79
  132. package/src/types/did.ts +0 -223
  133. package/src/types/eip712.ts +0 -175
  134. package/src/types/erc8004.ts +0 -293
  135. package/src/types/escrow.ts +0 -27
  136. package/src/types/index.ts +0 -17
  137. package/src/types/message.ts +0 -145
  138. package/src/types/state.ts +0 -87
  139. package/src/types/transaction.ts +0 -69
  140. package/src/types/x402.ts +0 -251
  141. package/src/utils/ErrorRecoveryGuide.ts +0 -676
  142. package/src/utils/Helpers.ts +0 -688
  143. package/src/utils/IPFSClient.ts +0 -368
  144. package/src/utils/Logger.ts +0 -484
  145. package/src/utils/NonceManager.ts +0 -591
  146. package/src/utils/RateLimiter.ts +0 -534
  147. package/src/utils/ReceivedNonceTracker.ts +0 -567
  148. package/src/utils/SDKLifecycle.ts +0 -416
  149. package/src/utils/SecureNonce.ts +0 -78
  150. package/src/utils/Semaphore.ts +0 -276
  151. package/src/utils/UsedAttestationTracker.ts +0 -385
  152. package/src/utils/canonicalJson.ts +0 -38
  153. package/src/utils/circuitBreaker.ts +0 -324
  154. package/src/utils/computeTypeHash.ts +0 -48
  155. package/src/utils/fsSafe.ts +0 -80
  156. package/src/utils/index.ts +0 -80
  157. package/src/utils/retry.ts +0 -364
  158. package/src/utils/security.ts +0 -418
  159. package/src/utils/validation.ts +0 -540
  160. package/src/wallet/AutoWalletProvider.ts +0 -299
  161. package/src/wallet/EOAWalletProvider.ts +0 -69
  162. package/src/wallet/IWalletProvider.ts +0 -135
  163. package/src/wallet/aa/BundlerClient.ts +0 -274
  164. package/src/wallet/aa/DualNonceManager.ts +0 -173
  165. package/src/wallet/aa/PaymasterClient.ts +0 -174
  166. package/src/wallet/aa/TransactionBatcher.ts +0 -353
  167. package/src/wallet/aa/UserOpBuilder.ts +0 -246
  168. package/src/wallet/aa/constants.ts +0 -60
  169. package/src/wallet/keystore.ts +0 -240
@@ -1,462 +0,0 @@
1
- /**
2
- * ERC-8004 Identity Bridge
3
- *
4
- * READ-ONLY access to ERC-8004 Identity Registry.
5
- * Resolves agent IDs to wallet addresses for ACTP payments.
6
- *
7
- * SECURITY NOTES:
8
- * - All operations are view functions (no gas costs)
9
- * - Safe to call without signer
10
- * - Caches results to minimize RPC calls
11
- * - Handles network errors gracefully
12
- *
13
- * @example
14
- * ```typescript
15
- * const bridge = new ERC8004Bridge({ network: 'base-sepolia' });
16
- *
17
- * // Check if agent exists
18
- * const exists = await bridge.verifyAgent('12345');
19
- *
20
- * // Get wallet for payment
21
- * const wallet = await bridge.getAgentWallet('12345');
22
- *
23
- * // Get full agent info
24
- * const agent = await bridge.resolveAgent('12345');
25
- * ```
26
- *
27
- * @module erc8004/ERC8004Bridge
28
- */
29
-
30
- import { ethers } from 'ethers';
31
- import {
32
- ERC8004Agent,
33
- ERC8004AgentMetadata,
34
- ERC8004Network,
35
- ERC8004Error,
36
- ERC8004ErrorCode,
37
- ERC8004_IDENTITY_REGISTRY,
38
- ERC8004_IDENTITY_ABI,
39
- ERC8004_DEFAULT_RPC,
40
- } from '../types/erc8004';
41
- import { sdkLogger } from '../utils/Logger';
42
-
43
- // ============================================================================
44
- // Types
45
- // ============================================================================
46
-
47
- /**
48
- * Interface for ERC-8004 Identity Registry contract.
49
- * Used for testing with mock implementations.
50
- */
51
- export interface IERC8004IdentityRegistry {
52
- ownerOf(agentId: string): Promise<string>;
53
- getAgentURI(agentId: string): Promise<string>;
54
- balanceOf(owner: string): Promise<bigint>;
55
- tokenOfOwnerByIndex(owner: string, index: number): Promise<bigint>;
56
- }
57
-
58
- /**
59
- * Configuration for ERC8004Bridge.
60
- */
61
- export interface ERC8004BridgeConfig {
62
- /** Target network */
63
- network: ERC8004Network;
64
-
65
- /** Custom RPC URL (optional, uses default if not provided) */
66
- rpcUrl?: string;
67
-
68
- /** Override registry address (optional, for testing) */
69
- registryAddress?: string;
70
-
71
- /** Custom fetch function (optional, for testing) */
72
- fetchFn?: typeof fetch;
73
-
74
- /** Cache TTL in milliseconds (default: 60000 = 1 minute) */
75
- cacheTimeMs?: number;
76
-
77
- /** Metadata fetch timeout in milliseconds (default: 10000 = 10 seconds) */
78
- metadataTimeoutMs?: number;
79
-
80
- /**
81
- * Injected contract instance (optional, for testing).
82
- * If provided, skips creating a real ethers Contract.
83
- * @internal
84
- */
85
- _testContract?: IERC8004IdentityRegistry;
86
- }
87
-
88
- /**
89
- * Cached agent entry.
90
- */
91
- interface CachedAgent {
92
- agent: ERC8004Agent;
93
- expiresAt: number;
94
- }
95
-
96
- // ============================================================================
97
- // ERC8004Bridge
98
- // ============================================================================
99
-
100
- /**
101
- * Bridge for reading from ERC-8004 Identity Registry.
102
- *
103
- * Provides methods to:
104
- * - Verify agent existence
105
- * - Get agent wallet address for payments
106
- * - Resolve full agent info including metadata
107
- * - List agents owned by an address
108
- */
109
- export class ERC8004Bridge {
110
- private readonly provider: ethers.JsonRpcProvider | null;
111
- private readonly registry: IERC8004IdentityRegistry;
112
- private readonly cache: Map<string, CachedAgent>;
113
- private readonly fetchFn: typeof fetch;
114
- private readonly cacheTimeMs: number;
115
- private readonly metadataTimeoutMs: number;
116
- private readonly network: ERC8004Network;
117
-
118
- constructor(config: ERC8004BridgeConfig) {
119
- this.network = config.network;
120
- this.fetchFn = config.fetchFn ?? fetch;
121
- this.cacheTimeMs = config.cacheTimeMs ?? 60000;
122
- this.metadataTimeoutMs = config.metadataTimeoutMs ?? 10000;
123
- this.cache = new Map();
124
-
125
- // Use injected contract for testing
126
- if (config._testContract) {
127
- this.provider = null;
128
- this.registry = config._testContract;
129
- return;
130
- }
131
-
132
- // Setup provider
133
- const rpcUrl = config.rpcUrl ?? ERC8004_DEFAULT_RPC[config.network];
134
- this.provider = new ethers.JsonRpcProvider(rpcUrl);
135
-
136
- // Setup registry contract
137
- const registryAddress =
138
- config.registryAddress ?? ERC8004_IDENTITY_REGISTRY[config.network];
139
-
140
- if (registryAddress === ethers.ZeroAddress) {
141
- sdkLogger.warn(
142
- `[ERC8004] Registry not deployed on ${config.network}. Using zero address.`
143
- );
144
- }
145
-
146
- this.registry = new ethers.Contract(
147
- registryAddress,
148
- ERC8004_IDENTITY_ABI,
149
- this.provider
150
- ) as unknown as IERC8004IdentityRegistry;
151
- }
152
-
153
- // ==========================================================================
154
- // Public Methods
155
- // ==========================================================================
156
-
157
- /**
158
- * Verify agent exists in ERC-8004 Identity Registry.
159
- *
160
- * Safe to call frequently - uses cache and is a view function.
161
- *
162
- * @param agentId - ERC-8004 agent ID (uint256 as string)
163
- * @returns true if agent exists, false otherwise
164
- */
165
- async verifyAgent(agentId: string): Promise<boolean> {
166
- // Validate format first
167
- if (!this.isValidAgentId(agentId)) {
168
- return false;
169
- }
170
-
171
- // Check cache
172
- const cached = this.cache.get(agentId);
173
- if (cached && cached.expiresAt > Date.now()) {
174
- return true;
175
- }
176
-
177
- try {
178
- const owner = await this.registry.ownerOf(agentId);
179
- return owner !== ethers.ZeroAddress;
180
- } catch {
181
- // ownerOf reverts for non-existent tokens (ERC-721 standard)
182
- return false;
183
- }
184
- }
185
-
186
- /**
187
- * Get wallet address for receiving payments.
188
- *
189
- * Wallet priority:
190
- * 1. metadata.paymentAddress (explicit payment destination)
191
- * 2. metadata.wallet (alternative field name)
192
- * 3. owner address (fallback)
193
- *
194
- * @param agentId - ERC-8004 agent ID
195
- * @returns Checksummed wallet address
196
- * @throws ERC8004Error if agent not found
197
- */
198
- async getAgentWallet(agentId: string): Promise<string> {
199
- const agent = await this.resolveAgent(agentId);
200
- return agent.wallet;
201
- }
202
-
203
- /**
204
- * Resolve full agent info from ERC-8004.
205
- *
206
- * Fetches on-chain data (owner, agentURI) and off-chain metadata.
207
- * Results are cached for cacheTimeMs.
208
- *
209
- * @param agentId - ERC-8004 agent ID
210
- * @returns Full agent info including metadata
211
- * @throws ERC8004Error if agent not found or invalid ID
212
- */
213
- async resolveAgent(agentId: string): Promise<ERC8004Agent> {
214
- // Check cache first
215
- const cached = this.cache.get(agentId);
216
- if (cached && cached.expiresAt > Date.now()) {
217
- return cached.agent;
218
- }
219
-
220
- // Validate format
221
- if (!this.isValidAgentId(agentId)) {
222
- throw new ERC8004Error(
223
- `Invalid agent ID format: "${agentId}"`,
224
- ERC8004ErrorCode.INVALID_AGENT_ID,
225
- agentId
226
- );
227
- }
228
-
229
- // Fetch on-chain data
230
- let owner: string;
231
- let agentURI: string;
232
-
233
- try {
234
- [owner, agentURI] = await Promise.all([
235
- this.registry.ownerOf(agentId),
236
- this.registry.getAgentURI(agentId),
237
- ]);
238
- } catch (error) {
239
- // Check if it's a "nonexistent token" error
240
- const isNotFound =
241
- error instanceof Error &&
242
- (error.message.includes('nonexistent') ||
243
- error.message.includes('ERC721') ||
244
- error.message.includes('invalid token'));
245
-
246
- if (isNotFound) {
247
- throw new ERC8004Error(
248
- `Agent ${agentId} not found in ERC-8004 registry`,
249
- ERC8004ErrorCode.AGENT_NOT_FOUND,
250
- agentId
251
- );
252
- }
253
-
254
- throw new ERC8004Error(
255
- `Failed to fetch agent ${agentId}: ${error instanceof Error ? error.message : 'Unknown error'}`,
256
- ERC8004ErrorCode.NETWORK_ERROR,
257
- agentId,
258
- error instanceof Error ? error : undefined
259
- );
260
- }
261
-
262
- // Check owner is valid
263
- if (owner === ethers.ZeroAddress) {
264
- throw new ERC8004Error(
265
- `Agent ${agentId} not found in ERC-8004 registry`,
266
- ERC8004ErrorCode.AGENT_NOT_FOUND,
267
- agentId
268
- );
269
- }
270
-
271
- // Fetch metadata (may return undefined if fetch fails)
272
- const metadata = await this.fetchMetadata(agentURI, agentId);
273
-
274
- // Determine wallet address
275
- // Priority: paymentAddress > wallet > owner
276
- let walletAddress = owner;
277
-
278
- if (metadata?.paymentAddress && this.isValidAddress(metadata.paymentAddress)) {
279
- walletAddress = metadata.paymentAddress;
280
- } else if (metadata?.wallet && this.isValidAddress(metadata.wallet)) {
281
- walletAddress = metadata.wallet;
282
- }
283
-
284
- // Build agent object
285
- const agent: ERC8004Agent = {
286
- agentId,
287
- owner: ethers.getAddress(owner), // Checksummed
288
- wallet: ethers.getAddress(walletAddress), // Checksummed
289
- agentURI,
290
- metadata,
291
- network: this.network,
292
- };
293
-
294
- // Cache result
295
- this.cache.set(agentId, {
296
- agent,
297
- expiresAt: Date.now() + this.cacheTimeMs,
298
- });
299
-
300
- return agent;
301
- }
302
-
303
- /**
304
- * Get all agent IDs owned by an address.
305
- *
306
- * @param owner - Owner address to query
307
- * @returns Array of agent IDs (may be empty)
308
- */
309
- async getAgentsByOwner(owner: string): Promise<string[]> {
310
- if (!this.isValidAddress(owner)) {
311
- return [];
312
- }
313
-
314
- try {
315
- const balance = await this.registry.balanceOf(owner);
316
- const balanceNum = Number(balance);
317
-
318
- if (balanceNum === 0) {
319
- return [];
320
- }
321
-
322
- const agentIds: string[] = [];
323
-
324
- for (let i = 0; i < balanceNum; i++) {
325
- const agentId = await this.registry.tokenOfOwnerByIndex(owner, i);
326
- agentIds.push(agentId.toString());
327
- }
328
-
329
- return agentIds;
330
- } catch (error) {
331
- sdkLogger.warn(`[ERC8004] Failed to get agents for owner ${owner}: ${error instanceof Error ? error.message : error}`);
332
- return [];
333
- }
334
- }
335
-
336
- /**
337
- * Clear all cached entries.
338
- * Useful for testing or forcing fresh data.
339
- */
340
- clearCache(): void {
341
- this.cache.clear();
342
- }
343
-
344
- /**
345
- * Get cache statistics (for debugging).
346
- */
347
- getCacheStats(): { size: number; network: ERC8004Network } {
348
- return {
349
- size: this.cache.size,
350
- network: this.network,
351
- };
352
- }
353
-
354
- // ==========================================================================
355
- // Private Methods
356
- // ==========================================================================
357
-
358
- /**
359
- * Validate agent ID format.
360
- * Agent IDs are uint256 values (0 to 2^256-1).
361
- */
362
- private isValidAgentId(agentId: string): boolean {
363
- if (!agentId || typeof agentId !== 'string') {
364
- return false;
365
- }
366
-
367
- // Must not look like an Ethereum address or URL
368
- if (agentId.startsWith('0x') || agentId.includes('://')) {
369
- return false;
370
- }
371
-
372
- try {
373
- const bn = BigInt(agentId);
374
- return bn >= 0n && bn < 2n ** 256n;
375
- } catch {
376
- return false;
377
- }
378
- }
379
-
380
- /**
381
- * Validate Ethereum address format.
382
- */
383
- private isValidAddress(address: string): boolean {
384
- try {
385
- ethers.getAddress(address);
386
- return true;
387
- } catch {
388
- return false;
389
- }
390
- }
391
-
392
- /**
393
- * Fetch and parse metadata from agentURI.
394
- *
395
- * Handles:
396
- * - IPFS URIs (ipfs://...)
397
- * - HTTPS URIs
398
- * - Timeout protection
399
- * - Parse errors
400
- *
401
- * Returns undefined on any failure (never throws).
402
- */
403
- private async fetchMetadata(
404
- agentURI: string,
405
- agentId: string
406
- ): Promise<ERC8004AgentMetadata | undefined> {
407
- if (!agentURI) {
408
- return undefined;
409
- }
410
-
411
- try {
412
- // Convert IPFS URI to HTTP gateway
413
- let url = agentURI;
414
- if (url.startsWith('ipfs://')) {
415
- const cid = url.slice(7);
416
- url = `https://ipfs.io/ipfs/${cid}`;
417
- }
418
-
419
- // Validate URL
420
- if (!url.startsWith('http://') && !url.startsWith('https://')) {
421
- sdkLogger.warn(`[ERC8004] Invalid agentURI scheme for ${agentId}: ${url}`);
422
- return undefined;
423
- }
424
-
425
- // Fetch with timeout
426
- const controller = new AbortController();
427
- const timeoutId = setTimeout(() => controller.abort(), this.metadataTimeoutMs);
428
-
429
- try {
430
- const response = await this.fetchFn(url, {
431
- headers: { Accept: 'application/json' },
432
- signal: controller.signal,
433
- });
434
-
435
- clearTimeout(timeoutId);
436
-
437
- if (!response.ok) {
438
- sdkLogger.warn(
439
- `[ERC8004] Metadata fetch failed for ${agentId}: HTTP ${response.status}`
440
- );
441
- return undefined;
442
- }
443
-
444
- const data = await response.json();
445
- return data as ERC8004AgentMetadata;
446
- } finally {
447
- clearTimeout(timeoutId);
448
- }
449
- } catch (error) {
450
- // Log but don't throw - metadata is optional
451
- const errorMessage =
452
- error instanceof Error
453
- ? error.name === 'AbortError'
454
- ? 'timeout'
455
- : error.message
456
- : 'unknown error';
457
-
458
- sdkLogger.warn(`[ERC8004] Metadata fetch failed for ${agentId}: ${errorMessage}`);
459
- return undefined;
460
- }
461
- }
462
- }