voltaire-effect 0.2.23 → 0.2.25

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 (397) hide show
  1. package/dist/KZGService-B7PJerOb.d.ts +146 -0
  2. package/dist/ProviderService-BZ5pqDrD.d.ts +319 -0
  3. package/dist/{X25519Test-DGsk1V9o.d.ts → X25519Test-D5Q-5fL9.d.ts} +4 -143
  4. package/dist/crypto/index.d.ts +5 -6
  5. package/dist/crypto/index.js +227 -201
  6. package/dist/{index-IgkEHjBe.d.ts → index-BCOuszKZ.d.ts} +17634 -11962
  7. package/dist/index.d.ts +3195 -976
  8. package/dist/index.js +6994 -4679
  9. package/dist/native/index.d.ts +25 -16
  10. package/dist/native/index.js +7020 -4705
  11. package/dist/primitives/index.d.ts +14 -8
  12. package/dist/primitives/index.js +4060 -2539
  13. package/dist/services/index.d.ts +9054 -30
  14. package/dist/services/index.js +1592 -1331
  15. package/package.json +2 -2
  16. package/src/crypto/ERC6492/ERC6492.test.ts +32 -14
  17. package/src/crypto/ERC6492/verifySignature.ts +4 -5
  18. package/src/crypto/Keccak256/Keccak256.test.ts +42 -1
  19. package/src/crypto/Keccak256/hashSync.ts +53 -0
  20. package/src/crypto/Keccak256/index.ts +2 -0
  21. package/src/index.ts +7 -2
  22. package/src/primitives/Abi/decode.test.ts +38 -0
  23. package/src/primitives/Abi/decode.ts +67 -0
  24. package/src/primitives/Abi/decodeData.test.ts +37 -0
  25. package/src/primitives/Abi/decodeData.ts +77 -0
  26. package/src/primitives/Abi/decodeLog.test.ts +32 -0
  27. package/src/primitives/Abi/decodeLog.ts +81 -0
  28. package/src/primitives/Abi/decodeWrappedError.test.ts +41 -0
  29. package/src/primitives/Abi/decodeWrappedError.ts +68 -0
  30. package/src/primitives/Abi/encode.test.ts +43 -0
  31. package/src/primitives/Abi/encode.ts +67 -0
  32. package/src/primitives/Abi/encodePacked.test.ts +35 -0
  33. package/src/primitives/Abi/encodePacked.ts +62 -0
  34. package/src/primitives/Abi/encodeWrappedError.test.ts +21 -0
  35. package/src/primitives/Abi/encodeWrappedError.ts +64 -0
  36. package/src/primitives/Abi/findSelectorCollisions.test.ts +50 -0
  37. package/src/primitives/Abi/findSelectorCollisions.ts +83 -0
  38. package/src/primitives/Abi/index.ts +33 -7
  39. package/src/primitives/Abi/parseLogs.test.ts +37 -0
  40. package/src/primitives/Abi/parseLogs.ts +62 -0
  41. package/src/primitives/AccessList/AccessList.test.ts +229 -0
  42. package/src/primitives/AccessList/AccessListTypeSchema.ts +16 -0
  43. package/src/primitives/AccessList/addressCount.ts +21 -0
  44. package/src/primitives/AccessList/assertValid.ts +37 -0
  45. package/src/primitives/AccessList/create.ts +19 -0
  46. package/src/primitives/AccessList/deduplicate.ts +23 -0
  47. package/src/primitives/AccessList/from.ts +39 -0
  48. package/src/primitives/AccessList/fromBytes.ts +36 -0
  49. package/src/primitives/AccessList/gasCost.ts +22 -0
  50. package/src/primitives/AccessList/gasSavings.ts +26 -0
  51. package/src/primitives/AccessList/hasSavings.ts +23 -0
  52. package/src/primitives/AccessList/includesAddress.ts +25 -0
  53. package/src/primitives/AccessList/includesStorageKey.ts +28 -0
  54. package/src/primitives/AccessList/index.ts +99 -19
  55. package/src/primitives/AccessList/is.ts +23 -0
  56. package/src/primitives/AccessList/isEmpty.ts +23 -0
  57. package/src/primitives/AccessList/isItem.ts +22 -0
  58. package/src/primitives/AccessList/keysFor.ts +29 -0
  59. package/src/primitives/AccessList/merge.ts +24 -0
  60. package/src/primitives/AccessList/storageKeyCount.ts +21 -0
  61. package/src/primitives/AccessList/toBytes.ts +23 -0
  62. package/src/primitives/AccessList/withAddress.ts +27 -0
  63. package/src/primitives/AccessList/withStorageKey.ts +30 -0
  64. package/src/primitives/Address/Address.test.ts +146 -0
  65. package/src/primitives/Address/assert.ts +51 -0
  66. package/src/primitives/Address/calculateCreate2Address.ts +33 -0
  67. package/src/primitives/Address/calculateCreateAddress.ts +30 -0
  68. package/src/primitives/Address/deduplicateAddresses.ts +20 -0
  69. package/src/primitives/Address/from.ts +41 -0
  70. package/src/primitives/Address/fromAbiEncoded.ts +35 -0
  71. package/src/primitives/Address/fromBase64.ts +25 -0
  72. package/src/primitives/Address/fromBytes.ts +25 -0
  73. package/src/primitives/Address/fromHex.ts +31 -0
  74. package/src/primitives/Address/fromNumber.ts +25 -0
  75. package/src/primitives/Address/fromPrivateKey.ts +25 -0
  76. package/src/primitives/Address/fromPublicKey.ts +56 -0
  77. package/src/primitives/Address/index.ts +99 -35
  78. package/src/primitives/Address/is.ts +20 -0
  79. package/src/primitives/Address/isAddress.ts +22 -0
  80. package/src/primitives/Address/sortAddresses.ts +19 -0
  81. package/src/primitives/Address/toChecksummed.ts +32 -0
  82. package/src/primitives/Address/toHex.ts +18 -0
  83. package/src/primitives/Address/zero.ts +18 -0
  84. package/src/primitives/Base64/Base64.test.ts +75 -0
  85. package/src/primitives/Base64/convert.ts +37 -0
  86. package/src/primitives/Base64/decode.ts +59 -0
  87. package/src/primitives/Base64/encode.ts +42 -0
  88. package/src/primitives/Base64/from.ts +39 -0
  89. package/src/primitives/Base64/index.ts +81 -1
  90. package/src/primitives/Base64/size.ts +16 -0
  91. package/src/primitives/Base64/validation.ts +16 -0
  92. package/src/primitives/Blob/Blob.test.ts +292 -0
  93. package/src/primitives/Blob/calculateGas.ts +30 -0
  94. package/src/primitives/Blob/estimateBlobCount.ts +30 -0
  95. package/src/primitives/Blob/from.ts +38 -0
  96. package/src/primitives/Blob/fromData.ts +36 -0
  97. package/src/primitives/Blob/index.ts +99 -12
  98. package/src/primitives/Blob/isValidVersion.ts +27 -0
  99. package/src/primitives/Blob/joinData.ts +43 -0
  100. package/src/primitives/Blob/splitData.ts +36 -0
  101. package/src/primitives/Blob/toCommitment.ts +43 -0
  102. package/src/primitives/Blob/toProof.ts +50 -0
  103. package/src/primitives/Blob/toVersionedHash.ts +35 -0
  104. package/src/primitives/Blob/verify.ts +49 -0
  105. package/src/primitives/Blob/verifyBatch.ts +119 -0
  106. package/src/primitives/BloomFilter/BloomFilter.test.ts +138 -0
  107. package/src/primitives/BloomFilter/add.ts +23 -0
  108. package/src/primitives/BloomFilter/combine.ts +21 -0
  109. package/src/primitives/BloomFilter/contains.ts +26 -0
  110. package/src/primitives/BloomFilter/create.ts +35 -0
  111. package/src/primitives/BloomFilter/density.ts +22 -0
  112. package/src/primitives/BloomFilter/expectedFalsePositiveRate.ts +25 -0
  113. package/src/primitives/BloomFilter/fromHex.ts +37 -0
  114. package/src/primitives/BloomFilter/hash.ts +43 -0
  115. package/src/primitives/BloomFilter/index.ts +59 -37
  116. package/src/primitives/BloomFilter/isEmpty.ts +22 -0
  117. package/src/primitives/BloomFilter/merge.ts +24 -0
  118. package/src/primitives/BloomFilter/toHex.ts +22 -0
  119. package/src/primitives/Bytecode/analyze.ts +58 -0
  120. package/src/primitives/Bytecode/detectFusions.ts +10 -0
  121. package/src/primitives/Bytecode/equals.ts +10 -0
  122. package/src/primitives/Bytecode/extractRuntime.ts +12 -0
  123. package/src/primitives/Bytecode/format.ts +16 -0
  124. package/src/primitives/Bytecode/from.ts +16 -0
  125. package/src/primitives/Bytecode/fromHex.ts +14 -0
  126. package/src/primitives/Bytecode/getBlock.ts +12 -0
  127. package/src/primitives/Bytecode/getNextPc.ts +12 -0
  128. package/src/primitives/Bytecode/getPushSize.ts +8 -0
  129. package/src/primitives/Bytecode/hasMetadata.ts +10 -0
  130. package/src/primitives/Bytecode/hash.ts +9 -0
  131. package/src/primitives/Bytecode/index.ts +103 -13
  132. package/src/primitives/Bytecode/isPush.ts +8 -0
  133. package/src/primitives/Bytecode/isTerminator.ts +8 -0
  134. package/src/primitives/Bytecode/isValidJumpDest.ts +12 -0
  135. package/src/primitives/Bytecode/parseInstructions.ts +10 -0
  136. package/src/primitives/Bytecode/prettyPrint.ts +12 -0
  137. package/src/primitives/Bytecode/scan.ts +20 -0
  138. package/src/primitives/Bytecode/size.ts +9 -0
  139. package/src/primitives/Bytecode/stripMetadata.ts +10 -0
  140. package/src/primitives/Bytecode/toAbi.ts +10 -0
  141. package/src/primitives/Bytecode/toHex.ts +10 -0
  142. package/src/primitives/Bytecode/types.ts +23 -0
  143. package/src/primitives/Bytecode/validate.ts +9 -0
  144. package/src/primitives/ContractSignature/ContractSignature.test.ts +1 -13
  145. package/src/primitives/ContractSignature/verifySignature.ts +88 -62
  146. package/src/primitives/Ens/Ens.test.ts +71 -0
  147. package/src/primitives/Ens/convert.ts +13 -0
  148. package/src/primitives/Ens/from.ts +32 -0
  149. package/src/primitives/Ens/hash.ts +46 -0
  150. package/src/primitives/Ens/index.ts +86 -4
  151. package/src/primitives/Ens/normalize.ts +45 -0
  152. package/src/primitives/Ens/validation.ts +38 -0
  153. package/src/primitives/EventLog/accessors.ts +32 -0
  154. package/src/primitives/EventLog/clone.ts +17 -0
  155. package/src/primitives/EventLog/create.ts +46 -0
  156. package/src/primitives/EventLog/filtering.ts +48 -0
  157. package/src/primitives/EventLog/index.ts +96 -6
  158. package/src/primitives/EventLog/status.ts +17 -0
  159. package/src/primitives/EventLog/toRpc.ts +49 -0
  160. package/src/primitives/Hardfork/HardforkSchema.ts +3 -3
  161. package/src/primitives/Hardfork/allIds.ts +13 -0
  162. package/src/primitives/Hardfork/allNames.ts +13 -0
  163. package/src/primitives/Hardfork/compare.ts +17 -0
  164. package/src/primitives/Hardfork/comparisons.ts +45 -0
  165. package/src/primitives/Hardfork/equals.ts +17 -0
  166. package/src/primitives/Hardfork/features.ts +61 -0
  167. package/src/primitives/Hardfork/fromString.ts +16 -0
  168. package/src/primitives/Hardfork/index.ts +128 -18
  169. package/src/primitives/Hardfork/isValidName.ts +14 -0
  170. package/src/primitives/Hardfork/minMax.ts +23 -0
  171. package/src/primitives/Hardfork/range.ts +19 -0
  172. package/src/primitives/Hardfork/toString.ts +16 -0
  173. package/src/primitives/Hash/Hash.test.ts +104 -0
  174. package/src/primitives/Hash/from.ts +47 -0
  175. package/src/primitives/Hash/fromBytes.ts +46 -0
  176. package/src/primitives/Hash/fromHex.ts +44 -0
  177. package/src/primitives/Hash/index.ts +45 -8
  178. package/src/primitives/Hash/isHash.ts +31 -0
  179. package/src/primitives/Hash/toHex.ts +29 -0
  180. package/src/primitives/Hex/Hex.test.ts +327 -153
  181. package/src/primitives/Hex/assertSize.ts +41 -0
  182. package/src/primitives/Hex/concat.ts +37 -0
  183. package/src/primitives/Hex/from.ts +38 -0
  184. package/src/primitives/Hex/fromBigInt.ts +40 -0
  185. package/src/primitives/Hex/fromBoolean.ts +29 -0
  186. package/src/primitives/Hex/fromNumber.ts +41 -0
  187. package/src/primitives/Hex/fromString.ts +28 -0
  188. package/src/primitives/Hex/index.ts +68 -37
  189. package/src/primitives/Hex/pad.ts +40 -0
  190. package/src/primitives/Hex/padRight.ts +39 -0
  191. package/src/primitives/Hex/size.ts +29 -0
  192. package/src/primitives/Hex/slice.ts +42 -0
  193. package/src/primitives/Hex/toBigInt.ts +27 -0
  194. package/src/primitives/Hex/toBoolean.ts +38 -0
  195. package/src/primitives/Hex/toNumber.ts +37 -0
  196. package/src/primitives/Hex/toStringHex.ts +39 -0
  197. package/src/primitives/Hex/trim.ts +27 -0
  198. package/src/primitives/Hex/validate.ts +37 -0
  199. package/src/primitives/Hex/xor.ts +39 -0
  200. package/src/primitives/Opcode/OpcodeSchema.ts +1 -1
  201. package/src/primitives/Opcode/disassemble.ts +15 -0
  202. package/src/primitives/Opcode/dupPosition.ts +15 -0
  203. package/src/primitives/Opcode/format.ts +15 -0
  204. package/src/primitives/Opcode/getters.ts +54 -0
  205. package/src/primitives/Opcode/index.ts +301 -11
  206. package/src/primitives/Opcode/info.ts +18 -0
  207. package/src/primitives/Opcode/jumpDests.ts +15 -0
  208. package/src/primitives/Opcode/logTopics.ts +15 -0
  209. package/src/primitives/Opcode/name.ts +15 -0
  210. package/src/primitives/Opcode/parse.ts +15 -0
  211. package/src/primitives/Opcode/predicates.ts +72 -0
  212. package/src/primitives/Opcode/pushBytes.ts +15 -0
  213. package/src/primitives/Opcode/pushOpcode.ts +15 -0
  214. package/src/primitives/Opcode/swapPosition.ts +15 -0
  215. package/src/primitives/Rlp/decodeBatch.ts +46 -0
  216. package/src/primitives/Rlp/decodeObject.ts +46 -0
  217. package/src/primitives/Rlp/decodeValue.ts +51 -0
  218. package/src/primitives/Rlp/encodeBatch.ts +50 -0
  219. package/src/primitives/Rlp/encodeObject.ts +48 -0
  220. package/src/primitives/Rlp/encodeVariadic.ts +49 -0
  221. package/src/primitives/Rlp/equals.ts +22 -0
  222. package/src/primitives/Rlp/from.ts +44 -0
  223. package/src/primitives/Rlp/fromJSON.ts +45 -0
  224. package/src/primitives/Rlp/getEncodedLength.ts +47 -0
  225. package/src/primitives/Rlp/getLength.ts +44 -0
  226. package/src/primitives/Rlp/index.ts +67 -14
  227. package/src/primitives/Rlp/isBytesData.ts +21 -0
  228. package/src/primitives/Rlp/isCanonical.ts +32 -0
  229. package/src/primitives/Rlp/isData.ts +21 -0
  230. package/src/primitives/Rlp/isList.ts +46 -0
  231. package/src/primitives/Rlp/isListData.ts +21 -0
  232. package/src/primitives/Rlp/isString.ts +46 -0
  233. package/src/primitives/Rlp/toJSON.ts +20 -0
  234. package/src/primitives/Rlp/toRaw.ts +31 -0
  235. package/src/primitives/Signature/Signature.test.ts +217 -0
  236. package/src/primitives/Signature/from.ts +38 -0
  237. package/src/primitives/Signature/fromBytes.ts +31 -0
  238. package/src/primitives/Signature/fromCompact.ts +33 -0
  239. package/src/primitives/Signature/fromDER.ts +35 -0
  240. package/src/primitives/Signature/fromEd25519.ts +24 -0
  241. package/src/primitives/Signature/fromHex.ts +29 -0
  242. package/src/primitives/Signature/fromP256.ts +25 -0
  243. package/src/primitives/Signature/fromRpc.ts +38 -0
  244. package/src/primitives/Signature/fromSecp256k1.ts +29 -0
  245. package/src/primitives/Signature/fromTuple.ts +33 -0
  246. package/src/primitives/Signature/getR.ts +24 -0
  247. package/src/primitives/Signature/getS.ts +24 -0
  248. package/src/primitives/Signature/getV.ts +24 -0
  249. package/src/primitives/Signature/index.ts +61 -11
  250. package/src/primitives/Signature/toDER.ts +24 -0
  251. package/src/primitives/Signature/toHex.ts +24 -0
  252. package/src/primitives/Signature/toRpc.ts +35 -0
  253. package/src/primitives/Signature/toTuple.ts +29 -0
  254. package/src/primitives/Signature/verify.ts +31 -0
  255. package/src/primitives/Siwe/create.ts +56 -0
  256. package/src/primitives/Siwe/hash.ts +27 -0
  257. package/src/primitives/Siwe/index.ts +57 -21
  258. package/src/primitives/Siwe/parse.ts +24 -0
  259. package/src/primitives/Siwe/verify.ts +47 -0
  260. package/src/primitives/Transaction/Transaction.test.ts +309 -0
  261. package/src/primitives/Transaction/index.ts +467 -2
  262. package/src/primitives/Uint/Uint.test.ts +200 -0
  263. package/src/primitives/Uint/dividedBy.ts +34 -0
  264. package/src/primitives/Uint/from.ts +35 -0
  265. package/src/primitives/Uint/fromAbiEncoded.ts +29 -0
  266. package/src/primitives/Uint/fromBigInt.ts +30 -0
  267. package/src/primitives/Uint/fromBytes.ts +32 -0
  268. package/src/primitives/Uint/fromHex.ts +32 -0
  269. package/src/primitives/Uint/fromNumber.ts +30 -0
  270. package/src/primitives/Uint/index.ts +90 -45
  271. package/src/primitives/Uint/isUint256.ts +25 -0
  272. package/src/primitives/Uint/isValid.ts +25 -0
  273. package/src/primitives/Uint/modulo.ts +34 -0
  274. package/src/primitives/Uint/toHex.ts +31 -0
  275. package/src/primitives/Uint/tryFrom.ts +30 -0
  276. package/src/services/Contract/Contract.test.ts +46 -41
  277. package/src/services/Contract/Contract.ts +25 -29
  278. package/src/services/Contract/ContractTypes.ts +6 -3
  279. package/src/services/Contract/estimateGas.test.ts +21 -9
  280. package/src/services/Contract/estimateGas.ts +21 -23
  281. package/src/services/Debug/Debug.ts +1 -1
  282. package/src/services/Debug/DebugService.ts +1 -1
  283. package/src/services/FeeEstimator/DefaultFeeEstimator.ts +10 -6
  284. package/src/services/FeeEstimator/FeeEstimator.test.ts +68 -62
  285. package/src/services/Multicall/BalanceResolver.ts +1 -1
  286. package/src/services/Multicall/GetBalance.ts +1 -1
  287. package/src/services/Multicall/Multicall.ts +1 -1
  288. package/src/services/NonceManager/DefaultNonceManager.ts +4 -7
  289. package/src/services/NonceManager/NonceManager.test.ts +20 -33
  290. package/src/services/Provider/Provider.test.ts +155 -349
  291. package/src/services/Provider/Provider.ts +14 -1180
  292. package/src/services/Provider/ProviderService.ts +14 -1199
  293. package/src/services/Provider/actions/multicall.test.ts +29 -39
  294. package/src/services/Provider/actions/multicall.ts +2 -2
  295. package/src/services/Provider/actions/readContract.test.ts +45 -50
  296. package/src/services/Provider/actions/readContract.ts +2 -6
  297. package/src/services/Provider/actions/simulateContract.test.ts +55 -232
  298. package/src/services/Provider/actions/simulateContract.ts +2 -3
  299. package/src/services/Provider/ens/getEnsAddress.ts +11 -14
  300. package/src/services/Provider/ens/getEnsName.ts +15 -18
  301. package/src/services/Provider/ens/getEnsResolver.ts +11 -14
  302. package/src/services/Provider/ens/getEnsText.ts +15 -18
  303. package/src/services/Provider/functions/backfillBlocks.ts +97 -0
  304. package/src/services/Provider/functions/call.ts +45 -0
  305. package/src/services/Provider/functions/createAccessList.ts +61 -0
  306. package/src/services/Provider/functions/createBlockFilter.ts +41 -0
  307. package/src/services/Provider/functions/createEventFilter.ts +43 -0
  308. package/src/services/Provider/functions/createPendingTransactionFilter.ts +41 -0
  309. package/src/services/Provider/functions/estimateGas.ts +52 -0
  310. package/src/services/Provider/functions/getAccounts.ts +40 -0
  311. package/src/services/Provider/functions/getBalance.ts +50 -0
  312. package/src/services/Provider/functions/getBlobBaseFee.ts +46 -0
  313. package/src/services/Provider/functions/getBlock.ts +95 -0
  314. package/src/services/Provider/functions/getBlockNumber.ts +51 -0
  315. package/src/services/Provider/functions/getBlockReceipts.ts +78 -0
  316. package/src/services/Provider/functions/getBlockTransactionCount.ts +86 -0
  317. package/src/services/Provider/functions/getChainId.ts +46 -0
  318. package/src/services/Provider/functions/getCode.ts +43 -0
  319. package/src/services/Provider/functions/getCoinbase.ts +40 -0
  320. package/src/services/Provider/functions/getFeeHistory.ts +85 -0
  321. package/src/services/Provider/functions/getFilterChanges.ts +42 -0
  322. package/src/services/Provider/functions/getFilterLogs.ts +44 -0
  323. package/src/services/Provider/functions/getGasPrice.ts +46 -0
  324. package/src/services/Provider/functions/getHashrate.ts +46 -0
  325. package/src/services/Provider/functions/getLogs.ts +45 -0
  326. package/src/services/Provider/functions/getMaxPriorityFeePerGas.ts +46 -0
  327. package/src/services/Provider/functions/getMining.ts +40 -0
  328. package/src/services/Provider/functions/getProof.ts +52 -0
  329. package/src/services/Provider/functions/getProtocolVersion.ts +40 -0
  330. package/src/services/Provider/functions/getStorageAt.ts +52 -0
  331. package/src/services/Provider/functions/getSyncing.ts +56 -0
  332. package/src/services/Provider/functions/getTransaction.ts +57 -0
  333. package/src/services/Provider/functions/getTransactionByBlockHashAndIndex.ts +73 -0
  334. package/src/services/Provider/functions/getTransactionByBlockNumberAndIndex.ts +86 -0
  335. package/src/services/Provider/functions/getTransactionConfirmations.ts +70 -0
  336. package/src/services/Provider/functions/getTransactionCount.ts +50 -0
  337. package/src/services/Provider/functions/getTransactionReceipt.ts +57 -0
  338. package/src/services/Provider/functions/getUncle.ts +97 -0
  339. package/src/services/Provider/functions/getUncleCount.ts +86 -0
  340. package/src/services/Provider/functions/index.ts +73 -0
  341. package/src/services/Provider/functions/netVersion.ts +40 -0
  342. package/src/services/Provider/functions/sendRawTransaction.ts +40 -0
  343. package/src/services/Provider/functions/sendTransaction.ts +48 -0
  344. package/src/services/Provider/functions/sign.ts +50 -0
  345. package/src/services/Provider/functions/signTransaction.ts +52 -0
  346. package/src/services/Provider/functions/simulateV1.ts +95 -0
  347. package/src/services/Provider/functions/simulateV2.ts +51 -0
  348. package/src/services/Provider/functions/subscribe.ts +49 -0
  349. package/src/services/Provider/functions/uninstallFilter.ts +40 -0
  350. package/src/services/Provider/functions/unsubscribe.ts +41 -0
  351. package/src/services/Provider/functions/waitForTransactionReceipt.ts +168 -0
  352. package/src/services/Provider/functions/watchBlocks.ts +98 -0
  353. package/src/services/Provider/index.ts +29 -178
  354. package/src/services/Provider/types.ts +780 -0
  355. package/src/services/Provider/utils.ts +204 -0
  356. package/src/services/RawProvider/ForkProviderTransport.ts +2 -3
  357. package/src/services/RawProvider/HttpProviderTransport.ts +3 -3
  358. package/src/services/RawProvider/InMemoryProviderTransport.ts +3 -3
  359. package/src/services/RawProvider/WebSocketProviderTransport.ts +3 -3
  360. package/src/services/Signer/Signer.test.ts +211 -187
  361. package/src/services/Signer/Signer.ts +26 -16
  362. package/src/services/Signer/actions/deployContract.test.ts +125 -105
  363. package/src/services/Signer/actions/deployContract.ts +3 -2
  364. package/src/services/Signer/actions/prepareAuthorization.test.ts +47 -48
  365. package/src/services/Signer/actions/prepareAuthorization.ts +3 -3
  366. package/src/services/Signer/actions/signAuthorization.test.ts +39 -45
  367. package/src/services/Signer/actions/signAuthorization.ts +3 -3
  368. package/src/services/Signer/actions/writeContract.test.ts +41 -57
  369. package/src/services/Transport/FallbackTransport.ts +3 -3
  370. package/src/services/Transport/HttpTransport.ts +3 -3
  371. package/src/services/Transport/config.ts +7 -7
  372. package/src/services/Transport/index.ts +3 -4
  373. package/src/services/errors.test.ts +3 -8
  374. package/src/services/index.ts +8 -90
  375. package/src/services/presets/index.ts +9 -10
  376. package/src/services/presets/presets.test.ts +14 -29
  377. package/src/standards/ERC165.test.ts +19 -20
  378. package/src/standards/ERC165.ts +9 -11
  379. package/src/type-exports.test.ts +37 -0
  380. package/dist/AccountService-BetXokad.d.ts +0 -1717
  381. package/dist/RpcResolver-BpvqybjD.d.ts +0 -6439
  382. package/src/services/Provider/Account.ts +0 -33
  383. package/src/services/Provider/AccountService.ts +0 -84
  384. package/src/services/Provider/Blocks.ts +0 -32
  385. package/src/services/Provider/BlocksService.ts +0 -73
  386. package/src/services/Provider/Events.ts +0 -33
  387. package/src/services/Provider/EventsService.ts +0 -71
  388. package/src/services/Provider/Network.ts +0 -41
  389. package/src/services/Provider/NetworkService.ts +0 -114
  390. package/src/services/Provider/Simulation.ts +0 -34
  391. package/src/services/Provider/SimulationService.ts +0 -161
  392. package/src/services/Provider/Streaming.ts +0 -30
  393. package/src/services/Provider/StreamingService.ts +0 -58
  394. package/src/services/Provider/Transaction.ts +0 -39
  395. package/src/services/Provider/TransactionService.ts +0 -83
  396. package/src/services/Provider/filters.ts +0 -91
  397. package/src/services/Provider/getBlobBaseFee.ts +0 -170
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "voltaire-effect",
3
- "version": "0.2.23",
3
+ "version": "0.2.25",
4
4
  "description": "Effect-TS integration for Voltaire Ethereum primitives library",
