@agirails/sdk 2.0.3 → 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.
- package/README.md +536 -87
- package/dist/adapters/BaseAdapter.js +2 -2
- package/dist/adapters/BaseAdapter.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts.map +1 -1
- package/dist/adapters/BasicAdapter.js +8 -0
- package/dist/adapters/BasicAdapter.js.map +1 -1
- package/dist/adapters/StandardAdapter.d.ts +10 -5
- package/dist/adapters/StandardAdapter.d.ts.map +1 -1
- package/dist/adapters/StandardAdapter.js +19 -6
- package/dist/adapters/StandardAdapter.js.map +1 -1
- package/dist/builders/QuoteBuilder.js +1 -1
- package/dist/builders/QuoteBuilder.js.map +1 -1
- package/dist/cli/commands/config.js +1 -1
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/simulate.js.map +1 -1
- package/dist/cli/commands/time.d.ts.map +1 -1
- package/dist/cli/commands/time.js.map +1 -1
- package/dist/config/networks.d.ts +9 -0
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +25 -10
- package/dist/config/networks.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -1
- package/dist/index.js.map +1 -1
- package/dist/level0/provide.d.ts.map +1 -1
- package/dist/level0/provide.js +2 -1
- package/dist/level0/provide.js.map +1 -1
- package/dist/level0/request.d.ts.map +1 -1
- package/dist/level0/request.js +1 -2
- package/dist/level0/request.js.map +1 -1
- package/dist/level1/Agent.d.ts.map +1 -1
- package/dist/level1/Agent.js +11 -3
- package/dist/level1/Agent.js.map +1 -1
- package/dist/level1/pricing/PriceCalculator.js +1 -1
- package/dist/level1/pricing/PriceCalculator.js.map +1 -1
- package/dist/level1/types/Options.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +7 -5
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/protocol/DIDResolver.js +1 -1
- package/dist/protocol/DIDResolver.js.map +1 -1
- package/dist/protocol/EASHelper.d.ts.map +1 -1
- package/dist/protocol/EASHelper.js +2 -3
- package/dist/protocol/EASHelper.js.map +1 -1
- package/dist/protocol/MessageSigner.d.ts.map +1 -1
- package/dist/protocol/MessageSigner.js +9 -9
- package/dist/protocol/MessageSigner.js.map +1 -1
- package/dist/protocol/ProofGenerator.d.ts.map +1 -1
- package/dist/protocol/ProofGenerator.js +1 -0
- package/dist/protocol/ProofGenerator.js.map +1 -1
- package/dist/runtime/BlockchainRuntime.d.ts +10 -3
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +41 -25
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/runtime/IACTPRuntime.d.ts +15 -0
- package/dist/runtime/IACTPRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.d.ts +7 -0
- package/dist/runtime/MockRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.js +15 -4
- package/dist/runtime/MockRuntime.js.map +1 -1
- package/dist/runtime/types/MockState.d.ts +5 -2
- package/dist/runtime/types/MockState.d.ts.map +1 -1
- package/dist/runtime/types/MockState.js.map +1 -1
- package/dist/storage/ArchiveBundleBuilder.d.ts +150 -0
- package/dist/storage/ArchiveBundleBuilder.d.ts.map +1 -0
- package/dist/storage/ArchiveBundleBuilder.js +468 -0
- package/dist/storage/ArchiveBundleBuilder.js.map +1 -0
- package/dist/storage/ArweaveClient.d.ts +271 -0
- package/dist/storage/ArweaveClient.d.ts.map +1 -0
- package/dist/storage/ArweaveClient.js +761 -0
- package/dist/storage/ArweaveClient.js.map +1 -0
- package/dist/storage/FilebaseClient.d.ts +193 -0
- package/dist/storage/FilebaseClient.d.ts.map +1 -0
- package/dist/storage/FilebaseClient.js +643 -0
- package/dist/storage/FilebaseClient.js.map +1 -0
- package/dist/storage/index.d.ts +47 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +64 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/types.d.ts +291 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +18 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/types/state.d.ts +5 -4
- package/dist/types/state.d.ts.map +1 -1
- package/dist/types/state.js +10 -9
- package/dist/types/state.js.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.d.ts.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.js +1 -2
- package/dist/utils/ErrorRecoveryGuide.js.map +1 -1
- package/dist/utils/IPFSClient.d.ts.map +1 -1
- package/dist/utils/IPFSClient.js +5 -2
- package/dist/utils/IPFSClient.js.map +1 -1
- package/dist/utils/NonceManager.d.ts.map +1 -1
- package/dist/utils/NonceManager.js +3 -2
- package/dist/utils/NonceManager.js.map +1 -1
- package/dist/utils/UsedAttestationTracker.d.ts +1 -1
- package/dist/utils/UsedAttestationTracker.d.ts.map +1 -1
- package/dist/utils/UsedAttestationTracker.js +4 -4
- package/dist/utils/UsedAttestationTracker.js.map +1 -1
- package/dist/utils/circuitBreaker.d.ts +136 -0
- package/dist/utils/circuitBreaker.d.ts.map +1 -0
- package/dist/utils/circuitBreaker.js +253 -0
- package/dist/utils/circuitBreaker.js.map +1 -0
- package/dist/utils/retry.d.ts +120 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +260 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/validation.d.ts +100 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +248 -1
- package/dist/utils/validation.js.map +1 -1
- package/package.json +14 -2
- package/src/adapters/BaseAdapter.ts +2 -2
- package/src/adapters/BasicAdapter.ts +12 -2
- package/src/adapters/StandardAdapter.ts +27 -7
- package/src/builders/QuoteBuilder.ts +1 -1
- package/src/cli/commands/config.ts +1 -1
- package/src/cli/commands/simulate.ts +1 -1
- package/src/cli/commands/time.ts +1 -2
- package/src/config/networks.ts +34 -10
- package/src/index.ts +54 -0
- package/src/level0/provide.ts +2 -1
- package/src/level0/request.ts +1 -2
- package/src/level1/Agent.ts +15 -5
- package/src/level1/pricing/PriceCalculator.ts +1 -1
- package/src/level1/types/Options.ts +1 -1
- package/src/protocol/ACTPKernel.ts +7 -5
- package/src/protocol/DIDResolver.ts +1 -1
- package/src/protocol/EASHelper.ts +2 -5
- package/src/protocol/MessageSigner.ts +9 -15
- package/src/protocol/ProofGenerator.ts +1 -0
- package/src/runtime/BlockchainRuntime.ts +42 -48
- package/src/runtime/IACTPRuntime.ts +16 -0
- package/src/runtime/MockRuntime.ts +16 -6
- package/src/runtime/types/MockState.ts +5 -2
- package/src/storage/ArchiveBundleBuilder.ts +563 -0
- package/src/storage/ArweaveClient.ts +945 -0
- package/src/storage/FilebaseClient.ts +790 -0
- package/src/storage/index.ts +96 -0
- package/src/storage/types.ts +348 -0
- package/src/types/state.ts +10 -9
- package/src/utils/ErrorRecoveryGuide.ts +1 -2
- package/src/utils/IPFSClient.ts +5 -4
- package/src/utils/NonceManager.ts +3 -2
- package/src/utils/UsedAttestationTracker.ts +4 -6
- package/src/utils/circuitBreaker.ts +324 -0
- package/src/utils/fsSafe.ts +5 -0
- package/src/utils/retry.ts +365 -0
- package/src/utils/validation.ts +295 -1
package/README.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AGIRAILS TypeScript SDK
|
|
2
2
|
|
|
3
|
-
TypeScript
|
|
3
|
+
[](https://www.typescriptlang.org/)
|
|
4
|
+
[](https://nodejs.org/)
|
|
5
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
|
+
[]()
|
|
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
|
-
###
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
41
|
-
|
|
195
|
+
mode: 'mock',
|
|
196
|
+
requesterAddress: '0x1111111111111111111111111111111111111111',
|
|
197
|
+
stateDirectory: '.actp' // Optional: persist state to disk
|
|
42
198
|
});
|
|
43
199
|
|
|
44
|
-
//
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
//
|
|
52
|
-
await
|
|
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
|
-
|
|
55
|
-
|
|
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
|
-
//
|
|
58
|
-
|
|
239
|
+
// ISO date string
|
|
240
|
+
deadline: '2025-01-01T00:00:00Z'
|
|
59
241
|
```
|
|
60
242
|
|
|
61
|
-
|
|
243
|
+
## Error Handling
|
|
244
|
+
|
|
245
|
+
The SDK provides structured exceptions with error codes:
|
|
62
246
|
|
|
63
247
|
```typescript
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
#
|
|
74
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
#
|
|
80
|
-
actp
|
|
327
|
+
# Dry-run simulation
|
|
328
|
+
actp simulate pay <provider> <amount>
|
|
329
|
+
actp simulate fee <amount>
|
|
330
|
+
```
|
|
81
331
|
|
|
82
|
-
|
|
83
|
-
actp status <txId>
|
|
332
|
+
### Configuration
|
|
84
333
|
|
|
85
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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 {
|
|
419
|
+
import { ServiceDirectory, request, provide } from '@agirails/sdk';
|
|
95
420
|
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
//
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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 | ⏳
|
|
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
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
499
|
+
did:ethr:84532:0x742d35cc6634c0532925a3b844bc9e7595f0beb
|
|
500
|
+
↑ ↑
|
|
501
|
+
chainId address
|
|
123
502
|
```
|
|
124
503
|
|
|
125
|
-
|
|
504
|
+
### Basic Usage
|
|
126
505
|
|
|
127
|
-
|
|
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
|
-
|
|
131
|
-
|
|
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
|
-
###
|
|
541
|
+
### Verify Signatures
|
|
135
542
|
|
|
136
543
|
```typescript
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
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
|
-
|
|
611
|
+
BASE_SEPOLIA_RPC=https://sepolia.base.org
|
|
612
|
+
IPFS_GATEWAY=https://gateway.pinata.cloud
|
|
160
613
|
```
|
|
161
614
|
|
|
162
|
-
##
|
|
615
|
+
## Requirements
|
|
163
616
|
|
|
164
|
-
-
|
|
165
|
-
-
|
|
617
|
+
- Node.js 18+
|
|
618
|
+
- TypeScript 5.0+ (for development)
|
|
619
|
+
- Dependencies: ethers, viem (optional)
|
|
166
620
|
|
|
167
|
-
##
|
|
621
|
+
## License
|
|
168
622
|
|
|
169
|
-
|
|
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)
|