@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
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuoteBuilder - AIP-2 Price Quote Construction
|
|
3
|
+
* Reference: AIP-2 §6.1
|
|
4
|
+
*
|
|
5
|
+
* Builds price quotes with:
|
|
6
|
+
* - Amount validation (≥ originalAmount, ≤ maxPrice)
|
|
7
|
+
* - EIP-712 signature
|
|
8
|
+
* - Canonical JSON hashing
|
|
9
|
+
* - Optional IPFS upload
|
|
10
|
+
*/
|
|
1
11
|
import { Signer } from 'ethers';
|
|
2
12
|
import { IPFSClient } from '../utils/IPFSClient';
|
|
3
13
|
import { NonceManager } from '../utils/NonceManager';
|
|
14
|
+
/**
|
|
15
|
+
* Quote message interface (AIP-2)
|
|
16
|
+
* Reference: AIP-2 §2.1
|
|
17
|
+
*/
|
|
4
18
|
export interface QuoteMessage {
|
|
5
19
|
type: 'agirails.quote.v1';
|
|
6
20
|
version: '1.0.0';
|
|
@@ -24,6 +38,10 @@ export interface QuoteMessage {
|
|
|
24
38
|
nonce: number;
|
|
25
39
|
signature: string;
|
|
26
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Quote build parameters
|
|
43
|
+
* Reference: AIP-2 §6.1
|
|
44
|
+
*/
|
|
27
45
|
export interface QuoteParams {
|
|
28
46
|
txId: string;
|
|
29
47
|
provider: string;
|
|
@@ -43,26 +61,109 @@ export interface QuoteParams {
|
|
|
43
61
|
chainId: number;
|
|
44
62
|
kernelAddress: string;
|
|
45
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* EIP-712 types for AIP-2 quote messages
|
|
66
|
+
* Reference: AIP-2 §3.1
|
|
67
|
+
*/
|
|
46
68
|
export declare const AIP2QuoteTypes: {
|
|
47
69
|
PriceQuote: {
|
|
48
70
|
name: string;
|
|
49
71
|
type: string;
|
|
50
72
|
}[];
|
|
51
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* QuoteBuilder - Main Builder Class
|
|
76
|
+
* Reference: AIP-2 §6.1
|
|
77
|
+
*/
|
|
52
78
|
export declare class QuoteBuilder {
|
|
53
79
|
private signer;
|
|
54
80
|
private nonceManager;
|
|
55
81
|
private ipfs?;
|
|
56
82
|
constructor(signer: Signer, nonceManager: NonceManager, ipfs?: IPFSClient | undefined);
|
|
83
|
+
/**
|
|
84
|
+
* Build and sign a quote message
|
|
85
|
+
* Reference: AIP-2 §4.1 (Provider workflow)
|
|
86
|
+
*
|
|
87
|
+
* @param params - Quote parameters
|
|
88
|
+
* @returns Signed quote message
|
|
89
|
+
*/
|
|
57
90
|
build(params: QuoteParams): Promise<QuoteMessage>;
|
|
91
|
+
/**
|
|
92
|
+
* Verify quote signature and business rules
|
|
93
|
+
* Reference: AIP-2 §5.2, §5.3
|
|
94
|
+
*
|
|
95
|
+
* @param quote - Quote message to verify
|
|
96
|
+
* @param kernelAddress - ACTPKernel contract address
|
|
97
|
+
* @returns true if valid, throws error otherwise
|
|
98
|
+
*/
|
|
58
99
|
verify(quote: QuoteMessage, kernelAddress: string): Promise<boolean>;
|
|
100
|
+
/**
|
|
101
|
+
* Upload quote to IPFS and return CID
|
|
102
|
+
* Reference: AIP-2 §6 (optional IPFS storage)
|
|
103
|
+
*
|
|
104
|
+
* @param quote - Quote message
|
|
105
|
+
* @returns IPFS CID
|
|
106
|
+
*/
|
|
59
107
|
uploadToIPFS(quote: QuoteMessage): Promise<string>;
|
|
108
|
+
/**
|
|
109
|
+
* Compute quote hash (canonical JSON + keccak256)
|
|
110
|
+
* Used for on-chain storage in transaction metadata
|
|
111
|
+
* Reference: AIP-2 §4.1 (Step 6)
|
|
112
|
+
*
|
|
113
|
+
* @param quote - Quote message
|
|
114
|
+
* @returns Keccak256 hash (0x-prefixed)
|
|
115
|
+
*/
|
|
60
116
|
computeHash(quote: QuoteMessage): string;
|
|
117
|
+
/**
|
|
118
|
+
* Sign quote message with EIP-712
|
|
119
|
+
* Reference: AIP-2 §3.1, §3.2
|
|
120
|
+
*
|
|
121
|
+
* @param quote - Quote message (unsigned)
|
|
122
|
+
* @param kernelAddress - ACTPKernel contract address
|
|
123
|
+
* @returns EIP-712 signature (0x-prefixed, 130 chars)
|
|
124
|
+
*/
|
|
61
125
|
private signQuote;
|
|
126
|
+
/**
|
|
127
|
+
* Recover signer address from quote signature
|
|
128
|
+
* Reference: AIP-2 §5.3
|
|
129
|
+
*
|
|
130
|
+
* @param quote - Quote message
|
|
131
|
+
* @param kernelAddress - ACTPKernel contract address
|
|
132
|
+
* @returns Recovered Ethereum address
|
|
133
|
+
*/
|
|
62
134
|
private recoverQuoteSigner;
|
|
135
|
+
/**
|
|
136
|
+
* Compute justification hash for EIP-712 signature
|
|
137
|
+
* Reference: AIP-2 §3.2
|
|
138
|
+
*
|
|
139
|
+
* @param justification - Optional justification object
|
|
140
|
+
* @returns Keccak256 hash (0x-prefixed), or zero hash if omitted
|
|
141
|
+
*/
|
|
63
142
|
private computeJustificationHash;
|
|
143
|
+
/**
|
|
144
|
+
* Validate quote parameters
|
|
145
|
+
* Reference: AIP-2 §5.1, §5.2
|
|
146
|
+
*
|
|
147
|
+
* @param params - Quote parameters
|
|
148
|
+
* @throws Error if validation fails
|
|
149
|
+
*/
|
|
64
150
|
private validateParams;
|
|
151
|
+
/**
|
|
152
|
+
* Validate quote message schema
|
|
153
|
+
* Reference: AIP-2 §2.1, §5.1
|
|
154
|
+
*
|
|
155
|
+
* @param quote - Quote message
|
|
156
|
+
* @throws Error if validation fails
|
|
157
|
+
*/
|
|
65
158
|
private validateQuoteSchema;
|
|
159
|
+
/**
|
|
160
|
+
* Extract Ethereum address from DID
|
|
161
|
+
* Supports: did:ethr:0x... and did:ethr:84532:0x...
|
|
162
|
+
* Reference: AIP-0 §2.1 (DID format)
|
|
163
|
+
*
|
|
164
|
+
* @param did - DID string
|
|
165
|
+
* @returns Ethereum address (0x-prefixed)
|
|
166
|
+
*/
|
|
66
167
|
private extractAddressFromDID;
|
|
67
168
|
}
|
|
68
169
|
//# sourceMappingURL=QuoteBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteBuilder.d.ts","sourceRoot":"","sources":["../../src/builders/QuoteBuilder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QuoteBuilder.d.ts","sourceRoot":"","sources":["../../src/builders/QuoteBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAA2C,MAAM,QAAQ,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,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;CACvB;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;;CAgB1B,CAAC;AAEF;;;GAGG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,IAAI,CAAC;gBAFL,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,EAC1B,IAAI,CAAC,wBAAY;IAG3B;;;;;;OAMG;IACG,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IA8CvD;;;;;;;OAOG;IACG,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA4C1E;;;;;;OAMG;IACG,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAUxD;;;;;;;OAOG;IACH,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM;IAMxC;;;;;;;OAOG;YACW,SAAS;IAoCvB;;;;;;;OAOG;IACH,OAAO,CAAC,kBAAkB;IAwC1B;;;;;;OAMG;IACH,OAAO,CAAC,wBAAwB;IAQhC;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IAsDtB;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;IAkD3B;;;;;;;OAOG;IACH,OAAO,CAAC,qBAAqB;CAU9B"}
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* QuoteBuilder - AIP-2 Price Quote Construction
|
|
4
|
+
* Reference: AIP-2 §6.1
|
|
5
|
+
*
|
|
6
|
+
* Builds price quotes with:
|
|
7
|
+
* - Amount validation (≥ originalAmount, ≤ maxPrice)
|
|
8
|
+
* - EIP-712 signature
|
|
9
|
+
* - Canonical JSON hashing
|
|
10
|
+
* - Optional IPFS upload
|
|
11
|
+
*/
|
|
2
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
13
|
exports.QuoteBuilder = exports.AIP2QuoteTypes = void 0;
|
|
4
14
|
const ethers_1 = require("ethers");
|
|
5
15
|
const canonicalJson_1 = require("../utils/canonicalJson");
|
|
6
16
|
const errors_1 = require("../errors");
|
|
17
|
+
/**
|
|
18
|
+
* EIP-712 types for AIP-2 quote messages
|
|
19
|
+
* Reference: AIP-2 §3.1
|
|
20
|
+
*/
|
|
7
21
|
exports.AIP2QuoteTypes = {
|
|
8
22
|
PriceQuote: [
|
|
9
23
|
{ name: 'txId', type: 'bytes32' },
|
|
@@ -21,22 +35,36 @@ exports.AIP2QuoteTypes = {
|
|
|
21
35
|
{ name: 'nonce', type: 'uint256' }
|
|
22
36
|
]
|
|
23
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* QuoteBuilder - Main Builder Class
|
|
40
|
+
* Reference: AIP-2 §6.1
|
|
41
|
+
*/
|
|
24
42
|
class QuoteBuilder {
|
|
25
43
|
constructor(signer, nonceManager, ipfs) {
|
|
26
44
|
this.signer = signer;
|
|
27
45
|
this.nonceManager = nonceManager;
|
|
28
46
|
this.ipfs = ipfs;
|
|
29
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Build and sign a quote message
|
|
50
|
+
* Reference: AIP-2 §4.1 (Provider workflow)
|
|
51
|
+
*
|
|
52
|
+
* @param params - Quote parameters
|
|
53
|
+
* @returns Signed quote message
|
|
54
|
+
*/
|
|
30
55
|
async build(params) {
|
|
56
|
+
// Validate parameters
|
|
31
57
|
this.validateParams(params);
|
|
32
58
|
const quotedAt = Math.floor(Date.now() / 1000);
|
|
33
|
-
const expiresAt = params.expiresAt || (quotedAt + 3600);
|
|
59
|
+
const expiresAt = params.expiresAt || (quotedAt + 3600); // Default 1 hour
|
|
60
|
+
// Validate expiry
|
|
34
61
|
if (expiresAt <= quotedAt) {
|
|
35
62
|
throw new Error('expiresAt must be after quotedAt');
|
|
36
63
|
}
|
|
37
64
|
if (expiresAt > quotedAt + 86400) {
|
|
38
65
|
throw new Error('expiresAt cannot exceed 24 hours from quotedAt');
|
|
39
66
|
}
|
|
67
|
+
// Construct quote message (unsigned)
|
|
40
68
|
const quote = {
|
|
41
69
|
type: 'agirails.quote.v1',
|
|
42
70
|
version: '1.0.0',
|
|
@@ -53,20 +81,33 @@ class QuoteBuilder {
|
|
|
53
81
|
justification: params.justification,
|
|
54
82
|
chainId: params.chainId,
|
|
55
83
|
nonce: this.nonceManager.getNextNonce('agirails.quote.v1'),
|
|
56
|
-
signature: ''
|
|
84
|
+
signature: '' // Filled in next step
|
|
57
85
|
};
|
|
86
|
+
// Sign with EIP-712
|
|
58
87
|
const signature = await this.signQuote(quote, params.kernelAddress);
|
|
59
88
|
quote.signature = signature;
|
|
89
|
+
// Record nonce usage
|
|
60
90
|
this.nonceManager.recordNonce('agirails.quote.v1', quote.nonce);
|
|
61
91
|
return quote;
|
|
62
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Verify quote signature and business rules
|
|
95
|
+
* Reference: AIP-2 §5.2, §5.3
|
|
96
|
+
*
|
|
97
|
+
* @param quote - Quote message to verify
|
|
98
|
+
* @param kernelAddress - ACTPKernel contract address
|
|
99
|
+
* @returns true if valid, throws error otherwise
|
|
100
|
+
*/
|
|
63
101
|
async verify(quote, kernelAddress) {
|
|
102
|
+
// 1. Validate schema
|
|
64
103
|
this.validateQuoteSchema(quote);
|
|
104
|
+
// 2. Verify signature
|
|
65
105
|
const recoveredAddress = this.recoverQuoteSigner(quote, kernelAddress);
|
|
66
106
|
const expectedAddress = this.extractAddressFromDID(quote.provider);
|
|
67
107
|
if (recoveredAddress.toLowerCase() !== expectedAddress.toLowerCase()) {
|
|
68
108
|
throw new Error('Invalid signature: recovered address does not match provider');
|
|
69
109
|
}
|
|
110
|
+
// 3. Validate business rules
|
|
70
111
|
const quotedAmount = BigInt(quote.quotedAmount);
|
|
71
112
|
const originalAmount = BigInt(quote.originalAmount);
|
|
72
113
|
const maxPrice = BigInt(quote.maxPrice);
|
|
@@ -76,30 +117,57 @@ class QuoteBuilder {
|
|
|
76
117
|
if (quotedAmount > maxPrice) {
|
|
77
118
|
throw new Error('Quoted amount exceeds maxPrice');
|
|
78
119
|
}
|
|
120
|
+
// Platform minimum: $0.05 = 50000 base units (6 decimals)
|
|
79
121
|
if (quotedAmount < 50000n) {
|
|
80
122
|
throw new Error('Quoted amount below platform minimum ($0.05)');
|
|
81
123
|
}
|
|
124
|
+
// 4. Check expiry
|
|
82
125
|
const now = Math.floor(Date.now() / 1000);
|
|
83
126
|
if (quote.expiresAt < now) {
|
|
84
127
|
throw new Error('Quote expired');
|
|
85
128
|
}
|
|
129
|
+
// 5. Timestamp freshness check
|
|
86
130
|
if (Math.abs(now - quote.quotedAt) > 300) {
|
|
87
131
|
throw new Error('Quote timestamp outside 5-minute tolerance');
|
|
88
132
|
}
|
|
89
133
|
return true;
|
|
90
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Upload quote to IPFS and return CID
|
|
137
|
+
* Reference: AIP-2 §6 (optional IPFS storage)
|
|
138
|
+
*
|
|
139
|
+
* @param quote - Quote message
|
|
140
|
+
* @returns IPFS CID
|
|
141
|
+
*/
|
|
91
142
|
async uploadToIPFS(quote) {
|
|
92
143
|
if (!this.ipfs) {
|
|
93
144
|
throw new Error('IPFS client not configured');
|
|
94
145
|
}
|
|
95
146
|
const cid = await this.ipfs.add(JSON.stringify(quote));
|
|
96
|
-
await this.ipfs.pin(cid);
|
|
147
|
+
await this.ipfs.pin(cid); // Pin for dispute window
|
|
97
148
|
return cid;
|
|
98
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Compute quote hash (canonical JSON + keccak256)
|
|
152
|
+
* Used for on-chain storage in transaction metadata
|
|
153
|
+
* Reference: AIP-2 §4.1 (Step 6)
|
|
154
|
+
*
|
|
155
|
+
* @param quote - Quote message
|
|
156
|
+
* @returns Keccak256 hash (0x-prefixed)
|
|
157
|
+
*/
|
|
99
158
|
computeHash(quote) {
|
|
159
|
+
// Remove signature field for hashing
|
|
100
160
|
const { signature, ...quoteWithoutSig } = quote;
|
|
101
161
|
return (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)((0, canonicalJson_1.canonicalJsonStringify)(quoteWithoutSig)));
|
|
102
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Sign quote message with EIP-712
|
|
165
|
+
* Reference: AIP-2 §3.1, §3.2
|
|
166
|
+
*
|
|
167
|
+
* @param quote - Quote message (unsigned)
|
|
168
|
+
* @param kernelAddress - ACTPKernel contract address
|
|
169
|
+
* @returns EIP-712 signature (0x-prefixed, 130 chars)
|
|
170
|
+
*/
|
|
103
171
|
async signQuote(quote, kernelAddress) {
|
|
104
172
|
const domain = {
|
|
105
173
|
name: 'AGIRAILS',
|
|
@@ -107,6 +175,7 @@ class QuoteBuilder {
|
|
|
107
175
|
chainId: quote.chainId,
|
|
108
176
|
verifyingContract: kernelAddress
|
|
109
177
|
};
|
|
178
|
+
// Compute justification hash
|
|
110
179
|
const justificationHash = this.computeJustificationHash(quote.justification);
|
|
111
180
|
const message = {
|
|
112
181
|
txId: quote.txId,
|
|
@@ -123,12 +192,21 @@ class QuoteBuilder {
|
|
|
123
192
|
chainId: quote.chainId,
|
|
124
193
|
nonce: quote.nonce
|
|
125
194
|
};
|
|
195
|
+
// Sign using ethers.js signTypedData (v6 API)
|
|
126
196
|
if ('signTypedData' in this.signer && typeof this.signer.signTypedData === 'function') {
|
|
127
197
|
const signature = await this.signer.signTypedData(domain, exports.AIP2QuoteTypes, message);
|
|
128
198
|
return signature;
|
|
129
199
|
}
|
|
130
200
|
throw new Error('Signer does not support EIP-712 typed data signing');
|
|
131
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Recover signer address from quote signature
|
|
204
|
+
* Reference: AIP-2 §5.3
|
|
205
|
+
*
|
|
206
|
+
* @param quote - Quote message
|
|
207
|
+
* @param kernelAddress - ACTPKernel contract address
|
|
208
|
+
* @returns Recovered Ethereum address
|
|
209
|
+
*/
|
|
132
210
|
recoverQuoteSigner(quote, kernelAddress) {
|
|
133
211
|
const domain = {
|
|
134
212
|
name: 'AGIRAILS',
|
|
@@ -152,21 +230,39 @@ class QuoteBuilder {
|
|
|
152
230
|
chainId: quote.chainId,
|
|
153
231
|
nonce: quote.nonce
|
|
154
232
|
};
|
|
233
|
+
// Recover address using ethers.js verifyTypedData
|
|
234
|
+
// Wrap in try-catch to handle low-level cryptographic errors gracefully
|
|
155
235
|
try {
|
|
156
236
|
const recoveredAddress = (0, ethers_1.verifyTypedData)(domain, exports.AIP2QuoteTypes, message, quote.signature);
|
|
157
237
|
return recoveredAddress;
|
|
158
238
|
}
|
|
159
239
|
catch (error) {
|
|
240
|
+
// Wrap low-level cryptographic errors in SignatureVerificationError
|
|
160
241
|
throw new errors_1.SignatureVerificationError(quote.provider, 'unknown');
|
|
161
242
|
}
|
|
162
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Compute justification hash for EIP-712 signature
|
|
246
|
+
* Reference: AIP-2 §3.2
|
|
247
|
+
*
|
|
248
|
+
* @param justification - Optional justification object
|
|
249
|
+
* @returns Keccak256 hash (0x-prefixed), or zero hash if omitted
|
|
250
|
+
*/
|
|
163
251
|
computeJustificationHash(justification) {
|
|
164
252
|
if (!justification || Object.keys(justification).length === 0) {
|
|
165
253
|
return '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
166
254
|
}
|
|
167
255
|
return (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)((0, canonicalJson_1.canonicalJsonStringify)(justification)));
|
|
168
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Validate quote parameters
|
|
259
|
+
* Reference: AIP-2 §5.1, §5.2
|
|
260
|
+
*
|
|
261
|
+
* @param params - Quote parameters
|
|
262
|
+
* @throws Error if validation fails
|
|
263
|
+
*/
|
|
169
264
|
validateParams(params) {
|
|
265
|
+
// Amount validation
|
|
170
266
|
const quotedAmount = BigInt(params.quotedAmount);
|
|
171
267
|
const originalAmount = BigInt(params.originalAmount);
|
|
172
268
|
const maxPrice = BigInt(params.maxPrice);
|
|
@@ -176,9 +272,11 @@ class QuoteBuilder {
|
|
|
176
272
|
if (quotedAmount > maxPrice) {
|
|
177
273
|
throw new Error('quotedAmount must be <= maxPrice');
|
|
178
274
|
}
|
|
275
|
+
// Platform minimum: $0.05 = 50000 base units (6 decimals)
|
|
179
276
|
if (quotedAmount < 50000n) {
|
|
180
277
|
throw new Error('quotedAmount must be >= $0.05 (50000 base units)');
|
|
181
278
|
}
|
|
279
|
+
// Expiry validation
|
|
182
280
|
if (params.expiresAt) {
|
|
183
281
|
const now = Math.floor(Date.now() / 1000);
|
|
184
282
|
if (params.expiresAt <= now) {
|
|
@@ -188,22 +286,33 @@ class QuoteBuilder {
|
|
|
188
286
|
throw new Error('expiresAt cannot be more than 24 hours in future');
|
|
189
287
|
}
|
|
190
288
|
}
|
|
289
|
+
// DID format validation
|
|
191
290
|
if (!params.provider.startsWith('did:ethr:')) {
|
|
192
291
|
throw new Error('provider must be valid did:ethr format');
|
|
193
292
|
}
|
|
194
293
|
if (!params.consumer.startsWith('did:ethr:')) {
|
|
195
294
|
throw new Error('consumer must be valid did:ethr format');
|
|
196
295
|
}
|
|
296
|
+
// Transaction ID format
|
|
197
297
|
if (!/^0x[a-fA-F0-9]{64}$/.test(params.txId)) {
|
|
198
298
|
throw new Error('txId must be valid bytes32 hex string');
|
|
199
299
|
}
|
|
300
|
+
// Kernel address format
|
|
200
301
|
if (!/^0x[a-fA-F0-9]{40}$/.test(params.kernelAddress)) {
|
|
201
302
|
throw new Error('kernelAddress must be valid Ethereum address');
|
|
202
303
|
}
|
|
304
|
+
// ChainId validation
|
|
203
305
|
if (params.chainId !== 84532 && params.chainId !== 8453) {
|
|
204
306
|
throw new Error('chainId must be 84532 (Base Sepolia) or 8453 (Base Mainnet)');
|
|
205
307
|
}
|
|
206
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Validate quote message schema
|
|
311
|
+
* Reference: AIP-2 §2.1, §5.1
|
|
312
|
+
*
|
|
313
|
+
* @param quote - Quote message
|
|
314
|
+
* @throws Error if validation fails
|
|
315
|
+
*/
|
|
207
316
|
validateQuoteSchema(quote) {
|
|
208
317
|
if (quote.type !== 'agirails.quote.v1') {
|
|
209
318
|
throw new Error('Invalid message type');
|
|
@@ -242,6 +351,14 @@ class QuoteBuilder {
|
|
|
242
351
|
throw new Error('Invalid signature format');
|
|
243
352
|
}
|
|
244
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Extract Ethereum address from DID
|
|
356
|
+
* Supports: did:ethr:0x... and did:ethr:84532:0x...
|
|
357
|
+
* Reference: AIP-0 §2.1 (DID format)
|
|
358
|
+
*
|
|
359
|
+
* @param did - DID string
|
|
360
|
+
* @returns Ethereum address (0x-prefixed)
|
|
361
|
+
*/
|
|
245
362
|
extractAddressFromDID(did) {
|
|
246
363
|
const parts = did.replace('did:ethr:', '').split(':');
|
|
247
364
|
const address = parts.length === 2 ? parts[1] : parts[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteBuilder.js","sourceRoot":"","sources":["../../src/builders/QuoteBuilder.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"QuoteBuilder.js","sourceRoot":"","sources":["../../src/builders/QuoteBuilder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,mCAAyE;AACzE,0DAAgE;AAIhE,sCAAuD;AAsDvD;;;GAGG;AACU,QAAA,cAAc,GAAG;IAC5B,UAAU,EAAE;QACV,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;QACjC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE;QACpC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE;QACpC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE;QACxC,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC1C,EAA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,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QAED,IAAI,KAAK,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACrC,CAAC;QAED,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,qBAAqB,CAAC,GAAW;QACvC,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACtD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAEzD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAlYD,oCAkYC"}
|
package/dist/builders/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACTP SDK Builders
|
|
3
|
+
* High-level builder classes for constructing ACTP messages
|
|
4
|
+
*/
|
|
1
5
|
export { DeliveryProofBuilder, DeliveryProofParams, AGIRAILS_DELIVERY_SCHEMA_UID } from './DeliveryProofBuilder';
|
|
2
6
|
export { QuoteBuilder, QuoteParams, QuoteMessage, AIP2QuoteTypes } from './QuoteBuilder';
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/builders/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/builders/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,4BAA4B,EAC7B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,cAAc,EACf,MAAM,gBAAgB,CAAC"}
|
package/dist/builders/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ACTP SDK Builders
|
|
4
|
+
* High-level builder classes for constructing ACTP messages
|
|
5
|
+
*/
|
|
2
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
7
|
exports.AIP2QuoteTypes = exports.QuoteBuilder = exports.AGIRAILS_DELIVERY_SCHEMA_UID = exports.DeliveryProofBuilder = void 0;
|
|
4
8
|
var DeliveryProofBuilder_1 = require("./DeliveryProofBuilder");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/builders/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/builders/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAIgC;AAH9B,4HAAA,oBAAoB,OAAA;AAEpB,oIAAA,4BAA4B,OAAA;AAG9B,+CAKwB;AAJtB,4GAAA,YAAY,OAAA;AAGZ,8GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import { Command } from 'commander';
|
|
9
|
+
import { Output } from '../utils/output';
|
|
10
|
+
export declare function createBalanceCommand(): Command;
|
|
11
|
+
declare function runBalance(address: string | undefined, output: Output): Promise<void>;
|
|
12
|
+
export { runBalance };
|
|
13
|
+
//# sourceMappingURL=balance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/balance.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAY,MAAM,iBAAiB,CAAC;AAQnD,wBAAgB,oBAAoB,IAAI,OAAO,CAyB9C;AAMD,iBAAe,UAAU,CACvB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAyCf;AAiBD,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Balance Command - Check USDC balance
|
|
4
|
+
*
|
|
5
|
+
* Shows the USDC balance for the current user or a specified address.
|
|
6
|
+
*
|
|
7
|
+
* @module cli/commands/balance
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.runBalance = exports.createBalanceCommand = void 0;
|
|
11
|
+
const commander_1 = require("commander");
|
|
12
|
+
const output_1 = require("../utils/output");
|
|
13
|
+
const client_1 = require("../utils/client");
|
|
14
|
+
const config_1 = require("../utils/config");
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Command Definition
|
|
17
|
+
// ============================================================================
|
|
18
|
+
function createBalanceCommand() {
|
|
19
|
+
const cmd = new commander_1.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_1.Output(options.json ? 'json' : options.quiet ? 'quiet' : 'human');
|
|
26
|
+
try {
|
|
27
|
+
await runBalance(address, output);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const structuredError = (0, client_1.mapError)(error);
|
|
31
|
+
output.errorResult({
|
|
32
|
+
code: structuredError.code,
|
|
33
|
+
message: structuredError.message,
|
|
34
|
+
details: structuredError.details,
|
|
35
|
+
});
|
|
36
|
+
process.exit(output_1.ExitCode.ERROR);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return cmd;
|
|
40
|
+
}
|
|
41
|
+
exports.createBalanceCommand = createBalanceCommand;
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// Implementation
|
|
44
|
+
// ============================================================================
|
|
45
|
+
async function runBalance(address, output) {
|
|
46
|
+
// Load config to get default address
|
|
47
|
+
const config = (0, config_1.loadConfig)();
|
|
48
|
+
// Use specified address or default to config address
|
|
49
|
+
const targetAddress = address || config.address;
|
|
50
|
+
// Validate address format
|
|
51
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(targetAddress)) {
|
|
52
|
+
throw new Error(`Invalid address format: "${targetAddress}"\n` +
|
|
53
|
+
'Expected 0x-prefixed 40-character hex string.');
|
|
54
|
+
}
|
|
55
|
+
// Create client and get balance
|
|
56
|
+
const client = await (0, client_1.createClient)();
|
|
57
|
+
const balanceWei = await client.getBalance(targetAddress.toLowerCase());
|
|
58
|
+
// Format balance
|
|
59
|
+
const balanceFormatted = formatUsdc(balanceWei);
|
|
60
|
+
const isOwnAddress = targetAddress.toLowerCase() === config.address.toLowerCase();
|
|
61
|
+
output.result({
|
|
62
|
+
address: targetAddress,
|
|
63
|
+
balance: `${balanceFormatted} USDC`,
|
|
64
|
+
balanceWei,
|
|
65
|
+
isYou: isOwnAddress,
|
|
66
|
+
}, { quietKey: 'balance' });
|
|
67
|
+
// Additional info in human mode
|
|
68
|
+
if (balanceWei === '0') {
|
|
69
|
+
output.blank();
|
|
70
|
+
output.warning('Balance is zero.');
|
|
71
|
+
if (config.mode === 'mock') {
|
|
72
|
+
output.print(' Mint tokens: actp mint ' + targetAddress + ' 1000');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.runBalance = runBalance;
|
|
77
|
+
/**
|
|
78
|
+
* Format USDC amount from wei to decimal with commas
|
|
79
|
+
*/
|
|
80
|
+
function formatUsdc(weiAmount) {
|
|
81
|
+
const amount = BigInt(weiAmount);
|
|
82
|
+
const whole = amount / 1000000n;
|
|
83
|
+
const decimal = amount % 1000000n;
|
|
84
|
+
const decimalStr = decimal.toString().padStart(6, '0').slice(0, 2);
|
|
85
|
+
// Add thousands separators
|
|
86
|
+
const wholeFormatted = whole.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
87
|
+
return `${wholeFormatted}.${decimalStr}`;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=balance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.js","sourceRoot":"","sources":["../../../src/cli/commands/balance.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,yCAAoC;AACpC,4CAAmD;AACnD,4CAAyD;AACzD,4CAA6C;AAE7C,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,SAAgB,oBAAoB;IAClC,MAAM,GAAG,GAAG,IAAI,mBAAO,CAAC,SAAS,CAAC;SAC/B,WAAW,CAAC,oBAAoB,CAAC;SACjC,QAAQ,CAAC,WAAW,EAAE,6CAA6C,CAAC;SACpE,MAAM,CAAC,QAAQ,EAAE,gBA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CAAC;IAE9E,OAAO,GAAG,cAAc,IAAI,UAAU,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch Command - Execute multiple commands from a file
|
|
3
|
+
*
|
|
4
|
+
* Agent-first feature: Process commands in bulk.
|
|
5
|
+
* Perfect for:
|
|
6
|
+
* - Scripted workflows
|
|
7
|
+
* - Replaying transaction sequences
|
|
8
|
+
* - Automated testing
|
|
9
|
+
*
|
|
10
|
+
* Security: Commands are validated against an allowlist and arguments
|
|
11
|
+
* are passed as an array to avoid shell injection attacks.
|
|
12
|
+
*
|
|
13
|
+
* @module cli/commands/batch
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
import { Output } from '../utils/output';
|
|
17
|
+
export declare function createBatchCommand(): Command;
|
|
18
|
+
interface BatchOptions {
|
|
19
|
+
dryRun?: boolean;
|
|
20
|
+
stopOnError?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare function runBatch(file: string | undefined, options: BatchOptions, output: Output): Promise<void>;
|
|
23
|
+
export { runBatch };
|
|
24
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AA0HxD,wBAAgB,kBAAkB,IAAI,OAAO,CA0B5C;AAMD,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAWD,iBAAe,QAAQ,CACrB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoHf;AAoLD,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|