@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,231 @@
1
+ /**
2
+ * BaseAdapter - Abstract base class for all adapter implementations
3
+ *
4
+ * Provides shared utility methods for parsing user-friendly inputs into
5
+ * protocol-level types. All adapters extend this class to ensure consistent
6
+ * behavior across the Three-Level API.
7
+ *
8
+ * Key Responsibilities:
9
+ * - Amount parsing (string → bigint with 6 decimals for USDC)
10
+ * - Address validation (0x-prefixed hex)
11
+ * - Deadline parsing ("+24h" → Unix timestamp)
12
+ * - User-friendly error messages
13
+ *
14
+ * @module adapters/BaseAdapter
15
+ */
16
+ /**
17
+ * Default dispute window in seconds (2 days).
18
+ * Used when no dispute window is specified in transaction parameters.
19
+ */
20
+ export declare const DEFAULT_DISPUTE_WINDOW_SECONDS = 172800;
21
+ /**
22
+ * Minimum dispute window in seconds (1 hour).
23
+ * Ensures requesters have reasonable time to dispute.
24
+ *
25
+ * SECURITY: Prevents providers from setting windows too short
26
+ * to avoid dispute detection.
27
+ */
28
+ export declare const MIN_DISPUTE_WINDOW_SECONDS = 3600;
29
+ /**
30
+ * Maximum dispute window in seconds (30 days).
31
+ * Prevents excessively long fund locks.
32
+ *
33
+ * SECURITY: Prevents DoS via indefinite fund locking.
34
+ */
35
+ export declare const MAX_DISPUTE_WINDOW_SECONDS: number;
36
+ /**
37
+ * Default deadline offset in seconds (24 hours).
38
+ * Used when no deadline is specified in transaction parameters.
39
+ */
40
+ export declare const DEFAULT_DEADLINE_SECONDS = 86400;
41
+ /**
42
+ * Minimum transaction amount in USDC wei (6 decimals).
43
+ * $0.05 minimum per AGIRAILS protocol specification.
44
+ */
45
+ export declare const MIN_AMOUNT_WEI = 50000n;
46
+ /**
47
+ * Maximum deadline in hours (10 years).
48
+ * Prevents integer overflow in deadline calculations.
49
+ */
50
+ export declare const MAX_DEADLINE_HOURS = 87600;
51
+ /**
52
+ * Maximum deadline in days (10 years).
53
+ * Prevents integer overflow in deadline calculations.
54
+ */
55
+ export declare const MAX_DEADLINE_DAYS = 3650;
56
+ /**
57
+ * Custom error for validation failures.
58
+ *
59
+ * Thrown when user input is invalid (e.g., malformed address, negative amount).
60
+ * Provides descriptive error messages for end-user debugging.
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * throw new ValidationError('Invalid amount format: "abc". Expected number like "100" or "100.50"');
65
+ * ```
66
+ */
67
+ export declare class ValidationError extends Error {
68
+ constructor(message: string);
69
+ }
70
+ /**
71
+ * Abstract base adapter with shared parsing utilities.
72
+ *
73
+ * Provides common functionality for all adapter implementations:
74
+ * - Amount parsing (USDC has 6 decimals)
75
+ * - Address validation
76
+ * - Deadline parsing (relative time or Unix timestamp)
77
+ * - Amount formatting
78
+ *
79
+ * @abstract
80
+ */
81
+ export declare abstract class BaseAdapter {
82
+ protected requesterAddress: string;
83
+ /**
84
+ * Creates a new BaseAdapter instance.
85
+ *
86
+ * @param requesterAddress - The requester's Ethereum address
87
+ */
88
+ constructor(requesterAddress: string);
89
+ /**
90
+ * Parse user-friendly amount string to bigint (USDC has 6 decimals).
91
+ *
92
+ * Accepts multiple input formats:
93
+ * - "100" → 100_000_000n (100.00 USDC)
94
+ * - "100.50" → 100_500_000n (100.50 USDC)
95
+ * - "100 USDC" → 100_000_000n (strips currency suffix)
96
+ * - "$100" → 100_000_000n (strips $ prefix)
97
+ * - 100 (number) → 100_000_000n
98
+ *
99
+ * Rejects:
100
+ * - "abc" → throws ValidationError
101
+ * - "" → throws ValidationError
102
+ * - "-100" → throws ValidationError (negative amounts)
103
+ * - "100.1234567" → throws ValidationError (too many decimals)
104
+ *
105
+ * @param amount - Amount as string or number
106
+ * @returns Amount as bigint with 6 decimals
107
+ * @throws {ValidationError} If amount format is invalid
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const amount = this.parseAmount("100.50"); // 100_500_000n
112
+ * const amount = this.parseAmount("100 USDC"); // 100_000_000n
113
+ * ```
114
+ */
115
+ protected parseAmount(amount: string | number): bigint;
116
+ /**
117
+ * Validate Ethereum address format.
118
+ *
119
+ * Checks that address:
120
+ * - Is a string
121
+ * - Starts with "0x"
122
+ * - Is exactly 42 characters (0x + 40 hex chars)
123
+ * - Contains only valid hex characters
124
+ *
125
+ * Note: Does not validate checksum (EIP-55) in mock mode.
126
+ *
127
+ * @param address - Address to validate
128
+ * @param paramName - Parameter name for error message
129
+ * @returns Validated address (unchanged)
130
+ * @throws {ValidationError} If address format is invalid
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const provider = this.validateAddress(params.to, 'to');
135
+ * ```
136
+ */
137
+ protected validateAddress(address: string, paramName: string): string;
138
+ /**
139
+ * Parse deadline from relative time expression or Unix timestamp.
140
+ *
141
+ * Accepts multiple formats:
142
+ * - undefined → now + 24 hours (default)
143
+ * - 1734076400 (number) → passed through as Unix timestamp
144
+ * - "+1h" → now + 1 hour
145
+ * - "+24h" → now + 24 hours
146
+ * - "+7d" → now + 7 days
147
+ *
148
+ * Rejects:
149
+ * - "invalid" → throws ValidationError
150
+ * - "-24h" → throws ValidationError (negative time)
151
+ *
152
+ * @param deadline - Deadline as relative time string, Unix timestamp, or undefined
153
+ * @param currentTime - Current time in seconds (defaults to Date.now() / 1000)
154
+ * @returns Unix timestamp in seconds
155
+ * @throws {ValidationError} If deadline format is invalid
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const deadline = this.parseDeadline("+24h"); // now + 86400
160
+ * const deadline = this.parseDeadline(1734076400); // 1734076400
161
+ * const deadline = this.parseDeadline(); // now + 86400 (default)
162
+ * ```
163
+ */
164
+ protected parseDeadline(deadline?: string | number, currentTime?: number): number;
165
+ /**
166
+ * Validate and normalize dispute window.
167
+ *
168
+ * SECURITY FIX (L-1): Enforces bounds on dispute window:
169
+ * - Minimum: 1 hour (prevents skipping disputes)
170
+ * - Maximum: 30 days (prevents indefinite fund locking)
171
+ *
172
+ * @param disputeWindow - Dispute window in seconds (undefined uses default)
173
+ * @returns Validated dispute window in seconds
174
+ * @throws {ValidationError} If window is outside allowed bounds
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * this.validateDisputeWindow(3600); // 1 hour - OK
179
+ * this.validateDisputeWindow(86400); // 1 day - OK
180
+ * this.validateDisputeWindow(100); // Too short - throws
181
+ * this.validateDisputeWindow(31 * 86400); // Too long - throws
182
+ * ```
183
+ */
184
+ protected validateDisputeWindow(disputeWindow?: number): number;
185
+ /**
186
+ * Validate bytes32 hex string format.
187
+ *
188
+ * SECURITY FIX (L-2): Validates that a string is a valid bytes32 hex.
189
+ * Used for transaction IDs, escrow IDs, attestation UIDs, etc.
190
+ *
191
+ * @param value - Value to validate
192
+ * @param paramName - Parameter name for error message
193
+ * @returns Validated bytes32 string (normalized to lowercase)
194
+ * @throws {ValidationError} If format is invalid
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * const txId = this.validateBytes32(id, 'transactionId');
199
+ * ```
200
+ */
201
+ protected validateBytes32(value: string, paramName: string): string;
202
+ /**
203
+ * Validate Unix timestamp is reasonable.
204
+ *
205
+ * SECURITY FIX (L-6): Validates timestamps to prevent overflow/underflow.
206
+ *
207
+ * @param timestamp - Unix timestamp in seconds
208
+ * @param paramName - Parameter name for error message
209
+ * @returns Validated timestamp
210
+ * @throws {ValidationError} If timestamp is invalid
211
+ */
212
+ protected validateTimestamp(timestamp: number, paramName: string): number;
213
+ /**
214
+ * Format bigint amount to human-readable string.
215
+ *
216
+ * Converts USDC wei (6 decimals) to formatted string with 2 decimal places.
217
+ * Uses proper rounding (round half up) for display purposes.
218
+ *
219
+ * @param amount - Amount as bigint (6 decimals) or string
220
+ * @returns Formatted string like "100.00 USDC"
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * this.formatAmount(100_000_000n); // "100.00 USDC"
225
+ * this.formatAmount(100_500_000n); // "100.50 USDC"
226
+ * this.formatAmount(100_126_000n); // "100.13 USDC" (rounded)
227
+ * ```
228
+ */
229
+ protected formatAmount(amount: bigint | string): string;
230
+ }
231
+ //# sourceMappingURL=BaseAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/BaseAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH;;;GAGG;AACH,eAAO,MAAM,8BAA8B,SAAS,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAAiB,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,wBAAwB,QAAQ,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,cAAc,SAAU,CAAC;AAEtC;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;GAUG;AACH,8BAAsB,WAAW;IAMnB,SAAS,CAAC,gBAAgB,EAAE,MAAM;IAL9C;;;;OAIG;gBACmB,gBAAgB,EAAE,MAAM;IAE9C;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAqDtD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;IAiCrE;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM;IAwCjF;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,qBAAqB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM;IAsB/D;;;;;;;;;;;;;;;OAeG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;IAgCnE;;;;;;;;;OASG;IACH,SAAS,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;IAkCzE;;;;;;;;;;;;;;;OAeG;IACH,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;CAoBxD"}
@@ -0,0 +1,393 @@
1
+ "use strict";
2
+ /**
3
+ * BaseAdapter - Abstract base class for all adapter implementations
4
+ *
5
+ * Provides shared utility methods for parsing user-friendly inputs into
6
+ * protocol-level types. All adapters extend this class to ensure consistent
7
+ * behavior across the Three-Level API.
8
+ *
9
+ * Key Responsibilities:
10
+ * - Amount parsing (string → bigint with 6 decimals for USDC)
11
+ * - Address validation (0x-prefixed hex)
12
+ * - Deadline parsing ("+24h" → Unix timestamp)
13
+ * - User-friendly error messages
14
+ *
15
+ * @module adapters/BaseAdapter
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.BaseAdapter = exports.ValidationError = exports.MAX_DEADLINE_DAYS = exports.MAX_DEADLINE_HOURS = exports.MIN_AMOUNT_WEI = exports.DEFAULT_DEADLINE_SECONDS = exports.MAX_DISPUTE_WINDOW_SECONDS = exports.MIN_DISPUTE_WINDOW_SECONDS = exports.DEFAULT_DISPUTE_WINDOW_SECONDS = void 0;
19
+ // ============================================================================
20
+ // Constants
21
+ // ============================================================================
22
+ /**
23
+ * Default dispute window in seconds (2 days).
24
+ * Used when no dispute window is specified in transaction parameters.
25
+ */
26
+ exports.DEFAULT_DISPUTE_WINDOW_SECONDS = 172800;
27
+ /**
28
+ * Minimum dispute window in seconds (1 hour).
29
+ * Ensures requesters have reasonable time to dispute.
30
+ *
31
+ * SECURITY: Prevents providers from setting windows too short
32
+ * to avoid dispute detection.
33
+ */
34
+ exports.MIN_DISPUTE_WINDOW_SECONDS = 3600; // 1 hour
35
+ /**
36
+ * Maximum dispute window in seconds (30 days).
37
+ * Prevents excessively long fund locks.
38
+ *
39
+ * SECURITY: Prevents DoS via indefinite fund locking.
40
+ */
41
+ exports.MAX_DISPUTE_WINDOW_SECONDS = 30 * 24 * 3600; // 30 days
42
+ /**
43
+ * Default deadline offset in seconds (24 hours).
44
+ * Used when no deadline is specified in transaction parameters.
45
+ */
46
+ exports.DEFAULT_DEADLINE_SECONDS = 86400;
47
+ /**
48
+ * Minimum transaction amount in USDC wei (6 decimals).
49
+ * $0.05 minimum per AGIRAILS protocol specification.
50
+ */
51
+ exports.MIN_AMOUNT_WEI = 50000n; // $0.05 USDC
52
+ /**
53
+ * Maximum deadline in hours (10 years).
54
+ * Prevents integer overflow in deadline calculations.
55
+ */
56
+ exports.MAX_DEADLINE_HOURS = 87600; // 10 years
57
+ /**
58
+ * Maximum deadline in days (10 years).
59
+ * Prevents integer overflow in deadline calculations.
60
+ */
61
+ exports.MAX_DEADLINE_DAYS = 3650; // 10 years
62
+ /**
63
+ * Custom error for validation failures.
64
+ *
65
+ * Thrown when user input is invalid (e.g., malformed address, negative amount).
66
+ * Provides descriptive error messages for end-user debugging.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * throw new ValidationError('Invalid amount format: "abc". Expected number like "100" or "100.50"');
71
+ * ```
72
+ */
73
+ class ValidationError extends Error {
74
+ constructor(message) {
75
+ super(message);
76
+ this.name = 'ValidationError';
77
+ }
78
+ }
79
+ exports.ValidationError = ValidationError;
80
+ /**
81
+ * Abstract base adapter with shared parsing utilities.
82
+ *
83
+ * Provides common functionality for all adapter implementations:
84
+ * - Amount parsing (USDC has 6 decimals)
85
+ * - Address validation
86
+ * - Deadline parsing (relative time or Unix timestamp)
87
+ * - Amount formatting
88
+ *
89
+ * @abstract
90
+ */
91
+ class BaseAdapter {
92
+ /**
93
+ * Creates a new BaseAdapter instance.
94
+ *
95
+ * @param requesterAddress - The requester's Ethereum address
96
+ */
97
+ constructor(requesterAddress) {
98
+ this.requesterAddress = requesterAddress;
99
+ }
100
+ /**
101
+ * Parse user-friendly amount string to bigint (USDC has 6 decimals).
102
+ *
103
+ * Accepts multiple input formats:
104
+ * - "100" → 100_000_000n (100.00 USDC)
105
+ * - "100.50" → 100_500_000n (100.50 USDC)
106
+ * - "100 USDC" → 100_000_000n (strips currency suffix)
107
+ * - "$100" → 100_000_000n (strips $ prefix)
108
+ * - 100 (number) → 100_000_000n
109
+ *
110
+ * Rejects:
111
+ * - "abc" → throws ValidationError
112
+ * - "" → throws ValidationError
113
+ * - "-100" → throws ValidationError (negative amounts)
114
+ * - "100.1234567" → throws ValidationError (too many decimals)
115
+ *
116
+ * @param amount - Amount as string or number
117
+ * @returns Amount as bigint with 6 decimals
118
+ * @throws {ValidationError} If amount format is invalid
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const amount = this.parseAmount("100.50"); // 100_500_000n
123
+ * const amount = this.parseAmount("100 USDC"); // 100_000_000n
124
+ * ```
125
+ */
126
+ parseAmount(amount) {
127
+ // Issue #3 Fix: Normalize input - handle all Unicode whitespace
128
+ // Converts all Unicode whitespace to regular spaces, then strip currency symbols
129
+ let normalized = String(amount)
130
+ .replace(/[\s\u00A0\u2000-\u200B\uFEFF]/g, ' ') // Replace all Unicode whitespace with regular space
131
+ .replace(/^[\$]/, '') // Strip leading $
132
+ .replace(/\s*(USDC|usdc)$/, '') // Strip trailing USDC
133
+ .replace(/,/g, '') // Strip thousands separators
134
+ .replace(/\s+/g, '') // Remove ALL whitespace (including normalized Unicode spaces)
135
+ .trim(); // Final trim for edge cases
136
+ // Check for negative
137
+ if (normalized.startsWith('-')) {
138
+ throw new ValidationError('Amount cannot be negative');
139
+ }
140
+ // Validate format (integer or decimal with up to 6 decimal places)
141
+ if (!/^\d+(\.\d{1,6})?$/.test(normalized)) {
142
+ throw new ValidationError(`Invalid amount format: "${amount}". Expected number like "100" or "100.50"`);
143
+ }
144
+ // Parse to bigint with 6 decimals
145
+ try {
146
+ const parts = normalized.split('.');
147
+ const wholePart = parts[0];
148
+ const decimalPart = (parts[1] || '').padEnd(6, '0'); // Pad to 6 decimals
149
+ const wholeAmount = BigInt(wholePart) * 1000000n;
150
+ const decimalAmount = BigInt(decimalPart);
151
+ const totalAmount = wholeAmount + decimalAmount;
152
+ // M1 Fix: Enforce minimum amount ($0.05 USDC = 50,000 wei)
153
+ if (totalAmount < exports.MIN_AMOUNT_WEI) {
154
+ throw new ValidationError(`Amount too small: "${amount}". Minimum transaction is $0.05 USDC`);
155
+ }
156
+ return totalAmount;
157
+ }
158
+ catch (error) {
159
+ // Re-throw ValidationError as-is
160
+ if (error instanceof ValidationError) {
161
+ throw error;
162
+ }
163
+ throw new ValidationError(`Failed to parse amount: "${amount}". Please use format like "100" or "100.50"`);
164
+ }
165
+ }
166
+ /**
167
+ * Validate Ethereum address format.
168
+ *
169
+ * Checks that address:
170
+ * - Is a string
171
+ * - Starts with "0x"
172
+ * - Is exactly 42 characters (0x + 40 hex chars)
173
+ * - Contains only valid hex characters
174
+ *
175
+ * Note: Does not validate checksum (EIP-55) in mock mode.
176
+ *
177
+ * @param address - Address to validate
178
+ * @param paramName - Parameter name for error message
179
+ * @returns Validated address (unchanged)
180
+ * @throws {ValidationError} If address format is invalid
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const provider = this.validateAddress(params.to, 'to');
185
+ * ```
186
+ */
187
+ validateAddress(address, paramName) {
188
+ if (typeof address !== 'string') {
189
+ throw new ValidationError(`Invalid ${paramName} address: expected string, got ${typeof address}`);
190
+ }
191
+ // Check 0x prefix
192
+ if (!address.startsWith('0x')) {
193
+ throw new ValidationError(`Invalid ${paramName} address: "${address}". Expected 0x-prefixed hex string.`);
194
+ }
195
+ // Check length (0x + 40 hex chars = 42 total)
196
+ if (address.length !== 42) {
197
+ throw new ValidationError(`Invalid ${paramName} address: "${address}". Expected 42 characters (0x + 40 hex).`);
198
+ }
199
+ // Check hex format
200
+ if (!/^0x[0-9a-fA-F]{40}$/.test(address)) {
201
+ throw new ValidationError(`Invalid ${paramName} address: "${address}". Contains invalid hex characters.`);
202
+ }
203
+ // Issue #2 Fix: Normalize to lowercase for consistency
204
+ // This prevents case-sensitivity issues when comparing addresses
205
+ return address.toLowerCase();
206
+ }
207
+ /**
208
+ * Parse deadline from relative time expression or Unix timestamp.
209
+ *
210
+ * Accepts multiple formats:
211
+ * - undefined → now + 24 hours (default)
212
+ * - 1734076400 (number) → passed through as Unix timestamp
213
+ * - "+1h" → now + 1 hour
214
+ * - "+24h" → now + 24 hours
215
+ * - "+7d" → now + 7 days
216
+ *
217
+ * Rejects:
218
+ * - "invalid" → throws ValidationError
219
+ * - "-24h" → throws ValidationError (negative time)
220
+ *
221
+ * @param deadline - Deadline as relative time string, Unix timestamp, or undefined
222
+ * @param currentTime - Current time in seconds (defaults to Date.now() / 1000)
223
+ * @returns Unix timestamp in seconds
224
+ * @throws {ValidationError} If deadline format is invalid
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * const deadline = this.parseDeadline("+24h"); // now + 86400
229
+ * const deadline = this.parseDeadline(1734076400); // 1734076400
230
+ * const deadline = this.parseDeadline(); // now + 86400 (default)
231
+ * ```
232
+ */
233
+ parseDeadline(deadline, currentTime) {
234
+ const now = currentTime ?? Math.floor(Date.now() / 1000);
235
+ if (deadline === undefined) {
236
+ // Default: 24 hours from now
237
+ return now + exports.DEFAULT_DEADLINE_SECONDS;
238
+ }
239
+ if (typeof deadline === 'number') {
240
+ return deadline;
241
+ }
242
+ // Parse relative time
243
+ const match = deadline.match(/^\+(\d+)(h|d)$/);
244
+ if (!match) {
245
+ throw new ValidationError(`Invalid deadline format: "${deadline}". Expected Unix timestamp or relative time (e.g., "+24h", "+7d")`);
246
+ }
247
+ const [, amountStr, unit] = match;
248
+ const amount = parseInt(amountStr, 10);
249
+ // H1 Fix: Add bounds check to prevent integer overflow
250
+ if (unit === 'h' && amount > exports.MAX_DEADLINE_HOURS) {
251
+ throw new ValidationError(`Deadline too far in future: "${deadline}". Maximum is 10 years (${exports.MAX_DEADLINE_HOURS}h)`);
252
+ }
253
+ if (unit === 'd' && amount > exports.MAX_DEADLINE_DAYS) {
254
+ throw new ValidationError(`Deadline too far in future: "${deadline}". Maximum is 10 years (${exports.MAX_DEADLINE_DAYS}d)`);
255
+ }
256
+ const multiplier = unit === 'h' ? 3600 : 86400;
257
+ return now + amount * multiplier;
258
+ }
259
+ /**
260
+ * Validate and normalize dispute window.
261
+ *
262
+ * SECURITY FIX (L-1): Enforces bounds on dispute window:
263
+ * - Minimum: 1 hour (prevents skipping disputes)
264
+ * - Maximum: 30 days (prevents indefinite fund locking)
265
+ *
266
+ * @param disputeWindow - Dispute window in seconds (undefined uses default)
267
+ * @returns Validated dispute window in seconds
268
+ * @throws {ValidationError} If window is outside allowed bounds
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * this.validateDisputeWindow(3600); // 1 hour - OK
273
+ * this.validateDisputeWindow(86400); // 1 day - OK
274
+ * this.validateDisputeWindow(100); // Too short - throws
275
+ * this.validateDisputeWindow(31 * 86400); // Too long - throws
276
+ * ```
277
+ */
278
+ validateDisputeWindow(disputeWindow) {
279
+ if (disputeWindow === undefined) {
280
+ return exports.DEFAULT_DISPUTE_WINDOW_SECONDS;
281
+ }
282
+ if (disputeWindow < exports.MIN_DISPUTE_WINDOW_SECONDS) {
283
+ throw new ValidationError(`Dispute window too short: ${disputeWindow} seconds. ` +
284
+ `Minimum is ${exports.MIN_DISPUTE_WINDOW_SECONDS} seconds (1 hour).`);
285
+ }
286
+ if (disputeWindow > exports.MAX_DISPUTE_WINDOW_SECONDS) {
287
+ throw new ValidationError(`Dispute window too long: ${disputeWindow} seconds. ` +
288
+ `Maximum is ${exports.MAX_DISPUTE_WINDOW_SECONDS} seconds (30 days).`);
289
+ }
290
+ return disputeWindow;
291
+ }
292
+ /**
293
+ * Validate bytes32 hex string format.
294
+ *
295
+ * SECURITY FIX (L-2): Validates that a string is a valid bytes32 hex.
296
+ * Used for transaction IDs, escrow IDs, attestation UIDs, etc.
297
+ *
298
+ * @param value - Value to validate
299
+ * @param paramName - Parameter name for error message
300
+ * @returns Validated bytes32 string (normalized to lowercase)
301
+ * @throws {ValidationError} If format is invalid
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const txId = this.validateBytes32(id, 'transactionId');
306
+ * ```
307
+ */
308
+ validateBytes32(value, paramName) {
309
+ if (typeof value !== 'string') {
310
+ throw new ValidationError(`Invalid ${paramName}: expected string, got ${typeof value}`);
311
+ }
312
+ // Check 0x prefix
313
+ if (!value.startsWith('0x')) {
314
+ throw new ValidationError(`Invalid ${paramName}: "${value}". Expected 0x-prefixed bytes32 (66 characters total).`);
315
+ }
316
+ // Check length (0x + 64 hex chars = 66 total)
317
+ if (value.length !== 66) {
318
+ throw new ValidationError(`Invalid ${paramName}: "${value}". Expected 66 characters (0x + 64 hex), got ${value.length}.`);
319
+ }
320
+ // Check hex format
321
+ if (!/^0x[0-9a-fA-F]{64}$/.test(value)) {
322
+ throw new ValidationError(`Invalid ${paramName}: "${value}". Contains invalid hex characters.`);
323
+ }
324
+ // Normalize to lowercase
325
+ return value.toLowerCase();
326
+ }
327
+ /**
328
+ * Validate Unix timestamp is reasonable.
329
+ *
330
+ * SECURITY FIX (L-6): Validates timestamps to prevent overflow/underflow.
331
+ *
332
+ * @param timestamp - Unix timestamp in seconds
333
+ * @param paramName - Parameter name for error message
334
+ * @returns Validated timestamp
335
+ * @throws {ValidationError} If timestamp is invalid
336
+ */
337
+ validateTimestamp(timestamp, paramName) {
338
+ // Check it's a number
339
+ if (typeof timestamp !== 'number' || isNaN(timestamp)) {
340
+ throw new ValidationError(`Invalid ${paramName}: expected number, got ${typeof timestamp}`);
341
+ }
342
+ // Check it's positive
343
+ if (timestamp <= 0) {
344
+ throw new ValidationError(`Invalid ${paramName}: timestamp must be positive`);
345
+ }
346
+ // Check it's not in the past (with 1 minute buffer)
347
+ const now = Math.floor(Date.now() / 1000);
348
+ const oneMinuteAgo = now - 60;
349
+ // Only apply this check if it looks like a deadline/future timestamp
350
+ // (e.g., createdAt can be in the past)
351
+ // For now, just validate it's reasonable
352
+ // Check for overflow (year 3000 = ~32503680000)
353
+ const year3000 = 32503680000;
354
+ if (timestamp > year3000) {
355
+ throw new ValidationError(`Invalid ${paramName}: timestamp ${timestamp} is too far in the future (overflow prevention)`);
356
+ }
357
+ return timestamp;
358
+ }
359
+ /**
360
+ * Format bigint amount to human-readable string.
361
+ *
362
+ * Converts USDC wei (6 decimals) to formatted string with 2 decimal places.
363
+ * Uses proper rounding (round half up) for display purposes.
364
+ *
365
+ * @param amount - Amount as bigint (6 decimals) or string
366
+ * @returns Formatted string like "100.00 USDC"
367
+ *
368
+ * @example
369
+ * ```typescript
370
+ * this.formatAmount(100_000_000n); // "100.00 USDC"
371
+ * this.formatAmount(100_500_000n); // "100.50 USDC"
372
+ * this.formatAmount(100_126_000n); // "100.13 USDC" (rounded)
373
+ * ```
374
+ */
375
+ formatAmount(amount) {
376
+ const amountBigInt = typeof amount === 'string' ? BigInt(amount) : amount;
377
+ // Convert from 6 decimals to decimal string
378
+ const wholePart = amountBigInt / 1000000n;
379
+ const decimalPart = amountBigInt % 1000000n;
380
+ // M3 Fix: Proper rounding to 2 decimal places (round half up)
381
+ // decimalPart is 0-999999, we need to round to nearest 10000 (cents)
382
+ const decimalNum = Number(decimalPart);
383
+ const roundedCents = Math.round(decimalNum / 10000); // 6 decimals → 2 decimals
384
+ // Handle case where rounding causes overflow (e.g., 99.999999 → 100.00)
385
+ if (roundedCents >= 100) {
386
+ return `${wholePart + 1n}.00 USDC`;
387
+ }
388
+ const formattedDecimal = roundedCents.toString().padStart(2, '0');
389
+ return `${wholePart}.${formattedDecimal} USDC`;
390
+ }
391
+ }
392
+ exports.BaseAdapter = BaseAdapter;
393
+ //# sourceMappingURL=BaseAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseAdapter.js","sourceRoot":"","sources":["../../src/adapters/BaseAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E;;;GAGG;AACU,QAAA,8BAA8B,GAAG,MAAM,CAAC;AAErD;;;;;;GAMG;AACU,QAAA,0BAA0B,GAAG,IAAI,CAAC,CAAC,SAAS;AAEzD;;;;;GAKG;AACU,QAAA,0BAA0B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,UAAU;AAEpE;;;GAGG;AACU,QAAA,wBAAwB,GAAG,KAAK,CAAC;AAE9C;;;GAGG;AACU,QAAA,cAAc,GAAG,MAAO,CAAC,CAAC,aAAa;AAEpD;;;GAGG;AACU,QAAA,kBAAkB,GAAG,KAAK,CAAC,CAAC,WAAW;AAEpD;;;GAGG;AACU,QAAA,iBAAiB,GAAG,IAAI,CAAC,CAAC,WAAW;AAElD;;;;;;;;;;GAUG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAED;;;;;;;;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