@agirails/sdk 2.0.4 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +536 -87
  2. package/dist/adapters/BasicAdapter.d.ts.map +1 -1
  3. package/dist/adapters/BasicAdapter.js +8 -0
  4. package/dist/adapters/BasicAdapter.js.map +1 -1
  5. package/dist/adapters/StandardAdapter.d.ts +10 -5
  6. package/dist/adapters/StandardAdapter.d.ts.map +1 -1
  7. package/dist/adapters/StandardAdapter.js +19 -6
  8. package/dist/adapters/StandardAdapter.js.map +1 -1
  9. package/dist/config/networks.d.ts +9 -0
  10. package/dist/config/networks.d.ts.map +1 -1
  11. package/dist/config/networks.js +25 -10
  12. package/dist/config/networks.js.map +1 -1
  13. package/dist/index.d.ts +6 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +31 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/level0/provide.d.ts.map +1 -1
  18. package/dist/level0/provide.js +2 -1
  19. package/dist/level0/provide.js.map +1 -1
  20. package/dist/level1/Agent.d.ts.map +1 -1
  21. package/dist/level1/Agent.js +11 -3
  22. package/dist/level1/Agent.js.map +1 -1
  23. package/dist/protocol/ACTPKernel.d.ts.map +1 -1
  24. package/dist/protocol/ACTPKernel.js +7 -5
  25. package/dist/protocol/ACTPKernel.js.map +1 -1
  26. package/dist/protocol/DIDResolver.js +1 -1
  27. package/dist/protocol/DIDResolver.js.map +1 -1
  28. package/dist/protocol/EASHelper.d.ts.map +1 -1
  29. package/dist/protocol/EASHelper.js +2 -3
  30. package/dist/protocol/EASHelper.js.map +1 -1
  31. package/dist/protocol/MessageSigner.d.ts.map +1 -1
  32. package/dist/protocol/MessageSigner.js +8 -8
  33. package/dist/protocol/MessageSigner.js.map +1 -1
  34. package/dist/runtime/BlockchainRuntime.d.ts +7 -0
  35. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  36. package/dist/runtime/BlockchainRuntime.js +38 -22
  37. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  38. package/dist/runtime/IACTPRuntime.d.ts +15 -0
  39. package/dist/runtime/IACTPRuntime.d.ts.map +1 -1
  40. package/dist/runtime/MockRuntime.d.ts +7 -0
  41. package/dist/runtime/MockRuntime.d.ts.map +1 -1
  42. package/dist/runtime/MockRuntime.js +15 -4
  43. package/dist/runtime/MockRuntime.js.map +1 -1
  44. package/dist/runtime/types/MockState.d.ts +5 -2
  45. package/dist/runtime/types/MockState.d.ts.map +1 -1
  46. package/dist/runtime/types/MockState.js.map +1 -1
  47. package/dist/storage/ArchiveBundleBuilder.d.ts +150 -0
  48. package/dist/storage/ArchiveBundleBuilder.d.ts.map +1 -0
  49. package/dist/storage/ArchiveBundleBuilder.js +468 -0
  50. package/dist/storage/ArchiveBundleBuilder.js.map +1 -0
  51. package/dist/storage/ArweaveClient.d.ts +271 -0
  52. package/dist/storage/ArweaveClient.d.ts.map +1 -0
  53. package/dist/storage/ArweaveClient.js +761 -0
  54. package/dist/storage/ArweaveClient.js.map +1 -0
  55. package/dist/storage/FilebaseClient.d.ts +193 -0
  56. package/dist/storage/FilebaseClient.d.ts.map +1 -0
  57. package/dist/storage/FilebaseClient.js +643 -0
  58. package/dist/storage/FilebaseClient.js.map +1 -0
  59. package/dist/storage/index.d.ts +47 -0
  60. package/dist/storage/index.d.ts.map +1 -0
  61. package/dist/storage/index.js +64 -0
  62. package/dist/storage/index.js.map +1 -0
  63. package/dist/storage/types.d.ts +291 -0
  64. package/dist/storage/types.d.ts.map +1 -0
  65. package/dist/storage/types.js +18 -0
  66. package/dist/storage/types.js.map +1 -0
  67. package/dist/types/state.d.ts +5 -4
  68. package/dist/types/state.d.ts.map +1 -1
  69. package/dist/types/state.js +10 -9
  70. package/dist/types/state.js.map +1 -1
  71. package/dist/utils/IPFSClient.d.ts.map +1 -1
  72. package/dist/utils/IPFSClient.js +5 -2
  73. package/dist/utils/IPFSClient.js.map +1 -1
  74. package/dist/utils/NonceManager.d.ts.map +1 -1
  75. package/dist/utils/NonceManager.js +3 -2
  76. package/dist/utils/NonceManager.js.map +1 -1
  77. package/dist/utils/UsedAttestationTracker.d.ts.map +1 -1
  78. package/dist/utils/UsedAttestationTracker.js +3 -3
  79. package/dist/utils/UsedAttestationTracker.js.map +1 -1
  80. package/dist/utils/circuitBreaker.d.ts +136 -0
  81. package/dist/utils/circuitBreaker.d.ts.map +1 -0
  82. package/dist/utils/circuitBreaker.js +253 -0
  83. package/dist/utils/circuitBreaker.js.map +1 -0
  84. package/dist/utils/retry.d.ts +120 -0
  85. package/dist/utils/retry.d.ts.map +1 -0
  86. package/dist/utils/retry.js +260 -0
  87. package/dist/utils/retry.js.map +1 -0
  88. package/dist/utils/validation.d.ts +100 -0
  89. package/dist/utils/validation.d.ts.map +1 -1
  90. package/dist/utils/validation.js +248 -1
  91. package/dist/utils/validation.js.map +1 -1
  92. package/package.json +14 -2
  93. package/src/adapters/BasicAdapter.ts +11 -0
  94. package/src/adapters/StandardAdapter.ts +26 -6
  95. package/src/config/networks.ts +34 -10
  96. package/src/index.ts +54 -0
  97. package/src/level0/provide.ts +2 -1
  98. package/src/level1/Agent.ts +13 -3
  99. package/src/protocol/ACTPKernel.ts +7 -5
  100. package/src/protocol/DIDResolver.ts +1 -1
  101. package/src/protocol/EASHelper.ts +2 -5
  102. package/src/protocol/MessageSigner.ts +8 -14
  103. package/src/runtime/BlockchainRuntime.ts +39 -45
  104. package/src/runtime/IACTPRuntime.ts +16 -0
  105. package/src/runtime/MockRuntime.ts +16 -4
  106. package/src/runtime/types/MockState.ts +5 -2
  107. package/src/storage/ArchiveBundleBuilder.ts +563 -0
  108. package/src/storage/ArweaveClient.ts +945 -0
  109. package/src/storage/FilebaseClient.ts +790 -0
  110. package/src/storage/index.ts +96 -0
  111. package/src/storage/types.ts +348 -0
  112. package/src/types/state.ts +10 -9
  113. package/src/utils/IPFSClient.ts +5 -4
  114. package/src/utils/NonceManager.ts +3 -2
  115. package/src/utils/UsedAttestationTracker.ts +3 -5
  116. package/src/utils/circuitBreaker.ts +324 -0
  117. package/src/utils/fsSafe.ts +5 -0
  118. package/src/utils/retry.ts +365 -0
  119. package/src/utils/validation.ts +295 -1
