@agirails/sdk 2.0.0 → 2.0.1-beta

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/README.md +108 -116
  2. package/dist/ACTPClient.d.ts +33 -456
  3. package/dist/ACTPClient.d.ts.map +1 -1
  4. package/dist/ACTPClient.js +93 -477
  5. package/dist/ACTPClient.js.map +1 -1
  6. package/dist/abi/EscrowVault.json +38 -106
  7. package/dist/builders/DeliveryProofBuilder.d.ts +1 -60
  8. package/dist/builders/DeliveryProofBuilder.d.ts.map +1 -1
  9. package/dist/builders/DeliveryProofBuilder.js +5 -81
  10. package/dist/builders/DeliveryProofBuilder.js.map +1 -1
  11. package/dist/builders/QuoteBuilder.d.ts +0 -101
  12. package/dist/builders/QuoteBuilder.d.ts.map +1 -1
  13. package/dist/builders/QuoteBuilder.js +3 -120
  14. package/dist/builders/QuoteBuilder.js.map +1 -1
  15. package/dist/builders/index.d.ts +0 -4
  16. package/dist/builders/index.d.ts.map +1 -1
  17. package/dist/builders/index.js +0 -4
  18. package/dist/builders/index.js.map +1 -1
  19. package/dist/config/networks.d.ts +0 -28
  20. package/dist/config/networks.d.ts.map +1 -1
  21. package/dist/config/networks.js +12 -60
  22. package/dist/config/networks.js.map +1 -1
  23. package/dist/errors/index.d.ts +2 -165
  24. package/dist/errors/index.d.ts.map +1 -1
  25. package/dist/errors/index.js +2 -260
  26. package/dist/errors/index.js.map +1 -1
  27. package/dist/index.d.ts +13 -61
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +36 -141
  30. package/dist/index.js.map +1 -1
  31. package/dist/protocol/ACTPKernel.d.ts +2 -229
  32. package/dist/protocol/ACTPKernel.d.ts.map +1 -1
  33. package/dist/protocol/ACTPKernel.js +33 -367
  34. package/dist/protocol/ACTPKernel.js.map +1 -1
  35. package/dist/protocol/EASHelper.d.ts +2 -57
  36. package/dist/protocol/EASHelper.d.ts.map +1 -1
  37. package/dist/protocol/EASHelper.js +37 -230
  38. package/dist/protocol/EASHelper.js.map +1 -1
  39. package/dist/protocol/EscrowVault.d.ts +2 -93
  40. package/dist/protocol/EscrowVault.d.ts.map +1 -1
  41. package/dist/protocol/EscrowVault.js +33 -122
  42. package/dist/protocol/EscrowVault.js.map +1 -1
  43. package/dist/protocol/EventMonitor.d.ts +1 -45
  44. package/dist/protocol/EventMonitor.d.ts.map +1 -1
  45. package/dist/protocol/EventMonitor.js +8 -64
  46. package/dist/protocol/EventMonitor.js.map +1 -1
  47. package/dist/protocol/MessageSigner.d.ts +2 -116
  48. package/dist/protocol/MessageSigner.d.ts.map +1 -1
  49. package/dist/protocol/MessageSigner.js +9 -215
  50. package/dist/protocol/MessageSigner.js.map +1 -1
  51. package/dist/protocol/ProofGenerator.d.ts +0 -93
  52. package/dist/protocol/ProofGenerator.d.ts.map +1 -1
  53. package/dist/protocol/ProofGenerator.js +9 -194
  54. package/dist/protocol/ProofGenerator.js.map +1 -1
  55. package/dist/protocol/QuoteBuilder.d.ts +0 -8
  56. package/dist/protocol/QuoteBuilder.d.ts.map +1 -1
  57. package/dist/protocol/QuoteBuilder.js +0 -8
  58. package/dist/protocol/QuoteBuilder.js.map +1 -1
  59. package/dist/types/eip712.d.ts +0 -34
  60. package/dist/types/eip712.d.ts.map +1 -1
  61. package/dist/types/eip712.js +5 -31
  62. package/dist/types/eip712.js.map +1 -1
  63. package/dist/types/escrow.d.ts +10 -17
  64. package/dist/types/escrow.d.ts.map +1 -1
  65. package/dist/types/index.d.ts +0 -5
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/dist/types/index.js +0 -8
  68. package/dist/types/index.js.map +1 -1
  69. package/dist/types/message.d.ts +0 -32
  70. package/dist/types/message.d.ts.map +1 -1
  71. package/dist/types/message.js +0 -4
  72. package/dist/types/message.js.map +1 -1
  73. package/dist/types/state.d.ts +0 -28
  74. package/dist/types/state.d.ts.map +1 -1
  75. package/dist/types/state.js +6 -37
  76. package/dist/types/state.js.map +1 -1
  77. package/dist/types/transaction.d.ts +0 -17
  78. package/dist/types/transaction.d.ts.map +1 -1
  79. package/dist/utils/IPFSClient.d.ts +0 -113
  80. package/dist/utils/IPFSClient.d.ts.map +1 -1
  81. package/dist/utils/IPFSClient.js +7 -128
  82. package/dist/utils/IPFSClient.js.map +1 -1
  83. package/dist/utils/NonceManager.d.ts +1 -234
  84. package/dist/utils/NonceManager.d.ts.map +1 -1
  85. package/dist/utils/NonceManager.js +7 -372
  86. package/dist/utils/NonceManager.js.map +1 -1
  87. package/dist/utils/ReceivedNonceTracker.d.ts +0 -175
  88. package/dist/utils/ReceivedNonceTracker.d.ts.map +1 -1
  89. package/dist/utils/ReceivedNonceTracker.js +5 -261
  90. package/dist/utils/ReceivedNonceTracker.js.map +1 -1
  91. package/dist/utils/canonicalJson.d.ts +0 -22
  92. package/dist/utils/canonicalJson.d.ts.map +1 -1
  93. package/dist/utils/canonicalJson.js +3 -26
  94. package/dist/utils/canonicalJson.js.map +1 -1
  95. package/dist/utils/computeTypeHash.d.ts +0 -14
  96. package/dist/utils/computeTypeHash.d.ts.map +1 -1
  97. package/dist/utils/computeTypeHash.js +2 -19
  98. package/dist/utils/computeTypeHash.js.map +1 -1
  99. package/dist/utils/validation.d.ts +0 -40
  100. package/dist/utils/validation.d.ts.map +1 -1
  101. package/dist/utils/validation.js +7 -184
  102. package/dist/utils/validation.js.map +1 -1
  103. package/package.json +37 -54
  104. package/src/ACTPClient.ts +178 -692
  105. package/src/__tests__/ProofGenerator.test.ts +124 -0
  106. package/src/__tests__/QuoteBuilder.test.ts +516 -0
  107. package/src/__tests__/StateMachine.test.ts +82 -0
  108. package/src/__tests__/builders/DeliveryProofBuilder.test.ts +581 -0
  109. package/src/__tests__/integration/ACTPClient.test.ts +263 -0
  110. package/src/__tests__/integration.test.ts +289 -0
  111. package/src/__tests__/protocol/EASHelper.test.ts +472 -0
  112. package/src/__tests__/protocol/EventMonitor.test.ts +382 -0
  113. package/src/__tests__/security/ACTPKernel.security.test.ts +1167 -0
  114. package/src/__tests__/security/EscrowVault.security.test.ts +570 -0
  115. package/src/__tests__/security/MessageSigner.security.test.ts +286 -0
  116. package/src/__tests__/security/NonceReplay.security.test.ts +501 -0
  117. package/src/__tests__/security/validation.security.test.ts +376 -0
  118. package/src/__tests__/utils/IPFSClient.test.ts +262 -0
  119. package/src/__tests__/utils/NonceManager.test.ts +205 -0
  120. package/src/__tests__/utils/canonicalJson.test.ts +153 -0
  121. package/src/abi/EscrowVault.json +38 -106
  122. package/src/builders/DeliveryProofBuilder.ts +2 -3
  123. package/src/config/networks.ts +9 -32
  124. package/src/errors/index.ts +1 -298
  125. package/src/index.ts +71 -207
  126. package/src/protocol/ACTPKernel.ts +23 -175
  127. package/src/protocol/EASHelper.ts +46 -230
  128. package/src/protocol/EscrowVault.ts +50 -68
  129. package/src/protocol/EventMonitor.ts +15 -44
  130. package/src/protocol/MessageSigner.ts +13 -193
  131. package/src/protocol/ProofGenerator.ts +4 -223
  132. package/src/types/escrow.ts +11 -12
  133. package/src/types/index.ts +1 -5
  134. package/src/types/state.ts +3 -12
  135. package/src/types/transaction.ts +1 -4
  136. package/src/utils/IPFSClient.ts +5 -122
  137. package/src/utils/NonceManager.ts +8 -305
  138. package/src/utils/ReceivedNonceTracker.ts +0 -170
  139. package/src/utils/validation.ts +0 -164
  140. package/LICENSE +0 -190
  141. package/bin/actp +0 -10
  142. package/dist/abi/AgentRegistry.json +0 -782
  143. package/dist/abi/IdentityRegistry.json +0 -316
  144. package/dist/adapters/BaseAdapter.d.ts +0 -231
  145. package/dist/adapters/BaseAdapter.d.ts.map +0 -1
  146. package/dist/adapters/BaseAdapter.js +0 -393
  147. package/dist/adapters/BaseAdapter.js.map +0 -1
  148. package/dist/adapters/BeginnerAdapter.d.ts +0 -152
  149. package/dist/adapters/BeginnerAdapter.d.ts.map +0 -1
  150. package/dist/adapters/BeginnerAdapter.js +0 -168
  151. package/dist/adapters/BeginnerAdapter.js.map +0 -1
  152. package/dist/adapters/IntermediateAdapter.d.ts +0 -211
  153. package/dist/adapters/IntermediateAdapter.d.ts.map +0 -1
  154. package/dist/adapters/IntermediateAdapter.js +0 -260
  155. package/dist/adapters/IntermediateAdapter.js.map +0 -1
  156. package/dist/adapters/index.d.ts +0 -15
  157. package/dist/adapters/index.d.ts.map +0 -1
  158. package/dist/adapters/index.js +0 -26
  159. package/dist/adapters/index.js.map +0 -1
  160. package/dist/cli/commands/balance.d.ts +0 -13
  161. package/dist/cli/commands/balance.d.ts.map +0 -1
  162. package/dist/cli/commands/balance.js +0 -89
  163. package/dist/cli/commands/balance.js.map +0 -1
  164. package/dist/cli/commands/batch.d.ts +0 -24
  165. package/dist/cli/commands/batch.d.ts.map +0 -1
  166. package/dist/cli/commands/batch.js +0 -424
  167. package/dist/cli/commands/batch.js.map +0 -1
  168. package/dist/cli/commands/config.d.ts +0 -13
  169. package/dist/cli/commands/config.d.ts.map +0 -1
  170. package/dist/cli/commands/config.js +0 -192
  171. package/dist/cli/commands/config.js.map +0 -1
  172. package/dist/cli/commands/init.d.ts +0 -19
  173. package/dist/cli/commands/init.d.ts.map +0 -1
  174. package/dist/cli/commands/init.js +0 -143
  175. package/dist/cli/commands/init.js.map +0 -1
  176. package/dist/cli/commands/mint.d.ts +0 -13
  177. package/dist/cli/commands/mint.d.ts.map +0 -1
  178. package/dist/cli/commands/mint.js +0 -91
  179. package/dist/cli/commands/mint.js.map +0 -1
  180. package/dist/cli/commands/pay.d.ts +0 -18
  181. package/dist/cli/commands/pay.d.ts.map +0 -1
  182. package/dist/cli/commands/pay.js +0 -87
  183. package/dist/cli/commands/pay.js.map +0 -1
  184. package/dist/cli/commands/simulate.d.ts +0 -32
  185. package/dist/cli/commands/simulate.d.ts.map +0 -1
  186. package/dist/cli/commands/simulate.js +0 -290
  187. package/dist/cli/commands/simulate.js.map +0 -1
  188. package/dist/cli/commands/time.d.ts +0 -29
  189. package/dist/cli/commands/time.d.ts.map +0 -1
  190. package/dist/cli/commands/time.js +0 -252
  191. package/dist/cli/commands/time.js.map +0 -1
  192. package/dist/cli/commands/tx.d.ts +0 -16
  193. package/dist/cli/commands/tx.d.ts.map +0 -1
  194. package/dist/cli/commands/tx.js +0 -379
  195. package/dist/cli/commands/tx.js.map +0 -1
  196. package/dist/cli/commands/watch.d.ts +0 -20
  197. package/dist/cli/commands/watch.d.ts.map +0 -1
  198. package/dist/cli/commands/watch.js +0 -160
  199. package/dist/cli/commands/watch.js.map +0 -1
  200. package/dist/cli/index.d.ts +0 -17
  201. package/dist/cli/index.d.ts.map +0 -1
  202. package/dist/cli/index.js +0 -104
  203. package/dist/cli/index.js.map +0 -1
  204. package/dist/cli/utils/client.d.ts +0 -70
  205. package/dist/cli/utils/client.d.ts.map +0 -1
  206. package/dist/cli/utils/client.js +0 -240
  207. package/dist/cli/utils/client.js.map +0 -1
  208. package/dist/cli/utils/config.d.ts +0 -91
  209. package/dist/cli/utils/config.d.ts.map +0 -1
  210. package/dist/cli/utils/config.js +0 -240
  211. package/dist/cli/utils/config.js.map +0 -1
  212. package/dist/cli/utils/output.d.ts +0 -174
  213. package/dist/cli/utils/output.d.ts.map +0 -1
  214. package/dist/cli/utils/output.js +0 -380
  215. package/dist/cli/utils/output.js.map +0 -1
  216. package/dist/level0/Provider.d.ts +0 -106
  217. package/dist/level0/Provider.d.ts.map +0 -1
  218. package/dist/level0/Provider.js +0 -10
  219. package/dist/level0/Provider.js.map +0 -1
  220. package/dist/level0/ServiceDirectory.d.ts +0 -74
  221. package/dist/level0/ServiceDirectory.d.ts.map +0 -1
  222. package/dist/level0/ServiceDirectory.js +0 -122
  223. package/dist/level0/ServiceDirectory.js.map +0 -1
  224. package/dist/level0/index.d.ts +0 -10
  225. package/dist/level0/index.d.ts.map +0 -1
  226. package/dist/level0/index.js +0 -15
  227. package/dist/level0/index.js.map +0 -1
  228. package/dist/level0/provide.d.ts +0 -51
  229. package/dist/level0/provide.d.ts.map +0 -1
  230. package/dist/level0/provide.js +0 -113
  231. package/dist/level0/provide.js.map +0 -1
  232. package/dist/level0/request.d.ts +0 -53
  233. package/dist/level0/request.d.ts.map +0 -1
  234. package/dist/level0/request.js +0 -462
  235. package/dist/level0/request.js.map +0 -1
  236. package/dist/level1/Agent.d.ts +0 -472
  237. package/dist/level1/Agent.d.ts.map +0 -1
  238. package/dist/level1/Agent.js +0 -1091
  239. package/dist/level1/Agent.js.map +0 -1
  240. package/dist/level1/index.d.ts +0 -10
  241. package/dist/level1/index.d.ts.map +0 -1
  242. package/dist/level1/index.js +0 -30
  243. package/dist/level1/index.js.map +0 -1
  244. package/dist/level1/pricing/PriceCalculator.d.ts +0 -62
  245. package/dist/level1/pricing/PriceCalculator.d.ts.map +0 -1
  246. package/dist/level1/pricing/PriceCalculator.js +0 -237
  247. package/dist/level1/pricing/PriceCalculator.js.map +0 -1
  248. package/dist/level1/pricing/PricingStrategy.d.ts +0 -179
  249. package/dist/level1/pricing/PricingStrategy.d.ts.map +0 -1
  250. package/dist/level1/pricing/PricingStrategy.js +0 -11
  251. package/dist/level1/pricing/PricingStrategy.js.map +0 -1
  252. package/dist/level1/types/Job.d.ts +0 -166
  253. package/dist/level1/types/Job.d.ts.map +0 -1
  254. package/dist/level1/types/Job.js +0 -11
  255. package/dist/level1/types/Job.js.map +0 -1
  256. package/dist/level1/types/Options.d.ts +0 -258
  257. package/dist/level1/types/Options.d.ts.map +0 -1
  258. package/dist/level1/types/Options.js +0 -8
  259. package/dist/level1/types/Options.js.map +0 -1
  260. package/dist/level1/types/index.d.ts +0 -8
  261. package/dist/level1/types/index.d.ts.map +0 -1
  262. package/dist/level1/types/index.js +0 -8
  263. package/dist/level1/types/index.js.map +0 -1
  264. package/dist/protocol/AgentRegistry.d.ts +0 -177
  265. package/dist/protocol/AgentRegistry.d.ts.map +0 -1
  266. package/dist/protocol/AgentRegistry.js +0 -449
  267. package/dist/protocol/AgentRegistry.js.map +0 -1
  268. package/dist/protocol/DIDManager.d.ts +0 -289
  269. package/dist/protocol/DIDManager.d.ts.map +0 -1
  270. package/dist/protocol/DIDManager.js +0 -481
  271. package/dist/protocol/DIDManager.js.map +0 -1
  272. package/dist/protocol/DIDResolver.d.ts +0 -236
  273. package/dist/protocol/DIDResolver.d.ts.map +0 -1
  274. package/dist/protocol/DIDResolver.js +0 -495
  275. package/dist/protocol/DIDResolver.js.map +0 -1
  276. package/dist/runtime/BlockchainRuntime.d.ts +0 -360
  277. package/dist/runtime/BlockchainRuntime.d.ts.map +0 -1
  278. package/dist/runtime/BlockchainRuntime.js +0 -767
  279. package/dist/runtime/BlockchainRuntime.js.map +0 -1
  280. package/dist/runtime/IACTPRuntime.d.ts +0 -271
  281. package/dist/runtime/IACTPRuntime.d.ts.map +0 -1
  282. package/dist/runtime/IACTPRuntime.js +0 -15
  283. package/dist/runtime/IACTPRuntime.js.map +0 -1
  284. package/dist/runtime/MockRuntime.d.ts +0 -445
  285. package/dist/runtime/MockRuntime.d.ts.map +0 -1
  286. package/dist/runtime/MockRuntime.js +0 -1065
  287. package/dist/runtime/MockRuntime.js.map +0 -1
  288. package/dist/runtime/MockStateManager.d.ts +0 -233
  289. package/dist/runtime/MockStateManager.d.ts.map +0 -1
  290. package/dist/runtime/MockStateManager.js +0 -533
  291. package/dist/runtime/MockStateManager.js.map +0 -1
  292. package/dist/runtime/index.d.ts +0 -14
  293. package/dist/runtime/index.d.ts.map +0 -1
  294. package/dist/runtime/index.js +0 -42
  295. package/dist/runtime/index.js.map +0 -1
  296. package/dist/runtime/types/MockState.d.ts +0 -167
  297. package/dist/runtime/types/MockState.d.ts.map +0 -1
  298. package/dist/runtime/types/MockState.js +0 -43
  299. package/dist/runtime/types/MockState.js.map +0 -1
  300. package/dist/types/agent.d.ts +0 -76
  301. package/dist/types/agent.d.ts.map +0 -1
  302. package/dist/types/agent.js +0 -8
  303. package/dist/types/agent.js.map +0 -1
  304. package/dist/types/did.d.ts +0 -192
  305. package/dist/types/did.d.ts.map +0 -1
  306. package/dist/types/did.js +0 -38
  307. package/dist/types/did.js.map +0 -1
  308. package/dist/utils/ErrorRecoveryGuide.d.ts +0 -125
  309. package/dist/utils/ErrorRecoveryGuide.d.ts.map +0 -1
  310. package/dist/utils/ErrorRecoveryGuide.js +0 -579
  311. package/dist/utils/ErrorRecoveryGuide.js.map +0 -1
  312. package/dist/utils/Helpers.d.ts +0 -453
  313. package/dist/utils/Helpers.d.ts.map +0 -1
  314. package/dist/utils/Helpers.js +0 -623
  315. package/dist/utils/Helpers.js.map +0 -1
  316. package/dist/utils/Logger.d.ts +0 -195
  317. package/dist/utils/Logger.d.ts.map +0 -1
  318. package/dist/utils/Logger.js +0 -382
  319. package/dist/utils/Logger.js.map +0 -1
  320. package/dist/utils/RateLimiter.d.ts +0 -253
  321. package/dist/utils/RateLimiter.d.ts.map +0 -1
  322. package/dist/utils/RateLimiter.js +0 -424
  323. package/dist/utils/RateLimiter.js.map +0 -1
  324. package/dist/utils/SDKLifecycle.d.ts +0 -156
  325. package/dist/utils/SDKLifecycle.d.ts.map +0 -1
  326. package/dist/utils/SDKLifecycle.js +0 -347
  327. package/dist/utils/SDKLifecycle.js.map +0 -1
  328. package/dist/utils/SecureNonce.d.ts +0 -57
  329. package/dist/utils/SecureNonce.d.ts.map +0 -1
  330. package/dist/utils/SecureNonce.js +0 -80
  331. package/dist/utils/SecureNonce.js.map +0 -1
  332. package/dist/utils/Semaphore.d.ts +0 -123
  333. package/dist/utils/Semaphore.d.ts.map +0 -1
  334. package/dist/utils/Semaphore.js +0 -247
  335. package/dist/utils/Semaphore.js.map +0 -1
  336. package/dist/utils/UsedAttestationTracker.d.ts +0 -167
  337. package/dist/utils/UsedAttestationTracker.d.ts.map +0 -1
  338. package/dist/utils/UsedAttestationTracker.js +0 -309
  339. package/dist/utils/UsedAttestationTracker.js.map +0 -1
  340. package/dist/utils/fsSafe.d.ts +0 -14
  341. package/dist/utils/fsSafe.d.ts.map +0 -1
  342. package/dist/utils/fsSafe.js +0 -89
  343. package/dist/utils/fsSafe.js.map +0 -1
  344. package/dist/utils/index.d.ts +0 -15
  345. package/dist/utils/index.d.ts.map +0 -1
  346. package/dist/utils/index.js +0 -51
  347. package/dist/utils/index.js.map +0 -1
  348. package/dist/utils/security.d.ts +0 -147
  349. package/dist/utils/security.d.ts.map +0 -1
  350. package/dist/utils/security.js +0 -391
  351. package/dist/utils/security.js.map +0 -1
  352. package/src/abi/AgentRegistry.json +0 -782
  353. package/src/abi/IdentityRegistry.json +0 -316
  354. package/src/adapters/BaseAdapter.ts +0 -473
  355. package/src/adapters/BeginnerAdapter.ts +0 -232
  356. package/src/adapters/IntermediateAdapter.ts +0 -316
  357. package/src/adapters/index.ts +0 -25
  358. package/src/cli/commands/balance.ts +0 -110
  359. package/src/cli/commands/batch.ts +0 -487
  360. package/src/cli/commands/config.ts +0 -231
  361. package/src/cli/commands/init.ts +0 -161
  362. package/src/cli/commands/mint.ts +0 -116
  363. package/src/cli/commands/pay.ts +0 -113
  364. package/src/cli/commands/simulate.ts +0 -345
  365. package/src/cli/commands/time.ts +0 -303
  366. package/src/cli/commands/tx.ts +0 -448
  367. package/src/cli/commands/watch.ts +0 -211
  368. package/src/cli/index.ts +0 -116
  369. package/src/cli/utils/client.ts +0 -249
  370. package/src/cli/utils/config.ts +0 -282
  371. package/src/cli/utils/output.ts +0 -465
  372. package/src/level0/Provider.ts +0 -117
  373. package/src/level0/ServiceDirectory.ts +0 -131
  374. package/src/level0/index.ts +0 -10
  375. package/src/level0/provide.ts +0 -131
  376. package/src/level0/request.ts +0 -494
  377. package/src/level1/Agent.ts +0 -1432
  378. package/src/level1/index.ts +0 -10
  379. package/src/level1/pricing/PriceCalculator.ts +0 -255
  380. package/src/level1/pricing/PricingStrategy.ts +0 -198
  381. package/src/level1/types/Job.ts +0 -179
  382. package/src/level1/types/Options.ts +0 -291
  383. package/src/level1/types/index.ts +0 -8
  384. package/src/protocol/AgentRegistry.ts +0 -559
  385. package/src/protocol/DIDManager.ts +0 -629
  386. package/src/protocol/DIDResolver.ts +0 -554
  387. package/src/runtime/BlockchainRuntime.ts +0 -993
  388. package/src/runtime/IACTPRuntime.ts +0 -284
  389. package/src/runtime/MockRuntime.ts +0 -1244
  390. package/src/runtime/MockStateManager.ts +0 -576
  391. package/src/runtime/index.ts +0 -25
  392. package/src/runtime/types/MockState.ts +0 -227
  393. package/src/types/agent.ts +0 -79
  394. package/src/types/did.ts +0 -223
  395. package/src/utils/ErrorRecoveryGuide.ts +0 -675
  396. package/src/utils/Helpers.ts +0 -688
  397. package/src/utils/Logger.ts +0 -484
  398. package/src/utils/RateLimiter.ts +0 -534
  399. package/src/utils/SDKLifecycle.ts +0 -416
  400. package/src/utils/SecureNonce.ts +0 -78
  401. package/src/utils/Semaphore.ts +0 -276
  402. package/src/utils/UsedAttestationTracker.ts +0 -387
  403. package/src/utils/fsSafe.ts +0 -75
  404. package/src/utils/index.ts +0 -80
  405. package/src/utils/security.ts +0 -418
