@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,324 +0,0 @@
1
- /**
2
- * Circuit Breaker - Gateway Health Tracking (Retry Amplification Protection)
3
- *
4
- * Implements the Circuit Breaker pattern for storage gateways:
5
- * - Tracks consecutive failures per gateway
6
- * - "Opens" circuit after threshold failures (blocks requests)
7
- * - Auto-resets after cooldown period
8
- *
9
- * This prevents retry amplification attacks where a malicious/failing
10
- * gateway causes excessive retries.
11
- *
12
- * @module utils/circuitBreaker
13
- */
14
-
15
- // ============================================================================
16
- // Types
17
- // ============================================================================
18
-
19
- /**
20
- * Circuit state
21
- */
22
- export type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN';
23
-
24
- /**
25
- * Gateway health record
26
- */
27
- interface GatewayHealth {
28
- /** Consecutive failure count */
29
- failures: number;
30
- /** Timestamp of last failure */
31
- lastFailure: number;
32
- /** Current circuit state */
33
- state: CircuitState;
34
- /** Timestamp when circuit opened */
35
- openedAt?: number;
36
- }
37
-
38
- /**
39
- * Circuit breaker configuration
40
- */
41
- export interface CircuitBreakerConfig {
42
- /** Number of failures before opening circuit (default: 5) */
43
- failureThreshold?: number;
44
-
45
- /** Cooldown period in ms before attempting reset (default: 60000 = 1 min) */
46
- resetTimeoutMs?: number;
47
-
48
- /** Time window in ms for counting failures (default: 300000 = 5 min) */
49
- failureWindowMs?: number;
50
-
51
- /** Number of successes in half-open to close circuit (default: 2) */
52
- successThreshold?: number;
53
- }
54
-
55
- // ============================================================================
56
- // Constants
57
- // ============================================================================
58
-
59
- const DEFAULT_FAILURE_THRESHOLD = 5;
60
- const DEFAULT_RESET_TIMEOUT_MS = 60000; // 1 minute
61
- const DEFAULT_FAILURE_WINDOW_MS = 300000; // 5 minutes
62
- const DEFAULT_SUCCESS_THRESHOLD = 2;
63
-
64
- // ============================================================================
65
- // GatewayCircuitBreaker Class
66
- // ============================================================================
67
-
68
- /**
69
- * Circuit Breaker for gateway health management
70
- *
71
- * Usage:
72
- * ```typescript
73
- * const circuitBreaker = new GatewayCircuitBreaker();
74
- *
75
- * // Before making request
76
- * if (!circuitBreaker.isHealthy(gatewayUrl)) {
77
- * throw new Error('Gateway circuit open');
78
- * }
79
- *
80
- * try {
81
- * const result = await fetchFromGateway(gatewayUrl);
82
- * circuitBreaker.recordSuccess(gatewayUrl);
83
- * return result;
84
- * } catch (error) {
85
- * circuitBreaker.recordFailure(gatewayUrl);
86
- * throw error;
87
- * }
88
- * ```
89
- */
90
- export class GatewayCircuitBreaker {
91
- private readonly health = new Map<string, GatewayHealth>();
92
- private readonly config: Required<CircuitBreakerConfig>;
93
- private halfOpenSuccesses = new Map<string, number>();
94
-
95
- constructor(config: CircuitBreakerConfig = {}) {
96
- this.config = {
97
- failureThreshold: config.failureThreshold ?? DEFAULT_FAILURE_THRESHOLD,
98
- resetTimeoutMs: config.resetTimeoutMs ?? DEFAULT_RESET_TIMEOUT_MS,
99
- failureWindowMs: config.failureWindowMs ?? DEFAULT_FAILURE_WINDOW_MS,
100
- successThreshold: config.successThreshold ?? DEFAULT_SUCCESS_THRESHOLD
101
- };
102
- }
103
-
104
- /**
105
- * Check if gateway is healthy (circuit closed or half-open)
106
- *
107
- * @param url - Gateway URL
108
- * @returns true if requests should be allowed
109
- */
110
- isHealthy(url: string): boolean {
111
- const state = this.getState(url);
112
- return state !== 'OPEN';
113
- }
114
-
115
- /**
116
- * Get current circuit state for gateway
117
- *
118
- * @param url - Gateway URL
119
- * @returns Circuit state
120
- */
121
- getState(url: string): CircuitState {
122
- const health = this.health.get(url);
123
-
124
- if (!health) {
125
- return 'CLOSED';
126
- }
127
-
128
- // Check if circuit should transition from OPEN to HALF_OPEN
129
- if (health.state === 'OPEN') {
130
- const timeSinceOpen = Date.now() - (health.openedAt || 0);
131
- if (timeSinceOpen >= this.config.resetTimeoutMs) {
132
- // Transition to half-open
133
- health.state = 'HALF_OPEN';
134
- this.halfOpenSuccesses.set(url, 0);
135
- }
136
- }
137
-
138
- // Check if failures have expired (outside window)
139
- if (health.state === 'CLOSED') {
140
- const timeSinceLastFailure = Date.now() - health.lastFailure;
141
- if (timeSinceLastFailure >= this.config.failureWindowMs) {
142
- // Reset failure count
143
- health.failures = 0;
144
- }
145
- }
146
-
147
- return health.state;
148
- }
149
-
150
- /**
151
- * Record a successful request
152
- *
153
- * @param url - Gateway URL
154
- */
155
- recordSuccess(url: string): void {
156
- const health = this.health.get(url);
157
-
158
- if (!health) {
159
- return; // No failures recorded, nothing to do
160
- }
161
-
162
- if (health.state === 'HALF_OPEN') {
163
- // Count successes in half-open state
164
- const successes = (this.halfOpenSuccesses.get(url) || 0) + 1;
165
- this.halfOpenSuccesses.set(url, successes);
166
-
167
- if (successes >= this.config.successThreshold) {
168
- // Enough successes - close circuit
169
- this.reset(url);
170
- }
171
- } else if (health.state === 'CLOSED') {
172
- // Reset failure count on success
173
- health.failures = 0;
174
- }
175
- }
176
-
177
- /**
178
- * Record a failed request
179
- *
180
- * @param url - Gateway URL
181
- */
182
- recordFailure(url: string): void {
183
- const now = Date.now();
184
- let health = this.health.get(url);
185
-
186
- if (!health) {
187
- health = {
188
- failures: 0,
189
- lastFailure: now,
190
- state: 'CLOSED'
191
- };
192
- this.health.set(url, health);
193
- }
194
-
195
- // If in half-open state, any failure opens circuit again
196
- if (health.state === 'HALF_OPEN') {
197
- health.state = 'OPEN';
198
- health.openedAt = now;
199
- health.failures = this.config.failureThreshold; // Keep at threshold
200
- this.halfOpenSuccesses.delete(url);
201
- return;
202
- }
203
-
204
- // Check if previous failures have expired
205
- const timeSinceLastFailure = now - health.lastFailure;
206
- if (timeSinceLastFailure >= this.config.failureWindowMs) {
207
- health.failures = 0;
208
- }
209
-
210
- // Increment failure count
211
- health.failures++;
212
- health.lastFailure = now;
213
-
214
- // Check if threshold reached
215
- if (health.failures >= this.config.failureThreshold) {
216
- health.state = 'OPEN';
217
- health.openedAt = now;
218
- }
219
- }
220
-
221
- /**
222
- * Reset circuit for gateway (force close)
223
- *
224
- * @param url - Gateway URL
225
- */
226
- reset(url: string): void {
227
- this.health.delete(url);
228
- this.halfOpenSuccesses.delete(url);
229
- }
230
-
231
- /**
232
- * Reset all circuits
233
- */
234
- resetAll(): void {
235
- this.health.clear();
236
- this.halfOpenSuccesses.clear();
237
- }
238
-
239
- /**
240
- * Get health status for all tracked gateways
241
- *
242
- * @returns Map of gateway URL to health info
243
- */
244
- getHealthStatus(): Map<string, { state: CircuitState; failures: number }> {
245
- const status = new Map<string, { state: CircuitState; failures: number }>();
246
-
247
- for (const [url, health] of this.health) {
248
- status.set(url, {
249
- state: this.getState(url), // This updates state if needed
250
- failures: health.failures
251
- });
252
- }
253
-
254
- return status;
255
- }
256
-
257
- /**
258
- * Get failure count for gateway
259
- *
260
- * @param url - Gateway URL
261
- * @returns Number of consecutive failures
262
- */
263
- getFailureCount(url: string): number {
264
- return this.health.get(url)?.failures || 0;
265
- }
266
- }
267
-
268
- // ============================================================================
269
- // Singleton Instance
270
- // ============================================================================
271
-
272
- /**
273
- * Default global circuit breaker instance
274
- *
275
- * Use this for simple cases where a single circuit breaker is sufficient.
276
- * For more control, create your own GatewayCircuitBreaker instance.
277
- */
278
- export const globalCircuitBreaker = new GatewayCircuitBreaker();
279
-
280
- // ============================================================================
281
- // Helper Functions
282
- // ============================================================================
283
-
284
- /**
285
- * Wrap an async operation with circuit breaker protection
286
- *
287
- * @param url - Gateway URL to track
288
- * @param operation - Async operation to execute
289
- * @param circuitBreaker - Circuit breaker instance (default: global)
290
- * @returns Operation result
291
- * @throws Error if circuit is open, or operation error
292
- *
293
- * @example
294
- * ```typescript
295
- * const result = await withCircuitBreaker(
296
- * 'https://ipfs.filebase.io',
297
- * () => fetch(url).then(r => r.json())
298
- * );
299
- * ```
300
- */
301
- export async function withCircuitBreaker<T>(
302
- url: string,
303
- operation: () => Promise<T>,
304
- circuitBreaker: GatewayCircuitBreaker = globalCircuitBreaker
305
- ): Promise<T> {
306
- // Check if circuit allows request
307
- if (!circuitBreaker.isHealthy(url)) {
308
- const state = circuitBreaker.getState(url);
309
- throw new Error(
310
- `Circuit breaker OPEN for gateway: ${url}. ` +
311
- `State: ${state}, Failures: ${circuitBreaker.getFailureCount(url)}. ` +
312
- `Please wait for cooldown period before retrying.`
313
- );
314
- }
315
-
316
- try {
317
- const result = await operation();
318
- circuitBreaker.recordSuccess(url);
319
- return result;
320
- } catch (error) {
321
- circuitBreaker.recordFailure(url);
322
- throw error;
323
- }
324
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Compute EIP-712 Type Hash for AIP-4 Delivery Proof
3
- * Reference: AIP-4 §3.3, EIP-712 specification
4
- *
5
- * Run with: npx tsx src/utils/computeTypeHash.ts
6
- */
7
-
8
- import { TypedDataEncoder, keccak256, toUtf8Bytes } from 'ethers';
9
- import { AIP4DeliveryProofTypes } from '../types/eip712';
10
-
11
- /**
12
- * Compute EIP-712 type hash for DeliveryProof
13
- * @returns Type hash (bytes32)
14
- */
15
- export function computeDeliveryProofTypeHash(): string {
16
- const encoder = TypedDataEncoder.from(AIP4DeliveryProofTypes);
17
- const typeString = encoder.encodeType('DeliveryProof');
18
-
19
- // Type hash is keccak256 of the encoded type string
20
- const typeHash = keccak256(toUtf8Bytes(typeString));
21
-
22
- return typeHash;
23
- }
24
-
25
- /**
26
- * Get encoded type string for DeliveryProof
27
- * @returns Type string (for documentation)
28
- */
29
- export function getDeliveryProofTypeString(): string {
30
- return TypedDataEncoder.from(AIP4DeliveryProofTypes).encodeType('DeliveryProof');
31
- }
32
-
33
- // If run directly, compute and print type hash
34
- if (require.main === module) {
35
- console.log('=== AIP-4 Delivery Proof EIP-712 Type Hash ===\n');
36
-
37
- const typeString = getDeliveryProofTypeString();
38
- console.log('Type String:');
39
- console.log(typeString);
40
- console.log();
41
-
42
- const typeHash = computeDeliveryProofTypeHash();
43
- console.log('Type Hash (bytes32):');
44
- console.log(typeHash);
45
- console.log();
46
-
47
- console.log('Use this type hash in your EIP-712 typed data configuration.');
48
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * fsSafe - minimal filesystem hardening helpers
3
- *
4
- * Focus:
5
- * - Prevent symlink-based path escapes when persisting local state
6
- * - Avoid clobbering arbitrary files via pre-created symlink temp files
7
- *
8
- * NOTE: This is not a complete TOCTOU-proof sandbox, but it eliminates the
9
- * most common local symlink/hardlink footguns for SDK-managed state files.
10
- */
11
-
12
- import * as fs from 'fs';
13
-
14
- export function ensureSafeDir(dirPath: string, mode: number = 0o755): void {
15
- if (fs.existsSync(dirPath)) {
16
- const st = fs.lstatSync(dirPath);
17
- if (st.isSymbolicLink()) {
18
- throw new Error(`Refusing to use symlink directory: ${dirPath}`);
19
- }
20
- if (!st.isDirectory()) {
21
- throw new Error(`Expected directory but found non-directory: ${dirPath}`);
22
- }
23
- return;
24
- }
25
-
26
- fs.mkdirSync(dirPath, { recursive: true, mode });
27
-
28
- // Post-create sanity: ensure it didn't become a symlink (defense-in-depth)
29
- const st = fs.lstatSync(dirPath);
30
- if (st.isSymbolicLink() || !st.isDirectory()) {
31
- throw new Error(`Created unsafe directory (symlink or non-dir): ${dirPath}`);
32
- }
33
- }
34
-
35
- export function assertSafeFileForRead(filePath: string): void {
36
- if (!fs.existsSync(filePath)) return;
37
- const st = fs.lstatSync(filePath);
38
- if (st.isSymbolicLink()) {
39
- throw new Error(`Refusing to read from symlink file: ${filePath}`);
40
- }
41
- if (!st.isFile()) {
42
- throw new Error(`Expected file but found non-file: ${filePath}`);
43
- }
44
- }
45
-
46
- export function ensureSafeFile(
47
- filePath: string,
48
- contents: string,
49
- mode: number = 0o644
50
- ): void {
51
- if (fs.existsSync(filePath)) {
52
- const st = fs.lstatSync(filePath);
53
- if (st.isSymbolicLink()) {
54
- throw new Error(`Refusing to use symlink file: ${filePath}`);
55
- }
56
- if (!st.isFile()) {
57
- throw new Error(`Expected file but found non-file: ${filePath}`);
58
- }
59
- return;
60
- }
61
-
62
- // Use exclusive create to avoid clobbering a file that appears between
63
- // existsSync() and writeFileSync().
64
- fs.writeFileSync(filePath, contents, {
65
- encoding: 'utf-8',
66
- mode,
67
- flag: 'wx',
68
- });
69
- }
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
@@ -1,80 +0,0 @@
1
- /**
2
- * ACTP SDK Utilities
3
- *
4
- * This module exports all utility classes for the ACTP SDK.
5
- *
6
- * @module utils
7
- */
8
-
9
- // Error Recovery (HIGH-6)
10
- export {
11
- ErrorRecoveryGuide,
12
- withRecoveryGuidance,
13
- type ErrorRecoveryInfo,
14
- type ErrorSeverity,
15
- type ErrorCategory,
16
- } from './ErrorRecoveryGuide';
17
-
18
- // Rate Limiting & Circuit Breaker (M-4, M-5)
19
- export {
20
- RateLimiter,
21
- CircuitBreaker,
22
- APIProtector,
23
- type RateLimiterConfig,
24
- type RateLimitResult,
25
- type CircuitBreakerConfig,
26
- type CircuitBreakerResult,
27
- type CircuitState,
28
- } from './RateLimiter';
29
-
30
- // Logging & Metrics (M-6, M-7)
31
- export {
32
- Logger,
33
- MetricsCollector,
34
- sdkLogger,
35
- sdkMetrics,
36
- type LogLevel,
37
- type LogEntry,
38
- type LoggerConfig,
39
- type MetricsHook,
40
- } from './Logger';
41
-
42
- // SDK Lifecycle (M-8)
43
- export {
44
- SDKLifecycle,
45
- sdkLifecycle,
46
- onShutdown,
47
- registerDisposable,
48
- shutdownSDK,
49
- type Disposable,
50
- type ShutdownHandler,
51
- type LifecycleEvent,
52
- type LifecycleListener,
53
- } from './SDKLifecycle';
54
-
55
- // Nonce Tracking (Security)
56
- export {
57
- InMemoryReceivedNonceTracker,
58
- SetBasedReceivedNonceTracker,
59
- createReceivedNonceTracker,
60
- type IReceivedNonceTracker,
61
- type NonceValidationResult,
62
- } from './ReceivedNonceTracker';
63
-
64
- // Attestation Tracking (Security)
65
- export {
66
- InMemoryUsedAttestationTracker,
67
- FileBasedUsedAttestationTracker,
68
- createUsedAttestationTracker,
69
- type IUsedAttestationTracker,
70
- } from './UsedAttestationTracker';
71
-
72
- // Helper Utilities (L-7)
73
- export {
74
- USDC,
75
- Deadline,
76
- Address,
77
- Bytes32,
78
- State,
79
- DisputeWindow,
80
- } from './Helpers';