@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,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init Command - Initialize ACTP in the current directory
|
|
3
|
+
*
|
|
4
|
+
* Creates .actp/ directory with configuration and initial state.
|
|
5
|
+
* Supports interactive and non-interactive modes.
|
|
6
|
+
*
|
|
7
|
+
* @module cli/commands/init
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as crypto from 'crypto';
|
|
11
|
+
import { Command } from 'commander';
|
|
12
|
+
import {
|
|
13
|
+
saveConfig,
|
|
14
|
+
addToGitignore,
|
|
15
|
+
isInitialized,
|
|
16
|
+
getActpDir,
|
|
17
|
+
CLIConfig,
|
|
18
|
+
CLIMode,
|
|
19
|
+
} from '../utils/config';
|
|
20
|
+
import { Output, ExitCode } from '../utils/output';
|
|
21
|
+
import { MockStateManager } from '../../runtime/MockStateManager';
|
|
22
|
+
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Command Definition
|
|
25
|
+
// ============================================================================
|
|
26
|
+
|
|
27
|
+
export function createInitCommand(): Command {
|
|
28
|
+
const cmd = new Command('init')
|
|
29
|
+
.description('Initialize ACTP in the current directory')
|
|
30
|
+
.option('-m, --mode <mode>', 'Operating mode: mock, testnet, mainnet', 'mock')
|
|
31
|
+
.option('-a, --address <address>', 'Your Ethereum address')
|
|
32
|
+
.option('-f, --force', 'Overwrite existing configuration')
|
|
33
|
+
.option('--json', 'Output as JSON')
|
|
34
|
+
.option('-q, --quiet', 'Minimal output')
|
|
35
|
+
.action(async (options) => {
|
|
36
|
+
const output = new Output(
|
|
37
|
+
options.json ? 'json' : options.quiet ? 'quiet' : 'human'
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
await runInit(options, output);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
output.errorResult({
|
|
44
|
+
code: 'INIT_FAILED',
|
|
45
|
+
message: (error as Error).message,
|
|
46
|
+
});
|
|
47
|
+
process.exit(ExitCode.ERROR);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return cmd;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Implementation
|
|
56
|
+
// ============================================================================
|
|
57
|
+
|
|
58
|
+
interface InitOptions {
|
|
59
|
+
mode: string;
|
|
60
|
+
address?: string;
|
|
61
|
+
force?: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function runInit(options: InitOptions, output: Output): Promise<void> {
|
|
65
|
+
const projectRoot = process.cwd();
|
|
66
|
+
|
|
67
|
+
// Check if already initialized
|
|
68
|
+
if (isInitialized(projectRoot) && !options.force) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
'ACTP already initialized in this directory.\n' +
|
|
71
|
+
'Use --force to reinitialize.'
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Validate mode
|
|
76
|
+
const validModes: CLIMode[] = ['mock', 'testnet', 'mainnet'];
|
|
77
|
+
if (!validModes.includes(options.mode as CLIMode)) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`Invalid mode: "${options.mode}". Valid modes: ${validModes.join(', ')}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const mode = options.mode as CLIMode;
|
|
84
|
+
|
|
85
|
+
// Get or generate address
|
|
86
|
+
let address = options.address;
|
|
87
|
+
if (!address) {
|
|
88
|
+
if (mode === 'mock') {
|
|
89
|
+
// Generate a random address for mock mode
|
|
90
|
+
address = '0x' + crypto.randomBytes(20).toString('hex');
|
|
91
|
+
output.info(`Generated mock address: ${address}`);
|
|
92
|
+
} else {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Address required for ${mode} mode.\n` +
|
|
95
|
+
'Use --address <your-address> to specify.'
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Validate address format
|
|
101
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(address)) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`Invalid address format: "${address}"\n` +
|
|
104
|
+
'Expected 0x-prefixed 40-character hex string.'
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Create configuration
|
|
109
|
+
const config: CLIConfig = {
|
|
110
|
+
mode,
|
|
111
|
+
address: address.toLowerCase(),
|
|
112
|
+
version: '1.0',
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// Save configuration
|
|
116
|
+
saveConfig(config, projectRoot);
|
|
117
|
+
output.success('Configuration saved');
|
|
118
|
+
|
|
119
|
+
// Initialize mock state if in mock mode
|
|
120
|
+
if (mode === 'mock') {
|
|
121
|
+
const stateManager = new MockStateManager(projectRoot);
|
|
122
|
+
if (!stateManager.exists() || options.force) {
|
|
123
|
+
stateManager.reset();
|
|
124
|
+
output.success('Mock state initialized');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Mint initial tokens for the address
|
|
128
|
+
const { MockRuntime } = await import('../../runtime/MockRuntime');
|
|
129
|
+
const runtime = new MockRuntime(stateManager);
|
|
130
|
+
await runtime.mintTokens(address.toLowerCase(), '10000000000'); // 10,000 USDC
|
|
131
|
+
output.info('Minted 10,000 USDC to your address');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Add to gitignore
|
|
135
|
+
try {
|
|
136
|
+
addToGitignore(projectRoot);
|
|
137
|
+
output.success('Added .actp/ to .gitignore');
|
|
138
|
+
} catch {
|
|
139
|
+
output.warning('Could not update .gitignore (may not exist)');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Output result
|
|
143
|
+
output.blank();
|
|
144
|
+
output.result(
|
|
145
|
+
{
|
|
146
|
+
initialized: true,
|
|
147
|
+
directory: getActpDir(projectRoot),
|
|
148
|
+
mode,
|
|
149
|
+
address,
|
|
150
|
+
},
|
|
151
|
+
{ quietKey: 'address' }
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
output.blank();
|
|
155
|
+
output.print('Next steps:');
|
|
156
|
+
output.print(' 1. Create a payment: actp pay <provider> <amount>');
|
|
157
|
+
output.print(' 2. Check your balance: actp balance');
|
|
158
|
+
output.print(' 3. List transactions: actp tx list');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { runInit };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mint Command - Mint test USDC tokens (mock mode only)
|
|
3
|
+
*
|
|
4
|
+
* Useful for testing scenarios where you need to fund accounts.
|
|
5
|
+
*
|
|
6
|
+
* @module cli/commands/mint
|
|
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 createMintCommand(): Command {
|
|
19
|
+
const cmd = new Command('mint')
|
|
20
|
+
.description('Mint test USDC tokens (mock mode only)')
|
|
21
|
+
.argument('<address>', 'Address to mint tokens to')
|
|
22
|
+
.argument('<amount>', 'Amount to mint (in USDC, e.g., "1000")')
|
|
23
|
+
.option('--json', 'Output as JSON')
|
|
24
|
+
.option('-q, --quiet', 'Minimal output')
|
|
25
|
+
.action(async (address, amount, options) => {
|
|
26
|
+
const output = new Output(
|
|
27
|
+
options.json ? 'json' : options.quiet ? 'quiet' : 'human'
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
await runMint(address, amount, output);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
const structuredError = mapError(error);
|
|
34
|
+
output.errorResult({
|
|
35
|
+
code: structuredError.code,
|
|
36
|
+
message: structuredError.message,
|
|
37
|
+
details: structuredError.details,
|
|
38
|
+
});
|
|
39
|
+
process.exit(ExitCode.ERROR);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return cmd;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// Implementation
|
|
48
|
+
// ============================================================================
|
|
49
|
+
|
|
50
|
+
async function runMint(
|
|
51
|
+
address: string,
|
|
52
|
+
amount: string,
|
|
53
|
+
output: Output
|
|
54
|
+
): Promise<void> {
|
|
55
|
+
// Check we're in mock mode
|
|
56
|
+
const config = loadConfig();
|
|
57
|
+
if (config.mode !== 'mock') {
|
|
58
|
+
throw new Error(
|
|
59
|
+
'Mint command only available in mock mode.\n' +
|
|
60
|
+
'You cannot mint real USDC on testnet/mainnet.'
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Validate address format
|
|
65
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(address)) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Invalid address format: "${address}"\n` +
|
|
68
|
+
'Expected 0x-prefixed 40-character hex string.'
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Parse amount (user enters USDC, we convert to wei)
|
|
73
|
+
const amountNum = parseFloat(amount);
|
|
74
|
+
if (isNaN(amountNum) || amountNum <= 0) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Invalid amount: "${amount}"\n` +
|
|
77
|
+
'Expected positive number (e.g., "1000" for 1000 USDC).'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Convert to wei (USDC has 6 decimals)
|
|
82
|
+
const amountWei = Math.floor(amountNum * 1_000_000).toString();
|
|
83
|
+
|
|
84
|
+
// Create client and mint
|
|
85
|
+
const client = await createClient();
|
|
86
|
+
await client.mintTokens(address.toLowerCase(), amountWei);
|
|
87
|
+
|
|
88
|
+
// Get new balance
|
|
89
|
+
const newBalance = await client.getBalance(address.toLowerCase());
|
|
90
|
+
|
|
91
|
+
output.result(
|
|
92
|
+
{
|
|
93
|
+
address,
|
|
94
|
+
minted: `${amountNum} USDC`,
|
|
95
|
+
mintedWei: amountWei,
|
|
96
|
+
newBalance: `${formatUsdc(newBalance)} USDC`,
|
|
97
|
+
},
|
|
98
|
+
{ quietKey: 'newBalance' }
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
output.success(`Minted ${amountNum} USDC to ${address}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Format USDC amount from wei to decimal
|
|
106
|
+
*/
|
|
107
|
+
function formatUsdc(weiAmount: string): string {
|
|
108
|
+
const amount = BigInt(weiAmount);
|
|
109
|
+
const whole = amount / 1_000_000n;
|
|
110
|
+
const decimal = amount % 1_000_000n;
|
|
111
|
+
const decimalStr = decimal.toString().padStart(6, '0').slice(0, 2);
|
|
112
|
+
const wholeFormatted = whole.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
113
|
+
return `${wholeFormatted}.${decimalStr}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { runMint };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pay Command - One-liner payment command (beginner API)
|
|
3
|
+
*
|
|
4
|
+
* The simplest way to create a payment transaction.
|
|
5
|
+
* Creates transaction, links escrow, and returns immediately.
|
|
6
|
+
*
|
|
7
|
+
* @module cli/commands/pay
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from 'commander';
|
|
11
|
+
import { Output, ExitCode } from '../utils/output';
|
|
12
|
+
import { createClient, mapError } from '../utils/client';
|
|
13
|
+
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Command Definition
|
|
16
|
+
// ============================================================================
|
|
17
|
+
|
|
18
|
+
export function createPayCommand(): Command {
|
|
19
|
+
const cmd = new Command('pay')
|
|
20
|
+
.description('Create a payment transaction (simplest API)')
|
|
21
|
+
.argument('<to>', 'Provider address (recipient)')
|
|
22
|
+
.argument('<amount>', 'Amount to pay (e.g., "100", "100.50", "100 USDC")')
|
|
23
|
+
.option('-d, --deadline <deadline>', 'Deadline (+24h, +7d, or Unix timestamp)', '+24h')
|
|
24
|
+
.option('-w, --dispute-window <seconds>', 'Dispute window in seconds', '172800')
|
|
25
|
+
.option('--json', 'Output as JSON')
|
|
26
|
+
.option('-q, --quiet', 'Output only the transaction ID')
|
|
27
|
+
.action(async (to, amount, options) => {
|
|
28
|
+
const output = new Output(
|
|
29
|
+
options.json ? 'json' : options.quiet ? 'quiet' : 'human'
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
await runPay(to, amount, options, output);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const structuredError = mapError(error);
|
|
36
|
+
output.errorResult({
|
|
37
|
+
code: structuredError.code,
|
|
38
|
+
message: structuredError.message,
|
|
39
|
+
details: structuredError.details,
|
|
40
|
+
});
|
|
41
|
+
process.exit(ExitCode.ERROR);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return cmd;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// Implementation
|
|
50
|
+
// ============================================================================
|
|
51
|
+
|
|
52
|
+
interface PayOptions {
|
|
53
|
+
deadline: string;
|
|
54
|
+
disputeWindow: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function runPay(
|
|
58
|
+
to: string,
|
|
59
|
+
amount: string,
|
|
60
|
+
options: PayOptions,
|
|
61
|
+
output: Output
|
|
62
|
+
): Promise<void> {
|
|
63
|
+
// Create spinner for human mode
|
|
64
|
+
const spinner = output.spinner('Creating payment...');
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
// Create client
|
|
68
|
+
const client = await createClient();
|
|
69
|
+
|
|
70
|
+
// Parse options
|
|
71
|
+
let deadline: string | number = options.deadline;
|
|
72
|
+
if (/^\d+$/.test(options.deadline)) {
|
|
73
|
+
deadline = parseInt(options.deadline, 10);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const disputeWindow = parseInt(options.disputeWindow, 10);
|
|
77
|
+
|
|
78
|
+
// Create payment
|
|
79
|
+
const result = await client.beginner.pay({
|
|
80
|
+
to,
|
|
81
|
+
amount,
|
|
82
|
+
deadline,
|
|
83
|
+
disputeWindow,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
spinner.stop(true);
|
|
87
|
+
|
|
88
|
+
// Output result
|
|
89
|
+
output.result(
|
|
90
|
+
{
|
|
91
|
+
txId: result.txId,
|
|
92
|
+
state: result.state,
|
|
93
|
+
provider: result.provider,
|
|
94
|
+
requester: result.requester,
|
|
95
|
+
amount: result.amount,
|
|
96
|
+
deadline: result.deadline,
|
|
97
|
+
},
|
|
98
|
+
{ quietKey: 'txId' }
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
output.blank();
|
|
102
|
+
output.success('Payment created and funded!');
|
|
103
|
+
output.print('');
|
|
104
|
+
output.print('Next steps:');
|
|
105
|
+
output.print(' - Provider delivers: actp tx deliver ' + result.txId.slice(0, 10) + '...');
|
|
106
|
+
output.print(' - Check status: actp tx status ' + result.txId.slice(0, 10) + '...');
|
|
107
|
+
} catch (error) {
|
|
108
|
+
spinner.stop(false);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { runPay };
|