@agirails/sdk 2.0.1-beta → 2.0.2
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/LICENSE +190 -0
- package/README.md +116 -108
- package/bin/actp +10 -0
- package/dist/ACTPClient.d.ts +456 -33
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +477 -93
- package/dist/ACTPClient.js.map +1 -1
- package/dist/abi/AgentRegistry.json +782 -0
- package/dist/abi/EscrowVault.json +106 -38
- package/dist/abi/IdentityRegistry.json +316 -0
- package/dist/adapters/BaseAdapter.d.ts +231 -0
- package/dist/adapters/BaseAdapter.d.ts.map +1 -0
- package/dist/adapters/BaseAdapter.js +393 -0
- package/dist/adapters/BaseAdapter.js.map +1 -0
- package/dist/adapters/BeginnerAdapter.d.ts +152 -0
- package/dist/adapters/BeginnerAdapter.d.ts.map +1 -0
- package/dist/adapters/BeginnerAdapter.js +168 -0
- package/dist/adapters/BeginnerAdapter.js.map +1 -0
- package/dist/adapters/IntermediateAdapter.d.ts +211 -0
- package/dist/adapters/IntermediateAdapter.d.ts.map +1 -0
- package/dist/adapters/IntermediateAdapter.js +260 -0
- package/dist/adapters/IntermediateAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +15 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +26 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/builders/DeliveryProofBuilder.d.ts +60 -1
- package/dist/builders/DeliveryProofBuilder.d.ts.map +1 -1
- package/dist/builders/DeliveryProofBuilder.js +81 -5
- package/dist/builders/DeliveryProofBuilder.js.map +1 -1
- package/dist/builders/QuoteBuilder.d.ts +101 -0
- package/dist/builders/QuoteBuilder.d.ts.map +1 -1
- package/dist/builders/QuoteBuilder.js +120 -3
- package/dist/builders/QuoteBuilder.js.map +1 -1
- package/dist/builders/index.d.ts +4 -0
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +4 -0
- package/dist/builders/index.js.map +1 -1
- package/dist/cli/commands/balance.d.ts +13 -0
- package/dist/cli/commands/balance.d.ts.map +1 -0
- package/dist/cli/commands/balance.js +89 -0
- package/dist/cli/commands/balance.js.map +1 -0
- package/dist/cli/commands/batch.d.ts +24 -0
- package/dist/cli/commands/batch.d.ts.map +1 -0
- package/dist/cli/commands/batch.js +424 -0
- package/dist/cli/commands/batch.js.map +1 -0
- package/dist/cli/commands/config.d.ts +13 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +192 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/init.d.ts +19 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +143 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/mint.d.ts +13 -0
- package/dist/cli/commands/mint.d.ts.map +1 -0
- package/dist/cli/commands/mint.js +91 -0
- package/dist/cli/commands/mint.js.map +1 -0
- package/dist/cli/commands/pay.d.ts +18 -0
- package/dist/cli/commands/pay.d.ts.map +1 -0
- package/dist/cli/commands/pay.js +87 -0
- package/dist/cli/commands/pay.js.map +1 -0
- package/dist/cli/commands/simulate.d.ts +32 -0
- package/dist/cli/commands/simulate.d.ts.map +1 -0
- package/dist/cli/commands/simulate.js +290 -0
- package/dist/cli/commands/simulate.js.map +1 -0
- package/dist/cli/commands/time.d.ts +29 -0
- package/dist/cli/commands/time.d.ts.map +1 -0
- package/dist/cli/commands/time.js +252 -0
- package/dist/cli/commands/time.js.map +1 -0
- package/dist/cli/commands/tx.d.ts +16 -0
- package/dist/cli/commands/tx.d.ts.map +1 -0
- package/dist/cli/commands/tx.js +379 -0
- package/dist/cli/commands/tx.js.map +1 -0
- package/dist/cli/commands/watch.d.ts +20 -0
- package/dist/cli/commands/watch.d.ts.map +1 -0
- package/dist/cli/commands/watch.js +160 -0
- package/dist/cli/commands/watch.js.map +1 -0
- package/dist/cli/index.d.ts +17 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +104 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/client.d.ts +70 -0
- package/dist/cli/utils/client.d.ts.map +1 -0
- package/dist/cli/utils/client.js +240 -0
- package/dist/cli/utils/client.js.map +1 -0
- package/dist/cli/utils/config.d.ts +91 -0
- package/dist/cli/utils/config.d.ts.map +1 -0
- package/dist/cli/utils/config.js +240 -0
- package/dist/cli/utils/config.js.map +1 -0
- package/dist/cli/utils/output.d.ts +174 -0
- package/dist/cli/utils/output.d.ts.map +1 -0
- package/dist/cli/utils/output.js +380 -0
- package/dist/cli/utils/output.js.map +1 -0
- package/dist/config/networks.d.ts +28 -0
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +60 -12
- package/dist/config/networks.js.map +1 -1
- package/dist/errors/index.d.ts +165 -2
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +260 -2
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +61 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +141 -36
- package/dist/index.js.map +1 -1
- package/dist/level0/Provider.d.ts +106 -0
- package/dist/level0/Provider.d.ts.map +1 -0
- package/dist/level0/Provider.js +10 -0
- package/dist/level0/Provider.js.map +1 -0
- package/dist/level0/ServiceDirectory.d.ts +74 -0
- package/dist/level0/ServiceDirectory.d.ts.map +1 -0
- package/dist/level0/ServiceDirectory.js +122 -0
- package/dist/level0/ServiceDirectory.js.map +1 -0
- package/dist/level0/index.d.ts +10 -0
- package/dist/level0/index.d.ts.map +1 -0
- package/dist/level0/index.js +15 -0
- package/dist/level0/index.js.map +1 -0
- package/dist/level0/provide.d.ts +51 -0
- package/dist/level0/provide.d.ts.map +1 -0
- package/dist/level0/provide.js +113 -0
- package/dist/level0/provide.js.map +1 -0
- package/dist/level0/request.d.ts +53 -0
- package/dist/level0/request.d.ts.map +1 -0
- package/dist/level0/request.js +462 -0
- package/dist/level0/request.js.map +1 -0
- package/dist/level1/Agent.d.ts +472 -0
- package/dist/level1/Agent.d.ts.map +1 -0
- package/dist/level1/Agent.js +1091 -0
- package/dist/level1/Agent.js.map +1 -0
- package/dist/level1/index.d.ts +10 -0
- package/dist/level1/index.d.ts.map +1 -0
- package/dist/level1/index.js +30 -0
- package/dist/level1/index.js.map +1 -0
- package/dist/level1/pricing/PriceCalculator.d.ts +62 -0
- package/dist/level1/pricing/PriceCalculator.d.ts.map +1 -0
- package/dist/level1/pricing/PriceCalculator.js +237 -0
- package/dist/level1/pricing/PriceCalculator.js.map +1 -0
- package/dist/level1/pricing/PricingStrategy.d.ts +179 -0
- package/dist/level1/pricing/PricingStrategy.d.ts.map +1 -0
- package/dist/level1/pricing/PricingStrategy.js +11 -0
- package/dist/level1/pricing/PricingStrategy.js.map +1 -0
- package/dist/level1/types/Job.d.ts +166 -0
- package/dist/level1/types/Job.d.ts.map +1 -0
- package/dist/level1/types/Job.js +11 -0
- package/dist/level1/types/Job.js.map +1 -0
- package/dist/level1/types/Options.d.ts +258 -0
- package/dist/level1/types/Options.d.ts.map +1 -0
- package/dist/level1/types/Options.js +8 -0
- package/dist/level1/types/Options.js.map +1 -0
- package/dist/level1/types/index.d.ts +8 -0
- package/dist/level1/types/index.d.ts.map +1 -0
- package/dist/level1/types/index.js +8 -0
- package/dist/level1/types/index.js.map +1 -0
- package/dist/protocol/ACTPKernel.d.ts +229 -2
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +367 -33
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/protocol/AgentRegistry.d.ts +177 -0
- package/dist/protocol/AgentRegistry.d.ts.map +1 -0
- package/dist/protocol/AgentRegistry.js +449 -0
- package/dist/protocol/AgentRegistry.js.map +1 -0
- package/dist/protocol/DIDManager.d.ts +289 -0
- package/dist/protocol/DIDManager.d.ts.map +1 -0
- package/dist/protocol/DIDManager.js +481 -0
- package/dist/protocol/DIDManager.js.map +1 -0
- package/dist/protocol/DIDResolver.d.ts +236 -0
- package/dist/protocol/DIDResolver.d.ts.map +1 -0
- package/dist/protocol/DIDResolver.js +495 -0
- package/dist/protocol/DIDResolver.js.map +1 -0
- package/dist/protocol/EASHelper.d.ts +57 -2
- package/dist/protocol/EASHelper.d.ts.map +1 -1
- package/dist/protocol/EASHelper.js +230 -37
- package/dist/protocol/EASHelper.js.map +1 -1
- package/dist/protocol/EscrowVault.d.ts +93 -2
- package/dist/protocol/EscrowVault.d.ts.map +1 -1
- package/dist/protocol/EscrowVault.js +122 -33
- package/dist/protocol/EscrowVault.js.map +1 -1
- package/dist/protocol/EventMonitor.d.ts +45 -1
- package/dist/protocol/EventMonitor.d.ts.map +1 -1
- package/dist/protocol/EventMonitor.js +64 -8
- package/dist/protocol/EventMonitor.js.map +1 -1
- package/dist/protocol/MessageSigner.d.ts +116 -2
- package/dist/protocol/MessageSigner.d.ts.map +1 -1
- package/dist/protocol/MessageSigner.js +215 -9
- package/dist/protocol/MessageSigner.js.map +1 -1
- package/dist/protocol/ProofGenerator.d.ts +93 -0
- package/dist/protocol/ProofGenerator.d.ts.map +1 -1
- package/dist/protocol/ProofGenerator.js +194 -9
- package/dist/protocol/ProofGenerator.js.map +1 -1
- package/dist/protocol/QuoteBuilder.d.ts +8 -0
- package/dist/protocol/QuoteBuilder.d.ts.map +1 -1
- package/dist/protocol/QuoteBuilder.js +8 -0
- package/dist/protocol/QuoteBuilder.js.map +1 -1
- package/dist/runtime/BlockchainRuntime.d.ts +360 -0
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -0
- package/dist/runtime/BlockchainRuntime.js +767 -0
- package/dist/runtime/BlockchainRuntime.js.map +1 -0
- package/dist/runtime/IACTPRuntime.d.ts +271 -0
- package/dist/runtime/IACTPRuntime.d.ts.map +1 -0
- package/dist/runtime/IACTPRuntime.js +15 -0
- package/dist/runtime/IACTPRuntime.js.map +1 -0
- package/dist/runtime/MockRuntime.d.ts +445 -0
- package/dist/runtime/MockRuntime.d.ts.map +1 -0
- package/dist/runtime/MockRuntime.js +1065 -0
- package/dist/runtime/MockRuntime.js.map +1 -0
- package/dist/runtime/MockStateManager.d.ts +233 -0
- package/dist/runtime/MockStateManager.d.ts.map +1 -0
- package/dist/runtime/MockStateManager.js +533 -0
- package/dist/runtime/MockStateManager.js.map +1 -0
- package/dist/runtime/index.d.ts +14 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +42 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/types/MockState.d.ts +167 -0
- package/dist/runtime/types/MockState.d.ts.map +1 -0
- package/dist/runtime/types/MockState.js +43 -0
- package/dist/runtime/types/MockState.js.map +1 -0
- package/dist/types/agent.d.ts +76 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +8 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/did.d.ts +192 -0
- package/dist/types/did.d.ts.map +1 -0
- package/dist/types/did.js +38 -0
- package/dist/types/did.js.map +1 -0
- package/dist/types/eip712.d.ts +34 -0
- package/dist/types/eip712.d.ts.map +1 -1
- package/dist/types/eip712.js +31 -5
- package/dist/types/eip712.js.map +1 -1
- package/dist/types/escrow.d.ts +17 -10
- package/dist/types/escrow.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/message.d.ts +32 -0
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js +4 -0
- package/dist/types/message.js.map +1 -1
- package/dist/types/state.d.ts +28 -0
- package/dist/types/state.d.ts.map +1 -1
- package/dist/types/state.js +37 -6
- package/dist/types/state.js.map +1 -1
- package/dist/types/transaction.d.ts +17 -0
- package/dist/types/transaction.d.ts.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.d.ts +125 -0
- package/dist/utils/ErrorRecoveryGuide.d.ts.map +1 -0
- package/dist/utils/ErrorRecoveryGuide.js +579 -0
- package/dist/utils/ErrorRecoveryGuide.js.map +1 -0
- package/dist/utils/Helpers.d.ts +453 -0
- package/dist/utils/Helpers.d.ts.map +1 -0
- package/dist/utils/Helpers.js +623 -0
- package/dist/utils/Helpers.js.map +1 -0
- package/dist/utils/IPFSClient.d.ts +113 -0
- package/dist/utils/IPFSClient.d.ts.map +1 -1
- package/dist/utils/IPFSClient.js +128 -7
- package/dist/utils/IPFSClient.js.map +1 -1
- package/dist/utils/Logger.d.ts +195 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +382 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/NonceManager.d.ts +234 -1
- package/dist/utils/NonceManager.d.ts.map +1 -1
- package/dist/utils/NonceManager.js +372 -7
- package/dist/utils/NonceManager.js.map +1 -1
- package/dist/utils/RateLimiter.d.ts +253 -0
- package/dist/utils/RateLimiter.d.ts.map +1 -0
- package/dist/utils/RateLimiter.js +424 -0
- package/dist/utils/RateLimiter.js.map +1 -0
- package/dist/utils/ReceivedNonceTracker.d.ts +175 -0
- package/dist/utils/ReceivedNonceTracker.d.ts.map +1 -1
- package/dist/utils/ReceivedNonceTracker.js +261 -5
- package/dist/utils/ReceivedNonceTracker.js.map +1 -1
- package/dist/utils/SDKLifecycle.d.ts +156 -0
- package/dist/utils/SDKLifecycle.d.ts.map +1 -0
- package/dist/utils/SDKLifecycle.js +347 -0
- package/dist/utils/SDKLifecycle.js.map +1 -0
- package/dist/utils/SecureNonce.d.ts +57 -0
- package/dist/utils/SecureNonce.d.ts.map +1 -0
- package/dist/utils/SecureNonce.js +80 -0
- package/dist/utils/SecureNonce.js.map +1 -0
- package/dist/utils/Semaphore.d.ts +123 -0
- package/dist/utils/Semaphore.d.ts.map +1 -0
- package/dist/utils/Semaphore.js +247 -0
- package/dist/utils/Semaphore.js.map +1 -0
- package/dist/utils/UsedAttestationTracker.d.ts +167 -0
- package/dist/utils/UsedAttestationTracker.d.ts.map +1 -0
- package/dist/utils/UsedAttestationTracker.js +309 -0
- package/dist/utils/UsedAttestationTracker.js.map +1 -0
- package/dist/utils/canonicalJson.d.ts +22 -0
- package/dist/utils/canonicalJson.d.ts.map +1 -1
- package/dist/utils/canonicalJson.js +26 -3
- package/dist/utils/canonicalJson.js.map +1 -1
- package/dist/utils/computeTypeHash.d.ts +14 -0
- package/dist/utils/computeTypeHash.d.ts.map +1 -1
- package/dist/utils/computeTypeHash.js +19 -2
- package/dist/utils/computeTypeHash.js.map +1 -1
- package/dist/utils/fsSafe.d.ts +14 -0
- package/dist/utils/fsSafe.d.ts.map +1 -0
- package/dist/utils/fsSafe.js +89 -0
- package/dist/utils/fsSafe.js.map +1 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +51 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/security.d.ts +147 -0
- package/dist/utils/security.d.ts.map +1 -0
- package/dist/utils/security.js +391 -0
- package/dist/utils/security.js.map +1 -0
- package/dist/utils/validation.d.ts +40 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +184 -7
- package/dist/utils/validation.js.map +1 -1
- package/package.json +54 -37
- package/src/ACTPClient.ts +692 -178
- package/src/abi/AgentRegistry.json +782 -0
- package/src/abi/EscrowVault.json +106 -38
- package/src/abi/IdentityRegistry.json +316 -0
- package/src/adapters/BaseAdapter.ts +473 -0
- package/src/adapters/BeginnerAdapter.ts +232 -0
- package/src/adapters/IntermediateAdapter.ts +316 -0
- package/src/adapters/index.ts +25 -0
- package/src/builders/DeliveryProofBuilder.ts +3 -2
- package/src/cli/commands/balance.ts +110 -0
- package/src/cli/commands/batch.ts +487 -0
- package/src/cli/commands/config.ts +231 -0
- package/src/cli/commands/init.ts +161 -0
- package/src/cli/commands/mint.ts +116 -0
- package/src/cli/commands/pay.ts +113 -0
- package/src/cli/commands/simulate.ts +345 -0
- package/src/cli/commands/time.ts +303 -0
- package/src/cli/commands/tx.ts +448 -0
- package/src/cli/commands/watch.ts +211 -0
- package/src/cli/index.ts +116 -0
- package/src/cli/utils/client.ts +249 -0
- package/src/cli/utils/config.ts +282 -0
- package/src/cli/utils/output.ts +465 -0
- package/src/config/networks.ts +32 -9
- package/src/errors/index.ts +298 -1
- package/src/index.ts +207 -71
- package/src/level0/Provider.ts +117 -0
- package/src/level0/ServiceDirectory.ts +131 -0
- package/src/level0/index.ts +10 -0
- package/src/level0/provide.ts +131 -0
- package/src/level0/request.ts +494 -0
- package/src/level1/Agent.ts +1432 -0
- package/src/level1/index.ts +10 -0
- package/src/level1/pricing/PriceCalculator.ts +255 -0
- package/src/level1/pricing/PricingStrategy.ts +198 -0
- package/src/level1/types/Job.ts +179 -0
- package/src/level1/types/Options.ts +291 -0
- package/src/level1/types/index.ts +8 -0
- package/src/protocol/ACTPKernel.ts +175 -23
- package/src/protocol/AgentRegistry.ts +559 -0
- package/src/protocol/DIDManager.ts +629 -0
- package/src/protocol/DIDResolver.ts +554 -0
- package/src/protocol/EASHelper.ts +230 -46
- package/src/protocol/EscrowVault.ts +68 -50
- package/src/protocol/EventMonitor.ts +44 -15
- package/src/protocol/MessageSigner.ts +193 -13
- package/src/protocol/ProofGenerator.ts +223 -4
- package/src/runtime/BlockchainRuntime.ts +993 -0
- package/src/runtime/IACTPRuntime.ts +284 -0
- package/src/runtime/MockRuntime.ts +1244 -0
- package/src/runtime/MockStateManager.ts +576 -0
- package/src/runtime/index.ts +25 -0
- package/src/runtime/types/MockState.ts +227 -0
- package/src/types/agent.ts +79 -0
- package/src/types/did.ts +223 -0
- package/src/types/escrow.ts +12 -11
- package/src/types/index.ts +5 -1
- package/src/types/state.ts +12 -3
- package/src/types/transaction.ts +4 -1
- package/src/utils/ErrorRecoveryGuide.ts +675 -0
- package/src/utils/Helpers.ts +688 -0
- package/src/utils/IPFSClient.ts +122 -5
- package/src/utils/Logger.ts +484 -0
- package/src/utils/NonceManager.ts +305 -8
- package/src/utils/RateLimiter.ts +534 -0
- package/src/utils/ReceivedNonceTracker.ts +170 -0
- package/src/utils/SDKLifecycle.ts +416 -0
- package/src/utils/SecureNonce.ts +78 -0
- package/src/utils/Semaphore.ts +276 -0
- package/src/utils/UsedAttestationTracker.ts +387 -0
- package/src/utils/fsSafe.ts +75 -0
- package/src/utils/index.ts +80 -0
- package/src/utils/security.ts +418 -0
- package/src/utils/validation.ts +164 -0
- package/src/__tests__/ProofGenerator.test.ts +0 -124
- package/src/__tests__/QuoteBuilder.test.ts +0 -516
- package/src/__tests__/StateMachine.test.ts +0 -82
- package/src/__tests__/builders/DeliveryProofBuilder.test.ts +0 -581
- package/src/__tests__/integration/ACTPClient.test.ts +0 -263
- package/src/__tests__/integration.test.ts +0 -289
- package/src/__tests__/protocol/EASHelper.test.ts +0 -472
- package/src/__tests__/protocol/EventMonitor.test.ts +0 -382
- package/src/__tests__/security/ACTPKernel.security.test.ts +0 -1167
- package/src/__tests__/security/EscrowVault.security.test.ts +0 -570
- package/src/__tests__/security/MessageSigner.security.test.ts +0 -286
- package/src/__tests__/security/NonceReplay.security.test.ts +0 -501
- package/src/__tests__/security/validation.security.test.ts +0 -376
- package/src/__tests__/utils/IPFSClient.test.ts +0 -262
- package/src/__tests__/utils/NonceManager.test.ts +0 -205
- package/src/__tests__/utils/canonicalJson.test.ts +0 -153
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ACTP SDK Utilities
|
|
4
|
+
*
|
|
5
|
+
* This module exports all utility classes for the ACTP SDK.
|
|
6
|
+
*
|
|
7
|
+
* @module utils
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DisputeWindow = exports.State = exports.Bytes32 = exports.Address = exports.Deadline = exports.USDC = exports.createUsedAttestationTracker = exports.FileBasedUsedAttestationTracker = exports.InMemoryUsedAttestationTracker = exports.createReceivedNonceTracker = exports.SetBasedReceivedNonceTracker = exports.InMemoryReceivedNonceTracker = exports.shutdownSDK = exports.registerDisposable = exports.onShutdown = exports.sdkLifecycle = exports.SDKLifecycle = exports.sdkMetrics = exports.sdkLogger = exports.MetricsCollector = exports.Logger = exports.APIProtector = exports.CircuitBreaker = exports.RateLimiter = exports.withRecoveryGuidance = exports.ErrorRecoveryGuide = void 0;
|
|
11
|
+
// Error Recovery (HIGH-6)
|
|
12
|
+
var ErrorRecoveryGuide_1 = require("./ErrorRecoveryGuide");
|
|
13
|
+
Object.defineProperty(exports, "ErrorRecoveryGuide", { enumerable: true, get: function () { return ErrorRecoveryGuide_1.ErrorRecoveryGuide; } });
|
|
14
|
+
Object.defineProperty(exports, "withRecoveryGuidance", { enumerable: true, get: function () { return ErrorRecoveryGuide_1.withRecoveryGuidance; } });
|
|
15
|
+
// Rate Limiting & Circuit Breaker (M-4, M-5)
|
|
16
|
+
var RateLimiter_1 = require("./RateLimiter");
|
|
17
|
+
Object.defineProperty(exports, "RateLimiter", { enumerable: true, get: function () { return RateLimiter_1.RateLimiter; } });
|
|
18
|
+
Object.defineProperty(exports, "CircuitBreaker", { enumerable: true, get: function () { return RateLimiter_1.CircuitBreaker; } });
|
|
19
|
+
Object.defineProperty(exports, "APIProtector", { enumerable: true, get: function () { return RateLimiter_1.APIProtector; } });
|
|
20
|
+
// Logging & Metrics (M-6, M-7)
|
|
21
|
+
var Logger_1 = require("./Logger");
|
|
22
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return Logger_1.Logger; } });
|
|
23
|
+
Object.defineProperty(exports, "MetricsCollector", { enumerable: true, get: function () { return Logger_1.MetricsCollector; } });
|
|
24
|
+
Object.defineProperty(exports, "sdkLogger", { enumerable: true, get: function () { return Logger_1.sdkLogger; } });
|
|
25
|
+
Object.defineProperty(exports, "sdkMetrics", { enumerable: true, get: function () { return Logger_1.sdkMetrics; } });
|
|
26
|
+
// SDK Lifecycle (M-8)
|
|
27
|
+
var SDKLifecycle_1 = require("./SDKLifecycle");
|
|
28
|
+
Object.defineProperty(exports, "SDKLifecycle", { enumerable: true, get: function () { return SDKLifecycle_1.SDKLifecycle; } });
|
|
29
|
+
Object.defineProperty(exports, "sdkLifecycle", { enumerable: true, get: function () { return SDKLifecycle_1.sdkLifecycle; } });
|
|
30
|
+
Object.defineProperty(exports, "onShutdown", { enumerable: true, get: function () { return SDKLifecycle_1.onShutdown; } });
|
|
31
|
+
Object.defineProperty(exports, "registerDisposable", { enumerable: true, get: function () { return SDKLifecycle_1.registerDisposable; } });
|
|
32
|
+
Object.defineProperty(exports, "shutdownSDK", { enumerable: true, get: function () { return SDKLifecycle_1.shutdownSDK; } });
|
|
33
|
+
// Nonce Tracking (Security)
|
|
34
|
+
var ReceivedNonceTracker_1 = require("./ReceivedNonceTracker");
|
|
35
|
+
Object.defineProperty(exports, "InMemoryReceivedNonceTracker", { enumerable: true, get: function () { return ReceivedNonceTracker_1.InMemoryReceivedNonceTracker; } });
|
|
36
|
+
Object.defineProperty(exports, "SetBasedReceivedNonceTracker", { enumerable: true, get: function () { return ReceivedNonceTracker_1.SetBasedReceivedNonceTracker; } });
|
|
37
|
+
Object.defineProperty(exports, "createReceivedNonceTracker", { enumerable: true, get: function () { return ReceivedNonceTracker_1.createReceivedNonceTracker; } });
|
|
38
|
+
// Attestation Tracking (Security)
|
|
39
|
+
var UsedAttestationTracker_1 = require("./UsedAttestationTracker");
|
|
40
|
+
Object.defineProperty(exports, "InMemoryUsedAttestationTracker", { enumerable: true, get: function () { return UsedAttestationTracker_1.InMemoryUsedAttestationTracker; } });
|
|
41
|
+
Object.defineProperty(exports, "FileBasedUsedAttestationTracker", { enumerable: true, get: function () { return UsedAttestationTracker_1.FileBasedUsedAttestationTracker; } });
|
|
42
|
+
Object.defineProperty(exports, "createUsedAttestationTracker", { enumerable: true, get: function () { return UsedAttestationTracker_1.createUsedAttestationTracker; } });
|
|
43
|
+
// Helper Utilities (L-7)
|
|
44
|
+
var Helpers_1 = require("./Helpers");
|
|
45
|
+
Object.defineProperty(exports, "USDC", { enumerable: true, get: function () { return Helpers_1.USDC; } });
|
|
46
|
+
Object.defineProperty(exports, "Deadline", { enumerable: true, get: function () { return Helpers_1.Deadline; } });
|
|
47
|
+
Object.defineProperty(exports, "Address", { enumerable: true, get: function () { return Helpers_1.Address; } });
|
|
48
|
+
Object.defineProperty(exports, "Bytes32", { enumerable: true, get: function () { return Helpers_1.Bytes32; } });
|
|
49
|
+
Object.defineProperty(exports, "State", { enumerable: true, get: function () { return Helpers_1.State; } });
|
|
50
|
+
Object.defineProperty(exports, "DisputeWindow", { enumerable: true, get: function () { return Helpers_1.DisputeWindow; } });
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,0BAA0B;AAC1B,2DAM8B;AAL5B,wHAAA,kBAAkB,OAAA;AAClB,0HAAA,oBAAoB,OAAA;AAMtB,6CAA6C;AAC7C,6CASuB;AARrB,0GAAA,WAAW,OAAA;AACX,6GAAA,cAAc,OAAA;AACd,2GAAA,YAAY,OAAA;AAQd,+BAA+B;AAC/B,mCASkB;AARhB,gGAAA,MAAM,OAAA;AACN,0GAAA,gBAAgB,OAAA;AAChB,mGAAA,SAAS,OAAA;AACT,oGAAA,UAAU,OAAA;AAOZ,sBAAsB;AACtB,+CAUwB;AATtB,4GAAA,YAAY,OAAA;AACZ,4GAAA,YAAY,OAAA;AACZ,0GAAA,UAAU,OAAA;AACV,kHAAA,kBAAkB,OAAA;AAClB,2GAAA,WAAW,OAAA;AAOb,4BAA4B;AAC5B,+DAMgC;AAL9B,oIAAA,4BAA4B,OAAA;AAC5B,oIAAA,4BAA4B,OAAA;AAC5B,kIAAA,0BAA0B,OAAA;AAK5B,kCAAkC;AAClC,mEAKkC;AAJhC,wIAAA,8BAA8B,OAAA;AAC9B,yIAAA,+BAA+B,OAAA;AAC/B,sIAAA,4BAA4B,OAAA;AAI9B,yBAAyB;AACzB,qCAOmB;AANjB,+FAAA,IAAI,OAAA;AACJ,mGAAA,QAAQ,OAAA;AACR,kGAAA,OAAO,OAAA;AACP,kGAAA,OAAO,OAAA;AACP,gGAAA,KAAK,OAAA;AACL,wGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Utilities for ACTP SDK
|
|
3
|
+
*
|
|
4
|
+
* SECURITY FIXES:
|
|
5
|
+
* - H-7: Constant-time string comparison (timing attack prevention)
|
|
6
|
+
* - H-6: Path traversal prevention
|
|
7
|
+
* - H-2: Input validation and sanitization
|
|
8
|
+
* - C-3: Safe JSON parsing with schema validation
|
|
9
|
+
*
|
|
10
|
+
* @module utils/security
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* H-7: Constant-time string comparison to prevent timing attacks
|
|
14
|
+
*
|
|
15
|
+
* Never use === for comparing signatures, hashes, or other security-sensitive strings
|
|
16
|
+
* as it can leak timing information that attackers can exploit.
|
|
17
|
+
*
|
|
18
|
+
* @param a - First string to compare
|
|
19
|
+
* @param b - Second string to compare
|
|
20
|
+
* @returns true if strings are equal, false otherwise
|
|
21
|
+
*/
|
|
22
|
+
export declare function timingSafeEqual(a: string, b: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* H-6: Validate and sanitize directory path to prevent path traversal
|
|
25
|
+
*
|
|
26
|
+
* Ensures that the provided path:
|
|
27
|
+
* 1. Does not contain '..' sequences
|
|
28
|
+
* 2. Resolves to a location within the allowed base directory
|
|
29
|
+
* 3. Does not follow symlinks (optional)
|
|
30
|
+
*
|
|
31
|
+
* @param requestedPath - The path to validate
|
|
32
|
+
* @param baseDirectory - The base directory to restrict paths to
|
|
33
|
+
* @returns Sanitized absolute path
|
|
34
|
+
* @throws Error if path is invalid or contains traversal attempts
|
|
35
|
+
*/
|
|
36
|
+
export declare function validatePath(requestedPath: string, baseDirectory: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* H-2: Validate and sanitize service name
|
|
39
|
+
*
|
|
40
|
+
* Ensures service name:
|
|
41
|
+
* 1. Contains only safe characters (alphanumeric, dash, dot, underscore)
|
|
42
|
+
* 2. Does not exceed maximum length
|
|
43
|
+
* 3. Does not contain special characters that could cause injection
|
|
44
|
+
*
|
|
45
|
+
* @param serviceName - The service name to validate
|
|
46
|
+
* @returns Sanitized service name
|
|
47
|
+
* @throws Error if service name is invalid
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateServiceName(serviceName: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* H-5: Validate Ethereum address format
|
|
52
|
+
*
|
|
53
|
+
* Ensures address:
|
|
54
|
+
* 1. Is a valid hex string
|
|
55
|
+
* 2. Has correct length (42 chars including '0x' prefix)
|
|
56
|
+
* 3. Uses valid checksum if provided (EIP-55)
|
|
57
|
+
*
|
|
58
|
+
* @param address - The Ethereum address to validate
|
|
59
|
+
* @returns true if address is valid, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
export declare function isValidAddress(address: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* C-3: Safe JSON parsing with schema validation
|
|
64
|
+
*
|
|
65
|
+
* Prevents code injection and prototype pollution attacks by:
|
|
66
|
+
* 1. Safely parsing JSON with error handling
|
|
67
|
+
* 2. Validating the parsed object against an expected schema
|
|
68
|
+
* 3. Removing __proto__, constructor, and prototype properties
|
|
69
|
+
* 4. Returning only whitelisted fields
|
|
70
|
+
*
|
|
71
|
+
* @param jsonString - The JSON string to parse
|
|
72
|
+
* @param schema - Expected schema (object with field names and types)
|
|
73
|
+
* @returns Parsed and validated object, or null if invalid
|
|
74
|
+
*/
|
|
75
|
+
export declare function safeJSONParse<T = any>(jsonString: string, schema?: Record<string, string>): T | null;
|
|
76
|
+
/**
|
|
77
|
+
* LRU (Least Recently Used) cache with maximum size
|
|
78
|
+
* Used for preventing unbounded memory growth
|
|
79
|
+
*
|
|
80
|
+
* @template K - Key type
|
|
81
|
+
* @template V - Value type
|
|
82
|
+
*/
|
|
83
|
+
export declare class LRUCache<K, V> {
|
|
84
|
+
private cache;
|
|
85
|
+
private readonly maxSize;
|
|
86
|
+
constructor(maxSize?: number);
|
|
87
|
+
/**
|
|
88
|
+
* Get value from cache
|
|
89
|
+
*
|
|
90
|
+
* @param key - Cache key
|
|
91
|
+
* @returns Cached value or undefined
|
|
92
|
+
*/
|
|
93
|
+
get(key: K): V | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Set value in cache
|
|
96
|
+
*
|
|
97
|
+
* @param key - Cache key
|
|
98
|
+
* @param value - Value to cache
|
|
99
|
+
*/
|
|
100
|
+
set(key: K, value: V): void;
|
|
101
|
+
/**
|
|
102
|
+
* Check if key exists in cache
|
|
103
|
+
*
|
|
104
|
+
* SECURITY FIX (N-1): Use Map's native has() instead of get()
|
|
105
|
+
* to avoid modifying LRU order on read-only operations.
|
|
106
|
+
*
|
|
107
|
+
* @param key - Cache key
|
|
108
|
+
* @returns true if key exists
|
|
109
|
+
*/
|
|
110
|
+
has(key: K): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Delete key from cache
|
|
113
|
+
*
|
|
114
|
+
* @param key - Cache key
|
|
115
|
+
*/
|
|
116
|
+
delete(key: K): void;
|
|
117
|
+
/**
|
|
118
|
+
* Clear all entries
|
|
119
|
+
*/
|
|
120
|
+
clear(): void;
|
|
121
|
+
/**
|
|
122
|
+
* Get current cache size
|
|
123
|
+
*/
|
|
124
|
+
get size(): number;
|
|
125
|
+
/**
|
|
126
|
+
* Get all values from cache
|
|
127
|
+
*
|
|
128
|
+
* SECURITY FIX (N-2): Add iterator support for LRUCache.
|
|
129
|
+
* Returns values in LRU order (oldest to newest).
|
|
130
|
+
*
|
|
131
|
+
* @returns Array of all cached values
|
|
132
|
+
*/
|
|
133
|
+
values(): V[];
|
|
134
|
+
/**
|
|
135
|
+
* Get all keys from cache
|
|
136
|
+
*
|
|
137
|
+
* @returns Array of all cached keys
|
|
138
|
+
*/
|
|
139
|
+
keys(): K[];
|
|
140
|
+
/**
|
|
141
|
+
* Get all entries from cache
|
|
142
|
+
*
|
|
143
|
+
* @returns Array of all cached [key, value] pairs
|
|
144
|
+
*/
|
|
145
|
+
entries(): [K, V][];
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/utils/security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAkB7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CA4BjF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAgC/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAyBvD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,GAAG,EACnC,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,CAAC,GAAG,IAAI,CAoEV;AAqCD;;;;;;GAMG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC;IACxB,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,GAAE,MAAa;IAOlC;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAU1B;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAmB3B;;;;;;;;OAQG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIpB;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;IAIpB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;;;OAOG;IACH,MAAM,IAAI,CAAC,EAAE;IAIb;;;;OAIG;IACH,IAAI,IAAI,CAAC,EAAE;IAIX;;;;OAIG;IACH,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;CAGpB"}
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Security Utilities for ACTP SDK
|
|
4
|
+
*
|
|
5
|
+
* SECURITY FIXES:
|
|
6
|
+
* - H-7: Constant-time string comparison (timing attack prevention)
|
|
7
|
+
* - H-6: Path traversal prevention
|
|
8
|
+
* - H-2: Input validation and sanitization
|
|
9
|
+
* - C-3: Safe JSON parsing with schema validation
|
|
10
|
+
*
|
|
11
|
+
* @module utils/security
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.LRUCache = exports.safeJSONParse = exports.isValidAddress = exports.validateServiceName = exports.validatePath = exports.timingSafeEqual = void 0;
|
|
38
|
+
const crypto = __importStar(require("crypto"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
/**
|
|
41
|
+
* H-7: Constant-time string comparison to prevent timing attacks
|
|
42
|
+
*
|
|
43
|
+
* Never use === for comparing signatures, hashes, or other security-sensitive strings
|
|
44
|
+
* as it can leak timing information that attackers can exploit.
|
|
45
|
+
*
|
|
46
|
+
* @param a - First string to compare
|
|
47
|
+
* @param b - Second string to compare
|
|
48
|
+
* @returns true if strings are equal, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
function timingSafeEqual(a, b) {
|
|
51
|
+
if (typeof a !== 'string' || typeof b !== 'string') {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
// Convert to buffers for crypto.timingSafeEqual
|
|
55
|
+
const bufA = Buffer.from(a);
|
|
56
|
+
const bufB = Buffer.from(b);
|
|
57
|
+
// If lengths differ, still use timingSafeEqual to prevent timing leaks
|
|
58
|
+
if (bufA.length !== bufB.length) {
|
|
59
|
+
// Compare against a dummy buffer of the same length to maintain constant time
|
|
60
|
+
const dummy = Buffer.alloc(bufA.length);
|
|
61
|
+
crypto.timingSafeEqual(bufA, dummy);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return crypto.timingSafeEqual(bufA, bufB);
|
|
65
|
+
}
|
|
66
|
+
exports.timingSafeEqual = timingSafeEqual;
|
|
67
|
+
/**
|
|
68
|
+
* H-6: Validate and sanitize directory path to prevent path traversal
|
|
69
|
+
*
|
|
70
|
+
* Ensures that the provided path:
|
|
71
|
+
* 1. Does not contain '..' sequences
|
|
72
|
+
* 2. Resolves to a location within the allowed base directory
|
|
73
|
+
* 3. Does not follow symlinks (optional)
|
|
74
|
+
*
|
|
75
|
+
* @param requestedPath - The path to validate
|
|
76
|
+
* @param baseDirectory - The base directory to restrict paths to
|
|
77
|
+
* @returns Sanitized absolute path
|
|
78
|
+
* @throws Error if path is invalid or contains traversal attempts
|
|
79
|
+
*/
|
|
80
|
+
function validatePath(requestedPath, baseDirectory) {
|
|
81
|
+
// Check for null bytes (can be used to bypass security checks)
|
|
82
|
+
if (requestedPath.includes('\0')) {
|
|
83
|
+
throw new Error('Invalid path: null byte detected');
|
|
84
|
+
}
|
|
85
|
+
// Normalize the path BEFORE checking for '..'
|
|
86
|
+
// This prevents tricks like '.../...//' or 'foo/../../../etc/passwd'
|
|
87
|
+
const normalized = path.normalize(requestedPath);
|
|
88
|
+
// Check for '..' sequences after normalization
|
|
89
|
+
if (normalized.includes('..')) {
|
|
90
|
+
throw new Error('Invalid path: path traversal detected (..)');
|
|
91
|
+
}
|
|
92
|
+
// Resolve to absolute path
|
|
93
|
+
const absolute = path.resolve(baseDirectory, normalized);
|
|
94
|
+
// Ensure the resolved path is still within the base directory
|
|
95
|
+
// This prevents attacks like:
|
|
96
|
+
// - Symlink following to escape the directory
|
|
97
|
+
// - Absolute paths that ignore the base directory
|
|
98
|
+
const normalizedBase = path.resolve(baseDirectory);
|
|
99
|
+
if (!absolute.startsWith(normalizedBase + path.sep) && absolute !== normalizedBase) {
|
|
100
|
+
throw new Error(`Invalid path: resolved path '${absolute}' is outside base directory '${normalizedBase}'`);
|
|
101
|
+
}
|
|
102
|
+
return absolute;
|
|
103
|
+
}
|
|
104
|
+
exports.validatePath = validatePath;
|
|
105
|
+
/**
|
|
106
|
+
* H-2: Validate and sanitize service name
|
|
107
|
+
*
|
|
108
|
+
* Ensures service name:
|
|
109
|
+
* 1. Contains only safe characters (alphanumeric, dash, dot, underscore)
|
|
110
|
+
* 2. Does not exceed maximum length
|
|
111
|
+
* 3. Does not contain special characters that could cause injection
|
|
112
|
+
*
|
|
113
|
+
* @param serviceName - The service name to validate
|
|
114
|
+
* @returns Sanitized service name
|
|
115
|
+
* @throws Error if service name is invalid
|
|
116
|
+
*/
|
|
117
|
+
function validateServiceName(serviceName) {
|
|
118
|
+
if (!serviceName || typeof serviceName !== 'string') {
|
|
119
|
+
throw new Error('Invalid service name: must be a non-empty string');
|
|
120
|
+
}
|
|
121
|
+
// Trim whitespace
|
|
122
|
+
const trimmed = serviceName.trim();
|
|
123
|
+
// Check length (max 256 chars)
|
|
124
|
+
if (trimmed.length === 0) {
|
|
125
|
+
throw new Error('Invalid service name: cannot be empty');
|
|
126
|
+
}
|
|
127
|
+
if (trimmed.length > 256) {
|
|
128
|
+
throw new Error('Invalid service name: exceeds maximum length of 256 characters');
|
|
129
|
+
}
|
|
130
|
+
// Validate format: alphanumeric, dash, dot, underscore only
|
|
131
|
+
// This prevents injection attacks and ensures compatibility across systems
|
|
132
|
+
const validPattern = /^[a-zA-Z0-9._-]+$/;
|
|
133
|
+
if (!validPattern.test(trimmed)) {
|
|
134
|
+
throw new Error('Invalid service name: only alphanumeric characters, dots, dashes, and underscores are allowed');
|
|
135
|
+
}
|
|
136
|
+
// Prevent names that could cause issues
|
|
137
|
+
if (trimmed === '.' || trimmed === '..' || trimmed.startsWith('.')) {
|
|
138
|
+
throw new Error('Invalid service name: cannot start with a dot');
|
|
139
|
+
}
|
|
140
|
+
return trimmed;
|
|
141
|
+
}
|
|
142
|
+
exports.validateServiceName = validateServiceName;
|
|
143
|
+
/**
|
|
144
|
+
* H-5: Validate Ethereum address format
|
|
145
|
+
*
|
|
146
|
+
* Ensures address:
|
|
147
|
+
* 1. Is a valid hex string
|
|
148
|
+
* 2. Has correct length (42 chars including '0x' prefix)
|
|
149
|
+
* 3. Uses valid checksum if provided (EIP-55)
|
|
150
|
+
*
|
|
151
|
+
* @param address - The Ethereum address to validate
|
|
152
|
+
* @returns true if address is valid, false otherwise
|
|
153
|
+
*/
|
|
154
|
+
function isValidAddress(address) {
|
|
155
|
+
if (!address || typeof address !== 'string') {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
// Must start with 0x
|
|
159
|
+
if (!address.startsWith('0x')) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
// Must be exactly 42 characters (0x + 40 hex chars)
|
|
163
|
+
if (address.length !== 42) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
// Must contain only valid hex characters
|
|
167
|
+
const hexPattern = /^0x[a-fA-F0-9]{40}$/;
|
|
168
|
+
if (!hexPattern.test(address)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
// Note: Full EIP-55 checksum validation would be more complex
|
|
172
|
+
// For now, we just validate format. In production, consider using ethers.utils.getAddress()
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
exports.isValidAddress = isValidAddress;
|
|
176
|
+
/**
|
|
177
|
+
* C-3: Safe JSON parsing with schema validation
|
|
178
|
+
*
|
|
179
|
+
* Prevents code injection and prototype pollution attacks by:
|
|
180
|
+
* 1. Safely parsing JSON with error handling
|
|
181
|
+
* 2. Validating the parsed object against an expected schema
|
|
182
|
+
* 3. Removing __proto__, constructor, and prototype properties
|
|
183
|
+
* 4. Returning only whitelisted fields
|
|
184
|
+
*
|
|
185
|
+
* @param jsonString - The JSON string to parse
|
|
186
|
+
* @param schema - Expected schema (object with field names and types)
|
|
187
|
+
* @returns Parsed and validated object, or null if invalid
|
|
188
|
+
*/
|
|
189
|
+
function safeJSONParse(jsonString, schema) {
|
|
190
|
+
if (!jsonString || typeof jsonString !== 'string') {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
// SECURITY FIX (C-3): Check JSON size to prevent DoS attacks
|
|
194
|
+
const MAX_JSON_SIZE = 1000000; // 1MB
|
|
195
|
+
if (jsonString.length > MAX_JSON_SIZE) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
let parsed;
|
|
199
|
+
try {
|
|
200
|
+
// Basic JSON parsing
|
|
201
|
+
parsed = JSON.parse(jsonString);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
// Invalid JSON
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
// Ensure we got an object (not a primitive or array at the top level)
|
|
208
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
// Remove dangerous properties that could be used for prototype pollution
|
|
212
|
+
const dangerous = ['__proto__', 'constructor', 'prototype'];
|
|
213
|
+
for (const key of dangerous) {
|
|
214
|
+
delete parsed[key];
|
|
215
|
+
}
|
|
216
|
+
// If schema is provided, validate and whitelist
|
|
217
|
+
if (schema) {
|
|
218
|
+
const validated = {};
|
|
219
|
+
for (const [field, expectedType] of Object.entries(schema)) {
|
|
220
|
+
const value = parsed[field];
|
|
221
|
+
// Skip if field doesn't exist
|
|
222
|
+
if (value === undefined) {
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
// Type check
|
|
226
|
+
const actualType = Array.isArray(value) ? 'array' : typeof value;
|
|
227
|
+
if (actualType !== expectedType && expectedType !== 'any') {
|
|
228
|
+
// Type mismatch - skip this field
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
// Recursively sanitize nested objects
|
|
232
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
233
|
+
validated[field] = sanitizeObject(value);
|
|
234
|
+
}
|
|
235
|
+
else if (Array.isArray(value)) {
|
|
236
|
+
validated[field] = value.map((item) => typeof item === 'object' && item !== null ? sanitizeObject(item) : item);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
validated[field] = value;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return validated;
|
|
243
|
+
}
|
|
244
|
+
// No schema - return sanitized object
|
|
245
|
+
return sanitizeObject(parsed);
|
|
246
|
+
}
|
|
247
|
+
exports.safeJSONParse = safeJSONParse;
|
|
248
|
+
/**
|
|
249
|
+
* Recursively sanitize an object by removing dangerous properties
|
|
250
|
+
*
|
|
251
|
+
* @param obj - Object to sanitize
|
|
252
|
+
* @returns Sanitized object
|
|
253
|
+
*/
|
|
254
|
+
function sanitizeObject(obj) {
|
|
255
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
256
|
+
return obj;
|
|
257
|
+
}
|
|
258
|
+
const sanitized = {};
|
|
259
|
+
const dangerous = ['__proto__', 'constructor', 'prototype'];
|
|
260
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
261
|
+
// Skip dangerous keys
|
|
262
|
+
if (dangerous.includes(key)) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
// Recursively sanitize nested objects
|
|
266
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
267
|
+
sanitized[key] = sanitizeObject(value);
|
|
268
|
+
}
|
|
269
|
+
else if (Array.isArray(value)) {
|
|
270
|
+
sanitized[key] = value.map((item) => typeof item === 'object' && item !== null ? sanitizeObject(item) : item);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
sanitized[key] = value;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return sanitized;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* LRU (Least Recently Used) cache with maximum size
|
|
280
|
+
* Used for preventing unbounded memory growth
|
|
281
|
+
*
|
|
282
|
+
* @template K - Key type
|
|
283
|
+
* @template V - Value type
|
|
284
|
+
*/
|
|
285
|
+
class LRUCache {
|
|
286
|
+
constructor(maxSize = 1000) {
|
|
287
|
+
this.cache = new Map();
|
|
288
|
+
if (maxSize <= 0) {
|
|
289
|
+
throw new Error('LRU cache maxSize must be positive');
|
|
290
|
+
}
|
|
291
|
+
this.maxSize = maxSize;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Get value from cache
|
|
295
|
+
*
|
|
296
|
+
* @param key - Cache key
|
|
297
|
+
* @returns Cached value or undefined
|
|
298
|
+
*/
|
|
299
|
+
get(key) {
|
|
300
|
+
const value = this.cache.get(key);
|
|
301
|
+
if (value !== undefined) {
|
|
302
|
+
// Move to end (most recently used)
|
|
303
|
+
this.cache.delete(key);
|
|
304
|
+
this.cache.set(key, value);
|
|
305
|
+
}
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Set value in cache
|
|
310
|
+
*
|
|
311
|
+
* @param key - Cache key
|
|
312
|
+
* @param value - Value to cache
|
|
313
|
+
*/
|
|
314
|
+
set(key, value) {
|
|
315
|
+
// Delete if already exists (to update position)
|
|
316
|
+
if (this.cache.has(key)) {
|
|
317
|
+
this.cache.delete(key);
|
|
318
|
+
}
|
|
319
|
+
// Evict oldest if at capacity
|
|
320
|
+
if (this.cache.size >= this.maxSize) {
|
|
321
|
+
const firstKey = this.cache.keys().next().value;
|
|
322
|
+
// TypeScript doesn't know that Map iterator always returns defined values when size > 0
|
|
323
|
+
// But we check size >= maxSize above, so this is safe
|
|
324
|
+
if (firstKey !== undefined) {
|
|
325
|
+
this.cache.delete(firstKey);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
this.cache.set(key, value);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Check if key exists in cache
|
|
332
|
+
*
|
|
333
|
+
* SECURITY FIX (N-1): Use Map's native has() instead of get()
|
|
334
|
+
* to avoid modifying LRU order on read-only operations.
|
|
335
|
+
*
|
|
336
|
+
* @param key - Cache key
|
|
337
|
+
* @returns true if key exists
|
|
338
|
+
*/
|
|
339
|
+
has(key) {
|
|
340
|
+
return this.cache.has(key);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Delete key from cache
|
|
344
|
+
*
|
|
345
|
+
* @param key - Cache key
|
|
346
|
+
*/
|
|
347
|
+
delete(key) {
|
|
348
|
+
this.cache.delete(key);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Clear all entries
|
|
352
|
+
*/
|
|
353
|
+
clear() {
|
|
354
|
+
this.cache.clear();
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Get current cache size
|
|
358
|
+
*/
|
|
359
|
+
get size() {
|
|
360
|
+
return this.cache.size;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Get all values from cache
|
|
364
|
+
*
|
|
365
|
+
* SECURITY FIX (N-2): Add iterator support for LRUCache.
|
|
366
|
+
* Returns values in LRU order (oldest to newest).
|
|
367
|
+
*
|
|
368
|
+
* @returns Array of all cached values
|
|
369
|
+
*/
|
|
370
|
+
values() {
|
|
371
|
+
return Array.from(this.cache.values());
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Get all keys from cache
|
|
375
|
+
*
|
|
376
|
+
* @returns Array of all cached keys
|
|
377
|
+
*/
|
|
378
|
+
keys() {
|
|
379
|
+
return Array.from(this.cache.keys());
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Get all entries from cache
|
|
383
|
+
*
|
|
384
|
+
* @returns Array of all cached [key, value] pairs
|
|
385
|
+
*/
|
|
386
|
+
entries() {
|
|
387
|
+
return Array.from(this.cache.entries());
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
exports.LRUCache = LRUCache;
|
|
391
|
+
//# sourceMappingURL=security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.js","sourceRoot":"","sources":["../../src/utils/security.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAAiC;AACjC,2CAA6B;AAE7B;;;;;;;;;GASG;AACH,SAAgB,eAAe,CAAC,CAAS,EAAE,CAAS;IAClD,IAAI,OAAO,CAAC,KAAK,QAAQ,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AAQ,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,GAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAM;QACX,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;;;;;;OAOG;IACH,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACH,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1C,CAAC;CACF;AArHD,4BAqHC"}
|
|
@@ -1,6 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input validation utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Validate Ethereum address
|
|
6
|
+
*/
|
|
1
7
|
export declare function validateAddress(address: string, fieldName?: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* Validate amount (must be > 0)
|
|
10
|
+
*/
|
|
2
11
|
export declare function validateAmount(amount: bigint, _fieldName?: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Validate deadline (must be future timestamp)
|
|
14
|
+
*/
|
|
3
15
|
export declare function validateDeadline(deadline: number, fieldName?: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Validate dispute window (max 30 days per spec)
|
|
18
|
+
*/
|
|
4
19
|
export declare function validateDisputeWindow(disputeWindow: number, fieldName?: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Validate transaction ID format
|
|
22
|
+
*/
|
|
5
23
|
export declare function validateTxId(txId: string, fieldName?: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Validate endpoint URL (for AgentRegistry)
|
|
26
|
+
*
|
|
27
|
+
* SECURITY FIX (H-1): Enhanced SSRF protection with DNS resolution
|
|
28
|
+
*
|
|
29
|
+
* Security checks:
|
|
30
|
+
* - Valid URL format
|
|
31
|
+
* - HTTPS or IPFS protocols only
|
|
32
|
+
* - Maximum length 256 characters
|
|
33
|
+
* - DNS resolution check (hostname → IP validation)
|
|
34
|
+
* - No private/local IP addresses (SSRF protection)
|
|
35
|
+
* - Blocks AWS metadata endpoint (169.254.169.254)
|
|
36
|
+
* - Fail-secure: if DNS lookup fails, reject
|
|
37
|
+
*
|
|
38
|
+
* **CRITICAL**: This function is now ASYNC due to DNS resolution.
|
|
39
|
+
* All callers MUST await this function.
|
|
40
|
+
*
|
|
41
|
+
* @param endpoint - URL to validate
|
|
42
|
+
* @param fieldName - Field name for error messages
|
|
43
|
+
* @throws {ValidationError} If endpoint is invalid or points to private IP
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateEndpointURL(endpoint: string, fieldName?: string): Promise<void>;
|
|
6
46
|
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAOA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAkB,GAAG,IAAI,CAQpF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,MAAiB,GAAG,IAAI,CASlF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,MAAmB,GAAG,IAAI,CASvF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EACrB,SAAS,GAAE,MAAwB,GAClC,IAAI,CAaN;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAe,GAAG,IAAI,CAI3E;AAwDD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,MAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuFzG"}
|