package/src/ACTPClient.ts CHANGED
@@ -1,790 +1,276 @@
1
- /**
2
- * ACTPClient - Main entry point for AGIRAILS SDK
3
- *
4
- * Provides the unified API for interacting with the ACTP protocol
5
- * through three different abstraction levels:
6
- * - `beginner`: High-level, opinionated API for simple use cases
7
- * - `intermediate`: Balanced API with more control
8
- * - `advanced`: Direct protocol access for full control
9
- *
10
- * @module ACTPClient
11
- *
12
- * @example
13
- * ```typescript
14
- * // Create client in mock mode
15
- * const client = await ACTPClient.create({
16
- * mode: 'mock',
17
- * requesterAddress: '0x1234...',
18
- * });
19
- *
20
- * // Beginner API - simplest approach
21
- * const result = await client.beginner.pay({
22
- * to: '0xProvider...',
23
- * amount: '100',
24
- * });
25
- *
26
- * // Intermediate API - more control
27
- * const txId = await client.intermediate.createTransaction({
28
- * provider: '0xProvider...',
29
- * amount: '100',
30
- * });
31
- * await client.intermediate.linkEscrow(txId);
32
- *
33
- * // Advanced API - direct protocol access
34
- * const tx = await client.advanced.getTransaction(txId);
35
- * ```
36
- */
37
-
38
- import * as path from 'path';
39
- import * as os from 'os';
40
- import * as fs from 'fs';
41
- import { ethers } from 'ethers';
42
- import { MockRuntime } from './runtime/MockRuntime';
43
- import { MockStateManager } from './runtime/MockStateManager';
44
- import { BlockchainRuntime } from './runtime/BlockchainRuntime';
45
- import { IACTPRuntime, IMockRuntime } from './runtime/IACTPRuntime';
46
- import { BeginnerAdapter } from './adapters/BeginnerAdapter';
47
- import { IntermediateAdapter } from './adapters/IntermediateAdapter';
1
+ import { ethers, Wallet, Signer } from 'ethers';
2
+ import type { JsonRpcProvider } from 'ethers';
3
+ import { ACTPKernel } from './protocol/ACTPKernel';
4
+ import { EscrowVault } from './protocol/EscrowVault';
5
+ import { EventMonitor } from './protocol/EventMonitor';
6
+ import { ProofGenerator } from './protocol/ProofGenerator';
7
+ import { MessageSigner } from './protocol/MessageSigner';
8
+ import { QuoteBuilder } from './builders/QuoteBuilder';
9
+ import { NetworkConfig, getNetwork } from './config/networks';
10
+ import { NetworkError, ValidationError } from './errors';
48
11
  import { EASHelper, EASConfig } from './protocol/EASHelper';
