@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
@@ -451,6 +451,7 @@ export class MockRuntime implements IACTPRuntime {
451
451
  serviceDescription: params.serviceDescription ?? '',
452
452
  deliveryProof: null,
453
453
  events: [],
454
+ agentId: params.agentId,
454
455
  };
455
456
 
456
457
  // Record event
@@ -464,6 +465,7 @@ export class MockRuntime implements IACTPRuntime {
464
465
  provider: params.provider,
465
466
  amount: params.amount,
466
467
  deadline: params.deadline,
468
+ agentId: params.agentId,
467
469
  },
468
470
  };
469
471
 
@@ -480,14 +482,54 @@ export class MockRuntime implements IACTPRuntime {
480
482
  /**
481
483
  * Gets a transaction by ID.
482
484
  *
485
+ * AUTO-RELEASE: If transaction is DELIVERED and dispute window has passed,
486
+ * automatically settles the transaction (lazy auto-release).
487
+ *
483
488
  * @param txId - Transaction ID
484
489
  * @returns Promise resolving to the transaction or null if not found
485
490
  */
486
491
  async getTransaction(txId: string): Promise<MockTransaction | null> {
492
+ // First, check if auto-settle is needed
493
+ await this.autoSettleIfReady(txId);
494
+
495
+ // Then return the (possibly updated) transaction
487
496
  const state = this.stateManager.loadState();
488
497
  return state.transactions[txId] ?? null;
489
498
  }
490
499
 
500
+ /**
501
+ * Auto-settle a transaction if dispute window has passed.
502
+ *
503
+ * This implements "lazy auto-release" - when anyone checks a transaction
504
+ * that is DELIVERED with expired dispute window, it automatically settles.
505
+ *
506
+ * @param txId - Transaction ID to check
507
+ */
508
+ private async autoSettleIfReady(txId: string): Promise<void> {
509
+ const state = this.stateManager.loadState();
510
+ const tx = state.transactions[txId];
511
+
512
+ if (!tx) return;
513
+ if (tx.state !== 'DELIVERED') return;
514
+ if (tx.completedAt === null) return;
515
+
516
+ const currentTime = state.blockchain.currentTime;
517
+ const disputeWindowEnd = tx.completedAt + tx.disputeWindow;
518
+
519
+ // Dispute window still active - don't auto-settle
520
+ if (currentTime < disputeWindowEnd) return;
521
+
522
+ // Dispute window passed - auto-settle!
523
+ // Find the escrow and release it
524
+ if (tx.escrowId) {
525
+ try {
526
+ await this.releaseEscrow(tx.escrowId);
527
+ } catch {
528
+ // Already settled or other issue - ignore
529
+ }
530
+ }
531
+ }
532
+
491
533
  /**
492
534
  * Gets all transactions.
493
535
  *
@@ -114,6 +114,13 @@ export interface MockTransaction {
114
114
 
115
115
  /** List of events emitted during transaction lifecycle */
116
116
  events: MockEvent[];
117
+
118
+ /**
119
+ * ERC-8004 agent ID (optional).
120
+ * If set, can be used for reputation reporting after settlement.
121
+ * Stored as string representation of uint256.
122
+ */
123
+ agentId?: string;
117
124
  }
118
125
 