package/README.md CHANGED
@@ -1,6 +1,20 @@
1
- # @agirails/sdk
1
+ # AGIRAILS TypeScript SDK
2
2
 
3
- TypeScript SDK for the **ACTP (Agent Commerce Transaction Protocol)** - enabling AI agents to transact, escrow funds, and settle payments autonomously.
3
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
4
+ [![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/)
5
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
+ [![Tests](https://img.shields.io/badge/tests-773%20passed-brightgreen.svg)]()
7
+
8
+ The official TypeScript SDK for the **Agent Commerce Transaction Protocol (ACTP)** - enabling AI agents to transact with each other through blockchain-based escrow.
9
+
10
+ ## Features
11
+
12
+ - **Three-tier API**: Basic, Standard, and Advanced levels for different use cases
13
+ - **Mock Runtime**: Full local testing without blockchain connection
14
+ - **Type-safe**: Complete TypeScript types with strict mode support
15
+ - **Async/Await**: Promise-based API for modern async workflows
16
+ - **Comprehensive Errors**: Structured exception types with error codes
17
+ - **Security Built-in**: EIP-712 signing, replay protection, safe nonce management
4
18
 
5
19
  ## Installation
6
20
 
@@ -8,175 +22,610 @@ TypeScript SDK for the **ACTP (Agent Commerce Transaction Protocol)** - enabling
8
22
  npm install @agirails/sdk
9
23
  ```
10
24
 
25
+ Or with yarn:
26
+
27
+ ```bash
28
+ yarn add @agirails/sdk
29
+ ```
30
+
11
31
  ## Quick Start
12
32
 
13
- ### Basic API
33
+ ### Testnet Quickstart (Base Sepolia)
34
+
35
+ Get started with real transactions on Base Sepolia testnet:
36
+
37
+ ```bash
38
+ # Install CLI globally
39
+ npm install -g @agirails/sdk
40
+
41
+ # Initialize configuration
42
+ actp init --network base-sepolia
43
+
44
+ # Set your private key (or use PRIVATE_KEY env var)
45
+ actp config set private-key YOUR_PRIVATE_KEY
46
+
47
+ # Note: mint is mock mode only. For testnet/mainnet, bridge real USDC via bridge.base.org
48
+ # In mock mode:
49
+ actp mint --amount 1000 # Mint 1000 test USDC (mock mode only)
50
+
51
+ # Check your balance
52
+ actp balance
53
+
54
+ # Make a payment
55
+ actp pay 0xProviderAddress 100 --deadline 24h
56
+
57
+ # Watch transaction status
58
+ actp watch TX_ID
59
+ ```
60
+
61
+ ### Basic API - Simple Payments
62
+
63
+ The simplest way to make a payment - just specify who, how much, and go:
14
64
 
15
65
  ```typescript
16
66
  import { ACTPClient } from '@agirails/sdk';
17
67
 
18
- const client = await ACTPClient.create({
19
- network: 'base-sepolia',
20
- privateKey: process.env.PRIVATE_KEY
21
- });
68
+ async function main() {
69
+ // Create client in mock mode (no blockchain needed)
70
+ const client = await ACTPClient.create({
71
+ mode: 'mock',
72
+ requesterAddress: '0x1111111111111111111111111111111111111111',
73
+ });
74
+
75
+ // Pay a provider
76
+ const result = await client.basic.pay({
77
+ to: '0xabcdefABCDEFabcdefABCDEFabcdefABCDEFabcd',
78
+ amount: '100.00', // $100 USDC
79
+ deadline: '24h', // Optional: expires in 24 hours
80
+ });
81
+
82
+ console.log('Transaction ID:', result.txId);
83
+ console.log('State:', result.state);
84
+ }
85
+
86
+ main();
87
+ ```
22
88
 
23
- // One-liner: pay an AI agent for a service
24
- const result = await client.basic.pay({
25
- provider: '0xProviderAddress...',
26
- amount: '10.00', // 10 USDC
27
- service: 'echo'
28
- });
89
+ ### Standard API - Full Lifecycle Control
90
+
91
+ For applications that need explicit control over each transaction step:
29
92
 
30
- console.log('Transaction ID:', result.txId);
31
- console.log('Status:', result.status);
93
+ ```typescript
94
+ import { ACTPClient } from '@agirails/sdk';
95
+ import { ethers } from 'ethers';
96
+
97
+ async function main() {
98
+ const client = await ACTPClient.create({
99
+ mode: 'testnet', // or 'mainnet' for production
100
+ requesterAddress: '0x1111111111111111111111111111111111111111',
101
+ privateKey: process.env.PRIVATE_KEY,
102
+ });
103
+
104
+ // Step 1: Create transaction (no funds locked yet)
105
+ const txId = await client.standard.createTransaction({
106
+ provider: '0xabcdefABCDEFabcdefABCDEFabcdefABCDEFabcd',
107
+ amount: '100.50',
108
+ deadline: '7d',
109
+ disputeWindow: 172800, // 2 days in seconds
110
+ });
111
+ console.log('Created transaction:', txId);
112
+
113
+ // Step 2: Link escrow (locks funds, moves to COMMITTED)
114
+ const escrowId = await client.standard.linkEscrow(txId);
115
+ console.log('Escrow linked:', escrowId);
116
+
117
+ // Step 3: Provider starts work (REQUIRED before DELIVERED!)
118
+ await client.standard.transitionState(txId, 'IN_PROGRESS');
119
+
120
+ // Step 4: Provider delivers with dispute window proof
121
+ const abiCoder = ethers.AbiCoder.defaultAbiCoder();
122
+ const disputeWindowProof = abiCoder.encode(['uint256'], [172800]); // 2 days
123
+ await client.standard.transitionState(txId, 'DELIVERED', disputeWindowProof);
124
+
125
+ // Step 5: Release funds to provider (after dispute window)
126
+ await client.standard.releaseEscrow(txId);
127
+ console.log('Payment complete!');
128
+ }
129
+
130
+ main();
32
131
  ```
33
132
 
34
- ### Standard API
133
+ ### Advanced API - Direct Runtime Access
134
+
135
+ For custom workflows and maximum flexibility:
35
136
 
36
137
  ```typescript
37
138
  import { ACTPClient } from '@agirails/sdk';
38
139
 
140
+ async function main() {
141
+ const client = await ACTPClient.create({
142
+ mode: 'mock',
143
+ requesterAddress: '0x1111111111111111111111111111111111111111',
144
+ });
145
+
146
+ // Direct runtime access
147
+ const runtime = client.advanced;
148
+
149
+ // Create transaction with full control
150
+ const txId = await runtime.createTransaction({
151
+ requester: '0x...',
152
+ provider: '0x...',
153
+ amount: '1000000', // Raw wei
154
+ deadline: 1735689600,
155
+ disputeWindow: 86400,
156
+ serviceDescription: '0x...'
157
+ });
158
+
159
+ // Get transaction details
160
+ const tx = await runtime.getTransaction(txId);
161
+ console.log('State:', tx.state, 'Amount:', tx.amount);
162
+ }
163
+
164
+ main();
165
+ ```
166
+
167
+ ## Transaction Lifecycle
168
+
169
+ ACTP transactions follow an 8-state lifecycle:
170
+
171
+ ```
172
+ INITIATED → QUOTED → COMMITTED → IN_PROGRESS → DELIVERED → SETTLED
173
+ ↘ ↘ ↘
174
+ CANCELLED CANCELLED DISPUTED → SETTLED
175
+ ```
176
+
177
+ | State | Description |
178
+ |-------|-------------|
179
+ | `INITIATED` | Transaction created, no escrow linked |
180
+ | `QUOTED` | Provider submitted price quote (optional) |
181
+ | `COMMITTED` | Escrow linked, funds locked |
182
+ | `IN_PROGRESS` | Provider actively working (optional) |
183
+ | `DELIVERED` | Work delivered with proof |
184
+ | `SETTLED` | Payment released (terminal) |
185
+ | `DISPUTED` | Under dispute resolution |
186
+ | `CANCELLED` | Cancelled before completion (terminal) |
187
+
188
+ ## Configuration
189
+
190
+ ### Client Modes
191
+
192
+ ```typescript
193
+ // Mock mode - local testing, no blockchain
39
194
  const client = await ACTPClient.create({
40
- network: 'base-sepolia',
41
- privateKey: process.env.PRIVATE_KEY
195
+ mode: 'mock',
196
+ requesterAddress: '0x1111111111111111111111111111111111111111',
197
+ stateDirectory: '.actp' // Optional: persist state to disk
42
198
  });
43
199
 
44
- // 1. Create transaction
45
- const txId = await client.standard.createTransaction({
46
- provider: '0xProviderAddress...',
47
- amount: '10.00',
48
- serviceRef: 'ipfs://Qm...'
200
+ // Testnet mode - Base Sepolia
201
+ const client = await ACTPClient.create({
202
+ mode: 'testnet',
203
+ requesterAddress: '0x1111111111111111111111111111111111111111',
204
+ privateKey: '0x...',
205
+ rpcUrl: 'https://sepolia.base.org' // Optional: custom RPC
49
206
  });
50
207
 
51
- // 2. Link escrow (funds locked, state → COMMITTED)
52
- await client.standard.linkEscrow(txId);
208
+ // Mainnet mode - Base
209
+ const client = await ACTPClient.create({
210
+ mode: 'mainnet',
211
+ requesterAddress: '0x1111111111111111111111111111111111111111',
212
+ privateKey: '0x...'
213
+ });
214
+ ```
215
+
216
+ ### Amount Formats
217
+
218
+ The SDK accepts amounts in multiple formats:
219
+
220
+ ```typescript
221
+ // All equivalent to $100.50 USDC
222
+ await client.basic.pay({ to: '0x...', amount: 100.50 });
223
+ await client.basic.pay({ to: '0x...', amount: '100.50' });
224
+ await client.basic.pay({ to: '0x...', amount: '$100.50' });
225
+ await client.basic.pay({ to: '0x...', amount: '100500000' }); // Wei
226
+ ```
227
+
228
+ ### Deadline Formats
53
229
 
54
- // 3. Provider delivers (after work is done)
55
- await client.standard.transitionState(txId, 'DELIVERED');
230
+ ```typescript
231
+ // Relative formats
232
+ deadline: '1h' // 1 hour from now
233
+ deadline: '24h' // 24 hours from now
234
+ deadline: '7d' // 7 days from now
235
+
236
+ // Absolute timestamp
237
+ deadline: 1735689600 // Unix timestamp
56
238
 
57
- // 4. Release payment to provider
58
- await client.standard.releaseEscrow(txId);
239
+ // ISO date string
240
+ deadline: '2025-01-01T00:00:00Z'
59
241
  ```
60
242
 
61
- ### Check Transaction Status
243
+ ## Error Handling
244
+
245
+ The SDK provides structured exceptions with error codes:
62
246
 
63
247
  ```typescript
64
- const status = await client.basic.checkStatus(txId);
65
- console.log(status.state); // 'COMMITTED', 'DELIVERED', 'SETTLED', etc.
66
- console.log(status.amount); // '10.00'
67
- console.log(status.provider); // '0x...'
248
+ import {
249
+ ACTPError,
250
+ TransactionNotFoundError,
251
+ InvalidStateTransitionError,
252
+ InsufficientBalanceError,
253
+ ValidationError
254
+ } from '@agirails/sdk';
255
+
256
+ try {
257
+ await client.basic.pay({ to: 'invalid', amount: 100 });
258
+ } catch (error) {
259
+ if (error instanceof ValidationError) {
260
+ console.log('Validation failed:', error.message);
261
+ console.log('Error code:', error.code);
262
+ console.log('Details:', error.details);
263
+ } else if (error instanceof InsufficientBalanceError) {
264
+ console.log(`Need ${error.required}, have ${error.available}`);
265
+ } else if (error instanceof ACTPError) {
266
+ console.log(`ACTP error [${error.code}]: ${error.message}`);
267
+ }
268
+ }
68
269
  ```
69
270
 
70
- ## CLI Usage
271
+ ### Exception Hierarchy
272
+
273
+ ```
274
+ ACTPError (base)
275
+ ├── TransactionNotFoundError
276
+ ├── InvalidStateTransitionError
277
+ ├── EscrowNotFoundError
278
+ ├── InsufficientBalanceError
279
+ ├── DeadlinePassedError
280
+ ├── DisputeWindowActiveError
281
+ ├── ContractPausedError
282
+ ├── ValidationError
283
+ │ ├── InvalidAddressError
284
+ │ └── InvalidAmountError
285
+ ├── NetworkError
286
+ │ ├── TransactionRevertedError
287
+ │ └── SignatureVerificationError
288
+ ├── StorageError
289
+ │ ├── InvalidCIDError
290
+ │ ├── UploadTimeoutError
291
+ │ └── ContentNotFoundError
292
+ └── AgentLifecycleError
293
+ ```
294
+
295
+ ## CLI Reference
296
+
297
+ The SDK includes a full-featured CLI for interacting with ACTP:
298
+
299
+ ### Core Commands
71
300
 
72
301
  ```bash
73
- # Install globally
74
- npm install -g @agirails/sdk
302
+ # Payment operations
303
+ actp pay <provider> <amount> [--deadline TIME] [--service TEXT]
304
+ actp balance [ADDRESS]
305
+ actp mint --amount AMOUNT # Mock mode only
306
+
307
+ # Transaction management
308
+ actp list [--state STATE] [--limit N]
309
+ actp status <tx_id>
310
+ actp cancel <tx_id>
311
+
312
+ # Time manipulation (mock mode only)
313
+ actp time advance <seconds>
314
+ actp time set <timestamp>
315
+ actp time now
316
+ ```
75
317
 
76
- # Initialize configuration
77
- actp init
318
+ ### Agent-First Features
319
+
320
+ ```bash
321
+ # Watch transaction state changes (streams updates)
322
+ actp watch <tx_id> [--interval SECONDS] [--format json|text]
323
+
324
+ # Batch operations from file
325
+ actp batch <command_file> [--parallel N] [--continue-on-error]
78
326
 
79
- # Create a transaction
80
- actp create --provider 0x... --amount 10 --service "echo service"
327
+ # Dry-run simulation
328
+ actp simulate pay <provider> <amount>
329
+ actp simulate fee <amount>
330
+ ```
81
331
 
82
- # Check transaction status
83
- actp status <txId>
332
+ ### Configuration
84
333
 
85
- # List your transactions
334
+ ```bash
335
+ # Set configuration
336
+ actp config set <key> <value>
337
+ actp config get <key>
338
+ actp config list
339
+ actp config reset
340
+
341
+ # Available config keys:
342
+ # network: base-sepolia | base-mainnet | mock
343
+ # rpc-url: RPC endpoint URL
344
+ # private-key: Wallet private key (or use PRIVATE_KEY env)
345
+ # state-directory: Directory for mock state persistence
346
+ ```
347
+
348
+ ### Output Formats
349
+
350
+ ```bash
351
+ # Human-readable (default)
86
352
  actp list
353
+
354
+ # JSON output for scripting
355
+ actp list --format json
356
+
357
+ # NDJSON streaming for watch
358
+ actp watch TX_ID --format ndjson
87
359
  ```
88
360
 
89
- ## Mock Mode (Testing)
361
+ ## Testing
362
+
363
+ Run the test suite:
364
+
365
+ ```bash
366
+ # Run all tests
367
+ npm test
368
+
369
+ # Run with verbose output
370
+ npm test -- --verbose
371
+
372
+ # Run specific test file
373
+ npm test -- src/__tests__/client.test.ts
374
+
375
+ # Run tests matching pattern
376
+ npm test -- --testNamePattern="pay"
377
+
378
+ # Run with coverage
379
+ npm run test:coverage
380
+ ```
381
+
382
+ ## API Reference
383
+
384
+ ### ACTPClient
385
+
386
+ | Method | Description |
387
+ |--------|-------------|
388
+ | `ACTPClient.create(config)` | Factory method to create client |
389
+ | `client.basic` | Access basic adapter |
390
+ | `client.standard` | Access standard adapter |
391
+ | `client.advanced` | Access runtime directly |
392
+ | `client.getBalance()` | Get USDC balance |
393
+ | `client.reset()` | Reset mock state |
90
394
 
91
- Test without blockchain - no gas fees, instant transactions:
395
+ ### BasicAdapter
396
+
397
+ | Method | Description |
398
+ |--------|-------------|
399
+ | `pay(params)` | Create and fund transaction |
400
+ | `checkStatus(txId)` | Get transaction status |
401
+ | `getBalance()` | Get formatted balance |
402
+
403
+ ### StandardAdapter
404
+
405
+ | Method | Description |
406
+ |--------|-------------|
407
+ | `createTransaction(params)` | Create transaction |
408
+ | `linkEscrow(txId)` | Link escrow and lock funds |
409
+ | `transitionState(txId, state, proof?)` | Transition to new state |
410
+ | `releaseEscrow(txId)` | Release funds |
411
+ | `getTransaction(txId)` | Get transaction details |
412
+ | `getAllTransactions()` | List all transactions |
413
+
414
+ ## Level 0 & Level 1 APIs
415
+
416
+ ### Level 0 - Low-level Primitives
92
417
 
93
418
  ```typescript
94
- import { ACTPClient } from '@agirails/sdk';
419
+ import { ServiceDirectory, request, provide } from '@agirails/sdk';
95
420
 
96
- const client = await ACTPClient.create({
97
- mode: 'mock'
421
+ // Register a service
422
+ const directory = new ServiceDirectory();
423
+ directory.register('text-gen', {
424
+ providerAddress: '0x...',
425
+ capabilities: ['gpt-4']
98
426
  });
99
427
 
100
- // Full ACTP flow works identically
101
- const result = await client.basic.pay({
102
- provider: '0x1234...',
103
- amount: '5.00',
104
- service: 'test-service'
428
+ // Find providers
429
+ const providers = directory.find({ capabilities: ['gpt-4'] });
430
+ ```
431
+
432
+ ### Level 1 - Agent Framework
433
+
434
+ ```typescript
435
+ import { Agent, AgentConfig } from '@agirails/sdk';
436
+
437
+ // Create an agent
438
+ const agent = new Agent({
439
+ name: 'my-agent',
440
+ address: '0x...',
441
+ services: ['text-generation']
442
+ });
443
+
444
+ // Handle jobs
445
+ agent.onJob(async (job) => {
446
+ return { result: `Processed: ${job.input}` };
105
447
  });
448
+
449
+ await agent.start();
106
450
  ```
107
451
 
452
+ ## SDK Parity
453
+
454
+ This TypeScript SDK maintains **full parity** with the Python SDK:
455
+
456
+ | Feature | TypeScript SDK | Python SDK |
457
+ |---------|----------------|------------|
458
+ | DeliveryProof Schema | AIP-4 v1.1 (12 fields) | AIP-4 v1.1 (12 fields) |
459
+ | Result Hashing | keccak256 | keccak256 |
460
+ | JSON Canonicalization | Insertion order | Insertion order |
461
+ | EIP-712 Signing | Full support | Full support |
462
+ | Level0 API | Full ACTP flow | Full ACTP flow |
463
+ | Level1 Agent API | Complete | Complete |
464
+ | CLI Commands | watch, batch, simulate | watch, batch, simulate |
465
+ | Nonce Tracking | SecureNonce, ReceivedNonceTracker | SecureNonce, ReceivedNonceTracker |
466
+ | Attestation Tracking | UsedAttestationTracker | UsedAttestationTracker |
467
+
468
+ **Shared Test Vectors**: Both SDKs use the same JSON test fixtures to ensure identical behavior.
469
+
108
470
  ## Networks
109
471
 
110
472
  | Network | Chain ID | Status |
111
473
  |---------|----------|--------|
112
474
  | Base Sepolia | 84532 | ✅ Active (Testnet) |
113
- | Base Mainnet | 8453 | ⏳ Not Deployed |
475
+ | Base Mainnet | 8453 | ⏳ Coming Soon |
476
+
477
+ ## Fee Structure
478
+
479
+ - **Platform Fee**: 1% of transaction amount
480
+ - **Minimum Fee**: $0.05 USDC
481
+
482
+ ## Security
114
483
 
115
- > **Note**: Mainnet contracts are not yet deployed. Using `network: 'base-mainnet'` will throw an error. Use `'base-sepolia'` for development and testing.
484
+ - **EIP-712 Signing**: Typed structured data for secure message signing
485
+ - **Replay Protection**: Nonce management prevents transaction replay
486
+ - **Non-custodial Escrow**: 2-of-2 release pattern
487
+ - **EAS Integration**: Ethereum Attestation Service for delivery proofs
488
+ - **Input Validation**: All user inputs validated before processing
116
489
 
117
- ## Transaction States
490
+ ## Decentralized Identifiers (DIDs)
491
+
492
+ AGIRAILS uses **did:ethr** DIDs based on the [ERC-1056](https://eips.ethereum.org/EIPS/eip-1056) standard for identity management.
493
+
494
+ ### DID Format
495
+
496
+ Every Ethereum address automatically IS a DID - no registration required:
118
497
 
119
498
  ```
120
- INITIATED → QUOTED → COMMITTED → IN_PROGRESS → DELIVERED → SETTLED
121
-
122
- DISPUTED → SETTLED
499
+ did:ethr:84532:0x742d35cc6634c0532925a3b844bc9e7595f0beb
500
+ ↑ ↑
501
+ chainId address
123
502
  ```
124
503
 
125
- ## API Layers
504
+ ### Basic Usage
126
505
 
127
- ### Basic
506
+ ```typescript
507
+ import { DIDResolver } from '@agirails/sdk';
508
+
509
+ // Build DID from address (no registration needed!)
510
+ const did = DIDResolver.buildDID('0x742d35cc6634c0532925a3b844bc9e7595f0beb', 84532);
511
+ // → 'did:ethr:84532:0x742d35cc6634c0532925a3b844bc9e7595f0beb'
512
+
513
+ // Parse DID components
514
+ const parsed = DIDResolver.parseDID(did);
515
+ console.log(parsed.method); // 'ethr'
516
+ console.log(parsed.chainId); // 84532
517
+ console.log(parsed.address); // '0x742d35cc6634c0532925a3b844bc9e7595f0beb'
518
+
519
+ // Validate DID format
520
+ const isValid = DIDResolver.isValidDID(did); // true
521
+ ```
522
+
523
+ ### Resolve DID to DID Document
128
524
 
129
525
  ```typescript
130
- client.basic.pay(params) // Create, fund, and track in one call
131
- client.basic.checkStatus(txId) // Get human-readable status
526
+ import { DIDResolver } from '@agirails/sdk';
527
+
528
+ // Create resolver for Base Sepolia
529
+ const resolver = await DIDResolver.create({ network: 'base-sepolia' });
530
+
531
+ // Resolve DID to W3C DID Document
532
+ const result = await resolver.resolve('did:ethr:84532:0x742d35cc...');
533
+
534
+ if (result.didDocument) {
535
+ console.log('Controller:', result.didDocument.controller);
536
+ console.log('Verification Methods:', result.didDocument.verificationMethod);
537
+ console.log('Service Endpoints:', result.didDocument.service);
538
+ }
132
539
  ```
133
540
 
134
- ### Standard
541
+ ### Verify Signatures
135
542
 
136
543
  ```typescript
137
- client.standard.createTransaction(params) // Create transaction
138
- client.standard.linkEscrow(txId) // Lock funds in escrow
139
- client.standard.transitionState(txId, state) // Change state
140
- client.standard.releaseEscrow(txId) // Release funds to provider
141
- client.standard.getTransaction(txId) // Get transaction details
142
- client.standard.getEscrowBalance(escrowId) // Check locked amount
544
+ import { DIDResolver } from '@agirails/sdk';
545
+
546
+ const resolver = await DIDResolver.create({ network: 'base-sepolia' });
547
+
548
+ // Verify a signature was made by a DID's controller (or authorized delegate)
549
+ const result = await resolver.verifySignature(
550
+ 'did:ethr:84532:0x742d35cc...', // DID
551
+ 'Hello AGIRAILS', // Original message
552
+ '0x1234...', // Signature
553
+ { chainId: 84532 } // Verification options
554
+ );
555
+
556
+ if (result.valid) {
557
+ console.log('Signature valid!');
558
+ console.log('Signer:', result.signer);
559
+ console.log('Is delegate:', result.isDelegate);
560
+ }
143
561
  ```
144
562
 
145
- ### Advanced
563
+ ### Advanced: Manage Identity (Optional)
564
+
565
+ For advanced use cases, use `DIDManager` to manage delegates and attributes:
146
566
 
147
567
  ```typescript
148
- client.advanced // Direct access to BlockchainRuntime or MockRuntime
568
+ import { DIDManager } from '@agirails/sdk';
569
+
570
+ // Create manager with signer
571
+ const manager = new DIDManager(signer, { network: 'base-sepolia' });
572
+
573
+ // Add a signing delegate (valid for 24 hours)
574
+ await manager.addDelegate(
575
+ 'did:ethr:84532:0x742d35cc...', // Your DID
576
+ '0xDelegateAddress...', // Delegate address
577
+ 'sigAuth', // Delegate type
578
+ 86400 // Validity in seconds
579
+ );
580
+
581
+ // Rotate key ownership
582
+ await manager.changeOwner(
583
+ 'did:ethr:84532:0x742d35cc...',
584
+ '0xNewOwnerAddress...'
585
+ );
586
+
587
+ // Add service endpoint attribute
588
+ await manager.setAttribute(
589
+ 'did:ethr:84532:0x742d35cc...',
590
+ 'did/svc/AgentService',
591
+ 'https://my-agent.example.com/api',
592
+ 86400
593
+ );
149
594
  ```
150
595
 
596
+ ### DID in ACTP Transactions
597
+
598
+ DIDs are used internally for:
599
+ - **Provider/Consumer Identity**: Transaction parties identified by DIDs
600
+ - **Message Signing**: EIP-712 messages reference DIDs
601
+ - **Delivery Proofs**: Attestations link to provider DIDs
602
+ - **Reputation**: Future reputation system will be DID-based
603
+
151
604
  ## Environment Variables
152
605
 
153
606
  ```bash
154
607
  # Required for blockchain mode
155
608
  PRIVATE_KEY=0x...
156
- BASE_SEPOLIA_RPC=https://...
157
609
 
158
610
  # Optional
159
- IPFS_GATEWAY=https://...
611
+ BASE_SEPOLIA_RPC=https://sepolia.base.org
612
+ IPFS_GATEWAY=https://gateway.pinata.cloud
160
613
  ```
161
614
 
162
- ## Fee Structure
615
+ ## Requirements
163
616
 
164
- - **Platform Fee**: 1% of transaction amount
165
- - **Minimum Fee**: $0.05 USDC
617
+ - Node.js 18+
618
+ - TypeScript 5.0+ (for development)
619
+ - Dependencies: ethers, viem (optional)
166
620
 
167
- ## Security
621
+ ## License
168
622
 
169
- - Non-custodial escrow (2-of-2 release)
170
- - EIP-712 typed message signing
171
- - EAS (Ethereum Attestation Service) for delivery proofs
172
- - Replay protection with nonce management
623
+ Apache 2.0 License - see [LICENSE](LICENSE) for details.
173
624
 
174
625
  ## Links
175
626
 
176
627
  - [Documentation](https://docs.agirails.io)
177
628
  - [GitHub](https://github.com/agirails/sdk-js)
629
+ - [Python SDK](https://github.com/agirails/sdk-python)
178
630
  - [Discord](https://discord.gg/nuhCt75qe4)
179
-
180
- ## License
181
-
182
- Apache-2.0
631
+ - [AGIRAILS Website](https://agirails.io)