49
- import { getNetwork } from './config/networks';
50
-
51
- // ============================================================================
52
- // Security: Path Validation
53
- // ============================================================================
54
-
55
- /**
56
- * Validates that a state directory path is safe to use.
57
- *
58
- * SECURITY: Prevents path traversal attacks by ensuring:
59
- * 1. No '..' components in the path
60
- * 2. No symbolic links that could escape the intended directory
61
- * 3. Path resolves to a location within home directory or current working directory
62
- *
63
- * @param stateDirectory - The directory path to validate
64
- * @throws Error if path is unsafe
65
- */
66
- function validateStateDirectory(stateDirectory: string): void {
67
- // Check for path traversal characters
68
- if (stateDirectory.includes('..')) {
69
- throw new Error(
70
- 'stateDirectory cannot contain path traversal characters (..). ' +
71
- 'Use absolute paths only for security.'
72
- );
73
- }
74
-
75
- // Resolve the path to get the absolute path
76
- const resolvedPath = path.resolve(stateDirectory);
77
-
78
- // If path exists, reject symlinks and use realpath for boundary checks.
79
- // This blocks symlink escapes like "~/project" -> "/etc".
80
- let effectivePath = resolvedPath;
81
- if (fs.existsSync(resolvedPath)) {
82
- const st = fs.lstatSync(resolvedPath);
83
- if (st.isSymbolicLink()) {
84
- throw new Error(
85
- 'stateDirectory cannot be a symbolic link. ' +
86
- `Path "${stateDirectory}" resolves to a symlink at "${resolvedPath}".`
87
- );
88
- }
89
- if (!st.isDirectory()) {
90
- throw new Error(
91
- `stateDirectory must be a directory. Path "${resolvedPath}" is not a directory.`
92
- );
93
- }
94
- effectivePath = fs.realpathSync(resolvedPath);
95
- }
96
-
97
- // Get safe base directories
98
- const homeDir = os.homedir();
99
- const cwd = process.cwd();
100
-
101
- // SECURITY FIX (C-5): Use path.relative() instead of startsWith()
102
- // to handle case-insensitive filesystems (macOS, Windows) correctly.
103
- // path.relative() returns a path starting with '..' if target is outside base.
104
- const relativeToHome = path.relative(homeDir, effectivePath);
105
- const relativeToCwd = path.relative(cwd, effectivePath);
106
-
107
- // Check if path escapes the boundary (starts with '..' or is absolute)
108
- const isUnderHome = !relativeToHome.startsWith('..') && !path.isAbsolute(relativeToHome);
109
- const isUnderCwd = !relativeToCwd.startsWith('..') && !path.isAbsolute(relativeToCwd);
110
-
111
- if (!isUnderHome && !isUnderCwd) {
112
- throw new Error(
113
- 'stateDirectory must be within home directory or current working directory. ' +
114
- `Resolved path "${resolvedPath}" is outside allowed boundaries.`
115
- );
116
- }
117
-
118
- // Additional check: Ensure path doesn't contain null bytes (can bypass validation)
119
- if (stateDirectory.includes('\0')) {
120
- throw new Error('stateDirectory contains invalid null byte character');
121
- }
122
- }
123
-
124
- // ============================================================================
125
- // Type Guards
126
- // ============================================================================
12
+ import { NonceManager, InMemoryNonceManager } from './utils/NonceManager';
13
+ import { IPFSClient } from './utils/IPFSClient';
127
14
 
