@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,559 @@
1
+ import { Contract, Signer, keccak256, toUtf8Bytes } from 'ethers';
2
+ import AgentRegistryABI from '../abi/AgentRegistry.json';
3
+ import {
4
+ AgentProfile,
5
+ ServiceDescriptor,
6
+ RegisterAgentParams,
7
+ QueryAgentsParams
8
+ } from '../types';
9
+ import { TransactionRevertedError, ValidationError, QueryCapExceededError } from '../errors';
10
+ import { validateAddress, validateEndpointURL } from '../utils/validation';
11
+
12
+ /**
13
+ * Gas options for transactions
14
+ */
15
+ interface GasOptions {
16
+ maxFeePerGas?: bigint;
17
+ maxPriorityFeePerGas?: bigint;
18
+ }
19
+
20
+ /**
21
+ * AgentRegistry - Agent Identity & Reputation SDK Module (AIP-7)
22
+ *
23
+ * Provides methods for:
24
+ * - Registering AI agents on-chain
25
+ * - Managing agent profiles and services
26
+ * - Querying agents by service type
27
+ * - Reading reputation scores
28
+ *
29
+ * Reference: AIP-7 Agent Identity, Registry & Storage System
30
+ */
31
+ export class AgentRegistry {
32
+ private contract: Contract;
33
+ private readonly gasSettings?: GasOptions;
34
+
35
+ constructor(
36
+ private readonly address: string,
37
+ signer: Signer,
38
+ gasSettings?: GasOptions
39
+ ) {
40
+ this.contract = new Contract(address, AgentRegistryABI, signer);
41
+ this.gasSettings = gasSettings;
42
+ }
43
+
44
+ /**
45
+ * Get gas buffer multiplier based on operation complexity
46
+ */
47
+ private getGasBufferMultiplier(operation: string): number {
48
+ const buffers: Record<string, number> = {
49
+ 'registerAgent': 1.40, // 40% - Complex storage writes
50
+ 'addServiceType': 1.25, // 25% - Storage update
51
+ 'removeServiceType': 1.25,
52
+ 'updateEndpoint': 1.20, // 20% - Simple storage update
53
+ 'setActiveStatus': 1.15 // 15% - Boolean update
54
+ };
55
+
56
+ return buffers[operation] || 1.20;
57
+ }
58
+
59
+ /**
60
+ * Build transaction options with gas settings
61
+ */
62
+ private buildTxOptions(estimatedGas: bigint, operation: string = 'default'): any {
63
+ const bufferMultiplier = this.getGasBufferMultiplier(operation);
64
+ let gasLimit = (estimatedGas * BigInt(Math.round(bufferMultiplier * 100))) / 100n;
65
+
66
+ // Cap gas limit (Base L2 safety)
67
+ const MAX_GAS_LIMIT = 10_000_000n;
68
+ if (gasLimit > MAX_GAS_LIMIT) {
69
+ throw new ValidationError('gasLimit', `Estimated gas exceeds maximum safe limit (${MAX_GAS_LIMIT})`);
70
+ }
71
+
72
+ const options: any = { gasLimit };
73
+
74
+ if (this.gasSettings?.maxFeePerGas) {
75
+ options.maxFeePerGas = this.gasSettings.maxFeePerGas;
76
+ }
77
+ if (this.gasSettings?.maxPriorityFeePerGas) {
78
+ options.maxPriorityFeePerGas = this.gasSettings.maxPriorityFeePerGas;
79
+ }
80
+
81
+ return options;
82
+ }
83
+
84
+ /**
85
+ * Get registry contract address
86
+ */
87
+ getAddress(): string {
88
+ return this.address;
89
+ }
90
+
91
+ /**
92
+ * Compute service type hash
93
+ * Service types must be lowercase with only a-z, 0-9, and hyphens
94
+ *
95
+ * @param serviceType - Human-readable service type (e.g., "text-generation")
96
+ * @returns keccak256 hash of the service type
97
+ */
98
+ computeServiceTypeHash(serviceType: string): string {
99
+ // Validate length
100
+ const MAX_SERVICE_TYPE_LENGTH = 64;
101
+ if (serviceType.length > MAX_SERVICE_TYPE_LENGTH) {
102
+ throw new ValidationError(
103
+ 'serviceType',
104
+ `Service type exceeds maximum length (${MAX_SERVICE_TYPE_LENGTH} characters)`
105
+ );
106
+ }
107
+
108
+ // Validate format
109
+ if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(serviceType)) {
110
+ throw new ValidationError(
111
+ 'serviceType',
112
+ 'Must be lowercase alphanumeric with hyphens (e.g., "text-generation")'
113
+ );
114
+ }
115
+ return keccak256(toUtf8Bytes(serviceType));
116
+ }
117
+
118
+ // ========== WRITE FUNCTIONS ==========
119
+
120
+ /**
121
+ * Register a new agent profile
122
+ *
123
+ * @param params - Registration parameters
124
+ * @returns Transaction hash
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * await registry.registerAgent({
129
+ * endpoint: 'https://myagent.example.com/webhook',
130
+ * serviceDescriptors: [{
131
+ * serviceTypeHash: registry.computeServiceTypeHash('text-generation'),
132
+ * serviceType: 'text-generation',
133
+ * schemaURI: 'ipfs://Qm...',
134
+ * minPrice: 1_000_000n, // 1 USDC
135
+ * maxPrice: 100_000_000n, // 100 USDC
136
+ * avgCompletionTime: 60,
137
+ * metadataCID: 'Qm...'
138
+ * }]
139
+ * });
140
+ * ```
141
+ */
142
+ async registerAgent(params: RegisterAgentParams): Promise<string> {
143
+ // SECURITY FIX (H-1): Await async endpoint validation (DNS resolution + SSRF check)
144
+ await validateEndpointURL(params.endpoint, 'endpoint');
145
+
146
+ if (!params.serviceDescriptors || params.serviceDescriptors.length === 0) {
147
+ throw new ValidationError('serviceDescriptors', 'At least one service descriptor required');
148
+ }
149
+
150
+ const MAX_SERVICE_DESCRIPTORS = 100;
151
+ if (params.serviceDescriptors.length > MAX_SERVICE_DESCRIPTORS) {
152
+ throw new ValidationError(
153
+ 'serviceDescriptors',
154
+ `Too many service descriptors (max: ${MAX_SERVICE_DESCRIPTORS})`
155
+ );
156
+ }
157
+
158
+ // Validate each service descriptor
159
+ for (const sd of params.serviceDescriptors) {
160
+ const expectedHash = this.computeServiceTypeHash(sd.serviceType);
161
+ if (sd.serviceTypeHash !== expectedHash) {
162
+ throw new ValidationError(
163
+ 'serviceTypeHash',
164
+ `Hash mismatch for ${sd.serviceType}. Expected ${expectedHash}`
165
+ );
166
+ }
167
+
168
+ // C-2: Validate price range
169
+ if (sd.minPrice < 0n) {
170
+ throw new ValidationError('minPrice', 'Minimum price cannot be negative');
171
+ }
172
+ if (sd.maxPrice < 0n) {
173
+ throw new ValidationError('maxPrice', 'Maximum price cannot be negative');
174
+ }
175
+ if (sd.minPrice > sd.maxPrice) {
176
+ throw new ValidationError('priceRange', `minPrice (${sd.minPrice}) cannot exceed maxPrice (${sd.maxPrice})`);
177
+ }
178
+
179
+ // Sanity check: max $1M USDC
180
+ const MAX_PRICE = 1_000_000_000_000n;
181
+ if (sd.maxPrice > MAX_PRICE) {
182
+ throw new ValidationError('maxPrice', 'Price exceeds maximum reasonable value ($1M USDC)');
183
+ }
184
+
185
+ // Validate completion time
186
+ if (sd.avgCompletionTime <= 0) {
187
+ throw new ValidationError('avgCompletionTime', 'Average completion time must be positive');
188
+ }
189
+ const MAX_COMPLETION_TIME = 30 * 24 * 60 * 60; // 30 days
190
+ if (sd.avgCompletionTime > MAX_COMPLETION_TIME) {
191
+ throw new ValidationError('avgCompletionTime', 'Completion time exceeds maximum (30 days)');
192
+ }
193
+ }
194
+
195
+ try {
196
+ const registerFunc = this.contract.getFunction('registerAgent');
197
+
198
+ // Convert to contract format
199
+ const descriptors = params.serviceDescriptors.map(sd => ({
200
+ serviceTypeHash: sd.serviceTypeHash,
201
+ serviceType: sd.serviceType,
202
+ schemaURI: sd.schemaURI,
203
+ minPrice: sd.minPrice,
204
+ maxPrice: sd.maxPrice,
205
+ avgCompletionTime: sd.avgCompletionTime,
206
+ metadataCID: sd.metadataCID
207
+ }));
208
+
209
+ const estimatedGas = await registerFunc.estimateGas(params.endpoint, descriptors);
210
+ const txOptions = this.buildTxOptions(estimatedGas, 'registerAgent');
211
+
212
+ const tx = await registerFunc(params.endpoint, descriptors, txOptions);
213
+ const receipt = await tx.wait(2); // L-2: Wait for 2 confirmations
214
+
215
+ return receipt.hash;
216
+ } catch (error: any) {
217
+ throw new TransactionRevertedError(
218
+ error.transactionHash,
219
+ `Agent registration failed: ${error.reason || error.message}`
220
+ );
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Update agent endpoint URL
226
+ *
227
+ * @param newEndpoint - New webhook/IPFS gateway URL
228
+ */
229
+ async updateEndpoint(newEndpoint: string): Promise<string> {
230
+ // SECURITY FIX (H-1): Await async endpoint validation (DNS resolution + SSRF check)
231
+ await validateEndpointURL(newEndpoint, 'newEndpoint');
232
+
233
+ try {
234
+ const updateFunc = this.contract.getFunction('updateEndpoint');
235
+ const estimatedGas = await updateFunc.estimateGas(newEndpoint);
236
+ const txOptions = this.buildTxOptions(estimatedGas, 'updateEndpoint');
237
+
238
+ const tx = await updateFunc(newEndpoint, txOptions);
239
+ const receipt = await tx.wait(2); // L-2: Wait for 2 confirmations
240
+
241
+ return receipt.hash;
242
+ } catch (error: any) {
243
+ throw new TransactionRevertedError(
244
+ error.transactionHash,
245
+ `Endpoint update failed: ${error.reason || error.message}`
246
+ );
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Add a new service type to agent profile
252
+ *
253
+ * @param serviceType - Lowercase service type (e.g., "code-review")
254
+ */
255
+ async addServiceType(serviceType: string): Promise<string> {
256
+ // Validate format
257
+ this.computeServiceTypeHash(serviceType);
258
+
259
+ try {
260
+ const addFunc = this.contract.getFunction('addServiceType');
261
+ const estimatedGas = await addFunc.estimateGas(serviceType);
262
+ const txOptions = this.buildTxOptions(estimatedGas, 'addServiceType');
263
+
264
+ const tx = await addFunc(serviceType, txOptions);
265
+ const receipt = await tx.wait(2); // L-2: Wait for 2 confirmations
266
+
267
+ return receipt.hash;
268
+ } catch (error: any) {
269
+ throw new TransactionRevertedError(
270
+ error.transactionHash,
271
+ `Add service type failed: ${error.reason || error.message}`
272
+ );
273
+ }
274
+ }
275
+
276
+ /**
277
+ * Remove a service type from agent profile
278
+ *
279
+ * @param serviceTypeHash - Hash of service type to remove
280
+ */
281
+ async removeServiceType(serviceTypeHash: string): Promise<string> {
282
+ // C-3: Validate hash format (bytes32)
283
+ if (!serviceTypeHash || !/^0x[a-fA-F0-9]{64}$/.test(serviceTypeHash)) {
284
+ throw new ValidationError('serviceTypeHash', 'Must be valid bytes32 hex string (0x + 64 hex chars)');
285
+ }
286
+ if (serviceTypeHash === '0x0000000000000000000000000000000000000000000000000000000000000000') {
287
+ throw new ValidationError('serviceTypeHash', 'Cannot be zero hash');
288
+ }
289
+
290
+ try {
291
+ const removeFunc = this.contract.getFunction('removeServiceType');
292
+ const estimatedGas = await removeFunc.estimateGas(serviceTypeHash);
293
+ const txOptions = this.buildTxOptions(estimatedGas, 'removeServiceType');
294
+
295
+ const tx = await removeFunc(serviceTypeHash, txOptions);
296
+ const receipt = await tx.wait(2); // L-2: Wait for 2 confirmations
297
+
298
+ return receipt.hash;
299
+ } catch (error: any) {
300
+ throw new TransactionRevertedError(
301
+ error.transactionHash,
302
+ `Remove service type failed: ${error.reason || error.message}`
303
+ );
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Set agent active/inactive status
309
+ *
310
+ * @param isActive - Whether agent is accepting new requests
311
+ */
312
+ async setActiveStatus(isActive: boolean): Promise<string> {
313
+ try {
314
+ const setFunc = this.contract.getFunction('setActiveStatus');
315
+ const estimatedGas = await setFunc.estimateGas(isActive);
316
+ const txOptions = this.buildTxOptions(estimatedGas, 'setActiveStatus');
317
+
318
+ const tx = await setFunc(isActive, txOptions);
319
+ const receipt = await tx.wait(2); // L-2: Wait for 2 confirmations
320
+
321
+ return receipt.hash;
322
+ } catch (error: any) {
323
+ throw new TransactionRevertedError(
324
+ error.transactionHash,
325
+ `Set active status failed: ${error.reason || error.message}`
326
+ );
327
+ }
328
+ }
329
+
330
+ // ========== READ FUNCTIONS ==========
331
+
332
+ /**
333
+ * Get agent profile by address
334
+ *
335
+ * @param agentAddress - Agent's Ethereum address
336
+ * @returns Agent profile or null if not registered
337
+ */
338
+ async getAgent(agentAddress: string): Promise<AgentProfile | null> {
339
+ validateAddress(agentAddress, 'agentAddress');
340
+
341
+ const profile = await this.contract.getAgent(agentAddress);
342
+
343
+ // Check if registered (registeredAt > 0)
344
+ if (profile.registeredAt === 0n) {
345
+ return null;
346
+ }
347
+
348
+ return this._mapProfile(profile);
349
+ }
350
+
351
+ /**
352
+ * Get agent profile by DID
353
+ *
354
+ * @param did - Agent's DID (e.g., "did:ethr:8453:0x...")
355
+ * @returns Agent profile or null if not found
356
+ */
357
+ async getAgentByDID(did: string): Promise<AgentProfile | null> {
358
+ // H-2: Strengthen DID validation
359
+ const didPattern = /^did:ethr:(\d+):(0x[a-fA-F0-9]{40})$/;
360
+ const match = did.match(didPattern);
361
+
362
+ if (!match) {
363
+ throw new ValidationError(
364
+ 'did',
365
+ 'Invalid DID format. Expected did:ethr:<chainId>:<address> (e.g., did:ethr:84532:0x1234...)'
366
+ );
367
+ }
368
+
369
+ const [, chainIdStr] = match;
370
+
371
+ // Validate chain ID matches
372
+ const currentChainId = await this.getChainId();
373
+ if (parseInt(chainIdStr, 10) !== currentChainId) {
374
+ throw new ValidationError(
375
+ 'did',
376
+ `DID chain ID (${chainIdStr}) does not match registry chain ID (${currentChainId})`
377
+ );
378
+ }
379
+
380
+ const profile = await this.contract.getAgentByDID(did);
381
+
382
+ if (profile.registeredAt === 0n) {
383
+ return null;
384
+ }
385
+
386
+ return this._mapProfile(profile);
387
+ }
388
+
389
+ /**
390
+ * Query agents by service type
391
+ *
392
+ * **IMPORTANT - Query Cap Limitation (L-4)**:
393
+ *
394
+ * This method will throw `QueryCapExceededError` when the registry contains
395
+ * more than 1000 agents. This is an intentional DoS prevention measure.
396
+ *
397
+ * When you encounter this error, migrate to an off-chain indexer:
398
+ * - The Graph: https://thegraph.com/
399
+ * - Goldsky: https://goldsky.com/
400
+ * - Alchemy Subgraphs: https://docs.alchemy.com/docs/subgraphs-overview
401
+ *
402
+ * See `QueryCapExceededError` documentation for event schemas to index.
403
+ *
404
+ * @param params - Query parameters
405
+ * @returns List of agent addresses matching criteria
406
+ * @throws {QueryCapExceededError} When registry exceeds 1000 agents
407
+ * @throws {ValidationError} For invalid parameters
408
+ *
409
+ * @example
410
+ * ```typescript
411
+ * try {
412
+ * const agents = await registry.queryAgentsByService({
413
+ * serviceTypeHash: registry.computeServiceTypeHash('text-generation'),
414
+ * minReputation: 5000,
415
+ * limit: 50
416
+ * });
417
+ * } catch (error) {
418
+ * if (error instanceof QueryCapExceededError) {
419
+ * console.log('Registry too large, use off-chain indexer');
420
+ * // Fallback to your indexer implementation
421
+ * }
422
+ * }
423
+ * ```
424
+ */
425
+ async queryAgentsByService(params: QueryAgentsParams): Promise<string[]> {
426
+ // H-3: Add pagination bounds and validation
427
+ // Validate serviceTypeHash format
428
+ if (!params.serviceTypeHash || !/^0x[a-fA-F0-9]{64}$/.test(params.serviceTypeHash)) {
429
+ throw new ValidationError('serviceTypeHash', 'Must be valid bytes32 hex string');
430
+ }
431
+
432
+ // Validate reputation bounds (0-10000 scale)
433
+ const reputation = params.minReputation ?? 0;
434
+ if (reputation < 0 || reputation > 10000) {
435
+ throw new ValidationError('minReputation', 'Must be between 0 and 10000');
436
+ }
437
+
438
+ // Validate offset
439
+ const offset = params.offset ?? 0;
440
+ if (offset < 0) {
441
+ throw new ValidationError('offset', 'Cannot be negative');
442
+ }
443
+
444
+ // Validate and cap limit
445
+ const MAX_LIMIT = 1000;
446
+ let limit = params.limit ?? 100;
447
+ if (limit <= 0) {
448
+ throw new ValidationError('limit', 'Must be positive');
449
+ }
450
+ if (limit > MAX_LIMIT) {
451
+ limit = MAX_LIMIT; // Cap silently
452
+ }
453
+
454
+ try {
455
+ const agents = await this.contract.queryAgentsByService(
456
+ params.serviceTypeHash,
457
+ reputation,
458
+ offset,
459
+ limit
460
+ );
461
+
462
+ return agents;
463
+ } catch (error: any) {
464
+ // [L-4] Catch query cap exceeded revert and throw descriptive error
465
+ const message = error.message || error.reason || '';
466
+ if (message.includes('Too many agents')) {
467
+ // Extract approximate size from error or use default
468
+ throw new QueryCapExceededError(1001, 1000);
469
+ }
470
+ throw error;
471
+ }
472
+ }
473
+
474
+ /**
475
+ * Get service descriptors for an agent
476
+ *
477
+ * @param agentAddress - Agent's Ethereum address
478
+ * @returns List of service descriptors
479
+ */
480
+ async getServiceDescriptors(agentAddress: string): Promise<ServiceDescriptor[]> {
481
+ validateAddress(agentAddress, 'agentAddress');
482
+
483
+ const descriptors = await this.contract.getServiceDescriptors(agentAddress);
484
+
485
+ return descriptors.map((d: any) => ({
486
+ serviceTypeHash: d.serviceTypeHash,
487
+ serviceType: d.serviceType,
488
+ schemaURI: d.schemaURI,
489
+ minPrice: d.minPrice,
490
+ maxPrice: d.maxPrice,
491
+ avgCompletionTime: Number(d.avgCompletionTime),
492
+ metadataCID: d.metadataCID
493
+ }));
494
+ }
495
+
496
+ /**
497
+ * Check if agent supports a service type
498
+ *
499
+ * @param agentAddress - Agent's Ethereum address
500
+ * @param serviceTypeHash - Service type hash
501
+ * @returns True if supported
502
+ */
503
+ async supportsService(agentAddress: string, serviceTypeHash: string): Promise<boolean> {
504
+ validateAddress(agentAddress, 'agentAddress');
505
+ return await this.contract.supportsService(agentAddress, serviceTypeHash);
506
+ }
507
+
508
+ /**
509
+ * Get the chain ID used for DID generation
510
+ */
511
+ async getChainId(): Promise<number> {
512
+ return Number(await this.contract.chainId());
513
+ }
514
+
515
+ /**
516
+ * Build a DID for an address on the current chain
517
+ *
518
+ * @param address - Ethereum address
519
+ * @returns DID string (e.g., "did:ethr:8453:0x...")
520
+ */
521
+ async buildDID(address: string): Promise<string> {
522
+ validateAddress(address, 'address');
523
+ const chainId = await this.getChainId();
524
+ return `did:ethr:${chainId}:${address.toLowerCase()}`;
525
+ }
526
+
527
+ // ========== PRIVATE HELPERS ==========
528
+
529
+ /**
530
+ * Safely convert bigint to number, throwing if precision would be lost
531
+ */
532
+ private safeToNumber(value: bigint | number, fieldName: string): number {
533
+ const bigIntValue = typeof value === 'bigint' ? value : BigInt(value);
534
+ if (bigIntValue > BigInt(Number.MAX_SAFE_INTEGER)) {
535
+ throw new Error(`${fieldName} exceeds JavaScript MAX_SAFE_INTEGER`);
536
+ }
537
+ if (bigIntValue < BigInt(Number.MIN_SAFE_INTEGER)) {
538
+ throw new Error(`${fieldName} below JavaScript MIN_SAFE_INTEGER`);
539
+ }
540
+ return Number(bigIntValue);
541
+ }
542
+
543
+ private _mapProfile(profile: any): AgentProfile {
544
+ return {
545
+ agentAddress: profile.agentAddress,
546
+ did: profile.did,
547
+ endpoint: profile.endpoint,
548
+ serviceTypes: [...profile.serviceTypes], // H-4: Clone array
549
+ stakedAmount: profile.stakedAmount,
550
+ reputationScore: this.safeToNumber(profile.reputationScore, 'reputationScore'),
551
+ totalTransactions: this.safeToNumber(profile.totalTransactions, 'totalTransactions'),
552
+ disputedTransactions: this.safeToNumber(profile.disputedTransactions, 'disputedTransactions'),
553
+ totalVolumeUSDC: profile.totalVolumeUSDC,
554
+ registeredAt: this.safeToNumber(profile.registeredAt, 'registeredAt'),
555
+ updatedAt: this.safeToNumber(profile.updatedAt, 'updatedAt'),
556
+ isActive: Boolean(profile.isActive)
557
+ };
558
+ }
559
+ }