5
5
  "author": "TEVM",
6
6
  "license": "MIT",
@@ -79,7 +79,7 @@
79
79
  "sideEffects": false,
80
80
  "peerDependencies": {
81
81
  "effect": "^3.12.0",
82
- "@tevm/voltaire": "0.2.23"
82
+ "@tevm/voltaire": "0.2.25"
83
83
  },
84
84
  "dependencies": {
85
85
  "@effect/platform": "^0.77.0"
@@ -4,6 +4,11 @@ import { Address } from "@tevm/voltaire/Address";
4
4
  import * as Hex from "@tevm/voltaire/Hex";
5
5
  import * as Effect from "effect/Effect";
6
6
  import * as Exit from "effect/Exit";
7
+ import * as Layer from "effect/Layer";
8
+ import {
9
+ ProviderService,
10
+ type ProviderShape,
11
+ } from "../../services/Provider/index.js";
7
12
  import { VerifyError } from "../Signature/errors.js";
8
13
  import { unwrapSignature, verifySignature, wrapSignature } from "./index.js";
9
14
 
@@ -57,20 +62,25 @@ describe("ERC6492", () => {
57
62
  it.effect("verifies using deployless validator", () =>
58
63
  Effect.gen(function* () {
59
64
  const calls: Array<{ data?: string }> = [];
60
- const provider = {
61
- call: (tx: { data?: `0x${string}` }) =>
62
- Effect.sync(() => {
65
+
66
+ const mockProvider: ProviderShape = {
67
+ request: <T>(method: string, params?: unknown[]) => {
68
+ if (method === "eth_call") {
69
+ const tx = params?.[0] as { data?: string };
63
70
  calls.push(tx);
64
- return "0x01" as `0x${string}`;
65
- }),
66
- } as any;
71
+ return Effect.succeed("0x01" as T);
72
+ }
73
+ return Effect.succeed(null as T);
74
+ },
75
+ };
76
+
77
+ const MockProviderLayer = Layer.succeed(ProviderService, mockProvider);
67
78
 
68
79
  const result = yield* verifySignature({
69
80
  address: signer,
70
81
  message: messageHash,
71
82
  signature: innerSignature,
72
- provider,
73
- });
83
+ }).pipe(Effect.provide(MockProviderLayer));
74
84
 
75
85
  expect(result).toBe(true);
76
86
  expect(calls.length).toBe(1);
@@ -90,18 +100,26 @@ describe("ERC6492", () => {
90
100
  const revertData = Hex.fromBytes(
91
101
  encodeParameters([{ type: "string" }] as const, ["boom"] as any),
92
102
  );
93
- const provider = {
94
- call: () =>
95
- Effect.succeed(`0x08c379a0${revertData.slice(2)}` as `0x${string}`),
96
- } as any;
103
+
104
+ const mockProvider: ProviderShape = {
105
+ request: <T>(method: string, _params?: unknown[]) => {
106
+ if (method === "eth_call") {
107
+ return Effect.succeed(
108
+ `0x08c379a0${revertData.slice(2)}` as T,
109
+ );
110
+ }
111
+ return Effect.succeed(null as T);
112
+ },
113
+ };
114
+
115
+ const MockProviderLayer = Layer.succeed(ProviderService, mockProvider);
97
116
 
98
117
  const exit = yield* Effect.exit(
99
118
  verifySignature({
100
119
  address: signer,
101
120
  message: messageHash,
102
121
  signature: innerSignature,
103
- provider,
104
- }),
122
+ }).pipe(Effect.provide(MockProviderLayer)),
105
123
  );
106
124
 
107
125
  expect(Exit.isFailure(exit)).toBe(true);
@@ -9,7 +9,8 @@ import { Address, type AddressType } from "@tevm/voltaire/Address";
9
9
  import type { HexType } from "@tevm/voltaire/Hex";
10
10
  import * as Hex from "@tevm/voltaire/Hex";
11
11
  import * as Effect from "effect/Effect";
12
- import type { ProviderShape as ProviderService } from "../../services/Provider/index.js";
12
+ import { call } from "../../services/Provider/functions/index.js";
13
+ import { ProviderService } from "../../services/Provider/index.js";
13
14
  import { VerifyError } from "../Signature/errors.js";
14
15
 
15
16
  // Output from solc contracts/DeploylessUniversalSigValidator.sol --bin --optimize --optimize-runs=1
@@ -52,7 +53,6 @@ const normalizeCallResult = (value: HexType | `0x${string}`): `0x${string}` =>
52
53
  * @param params.address - Expected signer address
53
54
  * @param params.message - 32-byte message hash
54
55
  * @param params.signature - Signature bytes (may be ERC-6492 wrapped)
55
- * @param params.provider - Provider service used for eth_call
56
56
  * @returns Effect containing true if signature is valid
57
57
  *
58
58
  * @since 0.2.14
@@ -61,8 +61,7 @@ export const verifySignature = (params: {
61
61
  address: AddressType | `0x${string}`;
62
62
  message: HexType | `0x${string}`;
63
63
  signature: HexType | `0x${string}`;
64
- provider: ProviderService;
65
- }): Effect.Effect<boolean, VerifyError> =>
64
+ }): Effect.Effect<boolean, VerifyError, ProviderService> =>
66
65
  Effect.gen(function* () {
67
66
  const messageHex = params.message as `0x${string}`;
68
67
  const messageBytes = yield* Effect.try({
@@ -102,7 +101,7 @@ export const verifySignature = (params: {
102
101
  const data =
103
102
  `${UNIVERSAL_VALIDATOR_BYTECODE}${Hex.fromBytes(encodedParams).slice(2)}` as `0x${string}`;
104
103
 
105
- const callResult = yield* params.provider.call({ data }).pipe(
104
+ const callResult = yield* call({ data }).pipe(
106
105
  Effect.mapError(
107
106
  (e) =>
108
107
  new VerifyError({
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from "@effect/vitest";
2
2
  import * as Effect from "effect/Effect";
3
- import { hash, KeccakLive, KeccakService, KeccakTest } from "./index.js";
3
+ import { hash, hashSync, KeccakLive, KeccakService, KeccakTest } from "./index.js";
4
4
 
5
5
  const bytesToHex = (bytes: Uint8Array): string => {
6
6
  return (
@@ -263,3 +263,44 @@ describe("hash", () => {
263
263
  expect(bytesToHex(hashResult)).toBe(bytesToHex(serviceResult));
264
264
  });
265
265
  });
266
+
267
+ describe("hashSync", () => {
268
+ it("hashes data synchronously without Effect service", () => {
269
+ const data = new Uint8Array([104, 101, 108, 108, 111]); // "hello"
270
+ const result = hashSync(data);
271
+ expect(result).toBeInstanceOf(Uint8Array);
272
+ expect(result.length).toBe(32);
273
+ expect(bytesToHex(result)).toBe(
274
+ "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8",
275
+ );
276
+ });
277
+
278
+ it("matches Effect-based hash result", async () => {
279
+ const data = new Uint8Array([1, 2, 3]);
280
+ const syncResult = hashSync(data);
281
+ const effectResult = await Effect.runPromise(
282
+ hash(data).pipe(Effect.provide(KeccakLive)),
283
+ );
284
+ expect(bytesToHex(syncResult)).toBe(bytesToHex(effectResult));
285
+ });
286
+
287
+ it("works with empty input", () => {
288
+ const result = hashSync(new Uint8Array(0));
289
+ expect(bytesToHex(result)).toBe(
290
+ "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
291
+ );
292
+ });
293
+
294
+ it("works with large input", () => {
295
+ const result = hashSync(new Uint8Array(1024).fill(0x42));
296
+ expect(result).toBeInstanceOf(Uint8Array);
297
+ expect(result.length).toBe(32);
298
+ });
299
+
300
+ it("is deterministic", () => {
301
+ const data = new Uint8Array([1, 2, 3, 4, 5]);
302
+ const hash1 = hashSync(data);
303
+ const hash2 = hashSync(data);
304
+ expect(bytesToHex(hash1)).toBe(bytesToHex(hash2));
305
+ });
306
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @fileoverview Synchronous Keccak-256 hash function without Effect service layer.
3
+ *
4
+ * @description
5
+ * Provides a direct synchronous Keccak-256 hash function that bypasses the Effect
6
+ * service layer. Use this when you need a simple hash without Effect dependency
7
+ * injection overhead.
8
+ *
9
+ * @module Keccak256/hashSync
10
+ * @since 0.2.25
11
+ */
12
+
13
+ import type { Keccak256Hash } from "@tevm/voltaire";
14
+ import { Keccak256 } from "@tevm/voltaire";
15
+
16
+ /**
17
+ * Computes the Keccak-256 hash of the provided data synchronously.
18
+ *
19
+ * @description
20
+ * This is a direct synchronous version of the Keccak-256 hash that does not
21
+ * require the Effect service layer. Use this when you need a simple hash
22
+ * operation without Effect dependency injection.
23
+ *
24
+ * For Effect-based applications that need testability and dependency injection,
25
+ * use {@link hash} with {@link KeccakService} instead.
26
+ *
27
+ * @param {Uint8Array} data - The input bytes to hash. Can be any length.
28
+ * @returns {Keccak256Hash} A 32-byte Keccak256Hash (branded Uint8Array)
29
+ *
30
+ * @example Basic usage
31
+ * ```typescript
32
+ * import { hashSync } from 'voltaire-effect/crypto/Keccak256'
33
+ *
34
+ * const data = new Uint8Array([1, 2, 3])
35
+ * const result = hashSync(data)
36
+ * console.log(result) // Uint8Array(32) [...]
37
+ * ```
38
+ *
39
+ * @example Hashing a string
40
+ * ```typescript
41
+ * import { hashSync } from 'voltaire-effect/crypto/Keccak256'
42
+ *
43
+ * const message = new TextEncoder().encode('hello world')
44
+ * const hash = hashSync(message)
45
+ * ```
46
+ *
47
+ * @see {@link hash} - Effect-based version with dependency injection
48
+ * @see {@link KeccakService} - Service interface for Effect-based usage
49
+ * @since 0.2.25
50
+ */
51
+ export const hashSync = (data: Uint8Array): Keccak256Hash => {
52
+ return Keccak256.hash(data);
53
+ };
@@ -41,6 +41,8 @@
41
41
  */
42
42
 
43
43
  export { hash } from "./hash.js";
44
+ export { hashSync } from "./hashSync.js";
45
+ export type { Keccak256Hash } from "@tevm/voltaire";
44
46
  export {
45
47
  KeccakLive,
46
48
  KeccakService,
package/src/index.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  // Primitives - explicit namespace exports
2
2
 
3
+ // Re-export core types for direct import (e.g., import { AddressType } from 'voltaire-effect')
4
+ export type { AddressType, BrandedAddress } from "@tevm/voltaire/Address";
5
+ export type { HexType, Hex as HexBrand, Sized } from "@tevm/voltaire/Hex";
6
+ export type { HashType } from "@tevm/voltaire/Hash";
7
+
3
8
  // Re-export voltaire error types for Effect compatibility
4
9
  export {
5
10
  // Base errors
@@ -70,8 +75,8 @@ export * as SHA256 from "./crypto/SHA256/index.js";
70
75
  export * as X25519 from "./crypto/X25519/index.js";
71
76
  // JSON-RPC module
72
77
  export * as JsonRpc from "./jsonrpc/index.js";
73
- // Abi temporarily disabled - requires @tevm/voltaire subpath exports
74
- // export * as Abi from "./primitives/Abi/index.js";
78
+ // ABI encoding/decoding
79
+ export * as Abi from "./primitives/Abi/index.js";
75
80
  export * as AccessList from "./primitives/AccessList/index.js";
76
81
  export * as AccountState from "./primitives/AccountState/index.js";
77
82
  export * as Address from "./primitives/Address/index.js";
@@ -0,0 +1,38 @@
1
+ import { describe, expect, it } from "@effect/vitest";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Exit from "effect/Exit";
4
+ import * as S from "effect/Schema";
5
+ import { fromArray } from "./AbiSchema.js";
6
+ import { decode } from "./decode.js";
7
+
8
+ const erc20Abi = S.decodeUnknownSync(fromArray)([
9
+ {
10
+ type: "function",
11
+ name: "balanceOf",
12
+ stateMutability: "view",
13
+ inputs: [{ name: "account", type: "address" }],
14
+ outputs: [{ type: "uint256" }],
15
+ },
16
+ ]);
17
+
18
+ describe("decode", () => {
19
+ describe("success cases", () => {
20
+ it.effect("decodes balanceOf result", () =>
21
+ Effect.gen(function* () {
22
+ const encoded = new Uint8Array(32);
23
+ encoded[31] = 100;
24
+ const result = yield* decode(erc20Abi, "balanceOf", encoded);
25
+ expect(result).toBeInstanceOf(Array);
26
+ }),
27
+ );
28
+ });
29
+
30
+ describe("error cases", () => {
31
+ it("fails for unknown function", async () => {
32
+ const exit = await Effect.runPromiseExit(
33
+ decode(erc20Abi, "unknownFunction", new Uint8Array(32)),
34
+ );
35
+ expect(Exit.isFailure(exit)).toBe(true);
36
+ });
37
+ });
38
+ });
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @fileoverview Decodes function return values from ABI by function name.
3
+ * Provides Effect-based wrapper around the branded ABI decode method.
4
+ *
5
+ * @module Abi/decode
6
+ * @since 0.0.1
7
+ */
8
+
9
+ import {
10
+ type Abi,
11
+ AbiDecodingError as AbiDecodingErrorClass,
12
+ type AbiDecodingError,
13
+ type AbiItemNotFoundError,
14
+ type ItemType,
15
+ } from "@tevm/voltaire/Abi";
16
+ import * as Effect from "effect/Effect";
17
+
18
+ type AbiInput = readonly ItemType[];
19
+
20
+ const toAbi = (input: AbiInput): Abi => input as unknown as Abi;
21
+
22
+ type DecodeErrorType = AbiItemNotFoundError | AbiDecodingError;
23
+
24
+ const isAbiError = (e: unknown): e is DecodeErrorType =>
25
+ e !== null &&
26
+ typeof e === "object" &&
27
+ "name" in e &&
28
+ (e.name === "AbiItemNotFoundError" || e.name === "AbiDecodingError");
29
+
30
+ /**
31
+ * Decodes function return values from ABI by function name.
32
+ *
33
+ * @description
34
+ * Decodes the return data from a contract call using the function's output types.
35
+ *
36
+ * @param {AbiInput} abi - The contract ABI.
37
+ * @param {string} functionName - The function name whose outputs to decode.
38
+ * @param {Uint8Array} data - The encoded return data.
39
+ * @returns {Effect.Effect<readonly unknown[], AbiItemNotFoundError | AbiDecodingError>}
40
+ * Effect yielding decoded return values.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * import * as Effect from 'effect/Effect'
45
+ * import { decode } from 'voltaire-effect/primitives/Abi'
46
+ *
47
+ * const result = await Effect.runPromise(
48
+ * decode(abi, 'balanceOf', returnData)
49
+ * )
50
+ * ```
51
+ *
52
+ * @since 0.0.1
53
+ */
54
+ export const decode = (
55
+ abi: AbiInput,
56
+ functionName: string,
57
+ data: Uint8Array,
58
+ ): Effect.Effect<readonly unknown[], AbiItemNotFoundError | AbiDecodingError> =>
59
+ Effect.try({
60
+ try: () => toAbi(abi).decode(functionName, data),
61
+ catch: (e) =>
62
+ isAbiError(e)
63
+ ? e
64
+ : new AbiDecodingErrorClass("Failed to decode function result", {
65
+ cause: e instanceof Error ? e : undefined,
66
+ }),
67
+ });
@@ -0,0 +1,37 @@
1
+ import { describe, expect, it } from "@effect/vitest";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Exit from "effect/Exit";
4
+ import * as S from "effect/Schema";
5
+ import { fromArray } from "./AbiSchema.js";
6
+ import { decodeData } from "./decodeData.js";
7
+
8
+ const erc20Abi = S.decodeUnknownSync(fromArray)([
9
+ {
10
+ type: "function",
11
+ name: "transfer",
12
+ stateMutability: "nonpayable",
13
+ inputs: [
14
+ { name: "to", type: "address" },
15
+ { name: "amount", type: "uint256" },
16
+ ],
17
+ outputs: [{ type: "bool" }],
18
+ },
19
+ ]);
20
+
21
+ describe("decodeData", () => {
22
+ describe("error cases", () => {
23
+ it("fails for data too short", async () => {
24
+ const exit = await Effect.runPromiseExit(
25
+ decodeData(erc20Abi, new Uint8Array(2)),
26
+ );
27
+ expect(Exit.isFailure(exit)).toBe(true);
28
+ });
29
+
30
+ it("fails for unknown selector", async () => {
31
+ const exit = await Effect.runPromiseExit(
32
+ decodeData(erc20Abi, new Uint8Array(68)),
33
+ );
34
+ expect(Exit.isFailure(exit)).toBe(true);
35
+ });
36
+ });
37
+ });
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @fileoverview Decodes function call data and identifies the function.
3
+ * Provides Effect-based wrapper around the branded ABI decodeData method.
4
+ *
5
+ * @module Abi/decodeData
6
+ * @since 0.0.1
7
+ */
8
+
9
+ import {
10
+ type Abi,
11
+ AbiDecodingError as AbiDecodingErrorClass,
12
+ type AbiDecodingError,
13
+ type AbiInvalidSelectorError,
14
+ type AbiItemNotFoundError,
15
+ type ItemType,
16
+ } from "@tevm/voltaire/Abi";
17
+ import * as Effect from "effect/Effect";
18
+
19
+ type AbiInput = readonly ItemType[];
20
+
21
+ const toAbi = (input: AbiInput): Abi => input as unknown as Abi;
22
+
23
+ type DecodeDataErrorType =
24
+ | AbiItemNotFoundError
25
+ | AbiInvalidSelectorError
26
+ | AbiDecodingError;
27
+
28
+ const isAbiError = (e: unknown): e is DecodeDataErrorType =>
29
+ e !== null &&
30
+ typeof e === "object" &&
31
+ "name" in e &&
32
+ (e.name === "AbiItemNotFoundError" ||
33
+ e.name === "AbiInvalidSelectorError" ||
34
+ e.name === "AbiDecodingError");
35
+
36
+ /**
37
+ * Decodes function call data and identifies the function.
38
+ *
39
+ * @description
40
+ * Parses encoded calldata to extract the function name and decoded arguments.
41
+ * The data must start with a 4-byte function selector.
42
+ *
43
+ * @param {AbiInput} abi - The contract ABI.
44
+ * @param {Uint8Array} data - The encoded function call data.
45
+ * @returns {Effect.Effect<{ functionName: string; args: readonly unknown[] }, AbiItemNotFoundError | AbiInvalidSelectorError | AbiDecodingError>}
46
+ * Effect yielding the function name and decoded arguments.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import * as Effect from 'effect/Effect'
51
+ * import { decodeData } from 'voltaire-effect/primitives/Abi'
52
+ *
53
+ * const decoded = await Effect.runPromise(
54
+ * decodeData(abi, calldata)
55
+ * )
56
+ * console.log(decoded.functionName) // 'transfer'
57
+ * console.log(decoded.args) // ['0x...', 100n]
58
+ * ```
59
+ *
60
+ * @since 0.0.1
61
+ */
62
+ export const decodeData = (
63
+ abi: AbiInput,
64
+ data: Uint8Array,
65
+ ): Effect.Effect<
66
+ { functionName: string; args: readonly unknown[] },
67
+ AbiItemNotFoundError | AbiInvalidSelectorError | AbiDecodingError
68
+ > =>
69
+ Effect.try({
70
+ try: () => toAbi(abi).decodeData(data),
71
+ catch: (e) =>
72
+ isAbiError(e)
73
+ ? e
74
+ : new AbiDecodingErrorClass("Failed to decode function data", {
75
+ cause: e instanceof Error ? e : undefined,
76
+ }),
77
+ });
@@ -0,0 +1,32 @@
1
+ import { describe, expect, it } from "@effect/vitest";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Exit from "effect/Exit";
4
+ import * as S from "effect/Schema";
5
+ import { fromArray } from "./AbiSchema.js";
6
+ import { decodeLog } from "./decodeLog.js";
7
+
8
+ const erc20Abi = S.decodeUnknownSync(fromArray)([
9
+ {
10
+ type: "event",
11
+ name: "Transfer",
12
+ inputs: [
13
+ { name: "from", type: "address", indexed: true },
14
+ { name: "to", type: "address", indexed: true },
15
+ { name: "value", type: "uint256", indexed: false },
16
+ ],
17
+ },
18
+ ]);
19
+
20
+ describe("decodeLog", () => {
21
+ describe("error cases", () => {
22
+ it("fails for unknown event", async () => {
23
+ const exit = await Effect.runPromiseExit(
24
+ decodeLog(erc20Abi, {
25
+ data: new Uint8Array(32),
26
+ topics: [new Uint8Array(32)],
27
+ }),
28
+ );
29
+ expect(Exit.isFailure(exit)).toBe(true);
30
+ });
31
+ });
32
+ });
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @fileoverview Decodes event log data using ABI.
3
+ * Provides Effect-based wrapper for parsing log entries.
4
+ *
5
+ * @module Abi/decodeLog
6
+ * @since 0.0.1
7
+ */
8
+
9
+ import {
10
+ type Abi,
11
+ AbiDecodingError as AbiDecodingErrorClass,
12
+ type AbiDecodingError,
13
+ type AbiItemNotFoundError,
14
+ type ItemType,
15
+ decodeLog as _decodeLog,
16
+ } from "@tevm/voltaire/Abi";
17
+ import type { HexType } from "@tevm/voltaire/Hex";
18
+ import * as Effect from "effect/Effect";
19
+
20
+ type AbiInput = readonly ItemType[];
21
+
22
+ const toAbi = (input: AbiInput): Abi => input as unknown as Abi;
23
+
24
+ type DecodeLogErrorType = AbiItemNotFoundError | AbiDecodingError;
25
+
26
+ const isAbiError = (e: unknown): e is DecodeLogErrorType =>
27
+ e !== null &&
28
+ typeof e === "object" &&
29
+ "name" in e &&
30
+ (e.name === "AbiItemNotFoundError" || e.name === "AbiDecodingError");
31
+
32
+ /**
33
+ * Log input structure.
34
+ */
35
+ export interface LogInput {
36
+ data: HexType | Uint8Array;
37
+ topics: readonly (HexType | Uint8Array)[];
38
+ }
39
+
40
+ /**
41
+ * Decodes event log data using ABI.
42
+ *
43
+ * @description
44
+ * Parses a log entry to extract the event name and decoded parameters.
45
+ * Supports both regular events (matched by topic0) and anonymous events.
46
+ *
47
+ * @param {AbiInput} abi - The contract ABI.
48
+ * @param {LogInput} log - The log object with data and topics.
49
+ * @returns {Effect.Effect<{ event: string; params: Record<string, unknown> }, AbiItemNotFoundError | AbiDecodingError>}
50
+ * Effect yielding the event name and decoded parameters.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * import * as Effect from 'effect/Effect'
55
+ * import { decodeLog } from 'voltaire-effect/primitives/Abi'
56
+ *
57
+ * const decoded = await Effect.runPromise(
58
+ * decodeLog(abi, { data: '0x...', topics: ['0x...', ...] })
59
+ * )
60
+ * console.log(decoded.event) // 'Transfer'
61
+ * console.log(decoded.params) // { from: '0x...', to: '0x...', value: 100n }
62
+ * ```
63
+ *
64
+ * @since 0.0.1
65
+ */
66
+ export const decodeLog = (
67
+ abi: AbiInput,
68
+ log: LogInput,
69
+ ): Effect.Effect<
70
+ { event: string; params: Record<string, unknown> },
71
+ AbiItemNotFoundError | AbiDecodingError
72
+ > =>
73
+ Effect.try({
74
+ try: () => _decodeLog(toAbi(abi), log),
75
+ catch: (e) =>
76
+ isAbiError(e)
77
+ ? e
78
+ : new AbiDecodingErrorClass("Failed to decode log", {
79
+ cause: e instanceof Error ? e : undefined,
80
+ }),
81
+ });
@@ -0,0 +1,41 @@
1
+ import { describe, expect, it } from "@effect/vitest";
2
+ import { Address, Bytes, Selector } from "@tevm/voltaire";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Exit from "effect/Exit";
5
+ import { decodeWrappedError } from "./decodeWrappedError.js";
6
+ import { encodeWrappedError } from "./encodeWrappedError.js";
7
+
8
+ describe("decodeWrappedError", () => {
9
+ describe("success cases", () => {
10
+ it.effect("decodes encoded wrapped error", () =>
11
+ Effect.gen(function* () {
12
+ const original = {
13
+ target: Address.from("0x742d35Cc6634C0532925a3b844Bc9e7595f251e3"),
14
+ selector: Selector.fromHex("0xa9059cbb"),
15
+ reason: Bytes.from(new Uint8Array([1, 2, 3])),
16
+ details: Bytes.from(new Uint8Array([4, 5, 6])),
17
+ };
18
+ const encoded = yield* encodeWrappedError(original);
19
+ const decoded = yield* decodeWrappedError(encoded);
20
+ expect(decoded.target).toBeDefined();
21
+ expect(decoded.selector).toBeDefined();
22
+ }),
23
+ );
24
+ });
25
+
26
+ describe("error cases", () => {
27
+ it("fails for data too short", async () => {
28
+ const exit = await Effect.runPromiseExit(
29
+ decodeWrappedError(new Uint8Array(2)),
30
+ );
31
+ expect(Exit.isFailure(exit)).toBe(true);
32
+ });
33
+
34
+ it("fails for invalid selector", async () => {
35
+ const exit = await Effect.runPromiseExit(
36
+ decodeWrappedError(new Uint8Array(100)),
37
+ );
38
+ expect(Exit.isFailure(exit)).toBe(true);
39
+ });
40
+ });
41
+ });