128
15
  /**
129
- * Type guard to check if runtime is MockRuntime.
130
- *
131
- * @param runtime - Runtime to check
132
- * @returns True if runtime is IMockRuntime
133
- */
134
- function isMockRuntime(runtime: IACTPRuntime): runtime is IMockRuntime {
135
- return 'reset' in runtime && typeof (runtime as IMockRuntime).reset === 'function';
136
- }
137
-
138
- // ============================================================================
139
- // Types
140
- // ============================================================================
141
-
142
- /**
143
- * Supported modes for ACTPClient.
144
- *
145
- * - `mock`: Local development mode with file-based state
146
- * - `testnet`: Base Sepolia testnet (future)
147
- * - `mainnet`: Base mainnet (future)
148
- */
149
- export type ACTPClientMode = 'mock' | 'testnet' | 'mainnet';
150
-
151
- /**
152
- * Configuration for creating an ACTPClient instance.
16
+ * ACTPClient configuration
153
17
  */
154
18
  export interface ACTPClientConfig {
155
- /**
156
- * Operating mode.
157
- *
158
- * - 'mock': Local development with file-based state
159
- * - 'testnet': Base Sepolia testnet
160
- * - 'mainnet': Base mainnet
161
- */
162
- mode: ACTPClientMode;
163
-
164
- /**
165
- * The requester's Ethereum address.
166
- *
167
- * This address is used as the "from" address for all transactions
168
- * created through this client instance.
169
- *
170
- * @example '0x1111111111111111111111111111111111111111'
171
- */
172
- requesterAddress: string;
173
-
174
- /**
175
- * Optional: Project root directory for mock state file storage.
176
- *
177
- * The state file will be stored at `{stateDirectory}/.actp/mock-state.json`.
178
- * Defaults to current working directory.
179
- * Only used when mode is 'mock'.
180
- */
181
- stateDirectory?: string;
182
-
183
- /**
184
- * Optional: Private key for signing transactions.
185
- *
186
- * Required when mode is 'testnet' or 'mainnet'.
187
- * Not used in 'mock' mode.
188
- *
189
- * ⚠️ CRITICAL SECURITY WARNING (C-1):
190
- *
191
- * **NEVER use raw private keys in production environments**
192
- *
193
- * **Recommended Approaches:**
194
- * 1. **Encrypted JSON Keystore** (ethers.Wallet.fromEncryptedJson) - Best for server-side
195
- * - Stores key encrypted with password
196
- * - Requires decryption at runtime (password from secure vault)
197
- * - Standard Web3 format (compatible with MetaMask, Geth, etc.)
198
- *
199
- * 2. **Hardware Wallets** (Ledger/Trezor) - Best for high-value operations
200
- * - Private key never leaves device
201
- * - User confirmation for each transaction
202
- * - Future SDK integration planned
203
- *
204
- * 3. **KMS/HSM Integration** - Best for enterprise deployment
205
- * - AWS KMS, Google Cloud KMS, Azure Key Vault
206
- * - Private key never accessible to application
207
- * - Audit trail for all signing operations
208
- *
209
- * **Security Requirements:**
210
- * - NEVER log this value or include in error messages
211
- * - NEVER store in plaintext files or git repositories
212
- * - NEVER expose in API responses or client-side code
213
- * - NEVER hardcode in source code (use environment variables minimum)
214
- * - ALWAYS use encrypted storage (keystore, KMS, hardware wallet)
215
- * - ALWAYS rotate keys if compromise suspected
216
- * - The ACTPClient toJSON() method excludes this field from serialization
217
- *
218
- * **Example (Encrypted Keystore):**
219
- * ```typescript
220
- * import { Wallet } from 'ethers';
221
- * import fs from 'fs';
222
- *
223
- * // Load encrypted keystore
224
- * const keystore = fs.readFileSync('path/to/keystore.json', 'utf8');
225
- * const password = process.env.KEYSTORE_PASSWORD; // From secure vault, not .env file
226
- * const wallet = await Wallet.fromEncryptedJson(keystore, password);
227
- *
228
- * // Use with ACTPClient
229
- * const client = await ACTPClient.create({
230
- * mode: 'testnet',
231
- * requesterAddress: wallet.address,
232
- * privateKey: wallet.privateKey, // Decrypted at runtime only
233
- * rpcUrl: process.env.RPC_URL
234
- * });
235
- * ```
236
- */
19
+ network: 'base-sepolia' | 'base-mainnet';
237
20
  privateKey?: string;
238
-
239
- /**
240
- * Optional: RPC URL for blockchain connection.
241
- *
242
- * Required when mode is 'testnet' or 'mainnet'.
243
- * Not used in 'mock' mode.
244
- *
245
- * @example 'https://base-sepolia.g.alchemy.com/v2/YOUR_KEY'
246
- */
21
+ signer?: Signer;
22
+ provider?: JsonRpcProvider;
247
23
  rpcUrl?: string;
248
-
249
- /**
250
- * Optional: Contract address overrides.
251
- *
252
- * Override default deployed contract addresses.
253
- * Used in 'testnet' and 'mainnet' modes.
254
- */
255
24
  contracts?: {
256
25
  actpKernel?: string;
257
26
  escrowVault?: string;
258
27
  usdc?: string;
259
28
  };
260
-
261
- /**
262
- * Optional: Gas settings for blockchain transactions.
263
- *
264
- * Used in 'testnet' and 'mainnet' modes.
265
- */
266
29
  gasSettings?: {
267
30
  maxFeePerGas?: bigint;
268
31
  maxPriorityFeePerGas?: bigint;
269
32
  };
270
-
271
- /**
272
- * Optional: EAS (Ethereum Attestation Service) configuration.
273
- *
274
- * SECURITY FIX (C-4): Required for attestation verification in testnet/mainnet modes.
275
- * If not provided, attestation verification in releaseEscrow() will be skipped.
276
- *
277
- * Used in 'testnet' and 'mainnet' modes.
278
- */
279
- easConfig?: EASConfig;
280
-
281
- /**
282
- * Optional: Require valid EAS attestation before escrow release (blockchain modes).
283
- *
284
- * If true, `releaseEscrow()` will require an `attestationUID` and verify it on-chain via EAS.
285
- *
286
- * Default:
287
- * - true when `easConfig` is provided
288
- * - false otherwise
289
- */
290
- requireAttestation?: boolean;
291
-
292
- /**
293
- * Optional: Custom runtime instance.
294
- *
295
- * For advanced use cases where you want to provide your own
296
- * runtime implementation (e.g., for testing with custom mocks).
297
- *
298
- * If provided, mode and stateDirectory are ignored.
299
- */
300
- runtime?: IACTPRuntime;
301
- }
302
-
303
- /**
304
- * Result of creating an ACTPClient.
305
- *
306
- * Contains metadata about the client initialization.
307
- */
308
- export interface ACTPClientInfo {
309
- /** Operating mode */
310
- mode: ACTPClientMode;
311
- /** Requester address */
312
- address: string;
313
- /** State directory (mock mode only) */
314
- stateDirectory?: string;
33
+ eas?: EASConfig;
315
34
  }
