@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,309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* UsedAttestationTracker - Prevents EAS Attestation Replay Attacks (C-1)
|
|
4
|
+
*
|
|
5
|
+
* Tracks which attestation UIDs have been used for which transaction IDs.
|
|
6
|
+
* This prevents a malicious provider from reusing an attestation from
|
|
7
|
+
* Transaction A to settle Transaction B.
|
|
8
|
+
*
|
|
9
|
+
* SECURITY: ACTPKernel V1 contract accepts any attestationUID without validation.
|
|
10
|
+
* This tracker provides SDK-side protection until contract is upgraded.
|
|
11
|
+
*
|
|
12
|
+
* @module utils/UsedAttestationTracker
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createUsedAttestationTracker = exports.FileBasedUsedAttestationTracker = exports.InMemoryUsedAttestationTracker = void 0;
|
|
16
|
+
const fsSafe_1 = require("./fsSafe");
|
|
17
|
+
/**
|
|
18
|
+
* In-Memory Used Attestation Tracker
|
|
19
|
+
*
|
|
20
|
+
* SECURITY FIX (C-1): Prevents attestation replay attacks by tracking
|
|
21
|
+
* which attestation UIDs have been used for which transactions.
|
|
22
|
+
*
|
|
23
|
+
* SECURITY FIX (NEW-H-2): LRU-style cache with max size to prevent DoS
|
|
24
|
+
*
|
|
25
|
+
* WARNING: In-memory only. For production:
|
|
26
|
+
* - Use persistent storage (Redis, PostgreSQL, etc.)
|
|
27
|
+
* - Implement recovery from blockchain events
|
|
28
|
+
*/
|
|
29
|
+
class InMemoryUsedAttestationTracker {
|
|
30
|
+
/**
|
|
31
|
+
* Create in-memory tracker with optional max size
|
|
32
|
+
* @param maxSize - Maximum entries to store (default: 100,000)
|
|
33
|
+
*/
|
|
34
|
+
constructor(maxSize = 100000) {
|
|
35
|
+
// Map: attestationUID -> txId
|
|
36
|
+
this.usedAttestations = new Map();
|
|
37
|
+
if (maxSize <= 0) {
|
|
38
|
+
throw new Error('maxSize must be positive');
|
|
39
|
+
}
|
|
40
|
+
this.maxSize = maxSize;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Record that an attestation was used for a transaction
|
|
44
|
+
* @param attestationUID - EAS attestation UID (bytes32)
|
|
45
|
+
* @param txId - Transaction ID (bytes32)
|
|
46
|
+
* @returns true if recorded, false if already used for different transaction
|
|
47
|
+
*
|
|
48
|
+
* SECURITY FIX (NEW-H-2): LRU eviction when max size reached
|
|
49
|
+
* SECURITY FIX (HIGH-1): Now async for interface consistency
|
|
50
|
+
*/
|
|
51
|
+
async recordUsage(attestationUID, txId) {
|
|
52
|
+
return this.recordUsageSync(attestationUID, txId);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Synchronous version of recordUsage (for backward compatibility)
|
|
56
|
+
* @param attestationUID - EAS attestation UID (bytes32)
|
|
57
|
+
* @param txId - Transaction ID (bytes32)
|
|
58
|
+
* @returns true if recorded, false if already used for different transaction
|
|
59
|
+
*/
|
|
60
|
+
recordUsageSync(attestationUID, txId) {
|
|
61
|
+
const normalizedUID = attestationUID.toLowerCase();
|
|
62
|
+
const normalizedTxId = txId.toLowerCase();
|
|
63
|
+
const existingTxId = this.usedAttestations.get(normalizedUID);
|
|
64
|
+
// If attestation was already used for a different transaction, reject
|
|
65
|
+
if (existingTxId && existingTxId !== normalizedTxId) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
// SECURITY FIX (NEW-H-2): Enforce max size limit with true LRU behavior
|
|
69
|
+
if (this.usedAttestations.size >= this.maxSize && !existingTxId) {
|
|
70
|
+
// Remove oldest entry (first entry in Map)
|
|
71
|
+
const firstKey = this.usedAttestations.keys().next().value;
|
|
72
|
+
if (firstKey) {
|
|
73
|
+
this.usedAttestations.delete(firstKey);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (existingTxId) {
|
|
77
|
+
// SECURITY FIX (M-3): True LRU - delete and re-add to move to end
|
|
78
|
+
this.usedAttestations.delete(normalizedUID);
|
|
79
|
+
}
|
|
80
|
+
// Record the usage (at end for LRU)
|
|
81
|
+
this.usedAttestations.set(normalizedUID, normalizedTxId);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if attestation has been used
|
|
86
|
+
* @param attestationUID - EAS attestation UID (bytes32)
|
|
87
|
+
* @returns Transaction ID if used, null if not used
|
|
88
|
+
*
|
|
89
|
+
* SECURITY FIX (MEDIUM-4): Updates access order for true LRU behavior
|
|
90
|
+
* Accessed items are moved to end of Map (most recently used)
|
|
91
|
+
*/
|
|
92
|
+
getUsageForAttestation(attestationUID) {
|
|
93
|
+
const normalizedUID = attestationUID.toLowerCase();
|
|
94
|
+
const txId = this.usedAttestations.get(normalizedUID);
|
|
95
|
+
// SECURITY FIX (MEDIUM-4): True LRU - move accessed item to end
|
|
96
|
+
// Without this, eviction uses insertion order, not access order
|
|
97
|
+
if (txId !== undefined) {
|
|
98
|
+
this.usedAttestations.delete(normalizedUID);
|
|
99
|
+
this.usedAttestations.set(normalizedUID, txId);
|
|
100
|
+
}
|
|
101
|
+
return txId || null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if attestation is valid for transaction
|
|
105
|
+
* @param attestationUID - EAS attestation UID
|
|
106
|
+
* @param txId - Transaction ID
|
|
107
|
+
* @returns true if attestation is unused or already used for this txId
|
|
108
|
+
*
|
|
109
|
+
* SECURITY FIX (MEDIUM-4): Updates access order for true LRU behavior
|
|
110
|
+
*/
|
|
111
|
+
isValidForTransaction(attestationUID, txId) {
|
|
112
|
+
const normalizedUID = attestationUID.toLowerCase();
|
|
113
|
+
const normalizedTxId = txId.toLowerCase();
|
|
114
|
+
const existingTxId = this.usedAttestations.get(normalizedUID);
|
|
115
|
+
// SECURITY FIX (MEDIUM-4): True LRU - move accessed item to end
|
|
116
|
+
if (existingTxId !== undefined) {
|
|
117
|
+
this.usedAttestations.delete(normalizedUID);
|
|
118
|
+
this.usedAttestations.set(normalizedUID, existingTxId);
|
|
119
|
+
}
|
|
120
|
+
// Valid if: not used OR used for same transaction
|
|
121
|
+
return !existingTxId || existingTxId === normalizedTxId;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Clear all tracked attestations
|
|
125
|
+
*/
|
|
126
|
+
clear() {
|
|
127
|
+
this.usedAttestations.clear();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get all tracked attestations (for debugging/persistence)
|
|
131
|
+
*/
|
|
132
|
+
getAllUsages() {
|
|
133
|
+
return Object.fromEntries(this.usedAttestations.entries());
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get count of tracked attestations
|
|
137
|
+
*/
|
|
138
|
+
getCount() {
|
|
139
|
+
return this.usedAttestations.size;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Cleanup old entries based on timestamp (optional)
|
|
143
|
+
*
|
|
144
|
+
* SECURITY FIX (NEW-H-2): Manual cleanup for old entries
|
|
145
|
+
* Note: This requires external timestamp tracking. For automatic cleanup,
|
|
146
|
+
* use FileBasedUsedAttestationTracker with periodic cleanup.
|
|
147
|
+
*
|
|
148
|
+
* @param maxAgeHours - Remove entries older than this many hours
|
|
149
|
+
*/
|
|
150
|
+
cleanupOldEntries(maxAgeHours) {
|
|
151
|
+
// In-memory tracker doesn't track timestamps
|
|
152
|
+
// This is a placeholder for future enhancement
|
|
153
|
+
console.warn('cleanupOldEntries not implemented for InMemoryUsedAttestationTracker. ' +
|
|
154
|
+
'Consider using FileBasedUsedAttestationTracker for time-based cleanup.');
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.InMemoryUsedAttestationTracker = InMemoryUsedAttestationTracker;
|
|
159
|
+
/**
|
|
160
|
+
* File-based Used Attestation Tracker for persistence
|
|
161
|
+
*
|
|
162
|
+
* SECURITY FIX (C-1): Persistent storage for attestation tracking
|
|
163
|
+
* SECURITY FIX (NEW-H-4): File locking to prevent concurrent write corruption
|
|
164
|
+
*
|
|
165
|
+
* Survives process restarts.
|
|
166
|
+
*/
|
|
167
|
+
class FileBasedUsedAttestationTracker {
|
|
168
|
+
constructor(stateDirectory) {
|
|
169
|
+
this.inMemory = new InMemoryUsedAttestationTracker();
|
|
170
|
+
this.fs = require('fs');
|
|
171
|
+
this.path = require('path');
|
|
172
|
+
// SECURITY FIX (NEW-H-4): File locking to prevent race conditions
|
|
173
|
+
this.lockfile = require('proper-lockfile');
|
|
174
|
+
// Ensure directory exists
|
|
175
|
+
const actpDir = this.path.join(stateDirectory, '.actp');
|
|
176
|
+
(0, fsSafe_1.ensureSafeDir)(actpDir, 0o755);
|
|
177
|
+
this.filePath = this.path.join(actpDir, 'used-attestations.json');
|
|
178
|
+
// Load existing data
|
|
179
|
+
this.loadFromFile();
|
|
180
|
+
}
|
|
181
|
+
loadFromFile() {
|
|
182
|
+
if (!this.fs.existsSync(this.filePath))
|
|
183
|
+
return;
|
|
184
|
+
// SECURITY: Refuse to read from symlinked tracker files
|
|
185
|
+
(0, fsSafe_1.assertSafeFileForRead)(this.filePath);
|
|
186
|
+
// Basic size limit to avoid memory DoS on parse
|
|
187
|
+
const MAX_TRACKER_FILE_SIZE = 10 * 1024 * 1024; // 10MB
|
|
188
|
+
const st = this.fs.statSync(this.filePath);
|
|
189
|
+
if (st.size > MAX_TRACKER_FILE_SIZE) {
|
|
190
|
+
throw new Error(`used-attestations.json exceeds ${MAX_TRACKER_FILE_SIZE / 1024 / 1024}MB limit: ${this.filePath}`);
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
const data = JSON.parse(this.fs.readFileSync(this.filePath, 'utf-8'));
|
|
194
|
+
for (const [uid, txId] of Object.entries(data)) {
|
|
195
|
+
this.inMemory.recordUsageSync(uid, txId);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
// Fail closed: losing replay-protection state is a security issue.
|
|
200
|
+
throw new Error(`Failed to parse used-attestations.json (replay protection would be disabled). ` +
|
|
201
|
+
`Fix/delete the file: ${this.filePath}. Error: ${e?.message || String(e)}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Save data to file with file locking
|
|
206
|
+
*
|
|
207
|
+
* SECURITY FIX (NEW-H-4): File locking prevents concurrent write corruption
|
|
208
|
+
* SECURITY FIX (NEW-HIGH-1): Create file before locking if it doesn't exist
|
|
209
|
+
*/
|
|
210
|
+
async saveToFile() {
|
|
211
|
+
const data = this.inMemory.getAllUsages();
|
|
212
|
+
const tempPath = `${this.filePath}.tmp`;
|
|
213
|
+
// SECURITY FIX (NEW-HIGH-1): Ensure file exists before locking
|
|
214
|
+
// proper-lockfile.lock() fails on non-existent files
|
|
215
|
+
(0, fsSafe_1.ensureSafeFile)(this.filePath, '{}', 0o644);
|
|
216
|
+
// SECURITY FIX (NEW-H-4): Acquire file lock before writing
|
|
217
|
+
let release = null;
|
|
218
|
+
try {
|
|
219
|
+
release = await this.lockfile.lock(this.filePath, {
|
|
220
|
+
stale: 10000, // Lock expires after 10 seconds if process crashes
|
|
221
|
+
retries: {
|
|
222
|
+
retries: 5,
|
|
223
|
+
minTimeout: 100,
|
|
224
|
+
maxTimeout: 500
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
// Atomic write: temp file + rename
|
|
228
|
+
if (this.fs.existsSync(tempPath)) {
|
|
229
|
+
this.fs.unlinkSync(tempPath);
|
|
230
|
+
}
|
|
231
|
+
this.fs.writeFileSync(tempPath, JSON.stringify(data, null, 2), {
|
|
232
|
+
encoding: 'utf-8',
|
|
233
|
+
mode: 0o644,
|
|
234
|
+
flag: 'wx'
|
|
235
|
+
});
|
|
236
|
+
this.fs.renameSync(tempPath, this.filePath);
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
// Clean up temp file on error
|
|
240
|
+
if (this.fs.existsSync(tempPath)) {
|
|
241
|
+
try {
|
|
242
|
+
this.fs.unlinkSync(tempPath);
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
// Ignore cleanup errors
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
// Always release lock if acquired
|
|
252
|
+
if (release) {
|
|
253
|
+
await release();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Record attestation usage with guaranteed persistence
|
|
259
|
+
*
|
|
260
|
+
* SECURITY FIX (HIGH-1): Now properly awaits persistence to prevent data loss
|
|
261
|
+
*/
|
|
262
|
+
async recordUsage(attestationUID, txId) {
|
|
263
|
+
const result = this.inMemory.recordUsageSync(attestationUID, txId);
|
|
264
|
+
if (result) {
|
|
265
|
+
// SECURITY FIX (HIGH-1): Await persistence to ensure data is saved
|
|
266
|
+
await this.saveToFile();
|
|
267
|
+
}
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Fire-and-forget version for backward compatibility
|
|
272
|
+
* WARNING: May lose data if process crashes before save completes
|
|
273
|
+
*/
|
|
274
|
+
recordUsageSync(attestationUID, txId) {
|
|
275
|
+
const result = this.inMemory.recordUsageSync(attestationUID, txId);
|
|
276
|
+
if (result) {
|
|
277
|
+
this.saveToFile().catch((err) => {
|
|
278
|
+
console.error('Failed to save attestation tracker state:', err);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
getUsageForAttestation(attestationUID) {
|
|
284
|
+
return this.inMemory.getUsageForAttestation(attestationUID);
|
|
285
|
+
}
|
|
286
|
+
isValidForTransaction(attestationUID, txId) {
|
|
287
|
+
return this.inMemory.isValidForTransaction(attestationUID, txId);
|
|
288
|
+
}
|
|
289
|
+
clear() {
|
|
290
|
+
this.inMemory.clear();
|
|
291
|
+
if (this.fs.existsSync(this.filePath)) {
|
|
292
|
+
this.fs.unlinkSync(this.filePath);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.FileBasedUsedAttestationTracker = FileBasedUsedAttestationTracker;
|
|
297
|
+
/**
|
|
298
|
+
* Factory to create attestation tracker
|
|
299
|
+
* @param stateDirectory - Optional directory for persistent storage
|
|
300
|
+
* @returns IUsedAttestationTracker instance
|
|
301
|
+
*/
|
|
302
|
+
function createUsedAttestationTracker(stateDirectory) {
|
|
303
|
+
if (stateDirectory) {
|
|
304
|
+
return new FileBasedUsedAttestationTracker(stateDirectory);
|
|
305
|
+
}
|
|
306
|
+
return new InMemoryUsedAttestationTracker();
|
|
307
|
+
}
|
|
308
|
+
exports.createUsedAttestationTracker = createUsedAttestationTracker;
|
|
309
|
+
//# sourceMappingURL=UsedAttestation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CAAC;QACpC,CAAC;IACH,CAAC;CACF;AArJD,0EAqJC;AAED;;;;GAIG;AACH,SAAgB,4BAA4B,CAC1C,cAAuB;IAEvB,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,IAAI,+BAA+B,CAAC,cAAc,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,IAAI,8BAA8B,EAAE,CAAC;AAC9C,CAAC;AAPD,oEAOC"}
|
|
@@ -1,4 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical JSON Serialization for AIP-4
|
|
3
|
+
* Reference: AIP-4 §3.6
|
|
4
|
+
*
|
|
5
|
+
* CRITICAL: Uses fast-json-stable-stringify@^2.1.0 for deterministic hashing
|
|
6
|
+
* This ensures resultHash is identical across all implementations (JS, Python, Go, Rust)
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Canonical JSON stringify (sorted keys, no whitespace)
|
|
10
|
+
* @param obj - Any JSON-serializable object
|
|
11
|
+
* @returns Canonical JSON string
|
|
12
|
+
*/
|
|
1
13
|
export declare function canonicalJsonStringify(obj: any): string;
|
|
14
|
+
/**
|
|
15
|
+
* Compute keccak256 hash of canonical JSON
|
|
16
|
+
* @param obj - Any JSON-serializable object
|
|
17
|
+
* @returns Keccak256 hash (0x-prefixed hex string)
|
|
18
|
+
*/
|
|
2
19
|
export declare function computeCanonicalHash(obj: any): string;
|
|
20
|
+
/**
|
|
21
|
+
* Compute result hash for delivery proof (AIP-4)
|
|
22
|
+
* @param resultData - Service result data
|
|
23
|
+
* @returns Keccak256 hash of canonical result JSON
|
|
24
|
+
*/
|
|
3
25
|
export declare function computeResultHash(resultData: any): string;
|
|
4
26
|
//# sourceMappingURL=canonicalJson.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalJson.d.ts","sourceRoot":"","sources":["../../src/utils/canonicalJson.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"canonicalJson.d.ts","sourceRoot":"","sources":["../../src/utils/canonicalJson.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAGrD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,GAAG,GAAG,MAAM,CAEzD"}
|
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Canonical JSON Serialization for AIP-4
|
|
4
|
+
* Reference: AIP-4 §3.6
|
|
5
|
+
*
|
|
6
|
+
* CRITICAL: Uses fast-json-stable-stringify@^2.1.0 for deterministic hashing
|
|
7
|
+
* This ensures resultHash is identical across all implementations (JS, Python, Go, Rust)
|
|
8
|
+
*/
|
|
2
9
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
10
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
11
|
};
|
|
5
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.canonicalJsonStringify =
|
|
7
|
-
exports.computeCanonicalHash = computeCanonicalHash;
|
|
8
|
-
exports.computeResultHash = computeResultHash;
|
|
13
|
+
exports.computeResultHash = exports.computeCanonicalHash = exports.canonicalJsonStringify = void 0;
|
|
9
14
|
const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
|
|
10
15
|
const ethers_1 = require("ethers");
|
|
16
|
+
/**
|
|
17
|
+
* Canonical JSON stringify (sorted keys, no whitespace)
|
|
18
|
+
* @param obj - Any JSON-serializable object
|
|
19
|
+
* @returns Canonical JSON string
|
|
20
|
+
*/
|
|
11
21
|
function canonicalJsonStringify(obj) {
|
|
12
22
|
return (0, fast_json_stable_stringify_1.default)(obj);
|
|
13
23
|
}
|
|
24
|
+
exports.canonicalJsonStringify = canonicalJsonStringify;
|
|
25
|
+
/**
|
|
26
|
+
* Compute keccak256 hash of canonical JSON
|
|
27
|
+
* @param obj - Any JSON-serializable object
|
|
28
|
+
* @returns Keccak256 hash (0x-prefixed hex string)
|
|
29
|
+
*/
|
|
14
30
|
function computeCanonicalHash(obj) {
|
|
15
31
|
const canonical = canonicalJsonStringify(obj);
|
|
16
32
|
return (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(canonical));
|
|
17
33
|
}
|
|
34
|
+
exports.computeCanonicalHash = computeCanonicalHash;
|
|
35
|
+
/**
|
|
36
|
+
* Compute result hash for delivery proof (AIP-4)
|
|
37
|
+
* @param resultData - Service result data
|
|
38
|
+
* @returns Keccak256 hash of canonical result JSON
|
|
39
|
+
*/
|
|
18
40
|
function computeResultHash(resultData) {
|
|
19
41
|
return computeCanonicalHash(resultData);
|
|
20
42
|
}
|
|
43
|
+
exports.computeResultHash = computeResultHash;
|
|
21
44
|
//# sourceMappingURL=canonicalJson.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalJson.js","sourceRoot":"","sources":["../../src/utils/canonicalJson.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"canonicalJson.js","sourceRoot":"","sources":["../../src/utils/canonicalJson.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;AAEH,4FAAmD;AACnD,mCAAgD;AAEhD;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,GAAQ;IAC7C,OAAO,IAAA,oCAAS,EAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AAFD,wDAEC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,GAAQ;IAC3C,MAAM,SAAS,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC9C,OAAO,IAAA,kBAAS,EAAC,IAAA,oBAAW,EAAC,SAAS,CAAC,CAAC,CAAC;AAC3C,CAAC;AAHD,oDAGC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,UAAe;IAC/C,OAAO,oBAAoB,CAAC,UAAU,CAAC,CAAC;AAC1C,CAAC;AAFD,8CAEC"}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute EIP-712 Type Hash for AIP-4 Delivery Proof
|
|
3
|
+
* Reference: AIP-4 §3.3, EIP-712 specification
|
|
4
|
+
*
|
|
5
|
+
* Run with: npx tsx src/utils/computeTypeHash.ts
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Compute EIP-712 type hash for DeliveryProof
|
|
9
|
+
* @returns Type hash (bytes32)
|
|
10
|
+
*/
|
|
1
11
|
export declare function computeDeliveryProofTypeHash(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Get encoded type string for DeliveryProof
|
|
14
|
+
* @returns Type string (for documentation)
|
|
15
|
+
*/
|
|
2
16
|
export declare function getDeliveryProofTypeString(): string;
|
|
3
17
|
//# sourceMappingURL=computeTypeHash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeTypeHash.d.ts","sourceRoot":"","sources":["../../src/utils/computeTypeHash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"computeTypeHash.d.ts","sourceRoot":"","sources":["../../src/utils/computeTypeHash.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAQrD;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAEnD"}
|
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Compute EIP-712 Type Hash for AIP-4 Delivery Proof
|
|
4
|
+
* Reference: AIP-4 §3.3, EIP-712 specification
|
|
5
|
+
*
|
|
6
|
+
* Run with: npx tsx src/utils/computeTypeHash.ts
|
|
7
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computeDeliveryProofTypeHash =
|
|
4
|
-
exports.getDeliveryProofTypeString = getDeliveryProofTypeString;
|
|
9
|
+
exports.getDeliveryProofTypeString = exports.computeDeliveryProofTypeHash = void 0;
|
|
5
10
|
const ethers_1 = require("ethers");
|
|
6
11
|
const eip712_1 = require("../types/eip712");
|
|
12
|
+
/**
|
|
13
|
+
* Compute EIP-712 type hash for DeliveryProof
|
|
14
|
+
* @returns Type hash (bytes32)
|
|
15
|
+
*/
|
|
7
16
|
function computeDeliveryProofTypeHash() {
|
|
8
17
|
const encoder = ethers_1.TypedDataEncoder.from(eip712_1.AIP4DeliveryProofTypes);
|
|
9
18
|
const typeString = encoder.encodeType('DeliveryProof');
|
|
19
|
+
// Type hash is keccak256 of the encoded type string
|
|
10
20
|
const typeHash = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(typeString));
|
|
11
21
|
return typeHash;
|
|
12
22
|
}
|
|
23
|
+
exports.computeDeliveryProofTypeHash = computeDeliveryProofTypeHash;
|
|
24
|
+
/**
|
|
25
|
+
* Get encoded type string for DeliveryProof
|
|
26
|
+
* @returns Type string (for documentation)
|
|
27
|
+
*/
|
|
13
28
|
function getDeliveryProofTypeString() {
|
|
14
29
|
return ethers_1.TypedDataEncoder.from(eip712_1.AIP4DeliveryProofTypes).encodeType('DeliveryProof');
|
|
15
30
|
}
|
|
31
|
+
exports.getDeliveryProofTypeString = getDeliveryProofTypeString;
|
|
32
|
+
// If run directly, compute and print type hash
|
|
16
33
|
if (require.main === module) {
|
|
17
34
|
console.log('=== AIP-4 Delivery Proof EIP-712 Type Hash ===\n');
|
|
18
35
|
const typeString = getDeliveryProofTypeString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeTypeHash.js","sourceRoot":"","sources":["../../src/utils/computeTypeHash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"computeTypeHash.js","sourceRoot":"","sources":["../../src/utils/computeTypeHash.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mCAAkE;AA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|
|
4
|
+
* Focus:
|
|
5
|
+
* - Prevent symlink-based path escapes when persisting local state
|
|
6
|
+
* - Avoid clobbering arbitrary files via pre-created symlink temp files
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This is not a complete TOCTOU-proof sandbox, but it eliminates the
|
|
9
|
+
* most common local symlink/hardlink footguns for SDK-managed state files.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ensureSafeDir(dirPath: string, mode?: number): void;
|
|
12
|
+
export declare function assertSafeFileForRead(filePath: string): void;
|
|
13
|
+
export declare function ensureSafeFile(filePath: string, contents: string, mode?: number): void;
|
|
14
|
+
//# sourceMappingURL=fsSafe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsSafe.d.ts","sourceRoot":"","sources":["../../src/utils/fsSafe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAc,GAAG,IAAI,CAmBzE;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAS5D;AAED,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,MAAc,GACnB,IAAI,CAmBN"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* fsSafe - minimal filesystem hardening helpers
|
|
4
|
+
*
|
|
5
|
+
* Focus:
|
|
6
|
+
* - Prevent symlink-based path escapes when persisting local state
|
|
7
|
+
* - Avoid clobbering arbitrary files via pre-created symlink temp files
|
|
8
|
+
*
|
|
9
|
+
* NOTE: This is not a complete TOCTOU-proof sandbox, but it eliminates the
|
|
10
|
+
* most common local symlink/hardlink footguns for SDK-managed state files.
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ensureSafeFile = exports.assertSafeFileForRead = exports.ensureSafeDir = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
function ensureSafeDir(dirPath, mode = 0o755) {
|
|
39
|
+
if (fs.existsSync(dirPath)) {
|
|
40
|
+
const st = fs.lstatSync(dirPath);
|
|
41
|
+
if (st.isSymbolicLink()) {
|
|
42
|
+
throw new Error(`Refusing to use symlink directory: ${dirPath}`);
|
|
43
|
+
}
|
|
44
|
+
if (!st.isDirectory()) {
|
|
45
|
+
throw new Error(`Expected directory but found non-directory: ${dirPath}`);
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
fs.mkdirSync(dirPath, { recursive: true, mode });
|
|
50
|
+
// Post-create sanity: ensure it didn't become a symlink (defense-in-depth)
|
|
51
|
+
const st = fs.lstatSync(dirPath);
|
|
52
|
+
if (st.isSymbolicLink() || !st.isDirectory()) {
|
|
53
|
+
throw new Error(`Created unsafe directory (symlink or non-dir): ${dirPath}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.ensureSafeDir = ensureSafeDir;
|
|
57
|
+
function assertSafeFileForRead(filePath) {
|
|
58
|
+
if (!fs.existsSync(filePath))
|
|
59
|
+
return;
|
|
60
|
+
const st = fs.lstatSync(filePath);
|
|
61
|
+
if (st.isSymbolicLink()) {
|
|
62
|
+
throw new Error(`Refusing to read from symlink file: ${filePath}`);
|
|
63
|
+
}
|
|
64
|
+
if (!st.isFile()) {
|
|
65
|
+
throw new Error(`Expected file but found non-file: ${filePath}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.assertSafeFileForRead = assertSafeFileForRead;
|
|
69
|
+
function ensureSafeFile(filePath, contents, mode = 0o644) {
|
|
70
|
+
if (fs.existsSync(filePath)) {
|
|
71
|
+
const st = fs.lstatSync(filePath);
|
|
72
|
+
if (st.isSymbolicLink()) {
|
|
73
|
+
throw new Error(`Refusing to use symlink file: ${filePath}`);
|
|
74
|
+
}
|
|
75
|
+
if (!st.isFile()) {
|
|
76
|
+
throw new Error(`Expected file but found non-file: ${filePath}`);
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Use exclusive create to avoid clobbering a file that appears between
|
|
81
|
+
// existsSync() and writeFileSync().
|
|
82
|
+
fs.writeFileSync(filePath, contents, {
|
|
83
|
+
encoding: 'utf-8',
|
|
84
|
+
mode,
|
|
85
|
+
flag: 'wx',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
exports.ensureSafeFile = ensureSafeFile;
|
|
89
|
+
//# sourceMappingURL=fsSafe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsSaf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,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,qCAAqC,QAAQ,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AATD,sDASC;AAED,SAAgB,cAAc,CAC5B,QAAgB,EAChB,QAAgB,EAChB,OAAe,KAAK;IAEpB,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAClC,IAAI,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,qCAAqC,QAAQ,EAAE,CAAC,CAAC;QACnE,CAAC;QACD,OAAO;IACT,CAAC;IAED,uEAAuE;IACvE,oCAAoC;IACpC,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE;QACnC,QAAQ,EAAE,OAAO;QACjB,IAAI;QACJ,IAAI,EAAE,IAAI;KACX,CAAC,CAAC;AACL,CAAC;AAvBD,wCAuBC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACTP SDK Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module exports all utility classes for the ACTP SDK.
|
|
5
|
+
*
|
|
6
|
+
* @module utils
|
|
7
|
+
*/
|
|
8
|
+
export { ErrorRecoveryGuide, withRecoveryGuidance, type ErrorRecoveryInfo, type ErrorSeverity, type ErrorCategory, } from './ErrorRecoveryGuide';
|
|
9
|
+
export { RateLimiter, CircuitBreaker, APIProtector, type RateLimiterConfig, type RateLimitResult, type CircuitBreakerConfig, type CircuitBreakerResult, type CircuitState, } from './RateLimiter';
|
|
10
|
+
export { Logger, MetricsCollector, sdkLogger, sdkMetrics, type LogLevel, type LogEntry, type LoggerConfig, type MetricsHook, } from './Logger';
|
|
11
|
+
export { SDKLifecycle, sdkLifecycle, onShutdown, registerDisposable, shutdownSDK, type Disposable, type ShutdownHandler, type LifecycleEvent, type LifecycleListener, } from './SDKLifecycle';
|
|
12
|
+
export { InMemoryReceivedNonceTracker, SetBasedReceivedNonceTracker, createReceivedNonceTracker, type IReceivedNonceTracker, type NonceValidationResult, } from './ReceivedNonceTracker';
|
|
13
|
+
export { InMemoryUsedAttestationTracker, FileBasedUsedAttestationTracker, createUsedAttestationTracker, type IUsedAttestationTracker, } from './UsedAttestationTracker';
|
|
14
|
+
export { USDC, Deadline, Address, Bytes32, State, DisputeWindow, } from './Helpers';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,WAAW,EACX,cAAc,EACd,YAAY,EACZ,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,YAAY,GAClB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,WAAW,EACX,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,0BAA0B,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,GAC3B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,8BAA8B,EAC9B,+BAA+B,EAC/B,4BAA4B,EAC5B,KAAK,uBAAuB,GAC7B,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,OAAO,EACP,KAAK,EACL,aAAa,GACd,MAAM,WAAW,CAAC"}
|