@agirails/sdk 2.5.3 → 2.5.4

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 (166) hide show
  1. package/dist/ACTPClient.d.ts +18 -0
  2. package/dist/ACTPClient.d.ts.map +1 -1
  3. package/dist/ACTPClient.js +67 -22
  4. package/dist/ACTPClient.js.map +1 -1
  5. package/dist/adapters/BasicAdapter.d.ts +12 -0
  6. package/dist/adapters/BasicAdapter.d.ts.map +1 -1
  7. package/dist/adapters/BasicAdapter.js +30 -4
  8. package/dist/adapters/BasicAdapter.js.map +1 -1
  9. package/dist/adapters/StandardAdapter.d.ts +20 -3
  10. package/dist/adapters/StandardAdapter.d.ts.map +1 -1
  11. package/dist/adapters/StandardAdapter.js +45 -11
  12. package/dist/adapters/StandardAdapter.js.map +1 -1
  13. package/dist/cli/commands/publish.js +16 -4
  14. package/dist/cli/commands/publish.js.map +1 -1
  15. package/dist/cli/commands/register.js +16 -4
  16. package/dist/cli/commands/register.js.map +1 -1
  17. package/dist/cli/commands/tx.js +31 -3
  18. package/dist/cli/commands/tx.js.map +1 -1
  19. package/dist/config/networks.d.ts +2 -2
  20. package/dist/config/networks.d.ts.map +1 -1
  21. package/dist/config/networks.js +27 -22
  22. package/dist/config/networks.js.map +1 -1
  23. package/dist/level0/request.d.ts.map +1 -1
  24. package/dist/level0/request.js +2 -1
  25. package/dist/level0/request.js.map +1 -1
  26. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  27. package/dist/runtime/BlockchainRuntime.js +11 -5
  28. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  29. package/dist/utils/IPFSClient.d.ts +3 -1
  30. package/dist/utils/IPFSClient.d.ts.map +1 -1
  31. package/dist/utils/IPFSClient.js +27 -7
  32. package/dist/utils/IPFSClient.js.map +1 -1
  33. package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
  34. package/dist/wallet/AutoWalletProvider.js +52 -18
  35. package/dist/wallet/AutoWalletProvider.js.map +1 -1
  36. package/dist/wallet/SmartWalletRouter.d.ts +116 -0
  37. package/dist/wallet/SmartWalletRouter.d.ts.map +1 -0
  38. package/dist/wallet/SmartWalletRouter.js +212 -0
  39. package/dist/wallet/SmartWalletRouter.js.map +1 -0
  40. package/dist/wallet/aa/DualNonceManager.d.ts +19 -0
  41. package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
  42. package/dist/wallet/aa/DualNonceManager.js +100 -5
  43. package/dist/wallet/aa/DualNonceManager.js.map +1 -1
  44. package/package.json +3 -6
  45. package/src/ACTPClient.ts +0 -1579
  46. package/src/abi/ACTPKernel.json +0 -1356
  47. package/src/abi/AgentRegistry.json +0 -915
  48. package/src/abi/ERC20.json +0 -40
  49. package/src/abi/EscrowVault.json +0 -134
  50. package/src/abi/IdentityRegistry.json +0 -316
  51. package/src/adapters/AdapterRegistry.ts +0 -173
  52. package/src/adapters/AdapterRouter.ts +0 -416
  53. package/src/adapters/BaseAdapter.ts +0 -498
  54. package/src/adapters/BasicAdapter.ts +0 -514
  55. package/src/adapters/IAdapter.ts +0 -292
  56. package/src/adapters/StandardAdapter.ts +0 -555
  57. package/src/adapters/X402Adapter.ts +0 -731
  58. package/src/adapters/index.ts +0 -60
  59. package/src/builders/DeliveryProofBuilder.ts +0 -327
  60. package/src/builders/QuoteBuilder.ts +0 -483
  61. package/src/builders/index.ts +0 -17
  62. package/src/cli/commands/balance.ts +0 -110
  63. package/src/cli/commands/batch.ts +0 -487
  64. package/src/cli/commands/config.ts +0 -231
  65. package/src/cli/commands/deploy-check.ts +0 -364
  66. package/src/cli/commands/deploy-env.ts +0 -120
  67. package/src/cli/commands/diff.ts +0 -141
  68. package/src/cli/commands/init.ts +0 -469
  69. package/src/cli/commands/mint.ts +0 -116
  70. package/src/cli/commands/pay.ts +0 -113
  71. package/src/cli/commands/publish.ts +0 -475
  72. package/src/cli/commands/pull.ts +0 -124
  73. package/src/cli/commands/register.ts +0 -247
  74. package/src/cli/commands/simulate.ts +0 -345
  75. package/src/cli/commands/time.ts +0 -302
  76. package/src/cli/commands/tx.ts +0 -448
  77. package/src/cli/commands/watch.ts +0 -211
  78. package/src/cli/index.ts +0 -134
  79. package/src/cli/utils/client.ts +0 -252
  80. package/src/cli/utils/config.ts +0 -389
  81. package/src/cli/utils/output.ts +0 -465
  82. package/src/cli/utils/wallet.ts +0 -109
  83. package/src/config/agirailsmd.ts +0 -262
  84. package/src/config/networks.ts +0 -275
  85. package/src/config/pendingPublish.ts +0 -237
  86. package/src/config/publishPipeline.ts +0 -359
  87. package/src/config/syncOperations.ts +0 -279
  88. package/src/erc8004/ERC8004Bridge.ts +0 -462
  89. package/src/erc8004/ReputationReporter.ts +0 -468
  90. package/src/erc8004/index.ts +0 -61
  91. package/src/errors/index.ts +0 -427
  92. package/src/index.ts +0 -364
  93. package/src/level0/Provider.ts +0 -117
  94. package/src/level0/ServiceDirectory.ts +0 -131
  95. package/src/level0/index.ts +0 -10
  96. package/src/level0/provide.ts +0 -132
  97. package/src/level0/request.ts +0 -432
  98. package/src/level1/Agent.ts +0 -1426
  99. package/src/level1/index.ts +0 -10
  100. package/src/level1/pricing/PriceCalculator.ts +0 -255
  101. package/src/level1/pricing/PricingStrategy.ts +0 -198
  102. package/src/level1/types/Job.ts +0 -179
  103. package/src/level1/types/Options.ts +0 -291
  104. package/src/level1/types/index.ts +0 -8
  105. package/src/protocol/ACTPKernel.ts +0 -808
  106. package/src/protocol/AgentRegistry.ts +0 -559
  107. package/src/protocol/DIDManager.ts +0 -629
  108. package/src/protocol/DIDResolver.ts +0 -554
  109. package/src/protocol/EASHelper.ts +0 -378
  110. package/src/protocol/EscrowVault.ts +0 -255
  111. package/src/protocol/EventMonitor.ts +0 -204
  112. package/src/protocol/MessageSigner.ts +0 -510
  113. package/src/protocol/ProofGenerator.ts +0 -339
  114. package/src/protocol/QuoteBuilder.ts +0 -15
  115. package/src/registry/AgentRegistryClient.ts +0 -202
  116. package/src/runtime/BlockchainRuntime.ts +0 -1015
  117. package/src/runtime/IACTPRuntime.ts +0 -306
  118. package/src/runtime/MockRuntime.ts +0 -1298
  119. package/src/runtime/MockStateManager.ts +0 -577
  120. package/src/runtime/index.ts +0 -25
  121. package/src/runtime/types/MockState.ts +0 -237
  122. package/src/storage/ArchiveBundleBuilder.ts +0 -561
  123. package/src/storage/ArweaveClient.ts +0 -946
  124. package/src/storage/FilebaseClient.ts +0 -790
  125. package/src/storage/index.ts +0 -96
  126. package/src/storage/types.ts +0 -348
  127. package/src/types/adapter.ts +0 -310
  128. package/src/types/agent.ts +0 -79
  129. package/src/types/did.ts +0 -223
  130. package/src/types/eip712.ts +0 -175
  131. package/src/types/erc8004.ts +0 -293
  132. package/src/types/escrow.ts +0 -27
  133. package/src/types/index.ts +0 -17
  134. package/src/types/message.ts +0 -145
  135. package/src/types/state.ts +0 -87
  136. package/src/types/transaction.ts +0 -69
  137. package/src/types/x402.ts +0 -251
  138. package/src/utils/ErrorRecoveryGuide.ts +0 -676
  139. package/src/utils/Helpers.ts +0 -688
  140. package/src/utils/IPFSClient.ts +0 -368
  141. package/src/utils/Logger.ts +0 -484
  142. package/src/utils/NonceManager.ts +0 -591
  143. package/src/utils/RateLimiter.ts +0 -534
  144. package/src/utils/ReceivedNonceTracker.ts +0 -567
  145. package/src/utils/SDKLifecycle.ts +0 -416
  146. package/src/utils/SecureNonce.ts +0 -78
  147. package/src/utils/Semaphore.ts +0 -276
  148. package/src/utils/UsedAttestationTracker.ts +0 -385
  149. package/src/utils/canonicalJson.ts +0 -38
  150. package/src/utils/circuitBreaker.ts +0 -324
  151. package/src/utils/computeTypeHash.ts +0 -48
  152. package/src/utils/fsSafe.ts +0 -80
  153. package/src/utils/index.ts +0 -80
  154. package/src/utils/retry.ts +0 -364
  155. package/src/utils/security.ts +0 -418
  156. package/src/utils/validation.ts +0 -540
  157. package/src/wallet/AutoWalletProvider.ts +0 -299
  158. package/src/wallet/EOAWalletProvider.ts +0 -69
  159. package/src/wallet/IWalletProvider.ts +0 -135
  160. package/src/wallet/aa/BundlerClient.ts +0 -274
  161. package/src/wallet/aa/DualNonceManager.ts +0 -173
  162. package/src/wallet/aa/PaymasterClient.ts +0 -174
  163. package/src/wallet/aa/TransactionBatcher.ts +0 -353
  164. package/src/wallet/aa/UserOpBuilder.ts +0 -246
  165. package/src/wallet/aa/constants.ts +0 -60
  166. package/src/wallet/keystore.ts +0 -240