316
35
 
317
- // ============================================================================
318
- // ACTPClient Class
319
- // ============================================================================
320
-
321
36
  /**
322
- * ACTPClient - Main entry point for AGIRAILS SDK.
323
- *
324
- * This class provides a unified interface to the ACTP protocol through
325
- * three abstraction levels, catering to developers with different needs:
326
- *
327
- * **Beginner API** (`client.beginner`):
328
- * - Simplest possible interface
329
- * - Smart defaults (24h deadline, 2-day dispute window)
330
- * - User-friendly inputs (strings, no BigInt)
331
- * - Perfect for: Quick prototypes, simple integrations
37
+ * ACTPClient - Main entry point for ACTP SDK
332
38
  *
333
- * **Intermediate API** (`client.intermediate`):
334
- * - Explicit lifecycle methods
335
- * - More control over transaction flow
336
- * - Still with user-friendly input parsing
337
- * - Perfect for: Production apps needing control
338
- *
339
- * **Advanced API** (`client.advanced`):
340
- * - Direct access to protocol runtime
341
- * - Full control over all parameters
342
- * - Protocol-level types (BigInt, timestamps)
343
- * - Perfect for: Power users, custom integrations
344
- *
345
- * @example
39
+ * Example:
346
40
  * ```typescript
347
- * // Create client
348
41
  * const client = await ACTPClient.create({
349
- * mode: 'mock',
350
- * requesterAddress: '0xRequester...',
351
- * });
352
- *
353
- * // Three ways to create a transaction:
354
- *
355
- * // 1. Beginner: One call does everything
356
- * await client.beginner.pay({ to: '0xProvider', amount: '100' });
357
- *
358
- * // 2. Intermediate: Explicit steps
359
- * const txId = await client.intermediate.createTransaction({
360
- * provider: '0xProvider',
361
- * amount: '100',
42
+ * network: 'base-sepolia',
43
+ * privateKey: process.env.PRIVATE_KEY
362
44
  * });
363
- * await client.intermediate.linkEscrow(txId);
364
45
  *
365
- * // 3. Advanced: Full control
366
- * const txId = await client.advanced.createTransaction({
367
- * provider: '0xProvider',
368
- * requester: '0xRequester',
369
- * amount: '100000000', // wei
370
- * deadline: Math.floor(Date.now() / 1000) + 86400,
371
- * disputeWindow: 172800,
372
- * });
46
+ * const txId = await client.kernel.createTransaction({...});
373
47
  * ```
374
48
  */
