@agirails/sdk 2.5.2 → 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 (172) 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/cli/utils/client.d.ts.map +1 -1
  20. package/dist/cli/utils/client.js +1 -0
  21. package/dist/cli/utils/client.js.map +1 -1
  22. package/dist/config/networks.d.ts +2 -2
  23. package/dist/config/networks.d.ts.map +1 -1
  24. package/dist/config/networks.js +27 -22
  25. package/dist/config/networks.js.map +1 -1
  26. package/dist/level0/request.d.ts.map +1 -1
  27. package/dist/level0/request.js +2 -1
  28. package/dist/level0/request.js.map +1 -1
  29. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  30. package/dist/runtime/BlockchainRuntime.js +11 -5
  31. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  32. package/dist/runtime/MockStateManager.d.ts.map +1 -1
  33. package/dist/runtime/MockStateManager.js +2 -1
  34. package/dist/runtime/MockStateManager.js.map +1 -1
  35. package/dist/utils/IPFSClient.d.ts +3 -1
  36. package/dist/utils/IPFSClient.d.ts.map +1 -1
  37. package/dist/utils/IPFSClient.js +27 -7
  38. package/dist/utils/IPFSClient.js.map +1 -1
  39. package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
  40. package/dist/wallet/AutoWalletProvider.js +52 -18
  41. package/dist/wallet/AutoWalletProvider.js.map +1 -1
  42. package/dist/wallet/SmartWalletRouter.d.ts +116 -0
  43. package/dist/wallet/SmartWalletRouter.d.ts.map +1 -0
  44. package/dist/wallet/SmartWalletRouter.js +212 -0
  45. package/dist/wallet/SmartWalletRouter.js.map +1 -0
  46. package/dist/wallet/aa/DualNonceManager.d.ts +19 -0
  47. package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
  48. package/dist/wallet/aa/DualNonceManager.js +100 -5
  49. package/dist/wallet/aa/DualNonceManager.js.map +1 -1
  50. package/package.json +3 -6
  51. package/src/ACTPClient.ts +0 -1579
  52. package/src/abi/ACTPKernel.json +0 -1356
  53. package/src/abi/AgentRegistry.json +0 -915
  54. package/src/abi/ERC20.json +0 -40
  55. package/src/abi/EscrowVault.json +0 -134
  56. package/src/abi/IdentityRegistry.json +0 -316
  57. package/src/adapters/AdapterRegistry.ts +0 -173
  58. package/src/adapters/AdapterRouter.ts +0 -416
  59. package/src/adapters/BaseAdapter.ts +0 -498
  60. package/src/adapters/BasicAdapter.ts +0 -514
  61. package/src/adapters/IAdapter.ts +0 -292
  62. package/src/adapters/StandardAdapter.ts +0 -555
  63. package/src/adapters/X402Adapter.ts +0 -731
  64. package/src/adapters/index.ts +0 -60
  65. package/src/builders/DeliveryProofBuilder.ts +0 -327
  66. package/src/builders/QuoteBuilder.ts +0 -483
  67. package/src/builders/index.ts +0 -17
  68. package/src/cli/commands/balance.ts +0 -110
  69. package/src/cli/commands/batch.ts +0 -487
  70. package/src/cli/commands/config.ts +0 -231
  71. package/src/cli/commands/deploy-check.ts +0 -364
  72. package/src/cli/commands/deploy-env.ts +0 -120
  73. package/src/cli/commands/diff.ts +0 -141
  74. package/src/cli/commands/init.ts +0 -469
  75. package/src/cli/commands/mint.ts +0 -116
  76. package/src/cli/commands/pay.ts +0 -113
  77. package/src/cli/commands/publish.ts +0 -475
  78. package/src/cli/commands/pull.ts +0 -124
  79. package/src/cli/commands/register.ts +0 -247
  80. package/src/cli/commands/simulate.ts +0 -345
  81. package/src/cli/commands/time.ts +0 -302
  82. package/src/cli/commands/tx.ts +0 -448
  83. package/src/cli/commands/watch.ts +0 -211
  84. package/src/cli/index.ts +0 -134
  85. package/src/cli/utils/client.ts +0 -251
  86. package/src/cli/utils/config.ts +0 -389
  87. package/src/cli/utils/output.ts +0 -465
  88. package/src/cli/utils/wallet.ts +0 -109
  89. package/src/config/agirailsmd.ts +0 -262
  90. package/src/config/networks.ts +0 -275
  91. package/src/config/pendingPublish.ts +0 -237
  92. package/src/config/publishPipeline.ts +0 -359
  93. package/src/config/syncOperations.ts +0 -279
  94. package/src/erc8004/ERC8004Bridge.ts +0 -462
  95. package/src/erc8004/ReputationReporter.ts +0 -468
  96. package/src/erc8004/index.ts +0 -61
  97. package/src/errors/index.ts +0 -427
  98. package/src/index.ts +0 -364
  99. package/src/level0/Provider.ts +0 -117
  100. package/src/level0/ServiceDirectory.ts +0 -131
  101. package/src/level0/index.ts +0 -10
  102. package/src/level0/provide.ts +0 -132
  103. package/src/level0/request.ts +0 -432
  104. package/src/level1/Agent.ts +0 -1426
  105. package/src/level1/index.ts +0 -10
  106. package/src/level1/pricing/PriceCalculator.ts +0 -255
  107. package/src/level1/pricing/PricingStrategy.ts +0 -198
  108. package/src/level1/types/Job.ts +0 -179
  109. package/src/level1/types/Options.ts +0 -291
  110. package/src/level1/types/index.ts +0 -8
  111. package/src/protocol/ACTPKernel.ts +0 -808
  112. package/src/protocol/AgentRegistry.ts +0 -559
  113. package/src/protocol/DIDManager.ts +0 -629
  114. package/src/protocol/DIDResolver.ts +0 -554
  115. package/src/protocol/EASHelper.ts +0 -378
  116. package/src/protocol/EscrowVault.ts +0 -255
  117. package/src/protocol/EventMonitor.ts +0 -204
  118. package/src/protocol/MessageSigner.ts +0 -510
  119. package/src/protocol/ProofGenerator.ts +0 -339
  120. package/src/protocol/QuoteBuilder.ts +0 -15
  121. package/src/registry/AgentRegistryClient.ts +0 -202
  122. package/src/runtime/BlockchainRuntime.ts +0 -1015
  123. package/src/runtime/IACTPRuntime.ts +0 -306
  124. package/src/runtime/MockRuntime.ts +0 -1298
  125. package/src/runtime/MockStateManager.ts +0 -576
  126. package/src/runtime/index.ts +0 -25
  127. package/src/runtime/types/MockState.ts +0 -237
  128. package/src/storage/ArchiveBundleBuilder.ts +0 -561
  129. package/src/storage/ArweaveClient.ts +0 -946
  130. package/src/storage/FilebaseClient.ts +0 -790
  131. package/src/storage/index.ts +0 -96
  132. package/src/storage/types.ts +0 -348
  133. package/src/types/adapter.ts +0 -310
  134. package/src/types/agent.ts +0 -79
  135. package/src/types/did.ts +0 -223
  136. package/src/types/eip712.ts +0 -175
  137. package/src/types/erc8004.ts +0 -293
  138. package/src/types/escrow.ts +0 -27
  139. package/src/types/index.ts +0 -17
  140. package/src/types/message.ts +0 -145
  141. package/src/types/state.ts +0 -87
  142. package/src/types/transaction.ts +0 -69
  143. package/src/types/x402.ts +0 -251
  144. package/src/utils/ErrorRecoveryGuide.ts +0 -676
  145. package/src/utils/Helpers.ts +0 -688
  146. package/src/utils/IPFSClient.ts +0 -368
  147. package/src/utils/Logger.ts +0 -484
  148. package/src/utils/NonceManager.ts +0 -591
  149. package/src/utils/RateLimiter.ts +0 -534
  150. package/src/utils/ReceivedNonceTracker.ts +0 -567
  151. package/src/utils/SDKLifecycle.ts +0 -416
  152. package/src/utils/SecureNonce.ts +0 -78
  153. package/src/utils/Semaphore.ts +0 -276
  154. package/src/utils/UsedAttestationTracker.ts +0 -385
  155. package/src/utils/canonicalJson.ts +0 -38
  156. package/src/utils/circuitBreaker.ts +0 -324
  157. package/src/utils/computeTypeHash.ts +0 -48
  158. package/src/utils/fsSafe.ts +0 -80
  159. package/src/utils/index.ts +0 -80
  160. package/src/utils/retry.ts +0 -364
  161. package/src/utils/security.ts +0 -418
  162. package/src/utils/validation.ts +0 -540
  163. package/src/wallet/AutoWalletProvider.ts +0 -299
  164. package/src/wallet/EOAWalletProvider.ts +0 -69
  165. package/src/wallet/IWalletProvider.ts +0 -135
  166. package/src/wallet/aa/BundlerClient.ts +0 -274
  167. package/src/wallet/aa/DualNonceManager.ts +0 -173
  168. package/src/wallet/aa/PaymasterClient.ts +0 -174
  169. package/src/wallet/aa/TransactionBatcher.ts +0 -353
  170. package/src/wallet/aa/UserOpBuilder.ts +0 -246
  171. package/src/wallet/aa/constants.ts +0 -60
  172. package/src/wallet/keystore.ts +0 -240
