@agirails/sdk 2.2.0 → 2.2.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.
Files changed (120) hide show
  1. package/dist/ACTPClient.d.ts +200 -0
  2. package/dist/ACTPClient.d.ts.map +1 -1
  3. package/dist/ACTPClient.js +266 -2
  4. package/dist/ACTPClient.js.map +1 -1
  5. package/dist/abi/ACTPKernel.json +16 -0
  6. package/dist/adapters/AdapterRegistry.d.ts +140 -0
  7. package/dist/adapters/AdapterRegistry.d.ts.map +1 -0
  8. package/dist/adapters/AdapterRegistry.js +166 -0
  9. package/dist/adapters/AdapterRegistry.js.map +1 -0
  10. package/dist/adapters/AdapterRouter.d.ts +165 -0
  11. package/dist/adapters/AdapterRouter.d.ts.map +1 -0
  12. package/dist/adapters/AdapterRouter.js +350 -0
  13. package/dist/adapters/AdapterRouter.js.map +1 -0
  14. package/dist/adapters/BaseAdapter.d.ts +17 -0
  15. package/dist/adapters/BaseAdapter.d.ts.map +1 -1
  16. package/dist/adapters/BaseAdapter.js +21 -0
  17. package/dist/adapters/BaseAdapter.js.map +1 -1
  18. package/dist/adapters/BasicAdapter.d.ts +72 -3
  19. package/dist/adapters/BasicAdapter.d.ts.map +1 -1
  20. package/dist/adapters/BasicAdapter.js +170 -2
  21. package/dist/adapters/BasicAdapter.js.map +1 -1
  22. package/dist/adapters/IAdapter.d.ts +230 -0
  23. package/dist/adapters/IAdapter.d.ts.map +1 -0
  24. package/dist/adapters/IAdapter.js +44 -0
  25. package/dist/adapters/IAdapter.js.map +1 -0
  26. package/dist/adapters/StandardAdapter.d.ts +70 -1
  27. package/dist/adapters/StandardAdapter.d.ts.map +1 -1
  28. package/dist/adapters/StandardAdapter.js +184 -0
  29. package/dist/adapters/StandardAdapter.js.map +1 -1
  30. package/dist/adapters/X402Adapter.d.ts +208 -0
  31. package/dist/adapters/X402Adapter.d.ts.map +1 -0
  32. package/dist/adapters/X402Adapter.js +423 -0
  33. package/dist/adapters/X402Adapter.js.map +1 -0
  34. package/dist/adapters/index.d.ts +8 -0
  35. package/dist/adapters/index.d.ts.map +1 -1
  36. package/dist/adapters/index.js +19 -1
  37. package/dist/adapters/index.js.map +1 -1
  38. package/dist/cli/commands/init.d.ts +4 -0
  39. package/dist/cli/commands/init.d.ts.map +1 -1
  40. package/dist/cli/commands/init.js +184 -4
  41. package/dist/cli/commands/init.js.map +1 -1
  42. package/dist/config/networks.js +3 -3
  43. package/dist/config/networks.js.map +1 -1
  44. package/dist/erc8004/ERC8004Bridge.d.ts +155 -0
  45. package/dist/erc8004/ERC8004Bridge.d.ts.map +1 -0
  46. package/dist/erc8004/ERC8004Bridge.js +325 -0
  47. package/dist/erc8004/ERC8004Bridge.js.map +1 -0
  48. package/dist/erc8004/ReputationReporter.d.ts +223 -0
  49. package/dist/erc8004/ReputationReporter.d.ts.map +1 -0
  50. package/dist/erc8004/ReputationReporter.js +266 -0
  51. package/dist/erc8004/ReputationReporter.js.map +1 -0
  52. package/dist/erc8004/index.d.ts +36 -0
  53. package/dist/erc8004/index.d.ts.map +1 -0
  54. package/dist/erc8004/index.js +46 -0
  55. package/dist/erc8004/index.js.map +1 -0
  56. package/dist/index.d.ts +5 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +21 -2
  59. package/dist/index.js.map +1 -1
  60. package/dist/protocol/ACTPKernel.d.ts +1 -1
  61. package/dist/protocol/ACTPKernel.d.ts.map +1 -1
  62. package/dist/protocol/ACTPKernel.js +16 -7
  63. package/dist/protocol/ACTPKernel.js.map +1 -1
  64. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  65. package/dist/runtime/BlockchainRuntime.js +2 -0
  66. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  67. package/dist/runtime/IACTPRuntime.d.ts +6 -0
  68. package/dist/runtime/IACTPRuntime.d.ts.map +1 -1
  69. package/dist/runtime/MockRuntime.d.ts +12 -0
  70. package/dist/runtime/MockRuntime.d.ts.map +1 -1
  71. package/dist/runtime/MockRuntime.js +41 -0
  72. package/dist/runtime/MockRuntime.js.map +1 -1
  73. package/dist/runtime/types/MockState.d.ts +6 -0
  74. package/dist/runtime/types/MockState.d.ts.map +1 -1
  75. package/dist/runtime/types/MockState.js.map +1 -1
  76. package/dist/types/adapter.d.ts +359 -0
  77. package/dist/types/adapter.d.ts.map +1 -0
  78. package/dist/types/adapter.js +115 -0
  79. package/dist/types/adapter.js.map +1 -0
  80. package/dist/types/erc8004.d.ts +184 -0
  81. package/dist/types/erc8004.d.ts.map +1 -0
  82. package/dist/types/erc8004.js +132 -0
  83. package/dist/types/erc8004.js.map +1 -0
  84. package/dist/types/index.d.ts +3 -0
  85. package/dist/types/index.d.ts.map +1 -1
  86. package/dist/types/index.js +3 -0
  87. package/dist/types/index.js.map +1 -1
  88. package/dist/types/transaction.d.ts +12 -0
  89. package/dist/types/transaction.d.ts.map +1 -1
  90. package/dist/types/x402.d.ts +162 -0
  91. package/dist/types/x402.d.ts.map +1 -0
  92. package/dist/types/x402.js +162 -0
  93. package/dist/types/x402.js.map +1 -0
  94. package/package.json +3 -2
  95. package/src/ACTPClient.ts +318 -2
  96. package/src/abi/ACTPKernel.json +16 -0
  97. package/src/adapters/AdapterRegistry.ts +173 -0
  98. package/src/adapters/AdapterRouter.ts +417 -0
  99. package/src/adapters/BaseAdapter.ts +25 -0
  100. package/src/adapters/BasicAdapter.ts +199 -3
  101. package/src/adapters/IAdapter.ts +292 -0
  102. package/src/adapters/StandardAdapter.ts +220 -1
  103. package/src/adapters/X402Adapter.ts +653 -0
  104. package/src/adapters/index.ts +27 -0
  105. package/src/cli/commands/init.ts +208 -3
  106. package/src/config/networks.ts +3 -3
  107. package/src/erc8004/ERC8004Bridge.ts +461 -0
  108. package/src/erc8004/ReputationReporter.ts +472 -0
  109. package/src/erc8004/index.ts +61 -0
  110. package/src/index.ts +43 -0
  111. package/src/protocol/ACTPKernel.ts +26 -7
  112. package/src/runtime/BlockchainRuntime.ts +2 -0
  113. package/src/runtime/IACTPRuntime.ts +6 -0
  114. package/src/runtime/MockRuntime.ts +42 -0
  115. package/src/runtime/types/MockState.ts +7 -0
  116. package/src/types/adapter.ts +296 -0
  117. package/src/types/erc8004.ts +293 -0
  118. package/src/types/index.ts +3 -0
  119. package/src/types/transaction.ts +12 -0
  120. package/src/types/x402.ts +219 -0
