@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.
Files changed (405) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +116 -108
  3. package/bin/actp +10 -0
  4. package/dist/ACTPClient.d.ts +456 -33
  5. package/dist/ACTPClient.d.ts.map +1 -1
  6. package/dist/ACTPClient.js +477 -93
  7. package/dist/ACTPClient.js.map +1 -1
  8. package/dist/abi/AgentRegistry.json +782 -0
  9. package/dist/abi/EscrowVault.json +106 -38
  10. package/dist/abi/IdentityRegistry.json +316 -0
  11. package/dist/adapters/BaseAdapter.d.ts +231 -0
  12. package/dist/adapters/BaseAdapter.d.ts.map +1 -0
  13. package/dist/adapters/BaseAdapter.js +393 -0
  14. package/dist/adapters/BaseAdapter.js.map +1 -0
  15. package/dist/adapters/BeginnerAdapter.d.ts +152 -0
  16. package/dist/adapters/BeginnerAdapter.d.ts.map +1 -0
  17. package/dist/adapters/BeginnerAdapter.js +168 -0
  18. package/dist/adapters/BeginnerAdapter.js.map +1 -0
  19. package/dist/adapters/IntermediateAdapter.d.ts +211 -0
  20. package/dist/adapters/IntermediateAdapter.d.ts.map +1 -0
  21. package/dist/adapters/IntermediateAdapter.js +260 -0
  22. package/dist/adapters/IntermediateAdapter.js.map +1 -0
  23. package/dist/adapters/index.d.ts +15 -0
  24. package/dist/adapters/index.d.ts.map +1 -0
  25. package/dist/adapters/index.js +26 -0
  26. package/dist/adapters/index.js.map +1 -0
  27. package/dist/builders/DeliveryProofBuilder.d.ts +60 -1
  28. package/dist/builders/DeliveryProofBuilder.d.ts.map +1 -1
  29. package/dist/builders/DeliveryProofBuilder.js +81 -5
  30. package/dist/builders/DeliveryProofBuilder.js.map +1 -1
  31. package/dist/builders/QuoteBuilder.d.ts +101 -0
  32. package/dist/builders/QuoteBuilder.d.ts.map +1 -1
  33. package/dist/builders/QuoteBuilder.js +120 -3
  34. package/dist/builders/QuoteBuilder.js.map +1 -1
  35. package/dist/builders/index.d.ts +4 -0
  36. package/dist/builders/index.d.ts.map +1 -1
  37. package/dist/builders/index.js +4 -0
  38. package/dist/builders/index.js.map +1 -1
  39. package/dist/cli/commands/balance.d.ts +13 -0
  40. package/dist/cli/commands/balance.d.ts.map +1 -0
  41. package/dist/cli/commands/balance.js +89 -0
  42. package/dist/cli/commands/balance.js.map +1 -0
  43. package/dist/cli/commands/batch.d.ts +24 -0
  44. package/dist/cli/commands/batch.d.ts.map +1 -0
  45. package/dist/cli/commands/batch.js +424 -0
  46. package/dist/cli/commands/batch.js.map +1 -0
  47. package/dist/cli/commands/config.d.ts +13 -0
  48. package/dist/cli/commands/config.d.ts.map +1 -0
  49. package/dist/cli/commands/config.js +192 -0
  50. package/dist/cli/commands/config.js.map +1 -0
  51. package/dist/cli/commands/init.d.ts +19 -0
  52. package/dist/cli/commands/init.d.ts.map +1 -0
  53. package/dist/cli/commands/init.js +143 -0
  54. package/dist/cli/commands/init.js.map +1 -0
  55. package/dist/cli/commands/mint.d.ts +13 -0
  56. package/dist/cli/commands/mint.d.ts.map +1 -0
  57. package/dist/cli/commands/mint.js +91 -0
  58. package/dist/cli/commands/mint.js.map +1 -0
  59. package/dist/cli/commands/pay.d.ts +18 -0
  60. package/dist/cli/commands/pay.d.ts.map +1 -0
  61. package/dist/cli/commands/pay.js +87 -0
  62. package/dist/cli/commands/pay.js.map +1 -0
  63. package/dist/cli/commands/simulate.d.ts +32 -0
  64. package/dist/cli/commands/simulate.d.ts.map +1 -0
  65. package/dist/cli/commands/simulate.js +290 -0
  66. package/dist/cli/commands/simulate.js.map +1 -0
  67. package/dist/cli/commands/time.d.ts +29 -0
  68. package/dist/cli/commands/time.d.ts.map +1 -0
  69. package/dist/cli/commands/time.js +252 -0
  70. package/dist/cli/commands/time.js.map +1 -0
  71. package/dist/cli/commands/tx.d.ts +16 -0
  72. package/dist/cli/commands/tx.d.ts.map +1 -0
  73. package/dist/cli/commands/tx.js +379 -0
  74. package/dist/cli/commands/tx.js.map +1 -0
  75. package/dist/cli/commands/watch.d.ts +20 -0
  76. package/dist/cli/commands/watch.d.ts.map +1 -0
  77. package/dist/cli/commands/watch.js +160 -0
  78. package/dist/cli/commands/watch.js.map +1 -0
  79. package/dist/cli/index.d.ts +17 -0
  80. package/dist/cli/index.d.ts.map +1 -0
  81. package/dist/cli/index.js +104 -0
  82. package/dist/cli/index.js.map +1 -0
  83. package/dist/cli/utils/client.d.ts +70 -0
  84. package/dist/cli/utils/client.d.ts.map +1 -0
  85. package/dist/cli/utils/client.js +240 -0
  86. package/dist/cli/utils/client.js.map +1 -0
  87. package/dist/cli/utils/config.d.ts +91 -0
  88. package/dist/cli/utils/config.d.ts.map +1 -0
  89. package/dist/cli/utils/config.js +240 -0
  90. package/dist/cli/utils/config.js.map +1 -0
  91. package/dist/cli/utils/output.d.ts +174 -0
  92. package/dist/cli/utils/output.d.ts.map +1 -0
  93. package/dist/cli/utils/output.js +380 -0
  94. package/dist/cli/utils/output.js.map +1 -0
  95. package/dist/config/networks.d.ts +28 -0
  96. package/dist/config/networks.d.ts.map +1 -1
  97. package/dist/config/networks.js +60 -12
  98. package/dist/config/networks.js.map +1 -1
  99. package/dist/errors/index.d.ts +165 -2
  100. package/dist/errors/index.d.ts.map +1 -1
  101. package/dist/errors/index.js +260 -2
  102. package/dist/errors/index.js.map +1 -1
  103. package/dist/index.d.ts +61 -13
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +141 -36
  106. package/dist/index.js.map +1 -1
  107. package/dist/level0/Provider.d.ts +106 -0
  108. package/dist/level0/Provider.d.ts.map +1 -0
  109. package/dist/level0/Provider.js +10 -0
  110. package/dist/level0/Provider.js.map +1 -0
  111. package/dist/level0/ServiceDirectory.d.ts +74 -0
  112. package/dist/level0/ServiceDirectory.d.ts.map +1 -0
  113. package/dist/level0/ServiceDirectory.js +122 -0
  114. package/dist/level0/ServiceDirectory.js.map +1 -0
  115. package/dist/level0/index.d.ts +10 -0
  116. package/dist/level0/index.d.ts.map +1 -0
  117. package/dist/level0/index.js +15 -0
  118. package/dist/level0/index.js.map +1 -0
  119. package/dist/level0/provide.d.ts +51 -0
  120. package/dist/level0/provide.d.ts.map +1 -0
  121. package/dist/level0/provide.js +113 -0
  122. package/dist/level0/provide.js.map +1 -0
  123. package/dist/level0/request.d.ts +53 -0
  124. package/dist/level0/request.d.ts.map +1 -0
  125. package/dist/level0/request.js +462 -0
  126. package/dist/level0/request.js.map +1 -0
  127. package/dist/level1/Agent.d.ts +472 -0
  128. package/dist/level1/Agent.d.ts.map +1 -0
  129. package/dist/level1/Agent.js +1091 -0
  130. package/dist/level1/Agent.js.map +1 -0
  131. package/dist/level1/index.d.ts +10 -0
  132. package/dist/level1/index.d.ts.map +1 -0
  133. package/dist/level1/index.js +30 -0
  134. package/dist/level1/index.js.map +1 -0
  135. package/dist/level1/pricing/PriceCalculator.d.ts +62 -0
  136. package/dist/level1/pricing/PriceCalculator.d.ts.map +1 -0
  137. package/dist/level1/pricing/PriceCalculator.js +237 -0
  138. package/dist/level1/pricing/PriceCalculator.js.map +1 -0
  139. package/dist/level1/pricing/PricingStrategy.d.ts +179 -0
  140. package/dist/level1/pricing/PricingStrategy.d.ts.map +1 -0
  141. package/dist/level1/pricing/PricingStrategy.js +11 -0
  142. package/dist/level1/pricing/PricingStrategy.js.map +1 -0
  143. package/dist/level1/types/Job.d.ts +166 -0
  144. package/dist/level1/types/Job.d.ts.map +1 -0
  145. package/dist/level1/types/Job.js +11 -0
  146. package/dist/level1/types/Job.js.map +1 -0
  147. package/dist/level1/types/Options.d.ts +258 -0
  148. package/dist/level1/types/Options.d.ts.map +1 -0
  149. package/dist/level1/types/Options.js +8 -0
  150. package/dist/level1/types/Options.js.map +1 -0
  151. package/dist/level1/types/index.d.ts +8 -0
  152. package/dist/level1/types/index.d.ts.map +1 -0
  153. package/dist/level1/types/index.js +8 -0
  154. package/dist/level1/types/index.js.map +1 -0
  155. package/dist/protocol/ACTPKernel.d.ts +229 -2
  156. package/dist/protocol/ACTPKernel.d.ts.map +1 -1
  157. package/dist/protocol/ACTPKernel.js +367 -33
  158. package/dist/protocol/ACTPKernel.js.map +1 -1
  159. package/dist/protocol/AgentRegistry.d.ts +177 -0
  160. package/dist/protocol/AgentRegistry.d.ts.map +1 -0
  161. package/dist/protocol/AgentRegistry.js +449 -0
  162. package/dist/protocol/AgentRegistry.js.map +1 -0
  163. package/dist/protocol/DIDManager.d.ts +289 -0
  164. package/dist/protocol/DIDManager.d.ts.map +1 -0
  165. package/dist/protocol/DIDManager.js +481 -0
  166. package/dist/protocol/DIDManager.js.map +1 -0
  167. package/dist/protocol/DIDResolver.d.ts +236 -0
  168. package/dist/protocol/DIDResolver.d.ts.map +1 -0
  169. package/dist/protocol/DIDResolver.js +495 -0
  170. package/dist/protocol/DIDResolver.js.map +1 -0
  171. package/dist/protocol/EASHelper.d.ts +57 -2
  172. package/dist/protocol/EASHelper.d.ts.map +1 -1
  173. package/dist/protocol/EASHelper.js +230 -37
  174. package/dist/protocol/EASHelper.js.map +1 -1
  175. package/dist/protocol/EscrowVault.d.ts +93 -2
  176. package/dist/protocol/EscrowVault.d.ts.map +1 -1
  177. package/dist/protocol/EscrowVault.js +122 -33
  178. package/dist/protocol/EscrowVault.js.map +1 -1
  179. package/dist/protocol/EventMonitor.d.ts +45 -1
  180. package/dist/protocol/EventMonitor.d.ts.map +1 -1
  181. package/dist/protocol/EventMonitor.js +64 -8
  182. package/dist/protocol/EventMonitor.js.map +1 -1
  183. package/dist/protocol/MessageSigner.d.ts +116 -2
  184. package/dist/protocol/MessageSigner.d.ts.map +1 -1
  185. package/dist/protocol/MessageSigner.js +215 -9
  186. package/dist/protocol/MessageSigner.js.map +1 -1
  187. package/dist/protocol/ProofGenerator.d.ts +93 -0
  188. package/dist/protocol/ProofGenerator.d.ts.map +1 -1
  189. package/dist/protocol/ProofGenerator.js +194 -9
  190. package/dist/protocol/ProofGenerator.js.map +1 -1
  191. package/dist/protocol/QuoteBuilder.d.ts +8 -0
  192. package/dist/protocol/QuoteBuilder.d.ts.map +1 -1
  193. package/dist/protocol/QuoteBuilder.js +8 -0
  194. package/dist/protocol/QuoteBuilder.js.map +1 -1
  195. package/dist/runtime/BlockchainRuntime.d.ts +360 -0
  196. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -0
  197. package/dist/runtime/BlockchainRuntime.js +767 -0
  198. package/dist/runtime/BlockchainRuntime.js.map +1 -0
  199. package/dist/runtime/IACTPRuntime.d.ts +271 -0
  200. package/dist/runtime/IACTPRuntime.d.ts.map +1 -0
  201. package/dist/runtime/IACTPRuntime.js +15 -0
  202. package/dist/runtime/IACTPRuntime.js.map +1 -0
  203. package/dist/runtime/MockRuntime.d.ts +445 -0
  204. package/dist/runtime/MockRuntime.d.ts.map +1 -0
  205. package/dist/runtime/MockRuntime.js +1065 -0
  206. package/dist/runtime/MockRuntime.js.map +1 -0
  207. package/dist/runtime/MockStateManager.d.ts +233 -0
  208. package/dist/runtime/MockStateManager.d.ts.map +1 -0
  209. package/dist/runtime/MockStateManager.js +533 -0
  210. package/dist/runtime/MockStateManager.js.map +1 -0
  211. package/dist/runtime/index.d.ts +14 -0
  212. package/dist/runtime/index.d.ts.map +1 -0
  213. package/dist/runtime/index.js +42 -0
  214. package/dist/runtime/index.js.map +1 -0
  215. package/dist/runtime/types/MockState.d.ts +167 -0
  216. package/dist/runtime/types/MockState.d.ts.map +1 -0
  217. package/dist/runtime/types/MockState.js +43 -0
  218. package/dist/runtime/types/MockState.js.map +1 -0
  219. package/dist/types/agent.d.ts +76 -0
  220. package/dist/types/agent.d.ts.map +1 -0
  221. package/dist/types/agent.js +8 -0
  222. package/dist/types/agent.js.map +1 -0
  223. package/dist/types/did.d.ts +192 -0
  224. package/dist/types/did.d.ts.map +1 -0
  225. package/dist/types/did.js +38 -0
  226. package/dist/types/did.js.map +1 -0
  227. package/dist/types/eip712.d.ts +34 -0
  228. package/dist/types/eip712.d.ts.map +1 -1
  229. package/dist/types/eip712.js +31 -5
  230. package/dist/types/eip712.js.map +1 -1
  231. package/dist/types/escrow.d.ts +17 -10
  232. package/dist/types/escrow.d.ts.map +1 -1
  233. package/dist/types/index.d.ts +5 -0
  234. package/dist/types/index.d.ts.map +1 -1
  235. package/dist/types/index.js +8 -0
  236. package/dist/types/index.js.map +1 -1
  237. package/dist/types/message.d.ts +32 -0
  238. package/dist/types/message.d.ts.map +1 -1
  239. package/dist/types/message.js +4 -0
  240. package/dist/types/message.js.map +1 -1
  241. package/dist/types/state.d.ts +28 -0
  242. package/dist/types/state.d.ts.map +1 -1
  243. package/dist/types/state.js +37 -6
  244. package/dist/types/state.js.map +1 -1
  245. package/dist/types/transaction.d.ts +17 -0
  246. package/dist/types/transaction.d.ts.map +1 -1
  247. package/dist/utils/ErrorRecoveryGuide.d.ts +125 -0
  248. package/dist/utils/ErrorRecoveryGuide.d.ts.map +1 -0
  249. package/dist/utils/ErrorRecoveryGuide.js +579 -0
  250. package/dist/utils/ErrorRecoveryGuide.js.map +1 -0
  251. package/dist/utils/Helpers.d.ts +453 -0
  252. package/dist/utils/Helpers.d.ts.map +1 -0
  253. package/dist/utils/Helpers.js +623 -0
  254. package/dist/utils/Helpers.js.map +1 -0
  255. package/dist/utils/IPFSClient.d.ts +113 -0
  256. package/dist/utils/IPFSClient.d.ts.map +1 -1
  257. package/dist/utils/IPFSClient.js +128 -7
  258. package/dist/utils/IPFSClient.js.map +1 -1
  259. package/dist/utils/Logger.d.ts +195 -0
  260. package/dist/utils/Logger.d.ts.map +1 -0
  261. package/dist/utils/Logger.js +382 -0
  262. package/dist/utils/Logger.js.map +1 -0
  263. package/dist/utils/NonceManager.d.ts +234 -1
  264. package/dist/utils/NonceManager.d.ts.map +1 -1
  265. package/dist/utils/NonceManager.js +372 -7
  266. package/dist/utils/NonceManager.js.map +1 -1
  267. package/dist/utils/RateLimiter.d.ts +253 -0
  268. package/dist/utils/RateLimiter.d.ts.map +1 -0
  269. package/dist/utils/RateLimiter.js +424 -0
  270. package/dist/utils/RateLimiter.js.map +1 -0
  271. package/dist/utils/ReceivedNonceTracker.d.ts +175 -0
  272. package/dist/utils/ReceivedNonceTracker.d.ts.map +1 -1
  273. package/dist/utils/ReceivedNonceTracker.js +261 -5
  274. package/dist/utils/ReceivedNonceTracker.js.map +1 -1
  275. package/dist/utils/SDKLifecycle.d.ts +156 -0
  276. package/dist/utils/SDKLifecycle.d.ts.map +1 -0
  277. package/dist/utils/SDKLifecycle.js +347 -0
  278. package/dist/utils/SDKLifecycle.js.map +1 -0
  279. package/dist/utils/SecureNonce.d.ts +57 -0
  280. package/dist/utils/SecureNonce.d.ts.map +1 -0
  281. package/dist/utils/SecureNonce.js +80 -0
  282. package/dist/utils/SecureNonce.js.map +1 -0
  283. package/dist/utils/Semaphore.d.ts +123 -0
  284. package/dist/utils/Semaphore.d.ts.map +1 -0
  285. package/dist/utils/Semaphore.js +247 -0
  286. package/dist/utils/Semaphore.js.map +1 -0
  287. package/dist/utils/UsedAttestationTracker.d.ts +167 -0
  288. package/dist/utils/UsedAttestationTracker.d.ts.map +1 -0
  289. package/dist/utils/UsedAttestationTracker.js +309 -0
  290. package/dist/utils/UsedAttestationTracker.js.map +1 -0
  291. package/dist/utils/canonicalJson.d.ts +22 -0
  292. package/dist/utils/canonicalJson.d.ts.map +1 -1
  293. package/dist/utils/canonicalJson.js +26 -3
  294. package/dist/utils/canonicalJson.js.map +1 -1
  295. package/dist/utils/computeTypeHash.d.ts +14 -0
  296. package/dist/utils/computeTypeHash.d.ts.map +1 -1
  297. package/dist/utils/computeTypeHash.js +19 -2
  298. package/dist/utils/computeTypeHash.js.map +1 -1
  299. package/dist/utils/fsSafe.d.ts +14 -0
  300. package/dist/utils/fsSafe.d.ts.map +1 -0
  301. package/dist/utils/fsSafe.js +89 -0
  302. package/dist/utils/fsSafe.js.map +1 -0
  303. package/dist/utils/index.d.ts +15 -0
  304. package/dist/utils/index.d.ts.map +1 -0
  305. package/dist/utils/index.js +51 -0
  306. package/dist/utils/index.js.map +1 -0
  307. package/dist/utils/security.d.ts +147 -0
  308. package/dist/utils/security.d.ts.map +1 -0
  309. package/dist/utils/security.js +391 -0
  310. package/dist/utils/security.js.map +1 -0
  311. package/dist/utils/validation.d.ts +40 -0
  312. package/dist/utils/validation.d.ts.map +1 -1
  313. package/dist/utils/validation.js +184 -7
  314. package/dist/utils/validation.js.map +1 -1
  315. package/package.json +54 -37
  316. package/src/ACTPClient.ts +692 -178
  317. package/src/abi/AgentRegistry.json +782 -0
  318. package/src/abi/EscrowVault.json +106 -38
  319. package/src/abi/IdentityRegistry.json +316 -0
  320. package/src/adapters/BaseAdapter.ts +473 -0
  321. package/src/adapters/BeginnerAdapter.ts +232 -0
  322. package/src/adapters/IntermediateAdapter.ts +316 -0
  323. package/src/adapters/index.ts +25 -0
  324. package/src/builders/DeliveryProofBuilder.ts +3 -2
  325. package/src/cli/commands/balance.ts +110 -0
  326. package/src/cli/commands/batch.ts +487 -0
  327. package/src/cli/commands/config.ts +231 -0
  328. package/src/cli/commands/init.ts +161 -0
  329. package/src/cli/commands/mint.ts +116 -0
  330. package/src/cli/commands/pay.ts +113 -0
  331. package/src/cli/commands/simulate.ts +345 -0
  332. package/src/cli/commands/time.ts +303 -0
  333. package/src/cli/commands/tx.ts +448 -0
  334. package/src/cli/commands/watch.ts +211 -0
  335. package/src/cli/index.ts +116 -0
  336. package/src/cli/utils/client.ts +249 -0
  337. package/src/cli/utils/config.ts +282 -0
  338. package/src/cli/utils/output.ts +465 -0
  339. package/src/config/networks.ts +32 -9
  340. package/src/errors/index.ts +298 -1
  341. package/src/index.ts +207 -71
  342. package/src/level0/Provider.ts +117 -0
  343. package/src/level0/ServiceDirectory.ts +131 -0
  344. package/src/level0/index.ts +10 -0
  345. package/src/level0/provide.ts +131 -0
  346. package/src/level0/request.ts +494 -0
  347. package/src/level1/Agent.ts +1432 -0
  348. package/src/level1/index.ts +10 -0
  349. package/src/level1/pricing/PriceCalculator.ts +255 -0
  350. package/src/level1/pricing/PricingStrategy.ts +198 -0
  351. package/src/level1/types/Job.ts +179 -0
  352. package/src/level1/types/Options.ts +291 -0
  353. package/src/level1/types/index.ts +8 -0
  354. package/src/protocol/ACTPKernel.ts +175 -23
  355. package/src/protocol/AgentRegistry.ts +559 -0
  356. package/src/protocol/DIDManager.ts +629 -0
  357. package/src/protocol/DIDResolver.ts +554 -0
  358. package/src/protocol/EASHelper.ts +230 -46
  359. package/src/protocol/EscrowVault.ts +68 -50
  360. package/src/protocol/EventMonitor.ts +44 -15
  361. package/src/protocol/MessageSigner.ts +193 -13
  362. package/src/protocol/ProofGenerator.ts +223 -4
  363. package/src/runtime/BlockchainRuntime.ts +993 -0
  364. package/src/runtime/IACTPRuntime.ts +284 -0
  365. package/src/runtime/MockRuntime.ts +1244 -0
  366. package/src/runtime/MockStateManager.ts +576 -0
  367. package/src/runtime/index.ts +25 -0
  368. package/src/runtime/types/MockState.ts +227 -0
  369. package/src/types/agent.ts +79 -0
  370. package/src/types/did.ts +223 -0
  371. package/src/types/escrow.ts +12 -11
  372. package/src/types/index.ts +5 -1
  373. package/src/types/state.ts +12 -3
  374. package/src/types/transaction.ts +4 -1
  375. package/src/utils/ErrorRecoveryGuide.ts +675 -0
  376. package/src/utils/Helpers.ts +688 -0
  377. package/src/utils/IPFSClient.ts +122 -5
  378. package/src/utils/Logger.ts +484 -0
  379. package/src/utils/NonceManager.ts +305 -8
  380. package/src/utils/RateLimiter.ts +534 -0
  381. package/src/utils/ReceivedNonceTracker.ts +170 -0
  382. package/src/utils/SDKLifecycle.ts +416 -0
  383. package/src/utils/SecureNonce.ts +78 -0
  384. package/src/utils/Semaphore.ts +276 -0
  385. package/src/utils/UsedAttestationTracker.ts +387 -0
  386. package/src/utils/fsSafe.ts +75 -0
  387. package/src/utils/index.ts +80 -0
  388. package/src/utils/security.ts +418 -0
  389. package/src/utils/validation.ts +164 -0
  390. package/src/__tests__/ProofGenerator.test.ts +0 -124
  391. package/src/__tests__/QuoteBuilder.test.ts +0 -516
  392. package/src/__tests__/StateMachine.test.ts +0 -82
  393. package/src/__tests__/builders/DeliveryProofBuilder.test.ts +0 -581
  394. package/src/__tests__/integration/ACTPClient.test.ts +0 -263
  395. package/src/__tests__/integration.test.ts +0 -289
  396. package/src/__tests__/protocol/EASHelper.test.ts +0 -472
  397. package/src/__tests__/protocol/EventMonitor.test.ts +0 -382
  398. package/src/__tests__/security/ACTPKernel.security.test.ts +0 -1167
  399. package/src/__tests__/security/EscrowVault.security.test.ts +0 -570
  400. package/src/__tests__/security/MessageSigner.security.test.ts +0 -286
  401. package/src/__tests__/security/NonceReplay.security.test.ts +0 -501
  402. package/src/__tests__/security/validation.security.test.ts +0 -376
  403. package/src/__tests__/utils/IPFSClient.test.ts +0 -262
  404. package/src/__tests__/utils/NonceManager.test.ts +0 -205
  405. package/src/__tests__/utils/canonicalJson.test.ts +0 -153
