@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,316 @@
|
|
|
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
|
+
|
|
15
|
+
import { BaseAdapter, ValidationError, DEFAULT_DISPUTE_WINDOW_SECONDS } from './BaseAdapter';
|
|
16
|
+
import { IACTPRuntime } from '../runtime/IACTPRuntime';
|
|
17
|
+
import { MockTransaction, TransactionState } from '../runtime/types/MockState';
|
|
18
|
+
import { EASHelper } from '../protocol/EASHelper';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Parameters for creating a transaction (intermediate level).
|
|
22
|
+
*
|
|
23
|
+
* More explicit than BeginnerPayParams but still with smart defaults.
|
|
24
|
+
*/
|
|
25
|
+
export interface IntermediateTransactionParams {
|
|
26
|
+
/** Provider's Ethereum address */
|
|
27
|
+
provider: string;
|
|
28
|
+
|
|
29
|
+
/** Amount in user-friendly format ("100", "100.50", "100 USDC") */
|
|
30
|
+
amount: string | number;
|
|
31
|
+
|
|
32
|
+
/** Optional: Deadline as relative time ("+24h") or Unix timestamp. Defaults to +24h */
|
|
33
|
+
deadline?: string | number;
|
|
34
|
+
|
|
35
|
+
/** Optional: Dispute window in seconds. Defaults to 172800 (2 days) */
|
|
36
|
+
disputeWindow?: number;
|
|
37
|
+
|
|
38
|
+
/** Optional: Service description */
|
|
39
|
+
serviceDescription?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* IntermediateAdapter - Balanced API for transaction lifecycle control.
|
|
44
|
+
*
|
|
45
|
+
* Provides explicit methods for each stage of the ACTP lifecycle:
|
|
46
|
+
* - `createTransaction()` - Create transaction without escrow
|
|
47
|
+
* - `linkEscrow()` - Link escrow (auto-transitions to COMMITTED)
|
|
48
|
+
* - `transitionState()` - Manually transition state
|
|
49
|
+
* - `releaseEscrow()` - Release funds to provider
|
|
50
|
+
* - `getEscrowBalance()` - Check escrow balance
|
|
51
|
+
* - `getTransaction()` - Get transaction details
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const client = await ACTPClient.create({ mode: 'mock' });
|
|
56
|
+
*
|
|
57
|
+
* // Create transaction (INITIATED state)
|
|
58
|
+
* const txId = await client.intermediate.createTransaction({
|
|
59
|
+
* provider: '0xProvider123',
|
|
60
|
+
* amount: '100',
|
|
61
|
+
* deadline: '+7d',
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // Link escrow (auto-transitions to COMMITTED)
|
|
65
|
+
* await client.intermediate.linkEscrow(txId, '100');
|
|
66
|
+
*
|
|
67
|
+
* // Provider delivers
|
|
68
|
+
* await client.intermediate.transitionState(txId, 'DELIVERED');
|
|
69
|
+
*
|
|
70
|
+
* // Release funds after dispute window
|
|
71
|
+
* await client.intermediate.releaseEscrow(escrowId);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export class IntermediateAdapter extends BaseAdapter {
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new IntermediateAdapter instance.
|
|
77
|
+
*
|
|
78
|
+
* @param runtime - ACTP runtime implementation (MockRuntime or BlockchainRuntime)
|
|
79
|
+
* @param requesterAddress - The requester's Ethereum address
|
|
80
|
+
* @param easHelper - Optional EAS helper for attestation verification (SECURITY FIX C-4)
|
|
81
|
+
*/
|
|
82
|
+
constructor(
|
|
83
|
+
private runtime: IACTPRuntime,
|
|
84
|
+
requesterAddress: string,
|
|
85
|
+
private easHelper?: EASHelper
|
|
86
|
+
) {
|
|
87
|
+
super(requesterAddress);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Create a transaction (INITIATED state, no escrow yet).
|
|
92
|
+
*
|
|
93
|
+
* Unlike `beginner.pay()`, this only creates the transaction
|
|
94
|
+
* without linking escrow. You must call `linkEscrow()` separately.
|
|
95
|
+
*
|
|
96
|
+
* @param params - Transaction parameters
|
|
97
|
+
* @returns Transaction ID
|
|
98
|
+
* @throws {ValidationError} If inputs are invalid
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const txId = await adapter.createTransaction({
|
|
103
|
+
* provider: '0xProvider123',
|
|
104
|
+
* amount: '100',
|
|
105
|
+
* deadline: '+24h',
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
async createTransaction(params: IntermediateTransactionParams): Promise<string> {
|
|
110
|
+
const provider = this.validateAddress(params.provider, 'provider');
|
|
111
|
+
const amount = this.parseAmount(params.amount);
|
|
112
|
+
const currentTime = this.runtime.time.now();
|
|
113
|
+
const deadline = this.parseDeadline(params.deadline, currentTime);
|
|
114
|
+
// SECURITY FIX (L-1): Validate dispute window bounds
|
|
115
|
+
const disputeWindow = this.validateDisputeWindow(params.disputeWindow);
|
|
116
|
+
|
|
117
|
+
const requester = this.requesterAddress;
|
|
118
|
+
|
|
119
|
+
// Validation
|
|
120
|
+
if (requester.toLowerCase() === provider.toLowerCase()) {
|
|
121
|
+
throw new ValidationError('Cannot create transaction with yourself as provider');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (deadline <= currentTime) {
|
|
125
|
+
throw new ValidationError('Deadline must be in the future');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return this.runtime.createTransaction({
|
|
129
|
+
provider,
|
|
130
|
+
requester,
|
|
131
|
+
amount: amount.toString(),
|
|
132
|
+
deadline,
|
|
133
|
+
disputeWindow,
|
|
134
|
+
serviceDescription: params.serviceDescription,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Link escrow to a transaction.
|
|
140
|
+
*
|
|
141
|
+
* Automatically transitions INITIATED or QUOTED → COMMITTED.
|
|
142
|
+
* Deducts funds from requester and locks in escrow.
|
|
143
|
+
*
|
|
144
|
+
* @param txId - Transaction ID
|
|
145
|
+
* @returns Escrow ID
|
|
146
|
+
* @throws {Error} If transaction not found or in wrong state
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const escrowId = await adapter.linkEscrow(txId);
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
async linkEscrow(txId: string): Promise<string> {
|
|
154
|
+
const tx = await this.runtime.getTransaction(txId);
|
|
155
|
+
|
|
156
|
+
if (!tx) {
|
|
157
|
+
throw new Error(`Transaction ${txId} not found`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Use the transaction's amount (already in correct format)
|
|
161
|
+
return this.runtime.linkEscrow(txId, tx.amount);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Transition transaction to a new state.
|
|
166
|
+
*
|
|
167
|
+
* Validates the transition against the ACTP 8-state machine.
|
|
168
|
+
*
|
|
169
|
+
* Valid transitions:
|
|
170
|
+
* - INITIATED → QUOTED, COMMITTED, CANCELLED
|
|
171
|
+
* - QUOTED → COMMITTED, CANCELLED
|
|
172
|
+
* - COMMITTED → IN_PROGRESS, DELIVERED, CANCELLED
|
|
173
|
+
* - IN_PROGRESS → DELIVERED, CANCELLED
|
|
174
|
+
* - DELIVERED → SETTLED, DISPUTED
|
|
175
|
+
* - DISPUTED → SETTLED
|
|
176
|
+
*
|
|
177
|
+
* @param txId - Transaction ID
|
|
178
|
+
* @param newState - Target state
|
|
179
|
+
* @throws {Error} If transition is invalid
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* // Provider marks work as delivered
|
|
184
|
+
* await adapter.transitionState(txId, 'DELIVERED');
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
async transitionState(txId: string, newState: TransactionState): Promise<void> {
|
|
188
|
+
return this.runtime.transitionState(txId, newState);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Release escrow funds to the provider.
|
|
193
|
+
*
|
|
194
|
+
* Can only be called when transaction is in DELIVERED state
|
|
195
|
+
* and dispute window has expired.
|
|
196
|
+
*
|
|
197
|
+
* SECURITY FIX (C-4 + HIGH-5): MANDATORY attestation verification before release.
|
|
198
|
+
* When EASHelper is available (testnet/mainnet modes), attestation verification
|
|
199
|
+
* is REQUIRED - not optional. This prevents releasing funds without proper
|
|
200
|
+
* delivery proof.
|
|
201
|
+
*
|
|
202
|
+
* Verifications performed:
|
|
203
|
+
* - Attestation exists and is not revoked
|
|
204
|
+
* - Attestation belongs to this transaction (prevents replay attacks)
|
|
205
|
+
* - Attestation has not been used for a different transaction
|
|
206
|
+
*
|
|
207
|
+
* @param escrowId - Escrow ID
|
|
208
|
+
* @param attestationParams - Attestation verification params (REQUIRED when EASHelper available)
|
|
209
|
+
* @param attestationParams.txId - Transaction ID (bytes32)
|
|
210
|
+
* @param attestationParams.attestationUID - Attestation UID (bytes32)
|
|
211
|
+
* @throws {Error} If escrow not found or dispute window active
|
|
212
|
+
* @throws {Error} If EASHelper is available but attestationParams not provided (HIGH-5)
|
|
213
|
+
* @throws {Error} If attestation verification fails
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* // With attestation verification (REQUIRED in testnet/mainnet)
|
|
218
|
+
* await adapter.releaseEscrow(escrowId, {
|
|
219
|
+
* txId: '0x...',
|
|
220
|
+
* attestationUID: '0x...'
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* // Mock mode only (no attestation required)
|
|
224
|
+
* await adapter.releaseEscrow(escrowId);
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
async releaseEscrow(
|
|
228
|
+
escrowId: string,
|
|
229
|
+
attestationParams?: { txId: string; attestationUID: string }
|
|
230
|
+
): Promise<void> {
|
|
231
|
+
// Determine whether the underlying runtime requires attestation.
|
|
232
|
+
// BlockchainRuntime exposes isAttestationRequired(), but it's not part of the generic interface.
|
|
233
|
+
const runtimeAny = this.runtime as any;
|
|
234
|
+
const runtimeSupportsAttestationFlag =
|
|
235
|
+
typeof runtimeAny?.isAttestationRequired === 'function';
|
|
236
|
+
|
|
237
|
+
const attestationRequired: boolean = runtimeSupportsAttestationFlag
|
|
238
|
+
? Boolean(runtimeAny.isAttestationRequired())
|
|
239
|
+
: Boolean(this.easHelper);
|
|
240
|
+
|
|
241
|
+
if (attestationRequired && !attestationParams) {
|
|
242
|
+
throw new Error(
|
|
243
|
+
'Attestation verification is REQUIRED for escrow release. ' +
|
|
244
|
+
'Provide attestationParams: { txId: string, attestationUID: string }.'
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// If caller provided attestation params, ensure they match the escrow/tx being released.
|
|
249
|
+
if (attestationParams) {
|
|
250
|
+
// Support legacy escrowId format "escrow-{txId}-{timestamp}".
|
|
251
|
+
// Standard is escrowId === txId.
|
|
252
|
+
const legacyMatch = escrowId.match(/^escrow-(.+)-\d+$/);
|
|
253
|
+
const txIdFromEscrowId = legacyMatch ? legacyMatch[1] : escrowId;
|
|
254
|
+
|
|
255
|
+
if (txIdFromEscrowId.toLowerCase() !== attestationParams.txId.toLowerCase()) {
|
|
256
|
+
throw new Error(
|
|
257
|
+
`Attestation txId (${attestationParams.txId}) does not match escrow/txId (${txIdFromEscrowId}). ` +
|
|
258
|
+
`Refusing to release escrow with mismatched attestation.`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// If runtime does NOT handle attestation internally but EASHelper exists, verify here.
|
|
263
|
+
// Otherwise, pass attestationUID down so BlockchainRuntime can enforce/record.
|
|
264
|
+
if (!runtimeSupportsAttestationFlag && this.easHelper) {
|
|
265
|
+
await this.easHelper.verifyAndRecordForRelease(
|
|
266
|
+
attestationParams.txId,
|
|
267
|
+
attestationParams.attestationUID
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return this.runtime.releaseEscrow(
|
|
273
|
+
escrowId,
|
|
274
|
+
attestationParams?.attestationUID
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Get escrow balance.
|
|
280
|
+
*
|
|
281
|
+
* Returns formatted balance string (e.g., "100.00 USDC").
|
|
282
|
+
*
|
|
283
|
+
* @param escrowId - Escrow ID
|
|
284
|
+
* @returns Formatted balance
|
|
285
|
+
* @throws {Error} If escrow not found
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* const balance = await adapter.getEscrowBalance(escrowId);
|
|
290
|
+
* console.log(balance); // "100.00 USDC"
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
async getEscrowBalance(escrowId: string): Promise<string> {
|
|
294
|
+
const balance = await this.runtime.getEscrowBalance(escrowId);
|
|
295
|
+
return this.formatAmount(balance);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Get transaction details.
|
|
300
|
+
*
|
|
301
|
+
* Returns the full transaction object from the runtime.
|
|
302
|
+
*
|
|
303
|
+
* @param txId - Transaction ID
|
|
304
|
+
* @returns Transaction object or null if not found
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* const tx = await adapter.getTransaction(txId);
|
|
309
|
+
* console.log('State:', tx?.state);
|
|
310
|
+
* console.log('Amount:', tx?.amount);
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
async getTransaction(txId: string): Promise<MockTransaction | null> {
|
|
314
|
+
return this.runtime.getTransaction(txId);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter Layer - Bridges user-friendly API to protocol-level SDK
|
|
3
|
+
*
|
|
4
|
+
* This module exports all adapter classes and types for the Three-Level API:
|
|
5
|
+
* - BaseAdapter: Abstract base with shared utilities
|
|
6
|
+
* - BeginnerAdapter: High-level, opinionated API
|
|
7
|
+
* - IntermediateAdapter: Balanced control API
|
|
8
|
+
*
|
|
9
|
+
* @module adapters
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
BaseAdapter,
|
|
14
|
+
ValidationError,
|
|
15
|
+
DEFAULT_DISPUTE_WINDOW_SECONDS,
|
|
16
|
+
DEFAULT_DEADLINE_SECONDS,
|
|
17
|
+
MIN_AMOUNT_WEI,
|
|
18
|
+
MAX_DEADLINE_HOURS,
|
|
19
|
+
MAX_DEADLINE_DAYS,
|
|
20
|
+
} from './BaseAdapter';
|
|
21
|
+
export { BeginnerAdapter, BeginnerPayParams, BeginnerPayResult } from './BeginnerAdapter';
|
|
22
|
+
export { IntermediateAdapter, IntermediateTransactionParams } from './IntermediateAdapter';
|
|
23
|
+
|
|
24
|
+
// Re-export runtime interface for convenience
|
|
25
|
+
export { IACTPRuntime, CreateTransactionParams } from '../runtime/IACTPRuntime';
|
|
@@ -19,9 +19,10 @@ import { AIP4DeliveryProofTypes, AIP4DeliveryProofData, EIP712Domain } from '../
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* AGIRAILS Delivery Schema UID (Base Sepolia)
|
|
22
|
-
*
|
|
22
|
+
* Deployed 2025-11-23 - AIP-4 delivery proof schema
|
|
23
|
+
* Schema: bytes32 txId, string resultCID, bytes32 resultHash, uint256 deliveredAt
|
|
23
24
|
*/
|
|
24
|
-
export const AGIRAILS_DELIVERY_SCHEMA_UID = '
|
|
25
|
+
export const AGIRAILS_DELIVERY_SCHEMA_UID = '0x1b0ebdf0bd20c28ec9d5362571ce8715a55f46e81c3de2f9b0d8e1b95fb5ffce';
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Delivery proof build parameters
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Balance Command - Check USDC balance
|
|
3
|
+
*
|
|
4
|
+
* Shows the USDC balance for the current user or a specified address.
|
|
5
|
+
*
|
|
6
|
+
* @module cli/commands/balance
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Command } from 'commander';
|
|
10
|
+
import { Output, ExitCode } from '../utils/output';
|
|
11
|
+
import { createClient, mapError } from '../utils/client';
|
|
12
|
+
import { loadConfig } from '../utils/config';
|
|
13
|
+
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Command Definition
|
|
16
|
+
// ============================================================================
|
|
17
|
+
|
|
18
|
+
export function createBalanceCommand(): Command {
|
|
19
|
+
const cmd = new Command('balance')
|
|
20
|
+
.description('Check USDC balance')
|
|
21
|
+
.argument('[address]', 'Address to check (defaults to your address)')
|
|
22
|
+
.option('--json', 'Output as JSON')
|
|
23
|
+
.option('-q, --quiet', 'Output only the balance amount')
|
|
24
|
+
.action(async (address, options) => {
|
|
25
|
+
const output = new Output(
|
|
26
|
+
options.json ? 'json' : options.quiet ? 'quiet' : 'human'
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await runBalance(address, output);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
const structuredError = mapError(error);
|
|
33
|
+
output.errorResult({
|
|
34
|
+
code: structuredError.code,
|
|
35
|
+
message: structuredError.message,
|
|
36
|
+
details: structuredError.details,
|
|
37
|
+
});
|
|
38
|
+
process.exit(ExitCode.ERROR);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return cmd;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// Implementation
|
|
47
|
+
// ============================================================================
|
|
48
|
+
|
|
49
|
+
async function runBalance(
|
|
50
|
+
address: string | undefined,
|
|
51
|
+
output: Output
|
|
52
|
+
): Promise<void> {
|
|
53
|
+
// Load config to get default address
|
|
54
|
+
const config = loadConfig();
|
|
55
|
+
|
|
56
|
+
// Use specified address or default to config address
|
|
57
|
+
const targetAddress = address || config.address;
|
|
58
|
+
|
|
59
|
+
// Validate address format
|
|
60
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(targetAddress)) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Invalid address format: "${targetAddress}"\n` +
|
|
63
|
+
'Expected 0x-prefixed 40-character hex string.'
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Create client and get balance
|
|
68
|
+
const client = await createClient();
|
|
69
|
+
const balanceWei = await client.getBalance(targetAddress.toLowerCase());
|
|
70
|
+
|
|
71
|
+
// Format balance
|
|
72
|
+
const balanceFormatted = formatUsdc(balanceWei);
|
|
73
|
+
const isOwnAddress = targetAddress.toLowerCase() === config.address.toLowerCase();
|
|
74
|
+
|
|
75
|
+
output.result(
|
|
76
|
+
{
|
|
77
|
+
address: targetAddress,
|
|
78
|
+
balance: `${balanceFormatted} USDC`,
|
|
79
|
+
balanceWei,
|
|
80
|
+
isYou: isOwnAddress,
|
|
81
|
+
},
|
|
82
|
+
{ quietKey: 'balance' }
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Additional info in human mode
|
|
86
|
+
if (balanceWei === '0') {
|
|
87
|
+
output.blank();
|
|
88
|
+
output.warning('Balance is zero.');
|
|
89
|
+
if (config.mode === 'mock') {
|
|
90
|
+
output.print(' Mint tokens: actp mint ' + targetAddress + ' 1000');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Format USDC amount from wei to decimal with commas
|
|
97
|
+
*/
|
|
98
|
+
function formatUsdc(weiAmount: string): string {
|
|
99
|
+
const amount = BigInt(weiAmount);
|
|
100
|
+
const whole = amount / 1_000_000n;
|
|
101
|
+
const decimal = amount % 1_000_000n;
|
|
102
|
+
const decimalStr = decimal.toString().padStart(6, '0').slice(0, 2);
|
|
103
|
+
|
|
104
|
+
// Add thousands separators
|
|
105
|
+
const wholeFormatted = whole.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
106
|
+
|
|
107
|
+
return `${wholeFormatted}.${decimalStr}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { runBalance };
|