@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,382 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger - Structured Logging Framework for ACTP SDK
|
|
4
|
+
*
|
|
5
|
+
* SECURITY FIX (M-6): Comprehensive logging with:
|
|
6
|
+
* - Log levels (debug, info, warn, error)
|
|
7
|
+
* - Structured metadata
|
|
8
|
+
* - Sensitive data filtering
|
|
9
|
+
* - Configurable output
|
|
10
|
+
*
|
|
11
|
+
* @module utils/Logger
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.sdkMetrics = exports.MetricsCollector = exports.sdkLogger = exports.Logger = void 0;
|
|
15
|
+
/**
|
|
16
|
+
* Sensitive key name patterns (for checking object keys)
|
|
17
|
+
*
|
|
18
|
+
* SECURITY FIX (NEW-HIGH-3): NO GLOBAL FLAG on patterns used with .test()
|
|
19
|
+
* Global regex maintains lastIndex state, causing alternating match/no-match
|
|
20
|
+
* on consecutive calls, potentially leaking sensitive data intermittently.
|
|
21
|
+
*/
|
|
22
|
+
const SENSITIVE_KEY_PATTERNS = [
|
|
23
|
+
/privateKey/i,
|
|
24
|
+
/secret/i,
|
|
25
|
+
/password/i,
|
|
26
|
+
/apiKey/i,
|
|
27
|
+
/authorization/i,
|
|
28
|
+
/mnemonic/i,
|
|
29
|
+
/seed/i,
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* Sensitive value patterns (for redacting from string values)
|
|
33
|
+
*
|
|
34
|
+
* SECURITY FIX (NEW-HIGH-3): These are PATTERN STRINGS that get converted
|
|
35
|
+
* to fresh RegExp instances with /g flag for each replace() call.
|
|
36
|
+
* This avoids lastIndex state pollution between calls.
|
|
37
|
+
*/
|
|
38
|
+
const SENSITIVE_VALUE_PATTERNS = [
|
|
39
|
+
'bearer\\s+[a-zA-Z0-9\\-_.]+', // Bearer tokens
|
|
40
|
+
'0x[a-fA-F0-9]{64}', // Private keys (64 hex chars)
|
|
41
|
+
'0x[a-fA-F0-9]{128}', // Extended private keys
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* Log level priority (higher = more severe)
|
|
45
|
+
*/
|
|
46
|
+
const LOG_LEVEL_PRIORITY = {
|
|
47
|
+
debug: 0,
|
|
48
|
+
info: 1,
|
|
49
|
+
warn: 2,
|
|
50
|
+
error: 3,
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Structured Logger for ACTP SDK
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const logger = new Logger({ source: 'BlockchainRuntime', minLevel: 'info' });
|
|
58
|
+
*
|
|
59
|
+
* logger.info('Transaction created', { txId: '0x...' });
|
|
60
|
+
* logger.error('Transaction failed', { txId: '0x...' }, error);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
class Logger {
|
|
64
|
+
constructor(config = {}) {
|
|
65
|
+
this.config = {
|
|
66
|
+
minLevel: config.minLevel ?? 'info',
|
|
67
|
+
source: config.source ?? 'ACTP-SDK',
|
|
68
|
+
timestamps: config.timestamps ?? true,
|
|
69
|
+
filterSensitive: config.filterSensitive ?? true,
|
|
70
|
+
output: config.output ?? this.defaultOutput.bind(this),
|
|
71
|
+
enabled: config.enabled ?? true,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create child logger with inherited config
|
|
76
|
+
*/
|
|
77
|
+
child(source) {
|
|
78
|
+
return new Logger({
|
|
79
|
+
...this.config,
|
|
80
|
+
source: `${this.config.source}:${source}`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Log debug message
|
|
85
|
+
*/
|
|
86
|
+
debug(message, metadata) {
|
|
87
|
+
this.log('debug', message, metadata);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Log info message
|
|
91
|
+
*/
|
|
92
|
+
info(message, metadata) {
|
|
93
|
+
this.log('info', message, metadata);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Log warning message
|
|
97
|
+
*/
|
|
98
|
+
warn(message, metadata) {
|
|
99
|
+
this.log('warn', message, metadata);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Log error message
|
|
103
|
+
*/
|
|
104
|
+
error(message, metadata, error) {
|
|
105
|
+
this.log('error', message, metadata, error);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Core logging method
|
|
109
|
+
*/
|
|
110
|
+
log(level, message, metadata, error) {
|
|
111
|
+
if (!this.config.enabled) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// Check log level
|
|
115
|
+
if (LOG_LEVEL_PRIORITY[level] < LOG_LEVEL_PRIORITY[this.config.minLevel]) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// Build log entry
|
|
119
|
+
const entry = {
|
|
120
|
+
timestamp: this.config.timestamps ? new Date().toISOString() : '',
|
|
121
|
+
level,
|
|
122
|
+
message,
|
|
123
|
+
source: this.config.source,
|
|
124
|
+
};
|
|
125
|
+
// Add metadata (filtered for sensitive data)
|
|
126
|
+
if (metadata) {
|
|
127
|
+
entry.metadata = this.config.filterSensitive
|
|
128
|
+
? this.filterSensitiveData(metadata)
|
|
129
|
+
: metadata;
|
|
130
|
+
}
|
|
131
|
+
// Add error details
|
|
132
|
+
if (error) {
|
|
133
|
+
entry.error = {
|
|
134
|
+
name: error.name,
|
|
135
|
+
message: error.message,
|
|
136
|
+
stack: error.stack,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// Output the log
|
|
140
|
+
this.config.output(entry);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Filter sensitive data from metadata
|
|
144
|
+
*
|
|
145
|
+
* SECURITY FIX (NEW-HIGH-3): Uses separate pattern arrays for keys and values.
|
|
146
|
+
* Key patterns have no /g flag (used with .test()).
|
|
147
|
+
* Value patterns are strings converted to fresh RegExp instances per call.
|
|
148
|
+
*/
|
|
149
|
+
filterSensitiveData(obj) {
|
|
150
|
+
const filtered = {};
|
|
151
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
152
|
+
// SECURITY FIX (NEW-HIGH-3): Check if key matches sensitive pattern
|
|
153
|
+
// Using patterns without /g flag - safe to use with .test()
|
|
154
|
+
const isSensitiveKey = SENSITIVE_KEY_PATTERNS.some((pattern) => pattern.test(key));
|
|
155
|
+
if (isSensitiveKey) {
|
|
156
|
+
filtered[key] = '[REDACTED]';
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
// Recursively filter nested objects
|
|
160
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
161
|
+
filtered[key] = this.filterSensitiveData(value);
|
|
162
|
+
}
|
|
163
|
+
else if (Array.isArray(value)) {
|
|
164
|
+
// SECURITY FIX: Also filter arrays
|
|
165
|
+
filtered[key] = value.map((item) => {
|
|
166
|
+
if (typeof item === 'string') {
|
|
167
|
+
return this.redactSensitiveValues(item);
|
|
168
|
+
}
|
|
169
|
+
else if (item && typeof item === 'object') {
|
|
170
|
+
return this.filterSensitiveData(item);
|
|
171
|
+
}
|
|
172
|
+
return item;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
else if (typeof value === 'string') {
|
|
176
|
+
// SECURITY FIX (NEW-HIGH-3): Redact sensitive patterns from values
|
|
177
|
+
filtered[key] = this.redactSensitiveValues(value);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
filtered[key] = value;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return filtered;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Redact sensitive patterns from a string value
|
|
187
|
+
*
|
|
188
|
+
* SECURITY FIX (NEW-HIGH-3): Creates fresh RegExp instances with /gi flag
|
|
189
|
+
* for each call, avoiding lastIndex state pollution.
|
|
190
|
+
*/
|
|
191
|
+
redactSensitiveValues(value) {
|
|
192
|
+
let result = value;
|
|
193
|
+
for (const patternStr of SENSITIVE_VALUE_PATTERNS) {
|
|
194
|
+
// Create fresh RegExp instance with global+case-insensitive flags
|
|
195
|
+
// This avoids lastIndex state issues from reusing regex instances
|
|
196
|
+
const pattern = new RegExp(patternStr, 'gi');
|
|
197
|
+
result = result.replace(pattern, '[REDACTED]');
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Default console output handler
|
|
203
|
+
*/
|
|
204
|
+
defaultOutput(entry) {
|
|
205
|
+
const prefix = entry.timestamp ? `[${entry.timestamp}] ` : '';
|
|
206
|
+
const source = entry.source ? `[${entry.source}] ` : '';
|
|
207
|
+
const levelStr = entry.level.toUpperCase().padEnd(5);
|
|
208
|
+
const baseMessage = `${prefix}${levelStr} ${source}${entry.message}`;
|
|
209
|
+
switch (entry.level) {
|
|
210
|
+
case 'debug':
|
|
211
|
+
console.debug(baseMessage, entry.metadata || '');
|
|
212
|
+
break;
|
|
213
|
+
case 'info':
|
|
214
|
+
console.info(baseMessage, entry.metadata || '');
|
|
215
|
+
break;
|
|
216
|
+
case 'warn':
|
|
217
|
+
console.warn(baseMessage, entry.metadata || '');
|
|
218
|
+
break;
|
|
219
|
+
case 'error':
|
|
220
|
+
console.error(baseMessage, entry.metadata || '', entry.error || '');
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Enable logging
|
|
226
|
+
*/
|
|
227
|
+
enable() {
|
|
228
|
+
this.config.enabled = true;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Disable logging
|
|
232
|
+
*/
|
|
233
|
+
disable() {
|
|
234
|
+
this.config.enabled = false;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Set minimum log level
|
|
238
|
+
*/
|
|
239
|
+
setLevel(level) {
|
|
240
|
+
this.config.minLevel = level;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.Logger = Logger;
|
|
244
|
+
/**
|
|
245
|
+
* Global SDK logger instance
|
|
246
|
+
*/
|
|
247
|
+
exports.sdkLogger = new Logger({
|
|
248
|
+
source: 'ACTP-SDK',
|
|
249
|
+
minLevel: process.env.ACTP_LOG_LEVEL || 'info',
|
|
250
|
+
enabled: process.env.ACTP_LOGGING !== 'false',
|
|
251
|
+
});
|
|
252
|
+
/**
|
|
253
|
+
* Metrics collector for SDK operations
|
|
254
|
+
*/
|
|
255
|
+
class MetricsCollector {
|
|
256
|
+
constructor(logger) {
|
|
257
|
+
this.hooks = [];
|
|
258
|
+
this.logger = logger ?? exports.sdkLogger.child('Metrics');
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Register a metrics hook
|
|
262
|
+
*/
|
|
263
|
+
addHook(hook) {
|
|
264
|
+
this.hooks.push(hook);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Remove a metrics hook
|
|
268
|
+
*/
|
|
269
|
+
removeHook(hook) {
|
|
270
|
+
const index = this.hooks.indexOf(hook);
|
|
271
|
+
if (index > -1) {
|
|
272
|
+
this.hooks.splice(index, 1);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Emit transaction created event
|
|
277
|
+
*/
|
|
278
|
+
transactionCreated(txId, metadata) {
|
|
279
|
+
this.logger.info('Transaction created', { txId, ...metadata });
|
|
280
|
+
for (const hook of this.hooks) {
|
|
281
|
+
try {
|
|
282
|
+
hook.onTransactionCreated?.(txId, metadata);
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
this.logger.error('Metrics hook error', { hook: 'onTransactionCreated' }, error);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Emit escrow linked event
|
|
291
|
+
*/
|
|
292
|
+
escrowLinked(txId, escrowId, amount) {
|
|
293
|
+
this.logger.info('Escrow linked', { txId, escrowId, amount });
|
|
294
|
+
for (const hook of this.hooks) {
|
|
295
|
+
try {
|
|
296
|
+
hook.onEscrowLinked?.(txId, escrowId, amount);
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
this.logger.error('Metrics hook error', { hook: 'onEscrowLinked' }, error);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Emit state transition event
|
|
305
|
+
*/
|
|
306
|
+
stateTransition(txId, fromState, toState) {
|
|
307
|
+
this.logger.info('State transition', { txId, fromState, toState });
|
|
308
|
+
for (const hook of this.hooks) {
|
|
309
|
+
try {
|
|
310
|
+
hook.onStateTransition?.(txId, fromState, toState);
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
this.logger.error('Metrics hook error', { hook: 'onStateTransition' }, error);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Emit escrow released event
|
|
319
|
+
*/
|
|
320
|
+
escrowReleased(escrowId, amount) {
|
|
321
|
+
this.logger.info('Escrow released', { escrowId, amount });
|
|
322
|
+
for (const hook of this.hooks) {
|
|
323
|
+
try {
|
|
324
|
+
hook.onEscrowReleased?.(escrowId, amount);
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
this.logger.error('Metrics hook error', { hook: 'onEscrowReleased' }, error);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Emit error event
|
|
333
|
+
*/
|
|
334
|
+
recordError(error, context) {
|
|
335
|
+
this.logger.error('Error recorded', context, error);
|
|
336
|
+
for (const hook of this.hooks) {
|
|
337
|
+
try {
|
|
338
|
+
hook.onError?.(error, context);
|
|
339
|
+
}
|
|
340
|
+
catch (hookError) {
|
|
341
|
+
this.logger.error('Metrics hook error', { hook: 'onError' }, hookError);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Emit performance metric
|
|
347
|
+
*/
|
|
348
|
+
recordPerformance(operation, durationMs, metadata) {
|
|
349
|
+
this.logger.debug('Performance', { operation, durationMs, ...metadata });
|
|
350
|
+
for (const hook of this.hooks) {
|
|
351
|
+
try {
|
|
352
|
+
hook.onPerformance?.(operation, durationMs, metadata);
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
this.logger.error('Metrics hook error', { hook: 'onPerformance' }, error);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Helper to time an operation
|
|
361
|
+
*/
|
|
362
|
+
async timeOperation(operation, fn, metadata) {
|
|
363
|
+
const startTime = Date.now();
|
|
364
|
+
try {
|
|
365
|
+
const result = await fn();
|
|
366
|
+
const durationMs = Date.now() - startTime;
|
|
367
|
+
this.recordPerformance(operation, durationMs, { ...metadata, success: true });
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
const durationMs = Date.now() - startTime;
|
|
372
|
+
this.recordPerformance(operation, durationMs, { ...metadata, success: false });
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
exports.MetricsCollector = MetricsCollector;
|
|
378
|
+
/**
|
|
379
|
+
* Global metrics collector instance
|
|
380
|
+
*/
|
|
381
|
+
exports.sdkMetrics = new MetricsCollector();
|
|
382
|
+
//# sourceMappingURL=Logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/utils/Logger.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AA+CH;;;;;;GAMG;AACH,MAAM,sBAAsB,GAAa;IACvC,aAAa;IACb,SAAS;IACT,WAAW;IACX,SAAS;IACT,gBAAgB;IAChB,WAAW;IACX,OAAO;CACR,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,wBAAwB,GAAa;IACzC,6BAA6B,EAAG,gBAAgB;IAChD,mBAAmB,EAAa,8BAA8B;IAC9D,oBAAoB,EAAY,wBAAwB;CACzD,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAA6B;IACnD,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAa,MAAM;IAGjB,YAAY,SAAuB,EAAE;QACnC,IAAI,CAAC,MAAM,GAAG;YACZ,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,MAAM;YACnC,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,UAAU;YACnC,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,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ce field requirement)
|
|
5
|
+
*
|
|
6
|
+
* SECURITY FIXES:
|
|
7
|
+
* - C-2: Added atomic nonce allocation with locking
|
|
8
|
+
* - H-1: Added persistent nonce storage option
|
|
9
|
+
* - H-5: Added nonce upper bound validation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Maximum allowed nonce value.
|
|
13
|
+
* SECURITY FIX (H-5): Prevents nonce overflow attacks.
|
|
14
|
+
* Using Number.MAX_SAFE_INTEGER (2^53 - 1) to ensure safe JavaScript integer operations.
|
|
15
|
+
*/
|
|
16
|
+
export declare const MAX_NONCE_VALUE: number;
|
|
17
|
+
/**
|
|
18
|
+
* Nonce Manager Interface (from DeliveryProofBuilder)
|
|
19
|
+
*/
|
|
1
20
|
export interface NonceManager {
|
|
21
|
+
/**
|
|
22
|
+
* Get next nonce for message type
|
|
23
|
+
* @param messageType - Message type identifier (e.g., "agirails.delivery.v1")
|
|
24
|
+
* @returns Monotonically increasing nonce
|
|
25
|
+
*/
|
|
2
26
|
getNextNonce(messageType: string): number;
|
|
27
|
+
/**
|
|
28
|
+
* Record nonce usage
|
|
29
|
+
* @param messageType - Message type identifier
|
|
30
|
+
* @param nonce - Nonce used
|
|
31
|
+
*/
|
|
3
32
|
recordNonce(messageType: string, nonce: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get current nonce (last used)
|
|
35
|
+
* @param messageType - Message type identifier
|
|
36
|
+
* @returns Current nonce or 0 if none used
|
|
37
|
+
*/
|
|
4
38
|
getCurrentNonce(messageType: string): number;
|
|
39
|
+
/**
|
|
40
|
+
* Reset nonce for message type
|
|
41
|
+
* @param messageType - Message type identifier
|
|
42
|
+
*/
|
|
5
43
|
resetNonce(messageType: string): void;
|
|
6
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* In-Memory Nonce Manager
|
|
47
|
+
* Simple implementation using Map for per-message-type nonce tracking
|
|
48
|
+
*
|
|
49
|
+
* SECURITY FIXES:
|
|
50
|
+
* - C-2: Added atomic getAndIncrementNonce() to prevent race conditions
|
|
51
|
+
* - H-5: Added nonce upper bound validation
|
|
52
|
+
*
|
|
53
|
+
* ⚠️ WARNING: Nonces are lost on process restart. For production:
|
|
54
|
+
* - Use persistent storage (Redis, PostgreSQL, etc.)
|
|
55
|
+
* - Implement nonce recovery from blockchain events
|
|
56
|
+
* - Add DID-scoped nonce tracking
|
|
57
|
+
*/
|
|
7
58
|
export declare class InMemoryNonceManager implements NonceManager {
|
|
8
59
|
private nonces;
|
|
60
|
+
private locks;
|
|
61
|
+
/**
|
|
62
|
+
* Create in-memory nonce manager
|
|
63
|
+
* @param initialNonces - Optional initial nonce values (for recovery)
|
|
64
|
+
*/
|
|
9
65
|
constructor(initialNonces?: Record<string, number>);
|
|
66
|
+
/**
|
|
67
|
+
* SECURITY FIX (C-2 + DEADLOCK-FIX): Acquire lock for message type
|
|
68
|
+
* Ensures atomic nonce operations.
|
|
69
|
+
*
|
|
70
|
+
* FIXED: Previous implementation had a deadlock bug where:
|
|
71
|
+
* - The resolver was stored in a closure but never accessible to releaseLock()
|
|
72
|
+
* - releaseLock() just deleted the entry without resolving waiting Promises
|
|
73
|
+
*
|
|
74
|
+
* New implementation stores both promise AND resolver together.
|
|
75
|
+
*/
|
|
76
|
+
private acquireLock;
|
|
77
|
+
/**
|
|
78
|
+
* SECURITY FIX (C-2 + DEADLOCK-FIX): Release lock for message type
|
|
79
|
+
*
|
|
80
|
+
* FIXED: Now properly resolves the Promise before deleting,
|
|
81
|
+
* so any waiting acquireLock() calls can proceed.
|
|
82
|
+
*/
|
|
83
|
+
private releaseLock;
|
|
84
|
+
/**
|
|
85
|
+
* Get next nonce for message type
|
|
86
|
+
* @param messageType - Message type identifier
|
|
87
|
+
* @returns Monotonically increasing nonce
|
|
88
|
+
*/
|
|
10
89
|
getNextNonce(messageType: string): number;
|
|
90
|
+
/**
|
|
91
|
+
* SECURITY FIX (C-2): Atomic get-and-increment nonce
|
|
92
|
+
* Returns the next nonce and records it atomically to prevent race conditions.
|
|
93
|
+
*
|
|
94
|
+
* @param messageType - Message type identifier
|
|
95
|
+
* @returns Atomically allocated nonce
|
|
96
|
+
*/
|
|
97
|
+
getAndIncrementNonce(messageType: string): Promise<number>;
|
|
98
|
+
/**
|
|
99
|
+
* Record nonce usage
|
|
100
|
+
* @param messageType - Message type identifier
|
|
101
|
+
* @param nonce - Nonce used
|
|
102
|
+
*/
|
|
11
103
|
recordNonce(messageType: string, nonce: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Get current nonce (last used)
|
|
106
|
+
* @param messageType - Message type identifier
|
|
107
|
+
* @returns Current nonce or 0 if none used
|
|
108
|
+
*/
|
|
12
109
|
getCurrentNonce(messageType: string): number;
|
|
110
|
+
/**
|
|
111
|
+
* Reset nonce for message type
|
|
112
|
+
* @param messageType - Message type identifier
|
|
113
|
+
*/
|
|
13
114
|
resetNonce(messageType: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Get all nonces (for persistence)
|
|
117
|
+
* @returns Record of all message type nonces
|
|
118
|
+
*/
|
|
14
119
|
getAllNonces(): Record<string, number>;
|
|
120
|
+
/**
|
|
121
|
+
* Clear all nonces
|
|
122
|
+
*/
|
|
15
123
|
clearAll(): void;
|
|
16
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* DID-Scoped Nonce Manager
|
|
127
|
+
* Tracks nonces per DID + message type combination
|
|
128
|
+
* Recommended for multi-agent scenarios
|
|
129
|
+
*/
|
|
17
130
|
export declare class DIDScopedNonceManager implements NonceManager {
|
|
18
131
|
private nonces;
|
|
19
132
|
private currentDID;
|
|
133
|
+
/**
|
|
134
|
+
* Create DID-scoped nonce manager
|
|
135
|
+
* @param did - DID to track nonces for
|
|
136
|
+
* @param initialNonces - Optional initial nonce values
|
|
137
|
+
*/
|
|
20
138
|
constructor(did: string, initialNonces?: Record<string, number>);
|
|
139
|
+
/**
|
|
140
|
+
* Get next nonce for message type (current DID)
|
|
141
|
+
* @param messageType - Message type identifier
|
|
142
|
+
* @returns Monotonically increasing nonce
|
|
143
|
+
*/
|
|
21
144
|
getNextNonce(messageType: string): number;
|
|
145
|
+
/**
|
|
146
|
+
* Record nonce usage (current DID)
|
|
147
|
+
* @param messageType - Message type identifier
|
|
148
|
+
* @param nonce - Nonce used
|
|
149
|
+
*/
|
|
22
150
|
recordNonce(messageType: string, nonce: number): void;
|
|
151
|
+
/**
|
|
152
|
+
* Get current nonce (current DID)
|
|
153
|
+
* @param messageType - Message type identifier
|
|
154
|
+
* @returns Current nonce or 0 if none used
|
|
155
|
+
*/
|
|
23
156
|
getCurrentNonce(messageType: string): number;
|
|
157
|
+
/**
|
|
158
|
+
* Reset nonce for message type (current DID)
|
|
159
|
+
* @param messageType - Message type identifier
|
|
160
|
+
*/
|
|
24
161
|
resetNonce(messageType: string): void;
|
|
162
|
+
/**
|
|
163
|
+
* Get next nonce for specific DID + message type
|
|
164
|
+
* @param did - DID identifier
|
|
165
|
+
* @param messageType - Message type identifier
|
|
166
|
+
* @returns Monotonically increasing nonce
|
|
167
|
+
*/
|
|
25
168
|
getNextNonceForDID(did: string, messageType: string): number;
|
|
169
|
+
/**
|
|
170
|
+
* Record nonce usage for specific DID + message type
|
|
171
|
+
* @param did - DID identifier
|
|
172
|
+
* @param messageType - Message type identifier
|
|
173
|
+
* @param nonce - Nonce used
|
|
174
|
+
*/
|
|
26
175
|
recordNonceForDID(did: string, messageType: string, nonce: number): void;
|
|
176
|
+
/**
|
|
177
|
+
* Get current nonce for specific DID + message type
|
|
178
|
+
* @param did - DID identifier
|
|
179
|
+
* @param messageType - Message type identifier
|
|
180
|
+
* @returns Current nonce or 0 if none used
|
|
181
|
+
*/
|
|
27
182
|
getCurrentNonceForDID(did: string, messageType: string): number;
|
|
183
|
+
/**
|
|
184
|
+
* Reset nonce for specific DID + message type
|
|
185
|
+
* @param did - DID identifier
|
|
186
|
+
* @param messageType - Message type identifier
|
|
187
|
+
*/
|
|
28
188
|
resetNonceForDID(did: string, messageType: string): void;
|
|
189
|
+
/**
|
|
190
|
+
* Switch current DID context
|
|
191
|
+
* @param did - New DID to track
|
|
192
|
+
*/
|
|
29
193
|
switchDID(did: string): void;
|
|
194
|
+
/**
|
|
195
|
+
* Get all nonces for all DIDs (for persistence)
|
|
196
|
+
* @returns Nested record of DID → message type → nonce
|
|
197
|
+
*/
|
|
30
198
|
getAllNonces(): Record<string, Record<string, number>>;
|
|
199
|
+
/**
|
|
200
|
+
* Clear all nonces for all DIDs
|
|
201
|
+
*/
|
|
31
202
|
clearAll(): void;
|
|
32
203
|
}
|
|
33
|
-
|
|
204
|
+
/**
|
|
205
|
+
* File-based Nonce Manager for Persistent Storage
|
|
206
|
+
*
|
|
207
|
+
* SECURITY FIX (H-1): Persists nonces to disk to survive process restarts.
|
|
208
|
+
* SECURITY FIX (NEW-H-4): File locking to prevent concurrent write corruption.
|
|
209
|
+
* Uses atomic file writes (temp file + rename) for crash safety.
|
|
210
|
+
*
|
|
211
|
+
* @module utils/NonceManager
|
|
212
|
+
*/
|
|
213
|
+
export declare class FileBasedNonceManager implements NonceManager {
|
|
214
|
+
private inMemory;
|
|
215
|
+
private filePath;
|
|
216
|
+
private fs;
|
|
217
|
+
private path;
|
|
218
|
+
private lockfile;
|
|
219
|
+
/**
|
|
220
|
+
* Create file-based nonce manager
|
|
221
|
+
* @param stateDirectory - Directory to store nonces file
|
|
222
|
+
*/
|
|
223
|
+
constructor(stateDirectory: string);
|
|
224
|
+
/**
|
|
225
|
+
* Load nonces from file
|
|
226
|
+
*/
|
|
227
|
+
private loadFromFile;
|
|
228
|
+
/**
|
|
229
|
+
* Save nonces to file atomically with file locking
|
|
230
|
+
*
|
|
231
|
+
* SECURITY FIX (NEW-H-4): File locking prevents concurrent write corruption
|
|
232
|
+
*/
|
|
233
|
+
private saveToFile;
|
|
234
|
+
getNextNonce(messageType: string): number;
|
|
235
|
+
/**
|
|
236
|
+
* Atomic get and increment with persistence
|
|
237
|
+
*/
|
|
238
|
+
getAndIncrementNonce(messageType: string): Promise<number>;
|
|
239
|
+
recordNonce(messageType: string, nonce: number): void;
|
|
240
|
+
getCurrentNonce(messageType: string): number;
|
|
241
|
+
resetNonce(messageType: string): void;
|
|
242
|
+
getAllNonces(): Record<string, number>;
|
|
243
|
+
clearAll(): void;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Create nonce manager based on environment
|
|
247
|
+
* @param options - Configuration options
|
|
248
|
+
* @returns NonceManager instance
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* // In-memory (default)
|
|
253
|
+
* const manager = createNonceManager();
|
|
254
|
+
*
|
|
255
|
+
* // DID-scoped
|
|
256
|
+
* const manager = createNonceManager({ did: 'did:ethr:0x...' });
|
|
257
|
+
*
|
|
258
|
+
* // Persistent (survives restarts)
|
|
259
|
+
* const manager = createNonceManager({ stateDirectory: '/path/to/project' });
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
export declare function createNonceManager(options?: {
|
|
263
|
+
did?: string;
|
|
264
|
+
initialNonces?: Record<string, number>;
|
|
265
|
+
stateDirectory?: string;
|
|
266
|
+
}): NonceManager;
|
|
34
267
|
//# sourceMappingURL=NonceManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NonceManager.d.ts","sourceRoot":"","sources":["../../src/utils/NonceManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NonceManager.d.ts","sourceRoot":"","sources":["../../src/utils/NonceManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAA0B,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAE1C;;;;OAIG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtD;;;;OAIG;IACH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