375
49
  export class ACTPClient {
376
- /**
377
- * Beginner-level API.
378
- *
379
- * Provides the simplest interface for creating and checking transactions.
380
- * Ideal for developers who want to "just make it work" without deep
381
- * protocol knowledge.
382
- *
383
- * @example
384
- * ```typescript
385
- * const result = await client.beginner.pay({
386
- * to: '0xProvider...',
387
- * amount: '100',
388
- * });
389
- * console.log('Transaction ID:', result.txId);
390
- * console.log('State:', result.state); // 'COMMITTED'
391
- * ```
392
- */
393
- public readonly beginner: BeginnerAdapter;
50
+ public readonly kernel: ACTPKernel;
51
+ public readonly escrow: EscrowVault;
52
+ public readonly events: EventMonitor;
53
+ public readonly proofGenerator: ProofGenerator;
54
+ public readonly messageSigner: MessageSigner;
55
+ public readonly quote: QuoteBuilder;
56
+ public readonly eas?: EASHelper;
57
+
58
+ private readonly provider: JsonRpcProvider;
59
+ private readonly signer: Signer;
60
+ private readonly networkConfig: NetworkConfig;
61
+ private readonly nonceManager: NonceManager;
62
+ private readonly ipfs?: IPFSClient;
394
63
 
395
64
  /**
396
- * Intermediate-level API.
397
- *
398
- * Provides explicit lifecycle methods for more control over
399
- * the transaction flow while still offering user-friendly inputs.
400
- *
401
- * @example
402
- * ```typescript
403
- * // Create transaction (INITIATED state)
404
- * const txId = await client.intermediate.createTransaction({
405
- * provider: '0xProvider...',
406
- * amount: '100',
407
- * deadline: '+7d',
408
- * });
409
- *
410
- * // Link escrow (auto-transitions to COMMITTED)
411
- * await client.intermediate.linkEscrow(txId);
412
- *
413
- * // Transition to DELIVERED
414
- * await client.intermediate.transitionState(txId, 'DELIVERED');
415
- * ```
416
- */
417
- public readonly intermediate: IntermediateAdapter;
418
-
419
- /**
420
- * The underlying runtime implementation.
421
- *
422
- * Direct access to the protocol runtime for advanced use cases.
423
- * This is the same as `client.advanced`.
65
+ * Private constructor - use ACTPClient.create() instead
424
66
  */
425
- public readonly runtime: IACTPRuntime;
426
-
427
- /**
428
- * Client information (mode, address, etc.)
429
- */
430
- public readonly info: ACTPClientInfo;
431
-
432
- /**
433
- * SECURITY FIX (C-4): EAS helper for attestation verification.
434
- * Only available in testnet/mainnet modes when easConfig is provided.
435
- */
436
- public readonly easHelper?: EASHelper;
437
-
438
- /**
439
- * Private constructor - use ACTPClient.create() factory method.
440
- */
441
- private constructor(
442
- runtime: IACTPRuntime,
443
- requesterAddress: string,
444
- info: ACTPClientInfo,
445
- easHelper?: EASHelper
446
- ) {
447
- this.runtime = runtime;
448
- this.info = info;
449
- this.easHelper = easHelper;
450
- this.beginner = new BeginnerAdapter(runtime, requesterAddress, easHelper);
451
- this.intermediate = new IntermediateAdapter(runtime, requesterAddress, easHelper);
452
- }
453
-
454
- // ==========================================================================
455
- // Factory Method
456
- // ==========================================================================
457
-
458
- /**
459
- * Creates a new ACTPClient instance.
460
- *
461
- * This is the primary way to instantiate an ACTPClient.
462
- * It handles runtime initialization based on the specified mode.
463
- *
464
- * @param config - Client configuration
465
- * @returns Promise resolving to initialized ACTPClient
466
- * @throws {Error} If mode is not supported (only 'mock' currently)
467
- *
468
- * @example
469
- * ```typescript
470
- * // Mock mode (local development)
471
- * const client = await ACTPClient.create({
472
- * mode: 'mock',
473
- * requesterAddress: '0x1234...',
474
- * });
475
- *
476
- * // Mock mode with custom state directory
477
- * const client = await ACTPClient.create({
478
- * mode: 'mock',
479
- * requesterAddress: '0x1234...',
480
- * stateDirectory: '/custom/path/.actp',
481
- * });
482
- *
483
- * // Custom runtime (for testing)
484
- * const customRuntime = new MockRuntime();
485
- * const client = await ACTPClient.create({
486
- * mode: 'mock',
487
- * requesterAddress: '0x1234...',
488
- * runtime: customRuntime,
489
- * });
490
- * ```
491
- */
492
- static async create(config: ACTPClientConfig): Promise<ACTPClient> {
493
- // Validate requester address
494
- if (!config.requesterAddress) {
495
- throw new Error('requesterAddress is required');
67
+ private constructor(config: ACTPClientConfig) {
68
+ // Validate config
69
+ this.validateConfig(config);
70
+
71
+ // Get network configuration (already cloned in getNetwork)
72
+ this.networkConfig = getNetwork(config.network);
73
+
74
+ // Apply overrides immutably (create new objects, don't mutate)
75
+ if (config.contracts) {
76
+ this.networkConfig = {
77
+ ...this.networkConfig,
78
+ contracts: {
79
+ ...this.networkConfig.contracts,
80
+ ...config.contracts
81
+ }
82
+ };
496
83
  }
497
84
 
498
- if (!/^0x[a-fA-F0-9]{40}$/.test(config.requesterAddress)) {
499
- throw new Error(
500
- `Invalid requesterAddress: "${config.requesterAddress}". ` +
501
- 'Must be a valid Ethereum address (0x-prefixed, 40 hex chars)'
502
- );
85
+ // Apply gas settings overrides
86
+ if (config.gasSettings) {
87
+ this.networkConfig = {
88
+ ...this.networkConfig,
89
+ gasSettings: {
90
+ ...this.networkConfig.gasSettings,
91
+ ...config.gasSettings
92
+ }
93
+ };
503
94
  }
504
95
 
505
- let runtime: IACTPRuntime;
506
- let stateDirectory: string | undefined;
507
- let easHelper: EASHelper | undefined;
96
+ // Freeze config to prevent accidental mutation
97
+ Object.freeze(this.networkConfig.contracts);
98
+ Object.freeze(this.networkConfig.gasSettings);
99
+ Object.freeze(this.networkConfig);
508
100
 
509
- // If custom runtime provided, use it directly
510
- if (config.runtime) {
511
- runtime = config.runtime;
101
+ // Setup provider
102
+ if (config.provider) {
103
+ this.provider = config.provider;
512
104
  } else {
513
- // Initialize runtime based on mode
514
- switch (config.mode) {
515
- case 'mock': {
516
- // SECURITY FIX: Enhanced path validation to prevent path traversal attacks
517
- if (config.stateDirectory) {
518
- validateStateDirectory(config.stateDirectory);
519
- }
520
-
521
- // MockStateManager takes projectRoot as string parameter
522
- const stateManager = new MockStateManager(config.stateDirectory);
523
- runtime = new MockRuntime(stateManager);
524
- stateDirectory = config.stateDirectory;
525
- // EASHelper not needed in mock mode
526
- break;
527
- }
528
-
529
- case 'testnet':
530
- case 'mainnet': {
531
- // Validate required parameters for blockchain modes
532
- if (!config.privateKey) {
533
- throw new Error(
534
- `privateKey is required for ${config.mode} mode`
535
- );
536
- }
105
+ const rpcUrl = config.rpcUrl || this.networkConfig.rpcUrl;
106
+ this.provider = new ethers.JsonRpcProvider(rpcUrl, this.networkConfig.chainId);
107
+ }
537
108
 
538
- // Map mode to network config
539
- const network = config.mode === 'testnet' ? 'base-sepolia' : 'base-mainnet';
109
+ // Setup signer
110
+ if (config.signer) {
111
+ this.signer = config.signer;
112
+ } else if (config.privateKey) {
113
+ this.signer = new Wallet(config.privateKey, this.provider);
114
+ } else {
115
+ // Attempt to derive signer from provider if possible
116
+ // In ethers v6, getSigner() is async and returns a JsonRpcSigner
117
+ throw new ValidationError('signer', 'Either privateKey or signer must be provided');
118
+ }
540
119
 
541
- // Default RPC URL from network config if not provided
542
- // This makes Level0/Agent usable on testnet without forcing users to pass rpcUrl explicitly.
543
- const rpcUrl = config.rpcUrl ?? getNetwork(network).rpcUrl;
120
+ // Initialize shared utilities
121
+ this.nonceManager = new InMemoryNonceManager();
544
122
 
545
- // Optional persistent state directory can be used for:
546
- // - mock mode state (mock-state.json)
547
- // - blockchain mode safety state (e.g., used-attestation replay protection)
548
- if (config.stateDirectory) {
549
- validateStateDirectory(config.stateDirectory);
550
- }
123
+ // Initialize IPFS client if configured
124
+ if (config.rpcUrl) {
125
+ // IPFS configuration could be added to ACTPClientConfig in the future
126
+ // For now, QuoteBuilder can work without IPFS (quotes stored only on-chain)
127
+ }
551
128
 
552
- // Create ethers provider and signer
553
- const provider = new ethers.JsonRpcProvider(rpcUrl);
554
- const signer = new ethers.Wallet(config.privateKey, provider);
129
+ // Initialize protocol modules
130
+ this.kernel = new ACTPKernel(
131
+ this.networkConfig.contracts.actpKernel,
132
+ this.signer,
133
+ this.networkConfig.gasSettings
134
+ );
555
135
 
556
- const requireAttestation = config.requireAttestation ?? Boolean(config.easConfig);
136
+ this.escrow = new EscrowVault(
137
+ this.networkConfig.contracts.escrowVault,
138
+ this.signer,
139
+ this.networkConfig.gasSettings
140
+ );
557
141
 
558
- // Create BlockchainRuntime
559
- const blockchainRuntime = new BlockchainRuntime({
560
- network,
561
- signer,
562
- provider,
563
- contracts: config.contracts,
564
- gasSettings: config.gasSettings,
565
- easConfig: config.easConfig,
566
- requireAttestation,
567
- stateDirectory: config.stateDirectory,
568
- });
142
+ this.events = new EventMonitor(
143
+ this.kernel['contract'], // Access private contract field
144
+ this.escrow['contract']
145
+ );
569
146
 
570
- // Initialize async components
571
- await blockchainRuntime.initialize();
147
+ this.proofGenerator = new ProofGenerator();
572
148
 
573
- runtime = blockchainRuntime;
149
+ this.messageSigner = new MessageSigner(this.signer);
574
150
 
575
- // SECURITY FIX (C-4): Use the runtime's initialized EASHelper so
576
- // adapters and runtime share the same tracker + verification logic.
577
- if (config.easConfig) {
578
- easHelper = blockchainRuntime.getEASHelper();
579
- }
580
- break;
581
- }
151
+ // Initialize QuoteBuilder (AIP-2)
152
+ this.quote = new QuoteBuilder(this.signer, this.nonceManager, this.ipfs);
582
153
 
583
- default:
584
- throw new Error(
585
- `Unknown mode: "${config.mode}". ` +
586
- 'Supported modes: "mock", "testnet", "mainnet"'
587
- );
588
- }
154
+ if (config.eas) {
155
+ this.eas = new EASHelper(this.signer, config.eas);
589
156
  }
590
-
591
- // Normalize address to lowercase for consistency
592
- const normalizedAddress = config.requesterAddress.toLowerCase();
593
-
594
- const info: ACTPClientInfo = {
595
- mode: config.mode,
596
- address: normalizedAddress,
597
- stateDirectory,
598
- };
599
-
600
- // SECURITY FIX (C-4): Pass EASHelper to adapters for attestation verification
601
- return new ACTPClient(runtime, normalizedAddress, info, easHelper);
602
157
  }
603
158
 
604
- // ==========================================================================
605
- // Public Methods
606
- // ==========================================================================
607
-
608
159
  /**
609
- * Advanced-level API.
610
- *
611
- * Provides direct access to the underlying protocol runtime.
612
- * Use this when you need full control over all parameters.
613
- *
614
- * This is the same as accessing `client.runtime` directly.
615
- *
616
- * @example
617
- * ```typescript
618
- * // Direct runtime access
619
- * const txId = await client.advanced.createTransaction({
620
- * provider: '0xProvider',
621
- * requester: '0xRequester',
622
- * amount: '100000000', // wei
623
- * deadline: Math.floor(Date.now() / 1000) + 86400,
624
- * });
625
- *
626
- * // Get transaction details
627
- * const tx = await client.advanced.getTransaction(txId);
628
- *
629
- * // Time manipulation (mock mode only - requires IMockRuntime cast)
630
- * import { IMockRuntime } from './runtime/IACTPRuntime';
631
- * if (client.getMode() === 'mock') {
632
- * (client.advanced as IMockRuntime).time.advanceTime(3600); // Advance 1 hour
633
- * }
634
- * ```
160
+ * Create and initialize ACTPClient (async factory pattern)
161
+ * Ensures all async components (EIP-712 domain) are ready before returning
635
162
  */
636
- get advanced(): IACTPRuntime {
637
- return this.runtime;
163
+ static async create(config: ACTPClientConfig): Promise<ACTPClient> {
164
+ const client = new ACTPClient(config);
165
+
166
+ // Initialize EIP-712 domain for message signing
167
+ await client.messageSigner.initDomain(client.networkConfig.contracts.actpKernel);
168
+
169
+ return client;
638
170
  }
639
171
 
640
172
  /**
641
- * Gets the requester's Ethereum address.
642
- *
643
- * This is the address used as the "from" address for all transactions
644
- * created through this client.
645
- *
646
- * @returns The requester's Ethereum address (normalized to lowercase)
647
- *
648
- * @example
649
- * ```typescript
650
- * const address = client.getAddress();
651
- * console.log('My address:', address);
652
- * // '0x1111111111111111111111111111111111111111'
653
- * ```
173
+ * @deprecated Use ACTPClient.create() instead
174
+ * Initialize async components (must be called after construction)
654
175
  */
655
- getAddress(): string {
656
- return this.info.address;
176
+ async initialize(): Promise<void> {
177
+ await this.messageSigner.initDomain(this.networkConfig.contracts.actpKernel);
657
178
  }
658
179
 
659
180
  /**
660
- * Gets the current operating mode.
661
- *
662
- * @returns The client's operating mode ('mock', 'testnet', or 'mainnet')
663
- *
664
- * @example
665
- * ```typescript
666
- * if (client.getMode() === 'mock') {
667
- * console.log('Running in local development mode');
668
- * }
669
- * ```
181
+ * Get signer address
670
182
  */
671
- getMode(): ACTPClientMode {
672
- return this.info.mode;
183
+ async getAddress(): Promise<string> {
184
+ return await this.signer.getAddress();
673
185
  }
674
186
 
675
187
  /**
676
- * Resets the mock state to default.
677
- *
678
- * Only available in mock mode. Clears all transactions, escrows,
679
- * and accounts, resetting to a fresh state.
680
- *
681
- * @throws {Error} If not in mock mode or runtime doesn't support reset
682
- *
683
- * @example
684
- * ```typescript
685
- * // Reset state between test runs
686
- * await client.reset();
687
- * ```
188
+ * Get network configuration
688
189
  */
689
- async reset(): Promise<void> {
690
- if (this.info.mode !== 'mock') {
691
- throw new Error(
692
- `reset() is only available in mock mode. Current mode: "${this.info.mode}"`
693
- );
694
- }
695
-
696
- if (!isMockRuntime(this.runtime)) {
697
- throw new Error('Runtime does not support reset operation');
698
- }
699
-
700
- await this.runtime.reset();
190
+ getNetworkConfig(): NetworkConfig {
191
+ return this.networkConfig;
701
192
  }
702
193
 
703
194
  /**
704
- * Custom JSON serialization to prevent private key exposure.
705
- *
706
- * SECURITY FIX (HIGH-4): Prevents accidental private key logging
707
- * when ACTPClient instance is serialized (e.g., JSON.stringify, console.log).
708
- *
709
- * @returns Safe serializable object with sensitive data removed
195
+ * Get provider
710
196
  */
711
- toJSON(): object {
712
- return {
713
- mode: this.info.mode,
714
- address: this.info.address,
715
- stateDirectory: this.info.stateDirectory,
716
- isInitialized: true,
717
- // Explicitly exclude: privateKey, signer, provider internals
718
- _warning: 'Sensitive data (privateKey, signer) excluded for security',
719
- };
197
+ getProvider(): JsonRpcProvider {
198
+ return this.provider;
720
199
  }
721
200
 
722
201
  /**
723
- * Custom string representation for debugging.
724
- *
725
- * SECURITY FIX (HIGH-4): Prevents private key exposure in logs.
202
+ * Get current block number
726
203
  */
727
- toString(): string {
728
- return `ACTPClient(mode=${this.info.mode}, address=${this.info.address})`;
204
+ async getBlockNumber(): Promise<number> {
205
+ try {
206
+ return await this.provider.getBlockNumber();
207
+ } catch (error: any) {
208
+ throw new NetworkError(this.networkConfig.name, error.message);
209
+ }
729
210
  }
730
211
 
731
212
  /**
732
- * Custom inspect for Node.js util.inspect (console.log).
733
- *
734
- * SECURITY FIX (HIGH-4): Prevents private key exposure in console output.
213
+ * Get gas price (ethers v6: use getFeeData instead)
735
214
  */
736
- [Symbol.for('nodejs.util.inspect.custom')](): string {
737
- return this.toString();
215
+ async getGasPrice() {
216
+ try {
217
+ const feeData = await this.provider.getFeeData();
218
+ return feeData.gasPrice || 0n;
219
+ } catch (error: any) {
220
+ throw new NetworkError(this.networkConfig.name, error.message);
221
+ }
738
222
  }
739
223
 
740
224
  /**
741
- * Mints USDC tokens to an address.
225
+ * Release escrow with automatic attestation verification (recommended for security).
226
+ *
227
+ * SECURITY: This method verifies the attestation belongs to the transaction BEFORE
228
+ * releasing escrow. This protects against malicious providers submitting attestations
229
+ * from different transactions.
742
230
  *
743
- * Only available in mock mode. Useful for testing scenarios
744
- * where you need to fund accounts.
231
+ * ACTPKernel V1 contract accepts any attestationUID without on-chain validation.
232
+ * This SDK-side verification is the recommended protection until V2 adds on-chain checks.
745
233
  *
746
- * @param address - Address to mint tokens to
747
- * @param amount - Amount to mint (in USDC wei, e.g., '1000000' for 1 USDC)
748
- * @throws {Error} If not in mock mode or runtime doesn't support mintTokens
234
+ * @param txId - Transaction ID to settle
235
+ * @param attestationUID - EAS attestation UID to verify
236
+ * @throws {Error} If EAS is not configured (client.eas is undefined)
237
+ * @throws {Error} If attestation verification fails (revoked, expired, or txId mismatch)
238
+ * @throws {TransactionRevertedError} If escrow release fails
749
239
  *
750
240
  * @example
751
241
  * ```typescript
752
- * // Mint 1000 USDC to the requester
753
- * await client.mintTokens(client.getAddress(), '1000000000'); // 1000 * 10^6
242
+ * // Get transaction to find attestation UID
243
+ * const tx = await client.kernel.getTransaction(txId);
244
+ *
245
+ * // Verify and release escrow in one call
246
+ * await client.releaseEscrowWithVerification(txId, tx.attestationUID);
754
247
  * ```
755
248
  */
756
- async mintTokens(address: string, amount: string): Promise<void> {
757
- if (this.info.mode !== 'mock') {
249
+ async releaseEscrowWithVerification(txId: string, attestationUID: string): Promise<void> {
250
+ // Ensure EAS is configured
251
+ if (!this.eas) {
758
252
  throw new Error(
759
- `mintTokens() is only available in mock mode. Current mode: "${this.info.mode}"`
253
+ 'EAS is not configured. Initialize ACTPClient with eas config or use kernel.releaseEscrow() directly (unsafe)'
760
254
  );
761
255
  }
762
256
 
763
- if (!isMockRuntime(this.runtime)) {
764
- throw new Error('Runtime does not support mintTokens operation');
765
- }
257
+ // Step 1: Verify attestation belongs to this transaction
258
+ await this.eas.verifyDeliveryAttestation(txId, attestationUID);
766
259
 
767
- await this.runtime.mintTokens(address, amount);
260
+ // Step 2: Release escrow (verification passed)
261
+ await this.kernel.releaseEscrow(txId);
768
262
  }
769
263
 
770
264
  /**
771
- * Gets the USDC balance of an address.
772
- *
773
- * @param address - Address to check balance for
774
- * @returns Promise resolving to balance in USDC wei
775
- * @throws {Error} If runtime doesn't support getBalance
776
- *
777
- * @example
778
- * ```typescript
779
- * const balance = await client.getBalance(client.getAddress());
780
- * console.log('Balance:', balance); // '1000000000' (1000 USDC)
781
- * ```
265
+ * Validate configuration
782
266
  */
783
- async getBalance(address: string): Promise<string> {
784
- if (!isMockRuntime(this.runtime)) {
785
- throw new Error('Runtime does not support getBalance operation');
267
+ private validateConfig(config: ACTPClientConfig): void {
268
+ if (!config.network) {
269
+ throw new ValidationError('network', 'Network is required');
786
270
  }
787
271
 
788
- return this.runtime.getBalance(address);
272
+ if (!config.privateKey && !config.signer && !config.provider) {
273
+ throw new ValidationError('auth', 'Provide either privateKey, signer, or provider with signer access');
274
+ }
789
275
  }
790
276
  }