119
126
  /**
@@ -0,0 +1,296 @@
1
+ /**
2
+ * Adapter types for the ACTP SDK adapter routing system.
3
+ *
4
+ * This module defines types and Zod schemas for:
5
+ * - AdapterMetadata: Capabilities and configuration for each adapter
6
+ * - PaymentMetadata: Request-level hints for adapter selection
7
+ * - UnifiedPayParams: Common payment parameters across adapters
8
+ * - UnifiedPayResult: Common result type for all adapters
9
+ *
10
+ * @module types/adapter
11
+ */
12
+
13
+ import { z } from 'zod';
14
+
15
+ // ============================================================================
16
+ // AdapterMetadata - Describes adapter capabilities
17
+ // ============================================================================
18
+
19
+ /**
20
+ * Metadata describing an adapter's capabilities.
21
+ *
22
+ * CRITICAL: All adapters must respect ACTP state machine:
23
+ * - No skipping IN_PROGRESS state
24
+ * - DELIVERED requires proof
25
+ * - releaseEscrow must be called explicitly (NO auto-settle)
26
+ */
27
+ export interface AdapterMetadata {
28
+ /** Unique adapter identifier */
29
+ id: string;
30
+
31
+ /** Human-readable name */
32
+ name: string;
33
+
34
+ /** Whether adapter uses escrow */
35
+ usesEscrow: boolean;
36
+
37
+ /** Whether adapter supports dispute resolution */
38
+ supportsDisputes: boolean;
39
+
40
+ /** Whether adapter requires on-chain identity */
41
+ requiresIdentity: boolean;
42
+
43
+ /** Supported identity types (erc8004, did, ens) */
44
+ supportedIdentityTypes?: string[];
45
+
46
+ /**
47
+ * Settlement mode:
48
+ * - 'explicit': caller must call releaseEscrow (REQUIRED for ACTP compliance)
49
+ * - 'timed': auto-release after dispute window (future, not Phase 1)
50
+ * - 'atomic': instant settlement, no escrow (x402 protocol)
51
+ */
52
+ settlementMode: 'explicit' | 'timed' | 'atomic';
53
+
54
+ /** Priority for auto-selection (higher = preferred) */
55
+ priority: number;
56
+ }
57
+
58
+ /**
59
+ * Zod schema for AdapterMetadata runtime validation.
60
+ */
61
+ export const AdapterMetadataSchema = z.object({
62
+ id: z.string().min(1),
63
+ name: z.string().min(1),
64
+ usesEscrow: z.boolean(),
65
+ supportsDisputes: z.boolean(),
66
+ requiresIdentity: z.boolean(),
67
+ supportedIdentityTypes: z.array(z.string()).optional(),
68
+ settlementMode: z.enum(['explicit', 'timed', 'atomic']),
69
+ priority: z.number().int().min(0).max(100),
70
+ });
71
+
72
+ // ============================================================================
73
+ // PaymentMetadata - Request-level hints for adapter selection
74
+ // ============================================================================
75
+
76
+ /**
77
+ * Identity information for adapter selection.
78
+ */
79
+ export interface PaymentIdentity {
80
+ type: 'erc8004' | 'did' | 'ens' | 'address';
81
+ value: string;
82
+ }
83
+
84
+ /**
85
+ * Payment request metadata for adapter selection.
86
+ */
87
+ export interface PaymentMetadata {
88
+ /** Explicitly request specific adapter */
89
+ preferredAdapter?: string;
90
+
91
+ /** Require escrow protection */
92
+ requiresEscrow?: boolean;
93
+
94
+ /** Require dispute resolution capability */
95
+ requiresDispute?: boolean;
96
+
97
+ /** Identity information */
98
+ identity?: PaymentIdentity;
99
+
100
+ /** x402 specific: payment method hint */
101
+ paymentMethod?: 'x402' | 'actp' | 'auto';
102
+ }
103
+
104
+ /**
105
+ * Zod schema for PaymentIdentity runtime validation.
106
+ */
107
+ export const PaymentIdentitySchema = z.object({
108
+ type: z.enum(['erc8004', 'did', 'ens', 'address']),
109
+ value: z.string().min(1),
110
+ });
111
+
112
+ /**
113
+ * Zod schema for PaymentMetadata runtime validation.
114
+ */
115
+ export const PaymentMetadataSchema = z.object({
116
+ preferredAdapter: z.string().optional(),
117
+ requiresEscrow: z.boolean().optional(),
118
+ requiresDispute: z.boolean().optional(),
119
+ identity: PaymentIdentitySchema.optional(),
120
+ paymentMethod: z.enum(['x402', 'actp', 'auto']).optional(),
121
+ });
122
+
123
+ // ============================================================================
124
+ // UnifiedPayParams - Common payment parameters
125
+ // ============================================================================
126
+
127
+ /**
128
+ * Unified payment parameters accepted by all adapters.
129
+ */
130
+ export interface UnifiedPayParams {
131
+ /** Recipient - address, HTTP endpoint, or ERC-8004 agent ID */
132
+ to: string;
133
+
134
+ /** Amount in human-readable format */
135
+ amount: string | number;
136
+
137
+ /** Deadline (relative like '+24h' or unix timestamp) */
138
+ deadline?: string | number;
139
+
140
+ /** Dispute window in seconds (min 3600, max 30 days) */
141
+ disputeWindow?: number;
142
+
143
+ /** Service description */
144
+ description?: string;
145
+
146
+ /** Adapter selection metadata */
147
+ metadata?: PaymentMetadata;
148
+
149
+ /**
150
+ * ERC-8004 agent ID (populated when 'to' was resolved from agentId).
151
+ * Set by AdapterRouter when resolving agent ID to wallet address.
152
+ * Used for reputation reporting after settlement.
153
+ */
154
+ erc8004AgentId?: string;
155
+ }
156
+
157
+ /**
158
+ * Minimum dispute window in seconds (1 hour).
159
+ * Ensures requesters have reasonable time to dispute.
160
+ */
161
+ const MIN_DISPUTE_WINDOW = 3600;
162
+
163
+ /**
164
+ * Maximum dispute window in seconds (30 days).
165
+ * Prevents excessively long fund locks.
166
+ */
167
+ const MAX_DISPUTE_WINDOW = 30 * 24 * 3600;
168
+
169
+ /**
170
+ * Zod schema for UnifiedPayParams with strict validation.
171
+ */
172
+ export const UnifiedPayParamsSchema = z.object({
173
+ to: z.string().min(1),
174
+ amount: z.union([z.string().min(1), z.number().positive()]),
175
+ deadline: z.union([z.string(), z.number()]).optional(),
176
+ disputeWindow: z
177
+ .number()
178
+ .int()
179
+ .min(MIN_DISPUTE_WINDOW)
180
+ .max(MAX_DISPUTE_WINDOW)
181
+ .optional(),
182
+ description: z.string().optional(),
183
+ metadata: PaymentMetadataSchema.optional(),
184
+ erc8004AgentId: z.string().optional(),
185
+ });
186
+
187
+ // ============================================================================
188
+ // UnifiedPayResult - Common result type
189
+ // ============================================================================
190
+
191
+ /**
192
+ * Transaction state after payment initiation.
193
+ *
194
+ * Note: 'COMMITTED' means funds are locked but work hasn't started.
195
+ * 'IN_PROGRESS' means provider has acknowledged and started work.
196
+ */
197
+ export type InitialTransactionState = 'COMMITTED' | 'IN_PROGRESS';
198
+
199
+ /**
200
+ * Unified payment result returned by all adapters.
201
+ *
202
+ * NOTE: success=true means payment INITIATED, not settled.
203
+ * Caller must call releaseEscrow() after delivery verification.
204
+ */
205
+ export interface UnifiedPayResult {
206
+ /** ACTP transaction ID */
207
+ txId: string;
208
+
209
+ /** Escrow ID (for release) - null for non-escrow adapters */
210
+ escrowId: string | null;
211
+
212
+ /** Adapter that handled the payment */
213
+ adapter: string;
214
+
215
+ /** Current state (COMMITTED, not SETTLED) */
216
+ state: InitialTransactionState;
217
+
218
+ /** Whether payment initiation succeeded */
219
+ success: boolean;
220
+
221
+ /** Amount locked (formatted) */
222
+ amount: string;
223
+
224
+ /** For x402: the HTTP response */
225
+ response?: Response;
226
+
227
+ /** Error message if failed */
228
+ error?: string;
229
+
230
+ /**
231
+ * IMPORTANT: Payment is NOT complete until you call:
232
+ * await client.release(result.escrowId)
233
+ *
234
+ * Always true for ACTP-compliant adapters.
235
+ */
236
+ releaseRequired: boolean;
237
+
238
+ /** Provider address (normalized to lowercase) */
239
+ provider: string;
240
+
241
+ /** Requester address (normalized to lowercase) */
242
+ requester: string;
243
+
244
+ /** Deadline as ISO 8601 timestamp */
245
+ deadline: string;
246
+
247
+ /**
248
+ * ERC-8004 agent ID (if transaction involved ERC-8004 agent).
249
+ * Use with ReputationReporter.reportSettlement() after release.
250
+ */
251
+ erc8004AgentId?: string;
252
+ }
253
+
254
+ /**
255
+ * Zod schema for UnifiedPayResult validation.
256
+ */
257
+ export const UnifiedPayResultSchema = z.object({
258
+ txId: z.string().min(1),
259
+ escrowId: z.string().nullable(),
260
+ adapter: z.string().min(1),
261
+ state: z.enum(['COMMITTED', 'IN_PROGRESS']),
262
+ success: z.boolean(),
263
+ amount: z.string().min(1),
264
+ response: z.any().optional(),
265
+ error: z.string().optional(),
266
+ releaseRequired: z.boolean(),
267
+ provider: z.string().min(1),
268
+ requester: z.string().min(1),
269
+ deadline: z.string().min(1),
270
+ erc8004AgentId: z.string().optional(),
271
+ });
272
+
273
+ // ============================================================================
274
+ // Validation Helpers
275
+ // ============================================================================
276
+
277
+ /**
278
+ * Validates UnifiedPayParams at runtime.
279
+ *
280
+ * @param params - Parameters to validate
281
+ * @returns Validated params
282
+ * @throws {z.ZodError} If validation fails
283
+ */
284
+ export function validatePayParams(params: unknown): UnifiedPayParams {
285
+ return UnifiedPayParamsSchema.parse(params);
286
+ }
287
+
288
+ /**
289
+ * Safe parse for UnifiedPayParams (doesn't throw).
290
+ *
291
+ * @param params - Parameters to validate
292
+ * @returns Result with success flag and data or error
293
+ */
294
+ export function safeValidatePayParams(params: unknown): z.SafeParseReturnType<unknown, UnifiedPayParams> {
295
+ return UnifiedPayParamsSchema.safeParse(params);
296
+ }
@@ -0,0 +1,293 @@
1
+ /**
2
+ * ERC-8004 Trustless Agents - SDK Types
3
+ *
4
+ * Types and constants for ERC-8004 integration.
5
+ *
6
+ * SECURITY NOTES:
7
+ * - Identity Registry is read-only (safe, no gas)
8
+ * - Reputation Registry writes require gas (requester pays)
9
+ * - Replay protection via feedbackHash = keccak256(txId)
10
+ * - ERC-8004 restriction: feedback submitter ≠ agent owner
11
+ *
12
+ * @see https://eips.ethereum.org/EIPS/eip-8004
13
+ * @module types/erc8004
14
+ */
15
+
16
+ // ============================================================================
17
+ // Networks
18
+ // ============================================================================
19
+
20
+ /**
21
+ * Networks with ERC-8004 registry deployments.
22
+ */
23
+ export type ERC8004Network = 'ethereum' | 'base' | 'base-sepolia';
24
+
25
+ // ============================================================================
26
+ // Identity Types (from Identity Registry)
27
+ // ============================================================================
28
+
29
+ /**
30
+ * Agent identity resolved from ERC-8004 Identity Registry.
31
+ */
32
+ export interface ERC8004Agent {
33
+ /** ERC-8004 agent ID (uint256 as string) */
34
+ agentId: string;
35
+
36
+ /** Owner address (EOA that controls the NFT) */
37
+ owner: string;
38
+
39
+ /** Payment wallet address (checksummed) */
40
+ wallet: string;
41
+
42
+ /** Agent URI (IPFS or HTTPS, points to metadata JSON) */
43
+ agentURI: string;
44
+
45
+ /** Parsed metadata from agentURI (may be undefined if fetch fails) */
46
+ metadata?: ERC8004AgentMetadata;
47
+
48
+ /** Network where agent is registered */
49
+ network: ERC8004Network;
50
+ }
51
+
52
+ /**
53
+ * Agent metadata schema from ERC-8004 agentURI.
54
+ *
55
+ * Standard fields defined by ERC-8004, plus arbitrary extensions.
56
+ */
57
+ export interface ERC8004AgentMetadata {
58
+ /** Human-readable agent name */
59
+ name?: string;
60
+
61
+ /** Agent description */
62
+ description?: string;
63
+
64
+ /** Agent avatar/logo URL */
65
+ image?: string;
66
+
67
+ /** Wallet address for receiving payments (overrides owner) */
68
+ paymentAddress?: string;
69
+
70
+ /** Alternative field name for payment address */
71
+ wallet?: string;
72
+
73
+ /** List of agent capabilities */
74
+ capabilities?: string[];
75
+
76
+ /** Service endpoints */
77
+ endpoints?: {
78
+ api?: string;
79
+ webhook?: string;
80
+ };
81
+
82
+ /** Allow arbitrary extensions */
83
+ [key: string]: unknown;
84
+ }
85
+
86
+ // ============================================================================
87
+ // Reputation Types (from Reputation Registry)
88
+ // ============================================================================
89
+
90
+ /**
91
+ * Feedback entry for ERC-8004 Reputation Registry.
92
+ *
93
+ * For ACTP settlements, we use binary values:
94
+ * - value: 1 (success) or -1 (dispute lost)
95
+ * - valueDecimals: 0 (no fractional part)
96
+ */
97
+ export interface ReputationFeedback {
98
+ /** ERC-8004 agent ID */
99
+ agentId: string;
100
+
101
+ /**
102
+ * Feedback value.
103
+ * For ACTP: 1 = successful settlement, -1 = dispute lost
104
+ */
105
+ value: number;
106
+
107
+ /**
108
+ * Decimal precision for value.
109
+ * For ACTP: always 0 (binary)
110
+ */
111
+ valueDecimals: number;
112
+
113
+ /**
114
+ * Primary tag for categorization.
115
+ * ACTP uses: 'actp_settled', 'actp_dispute_won', 'actp_dispute_lost'
116
+ */
117
+ tag1: string;
118
+
119
+ /**
120
+ * Secondary tag for filtering.
121
+ * ACTP uses: capability (e.g., 'code_generation', 'data_analysis')
122
+ */
123
+ tag2: string;
124
+
125
+ /** Service endpoint (optional) */
126
+ endpoint?: string;
127
+
128
+ /** Link to detailed feedback (optional, IPFS or HTTPS) */
129
+ feedbackURI?: string;
130
+
131
+ /**
132
+ * Hash for replay protection.
133
+ * ACTP uses: keccak256(txId)
134
+ */
135
+ feedbackHash: string;
136
+ }
137
+
138
+ /**
139
+ * Aggregated reputation summary for an agent.
140
+ */
141
+ export interface ReputationSummary {
142
+ /** ERC-8004 agent ID */
143
+ agentId: string;
144
+
145
+ /** Total feedback count */
146
+ feedbackCount: number;
147
+
148
+ /** Count of positive feedback (value > 0) */
149
+ positiveCount: number;
150
+
151
+ /** Count of negative feedback (value < 0) */
152
+ negativeCount: number;
153
+
154
+ /** Aggregated score (sum of values) */
155
+ score: number;
156
+ }
157
+
158
+ // ============================================================================
159
+ // Errors
160
+ // ============================================================================
161
+
162
+ /**
163
+ * ERC-8004 error codes.
164
+ */
165
+ export enum ERC8004ErrorCode {
166
+ // Identity errors
167
+ AGENT_NOT_FOUND = 'AGENT_NOT_FOUND',
168
+ INVALID_AGENT_ID = 'INVALID_AGENT_ID',
169
+ WALLET_NOT_FOUND = 'WALLET_NOT_FOUND',
170
+ METADATA_FETCH_FAILED = 'METADATA_FETCH_FAILED',
171
+
172
+ // Reputation errors
173
+ REPORT_FAILED = 'REPORT_FAILED',
174
+ ALREADY_REPORTED = 'ALREADY_REPORTED',
175
+ NOT_AUTHORIZED = 'NOT_AUTHORIZED',
176
+
177
+ // Network errors
178
+ NETWORK_ERROR = 'NETWORK_ERROR',
179
+ INVALID_NETWORK = 'INVALID_NETWORK',
180
+ }
181
+
182
+ /**
183
+ * Custom error for ERC-8004 operations.
184
+ */
185
+ export class ERC8004Error extends Error {
186
+ constructor(
187
+ message: string,
188
+ public readonly code: ERC8004ErrorCode,
189
+ public readonly agentId?: string,
190
+ public readonly cause?: Error
191
+ ) {
192
+ super(message);
193
+ this.name = 'ERC8004Error';
194
+
195
+ // Maintain proper stack trace in V8
196
+ if (Error.captureStackTrace) {
197
+ Error.captureStackTrace(this, ERC8004Error);
198
+ }
199
+ }
200
+ }
201
+
202
+ // ============================================================================
203
+ // Registry Addresses
204
+ // ============================================================================
205
+
206
+ /**
207
+ * ERC-8004 Identity Registry addresses per network.
208
+ *
209
+ * Canonical CREATE2 addresses from: https://github.com/erc-8004/erc-8004-contracts
210
+ * Vanity prefix 0x8004 ensures same address across all EVM chains.
211
+ */
212
+ export const ERC8004_IDENTITY_REGISTRY: Record<ERC8004Network, string> = {
213
+ ethereum: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432', // Ethereum Mainnet
214
+ base: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432', // Base Mainnet
215
+ 'base-sepolia': '0x8004A818BFB912233c491871b3d84c89A494BD9e', // Base Sepolia
216
+ };
217
+
218
+ /**
219
+ * ERC-8004 Reputation Registry addresses per network.
220
+ *
221
+ * Canonical CREATE2 addresses from: https://github.com/erc-8004/erc-8004-contracts
222
+ * Vanity prefix 0x8004 ensures same address across all EVM chains.
223
+ */
224
+ export const ERC8004_REPUTATION_REGISTRY: Record<ERC8004Network, string> = {
225
+ ethereum: '0x8004BAa17C55a88189AE136b182e5fdA19dE9b63', // Ethereum Mainnet
226
+ base: '0x8004BAa17C55a88189AE136b182e5fdA19dE9b63', // Base Mainnet
227
+ 'base-sepolia': '0x8004B663056A597Dffe9eCcC1965A193B7388713', // Base Sepolia
228
+ };
229
+
230
+ // ============================================================================
231
+ // ABI Fragments (minimal, view-only for Bridge)
232
+ // ============================================================================
233
+
234
+ /**
235
+ * Minimal ABI for ERC-8004 Identity Registry.
236
+ * Only includes view functions needed by ERC8004Bridge.
237
+ */
238
+ export const ERC8004_IDENTITY_ABI = [
239
+ 'function ownerOf(uint256 agentId) view returns (address)',
240
+ 'function getAgentURI(uint256 agentId) view returns (string)',
241
+ 'function balanceOf(address owner) view returns (uint256)',
242
+ 'function tokenOfOwnerByIndex(address owner, uint256 index) view returns (uint256)',
243
+ ] as const;
244
+
245
+ /**
246
+ * Minimal ABI for ERC-8004 Reputation Registry.
247
+ * Includes both read and write functions.
248
+ */
249
+ export const ERC8004_REPUTATION_ABI = [
250
+ // Write
251
+ 'function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash) external',
252
+ 'function revokeLatest(uint256 agentId, uint64 feedbackIndex) external',
253
+ // Read
254
+ 'function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) view returns (uint256 count, int256 summaryValue, uint8 summaryValueDecimals)',
255
+ 'function readFeedback(uint256 agentId, uint64 feedbackIndex) view returns (tuple(int128 value, uint8 valueDecimals, string tag1, string tag2, bool isRevoked, uint64 feedbackIndex))',
256
+ ] as const;
257
+
258
+ // ============================================================================
259
+ // Default RPC URLs
260
+ // ============================================================================
261
+
262
+ /**
263
+ * Default RPC URLs for each network.
264
+ * Used when no custom RPC is provided.
265
+ */
266
+ export const ERC8004_DEFAULT_RPC: Record<ERC8004Network, string> = {
267
+ ethereum: 'https://eth.llamarpc.com',
268
+ base: 'https://mainnet.base.org',
269
+ 'base-sepolia': 'https://sepolia.base.org',
270
+ };
271
+
272
+ // ============================================================================
273
+ // ACTP-specific constants
274
+ // ============================================================================
275
+
276
+ /**
277
+ * ACTP feedback tags for ERC-8004 Reputation.
278
+ */
279
+ export const ACTP_FEEDBACK_TAGS = {
280
+ /** Successful settlement */
281
+ SETTLED: 'actp_settled',
282
+
283
+ /** Agent won dispute */
284
+ DISPUTE_WON: 'actp_dispute_won',
285
+
286
+ /** Agent lost dispute (requester won) */
287
+ DISPUTE_LOST: 'actp_dispute_lost',
288
+ } as const;
289
+
290
+ /**
291
+ * Type for ACTP feedback tags.
292
+ */
293
+ export type ACTPFeedbackTag = (typeof ACTP_FEEDBACK_TAGS)[keyof typeof ACTP_FEEDBACK_TAGS];
@@ -9,6 +9,9 @@ export * from './message';
9
9
  export * from './eip712';
10
10
  export * from './agent';
11
11
  export * from './did';
12
+ export * from './adapter';
13
+ export * from './x402';
14
+ export * from './erc8004';
12
15
  // Note: storage and archive types are not yet implemented in this version
13
16
  // export * from './storage';
14
17
  // export * from './archive';
@@ -20,6 +20,12 @@ export interface Transaction {
20
20
  attestationUID: string;
21
21
  metadata: string;
22
22
  platformFeeBpsLocked: number;
23
+ /**
24
+ * ERC-8004 agent token ID (optional).
25
+ * 0 or undefined = not an ERC-8004 agent.
26
+ * See ADR-001 for architectural rationale.
27
+ */
28
+ agentId?: string;
23
29
  }
24
30
 
25
31
  /**
@@ -32,6 +38,12 @@ export interface CreateTransactionParams {
32
38
  deadline: number;
33
39
  disputeWindow: number;
34
40
  metadata?: string;
41
+ /**
42
+ * ERC-8004 agent token ID (optional).
43
+ * Set to 0 or omit if provider is not registered in ERC-8004 Identity Registry.
44
+ * See ADR-001 for architectural rationale.
45
+ */
46
+ agentId?: string;
35
47
  }
36
48
 
37
49
  /**