@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,448 @@
1
+ /**
2
+ * Transaction Commands - tx subcommand group
3
+ *
4
+ * Commands for managing ACTP transactions:
5
+ * - tx create: Create a new transaction (intermediate API)
6
+ * - tx status: Check transaction status
7
+ * - tx list: List all transactions
8
+ * - tx deliver: Mark transaction as delivered
9
+ * - tx settle: Release escrow funds
10
+ * - tx cancel: Cancel a transaction
11
+ *
12
+ * @module cli/commands/tx
13
+ */
14
+
15
+ import { Command } from 'commander';
16
+ import { Output, ExitCode, TransactionDisplay } from '../utils/output';
17
+ import { createClient, mapError, isValidTxId } from '../utils/client';
18
+ import { TransactionState, MockTransaction } from '../../runtime/types/MockState';
19
+
20
+ // ============================================================================
21
+ // Main tx Command
22
+ // ============================================================================
23
+
24
+ export function createTxCommand(): Command {
25
+ const cmd = new Command('tx')
26
+ .description('Transaction management commands');
27
+
28
+ cmd.addCommand(createTxCreateCommand());
29
+ cmd.addCommand(createTxStatusCommand());
30
+ cmd.addCommand(createTxListCommand());
31
+ cmd.addCommand(createTxDeliverCommand());
32
+ cmd.addCommand(createTxSettleCommand());
33
+ cmd.addCommand(createTxCancelCommand());
34
+
35
+ return cmd;
36
+ }
37
+
38
+ // ============================================================================
39
+ // tx create
40
+ // ============================================================================
41
+
42
+ function createTxCreateCommand(): Command {
43
+ return new Command('create')
44
+ .description('Create a new transaction (without auto-funding)')
45
+ .argument('<provider>', 'Provider address')
46
+ .argument('<amount>', 'Amount to pay')
47
+ .option('-d, --deadline <deadline>', 'Deadline (+24h, +7d, or Unix timestamp)', '+24h')
48
+ .option('-w, --dispute-window <seconds>', 'Dispute window in seconds', '172800')
49
+ .option('--description <text>', 'Service description')
50
+ .option('--fund', 'Automatically fund the escrow after creation')
51
+ .option('--json', 'Output as JSON')
52
+ .option('-q, --quiet', 'Output only the transaction ID')
53
+ .action(async (provider, amount, options) => {
54
+ const output = new Output(
55
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
56
+ );
57
+
58
+ try {
59
+ const client = await createClient();
60
+
61
+ let deadline: string | number = options.deadline;
62
+ if (/^\d+$/.test(options.deadline)) {
63
+ deadline = parseInt(options.deadline, 10);
64
+ }
65
+
66
+ const disputeWindow = parseInt(options.disputeWindow, 10);
67
+
68
+ // Create transaction
69
+ const txId = await client.intermediate.createTransaction({
70
+ provider,
71
+ amount,
72
+ deadline,
73
+ disputeWindow,
74
+ serviceDescription: options.description,
75
+ });
76
+
77
+ // Optionally fund
78
+ let escrowId: string | undefined;
79
+ if (options.fund) {
80
+ escrowId = await client.intermediate.linkEscrow(txId);
81
+ }
82
+
83
+ const tx = await client.intermediate.getTransaction(txId);
84
+ if (!tx) throw new Error('Transaction not found after creation');
85
+
86
+ output.result(
87
+ {
88
+ txId,
89
+ state: tx.state,
90
+ provider: tx.provider,
91
+ requester: tx.requester,
92
+ amount: `${formatUsdc(tx.amount)} USDC`,
93
+ deadline: new Date(tx.deadline * 1000).toISOString(),
94
+ escrowId: escrowId || null,
95
+ },
96
+ { quietKey: 'txId' }
97
+ );
98
+
99
+ if (!options.fund) {
100
+ output.blank();
101
+ output.info('Transaction created but not funded.');
102
+ output.print(' Fund it: actp tx fund ' + txId.slice(0, 10) + '...');
103
+ }
104
+ } catch (error) {
105
+ const structuredError = mapError(error);
106
+ output.errorResult({
107
+ code: structuredError.code,
108
+ message: structuredError.message,
109
+ details: structuredError.details,
110
+ });
111
+ process.exit(ExitCode.ERROR);
112
+ }
113
+ });
114
+ }
115
+
116
+ // ============================================================================
117
+ // tx status
118
+ // ============================================================================
119
+
120
+ function createTxStatusCommand(): Command {
121
+ return new Command('status')
122
+ .description('Check transaction status')
123
+ .argument('<txId>', 'Transaction ID')
124
+ .option('--json', 'Output as JSON')
125
+ .option('-q, --quiet', 'Output only the state')
126
+ .action(async (txId, options) => {
127
+ const output = new Output(
128
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
129
+ );
130
+
131
+ try {
132
+ if (!isValidTxId(txId)) {
133
+ throw new Error(`Invalid transaction ID format: "${txId}"`);
134
+ }
135
+
136
+ const client = await createClient();
137
+ const tx = await client.intermediate.getTransaction(txId);
138
+
139
+ if (!tx) {
140
+ throw new Error(`Transaction not found: ${txId}`);
141
+ }
142
+
143
+ const status = await client.beginner.checkStatus(txId);
144
+
145
+ if (options.quiet) {
146
+ output.raw(tx.state);
147
+ return;
148
+ }
149
+
150
+ const display: TransactionDisplay = {
151
+ txId: tx.id,
152
+ state: tx.state,
153
+ requester: tx.requester,
154
+ provider: tx.provider,
155
+ amount: `${formatUsdc(tx.amount)} USDC`,
156
+ deadline: new Date(tx.deadline * 1000).toISOString(),
157
+ escrowId: tx.escrowId,
158
+ createdAt: new Date(tx.createdAt * 1000).toISOString(),
159
+ };
160
+
161
+ if (options.json) {
162
+ output.result({
163
+ ...display,
164
+ actions: {
165
+ canAccept: status.canAccept,
166
+ canComplete: status.canComplete,
167
+ canDispute: status.canDispute,
168
+ },
169
+ });
170
+ } else {
171
+ output.transaction(display);
172
+ output.blank();
173
+ output.print('Available Actions:');
174
+ output.keyValue(' Can Accept', status.canAccept);
175
+ output.keyValue(' Can Complete', status.canComplete);
176
+ output.keyValue(' Can Dispute', status.canDispute);
177
+ }
178
+ } catch (error) {
179
+ const structuredError = mapError(error);
180
+ output.errorResult({
181
+ code: structuredError.code,
182
+ message: structuredError.message,
183
+ details: structuredError.details,
184
+ });
185
+ process.exit(ExitCode.ERROR);
186
+ }
187
+ });
188
+ }
189
+
190
+ // ============================================================================
191
+ // tx list
192
+ // ============================================================================
193
+
194
+ function createTxListCommand(): Command {
195
+ return new Command('list')
196
+ .description('List all transactions')
197
+ .option('-s, --state <state>', 'Filter by state')
198
+ .option('-l, --limit <n>', 'Limit number of results', '50')
199
+ .option('--json', 'Output as JSON')
200
+ .option('-q, --quiet', 'Output only transaction IDs (one per line)')
201
+ .action(async (options) => {
202
+ const output = new Output(
203
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
204
+ );
205
+
206
+ try {
207
+ const client = await createClient();
208
+ let transactions: MockTransaction[] = await client.advanced.getAllTransactions();
209
+
210
+ // Filter by state if specified
211
+ if (options.state) {
212
+ const stateFilter = options.state.toUpperCase();
213
+ transactions = transactions.filter((tx: MockTransaction) => tx.state === stateFilter);
214
+ }
215
+
216
+ // Sort by createdAt descending (newest first)
217
+ transactions.sort((a: MockTransaction, b: MockTransaction) => b.createdAt - a.createdAt);
218
+
219
+ // Apply limit
220
+ const limit = parseInt(options.limit, 10);
221
+ transactions = transactions.slice(0, limit);
222
+
223
+ if (options.quiet) {
224
+ for (const tx of transactions) {
225
+ console.log(tx.id);
226
+ }
227
+ return;
228
+ }
229
+
230
+ if (options.json) {
231
+ output.result({
232
+ count: transactions.length,
233
+ transactions: transactions.map((tx: MockTransaction) => ({
234
+ txId: tx.id,
235
+ state: tx.state,
236
+ requester: tx.requester,
237
+ provider: tx.provider,
238
+ amount: tx.amount,
239
+ deadline: new Date(tx.deadline * 1000).toISOString(),
240
+ createdAt: new Date(tx.createdAt * 1000).toISOString(),
241
+ })),
242
+ });
243
+ return;
244
+ }
245
+
246
+ output.section(`Transactions (${transactions.length})`);
247
+ output.transactionTable(
248
+ transactions.map((tx: MockTransaction) => ({
249
+ txId: tx.id,
250
+ state: tx.state,
251
+ requester: tx.requester,
252
+ provider: tx.provider,
253
+ amount: `${formatUsdc(tx.amount)} USDC`,
254
+ deadline: new Date(tx.deadline * 1000).toISOString(),
255
+ }))
256
+ );
257
+ } catch (error) {
258
+ const structuredError = mapError(error);
259
+ output.errorResult({
260
+ code: structuredError.code,
261
+ message: structuredError.message,
262
+ details: structuredError.details,
263
+ });
264
+ process.exit(ExitCode.ERROR);
265
+ }
266
+ });
267
+ }
268
+
269
+ // ============================================================================
270
+ // tx deliver
271
+ // ============================================================================
272
+
273
+ function createTxDeliverCommand(): Command {
274
+ return new Command('deliver')
275
+ .description('Mark transaction as delivered (provider action)')
276
+ .argument('<txId>', 'Transaction ID')
277
+ .option('--json', 'Output as JSON')
278
+ .option('-q, --quiet', 'Minimal output')
279
+ .action(async (txId, options) => {
280
+ const output = new Output(
281
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
282
+ );
283
+
284
+ try {
285
+ if (!isValidTxId(txId)) {
286
+ throw new Error(`Invalid transaction ID format: "${txId}"`);
287
+ }
288
+
289
+ const client = await createClient();
290
+
291
+ // Transition to DELIVERED
292
+ await client.intermediate.transitionState(txId, 'DELIVERED' as TransactionState);
293
+
294
+ const tx = await client.intermediate.getTransaction(txId);
295
+ if (!tx) throw new Error('Transaction not found');
296
+
297
+ output.result(
298
+ {
299
+ txId,
300
+ state: tx.state,
301
+ completedAt: tx.completedAt
302
+ ? new Date(tx.completedAt * 1000).toISOString()
303
+ : null,
304
+ },
305
+ { quietKey: 'state' }
306
+ );
307
+
308
+ output.success('Transaction marked as delivered!');
309
+ output.info(`Dispute window: ${tx.disputeWindow} seconds`);
310
+ output.print('');
311
+ output.print('After dispute window expires, settle with:');
312
+ output.print(' actp tx settle ' + txId.slice(0, 10) + '...');
313
+ } catch (error) {
314
+ const structuredError = mapError(error);
315
+ output.errorResult({
316
+ code: structuredError.code,
317
+ message: structuredError.message,
318
+ details: structuredError.details,
319
+ });
320
+ process.exit(ExitCode.ERROR);
321
+ }
322
+ });
323
+ }
324
+
325
+ // ============================================================================
326
+ // tx settle
327
+ // ============================================================================
328
+
329
+ function createTxSettleCommand(): Command {
330
+ return new Command('settle')
331
+ .description('Release escrow funds to provider')
332
+ .argument('<txId>', 'Transaction ID')
333
+ .option('--json', 'Output as JSON')
334
+ .option('-q, --quiet', 'Minimal output')
335
+ .action(async (txId, options) => {
336
+ const output = new Output(
337
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
338
+ );
339
+
340
+ try {
341
+ if (!isValidTxId(txId)) {
342
+ throw new Error(`Invalid transaction ID format: "${txId}"`);
343
+ }
344
+
345
+ const client = await createClient();
346
+
347
+ // Get transaction to find escrow
348
+ const tx = await client.intermediate.getTransaction(txId);
349
+ if (!tx) throw new Error(`Transaction not found: ${txId}`);
350
+ if (!tx.escrowId) throw new Error('Transaction has no linked escrow');
351
+
352
+ // Release escrow
353
+ await client.intermediate.releaseEscrow(tx.escrowId);
354
+
355
+ // Get updated transaction
356
+ const updatedTx = await client.intermediate.getTransaction(txId);
357
+ if (!updatedTx) throw new Error('Transaction not found');
358
+
359
+ output.result(
360
+ {
361
+ txId,
362
+ state: updatedTx.state,
363
+ provider: updatedTx.provider,
364
+ amount: `${formatUsdc(updatedTx.amount)} USDC`,
365
+ },
366
+ { quietKey: 'state' }
367
+ );
368
+
369
+ output.success('Escrow released! Funds sent to provider.');
370
+ } catch (error) {
371
+ const structuredError = mapError(error);
372
+ output.errorResult({
373
+ code: structuredError.code,
374
+ message: structuredError.message,
375
+ details: structuredError.details,
376
+ });
377
+ process.exit(ExitCode.ERROR);
378
+ }
379
+ });
380
+ }
381
+
382
+ // ============================================================================
383
+ // tx cancel
384
+ // ============================================================================
385
+
386
+ function createTxCancelCommand(): Command {
387
+ return new Command('cancel')
388
+ .description('Cancel a transaction (before delivery)')
389
+ .argument('<txId>', 'Transaction ID')
390
+ .option('--json', 'Output as JSON')
391
+ .option('-q, --quiet', 'Minimal output')
392
+ .action(async (txId, options) => {
393
+ const output = new Output(
394
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
395
+ );
396
+
397
+ try {
398
+ if (!isValidTxId(txId)) {
399
+ throw new Error(`Invalid transaction ID format: "${txId}"`);
400
+ }
401
+
402
+ const client = await createClient();
403
+
404
+ // Transition to CANCELLED
405
+ await client.intermediate.transitionState(txId, 'CANCELLED' as TransactionState);
406
+
407
+ const tx = await client.intermediate.getTransaction(txId);
408
+ if (!tx) throw new Error('Transaction not found');
409
+
410
+ output.result(
411
+ {
412
+ txId,
413
+ state: tx.state,
414
+ refunded: tx.escrowId !== null,
415
+ },
416
+ { quietKey: 'state' }
417
+ );
418
+
419
+ output.success('Transaction cancelled!');
420
+ if (tx.escrowId) {
421
+ output.info('Funds have been refunded to requester.');
422
+ }
423
+ } catch (error) {
424
+ const structuredError = mapError(error);
425
+ output.errorResult({
426
+ code: structuredError.code,
427
+ message: structuredError.message,
428
+ details: structuredError.details,
429
+ });
430
+ process.exit(ExitCode.ERROR);
431
+ }
432
+ });
433
+ }
434
+
435
+ // ============================================================================
436
+ // Helpers
437
+ // ============================================================================
438
+
439
+ /**
440
+ * Format USDC amount from wei to decimal
441
+ */
442
+ function formatUsdc(weiAmount: string): string {
443
+ const amount = BigInt(weiAmount);
444
+ const whole = amount / 1_000_000n;
445
+ const decimal = amount % 1_000_000n;
446
+ const decimalStr = decimal.toString().padStart(6, '0').slice(0, 2);
447
+ return `${whole}.${decimalStr}`;
448
+ }
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Watch Command - Stream transaction state changes
3
+ *
4
+ * Agent-first feature: Real-time monitoring of transaction state.
5
+ * Outputs state changes as they happen, perfect for scripts
6
+ * that need to react to transaction lifecycle events.
7
+ *
8
+ * @module cli/commands/watch
9
+ */
10
+
11
+ import { Command } from 'commander';
12
+ import { Output, ExitCode, formatState, fmt } from '../utils/output';
13
+ import { createClient, mapError, isValidTxId } from '../utils/client';
14
+ import { TransactionState } from '../../runtime/types/MockState';
15
+
16
+ // ============================================================================
17
+ // Command Definition
18
+ // ============================================================================
19
+
20
+ export function createWatchCommand(): Command {
21
+ const cmd = new Command('watch')
22
+ .description('Watch a transaction for state changes (agent-first feature)')
23
+ .argument('<txId>', 'Transaction ID to watch')
24
+ .option('-t, --timeout <seconds>', 'Exit after timeout (default: indefinite)', '0')
25
+ .option('-i, --interval <ms>', 'Polling interval in milliseconds', '1000')
26
+ .option('--until <state>', 'Exit when transaction reaches this state')
27
+ .option('--json', 'Output state changes as JSON lines (NDJSON)')
28
+ .option('-q, --quiet', 'Output only state names on change')
29
+ .action(async (txId, options) => {
30
+ const output = new Output(
31
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
32
+ );
33
+
34
+ try {
35
+ await runWatch(txId, options, output);
36
+ } catch (error) {
37
+ const structuredError = mapError(error);
38
+ output.errorResult({
39
+ code: structuredError.code,
40
+ message: structuredError.message,
41
+ details: structuredError.details,
42
+ });
43
+ process.exit(ExitCode.ERROR);
44
+ }
45
+ });
46
+
47
+ return cmd;
48
+ }
49
+
50
+ // ============================================================================
51
+ // Implementation
52
+ // ============================================================================
53
+
54
+ interface WatchOptions {
55
+ timeout: string;
56
+ interval: string;
57
+ until?: string;
58
+ }
59
+
60
+ async function runWatch(
61
+ txId: string,
62
+ options: WatchOptions,
63
+ output: Output
64
+ ): Promise<void> {
65
+ if (!isValidTxId(txId)) {
66
+ throw new Error(`Invalid transaction ID format: "${txId}"`);
67
+ }
68
+
69
+ const client = await createClient();
70
+ const pollIntervalMs = parseInt(options.interval, 10);
71
+ const timeoutSeconds = parseInt(options.timeout, 10);
72
+ const untilState = options.until?.toUpperCase() as TransactionState | undefined;
73
+
74
+ // Validate until state if provided
75
+ const validStates: TransactionState[] = [
76
+ 'INITIATED', 'QUOTED', 'COMMITTED', 'IN_PROGRESS',
77
+ 'DELIVERED', 'SETTLED', 'DISPUTED', 'CANCELLED',
78
+ ];
79
+
80
+ if (untilState && !validStates.includes(untilState)) {
81
+ throw new Error(
82
+ `Invalid state: "${options.until}"\n` +
83
+ `Valid states: ${validStates.join(', ')}`
84
+ );
85
+ }
86
+
87
+ // Get initial state
88
+ const tx = await client.intermediate.getTransaction(txId);
89
+ if (!tx) {
90
+ throw new Error(`Transaction not found: ${txId}`);
91
+ }
92
+
93
+ let currentState = tx.state;
94
+ const startTime = Date.now();
95
+
96
+ // Output initial state
97
+ emitStateChange(output, txId, null, currentState, tx.updatedAt);
98
+
99
+ // Check if already at target state
100
+ if (untilState && currentState === untilState) {
101
+ output.info('Transaction already at target state.');
102
+ process.exit(ExitCode.SUCCESS);
103
+ }
104
+
105
+ // Terminal states
106
+ const terminalStates: TransactionState[] = ['SETTLED', 'CANCELLED'];
107
+ if (terminalStates.includes(currentState)) {
108
+ output.info('Transaction is in terminal state.');
109
+ process.exit(ExitCode.SUCCESS);
110
+ }
111
+
112
+ output.info('Watching for state changes... (Ctrl+C to stop)');
113
+
114
+ // Polling loop
115
+ const poll = async (): Promise<void> => {
116
+ // Check timeout
117
+ if (timeoutSeconds > 0) {
118
+ const elapsed = (Date.now() - startTime) / 1000;
119
+ if (elapsed >= timeoutSeconds) {
120
+ output.warning(`Timeout reached (${timeoutSeconds}s)`);
121
+ process.exit(ExitCode.TIMEOUT);
122
+ }
123
+ }
124
+
125
+ try {
126
+ const updatedTx = await client.intermediate.getTransaction(txId);
127
+ if (!updatedTx) {
128
+ output.warning('Transaction no longer exists');
129
+ process.exit(ExitCode.ERROR);
130
+ }
131
+
132
+ if (updatedTx.state !== currentState) {
133
+ const previousState = currentState;
134
+ currentState = updatedTx.state;
135
+ emitStateChange(output, txId, previousState, currentState, updatedTx.updatedAt);
136
+
137
+ // Check if reached target state
138
+ if (untilState && currentState === untilState) {
139
+ output.success(`Reached target state: ${untilState}`);
140
+ process.exit(ExitCode.SUCCESS);
141
+ }
142
+
143
+ // Check if terminal
144
+ if (terminalStates.includes(currentState)) {
145
+ output.info(`Transaction reached terminal state: ${currentState}`);
146
+ process.exit(ExitCode.SUCCESS);
147
+ }
148
+ }
149
+ } catch (error) {
150
+ // Non-fatal: log warning and continue
151
+ output.warning(`Poll error: ${(error as Error).message}`);
152
+ }
153
+
154
+ // Schedule next poll
155
+ setTimeout(poll, pollIntervalMs);
156
+ };
157
+
158
+ // Start polling
159
+ setTimeout(poll, pollIntervalMs);
160
+
161
+ // Keep process alive
162
+ await new Promise(() => {});
163
+ }
164
+
165
+ /**
166
+ * Emit a state change event in the appropriate format
167
+ */
168
+ function emitStateChange(
169
+ output: Output,
170
+ txId: string,
171
+ fromState: TransactionState | null,
172
+ toState: TransactionState,
173
+ timestamp: number
174
+ ): void {
175
+ const time = new Date(timestamp * 1000).toISOString();
176
+
177
+ switch (output['mode']) {
178
+ case 'json':
179
+ // NDJSON format for easy parsing
180
+ console.log(
181
+ JSON.stringify({
182
+ event: 'state_change',
183
+ txId,
184
+ fromState,
185
+ toState,
186
+ timestamp: time,
187
+ unix: timestamp,
188
+ })
189
+ );
190
+ break;
191
+
192
+ case 'quiet':
193
+ console.log(toState);
194
+ break;
195
+
196
+ case 'human':
197
+ default:
198
+ if (fromState) {
199
+ console.log(
200
+ `${fmt.dim(time)} ${formatState(fromState)} ${fmt.dim('->')} ${formatState(toState)}`
201
+ );
202
+ } else {
203
+ console.log(
204
+ `${fmt.dim(time)} ${fmt.dim('Current:')} ${formatState(toState)}`
205
+ );
206
+ }
207
+ break;
208
+ }
209
+ }
210
+
211
+ export { runWatch };