@agirails/sdk 2.0.1-beta → 2.0.3
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/BasicAdapter.d.ts +152 -0
- package/dist/adapters/BasicAdapter.d.ts.map +1 -0
- package/dist/adapters/BasicAdapter.js +168 -0
- package/dist/adapters/BasicAdapter.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/StandardAdapter.d.ts +211 -0
- package/dist/adapters/StandardAdapter.d.ts.map +1 -0
- package/dist/adapters/StandardAdapter.js +260 -0
- package/dist/adapters/StandardAdapter.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/BasicAdapter.ts +232 -0
- package/src/adapters/StandardAdapter.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,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IntermediateAdapter - Balanced API for developers with some protocol knowledge
|
|
3
|
+
*
|
|
4
|
+
* Provides more control than BeginnerAdapter while still offering convenience:
|
|
5
|
+
* - Explicit transaction lifecycle methods
|
|
6
|
+
* - Direct escrow operations
|
|
7
|
+
* - State transition control
|
|
8
|
+
*
|
|
9
|
+
* Use this adapter when you need fine-grained control but still want
|
|
10
|
+
* user-friendly input parsing and validation.
|
|
11
|
+
*
|
|
12
|
+
* @module adapters/IntermediateAdapter
|
|
13
|
+
*/
|
|
14
|
+
import { BaseAdapter } from './BaseAdapter';
|
|
15
|
+
import { IACTPRuntime } from '../runtime/IACTPRuntime';
|
|
16
|
+
import { MockTransaction, TransactionState } from '../runtime/types/MockState';
|
|
17
|
+
import { EASHelper } from '../protocol/EASHelper';
|
|
18
|
+
/**
|
|
19
|
+
* Parameters for creating a transaction (intermediate level).
|
|
20
|
+
*
|
|
21
|
+
* More explicit than BeginnerPayParams but still with smart defaults.
|
|
22
|
+
*/
|
|
23
|
+
export interface IntermediateTransactionParams {
|
|
24
|
+
/** Provider's Ethereum address */
|
|
25
|
+
provider: string;
|
|
26
|
+
/** Amount in user-friendly format ("100", "100.50", "100 USDC") */
|
|
27
|
+
amount: string | number;
|
|
28
|
+
/** Optional: Deadline as relative time ("+24h") or Unix timestamp. Defaults to +24h */
|
|
29
|
+
deadline?: string | number;
|
|
30
|
+
/** Optional: Dispute window in seconds. Defaults to 172800 (2 days) */
|
|
31
|
+
disputeWindow?: number;
|
|
32
|
+
/** Optional: Service description */
|
|
33
|
+
serviceDescription?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* IntermediateAdapter - Balanced API for transaction lifecycle control.
|
|
37
|
+
*
|
|
38
|
+
* Provides explicit methods for each stage of the ACTP lifecycle:
|
|
39
|
+
* - `createTransaction()` - Create transaction without escrow
|
|
40
|
+
* - `linkEscrow()` - Link escrow (auto-transitions to COMMITTED)
|
|
41
|
+
* - `transitionState()` - Manually transition state
|
|
42
|
+
* - `releaseEscrow()` - Release funds to provider
|
|
43
|
+
* - `getEscrowBalance()` - Check escrow balance
|
|
44
|
+
* - `getTransaction()` - Get transaction details
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const client = await ACTPClient.create({ mode: 'mock' });
|
|
49
|
+
*
|
|
50
|
+
* // Create transaction (INITIATED state)
|
|
51
|
+
* const txId = await client.intermediate.createTransaction({
|
|
52
|
+
* provider: '0xProvider123',
|
|
53
|
+
* amount: '100',
|
|
54
|
+
* deadline: '+7d',
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Link escrow (auto-transitions to COMMITTED)
|
|
58
|
+
* await client.intermediate.linkEscrow(txId, '100');
|
|
59
|
+
*
|
|
60
|
+
* // Provider delivers
|
|
61
|
+
* await client.intermediate.transitionState(txId, 'DELIVERED');
|
|
62
|
+
*
|
|
63
|
+
* // Release funds after dispute window
|
|
64
|
+
* await client.intermediate.releaseEscrow(escrowId);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare class IntermediateAdapter extends BaseAdapter {
|
|
68
|
+
private runtime;
|
|
69
|
+
private easHelper?;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new IntermediateAdapter instance.
|
|
72
|
+
*
|
|
73
|
+
* @param runtime - ACTP runtime implementation (MockRuntime or BlockchainRuntime)
|
|
74
|
+
* @param requesterAddress - The requester's Ethereum address
|
|
75
|
+
* @param easHelper - Optional EAS helper for attestation verification (SECURITY FIX C-4)
|
|
76
|
+
*/
|
|
77
|
+
constructor(runtime: IACTPRuntime, requesterAddress: string, easHelper?: EASHelper | undefined);
|
|
78
|
+
/**
|
|
79
|
+
* Create a transaction (INITIATED state, no escrow yet).
|
|
80
|
+
*
|
|
81
|
+
* Unlike `beginner.pay()`, this only creates the transaction
|
|
82
|
+
* without linking escrow. You must call `linkEscrow()` separately.
|
|
83
|
+
*
|
|
84
|
+
* @param params - Transaction parameters
|
|
85
|
+
* @returns Transaction ID
|
|
86
|
+
* @throws {ValidationError} If inputs are invalid
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const txId = await adapter.createTransaction({
|
|
91
|
+
* provider: '0xProvider123',
|
|
92
|
+
* amount: '100',
|
|
93
|
+
* deadline: '+24h',
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
createTransaction(params: IntermediateTransactionParams): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Link escrow to a transaction.
|
|
100
|
+
*
|
|
101
|
+
* Automatically transitions INITIATED or QUOTED → COMMITTED.
|
|
102
|
+
* Deducts funds from requester and locks in escrow.
|
|
103
|
+
*
|
|
104
|
+
* @param txId - Transaction ID
|
|
105
|
+
* @returns Escrow ID
|
|
106
|
+
* @throws {Error} If transaction not found or in wrong state
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const escrowId = await adapter.linkEscrow(txId);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
linkEscrow(txId: string): Promise<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Transition transaction to a new state.
|
|
116
|
+
*
|
|
117
|
+
* Validates the transition against the ACTP 8-state machine.
|
|
118
|
+
*
|
|
119
|
+
* Valid transitions:
|
|
120
|
+
* - INITIATED → QUOTED, COMMITTED, CANCELLED
|
|
121
|
+
* - QUOTED → COMMITTED, CANCELLED
|
|
122
|
+
* - COMMITTED → IN_PROGRESS, DELIVERED, CANCELLED
|
|
123
|
+
* - IN_PROGRESS → DELIVERED, CANCELLED
|
|
124
|
+
* - DELIVERED → SETTLED, DISPUTED
|
|
125
|
+
* - DISPUTED → SETTLED
|
|
126
|
+
*
|
|
127
|
+
* @param txId - Transaction ID
|
|
128
|
+
* @param newState - Target state
|
|
129
|
+
* @throws {Error} If transition is invalid
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Provider marks work as delivered
|
|
134
|
+
* await adapter.transitionState(txId, 'DELIVERED');
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
transitionState(txId: string, newState: TransactionState): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Release escrow funds to the provider.
|
|
140
|
+
*
|
|
141
|
+
* Can only be called when transaction is in DELIVERED state
|
|
142
|
+
* and dispute window has expired.
|
|
143
|
+
*
|
|
144
|
+
* SECURITY FIX (C-4 + HIGH-5): MANDATORY attestation verification before release.
|
|
145
|
+
* When EASHelper is available (testnet/mainnet modes), attestation verification
|
|
146
|
+
* is REQUIRED - not optional. This prevents releasing funds without proper
|
|
147
|
+
* delivery proof.
|
|
148
|
+
*
|
|
149
|
+
* Verifications performed:
|
|
150
|
+
* - Attestation exists and is not revoked
|
|
151
|
+
* - Attestation belongs to this transaction (prevents replay attacks)
|
|
152
|
+
* - Attestation has not been used for a different transaction
|
|
153
|
+
*
|
|
154
|
+
* @param escrowId - Escrow ID
|
|
155
|
+
* @param attestationParams - Attestation verification params (REQUIRED when EASHelper available)
|
|
156
|
+
* @param attestationParams.txId - Transaction ID (bytes32)
|
|
157
|
+
* @param attestationParams.attestationUID - Attestation UID (bytes32)
|
|
158
|
+
* @throws {Error} If escrow not found or dispute window active
|
|
159
|
+
* @throws {Error} If EASHelper is available but attestationParams not provided (HIGH-5)
|
|
160
|
+
* @throws {Error} If attestation verification fails
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // With attestation verification (REQUIRED in testnet/mainnet)
|
|
165
|
+
* await adapter.releaseEscrow(escrowId, {
|
|
166
|
+
* txId: '0x...',
|
|
167
|
+
* attestationUID: '0x...'
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* // Mock mode only (no attestation required)
|
|
171
|
+
* await adapter.releaseEscrow(escrowId);
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
releaseEscrow(escrowId: string, attestationParams?: {
|
|
175
|
+
txId: string;
|
|
176
|
+
attestationUID: string;
|
|
177
|
+
}): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Get escrow balance.
|
|
180
|
+
*
|
|
181
|
+
* Returns formatted balance string (e.g., "100.00 USDC").
|
|
182
|
+
*
|
|
183
|
+
* @param escrowId - Escrow ID
|
|
184
|
+
* @returns Formatted balance
|
|
185
|
+
* @throws {Error} If escrow not found
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const balance = await adapter.getEscrowBalance(escrowId);
|
|
190
|
+
* console.log(balance); // "100.00 USDC"
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
getEscrowBalance(escrowId: string): Promise<string>;
|
|
194
|
+
/**
|
|
195
|
+
* Get transaction details.
|
|
196
|
+
*
|
|
197
|
+
* Returns the full transaction object from the runtime.
|
|
198
|
+
*
|
|
199
|
+
* @param txId - Transaction ID
|
|
200
|
+
* @returns Transaction object or null if not found
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const tx = await adapter.getTransaction(txId);
|
|
205
|
+
* console.log('State:', tx?.state);
|
|
206
|
+
* console.log('Amount:', tx?.amount);
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
getTransaction(txId: string): Promise<MockTransaction | null>;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=IntermediateAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntermediateAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/IntermediateAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAmD,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC5C,kCAAkC;IAClC,QAAQ,EAAE,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CAGpE"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IntermediateAdapter - Balanced API for developers with some protocol knowledge
|
|
4
|
+
*
|
|
5
|
+
* Provides more control than BeginnerAdapter while still offering convenience:
|
|
6
|
+
* - Explicit transaction lifecycle methods
|
|
7
|
+
* - Direct escrow operations
|
|
8
|
+
* - State transition control
|
|
9
|
+
*
|
|
10
|
+
* Use this adapter when you need fine-grained control but still want
|
|
11
|
+
* user-friendly input parsing and validation.
|
|
12
|
+
*
|
|
13
|
+
* @module adapters/IntermediateAdapter
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.IntermediateAdapter = void 0;
|
|
17
|
+
const BaseAdapter_1 = require("./BaseAdapter");
|
|
18
|
+
/**
|
|
19
|
+
* IntermediateAdapter - Balanced API for transaction lifecycle control.
|
|
20
|
+
*
|
|
21
|
+
* Provides explicit methods for each stage of the ACTP lifecycle:
|
|
22
|
+
* - `createTransaction()` - Create transaction without escrow
|
|
23
|
+
* - `linkEscrow()` - Link escrow (auto-transitions to COMMITTED)
|
|
24
|
+
* - `transitionState()` - Manually transition state
|
|
25
|
+
* - `releaseEscrow()` - Release funds to provider
|
|
26
|
+
* - `getEscrowBalance()` - Check escrow balance
|
|
27
|
+
* - `getTransaction()` - Get transaction details
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const client = await ACTPClient.create({ mode: 'mock' });
|
|
32
|
+
*
|
|
33
|
+
* // Create transaction (INITIATED state)
|
|
34
|
+
* const txId = await client.intermediate.createTransaction({
|
|
35
|
+
* provider: '0xProvider123',
|
|
36
|
+
* amount: '100',
|
|
37
|
+
* deadline: '+7d',
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Link escrow (auto-transitions to COMMITTED)
|
|
41
|
+
* await client.intermediate.linkEscrow(txId, '100');
|
|
42
|
+
*
|
|
43
|
+
* // Provider delivers
|
|
44
|
+
* await client.intermediate.transitionState(txId, 'DELIVERED');
|
|
45
|
+
*
|
|
46
|
+
* // Release funds after dispute window
|
|
47
|
+
* await client.intermediate.releaseEscrow(escrowId);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
class IntermediateAdapter extends BaseAdapter_1.BaseAdapter {
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new IntermediateAdapter instance.
|
|
53
|
+
*
|
|
54
|
+
* @param runtime - ACTP runtime implementation (MockRuntime or BlockchainRuntime)
|
|
55
|
+
* @param requesterAddress - The requester's Ethereum address
|
|
56
|
+
* @param easHelper - Optional EAS helper for attestation verification (SECURITY FIX C-4)
|
|
57
|
+
*/
|
|
58
|
+
constructor(runtime, requesterAddress, easHelper) {
|
|
59
|
+
super(requesterAddress);
|
|
60
|
+
this.runtime = runtime;
|
|
61
|
+
this.easHelper = easHelper;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a transaction (INITIATED state, no escrow yet).
|
|
65
|
+
*
|
|
66
|
+
* Unlike `beginner.pay()`, this only creates the transaction
|
|
67
|
+
* without linking escrow. You must call `linkEscrow()` separately.
|
|
68
|
+
*
|
|
69
|
+
* @param params - Transaction parameters
|
|
70
|
+
* @returns Transaction ID
|
|
71
|
+
* @throws {ValidationError} If inputs are invalid
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const txId = await adapter.createTransaction({
|
|
76
|
+
* provider: '0xProvider123',
|
|
77
|
+
* amount: '100',
|
|
78
|
+
* deadline: '+24h',
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
async createTransaction(params) {
|
|
83
|
+
const provider = this.validateAddress(params.provider, 'provider');
|
|
84
|
+
const amount = this.parseAmount(params.amount);
|
|
85
|
+
const currentTime = this.runtime.time.now();
|
|
86
|
+
const deadline = this.parseDeadline(params.deadline, currentTime);
|
|
87
|
+
// SECURITY FIX (L-1): Validate dispute window bounds
|
|
88
|
+
const disputeWindow = this.validateDisputeWindow(params.disputeWindow);
|
|
89
|
+
const requester = this.requesterAddress;
|
|
90
|
+
// Validation
|
|
91
|
+
if (requester.toLowerCase() === provider.toLowerCase()) {
|
|
92
|
+
throw new BaseAdapter_1.ValidationError('Cannot create transaction with yourself as provider');
|
|
93
|
+
}
|
|
94
|
+
if (deadline <= currentTime) {
|
|
95
|
+
throw new BaseAdapter_1.ValidationError('Deadline must be in the future');
|
|
96
|
+
}
|
|
97
|
+
return this.runtime.createTransaction({
|
|
98
|
+
provider,
|
|
99
|
+
requester,
|
|
100
|
+
amount: amount.toString(),
|
|
101
|
+
deadline,
|
|
102
|
+
disputeWindow,
|
|
103
|
+
serviceDescription: params.serviceDescription,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Link escrow to a transaction.
|
|
108
|
+
*
|
|
109
|
+
* Automatically transitions INITIATED or QUOTED → COMMITTED.
|
|
110
|
+
* Deducts funds from requester and locks in escrow.
|
|
111
|
+
*
|
|
112
|
+
* @param txId - Transaction ID
|
|
113
|
+
* @returns Escrow ID
|
|
114
|
+
* @throws {Error} If transaction not found or in wrong state
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const escrowId = await adapter.linkEscrow(txId);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
async linkEscrow(txId) {
|
|
122
|
+
const tx = await this.runtime.getTransaction(txId);
|
|
123
|
+
if (!tx) {
|
|
124
|
+
throw new Error(`Transaction ${txId} not found`);
|
|
125
|
+
}
|
|
126
|
+
// Use the transaction's amount (already in correct format)
|
|
127
|
+
return this.runtime.linkEscrow(txId, tx.amount);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Transition transaction to a new state.
|
|
131
|
+
*
|
|
132
|
+
* Validates the transition against the ACTP 8-state machine.
|
|
133
|
+
*
|
|
134
|
+
* Valid transitions:
|
|
135
|
+
* - INITIATED → QUOTED, COMMITTED, CANCELLED
|
|
136
|
+
* - QUOTED → COMMITTED, CANCELLED
|
|
137
|
+
* - COMMITTED → IN_PROGRESS, DELIVERED, CANCELLED
|
|
138
|
+
* - IN_PROGRESS → DELIVERED, CANCELLED
|
|
139
|
+
* - DELIVERED → SETTLED, DISPUTED
|
|
140
|
+
* - DISPUTED → SETTLED
|
|
141
|
+
*
|
|
142
|
+
* @param txId - Transaction ID
|
|
143
|
+
* @param newState - Target state
|
|
144
|
+
* @throws {Error} If transition is invalid
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* // Provider marks work as delivered
|
|
149
|
+
* await adapter.transitionState(txId, 'DELIVERED');
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
async transitionState(txId, newState) {
|
|
153
|
+
return this.runtime.transitionState(txId, newState);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Release escrow funds to the provider.
|
|
157
|
+
*
|
|
158
|
+
* Can only be called when transaction is in DELIVERED state
|
|
159
|
+
* and dispute window has expired.
|
|
160
|
+
*
|
|
161
|
+
* SECURITY FIX (C-4 + HIGH-5): MANDATORY attestation verification before release.
|
|
162
|
+
* When EASHelper is available (testnet/mainnet modes), attestation verification
|
|
163
|
+
* is REQUIRED - not optional. This prevents releasing funds without proper
|
|
164
|
+
* delivery proof.
|
|
165
|
+
*
|
|
166
|
+
* Verifications performed:
|
|
167
|
+
* - Attestation exists and is not revoked
|
|
168
|
+
* - Attestation belongs to this transaction (prevents replay attacks)
|
|
169
|
+
* - Attestation has not been used for a different transaction
|
|
170
|
+
*
|
|
171
|
+
* @param escrowId - Escrow ID
|
|
172
|
+
* @param attestationParams - Attestation verification params (REQUIRED when EASHelper available)
|
|
173
|
+
* @param attestationParams.txId - Transaction ID (bytes32)
|
|
174
|
+
* @param attestationParams.attestationUID - Attestation UID (bytes32)
|
|
175
|
+
* @throws {Error} If escrow not found or dispute window active
|
|
176
|
+
* @throws {Error} If EASHelper is available but attestationParams not provided (HIGH-5)
|
|
177
|
+
* @throws {Error} If attestation verification fails
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* // With attestation verification (REQUIRED in testnet/mainnet)
|
|
182
|
+
* await adapter.releaseEscrow(escrowId, {
|
|
183
|
+
* txId: '0x...',
|
|
184
|
+
* attestationUID: '0x...'
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* // Mock mode only (no attestation required)
|
|
188
|
+
* await adapter.releaseEscrow(escrowId);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
async releaseEscrow(escrowId, attestationParams) {
|
|
192
|
+
// Determine whether the underlying runtime requires attestation.
|
|
193
|
+
// BlockchainRuntime exposes isAttestationRequired(), but it's not part of the generic interface.
|
|
194
|
+
const runtimeAny = this.runtime;
|
|
195
|
+
const runtimeSupportsAttestationFlag = typeof runtimeAny?.isAttestationRequired === 'function';
|
|
196
|
+
const attestationRequired = runtimeSupportsAttestationFlag
|
|
197
|
+
? Boolean(runtimeAny.isAttestationRequired())
|
|
198
|
+
: Boolean(this.easHelper);
|
|
199
|
+
if (attestationRequired && !attestationParams) {
|
|
200
|
+
throw new Error('Attestation verification is REQUIRED for escrow release. ' +
|
|
201
|
+
'Provide attestationParams: { txId: string, attestationUID: string }.');
|
|
202
|
+
}
|
|
203
|
+
// If caller provided attestation params, ensure they match the escrow/tx being released.
|
|
204
|
+
if (attestationParams) {
|
|
205
|
+
// Support legacy escrowId format "escrow-{txId}-{timestamp}".
|
|
206
|
+
// Standard is escrowId === txId.
|
|
207
|
+
const legacyMatch = escrowId.match(/^escrow-(.+)-\d+$/);
|
|
208
|
+
const txIdFromEscrowId = legacyMatch ? legacyMatch[1] : escrowId;
|
|
209
|
+
if (txIdFromEscrowId.toLowerCase() !== attestationParams.txId.toLowerCase()) {
|
|
210
|
+
throw new Error(`Attestation txId (${attestationParams.txId}) does not match escrow/txId (${txIdFromEscrowId}). ` +
|
|
211
|
+
`Refusing to release escrow with mismatched attestation.`);
|
|
212
|
+
}
|
|
213
|
+
// If runtime does NOT handle attestation internally but EASHelper exists, verify here.
|
|
214
|
+
// Otherwise, pass attestationUID down so BlockchainRuntime can enforce/record.
|
|
215
|
+
if (!runtimeSupportsAttestationFlag && this.easHelper) {
|
|
216
|
+
await this.easHelper.verifyAndRecordForRelease(attestationParams.txId, attestationParams.attestationUID);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return this.runtime.releaseEscrow(escrowId, attestationParams?.attestationUID);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get escrow balance.
|
|
223
|
+
*
|
|
224
|
+
* Returns formatted balance string (e.g., "100.00 USDC").
|
|
225
|
+
*
|
|
226
|
+
* @param escrowId - Escrow ID
|
|
227
|
+
* @returns Formatted balance
|
|
228
|
+
* @throws {Error} If escrow not found
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* const balance = await adapter.getEscrowBalance(escrowId);
|
|
233
|
+
* console.log(balance); // "100.00 USDC"
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
async getEscrowBalance(escrowId) {
|
|
237
|
+
const balance = await this.runtime.getEscrowBalance(escrowId);
|
|
238
|
+
return this.formatAmount(balance);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Get transaction details.
|
|
242
|
+
*
|
|
243
|
+
* Returns the full transaction object from the runtime.
|
|
244
|
+
*
|
|
245
|
+
* @param txId - Transaction ID
|
|
246
|
+
* @returns Transaction object or null if not found
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* const tx = await adapter.getTransaction(txId);
|
|
251
|
+
* console.log('State:', tx?.state);
|
|
252
|
+
* console.log('Amount:', tx?.amount);
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
async getTransaction(txId) {
|
|
256
|
+
return this.runtime.getTransaction(txId);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
exports.IntermediateAdapter = IntermediateAdapter;
|
|
260
|
+
//# sourceMappingURL=IntermediateAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntermediateAdapter.js","sourceRoot":"","sources":["../../src/adapters/IntermediateAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,+CAA6F;AA2B7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,mBAAoB,SAAQ,yBAAW;IAClD;;;;;;OAMG;IACH,YACU,OAAqB,EAC7B,gBAAwB,EAChB,SAAqB;QAE7B,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAJhB,YAAO,GAAP,OAAO,CAAc;QAErB,cAAS,GAAT,SAAS,CAAY;IAG/B,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,iBAAiB,CAAC,MAAqC;QAC3D,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACnE,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAClE,qDAAqD;QACrD,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAEvE,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAExC,aAAa;QACb,IAAI,SAAS,CAAC,WAAW,EAAE,KAAK,QAAQ,CAAC,WAAW,EAA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I,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,cAAc,CAAC,IAAY;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF;AAlPD,kDAkPC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StandardAdapter - Balanced API for developers with some protocol knowledge
|
|
3
|
+
*
|
|
4
|
+
* Provides more control than BasicAdapter while still offering convenience:
|
|
5
|
+
* - Explicit transaction lifecycle methods
|
|
6
|
+
* - Direct escrow operations
|
|
7
|
+
* - State transition control
|
|
8
|
+
*
|
|
9
|
+
* Use this adapter when you need fine-grained control but still want
|
|
10
|
+
* user-friendly input parsing and validation.
|
|
11
|
+
*
|
|
12
|
+
* @module adapters/StandardAdapter
|
|
13
|
+
*/
|
|
14
|
+
import { BaseAdapter } from './BaseAdapter';
|
|
15
|
+
import { IACTPRuntime } from '../runtime/IACTPRuntime';
|
|
16
|
+
import { MockTransaction, TransactionState } from '../runtime/types/MockState';
|
|
17
|
+
import { EASHelper } from '../protocol/EASHelper';
|
|
18
|
+
/**
|
|
19
|
+
* Parameters for creating a transaction (standard level).
|
|
20
|
+
*
|
|
21
|
+
* More explicit than BasicPayParams but still with smart defaults.
|
|
22
|
+
*/
|
|
23
|
+
export interface StandardTransactionParams {
|
|
24
|
+
/** Provider's Ethereum address */
|
|
25
|
+
provider: string;
|
|
26
|
+
/** Amount in user-friendly format ("100", "100.50", "100 USDC") */
|
|
27
|
+
amount: string | number;
|
|
28
|
+
/** Optional: Deadline as relative time ("+24h") or Unix timestamp. Defaults to +24h */
|
|
29
|
+
deadline?: string | number;
|
|
30
|
+
/** Optional: Dispute window in seconds. Defaults to 172800 (2 days) */
|
|
31
|
+
disputeWindow?: number;
|
|
32
|
+
/** Optional: Service description */
|
|
33
|
+
serviceDescription?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* StandardAdapter - Balanced API for transaction lifecycle control.
|
|
37
|
+
*
|
|
38
|
+
* Provides explicit methods for each stage of the ACTP lifecycle:
|
|
39
|
+
* - `createTransaction()` - Create transaction without escrow
|
|
40
|
+
* - `linkEscrow()` - Link escrow (auto-transitions to COMMITTED)
|
|
41
|
+
* - `transitionState()` - Manually transition state
|
|
42
|
+
* - `releaseEscrow()` - Release funds to provider
|
|
43
|
+
* - `getEscrowBalance()` - Check escrow balance
|
|
44
|
+
* - `getTransaction()` - Get transaction details
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const client = await ACTPClient.create({ mode: 'mock' });
|
|
49
|
+
*
|
|
50
|
+
* // Create transaction (INITIATED state)
|
|
51
|
+
* const txId = await client.standard.createTransaction({
|
|
52
|
+
* provider: '0xProvider123',
|
|
53
|
+
* amount: '100',
|
|
54
|
+
* deadline: '+7d',
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Link escrow (auto-transitions to COMMITTED)
|
|
58
|
+
* await client.standard.linkEscrow(txId, '100');
|
|
59
|
+
*
|
|
60
|
+
* // Provider delivers
|
|
61
|
+
* await client.standard.transitionState(txId, 'DELIVERED');
|
|
62
|
+
*
|
|
63
|
+
* // Release funds after dispute window
|
|
64
|
+
* await client.standard.releaseEscrow(escrowId);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare class StandardAdapter extends BaseAdapter {
|
|
68
|
+
private runtime;
|
|
69
|
+
private easHelper?;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new StandardAdapter instance.
|
|
72
|
+
*
|
|
73
|
+
* @param runtime - ACTP runtime implementation (MockRuntime or BlockchainRuntime)
|
|
74
|
+
* @param requesterAddress - The requester's Ethereum address
|
|
75
|
+
* @param easHelper - Optional EAS helper for attestation verification (SECURITY FIX C-4)
|
|
76
|
+
*/
|
|
77
|
+
constructor(runtime: IACTPRuntime, requesterAddress: string, easHelper?: EASHelper | undefined);
|
|
78
|
+
/**
|
|
79
|
+
* Create a transaction (INITIATED state, no escrow yet).
|
|
80
|
+
*
|
|
81
|
+
* Unlike `basic.pay()`, this only creates the transaction
|
|
82
|
+
* without linking escrow. You must call `linkEscrow()` separately.
|
|
83
|
+
*
|
|
84
|
+
* @param params - Transaction parameters
|
|
85
|
+
* @returns Transaction ID
|
|
86
|
+
* @throws {ValidationError} If inputs are invalid
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const txId = await adapter.createTransaction({
|
|
91
|
+
* provider: '0xProvider123',
|
|
92
|
+
* amount: '100',
|
|
93
|
+
* deadline: '+24h',
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
createTransaction(params: StandardTransactionParams): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Link escrow to a transaction.
|
|
100
|
+
*
|
|
101
|
+
* Automatically transitions INITIATED or QUOTED → COMMITTED.
|
|
102
|
+
* Deducts funds from requester and locks in escrow.
|
|
103
|
+
*
|
|
104
|
+
* @param txId - Transaction ID
|
|
105
|
+
* @returns Escrow ID
|
|
106
|
+
* @throws {Error} If transaction not found or in wrong state
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const escrowId = await adapter.linkEscrow(txId);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
linkEscrow(txId: string): Promise<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Transition transaction to a new state.
|
|
116
|
+
*
|
|
117
|
+
* Validates the transition against the ACTP 8-state machine.
|
|
118
|
+
*
|
|
119
|
+
* Valid transitions:
|
|
120
|
+
* - INITIATED → QUOTED, COMMITTED, CANCELLED
|
|
121
|
+
* - QUOTED → COMMITTED, CANCELLED
|
|
122
|
+
* - COMMITTED → IN_PROGRESS, DELIVERED, CANCELLED
|
|
123
|
+
* - IN_PROGRESS → DELIVERED, CANCELLED
|
|
124
|
+
* - DELIVERED → SETTLED, DISPUTED
|
|
125
|
+
* - DISPUTED → SETTLED
|
|
126
|
+
*
|
|
127
|
+
* @param txId - Transaction ID
|
|
128
|
+
* @param newState - Target state
|
|
129
|
+
* @throws {Error} If transition is invalid
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Provider marks work as delivered
|
|
134
|
+
* await adapter.transitionState(txId, 'DELIVERED');
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
transitionState(txId: string, newState: TransactionState): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Release escrow funds to the provider.
|
|
140
|
+
*
|
|
141
|
+
* Can only be called when transaction is in DELIVERED state
|
|
142
|
+
* and dispute window has expired.
|
|
143
|
+
*
|
|
144
|
+
* SECURITY FIX (C-4 + HIGH-5): MANDATORY attestation verification before release.
|
|
145
|
+
* When EASHelper is available (testnet/mainnet modes), attestation verification
|
|
146
|
+
* is REQUIRED - not optional. This prevents releasing funds without proper
|
|
147
|
+
* delivery proof.
|
|
148
|
+
*
|
|
149
|
+
* Verifications performed:
|
|
150
|
+
* - Attestation exists and is not revoked
|
|
151
|
+
* - Attestation belongs to this transaction (prevents replay attacks)
|
|
152
|
+
* - Attestation has not been used for a different transaction
|
|
153
|
+
*
|
|
154
|
+
* @param escrowId - Escrow ID
|
|
155
|
+
* @param attestationParams - Attestation verification params (REQUIRED when EASHelper available)
|
|
156
|
+
* @param attestationParams.txId - Transaction ID (bytes32)
|
|
157
|
+
* @param attestationParams.attestationUID - Attestation UID (bytes32)
|
|
158
|
+
* @throws {Error} If escrow not found or dispute window active
|
|
159
|
+
* @throws {Error} If EASHelper is available but attestationParams not provided (HIGH-5)
|
|
160
|
+
* @throws {Error} If attestation verification fails
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // With attestation verification (REQUIRED in testnet/mainnet)
|
|
165
|
+
* await adapter.releaseEscrow(escrowId, {
|
|
166
|
+
* txId: '0x...',
|
|
167
|
+
* attestationUID: '0x...'
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* // Mock mode only (no attestation required)
|
|
171
|
+
* await adapter.releaseEscrow(escrowId);
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
releaseEscrow(escrowId: string, attestationParams?: {
|
|
175
|
+
txId: string;
|
|
176
|
+
attestationUID: string;
|
|
177
|
+
}): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Get escrow balance.
|
|
180
|
+
*
|
|
181
|
+
* Returns formatted balance string (e.g., "100.00 USDC").
|
|
182
|
+
*
|
|
183
|
+
* @param escrowId - Escrow ID
|
|
184
|
+
* @returns Formatted balance
|
|
185
|
+
* @throws {Error} If escrow not found
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const balance = await adapter.getEscrowBalance(escrowId);
|
|
190
|
+
* console.log(balance); // "100.00 USDC"
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
getEscrowBalance(escrowId: string): Promise<string>;
|
|
194
|
+
/**
|
|
195
|
+
* Get transaction details.
|
|
196
|
+
*
|
|
197
|
+
* Returns the full transaction object from the runtime.
|
|
198
|
+
*
|
|
199
|
+
* @param txId - Transaction ID
|
|
200
|
+
* @returns Transaction object or null if not found
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const tx = await adapter.getTransaction(txId);
|
|
205
|
+
* console.log('State:', tx?.state);
|
|
206
|
+
* console.log('Amount:', tx?.amount);
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
getTransaction(txId: string): Promise<MockTransaction | null>;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=StandardAdapter.d.ts.map
|