@@ -1,87 +0,0 @@
1
- /**
2
- * ACTP State Machine
3
- * Reference: Yellow Paper §3.2
4
- */
5
-
6
- export enum State {
7
- INITIATED = 0,
8
- QUOTED = 1,
9
- COMMITTED = 2,
10
- IN_PROGRESS = 3,
11
- DELIVERED = 4,
12
- SETTLED = 5,
13
- DISPUTED = 6,
14
- CANCELLED = 7
15
- }
16
-
17
- export class StateMachine {
18
- /**
19
- * Valid state transitions per Yellow Paper §3.2.2
20
- *
21
- * SECURITY FIX (AUDIT-2026-02): State machine must match ACTPKernel contract exactly
22
- *
23
- * Per on-chain ACTPKernel contract:
24
- * - COMMITTED must go through IN_PROGRESS before DELIVERED (cannot skip)
25
- * - DISPUTED can transition to SETTLED or CANCELLED (admin/pauser can cancel disputes)
26
- * - IN_PROGRESS can transition to DELIVERED or CANCELLED (not DISPUTED)
27
- */
28
- private static readonly TRANSITIONS: Record<State, State[]> = {
29
- [State.INITIATED]: [State.QUOTED, State.COMMITTED, State.CANCELLED], // Allow direct INITIATED → COMMITTED (AIP-3)
30
- [State.QUOTED]: [State.COMMITTED, State.CANCELLED],
31
- // AUDIT FIX: COMMITTED cannot skip to DELIVERED - must go through IN_PROGRESS first
32
- [State.COMMITTED]: [State.IN_PROGRESS, State.CANCELLED],
33
- // IN_PROGRESS can transition to DELIVERED or CANCELLED
34
- [State.IN_PROGRESS]: [State.DELIVERED, State.CANCELLED],
35
- [State.DELIVERED]: [State.SETTLED, State.DISPUTED],
36
- // AUDIT FIX: DISPUTED can also transition to CANCELLED (admin/pauser emergency cancellation)
37
- [State.DISPUTED]: [State.SETTLED, State.CANCELLED],
38
- [State.SETTLED]: [], // Terminal state
39
- [State.CANCELLED]: [] // Terminal state
40
- };
41
-
42
- /**
43
- * Check if state transition is valid
44
- */
45
- static isValidTransition(from: State, to: State): boolean {
46
- return this.TRANSITIONS[from]?.includes(to) ?? false;
47
- }
48
-
49
- /**
50
- * Check if state is terminal (no further transitions)
51
- */
52
- static isTerminalState(state: State): boolean {
53
- return state === State.SETTLED || state === State.CANCELLED;
54
- }
55
-
56
- /**
57
- * Get human-readable state name
58
- */
59
- static getStateName(state: State): string {
60
- return State[state];
61
- }
62
-
63
- /**
64
- * Get all valid next states from current state
65
- */
66
- static getNextValidStates(currentState: State): State[] {
67
- return this.TRANSITIONS[currentState] || [];
68
- }
69
-
70
- /**
71
- * Validate state transition or throw error
72
- */
73
- static validateTransition(from: State, to: State): void {
74
- if (!this.isValidTransition(from, to)) {
75
- const validStates = this.getNextValidStates(from)
76
- .map(s => State[s])
77
- .join(', ');
78
-
79
- throw new Error(
80
- `Invalid state transition: ${State[from]} → ${State[to]}. ` +
81
- `Valid transitions from ${State[from]}: ${validStates || 'none (terminal state)'}`
82
- );
83
- }
84
- }
85
- }
86
-
87
-
@@ -1,69 +0,0 @@
1
- import { State } from './state';
2
-
3
- /**
4
- * ACTP Transaction
5
- * Reference: Yellow Paper §3.1
6
- */
7
- export interface Transaction {
8
- txId: string;
9
- requester: string;
10
- provider: string;
11
- amount: bigint;
12
- state: State;
13
- createdAt: number;
14
- updatedAt: number;
15
- deadline: number;
16
- disputeWindow: number;
17
- escrowContract: string;
18
- escrowId: string;
19
- serviceHash: string;
20
- attestationUID: string;
21
- metadata: string;
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;
29
- }
30
-
31
- /**
32
- * Parameters for creating a new transaction
33
- */
34
- export interface CreateTransactionParams {
35
- provider: string;
36
- requester: string;
37
- amount: bigint;
38
- deadline: number;
39
- disputeWindow: number;
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;
47
- }
48
-
49
- /**
50
- * Dispute resolution split
51
- */
52
- export interface DisputeResolution {
53
- requesterAmount: bigint;
54
- providerAmount: bigint;
55
- mediatorAmount: bigint;
56
- mediator?: string;
57
- }
58
-
59
- /**
60
- * Economic parameters (fee structure)
61
- */
62
- export interface EconomicParams {
63
- baseFeeNumerator: number;
64
- baseFeeDenominator: number;
65
- feeRecipient: string;
66
- requesterPenaltyBps: number;
67
- providerPenaltyBps: number;
68
- }
69
-
package/src/types/x402.ts DELETED
@@ -1,251 +0,0 @@
1
- /**
2
- * X402 Protocol Types and Constants
3
- *
4
- * Defines types for the HTTP 402 Payment Required protocol implementation.
5
- * X402 enables atomic, instant API payments - NO escrow, NO state machine.
6
- *
7
- * Key difference from ACTP:
8
- * - ACTP: escrow → state machine → disputes → explicit release
9
- * - x402: atomic payment → instant settlement → done
10
- *
11
- * Flow:
12
- * 1. Client requests protected HTTPS endpoint → gets 402 response
13
- * 2. Parse X-Payment-* headers (address, amount, network, deadline)
14
- * 3. Execute atomic USDC transfer to provider (no escrow!)
15
- * 4. Retry request with tx hash as proof
16
- * 5. Return response - payment complete, no release needed
17
- *
18
- * Use x402 for: Simple API calls, instant delivery, low-value transactions
19
- * Use ACTP for: Complex services, dispute protection, high-value transactions
20
- *
21
- * @module types/x402
22
- */
23
-
24
- // ============================================================================
25
- // X402 Header Constants
26
- // ============================================================================
27
-
28
- /**
29
- * Standard X402 payment headers sent in 402 responses.
30
- *
31
- * These headers inform the client how to pay for the requested resource.
32
- */
33
- export const X402_HEADERS = {
34
- /** Indicates payment is required (must be "true") */
35
- REQUIRED: 'x-payment-required',
36
- /** Provider's wallet address (0x-prefixed) */
37
- ADDRESS: 'x-payment-address',
38
- /** Amount in USDC wei (6 decimals) */
39
- AMOUNT: 'x-payment-amount',
40
- /** Network identifier (base-mainnet or base-sepolia) */
41
- NETWORK: 'x-payment-network',
42
- /** Token type (currently only USDC) */
43
- TOKEN: 'x-payment-token',
44
- /** Unix timestamp deadline for payment */
45
- DEADLINE: 'x-payment-deadline',
46
- /** Optional: Dispute window in seconds */
47
- DISPUTE_WINDOW: 'x-dispute-window',
48
- /** Optional: Service identifier for tracking */
49
- SERVICE_ID: 'x-service-id',
50
- } as const;
51
-
52
- /**
53
- * Proof headers sent when retrying with payment.
54
- *
55
- * After creating an ACTP transaction, the client includes these
56
- * headers to prove payment was made.
57
- */
58
- export const X402_PROOF_HEADERS = {
59
- /** ACTP transaction ID (bytes32 hex) */
60
- TX_ID: 'x-payment-tx-id',
61
- /** ACTP escrow ID (bytes32 hex) */
62
- ESCROW_ID: 'x-payment-escrow-id',
63
- } as const;
64
-
65
- // ============================================================================
66
- // X402 Types
67
- // ============================================================================
68
-
69
- /** Supported networks for x402 payments */
70
- export type X402Network = 'base-mainnet' | 'base-sepolia';
71
-
72
- /** Supported tokens (currently only USDC) */
73
- export type X402Token = 'USDC';
74
-
75
- /**
76
- * Parsed payment headers from HTTP 402 response.
77
- *
78
- * Contains all information needed to create an ACTP transaction
79
- * for the requested resource.
80
- */
81
- export interface X402PaymentHeaders {
82
- /** Whether payment is required (always true for valid 402) */
83
- required: boolean;
84
-
85
- /** Provider's wallet address (0x-prefixed, 42 chars) */
86
- paymentAddress: string;
87
-
88
- /** Amount in USDC wei (6 decimals, as string) */
89
- amount: string;
90
-
91
- /** Target network */
92
- network: X402Network;
93
-
94
- /** Token type */
95
- token: X402Token;
96
-
97
- /** Unix timestamp deadline for accepting payment */
98
- deadline: number;
99
-
100
- /** Optional: Dispute window in seconds */
101
- disputeWindow?: number;
102
-
103
- /** Optional: Service identifier for tracking/debugging */
104
- serviceId?: string;
105
- }
106
-
107
- // ============================================================================
108
- // X402 Error Handling
109
- // ============================================================================
110
-
111
- /**
112
- * Error codes for X402 protocol failures.
113
- *
114
- * Used to identify specific error types and enable proper error handling.
115
- */
116
- export enum X402ErrorCode {
117
- /** Response status was not 402 */
118
- NOT_402_RESPONSE = 'NOT_402_RESPONSE',
119
-
120
- /** Required X-Payment-* headers are missing */
121
- MISSING_HEADERS = 'MISSING_HEADERS',
122
-
123
- /** X-Payment-Amount is invalid (not a number, negative, etc.) */
124
- INVALID_AMOUNT = 'INVALID_AMOUNT',
125
-
126
- /** X-Payment-Address is not a valid Ethereum address */
127
- INVALID_ADDRESS = 'INVALID_ADDRESS',
128
-
129
- /** X-Payment-Network is not a recognized network */
130
- INVALID_NETWORK = 'INVALID_NETWORK',
131
-
132
- /** Server's network doesn't match client's expected network */
133
- NETWORK_MISMATCH = 'NETWORK_MISMATCH',
134
-
135
- /** Failed to create ACTP transaction or link escrow */
136
- PAYMENT_FAILED = 'PAYMENT_FAILED',
137
-
138
- /** Retry request with proof headers failed */
139
- RETRY_FAILED = 'RETRY_FAILED',
140
-
141
- /** X-Payment-Deadline has already passed */
142
- DEADLINE_PASSED = 'DEADLINE_PASSED',
143
-
144
- /** HTTPS protocol required but HTTP used */
145
- INSECURE_PROTOCOL = 'INSECURE_PROTOCOL',
146
- }
147
-
148
- /**
149
- * Custom error for X402 protocol failures.
150
- *
151
- * Provides structured error information for debugging and error handling.
152
- *
153
- * @example
154
- * ```typescript
155
- * try {
156
- * await x402Adapter.pay({ to: 'https://api.example.com', amount: '10' });
157
- * } catch (error) {
158
- * if (error instanceof X402Error) {
159
- * if (error.code === X402ErrorCode.NETWORK_MISMATCH) {
160
- * console.error('Wrong network:', error.message);
161
- * }
162
- * }
163
- * }
164
- * ```
165
- */
166
- export class X402Error extends Error {
167
- public readonly name = 'X402Error';
168
-
169
- /**
170
- * Creates a new X402Error.
171
- *
172
- * @param message - Human-readable error message
173
- * @param code - Error code for programmatic handling
174
- * @param response - Optional HTTP response that triggered the error
175
- */
176
- constructor(
177
- message: string,
178
- public readonly code: X402ErrorCode,
179
- public readonly response?: Response
180
- ) {
181
- super(message);
182
-
183
- // Maintains proper stack trace in V8 environments
184
- if (Error.captureStackTrace) {
185
- Error.captureStackTrace(this, X402Error);
186
- }
187
- }
188
-
189
- /**
190
- * Creates a detailed error message with code.
191
- */
192
- toString(): string {
193
- return `X402Error [${this.code}]: ${this.message}`;
194
- }
195
- }
196
-
197
- // ============================================================================
198
- // Fee Types
199
- // ============================================================================
200
-
201
- /**
202
- * Fee breakdown for x402 payments routed through X402Relay.
203
- *
204
- * Shows how the gross amount was split between provider and platform.
205
- * Fee = max(grossAmount * feeBps / 10000, MIN_FEE).
206
- *
207
- * NOTE: This is a client-side **estimate** computed from the configured
208
- * platformFeeBps. The on-chain X402Relay contract is the source of truth.
209
- * If an admin updates the relay's fee rate, this estimate may diverge
210
- * from the actual on-chain split until the SDK config is refreshed.
211
- */
212
- export interface X402FeeBreakdown {
213
- /** Total amount from the 402 header (USDC wei, 6 decimals) */
214
- grossAmount: string;
215
-
216
- /** Estimated amount provider received: grossAmount - platformFee */
217
- providerNet: string;
218
-
219
- /** Estimated amount treasury received: max(feeBps%, $0.05) */
220
- platformFee: string;
221
-
222
- /** Fee rate used for estimate (basis points, e.g. 100 = 1%) */
223
- feeBps: number;
224
-
225
- /** True — this is a client-side estimate, not read from chain */
226
- estimated: true;
227
- }
228
-
229
- // ============================================================================
230
- // Type Guards
231
- // ============================================================================
232
-
233
- /**
234
- * Type guard to check if an error is an X402Error.
235
- *
236
- * @param error - Error to check
237
- * @returns True if error is X402Error
238
- */
239
- export function isX402Error(error: unknown): error is X402Error {
240
- return error instanceof X402Error;
241
- }
242
-
243
- /**
244
- * Validates that a network string is a valid X402Network.
245
- *
246
- * @param network - Network string to validate
247
- * @returns True if valid X402Network
248
- */
249
- export function isValidX402Network(network: string): network is X402Network {
250
- return network === 'base-mainnet' || network === 'base-sepolia';
251
- }