@@ -0,0 +1,487 @@
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
+
16
+ import * as fs from 'fs';
17
+ import * as readline from 'readline';
18
+ import { Command } from 'commander';
19
+ import { Output, ExitCode, fmt } from '../utils/output';
20
+ import { mapError } from '../utils/client';
21
+
22
+ // ============================================================================
23
+ // Security: Command Allowlist and Argument Parsing
24
+ // ============================================================================
25
+
26
+ /**
27
+ * Allowlist of valid ACTP subcommands.
28
+ * Only these commands can be executed through batch mode.
29
+ * This prevents command injection attacks.
30
+ */
31
+ const VALID_SUBCOMMANDS = new Set([
32
+ 'init', 'pay', 'tx', 'balance', 'mint', 'config',
33
+ 'watch', 'simulate', 'time',
34
+ ]);
35
+
36
+ /**
37
+ * Allowlist of valid 'tx' subcommands.
38
+ */
39
+ const VALID_TX_SUBCOMMANDS = new Set([
40
+ 'create', 'status', 'list', 'deliver', 'settle', 'cancel',
41
+ ]);
42
+
43
+ /**
44
+ * Characters that are not allowed in command arguments.
45
+ * These could be used for shell injection attacks.
46
+ */
47
+ const DANGEROUS_CHARS_PATTERN = /[;&|`$(){}[\]<>!\\'"]/;
48
+
49
+ /**
50
+ * Parse a command string into an array of arguments safely.
51
+ * Does NOT use shell for parsing - handles quotes manually.
52
+ *
53
+ * @param command - Raw command string
54
+ * @returns Array of parsed arguments
55
+ * @throws Error if command contains dangerous characters
56
+ */
57
+ function parseCommandArgs(command: string): string[] {
58
+ const args: string[] = [];
59
+ let current = '';
60
+ let inQuotes = false;
61
+ let quoteChar = '';
62
+
63
+ // Check for dangerous characters outside quotes
64
+ const cleanCommand = command.replace(/"[^"]*"|'[^']*'/g, ''); // Remove quoted strings
65
+ if (DANGEROUS_CHARS_PATTERN.test(cleanCommand)) {
66
+ throw new Error(
67
+ 'Command contains potentially dangerous characters. ' +
68
+ 'Shell metacharacters are not allowed for security reasons.'
69
+ );
70
+ }
71
+
72
+ for (let i = 0; i < command.length; i++) {
73
+ const char = command[i];
74
+
75
+ if (inQuotes) {
76
+ if (char === quoteChar) {
77
+ inQuotes = false;
78
+ quoteChar = '';
79
+ } else {
80
+ current += char;
81
+ }
82
+ } else if (char === '"' || char === "'") {
83
+ inQuotes = true;
84
+ quoteChar = char;
85
+ } else if (char === ' ' || char === '\t') {
86
+ if (current) {
87
+ args.push(current);
88
+ current = '';
89
+ }
90
+ } else {
91
+ current += char;
92
+ }
93
+ }
94
+
95
+ if (current) {
96
+ args.push(current);
97
+ }
98
+
99
+ if (inQuotes) {
100
+ throw new Error('Unclosed quote in command');
101
+ }
102
+
103
+ return args;
104
+ }
105
+
106
+ /**
107
+ * Validate that a command only uses allowed subcommands.
108
+ *
109
+ * @param args - Parsed command arguments
110
+ * @returns true if command is valid
111
+ * @throws Error if command is not in allowlist
112
+ */
113
+ function validateCommand(args: string[]): boolean {
114
+ if (args.length === 0) {
115
+ throw new Error('Empty command');
116
+ }
117
+
118
+ const subcommand = args[0];
119
+
120
+ if (subcommand === 'tx') {
121
+ if (args.length < 2) {
122
+ throw new Error('tx command requires a subcommand');
123
+ }
124
+ if (!VALID_TX_SUBCOMMANDS.has(args[1])) {
125
+ throw new Error(`Unknown tx subcommand: ${args[1]}. Allowed: ${Array.from(VALID_TX_SUBCOMMANDS).join(', ')}`);
126
+ }
127
+ return true;
128
+ }
129
+
130
+ if (!VALID_SUBCOMMANDS.has(subcommand)) {
131
+ throw new Error(`Unknown command: ${subcommand}. Allowed: ${Array.from(VALID_SUBCOMMANDS).join(', ')}`);
132
+ }
133
+
134
+ return true;
135
+ }
136
+
137
+ // ============================================================================
138
+ // Command Definition
139
+ // ============================================================================
140
+
141
+ export function createBatchCommand(): Command {
142
+ const cmd = new Command('batch')
143
+ .description('Execute multiple commands from a file (agent-first feature)')
144
+ .argument('[file]', 'File containing commands (one per line), or - for stdin')
145
+ .option('--dry-run', 'Parse and validate commands without executing')
146
+ .option('--stop-on-error', 'Stop execution on first error', false)
147
+ .option('--json', 'Output as JSON')
148
+ .option('-q, --quiet', 'Minimal output')
149
+ .action(async (file, options) => {
150
+ const output = new Output(
151
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
152
+ );
153
+
154
+ try {
155
+ await runBatch(file, options, output);
156
+ } catch (error) {
157
+ const structuredError = mapError(error);
158
+ output.errorResult({
159
+ code: structuredError.code,
160
+ message: structuredError.message,
161
+ });
162
+ process.exit(ExitCode.ERROR);
163
+ }
164
+ });
165
+
166
+ return cmd;
167
+ }
168
+
169
+ // ============================================================================
170
+ // Implementation
171
+ // ============================================================================
172
+
173
+ interface BatchOptions {
174
+ dryRun?: boolean;
175
+ stopOnError?: boolean;
176
+ }
177
+
178
+ interface BatchResult {
179
+ line: number;
180
+ command: string;
181
+ status: 'success' | 'error' | 'skipped';
182
+ output?: string;
183
+ error?: string;
184
+ duration?: number;
185
+ }
186
+
187
+ async function runBatch(
188
+ file: string | undefined,
189
+ options: BatchOptions,
190
+ output: Output
191
+ ): Promise<void> {
192
+ // Read commands
193
+ let commands: string[];
194
+
195
+ if (!file || file === '-') {
196
+ // Read from stdin
197
+ commands = await readStdin();
198
+ } else {
199
+ // Read from file
200
+ if (!fs.existsSync(file)) {
201
+ throw new Error(`File not found: ${file}`);
202
+ }
203
+ commands = fs.readFileSync(file, 'utf-8').split('\n');
204
+ }
205
+
206
+ // Filter empty lines and comments
207
+ const commandsWithLine = commands
208
+ .map((line, index) => ({ line: index + 1, command: line.trim() }))
209
+ .filter(({ command }) => command && !command.startsWith('#'));
210
+
211
+ if (commandsWithLine.length === 0) {
212
+ output.warning('No commands to execute.');
213
+ return;
214
+ }
215
+
216
+ output.info(`Processing ${commandsWithLine.length} command(s)...`);
217
+ output.blank();
218
+
219
+ const results: BatchResult[] = [];
220
+ let successCount = 0;
221
+ let errorCount = 0;
222
+ let skippedCount = 0;
223
+
224
+ for (const { line, command } of commandsWithLine) {
225
+ const startTime = Date.now();
226
+
227
+ if (options.dryRun) {
228
+ // Dry run: just parse and validate
229
+ const parseResult = parseCommand(command);
230
+
231
+ if (parseResult.valid) {
232
+ results.push({
233
+ line,
234
+ command,
235
+ status: 'success',
236
+ output: `Would execute: ${parseResult.parsed}`,
237
+ });
238
+ successCount++;
239
+ outputDryRunResult(output, line, command, true, parseResult.parsed);
240
+ } else {
241
+ results.push({
242
+ line,
243
+ command,
244
+ status: 'error',
245
+ error: parseResult.error,
246
+ });
247
+ errorCount++;
248
+ outputDryRunResult(output, line, command, false, parseResult.error);
249
+
250
+ if (options.stopOnError) {
251
+ output.error('Stopping on error (--stop-on-error)');
252
+ break;
253
+ }
254
+ }
255
+ } else {
256
+ // Execute command
257
+ try {
258
+ const result = await executeCommand(command);
259
+ const duration = Date.now() - startTime;
260
+
261
+ results.push({
262
+ line,
263
+ command,
264
+ status: 'success',
265
+ output: result,
266
+ duration,
267
+ });
268
+ successCount++;
269
+ outputExecutionResult(output, line, command, true, result, duration);
270
+ } catch (error) {
271
+ const duration = Date.now() - startTime;
272
+ const errorMessage = (error as Error).message;
273
+
274
+ results.push({
275
+ line,
276
+ command,
277
+ status: 'error',
278
+ error: errorMessage,
279
+ duration,
280
+ });
281
+ errorCount++;
282
+ outputExecutionResult(output, line, command, false, errorMessage, duration);
283
+
284
+ if (options.stopOnError) {
285
+ output.error('Stopping on error (--stop-on-error)');
286
+ skippedCount = commandsWithLine.length - successCount - errorCount;
287
+ break;
288
+ }
289
+ }
290
+ }
291
+ }
292
+
293
+ // Summary
294
+ output.blank();
295
+ output.section('Batch Summary');
296
+ output.keyValue('Total Commands', commandsWithLine.length);
297
+ output.keyValue('Succeeded', successCount);
298
+ output.keyValue('Failed', errorCount);
299
+ if (skippedCount > 0) {
300
+ output.keyValue('Skipped', skippedCount);
301
+ }
302
+
303
+ // Exit with appropriate code
304
+ if (errorCount > 0) {
305
+ process.exit(ExitCode.ERROR);
306
+ }
307
+ }
308
+
309
+ /**
310
+ * Read commands from stdin
311
+ */
312
+ async function readStdin(): Promise<string[]> {
313
+ return new Promise((resolve) => {
314
+ const lines: string[] = [];
315
+
316
+ const rl = readline.createInterface({
317
+ input: process.stdin,
318
+ output: process.stdout,
319
+ terminal: false,
320
+ });
321
+
322
+ rl.on('line', (line) => {
323
+ lines.push(line);
324
+ });
325
+
326
+ rl.on('close', () => {
327
+ resolve(lines);
328
+ });
329
+ });
330
+ }
331
+
332
+ /**
333
+ * Parse and validate a command (for dry-run)
334
+ *
335
+ * Security: Uses parseCommandArgs for safe argument parsing
336
+ * and validates against allowlist.
337
+ */
338
+ function parseCommand(command: string): {
339
+ valid: boolean;
340
+ parsed?: string;
341
+ args?: string[];
342
+ error?: string;
343
+ } {
344
+ try {
345
+ // Parse command safely (no shell interpretation)
346
+ const args = parseCommandArgs(command);
347
+
348
+ if (args.length === 0) {
349
+ return { valid: false, error: 'Empty command' };
350
+ }
351
+
352
+ // Validate against allowlist
353
+ validateCommand(args);
354
+
355
+ return {
356
+ valid: true,
357
+ parsed: `actp ${args.join(' ')}`,
358
+ args,
359
+ };
360
+ } catch (error) {
361
+ return {
362
+ valid: false,
363
+ error: (error as Error).message,
364
+ };
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Execute a command (by spawning a child process)
370
+ *
371
+ * SECURITY FIX: No longer uses shell interpolation.
372
+ * Arguments are passed as an array directly to the actp binary.
373
+ * This prevents command injection attacks.
374
+ */
375
+ async function executeCommand(command: string): Promise<string> {
376
+ const { spawn } = await import('child_process');
377
+
378
+ return new Promise((resolve, reject) => {
379
+ // Parse command safely - no shell interpretation
380
+ let args: string[];
381
+ try {
382
+ args = parseCommandArgs(command);
383
+ validateCommand(args);
384
+ } catch (error) {
385
+ reject(error);
386
+ return;
387
+ }
388
+
389
+ // Add --json flag for structured output
390
+ args.push('--json');
391
+
392
+ // SECURITY: Use shell: false and pass arguments as array
393
+ // This prevents any shell interpretation of the arguments
394
+ const child = spawn('actp', args, {
395
+ stdio: ['inherit', 'pipe', 'pipe'],
396
+ env: { ...process.env },
397
+ shell: false, // CRITICAL: Do not use shell
398
+ });
399
+
400
+ let stdout = '';
401
+ let stderr = '';
402
+
403
+ child.stdout.on('data', (data) => {
404
+ stdout += data.toString();
405
+ });
406
+
407
+ child.stderr.on('data', (data) => {
408
+ stderr += data.toString();
409
+ });
410
+
411
+ child.on('close', (code) => {
412
+ if (code === 0) {
413
+ resolve(stdout.trim() || 'OK');
414
+ } else {
415
+ // Try to parse error from JSON output
416
+ try {
417
+ const errorObj = JSON.parse(stderr || stdout);
418
+ reject(new Error(errorObj.error?.message || 'Command failed'));
419
+ } catch {
420
+ reject(new Error(stderr.trim() || stdout.trim() || `Exit code: ${code}`));
421
+ }
422
+ }
423
+ });
424
+
425
+ child.on('error', (error) => {
426
+ reject(error);
427
+ });
428
+ });
429
+ }
430
+
431
+ /**
432
+ * Output dry-run result
433
+ */
434
+ function outputDryRunResult(
435
+ output: Output,
436
+ line: number,
437
+ command: string,
438
+ success: boolean,
439
+ message?: string
440
+ ): void {
441
+ if (output['mode'] === 'json') {
442
+ return; // JSON output is aggregated at the end
443
+ }
444
+
445
+ if (output['mode'] === 'quiet') {
446
+ console.log(success ? 'OK' : 'ERROR');
447
+ return;
448
+ }
449
+
450
+ const lineStr = `[${line}]`.padEnd(5);
451
+ const status = success ? fmt.green('VALID') : fmt.red('INVALID');
452
+ console.log(`${fmt.dim(lineStr)} ${status} ${fmt.dim(command)}`);
453
+ if (message && !success) {
454
+ console.log(` ${fmt.red(message)}`);
455
+ }
456
+ }
457
+
458
+ /**
459
+ * Output execution result
460
+ */
461
+ function outputExecutionResult(
462
+ output: Output,
463
+ line: number,
464
+ command: string,
465
+ success: boolean,
466
+ message: string,
467
+ durationMs: number
468
+ ): void {
469
+ if (output['mode'] === 'json') {
470
+ return; // JSON output is aggregated at the end
471
+ }
472
+
473
+ if (output['mode'] === 'quiet') {
474
+ console.log(success ? 'OK' : 'ERROR');
475
+ return;
476
+ }
477
+
478
+ const lineStr = `[${line}]`.padEnd(5);
479
+ const status = success ? fmt.green('OK') : fmt.red('FAIL');
480
+ const duration = fmt.dim(`(${durationMs}ms)`);
481
+ console.log(`${fmt.dim(lineStr)} ${status} ${command} ${duration}`);
482
+ if (!success) {
483
+ console.log(` ${fmt.red(message)}`);
484
+ }
485
+ }
486
+
487
+ export { runBatch };
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Config Command - View and modify CLI configuration
3
+ *
4
+ * Commands:
5
+ * - config show: Display current configuration
6
+ * - config set <key> <value>: Set a configuration value
7
+ * - config get <key>: Get a specific configuration value
8
+ *
9
+ * @module cli/commands/config
10
+ */
11
+
12
+ import { Command } from 'commander';
13
+ import { Output, ExitCode } from '../utils/output';
14
+ import {
15
+ loadConfig,
16
+ updateConfig,
17
+ CLIConfig,
18
+ CLIMode,
19
+ validateAddress,
20
+ validatePrivateKey,
21
+ } from '../utils/config';
22
+ import { mapError } from '../utils/client';
23
+
24
+ // ============================================================================
25
+ // Main config Command
26
+ // ============================================================================
27
+
28
+ export function createConfigCommand(): Command {
29
+ const cmd = new Command('config')
30
+ .description('View and modify configuration');
31
+
32
+ cmd.addCommand(createConfigShowCommand());
33
+ cmd.addCommand(createConfigSetCommand());
34
+ cmd.addCommand(createConfigGetCommand());
35
+
36
+ return cmd;
37
+ }
38
+
39
+ // ============================================================================
40
+ // config show
41
+ // ============================================================================
42
+
43
+ function createConfigShowCommand(): Command {
44
+ return new Command('show')
45
+ .description('Display current configuration')
46
+ .option('--json', 'Output as JSON')
47
+ .action(async (options) => {
48
+ const output = new Output(options.json ? 'json' : 'human');
49
+
50
+ try {
51
+ const config = loadConfig();
52
+
53
+ // SECURITY FIX (C-1): Mask private key - show only last 4 chars
54
+ // Previous code showed 14 chars which reduces keyspace significantly
55
+ const displayConfig = {
56
+ ...config,
57
+ privateKey: config.privateKey
58
+ ? '****' + config.privateKey.slice(-4)
59
+ : undefined,
60
+ };
61
+
62
+ if (options.json) {
63
+ output.result(displayConfig);
64
+ } else {
65
+ output.section('ACTP Configuration');
66
+ output.keyValue('Mode', config.mode);
67
+ output.keyValue('Address', config.address);
68
+ output.keyValue('Version', config.version);
69
+ if (config.privateKey) {
70
+ output.keyValue('Private Key', '****' + config.privateKey.slice(-4));
71
+ }
72
+ if (config.rpcUrl) {
73
+ output.keyValue('RPC URL', config.rpcUrl);
74
+ }
75
+ }
76
+ } catch (error) {
77
+ const structuredError = mapError(error);
78
+ output.errorResult({
79
+ code: structuredError.code,
80
+ message: structuredError.message,
81
+ });
82
+ process.exit(ExitCode.ERROR);
83
+ }
84
+ });
85
+ }
86
+
87
+ // ============================================================================
88
+ // config set
89
+ // ============================================================================
90
+
91
+ function createConfigSetCommand(): Command {
92
+ return new Command('set')
93
+ .description('Set a configuration value')
94
+ .argument('<key>', 'Configuration key (mode, address, privateKey, rpcUrl)')
95
+ .argument('<value>', 'Value to set')
96
+ .option('--json', 'Output as JSON')
97
+ .action(async (key, value, options) => {
98
+ const output = new Output(options.json ? 'json' : 'human');
99
+
100
+ try {
101
+ // Validate key
102
+ const validKeys = ['mode', 'address', 'privateKey', 'rpcUrl'];
103
+ if (!validKeys.includes(key)) {
104
+ throw new Error(
105
+ `Invalid config key: "${key}"\n` +
106
+ `Valid keys: ${validKeys.join(', ')}`
107
+ );
108
+ }
109
+
110
+ // Validate value based on key
111
+ switch (key) {
112
+ case 'mode': {
113
+ const validModes: CLIMode[] = ['mock', 'testnet', 'mainnet'];
114
+ if (!validModes.includes(value as CLIMode)) {
115
+ throw new Error(
116
+ `Invalid mode: "${value}"\n` +
117
+ `Valid modes: ${validModes.join(', ')}`
118
+ );
119
+ }
120
+ break;
121
+ }
122
+
123
+ case 'address':
124
+ if (!validateAddress(value)) {
125
+ throw new Error(
126
+ `Invalid address: "${value}"\n` +
127
+ 'Expected 0x-prefixed 40-character hex string.'
128
+ );
129
+ }
130
+ break;
131
+
132
+ case 'privateKey':
133
+ if (!validatePrivateKey(value)) {
134
+ throw new Error(
135
+ `Invalid private key format.\n` +
136
+ 'Expected 64-character hex string (with or without 0x prefix).'
137
+ );
138
+ }
139
+ // Normalize: ensure no 0x prefix for storage
140
+ value = value.startsWith('0x') ? value.slice(2) : value;
141
+ break;
142
+
143
+ case 'rpcUrl':
144
+ if (!value.startsWith('http://') && !value.startsWith('https://')) {
145
+ throw new Error(
146
+ `Invalid RPC URL: "${value}"\n` +
147
+ 'Expected URL starting with http:// or https://'
148
+ );
149
+ }
150
+ break;
151
+ }
152
+
153
+ // Update config
154
+ const updates: Partial<CLIConfig> = { [key]: value };
155
+ if (key === 'address') {
156
+ updates.address = value.toLowerCase();
157
+ }
158
+
159
+ const newConfig = updateConfig(updates);
160
+
161
+ output.result({
162
+ [key]: key === 'privateKey' ? '****' + value.slice(-4) : value,
163
+ updated: true,
164
+ });
165
+
166
+ output.success(`Configuration updated: ${key}`);
167
+ } catch (error) {
168
+ const structuredError = mapError(error);
169
+ output.errorResult({
170
+ code: structuredError.code,
171
+ message: structuredError.message,
172
+ });
173
+ process.exit(ExitCode.ERROR);
174
+ }
175
+ });
176
+ }
177
+
178
+ // ============================================================================
179
+ // config get
180
+ // ============================================================================
181
+
182
+ function createConfigGetCommand(): Command {
183
+ return new Command('get')
184
+ .description('Get a specific configuration value')
185
+ .argument('<key>', 'Configuration key')
186
+ .option('--json', 'Output as JSON')
187
+ .option('-q, --quiet', 'Output only the value')
188
+ .action(async (key, options) => {
189
+ const output = new Output(
190
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
191
+ );
192
+
193
+ try {
194
+ const config = loadConfig();
195
+
196
+ const validKeys = ['mode', 'address', 'privateKey', 'rpcUrl', 'version'];
197
+ if (!validKeys.includes(key)) {
198
+ throw new Error(
199
+ `Invalid config key: "${key}"\n` +
200
+ `Valid keys: ${validKeys.join(', ')}`
201
+ );
202
+ }
203
+
204
+ const value = config[key as keyof CLIConfig];
205
+
206
+ // Mask private key
207
+ let displayValue = value;
208
+ if (key === 'privateKey' && value) {
209
+ displayValue = '****' + (value as string).slice(-4);
210
+ }
211
+
212
+ if (options.quiet) {
213
+ if (value !== undefined) {
214
+ console.log(key === 'privateKey' ? displayValue : value);
215
+ }
216
+ } else {
217
+ output.result({
218
+ key,
219
+ value: displayValue ?? null,
220
+ });
221
+ }
222
+ } catch (error) {
223
+ const structuredError = mapError(error);
224
+ output.errorResult({
225
+ code: structuredError.code,
226
+ message: structuredError.message,
227
+ });
228
+ process.exit(ExitCode.ERROR);
229
+ }
230
+ });
231
+ }