@@ -1,279 +0,0 @@
1
- /**
2
- * Sync Operations - Pull + Diff for AGIRAILS.md
3
- *
4
- * Terraform-style sync: compare local AGIRAILS.md with on-chain state.
5
- * Never auto-overwrites — shows diff and requires explicit confirmation.
6
- *
7
- * @module config/syncOperations
8
- */
9
-
10
- import { readFileSync, writeFileSync, existsSync } from 'fs';
11
- import { Provider } from 'ethers';
12
- import { computeConfigHash, parseAgirailsMd, serializeAgirailsMd } from './agirailsmd';
13
- import { validateCID } from '../utils/validation';
14
- import { AgentRegistryClient } from '../registry/AgentRegistryClient';
15
-
16
- // ============================================================================
17
- // Constants
18
- // ============================================================================
19
-
20
- /** Public IPFS gateways for read-only access (no credentials needed) */
21
- const IPFS_GATEWAYS = [
22
- 'https://ipfs.io/ipfs/',
23
- 'https://dweb.link/ipfs/',
24
- 'https://cloudflare-ipfs.com/ipfs/',
25
- ];
26
-
27
- // ============================================================================
28
- // Types
29
- // ============================================================================
30
-
31
- export interface DiffResult {
32
- /** Whether local and on-chain are in sync */
33
- inSync: boolean;
34
- /** Local config hash (or null if no local file) */
35
- localHash: string | null;
36
- /** On-chain config hash (or zero hash if not published) */
37
- onChainHash: string;
38
- /** On-chain IPFS CID (or empty if not published) */
39
- onChainCID: string;
40
- /** Whether on-chain has a published config */
41
- hasOnChainConfig: boolean;
42
- /** Whether local file exists */
43
- hasLocalFile: boolean;
44
- /** Human-readable status message */
45
- status: 'in-sync' | 'local-ahead' | 'remote-ahead' | 'diverged' | 'no-local' | 'no-remote';
46
- }
47
-
48
- export interface PullResult {
49
- /** Whether a file was written */
50
- written: boolean;
51
- /** The pulled content (if any) */
52
- content?: string;
53
- /** IPFS CID that was fetched */
54
- cid?: string;
55
- /** Status message */
56
- status: string;
57
- }
58
-
59
- export interface DiffOptions {
60
- /** Path to local AGIRAILS.md */
61
- path: string;
62
- /** Agent address to check on-chain */
63
- agentAddress: string;
64
- /** AgentRegistry contract address */
65
- registryAddress: string;
66
- /** Provider for reading on-chain state */
67
- provider: Provider;
68
- }
69
-
70
- export interface PullOptions extends DiffOptions {
71
- /** Force overwrite without confirmation */
72
- force?: boolean;
73
- }
74
-
75
- // ============================================================================
76
- // Diff
77
- // ============================================================================
78
-
79
- const ZERO_HASH = '0x' + '0'.repeat(64);
80
-
81
- /**
82
- * Compare local AGIRAILS.md with on-chain config state.
83
- *
84
- * @param options - Diff configuration
85
- * @returns Diff result showing sync status
86
- */
87
- export async function diff(options: DiffOptions): Promise<DiffResult> {
88
- const { path, agentAddress, registryAddress, provider } = options;
89
-
90
- // Read on-chain state
91
- const registryClient = AgentRegistryClient.readOnly(registryAddress, provider);
92
- const onChainState = await registryClient.getConfig(agentAddress);
93
-
94
- const hasOnChainConfig = onChainState.configHash !== ZERO_HASH && onChainState.configCID !== '';
95
- const onChainHash = onChainState.configHash;
96
- const onChainCID = onChainState.configCID;
97
-
98
- // Read local state
99
- const hasLocalFile = existsSync(path);
100
- let localHash: string | null = null;
101
-
102
- if (hasLocalFile) {
103
- const content = readFileSync(path, 'utf-8');
104
- const { configHash } = computeConfigHash(content);
105
- localHash = configHash;
106
- }
107
-
108
- // Determine status
109
- let status: DiffResult['status'];
110
- let inSync: boolean;
111
-
112
- if (!hasLocalFile && !hasOnChainConfig) {
113
- status = 'no-local';
114
- inSync = true; // both empty = in sync
115
- } else if (!hasLocalFile && hasOnChainConfig) {
116
- status = 'remote-ahead';
117
- inSync = false;
118
- } else if (hasLocalFile && !hasOnChainConfig) {
119
- status = 'no-remote';
120
- inSync = false;
121
- } else if (localHash === onChainHash) {
122
- status = 'in-sync';
123
- inSync = true;
124
- } else {
125
- // Both exist but hashes differ. Use the stored config_hash in frontmatter
126
- // to determine directionality:
127
- // - config_hash matches on-chain → user edited locally after last publish → local-ahead
128
- // - config_hash doesn't match on-chain → remote was updated too → diverged
129
- // - no config_hash → never published from this file → local-ahead
130
- status = 'diverged';
131
- inSync = false;
132
-
133
- if (hasLocalFile) {
134
- try {
135
- const content = readFileSync(path, 'utf-8');
136
- const { frontmatter } = parseAgirailsMd(content);
137
- if (!frontmatter.config_hash) {
138
- // Never published — local is the only source
139
- status = 'local-ahead';
140
- } else if (frontmatter.config_hash === onChainHash) {
141
- // Last publish matches on-chain, so local edits are newer
142
- status = 'local-ahead';
143
- }
144
- // else: frontmatter.config_hash !== onChainHash → remote updated → diverged
145
- } catch {
146
- // Parse error — keep as diverged
147
- }
148
- }
149
- }
150
-
151
- return {
152
- inSync,
153
- localHash,
154
- onChainHash,
155
- onChainCID,
156
- hasOnChainConfig,
157
- hasLocalFile,
158
- status,
159
- };
160
- }
161
-
162
- // ============================================================================
163
- // IPFS Fetch (public gateway, no credentials needed)
164
- // ============================================================================
165
-
166
- /**
167
- * Fetch content from IPFS using public gateways (no Filebase credentials needed).
168
- * Tries multiple gateways with fallback.
169
- *
170
- * @param cid - IPFS CID to fetch (validated before use)
171
- * @returns Raw content as string
172
- * @throws InvalidCIDError if CID format is invalid
173
- * @throws Error if all gateways fail
174
- */
175
- async function fetchFromIPFS(cid: string): Promise<string> {
176
- // Validate CID format before hitting any gateway
177
- validateCID(cid, 'onChainCID');
178
-
179
- const errors: string[] = [];
180
-
181
- for (const gateway of IPFS_GATEWAYS) {
182
- try {
183
- const response = await fetch(`${gateway}${cid}`, {
184
- signal: AbortSignal.timeout(15_000),
185
- });
186
- if (!response.ok) {
187
- errors.push(`${gateway}: HTTP ${response.status}`);
188
- continue;
189
- }
190
- return await response.text();
191
- } catch (err) {
192
- errors.push(`${gateway}: ${err instanceof Error ? err.message : String(err)}`);
193
- }
194
- }
195
-
196
- throw new Error(
197
- `Failed to fetch CID ${cid} from all IPFS gateways:\n${errors.map(e => ` - ${e}`).join('\n')}`
198
- );
199
- }
200
-
201
- // ============================================================================
202
- // Pull
203
- // ============================================================================
204
-
205
- /**
206
- * Pull on-chain config to local AGIRAILS.md.
207
- *
208
- * Downloads from IPFS via public gateways (no Filebase credentials needed),
209
- * verifies integrity against on-chain configHash, then writes locally.
210
- *
211
- * @param options - Pull configuration
212
- * @returns Pull result
213
- */
214
- export async function pull(options: PullOptions): Promise<PullResult> {
215
- const { path, agentAddress, registryAddress, provider, force = false } = options;
216
-
217
- // First, run diff
218
- const diffResult = await diff({ path, agentAddress, registryAddress, provider });
219
-
220
- if (!diffResult.hasOnChainConfig) {
221
- return {
222
- written: false,
223
- status: 'No config published on-chain for this agent.',
224
- };
225
- }
226
-
227
- if (diffResult.inSync) {
228
- return {
229
- written: false,
230
- status: 'Already in sync. No changes needed.',
231
- };
232
- }
233
-
234
- // Fetch raw AGIRAILS.md from IPFS (public gateway, no credentials)
235
- const content = await fetchFromIPFS(diffResult.onChainCID);
236
-
237
- // Integrity verification: hash downloaded content and compare with on-chain hash
238
- const { configHash: downloadedHash } = computeConfigHash(content);
239
- if (downloadedHash !== diffResult.onChainHash) {
240
- return {
241
- written: false,
242
- cid: diffResult.onChainCID,
243
- status: `Integrity check failed! Downloaded content hash (${downloadedHash}) does not match on-chain hash (${diffResult.onChainHash}). The IPFS content may have been tampered with.`,
244
- };
245
- }
246
-
247
- // Check if local file exists and we're not forcing
248
- if (diffResult.hasLocalFile && !force) {
249
- return {
250
- written: false,
251
- content,
252
- cid: diffResult.onChainCID,
253
- status: `Remote config differs from local. Use --force to overwrite. CID: ${diffResult.onChainCID}`,
254
- };
255
- }
256
-
257
- // Stamp on-chain metadata into frontmatter so diff heuristic can detect
258
- // future remote changes (without this, pulled files have no config_hash
259
- // and diff would always report "local-ahead" instead of "diverged")
260
- const { frontmatter, body } = parseAgirailsMd(content);
261
- const stamped = serializeAgirailsMd(
262
- {
263
- ...frontmatter,
264
- config_hash: diffResult.onChainHash,
265
- config_cid: diffResult.onChainCID,
266
- },
267
- body
268
- );
269
-
270
- // Write the stamped file
271
- writeFileSync(path, stamped, 'utf-8');
272
-
273
- return {
274
- written: true,
275
- content: stamped,
276
- cid: diffResult.onChainCID,
277
- status: `Pulled and verified config from IPFS (${diffResult.onChainCID}) → ${path}`,
278
- };
279
- }