@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,240 +0,0 @@
1
- /**
2
- * Keystore auto-resolution for ACTP wallets.
3
- *
4
- * Resolution order (AIP-13):
5
- * 1. ACTP_PRIVATE_KEY env var (policy-gated: mainnet/unknown = hard fail)
6
- * 2. ACTP_KEYSTORE_BASE64 + ACTP_KEY_PASSWORD (deployment-safe, preferred)
7
- * 3. .actp/keystore.json decrypted with ACTP_KEY_PASSWORD
8
- * 4. undefined (caller decides what to do)
9
- */
10
- import * as fs from 'fs';
11
- import * as path from 'path';
12
- import { Wallet } from 'ethers';
13
- import { sdkLogger } from '../utils/Logger';
14
-
15
- /** 30-minute TTL for cached private keys */
16
- const CACHE_TTL_MS = 30 * 60 * 1000;
17
-
18
- interface CacheEntry {
19
- key: string;
20
- address: string;
21
- expiresAt: number;
22
- }
23
-
24
- export interface ResolvePrivateKeyOptions {
25
- /** Network mode: 'mainnet', 'testnet', or 'mock'. Controls ACTP_PRIVATE_KEY policy. */
26
- network?: string;
27
- }
28
-
29
- // Cache keyed by resolved keystorePath to support multiple stateDirectories
30
- const _cache = new Map<string, CacheEntry>();
31
-
32
- // Separate cache for env-var-resolved key (no path dependency)
33
- let _envCache: CacheEntry | null = null;
34
-
35
- // Separate cache for base64-resolved key (no path dependency)
36
- let _base64Cache: CacheEntry | null = null;
37
-
38
- function isExpired(entry: CacheEntry): boolean {
39
- return Date.now() >= entry.expiresAt;
40
- }
41
-
42
- /**
43
- * Validate that stateDirectory doesn't escape expected boundaries.
44
- * Guards against path traversal when stateDirectory comes from user input.
45
- */
46
- function validateStateDirectory(stateDirectory: string): void {
47
- if (stateDirectory.includes('\0')) {
48
- throw new Error('Invalid stateDirectory: null byte detected');
49
- }
50
- // Reject raw '..' in the input (before normalization resolves it)
51
- // Catches both relative traversal (../../etc) and embedded traversal (/tmp/../../etc)
52
- if (stateDirectory.includes('..')) {
53
- throw new Error('Invalid stateDirectory: path traversal detected (..)');
54
- }
55
- }
56
-
57
- /**
58
- * Validate and normalize a raw private key string.
59
- * Trims whitespace and verifies 0x-prefixed 64-char hex format.
60
- */
61
- function validateRawKey(raw: string, source: string): string {
62
- const trimmed = raw.trim();
63
- if (!/^0x[0-9a-fA-F]{64}$/.test(trimmed)) {
64
- throw new Error(
65
- `Invalid private key from ${source}: expected 0x-prefixed 64-char hex string`
66
- );
67
- }
68
- return trimmed;
69
- }
70
-
71
- /**
72
- * Determine the effective network for ACTP_PRIVATE_KEY policy.
73
- * Falls back to ACTP_NETWORK env var. Null means unknown (fail-closed).
74
- */
75
- function getEffectiveNetwork(options?: ResolvePrivateKeyOptions): string | null {
76
- return options?.network ?? process.env.ACTP_NETWORK ?? null;
77
- }
78
-
79
- /**
80
- * Enforce ACTP_PRIVATE_KEY policy based on network (AIP-13).
81
- * - mainnet/unknown: hard fail
82
- * - testnet: warn once (on first resolution, not cache hits)
83
- * - mock: silent
84
- */
85
- function enforcePrivateKeyPolicy(network: string | null): void {
86
- if (network === 'mock') return;
87
-
88
- if (network === 'testnet') {
89
- // Warn once (only on first resolution — _envCache is null)
90
- if (_envCache === null) {
91
- sdkLogger.warn(
92
- 'ACTP_PRIVATE_KEY is deprecated. Use ACTP_KEYSTORE_BASE64 instead.\n' +
93
- 'Run: actp deploy:env'
94
- );
95
- }
96
- return;
97
- }
98
-
99
- // mainnet or unknown (null) — fail-closed
100
- const networkLabel = network === 'mainnet' ? 'production' : 'unknown network (fail-closed)';
101
- throw new Error(
102
- `ACTP_PRIVATE_KEY is not allowed in ${networkLabel}. Use ACTP_KEYSTORE_BASE64 instead.\n` +
103
- 'Run: actp deploy:env\n' +
104
- 'If this is testnet, set ACTP_NETWORK=testnet'
105
- );
106
- }
107
-
108
- /**
109
- * Auto-resolve private key: env var → base64 keystore → file keystore → undefined.
110
- * Never logs or prints the key itself.
111
- *
112
- * @param stateDirectory - Directory containing .actp/ (defaults to cwd)
113
- * @param options - Options including network for ACTP_PRIVATE_KEY policy
114
- */
115
- export async function resolvePrivateKey(
116
- stateDirectory?: string,
117
- options?: ResolvePrivateKeyOptions
118
- ): Promise<string | undefined> {
119
- // 1. ACTP_PRIVATE_KEY (highest priority, policy-gated)
120
- if (process.env.ACTP_PRIVATE_KEY) {
121
- const network = getEffectiveNetwork(options);
122
- enforcePrivateKeyPolicy(network);
123
-
124
- if (_envCache && !isExpired(_envCache)) return _envCache.key;
125
-
126
- const key = validateRawKey(process.env.ACTP_PRIVATE_KEY, 'ACTP_PRIVATE_KEY env var');
127
- const address = new Wallet(key).address;
128
- _envCache = { key, address, expiresAt: Date.now() + CACHE_TTL_MS };
129
- return key;
130
- }
131
-
132
- // 2. ACTP_KEYSTORE_BASE64 (deployment-safe, preferred for production)
133
- if (process.env.ACTP_KEYSTORE_BASE64) {
134
- if (_base64Cache && !isExpired(_base64Cache)) return _base64Cache.key;
135
-
136
- const raw = process.env.ACTP_KEYSTORE_BASE64.replace(/\s/g, '');
137
- let decoded: string;
138
- try {
139
- decoded = Buffer.from(raw, 'base64').toString('utf-8');
140
- } catch {
141
- throw new Error(
142
- 'ACTP_KEYSTORE_BASE64 is not valid base64.\n' +
143
- 'Run: actp deploy:env'
144
- );
145
- }
146
-
147
- try {
148
- JSON.parse(decoded);
149
- } catch {
150
- throw new Error(
151
- 'ACTP_KEYSTORE_BASE64 is not valid encrypted keystore JSON.\n' +
152
- 'Run: actp deploy:env'
153
- );
154
- }
155
-
156
- const password = process.env.ACTP_KEY_PASSWORD;
157
- if (!password) {
158
- throw new Error(
159
- 'ACTP_KEYSTORE_BASE64 is set but ACTP_KEY_PASSWORD is not set.\n' +
160
- 'Set it: export ACTP_KEY_PASSWORD="your-password"'
161
- );
162
- }
163
-
164
- let wallet: Wallet;
165
- try {
166
- wallet = (await Wallet.fromEncryptedJson(decoded, password)) as Wallet;
167
- } catch (err) {
168
- // Sanitize: do not leak keystore content in error messages
169
- const message = err instanceof Error ? err.message : 'unknown error';
170
- throw new Error(
171
- `Failed to decrypt ACTP_KEYSTORE_BASE64: ${message}`
172
- );
173
- }
174
-
175
- _base64Cache = { key: wallet.privateKey, address: wallet.address, expiresAt: Date.now() + CACHE_TTL_MS };
176
- return wallet.privateKey;
177
- }
178
-
179
- // 3. Resolve keystore path
180
- if (stateDirectory) {
181
- validateStateDirectory(stateDirectory);
182
- }
183
- const actpDir = stateDirectory
184
- ? path.join(stateDirectory, '.actp')
185
- : path.join(process.cwd(), '.actp');
186
- const keystorePath = path.resolve(actpDir, 'keystore.json');
187
-
188
- // 4. Cache hit (keyed by resolved path, with TTL)
189
- const cached = _cache.get(keystorePath);
190
- if (cached && !isExpired(cached)) return cached.key;
191
- if (cached) _cache.delete(keystorePath); // expired
192
-
193
- // 5. Keystore file
194
- if (!fs.existsSync(keystorePath)) return undefined;
195
-
196
- const password = process.env.ACTP_KEY_PASSWORD;
197
- if (!password) {
198
- throw new Error(
199
- 'Keystore found at ' + keystorePath + ' but ACTP_KEY_PASSWORD is not set.\n' +
200
- 'Set it: export ACTP_KEY_PASSWORD="your-password"'
201
- );
202
- }
203
-
204
- const keystore = fs.readFileSync(keystorePath, 'utf-8');
205
- const wallet = await Wallet.fromEncryptedJson(keystore, password);
206
-
207
- _cache.set(keystorePath, { key: wallet.privateKey, address: wallet.address, expiresAt: Date.now() + CACHE_TTL_MS });
208
- return wallet.privateKey;
209
- }
210
-
211
- /**
212
- * Get cached address from last resolvePrivateKey() call.
213
- * Works for env-var, base64, and keystore resolution paths.
214
- */
215
- export function getCachedAddress(stateDirectory?: string): string | undefined {
216
- // Env var path
217
- if (_envCache && !isExpired(_envCache)) return _envCache.address;
218
-
219
- // Base64 path
220
- if (_base64Cache && !isExpired(_base64Cache)) return _base64Cache.address;
221
-
222
- // Keystore path — look up by resolved path
223
- const actpDir = stateDirectory
224
- ? path.join(stateDirectory, '.actp')
225
- : path.join(process.cwd(), '.actp');
226
- const keystorePath = path.resolve(actpDir, 'keystore.json');
227
- const cached = _cache.get(keystorePath);
228
- if (cached && !isExpired(cached)) return cached.address;
229
- return undefined;
230
- }
231
-
232
- /**
233
- * Clear all cached keys and addresses (for testing).
234
- * @internal
235
- */
236
- export function _clearCache(): void {
237
- _cache.clear();
238
- _envCache = null;
239
- _base64Cache = null;
240
- }