@@ -0,0 +1,472 @@
1
+ /**
2
+ * ERC-8004 Reputation Reporter
3
+ *
4
+ * WRITES to ERC-8004 Reputation Registry after ACTP settlements.
5
+ *
6
+ * CRITICAL SECURITY NOTES:
7
+ * 1. Requires signer (pays gas) - typically the requester
8
+ * 2. Caller MUST NOT be agent owner (ERC-8004 restriction)
9
+ * 3. Uses feedbackHash = keccak256(txId) for replay protection
10
+ * 4. Failures are logged but NEVER block ACTP settlement
11
+ * 5. Local dedup prevents double-reporting in same session
12
+ *
13
+ * WHEN TO CALL:
14
+ * - reportSettlement(): After successful release() (state = SETTLED)
15
+ * - reportDispute(): After dispute resolution
16
+ *
17
+ * FAILURE HANDLING:
18
+ * - All methods return null on failure (never throw)
19
+ * - Settlement/dispute already succeeded - reputation is bonus
20
+ * - Log warnings for debugging
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const reporter = new ReputationReporter({
25
+ * network: 'base-sepolia',
26
+ * signer: requesterWallet,
27
+ * });
28
+ *
29
+ * // After successful release
30
+ * const txHash = await reporter.reportSettlement({
31
+ * agentId: '12345',
32
+ * txId: result.txId,
33
+ * capability: 'code_generation',
34
+ * });
35
+ *
36
+ * if (txHash) {
37
+ * console.log('Reputation reported:', txHash);
38
+ * } else {
39
+ * console.warn('Report failed (settlement still succeeded)');
40
+ * }
41
+ * ```
42
+ *
43
+ * @module erc8004/ReputationReporter
44
+ */
45
+
46
+ import { ethers, Signer } from 'ethers';
47
+ import {
48
+ ERC8004Network,
49
+ ERC8004_REPUTATION_REGISTRY,
50
+ ERC8004_REPUTATION_ABI,
51
+ ACTP_FEEDBACK_TAGS,
52
+ } from '../types/erc8004';
53
+
54
+ // ============================================================================
55
+ // Types
56
+ // ============================================================================
57
+
58
+ /**
59
+ * Transaction receipt interface for reputation reports.
60
+ */
61
+ interface TransactionReceipt {
62
+ hash: string;
63
+ blockNumber: number;
64
+ gasUsed: bigint;
65
+ }
66
+
67
+ /**
68
+ * Transaction response interface.
69
+ */
70
+ interface TransactionResponse {
71
+ wait(): Promise<TransactionReceipt>;
72
+ }
73
+
74
+ /**
75
+ * Interface for ERC-8004 Reputation Registry contract.
76
+ * Used for testing with mock implementations.
77
+ */
78
+ export interface IERC8004ReputationRegistry {
79
+ giveFeedback(
80
+ agentId: string,
81
+ value: number,
82
+ valueDecimals: number,
83
+ tag1: string,
84
+ tag2: string,
85
+ endpoint: string,
86
+ feedbackURI: string,
87
+ feedbackHash: string,
88
+ txOptions?: { gasLimit?: bigint }
89
+ ): Promise<TransactionResponse>;
90
+
91
+ getSummary(
92
+ agentId: string,
93
+ clientAddresses: string[],
94
+ tag1: string,
95
+ tag2: string
96
+ ): Promise<[bigint, bigint, number]>;
97
+
98
+ revokeLatest(agentId: string, feedbackIndex: bigint): Promise<TransactionResponse>;
99
+ }
100
+
101
+ /**
102
+ * Configuration for ReputationReporter.
103
+ */
104
+ export interface ReputationReporterConfig {
105
+ /** Target network */
106
+ network: ERC8004Network;
107
+
108
+ /** Signer for transactions (pays gas) */
109
+ signer: Signer;
110
+
111
+ /** Override registry address (optional, for testing) */
112
+ registryAddress?: string;
113
+
114
+ /** Gas limit override (optional) */
115
+ gasLimit?: bigint;
116
+
117
+ /**
118
+ * Injected contract instance (optional, for testing).
119
+ * If provided, skips creating a real ethers Contract.
120
+ * @internal
121
+ */
122
+ _testContract?: IERC8004ReputationRegistry;
123
+ }
124
+
125
+ /**
126
+ * Parameters for reporting a successful settlement.
127
+ */
128
+ export interface ReportSettlementParams {
129
+ /** ERC-8004 agent ID */
130
+ agentId: string;
131
+
132
+ /** ACTP transaction ID (used for replay protection) */
133
+ txId: string;
134
+
135
+ /** Agent capability (e.g., 'code_generation', 'data_analysis') */
136
+ capability?: string;
137
+
138
+ /** Service endpoint (optional) */
139
+ endpoint?: string;
140
+
141
+ /** Link to transaction details (optional, IPFS or HTTPS) */
142
+ feedbackURI?: string;
143
+ }
144
+
145
+ /**
146
+ * Parameters for reporting a dispute resolution.
147
+ */
148
+ export interface ReportDisputeParams {
149
+ /** ERC-8004 agent ID */
150
+ agentId: string;
151
+
152
+ /** ACTP transaction ID */
153
+ txId: string;
154
+
155
+ /** true if agent won the dispute, false if requester won */
156
+ agentWon: boolean;
157
+
158
+ /** Agent capability (optional) */
159
+ capability?: string;
160
+
161
+ /** Dispute reason/details (optional, stored as feedbackURI) */
162
+ reason?: string;
163
+ }
164
+
165
+ /**
166
+ * Result of a reputation report.
167
+ */
168
+ export interface ReportResult {
169
+ /** Transaction hash */
170
+ txHash: string;
171
+
172
+ /** Block number */
173
+ blockNumber: number;
174
+
175
+ /** Gas used */
176
+ gasUsed: bigint;
177
+ }
178
+
179
+ // ============================================================================
180
+ // ReputationReporter
181
+ // ============================================================================
182
+
183
+ /**
184
+ * Reporter for submitting ACTP settlement outcomes to ERC-8004 Reputation.
185
+ *
186
+ * Designed to never block or fail the main ACTP flow.
187
+ * All errors are caught and logged, returning null on failure.
188
+ */
189
+ export class ReputationReporter {
190
+ private readonly registry: IERC8004ReputationRegistry;
191
+ private readonly signer: Signer;
192
+ private readonly network: ERC8004Network;
193
+ private readonly gasLimit?: bigint;
194
+
195
+ /**
196
+ * Track reported txIds to prevent double-reporting in same session.
197
+ * Note: This is in-memory only, so restarts allow re-reporting.
198
+ * On-chain, feedbackHash provides permanent dedup.
199
+ */
200
+ private readonly reportedTxIds: Set<string> = new Set();
201
+
202
+ constructor(config: ReputationReporterConfig) {
203
+ this.network = config.network;
204
+ this.signer = config.signer;
205
+ this.gasLimit = config.gasLimit;
206
+
207
+ // Use injected contract for testing
208
+ if (config._testContract) {
209
+ this.registry = config._testContract;
210
+ return;
211
+ }
212
+
213
+ const registryAddress =
214
+ config.registryAddress ?? ERC8004_REPUTATION_REGISTRY[config.network];
215
+
216
+ if (registryAddress === ethers.ZeroAddress) {
217
+ console.warn(
218
+ `[ERC8004] Reputation Registry not deployed on ${config.network}. ` +
219
+ 'Reports will fail.'
220
+ );
221
+ }
222
+
223
+ this.registry = new ethers.Contract(
224
+ registryAddress,
225
+ ERC8004_REPUTATION_ABI,
226
+ config.signer
227
+ ) as unknown as IERC8004ReputationRegistry;
228
+ }
229
+
230
+ // ==========================================================================
231
+ // Public Methods
232
+ // ==========================================================================
233
+
234
+ /**
235
+ * Report successful ACTP settlement to ERC-8004 Reputation.
236
+ *
237
+ * Call this AFTER release() succeeds. Failure here does NOT affect settlement.
238
+ *
239
+ * Reports:
240
+ * - value: 1 (positive feedback)
241
+ * - valueDecimals: 0 (binary)
242
+ * - tag1: 'actp_settled'
243
+ * - tag2: capability
244
+ * - feedbackHash: keccak256(txId)
245
+ *
246
+ * @param params - Settlement details
247
+ * @returns ReportResult if successful, null if failed
248
+ */
249
+ async reportSettlement(params: ReportSettlementParams): Promise<ReportResult | null> {
250
+ const {
251
+ agentId,
252
+ txId,
253
+ capability = '',
254
+ endpoint = '',
255
+ feedbackURI = '',
256
+ } = params;
257
+
258
+ // Local dedup check
259
+ if (this.reportedTxIds.has(txId)) {
260
+ console.warn(`[ERC8004] Already reported txId in this session: ${txId}`);
261
+ return null;
262
+ }
263
+
264
+ try {
265
+ // Compute feedbackHash for on-chain replay protection
266
+ const feedbackHash = ethers.keccak256(ethers.toUtf8Bytes(txId));
267
+
268
+ // Prepare transaction options
269
+ const txOptions: { gasLimit?: bigint } = {};
270
+ if (this.gasLimit) {
271
+ txOptions.gasLimit = this.gasLimit;
272
+ }
273
+
274
+ // Submit feedback
275
+ const tx = await this.registry.giveFeedback(
276
+ agentId,
277
+ 1, // value: 1 = success
278
+ 0, // decimals: 0 (binary)
279
+ ACTP_FEEDBACK_TAGS.SETTLED, // tag1: 'actp_settled'
280
+ capability, // tag2: capability
281
+ endpoint,
282
+ feedbackURI,
283
+ feedbackHash,
284
+ txOptions
285
+ );
286
+
287
+ // Wait for confirmation
288
+ const receipt = await tx.wait();
289
+
290
+ // Mark as reported
291
+ this.reportedTxIds.add(txId);
292
+
293
+ return {
294
+ txHash: receipt.hash,
295
+ blockNumber: receipt.blockNumber,
296
+ gasUsed: receipt.gasUsed,
297
+ };
298
+ } catch (error) {
299
+ // Log but NEVER throw - settlement already succeeded
300
+ this.logError('reportSettlement', agentId, txId, error);
301
+ return null;
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Report ACTP dispute resolution to ERC-8004 Reputation.
307
+ *
308
+ * Call this after dispute is resolved (either party won).
309
+ *
310
+ * Reports:
311
+ * - value: 1 if agent won, -1 if requester won
312
+ * - valueDecimals: 0 (binary)
313
+ * - tag1: 'actp_dispute_won' or 'actp_dispute_lost'
314
+ * - tag2: capability
315
+ * - feedbackHash: keccak256(txId)
316
+ *
317
+ * @param params - Dispute details
318
+ * @returns ReportResult if successful, null if failed
319
+ */
320
+ async reportDispute(params: ReportDisputeParams): Promise<ReportResult | null> {
321
+ const { agentId, txId, agentWon, capability = '', reason = '' } = params;
322
+
323
+ // Local dedup check
324
+ if (this.reportedTxIds.has(txId)) {
325
+ console.warn(`[ERC8004] Already reported txId in this session: ${txId}`);
326
+ return null;
327
+ }
328
+
329
+ try {
330
+ const feedbackHash = ethers.keccak256(ethers.toUtf8Bytes(txId));
331
+
332
+ // Determine value and tag based on outcome
333
+ const value = agentWon ? 1 : -1;
334
+ const tag1 = agentWon
335
+ ? ACTP_FEEDBACK_TAGS.DISPUTE_WON
336
+ : ACTP_FEEDBACK_TAGS.DISPUTE_LOST;
337
+
338
+ const txOptions: { gasLimit?: bigint } = {};
339
+ if (this.gasLimit) {
340
+ txOptions.gasLimit = this.gasLimit;
341
+ }
342
+
343
+ const tx = await this.registry.giveFeedback(
344
+ agentId,
345
+ value,
346
+ 0, // decimals: 0 (binary)
347
+ tag1,
348
+ capability,
349
+ '', // endpoint
350
+ reason, // feedbackURI (contains dispute reason)
351
+ feedbackHash,
352
+ txOptions
353
+ );
354
+
355
+ const receipt = await tx.wait();
356
+ this.reportedTxIds.add(txId);
357
+
358
+ return {
359
+ txHash: receipt.hash,
360
+ blockNumber: receipt.blockNumber,
361
+ gasUsed: receipt.gasUsed,
362
+ };
363
+ } catch (error) {
364
+ this.logError('reportDispute', agentId, txId, error);
365
+ return null;
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Get reputation summary for an agent.
371
+ *
372
+ * This is a READ operation (no gas cost).
373
+ *
374
+ * @param agentId - ERC-8004 agent ID
375
+ * @param tag1 - Filter by tag1 (optional, e.g., 'actp_settled')
376
+ * @returns Summary if successful, null if failed
377
+ */
378
+ async getAgentReputation(
379
+ agentId: string,
380
+ tag1?: string
381
+ ): Promise<{ count: number; score: number } | null> {
382
+ try {
383
+ const [count, summaryValue] = await this.registry.getSummary(
384
+ agentId,
385
+ [], // clientAddresses (empty = all)
386
+ tag1 ?? '',
387
+ '' // tag2
388
+ );
389
+
390
+ return {
391
+ count: Number(count),
392
+ score: Number(summaryValue),
393
+ };
394
+ } catch (error) {
395
+ console.error(
396
+ `[ERC8004] getAgentReputation failed for ${agentId}:`,
397
+ error instanceof Error ? error.message : error
398
+ );
399
+ return null;
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Check if a transaction was already reported in this session.
405
+ *
406
+ * Note: This is local-only. For on-chain check, you'd need to
407
+ * query the feedbackHash mapping (not exposed in standard interface).
408
+ *
409
+ * @param txId - ACTP transaction ID
410
+ */
411
+ isReported(txId: string): boolean {
412
+ return this.reportedTxIds.has(txId);
413
+ }
414
+
415
+ /**
416
+ * Clear local dedup cache.
417
+ * Use when starting new session or for testing.
418
+ */
419
+ clearReportedCache(): void {
420
+ this.reportedTxIds.clear();
421
+ }
422
+
423
+ /**
424
+ * Get reporter statistics.
425
+ */
426
+ getStats(): { network: ERC8004Network; reportedCount: number } {
427
+ return {
428
+ network: this.network,
429
+ reportedCount: this.reportedTxIds.size,
430
+ };
431
+ }
432
+
433
+ // ==========================================================================
434
+ // Private Methods
435
+ // ==========================================================================
436
+
437
+ /**
438
+ * Log error in consistent format.
439
+ * NEVER throws - errors are informational only.
440
+ */
441
+ private logError(
442
+ method: string,
443
+ agentId: string,
444
+ txId: string,
445
+ error: unknown
446
+ ): void {
447
+ const errorMessage =
448
+ error instanceof Error ? error.message : String(error);
449
+
450
+ // Check for common error cases
451
+ if (errorMessage.includes('insufficient funds')) {
452
+ console.error(
453
+ `[ERC8004] ${method} failed for agent ${agentId}: ` +
454
+ 'Insufficient funds for gas. Signer needs ETH/native token.'
455
+ );
456
+ } else if (errorMessage.includes('cannot be the agent owner')) {
457
+ console.error(
458
+ `[ERC8004] ${method} failed for agent ${agentId}: ` +
459
+ 'Caller is agent owner. ERC-8004 requires different address.'
460
+ );
461
+ } else if (errorMessage.includes('user rejected')) {
462
+ console.warn(
463
+ `[ERC8004] ${method} cancelled by user for agent ${agentId}`
464
+ );
465
+ } else {
466
+ console.error(
467
+ `[ERC8004] ${method} failed for agent ${agentId} (tx: ${txId}): ` +
468
+ errorMessage
469
+ );
470
+ }
471
+ }
472
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * ERC-8004 Trustless Agents Integration
3
+ *
4
+ * Provides integration with ERC-8004 standard for:
5
+ * - Agent identity resolution (Identity Registry)
6
+ * - Reputation reporting (Reputation Registry)
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import {
11
+ * ERC8004Bridge,
12
+ * ReputationReporter,
13
+ * ERC8004Error,
14
+ * } from '@agirails/sdk/erc8004';
15
+ *
16
+ * // Read agent info
17
+ * const bridge = new ERC8004Bridge({ network: 'base-sepolia' });
18
+ * const agent = await bridge.resolveAgent('12345');
19
+ *
20
+ * // Report settlement
21
+ * const reporter = new ReputationReporter({
22
+ * network: 'base-sepolia',
23
+ * signer: wallet,
24
+ * });
25
+ * await reporter.reportSettlement({ agentId: '12345', txId });
26
+ * ```
27
+ *
28
+ * @module erc8004
29
+ */
30
+
31
+ // Bridge (read-only)
32
+ export { ERC8004Bridge } from './ERC8004Bridge';
33
+ export type { ERC8004BridgeConfig } from './ERC8004Bridge';
34
+
35
+ // Reporter (write)
36
+ export { ReputationReporter } from './ReputationReporter';
37
+ export type {
38
+ ReputationReporterConfig,
39
+ ReportSettlementParams,
40
+ ReportDisputeParams,
41
+ ReportResult,
42
+ } from './ReputationReporter';
43
+
44
+ // Re-export types from types/erc8004
45
+ export type {
46
+ ERC8004Network,
47
+ ERC8004Agent,
48
+ ERC8004AgentMetadata,
49
+ ReputationFeedback,
50
+ ReputationSummary,
51
+ ACTPFeedbackTag,
52
+ } from '../types/erc8004';
53
+
54
+ export {
55
+ ERC8004Error,
56
+ ERC8004ErrorCode,
57
+ ERC8004_IDENTITY_REGISTRY,
58
+ ERC8004_REPUTATION_REGISTRY,
59
+ ERC8004_DEFAULT_RPC,
60
+ ACTP_FEEDBACK_TAGS,
61
+ } from '../types/erc8004';
package/src/index.ts CHANGED
@@ -64,6 +64,20 @@ export {
64
64
  StandardTransactionParams,
65
65
  } from './adapters/StandardAdapter';
66
66
 
67
+ export { AdapterRegistry } from './adapters/AdapterRegistry';
68
+
69
+ export {
70
+ AdapterRouter,
71
+ AdapterSelectionResult,
72
+ } from './adapters/AdapterRouter';
73
+
74
+ export {
75
+ IAdapter,
76
+ TransactionStatus,
77
+ AdapterTransactionState,
78
+ isAdapter,
79
+ } from './adapters/IAdapter';
80
+
67
81
  // =============================================================================
68
82
  // Runtime Layer - Protocol Implementation
69
83
  // =============================================================================
@@ -257,6 +271,35 @@ export type {
257
271
  // Storage constants
258
272
  export { ARCHIVE_BUNDLE_TYPE } from './storage/types';
259
273
 
274
+ // =============================================================================
275
+ // ERC-8004 Integration
276
+ // =============================================================================
277
+
278
+ export {
279
+ ERC8004Bridge,
280
+ ReputationReporter,
281
+ ERC8004Error,
282
+ ERC8004ErrorCode,
283
+ ERC8004_IDENTITY_REGISTRY,
284
+ ERC8004_REPUTATION_REGISTRY,
285
+ ERC8004_DEFAULT_RPC,
286
+ ACTP_FEEDBACK_TAGS,
287
+ } from './erc8004';
288
+
289
+ export type {
290
+ ERC8004BridgeConfig,
291
+ ReputationReporterConfig,
292
+ ReportSettlementParams,
293
+ ReportDisputeParams,
294
+ ReportResult,
295
+ ERC8004Network,
296
+ ERC8004Agent,
297
+ ERC8004AgentMetadata,
298
+ ReputationFeedback,
299
+ ReputationSummary,
300
+ ACTPFeedbackTag,
301
+ } from './erc8004';
302
+
260
303
  // =============================================================================
261
304
  // Enhanced Error Exports
262
305
  // =============================================================================
@@ -161,7 +161,7 @@ export class ACTPKernel {
161
161
  * Create a new transaction
162
162
  * Reference: Yellow Paper §3.4.1
163
163
  *
164
- * Contract signature: createTransaction(provider, requester, amount, deadline, disputeWindow, serviceHash)
164
+ * Contract signature: createTransaction(provider, requester, amount, deadline, disputeWindow, serviceHash, agentId)
165
165
  * Returns: bytes32 transactionId (generated by contract)
166
166
  */
167
167
  async createTransaction(params: CreateTransactionParams): Promise<string> {
@@ -171,7 +171,8 @@ export class ACTPKernel {
171
171
  amount,
172
172
  deadline,
173
173
  disputeWindow,
174
- metadata = '0x0000000000000000000000000000000000000000000000000000000000000000'
174
+ metadata = '0x0000000000000000000000000000000000000000000000000000000000000000',
175
+ agentId = '0' // Default to 0 (not an ERC-8004 agent)
175
176
  } = params;
176
177
 
177
178
  // Input validation
@@ -185,14 +186,15 @@ export class ACTPKernel {
185
186
  // ethers v6: use getFunction() for typed access
186
187
  const createTxFunc = this.contract.getFunction('createTransaction');
187
188
 
188
- // Contract signature: createTransaction(provider, requester, amount, deadline, disputeWindow, serviceHash)
189
+ // Contract signature: createTransaction(provider, requester, amount, deadline, disputeWindow, serviceHash, agentId)
189
190
  const estimatedGas = await createTxFunc.estimateGas(
190
191
  provider,
191
192
  requester,
192
193
  amount,
193
194
  deadline,
194
195
  disputeWindow,
195
- metadata // serviceHash
196
+ metadata, // serviceHash
197
+ BigInt(agentId) // ERC-8004 agent ID (0 = not an agent)
196
198
  );
197
199
 
198
200
  // Build tx options with gas settings (15% buffer for simple state initialization)
@@ -207,6 +209,7 @@ export class ACTPKernel {
207
209
  deadline,
208
210
  disputeWindow,
209
211
  metadata, // serviceHash
212
+ BigInt(agentId), // ERC-8004 agent ID
210
213
  txOptions
211
214
  );
212
215
 
@@ -549,6 +552,11 @@ export class ACTPKernel {
549
552
  throw new TransactionNotFoundError(txId);
550
553
  }
551
554
 
555
+ // Parse agentId - convert BigInt to string, 0n means "not an ERC-8004 agent"
556
+ const agentIdValue = typeof txData.agentId === 'bigint'
557
+ ? txData.agentId.toString()
558
+ : txData.agentId?.toString();
559
+
552
560
  return {
553
561
  txId: txData.transactionId,
554
562
  requester: txData.requester,
@@ -568,7 +576,9 @@ export class ACTPKernel {
568
576
  platformFeeBpsLocked:
569
577
  typeof txData.platformFeeBpsLocked === 'bigint'
570
578
  ? Number(txData.platformFeeBpsLocked)
571
- : txData.platformFeeBpsLocked
579
+ : txData.platformFeeBpsLocked,
580
+ // ERC-8004 agent ID (undefined or '0' means not an ERC-8004 agent)
581
+ agentId: agentIdValue && agentIdValue !== '0' ? agentIdValue : undefined
572
582
  };
573
583
  }
574
584
 
@@ -602,7 +612,15 @@ export class ACTPKernel {
602
612
  * Estimate gas for transaction creation
603
613
  */
604
614
  async estimateCreateTransaction(params: CreateTransactionParams): Promise<bigint> {
605
- const { provider, requester, amount, deadline, disputeWindow, metadata = '0x0000000000000000000000000000000000000000000000000000000000000000' } = params;
615
+ const {
616
+ provider,
617
+ requester,
618
+ amount,
619
+ deadline,
620
+ disputeWindow,
621
+ metadata = '0x0000000000000000000000000000000000000000000000000000000000000000',
622
+ agentId = '0'
623
+ } = params;
606
624
 
607
625
  // ethers v6: use getFunction()
608
626
  const createTxFunc = this.contract.getFunction('createTransaction');
@@ -612,7 +630,8 @@ export class ACTPKernel {
612
630
  amount,
613
631
  deadline,
614
632
  disputeWindow,
615
- metadata
633
+ metadata,
634
+ BigInt(agentId)
616
635
  );
617
636
  }
618
637
 
@@ -395,6 +395,8 @@ export class BlockchainRuntime implements IACTPRuntime {
395
395
  // SECURITY FIX (CRITICAL): serviceDescription should be a bytes32 hash
396
396
  // If caller passes raw string, it will fail on-chain. Basic/Standard API now hash before calling.
397
397
  metadata: this.validateServiceHash(params.serviceDescription),
398
+ // ERC-8004 agent ID - pass through if provided (see ADR-001)
399
+ agentId: params.agentId,
398
400
  });
399
401
 
400
402
  return txId;
@@ -29,6 +29,12 @@ export interface CreateTransactionParams {
29
29
  disputeWindow?: number;
30
30
  /** Service description or metadata hash */
31
31
  serviceDescription?: string;
32
+ /**
33
+ * ERC-8004 agent ID (optional).
34
+ * If set, enables reputation reporting after settlement.
35
+ * Stored in transaction for later use by ReputationReporter.
36
+ */
37
+ agentId?: string;
32
38
  }
33
39
 
34
40
  /**