viem 0.3.0 → 0.3.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 (365) hide show
  1. package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
  2. package/dist/cjs/actions/ens/getEnsAvatar.js.map +1 -1
  3. package/dist/cjs/actions/ens/getEnsName.js.map +1 -1
  4. package/dist/cjs/actions/ens/getEnsResolver.js.map +1 -1
  5. package/dist/cjs/actions/ens/getEnsText.js.map +1 -1
  6. package/dist/cjs/actions/getContract.js.map +1 -1
  7. package/dist/cjs/actions/public/estimateContractGas.js.map +1 -1
  8. package/dist/cjs/actions/public/getBalance.js.map +1 -1
  9. package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
  10. package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
  11. package/dist/cjs/actions/public/getLogs.js.map +1 -1
  12. package/dist/cjs/actions/public/readContract.js.map +1 -1
  13. package/dist/cjs/actions/public/simulateContract.js.map +1 -1
  14. package/dist/cjs/actions/public/uninstallFilter.js.map +1 -1
  15. package/dist/cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
  16. package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
  17. package/dist/cjs/actions/public/watchEvent.js.map +1 -1
  18. package/dist/cjs/actions/public/watchPendingTransactions.js.map +1 -1
  19. package/dist/cjs/actions/test/dropTransaction.js.map +1 -1
  20. package/dist/cjs/actions/test/getAutomine.js.map +1 -1
  21. package/dist/cjs/actions/test/getTxpoolContent.js.map +1 -1
  22. package/dist/cjs/actions/test/getTxpoolStatus.js.map +1 -1
  23. package/dist/cjs/actions/test/impersonateAccount.js.map +1 -1
  24. package/dist/cjs/actions/test/increaseTime.js.map +1 -1
  25. package/dist/cjs/actions/test/inspectTxpool.js.map +1 -1
  26. package/dist/cjs/actions/test/mine.js.map +1 -1
  27. package/dist/cjs/actions/test/removeBlockTimestampInterval.js.map +1 -1
  28. package/dist/cjs/actions/test/reset.js.map +1 -1
  29. package/dist/cjs/actions/test/revert.js.map +1 -1
  30. package/dist/cjs/actions/test/sendUnsignedTransaction.js.map +1 -1
  31. package/dist/cjs/actions/test/setAutomine.js.map +1 -1
  32. package/dist/cjs/actions/test/setBalance.js.map +1 -1
  33. package/dist/cjs/actions/test/setBlockGasLimit.js.map +1 -1
  34. package/dist/cjs/actions/test/setBlockTimestampInterval.js.map +1 -1
  35. package/dist/cjs/actions/test/setCode.js.map +1 -1
  36. package/dist/cjs/actions/test/setCoinbase.js.map +1 -1
  37. package/dist/cjs/actions/test/setIntervalMining.js.map +1 -1
  38. package/dist/cjs/actions/test/setLoggingEnabled.js.map +1 -1
  39. package/dist/cjs/actions/test/setMinGasPrice.js.map +1 -1
  40. package/dist/cjs/actions/test/setNextBlockBaseFeePerGas.js.map +1 -1
  41. package/dist/cjs/actions/test/setNextBlockTimestamp.js.map +1 -1
  42. package/dist/cjs/actions/test/setNonce.js.map +1 -1
  43. package/dist/cjs/actions/test/setRpcUrl.js.map +1 -1
  44. package/dist/cjs/actions/test/setStorageAt.js.map +1 -1
  45. package/dist/cjs/actions/test/snapshot.js.map +1 -1
  46. package/dist/cjs/actions/test/stopImpersonatingAccount.js.map +1 -1
  47. package/dist/cjs/actions/wallet/addChain.js.map +1 -1
  48. package/dist/cjs/actions/wallet/getAddresses.js.map +1 -1
  49. package/dist/cjs/actions/wallet/getPermissions.js.map +1 -1
  50. package/dist/cjs/actions/wallet/requestAddresses.js.map +1 -1
  51. package/dist/cjs/actions/wallet/requestPermissions.js.map +1 -1
  52. package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
  53. package/dist/cjs/actions/wallet/signMessage.js.map +1 -1
  54. package/dist/cjs/actions/wallet/signTypedData.js.map +1 -1
  55. package/dist/cjs/actions/wallet/switchChain.js.map +1 -1
  56. package/dist/cjs/actions/wallet/watchAsset.js.map +1 -1
  57. package/dist/cjs/actions/wallet/writeContract.js.map +1 -1
  58. package/dist/cjs/clients/createPublicClient.js.map +1 -1
  59. package/dist/cjs/clients/createTestClient.js.map +1 -1
  60. package/dist/cjs/clients/createWalletClient.js.map +1 -1
  61. package/dist/cjs/clients/decorators/test.js.map +1 -1
  62. package/dist/cjs/clients/decorators/wallet.js.map +1 -1
  63. package/dist/cjs/errors/version.js +1 -1
  64. package/dist/cjs/index.js +2 -1
  65. package/dist/cjs/index.js.map +1 -1
  66. package/dist/cjs/utils/abi/getAbiItem.js.map +1 -1
  67. package/dist/cjs/utils/index.js +2 -1
  68. package/dist/cjs/utils/index.js.map +1 -1
  69. package/dist/cjs/utils/rpc.js +3 -6
  70. package/dist/cjs/utils/rpc.js.map +1 -1
  71. package/dist/cjs/utils/signature/index.js +3 -1
  72. package/dist/cjs/utils/signature/index.js.map +1 -1
  73. package/dist/cjs/utils/signature/recoverAddress.js +2 -11
  74. package/dist/cjs/utils/signature/recoverAddress.js.map +1 -1
  75. package/dist/cjs/utils/signature/recoverPublicKey.js +18 -0
  76. package/dist/cjs/utils/signature/recoverPublicKey.js.map +1 -0
  77. package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
  78. package/dist/esm/actions/ens/getEnsAvatar.js.map +1 -1
  79. package/dist/esm/actions/ens/getEnsName.js.map +1 -1
  80. package/dist/esm/actions/ens/getEnsResolver.js.map +1 -1
  81. package/dist/esm/actions/ens/getEnsText.js.map +1 -1
  82. package/dist/esm/actions/getContract.js.map +1 -1
  83. package/dist/esm/actions/public/estimateContractGas.js.map +1 -1
  84. package/dist/esm/actions/public/getBalance.js.map +1 -1
  85. package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
  86. package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
  87. package/dist/esm/actions/public/getLogs.js.map +1 -1
  88. package/dist/esm/actions/public/readContract.js.map +1 -1
  89. package/dist/esm/actions/public/simulateContract.js.map +1 -1
  90. package/dist/esm/actions/public/uninstallFilter.js.map +1 -1
  91. package/dist/esm/actions/public/waitForTransactionReceipt.js.map +1 -1
  92. package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
  93. package/dist/esm/actions/public/watchEvent.js.map +1 -1
  94. package/dist/esm/actions/public/watchPendingTransactions.js.map +1 -1
  95. package/dist/esm/actions/test/dropTransaction.js.map +1 -1
  96. package/dist/esm/actions/test/getAutomine.js.map +1 -1
  97. package/dist/esm/actions/test/getTxpoolContent.js.map +1 -1
  98. package/dist/esm/actions/test/getTxpoolStatus.js.map +1 -1
  99. package/dist/esm/actions/test/impersonateAccount.js.map +1 -1
  100. package/dist/esm/actions/test/increaseTime.js.map +1 -1
  101. package/dist/esm/actions/test/inspectTxpool.js.map +1 -1
  102. package/dist/esm/actions/test/mine.js.map +1 -1
  103. package/dist/esm/actions/test/removeBlockTimestampInterval.js.map +1 -1
  104. package/dist/esm/actions/test/reset.js.map +1 -1
  105. package/dist/esm/actions/test/revert.js.map +1 -1
  106. package/dist/esm/actions/test/sendUnsignedTransaction.js.map +1 -1
  107. package/dist/esm/actions/test/setAutomine.js.map +1 -1
  108. package/dist/esm/actions/test/setBalance.js.map +1 -1
  109. package/dist/esm/actions/test/setBlockGasLimit.js.map +1 -1
  110. package/dist/esm/actions/test/setBlockTimestampInterval.js.map +1 -1
  111. package/dist/esm/actions/test/setCode.js.map +1 -1
  112. package/dist/esm/actions/test/setCoinbase.js.map +1 -1
  113. package/dist/esm/actions/test/setIntervalMining.js.map +1 -1
  114. package/dist/esm/actions/test/setLoggingEnabled.js.map +1 -1
  115. package/dist/esm/actions/test/setMinGasPrice.js.map +1 -1
  116. package/dist/esm/actions/test/setNextBlockBaseFeePerGas.js.map +1 -1
  117. package/dist/esm/actions/test/setNextBlockTimestamp.js.map +1 -1
  118. package/dist/esm/actions/test/setNonce.js.map +1 -1
  119. package/dist/esm/actions/test/setRpcUrl.js.map +1 -1
  120. package/dist/esm/actions/test/setStorageAt.js.map +1 -1
  121. package/dist/esm/actions/test/snapshot.js.map +1 -1
  122. package/dist/esm/actions/test/stopImpersonatingAccount.js.map +1 -1
  123. package/dist/esm/actions/wallet/addChain.js.map +1 -1
  124. package/dist/esm/actions/wallet/getAddresses.js.map +1 -1
  125. package/dist/esm/actions/wallet/getPermissions.js.map +1 -1
  126. package/dist/esm/actions/wallet/requestAddresses.js.map +1 -1
  127. package/dist/esm/actions/wallet/requestPermissions.js.map +1 -1
  128. package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
  129. package/dist/esm/actions/wallet/signMessage.js.map +1 -1
  130. package/dist/esm/actions/wallet/signTypedData.js.map +1 -1
  131. package/dist/esm/actions/wallet/switchChain.js.map +1 -1
  132. package/dist/esm/actions/wallet/watchAsset.js.map +1 -1
  133. package/dist/esm/actions/wallet/writeContract.js.map +1 -1
  134. package/dist/esm/clients/createPublicClient.js.map +1 -1
  135. package/dist/esm/clients/createTestClient.js.map +1 -1
  136. package/dist/esm/clients/createWalletClient.js.map +1 -1
  137. package/dist/esm/clients/decorators/test.js.map +1 -1
  138. package/dist/esm/clients/decorators/wallet.js.map +1 -1
  139. package/dist/esm/errors/version.js +1 -1
  140. package/dist/esm/index.js +1 -1
  141. package/dist/esm/index.js.map +1 -1
  142. package/dist/esm/utils/abi/getAbiItem.js.map +1 -1
  143. package/dist/esm/utils/index.js +1 -1
  144. package/dist/esm/utils/index.js.map +1 -1
  145. package/dist/esm/utils/rpc.js +1 -1
  146. package/dist/esm/utils/rpc.js.map +1 -1
  147. package/dist/esm/utils/signature/index.js +1 -0
  148. package/dist/esm/utils/signature/index.js.map +1 -1
  149. package/dist/esm/utils/signature/recoverAddress.js +2 -11
  150. package/dist/esm/utils/signature/recoverAddress.js.map +1 -1
  151. package/dist/esm/utils/signature/recoverPublicKey.js +14 -0
  152. package/dist/esm/utils/signature/recoverPublicKey.js.map +1 -0
  153. package/dist/types/actions/ens/getEnsAddress.d.ts +0 -1
  154. package/dist/types/actions/ens/getEnsAddress.d.ts.map +1 -1
  155. package/dist/types/actions/ens/getEnsAvatar.d.ts +0 -1
  156. package/dist/types/actions/ens/getEnsAvatar.d.ts.map +1 -1
  157. package/dist/types/actions/ens/getEnsName.d.ts +0 -1
  158. package/dist/types/actions/ens/getEnsName.d.ts.map +1 -1
  159. package/dist/types/actions/ens/getEnsResolver.d.ts +0 -1
  160. package/dist/types/actions/ens/getEnsResolver.d.ts.map +1 -1
  161. package/dist/types/actions/ens/getEnsText.d.ts +0 -1
  162. package/dist/types/actions/ens/getEnsText.d.ts.map +1 -1
  163. package/dist/types/actions/getContract.d.ts +104 -2
  164. package/dist/types/actions/getContract.d.ts.map +1 -1
  165. package/dist/types/actions/public/estimateContractGas.d.ts +0 -1
  166. package/dist/types/actions/public/estimateContractGas.d.ts.map +1 -1
  167. package/dist/types/actions/public/getBalance.d.ts +0 -1
  168. package/dist/types/actions/public/getBalance.d.ts.map +1 -1
  169. package/dist/types/actions/public/getFilterChanges.d.ts +0 -1
  170. package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
  171. package/dist/types/actions/public/getFilterLogs.d.ts +0 -1
  172. package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
  173. package/dist/types/actions/public/getLogs.d.ts +2 -2
  174. package/dist/types/actions/public/getLogs.d.ts.map +1 -1
  175. package/dist/types/actions/public/readContract.d.ts +2 -3
  176. package/dist/types/actions/public/readContract.d.ts.map +1 -1
  177. package/dist/types/actions/public/simulateContract.d.ts +1 -2
  178. package/dist/types/actions/public/simulateContract.d.ts.map +1 -1
  179. package/dist/types/actions/public/uninstallFilter.d.ts +0 -1
  180. package/dist/types/actions/public/uninstallFilter.d.ts.map +1 -1
  181. package/dist/types/actions/public/waitForTransactionReceipt.d.ts +0 -1
  182. package/dist/types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
  183. package/dist/types/actions/public/watchContractEvent.d.ts +0 -1
  184. package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
  185. package/dist/types/actions/public/watchEvent.d.ts +0 -1
  186. package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
  187. package/dist/types/actions/public/watchPendingTransactions.d.ts +0 -1
  188. package/dist/types/actions/public/watchPendingTransactions.d.ts.map +1 -1
  189. package/dist/types/actions/test/dropTransaction.d.ts +22 -0
  190. package/dist/types/actions/test/dropTransaction.d.ts.map +1 -1
  191. package/dist/types/actions/test/getAutomine.d.ts +20 -0
  192. package/dist/types/actions/test/getAutomine.d.ts.map +1 -1
  193. package/dist/types/actions/test/getTxpoolContent.d.ts +22 -0
  194. package/dist/types/actions/test/getTxpoolContent.d.ts.map +1 -1
  195. package/dist/types/actions/test/getTxpoolStatus.d.ts +20 -0
  196. package/dist/types/actions/test/getTxpoolStatus.d.ts.map +1 -1
  197. package/dist/types/actions/test/impersonateAccount.d.ts +22 -0
  198. package/dist/types/actions/test/impersonateAccount.d.ts.map +1 -1
  199. package/dist/types/actions/test/increaseTime.d.ts +22 -0
  200. package/dist/types/actions/test/increaseTime.d.ts.map +1 -1
  201. package/dist/types/actions/test/inspectTxpool.d.ts +20 -0
  202. package/dist/types/actions/test/inspectTxpool.d.ts.map +1 -1
  203. package/dist/types/actions/test/mine.d.ts +20 -0
  204. package/dist/types/actions/test/mine.d.ts.map +1 -1
  205. package/dist/types/actions/test/removeBlockTimestampInterval.d.ts +19 -0
  206. package/dist/types/actions/test/removeBlockTimestampInterval.d.ts.map +1 -1
  207. package/dist/types/actions/test/reset.d.ts +20 -0
  208. package/dist/types/actions/test/reset.d.ts.map +1 -1
  209. package/dist/types/actions/test/revert.d.ts +20 -0
  210. package/dist/types/actions/test/revert.d.ts.map +1 -1
  211. package/dist/types/actions/test/sendUnsignedTransaction.d.ts +25 -0
  212. package/dist/types/actions/test/sendUnsignedTransaction.d.ts.map +1 -1
  213. package/dist/types/actions/test/setAutomine.d.ts +19 -0
  214. package/dist/types/actions/test/setAutomine.d.ts.map +1 -1
  215. package/dist/types/actions/test/setBalance.d.ts +23 -0
  216. package/dist/types/actions/test/setBalance.d.ts.map +1 -1
  217. package/dist/types/actions/test/setBlockGasLimit.d.ts +20 -0
  218. package/dist/types/actions/test/setBlockGasLimit.d.ts.map +1 -1
  219. package/dist/types/actions/test/setBlockTimestampInterval.d.ts +20 -0
  220. package/dist/types/actions/test/setBlockTimestampInterval.d.ts.map +1 -1
  221. package/dist/types/actions/test/setCode.d.ts +23 -0
  222. package/dist/types/actions/test/setCode.d.ts.map +1 -1
  223. package/dist/types/actions/test/setCoinbase.d.ts +22 -0
  224. package/dist/types/actions/test/setCoinbase.d.ts.map +1 -1
  225. package/dist/types/actions/test/setIntervalMining.d.ts +20 -0
  226. package/dist/types/actions/test/setIntervalMining.d.ts.map +1 -1
  227. package/dist/types/actions/test/setLoggingEnabled.d.ts +19 -0
  228. package/dist/types/actions/test/setLoggingEnabled.d.ts.map +1 -1
  229. package/dist/types/actions/test/setMinGasPrice.d.ts +24 -0
  230. package/dist/types/actions/test/setMinGasPrice.d.ts.map +1 -1
  231. package/dist/types/actions/test/setNextBlockBaseFeePerGas.d.ts +22 -0
  232. package/dist/types/actions/test/setNextBlockBaseFeePerGas.d.ts.map +1 -1
  233. package/dist/types/actions/test/setNextBlockTimestamp.d.ts +20 -0
  234. package/dist/types/actions/test/setNextBlockTimestamp.d.ts.map +1 -1
  235. package/dist/types/actions/test/setNonce.d.ts +23 -0
  236. package/dist/types/actions/test/setNonce.d.ts.map +1 -1
  237. package/dist/types/actions/test/setRpcUrl.d.ts +20 -0
  238. package/dist/types/actions/test/setRpcUrl.d.ts.map +1 -1
  239. package/dist/types/actions/test/setStorageAt.d.ts +24 -0
  240. package/dist/types/actions/test/setStorageAt.d.ts.map +1 -1
  241. package/dist/types/actions/test/snapshot.d.ts +19 -0
  242. package/dist/types/actions/test/snapshot.d.ts.map +1 -1
  243. package/dist/types/actions/test/stopImpersonatingAccount.d.ts +22 -0
  244. package/dist/types/actions/test/stopImpersonatingAccount.d.ts.map +1 -1
  245. package/dist/types/actions/wallet/addChain.d.ts +20 -0
  246. package/dist/types/actions/wallet/addChain.d.ts.map +1 -1
  247. package/dist/types/actions/wallet/deployContract.d.ts +1 -1
  248. package/dist/types/actions/wallet/getAddresses.d.ts +20 -0
  249. package/dist/types/actions/wallet/getAddresses.d.ts.map +1 -1
  250. package/dist/types/actions/wallet/getPermissions.d.ts +20 -0
  251. package/dist/types/actions/wallet/getPermissions.d.ts.map +1 -1
  252. package/dist/types/actions/wallet/requestAddresses.d.ts +24 -0
  253. package/dist/types/actions/wallet/requestAddresses.d.ts.map +1 -1
  254. package/dist/types/actions/wallet/requestPermissions.d.ts +26 -3
  255. package/dist/types/actions/wallet/requestPermissions.d.ts.map +1 -1
  256. package/dist/types/actions/wallet/sendTransaction.d.ts +45 -0
  257. package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
  258. package/dist/types/actions/wallet/signMessage.d.ts +46 -0
  259. package/dist/types/actions/wallet/signMessage.d.ts.map +1 -1
  260. package/dist/types/actions/wallet/signTypedData.d.ts +98 -0
  261. package/dist/types/actions/wallet/signTypedData.d.ts.map +1 -1
  262. package/dist/types/actions/wallet/switchChain.d.ts +21 -0
  263. package/dist/types/actions/wallet/switchChain.d.ts.map +1 -1
  264. package/dist/types/actions/wallet/watchAsset.d.ts +28 -0
  265. package/dist/types/actions/wallet/watchAsset.d.ts.map +1 -1
  266. package/dist/types/actions/wallet/writeContract.d.ts +50 -0
  267. package/dist/types/actions/wallet/writeContract.d.ts.map +1 -1
  268. package/dist/types/clients/createPublicClient.d.ts +17 -1
  269. package/dist/types/clients/createPublicClient.d.ts.map +1 -1
  270. package/dist/types/clients/createTestClient.d.ts +20 -0
  271. package/dist/types/clients/createTestClient.d.ts.map +1 -1
  272. package/dist/types/clients/createWalletClient.d.ts +34 -1
  273. package/dist/types/clients/createWalletClient.d.ts.map +1 -1
  274. package/dist/types/clients/decorators/public.d.ts +37 -37
  275. package/dist/types/clients/decorators/test.d.ts +536 -0
  276. package/dist/types/clients/decorators/test.d.ts.map +1 -1
  277. package/dist/types/clients/decorators/wallet.d.ts +389 -2
  278. package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
  279. package/dist/types/errors/version.d.ts +1 -1
  280. package/dist/types/index.d.ts +2 -2
  281. package/dist/types/index.d.ts.map +1 -1
  282. package/dist/types/utils/abi/getAbiItem.d.ts +1 -1
  283. package/dist/types/utils/abi/getAbiItem.d.ts.map +1 -1
  284. package/dist/types/utils/index.d.ts +2 -2
  285. package/dist/types/utils/index.d.ts.map +1 -1
  286. package/dist/types/utils/rpc.d.ts +1 -1
  287. package/dist/types/utils/rpc.d.ts.map +1 -1
  288. package/dist/types/utils/signature/index.d.ts +2 -0
  289. package/dist/types/utils/signature/index.d.ts.map +1 -1
  290. package/dist/types/utils/signature/recoverAddress.d.ts.map +1 -1
  291. package/dist/types/utils/signature/recoverPublicKey.d.ts +8 -0
  292. package/dist/types/utils/signature/recoverPublicKey.d.ts.map +1 -0
  293. package/package.json +1 -1
  294. package/src/actions/ens/getEnsAddress.ts +0 -1
  295. package/src/actions/ens/getEnsAvatar.ts +0 -1
  296. package/src/actions/ens/getEnsName.ts +0 -1
  297. package/src/actions/ens/getEnsResolver.ts +0 -1
  298. package/src/actions/ens/getEnsText.ts +0 -1
  299. package/src/actions/getContract.ts +104 -2
  300. package/src/actions/public/estimateContractGas.ts +0 -1
  301. package/src/actions/public/getBalance.ts +0 -1
  302. package/src/actions/public/getFilterChanges.ts +0 -1
  303. package/src/actions/public/getFilterLogs.ts +0 -1
  304. package/src/actions/public/getLogs.ts +3 -3
  305. package/src/actions/public/readContract.ts +2 -3
  306. package/src/actions/public/simulateContract.ts +1 -2
  307. package/src/actions/public/uninstallFilter.ts +0 -1
  308. package/src/actions/public/waitForTransactionReceipt.ts +0 -1
  309. package/src/actions/public/watchContractEvent.ts +0 -1
  310. package/src/actions/public/watchEvent.ts +0 -1
  311. package/src/actions/public/watchPendingTransactions.ts +0 -1
  312. package/src/actions/test/dropTransaction.ts +22 -0
  313. package/src/actions/test/getAutomine.ts +20 -0
  314. package/src/actions/test/getTxpoolContent.ts +22 -0
  315. package/src/actions/test/getTxpoolStatus.ts +20 -0
  316. package/src/actions/test/impersonateAccount.ts +22 -0
  317. package/src/actions/test/increaseTime.ts +22 -0
  318. package/src/actions/test/inspectTxpool.ts +20 -0
  319. package/src/actions/test/mine.ts +20 -0
  320. package/src/actions/test/removeBlockTimestampInterval.ts +19 -0
  321. package/src/actions/test/reset.ts +20 -0
  322. package/src/actions/test/revert.ts +20 -0
  323. package/src/actions/test/sendUnsignedTransaction.ts +25 -0
  324. package/src/actions/test/setAutomine.ts +19 -0
  325. package/src/actions/test/setBalance.ts +23 -0
  326. package/src/actions/test/setBlockGasLimit.ts +20 -0
  327. package/src/actions/test/setBlockTimestampInterval.ts +20 -0
  328. package/src/actions/test/setCode.ts +23 -0
  329. package/src/actions/test/setCoinbase.ts +22 -0
  330. package/src/actions/test/setIntervalMining.ts +20 -0
  331. package/src/actions/test/setLoggingEnabled.ts +19 -0
  332. package/src/actions/test/setMinGasPrice.ts +24 -0
  333. package/src/actions/test/setNextBlockBaseFeePerGas.ts +22 -0
  334. package/src/actions/test/setNextBlockTimestamp.ts +20 -0
  335. package/src/actions/test/setNonce.ts +23 -0
  336. package/src/actions/test/setRpcUrl.ts +20 -0
  337. package/src/actions/test/setStorageAt.ts +24 -0
  338. package/src/actions/test/snapshot.ts +19 -0
  339. package/src/actions/test/stopImpersonatingAccount.ts +22 -0
  340. package/src/actions/wallet/addChain.ts +20 -0
  341. package/src/actions/wallet/deployContract.ts +1 -1
  342. package/src/actions/wallet/getAddresses.ts +20 -0
  343. package/src/actions/wallet/getPermissions.ts +20 -0
  344. package/src/actions/wallet/requestAddresses.ts +24 -0
  345. package/src/actions/wallet/requestPermissions.ts +31 -6
  346. package/src/actions/wallet/sendTransaction.ts +45 -0
  347. package/src/actions/wallet/signMessage.ts +46 -0
  348. package/src/actions/wallet/signTypedData.ts +98 -0
  349. package/src/actions/wallet/switchChain.ts +24 -1
  350. package/src/actions/wallet/watchAsset.ts +28 -0
  351. package/src/actions/wallet/writeContract.ts +50 -0
  352. package/src/clients/createPublicClient.ts +17 -1
  353. package/src/clients/createTestClient.ts +20 -0
  354. package/src/clients/createWalletClient.ts +34 -1
  355. package/src/clients/decorators/public.ts +37 -37
  356. package/src/clients/decorators/test.ts +536 -0
  357. package/src/clients/decorators/wallet.ts +389 -2
  358. package/src/errors/version.ts +1 -1
  359. package/src/index.ts +3 -0
  360. package/src/utils/abi/getAbiItem.ts +9 -8
  361. package/src/utils/index.ts +3 -0
  362. package/src/utils/rpc.ts +2 -2
  363. package/src/utils/signature/index.ts +6 -0
  364. package/src/utils/signature/recoverAddress.ts +2 -17
  365. package/src/utils/signature/recoverPublicKey.ts +30 -0
@@ -44,6 +44,23 @@ export type WalletActions<
44
44
  TChain extends Chain | undefined = Chain | undefined,
45
45
  TAccount extends Account | undefined = Account | undefined,
46
46
  > = {
47
+ /**
48
+ * Adds an EVM chain to the wallet.
49
+ *
50
+ * - Docs: https://viem.sh/docs/actions/wallet/addChain.html
51
+ * - JSON-RPC Methods: [`eth_addEthereumChain`](https://eips.ethereum.org/EIPS/eip-3085)
52
+ *
53
+ * @param args - {@link AddChainParameters}
54
+ *
55
+ * @example
56
+ * import { createWalletClient, custom } from 'viem'
57
+ * import { optimism } from 'viem/chains'
58
+ *
59
+ * const client = createWalletClient({
60
+ * transport: custom(window.ethereum),
61
+ * })
62
+ * await client.addChain({ chain: optimism })
63
+ */
47
64
  addChain: (args: AddChainParameters) => Promise<void>
48
65
  /**
49
66
  * Deploys a contract to the network, given bytecode and constructor arguments.
@@ -51,7 +68,7 @@ export type WalletActions<
51
68
  * - Docs: https://viem.sh/docs/contract/deployContract.html
52
69
  * - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/deploying-contracts
53
70
  *
54
- * @param parameters - {@link DeployContractParameters}
71
+ * @param args - {@link DeployContractParameters}
55
72
  * @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
56
73
  *
57
74
  * @example
@@ -60,7 +77,7 @@ export type WalletActions<
60
77
  * import { mainnet } from 'viem/chains'
61
78
  *
62
79
  * const client = createWalletClient({
63
- * account = privateKeyToAccount('0x…'),
80
+ * account: privateKeyToAccount('0x…'),
64
81
  * chain: mainnet,
65
82
  * transport: http(),
66
83
  * })
@@ -76,27 +93,397 @@ export type WalletActions<
76
93
  >(
77
94
  args: DeployContractParameters<TAbi, TChain, TAccount, TChainOverride>,
78
95
  ) => Promise<DeployContractReturnType>
96
+ /**
97
+ * Returns a list of account addresses owned by the wallet or client.
98
+ *
99
+ * - Docs: https://viem.sh/docs/actions/wallet/getAddresses.html
100
+ * - JSON-RPC Methods: [`eth_accounts`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_accounts)
101
+ *
102
+ * @returns List of account addresses owned by the wallet or client. {@link GetAddressesReturnType}
103
+ *
104
+ * @example
105
+ * import { createWalletClient, custom } from 'viem'
106
+ * import { mainnet } from 'viem/chains'
107
+ *
108
+ * const client = createWalletClient({
109
+ * chain: mainnet,
110
+ * transport: custom(window.ethereum),
111
+ * })
112
+ * const accounts = await client.getAddresses()
113
+ */
79
114
  getAddresses: () => Promise<GetAddressesReturnType>
115
+ /**
116
+ * Returns the chain ID associated with the current network.
117
+ *
118
+ * - Docs: https://viem.sh/docs/actions/public/getChainId.html
119
+ * - JSON-RPC Methods: [`eth_chainId`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_chainid)
120
+ *
121
+ * @returns The current chain ID. {@link GetChainIdReturnType}
122
+ *
123
+ * @example
124
+ * import { createWalletClient, http } from 'viem'
125
+ * import { mainnet } from 'viem/chains'
126
+ *
127
+ * const client = createWalletClient({
128
+ * chain: mainnet,
129
+ * transport: custom(window.ethereum),
130
+ * })
131
+ * const chainId = await client.getChainId()
132
+ * // 1
133
+ */
80
134
  getChainId: () => Promise<GetChainIdReturnType>
135
+ /**
136
+ * Gets the wallets current permissions.
137
+ *
138
+ * - Docs: https://viem.sh/docs/actions/wallet/getPermissions.html
139
+ * - JSON-RPC Methods: [`wallet_getPermissions`](https://eips.ethereum.org/EIPS/eip-2255)
140
+ *
141
+ * @returns The wallet permissions. {@link GetPermissionsReturnType}
142
+ *
143
+ * @example
144
+ * import { createWalletClient, custom } from 'viem'
145
+ * import { mainnet } from 'viem/chains'
146
+ *
147
+ * const client = createWalletClient({
148
+ * chain: mainnet,
149
+ * transport: custom(window.ethereum),
150
+ * })
151
+ * const permissions = await client.getPermissions()
152
+ */
81
153
  getPermissions: () => Promise<GetPermissionsReturnType>
154
+ /**
155
+ * Requests a list of accounts managed by a wallet.
156
+ *
157
+ * - Docs: https://viem.sh/docs/actions/wallet/requestAddresses.html
158
+ * - JSON-RPC Methods: [`eth_requestAccounts`](https://eips.ethereum.org/EIPS/eip-1102)
159
+ *
160
+ * Sends a request to the wallet, asking for permission to access the user's accounts. After the user accepts the request, it will return a list of accounts (addresses).
161
+ *
162
+ * This API can be useful for dapps that need to access the user's accounts in order to execute transactions or interact with smart contracts.
163
+ *
164
+ * @returns List of accounts managed by a wallet {@link RequestAddressesReturnType}
165
+ *
166
+ * @example
167
+ * import { createWalletClient, custom } from 'viem'
168
+ * import { mainnet } from 'viem/chains'
169
+ *
170
+ * const client = createWalletClient({
171
+ * chain: mainnet,
172
+ * transport: custom(window.ethereum),
173
+ * })
174
+ * const accounts = await client.requestAddresses()
175
+ */
82
176
  requestAddresses: () => Promise<RequestAddressesReturnType>
177
+ /**
178
+ * Requests permissions for a wallet.
179
+ *
180
+ * - Docs: https://viem.sh/docs/actions/wallet/requestPermissions.html
181
+ * - JSON-RPC Methods: [`wallet_requestPermissions`](https://eips.ethereum.org/EIPS/eip-2255)
182
+ *
183
+ * @param args - {@link RequestPermissionsParameters}
184
+ * @returns The wallet permissions. {@link RequestPermissionsReturnType}
185
+ *
186
+ * @example
187
+ * import { createWalletClient, custom } from 'viem'
188
+ * import { mainnet } from 'viem/chains'
189
+ *
190
+ * const client = createWalletClient({
191
+ * chain: mainnet,
192
+ * transport: custom(window.ethereum),
193
+ * })
194
+ * const permissions = await client.requestPermissions({
195
+ * eth_accounts: {}
196
+ * })
197
+ */
83
198
  requestPermissions: (
84
199
  args: RequestPermissionsParameters,
85
200
  ) => Promise<RequestPermissionsReturnType>
201
+ /**
202
+ * Creates, signs, and sends a new transaction to the network.
203
+ *
204
+ * - Docs: https://viem.sh/docs/actions/wallet/sendTransaction.html
205
+ * - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/transactions/sending-transactions
206
+ * - JSON-RPC Methods:
207
+ * - JSON-RPC Accounts: [`eth_sendTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendtransaction)
208
+ * - Local Accounts: [`eth_sendRawTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendrawtransaction)
209
+ *
210
+ * @param args - {@link SendTransactionParameters}
211
+ * @returns The [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) hash. {@link SendTransactionReturnType}
212
+ *
213
+ * @example
214
+ * import { createWalletClient, custom } from 'viem'
215
+ * import { mainnet } from 'viem/chains'
216
+ *
217
+ * const client = createWalletClient({
218
+ * chain: mainnet,
219
+ * transport: custom(window.ethereum),
220
+ * })
221
+ * const hash = await client.sendTransaction({
222
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
223
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
224
+ * value: 1000000000000000000n,
225
+ * })
226
+ *
227
+ * @example
228
+ * // Account Hoisting
229
+ * import { createWalletClient, http } from 'viem'
230
+ * import { privateKeyToAccount } from 'viem/accounts'
231
+ * import { mainnet } from 'viem/chains'
232
+ *
233
+ * const client = createWalletClient({
234
+ * account: privateKeyToAccount('0x…'),
235
+ * chain: mainnet,
236
+ * transport: http(),
237
+ * })
238
+ * const hash = await client.sendTransaction({
239
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
240
+ * value: 1000000000000000000n,
241
+ * })
242
+ */
86
243
  sendTransaction: <TChainOverride extends Chain | undefined>(
87
244
  args: SendTransactionParameters<TChain, TAccount, TChainOverride>,
88
245
  ) => Promise<SendTransactionReturnType>
246
+ /**
247
+ * Calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191): `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`.
248
+ *
249
+ * - Docs: https://viem.sh/docs/actions/wallet/signMessage.html
250
+ * - JSON-RPC Methods:
251
+ * - JSON-RPC Accounts: [`personal_sign`](https://docs.metamask.io/guide/signing-data.html#personal-sign)
252
+ * - Local Accounts: Signs locally. No JSON-RPC request.
253
+ *
254
+ * With the calculated signature, you can:
255
+ * - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage) to verify the signature,
256
+ * - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress) to recover the signing address from a signature.
257
+ *
258
+ * @param args - {@link SignMessageParameters}
259
+ * @returns The signed message. {@link SignMessageReturnType}
260
+ *
261
+ * @example
262
+ * import { createWalletClient, custom } from 'viem'
263
+ * import { mainnet } from 'viem/chains'
264
+ *
265
+ * const client = createWalletClient({
266
+ * chain: mainnet,
267
+ * transport: custom(window.ethereum),
268
+ * })
269
+ * const signature = await client.signMessage({
270
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
271
+ * message: 'hello world',
272
+ * })
273
+ *
274
+ * @example
275
+ * // Account Hoisting
276
+ * import { createWalletClient, http } from 'viem'
277
+ * import { privateKeyToAccount } from 'viem/accounts'
278
+ * import { mainnet } from 'viem/chains'
279
+ *
280
+ * const client = createWalletClient({
281
+ * account: privateKeyToAccount('0x…'),
282
+ * chain: mainnet,
283
+ * transport: http(),
284
+ * })
285
+ * const signature = await client.signMessage({
286
+ * message: 'hello world',
287
+ * })
288
+ */
89
289
  signMessage: (
90
290
  args: SignMessageParameters<TAccount>,
91
291
  ) => Promise<SignMessageReturnType>
292
+ /**
293
+ * Signs typed data and calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191): `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`.
294
+ *
295
+ * - Docs: https://viem.sh/docs/actions/wallet/signTypedData.html
296
+ * - JSON-RPC Methods:
297
+ * - JSON-RPC Accounts: [`eth_signTypedData_v4`](https://docs.metamask.io/guide/signing-data.html#signtypeddata-v4)
298
+ * - Local Accounts: Signs locally. No JSON-RPC request.
299
+ *
300
+ * @param client - Client to use
301
+ * @param args - {@link SignTypedDataParameters}
302
+ * @returns The signed data. {@link SignTypedDataReturnType}
303
+ *
304
+ * @example
305
+ * import { createWalletClient, custom } from 'viem'
306
+ * import { mainnet } from 'viem/chains'
307
+ *
308
+ * const client = createWalletClient({
309
+ * chain: mainnet,
310
+ * transport: custom(window.ethereum),
311
+ * })
312
+ * const signature = await client.signTypedData({
313
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
314
+ * domain: {
315
+ * name: 'Ether Mail',
316
+ * version: '1',
317
+ * chainId: 1,
318
+ * verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
319
+ * },
320
+ * types: {
321
+ * Person: [
322
+ * { name: 'name', type: 'string' },
323
+ * { name: 'wallet', type: 'address' },
324
+ * ],
325
+ * Mail: [
326
+ * { name: 'from', type: 'Person' },
327
+ * { name: 'to', type: 'Person' },
328
+ * { name: 'contents', type: 'string' },
329
+ * ],
330
+ * },
331
+ * primaryType: 'Mail',
332
+ * message: {
333
+ * from: {
334
+ * name: 'Cow',
335
+ * wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
336
+ * },
337
+ * to: {
338
+ * name: 'Bob',
339
+ * wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
340
+ * },
341
+ * contents: 'Hello, Bob!',
342
+ * },
343
+ * })
344
+ *
345
+ * @example
346
+ * // Account Hoisting
347
+ * import { createWalletClient, http } from 'viem'
348
+ * import { privateKeyToAccount } from 'viem/accounts'
349
+ * import { mainnet } from 'viem/chains'
350
+ *
351
+ * const client = createWalletClient({
352
+ * account: privateKeyToAccount('0x…'),
353
+ * chain: mainnet,
354
+ * transport: http(),
355
+ * })
356
+ * const signature = await client.signTypedData({
357
+ * domain: {
358
+ * name: 'Ether Mail',
359
+ * version: '1',
360
+ * chainId: 1,
361
+ * verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
362
+ * },
363
+ * types: {
364
+ * Person: [
365
+ * { name: 'name', type: 'string' },
366
+ * { name: 'wallet', type: 'address' },
367
+ * ],
368
+ * Mail: [
369
+ * { name: 'from', type: 'Person' },
370
+ * { name: 'to', type: 'Person' },
371
+ * { name: 'contents', type: 'string' },
372
+ * ],
373
+ * },
374
+ * primaryType: 'Mail',
375
+ * message: {
376
+ * from: {
377
+ * name: 'Cow',
378
+ * wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
379
+ * },
380
+ * to: {
381
+ * name: 'Bob',
382
+ * wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
383
+ * },
384
+ * contents: 'Hello, Bob!',
385
+ * },
386
+ * })
387
+ */
92
388
  signTypedData: <
93
389
  TTypedData extends TypedData | { [key: string]: unknown },
94
390
  TPrimaryType extends string,
95
391
  >(
96
392
  args: SignTypedDataParameters<TTypedData, TPrimaryType, TAccount>,
97
393
  ) => Promise<SignTypedDataReturnType>
394
+ /**
395
+ * Switch the target chain in a wallet.
396
+ *
397
+ * - Docs: https://viem.sh/docs/actions/wallet/switchChain.html
398
+ * - JSON-RPC Methods: [`eth_switchEthereumChain`](https://eips.ethereum.org/EIPS/eip-3326)
399
+ *
400
+ * @param args - {@link SwitchChainParameters}
401
+ *
402
+ * @example
403
+ * import { createWalletClient, custom } from 'viem'
404
+ * import { mainnet, optimism } from 'viem/chains'
405
+ *
406
+ * const client = createWalletClient({
407
+ * chain: mainnet,
408
+ * transport: custom(window.ethereum),
409
+ * })
410
+ * await client.switchChain({ id: optimism.id })
411
+ */
98
412
  switchChain: (args: SwitchChainParameters) => Promise<void>
413
+ /**
414
+ * Adds an EVM chain to the wallet.
415
+ *
416
+ * - Docs: https://viem.sh/docs/actions/wallet/watchAsset.html
417
+ * - JSON-RPC Methods: [`eth_switchEthereumChain`](https://eips.ethereum.org/EIPS/eip-747)
418
+ *
419
+ * @param args - {@link WatchAssetParameters}
420
+ * @returns Boolean indicating if the token was successfully added. {@link WatchAssetReturnType}
421
+ *
422
+ * @example
423
+ * import { createWalletClient, custom } from 'viem'
424
+ * import { mainnet } from 'viem/chains'
425
+ *
426
+ * const client = createWalletClient({
427
+ * chain: mainnet,
428
+ * transport: custom(window.ethereum),
429
+ * })
430
+ * const success = await client.watchAsset({
431
+ * type: 'ERC20',
432
+ * options: {
433
+ * address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
434
+ * decimals: 18,
435
+ * symbol: 'WETH',
436
+ * },
437
+ * })
438
+ */
99
439
  watchAsset: (args: WatchAssetParameters) => Promise<WatchAssetReturnType>
440
+ /**
441
+ * Executes a write function on a contract.
442
+ *
443
+ * - Docs: https://viem.sh/docs/contract/writeContract.html
444
+ * - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/writing-to-contracts
445
+ *
446
+ * A "write" function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a [Transaction](https://viem.sh/docs/glossary/terms) is needed to be broadcast in order to change the state.
447
+ *
448
+ * Internally, uses a [Wallet Client](https://viem.sh/docs/clients/wallet) to call the [`sendTransaction` action](https://viem.sh/docs/actions/wallet/sendTransaction) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
449
+ *
450
+ * __Warning: The `write` internally sends a transaction – it does not validate if the contract write will succeed (the contract may throw an error). It is highly recommended to [simulate the contract write with `contract.simulate`](https://viem.sh/docs/contract/writeContract.html#usage) before you execute it.__
451
+ *
452
+ * @param args - {@link WriteContractParameters}
453
+ * @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms#hash). {@link WriteContractReturnType}
454
+ *
455
+ * @example
456
+ * import { createWalletClient, custom, parseAbi } from 'viem'
457
+ * import { mainnet } from 'viem/chains'
458
+ *
459
+ * const client = createWalletClient({
460
+ * chain: mainnet,
461
+ * transport: custom(window.ethereum),
462
+ * })
463
+ * const hash = await client.writeContract({
464
+ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
465
+ * abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
466
+ * functionName: 'mint',
467
+ * args: [69420],
468
+ * })
469
+ *
470
+ * @example
471
+ * // With Validation
472
+ * import { createWalletClient, custom, parseAbi } from 'viem'
473
+ * import { mainnet } from 'viem/chains'
474
+ *
475
+ * const client = createWalletClient({
476
+ * chain: mainnet,
477
+ * transport: custom(window.ethereum),
478
+ * })
479
+ * const { request } = await client.simulateContract({
480
+ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
481
+ * abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
482
+ * functionName: 'mint',
483
+ * args: [69420],
484
+ * }
485
+ * const hash = await client.writeContract(request)
486
+ */
100
487
  writeContract: <
101
488
  TAbi extends Abi | readonly unknown[],
102
489
  TFunctionName extends string,
@@ -1 +1 @@
1
- export const version = '0.3.0'
1
+ export const version = '0.3.2'
package/src/index.ts CHANGED
@@ -372,6 +372,8 @@ export type {
372
372
  RecoverAddressReturnType,
373
373
  RecoverMessageAddressParameters,
374
374
  RecoverMessageAddressReturnType,
375
+ RecoverPublicKeyParameters,
376
+ RecoverPublicKeyReturnType,
375
377
  RecoverTypedDataAddressParameters,
376
378
  RecoverTypedDataAddressReturnType,
377
379
  ToRlpReturnType,
@@ -463,6 +465,7 @@ export {
463
465
  prepareRequest,
464
466
  recoverAddress,
465
467
  recoverMessageAddress,
468
+ recoverPublicKey,
466
469
  recoverTypedDataAddress,
467
470
  serializeTransaction,
468
471
  size,
@@ -23,22 +23,23 @@ export type GetAbiItemReturnType<
23
23
  export function getAbiItem<
24
24
  TAbi extends Abi | readonly unknown[],
25
25
  TItemName extends string,
26
- TReturnType = GetAbiItemReturnType<TAbi, TItemName>,
27
26
  >({
28
27
  abi,
29
28
  args = [],
30
29
  name,
31
- }: GetAbiItemParameters<TAbi, TItemName>): TReturnType {
30
+ }: GetAbiItemParameters<TAbi, TItemName>): GetAbiItemReturnType<
31
+ TAbi,
32
+ TItemName
33
+ > {
32
34
  const abiItems = (abi as Abi).filter((x) => 'name' in x && x.name === name)
33
35
 
34
- if (abiItems.length === 0) return undefined as unknown as TReturnType
35
- if (abiItems.length === 1) return abiItems[0] as unknown as TReturnType
36
+ if (abiItems.length === 0) return undefined as any
37
+ if (abiItems.length === 1) return abiItems[0] as any
36
38
 
37
39
  for (const abiItem of abiItems) {
38
40
  if (!('inputs' in abiItem)) continue
39
41
  if (!args || args.length === 0) {
40
- if (!abiItem.inputs || abiItem.inputs.length === 0)
41
- return abiItem as unknown as TReturnType
42
+ if (!abiItem.inputs || abiItem.inputs.length === 0) return abiItem as any
42
43
  continue
43
44
  }
44
45
  if (!abiItem.inputs) continue
@@ -48,9 +49,9 @@ export function getAbiItem<
48
49
  if (!abiParameter) return false
49
50
  return isArgOfType(arg, abiParameter as AbiParameter)
50
51
  })
51
- if (matched) return abiItem as unknown as TReturnType
52
+ if (matched) return abiItem as any
52
53
  }
53
- return abiItems[0] as unknown as TReturnType
54
+ return abiItems[0] as any
54
55
  }
55
56
 
56
57
  export function isArgOfType(arg: unknown, abiParameter: AbiParameter): boolean {
@@ -165,6 +165,8 @@ export type {
165
165
  RecoverAddressReturnType,
166
166
  RecoverMessageAddressParameters,
167
167
  RecoverMessageAddressReturnType,
168
+ RecoverPublicKeyParameters,
169
+ RecoverPublicKeyReturnType,
168
170
  RecoverTypedDataAddressParameters,
169
171
  RecoverTypedDataAddressReturnType,
170
172
  VerifyMessageParameters,
@@ -177,6 +179,7 @@ export {
177
179
  hashTypedData,
178
180
  recoverAddress,
179
181
  recoverMessageAddress,
182
+ recoverPublicKey,
180
183
  recoverTypedDataAddress,
181
184
  verifyMessage,
182
185
  verifyTypedData,
package/src/utils/rpc.ts CHANGED
@@ -1,5 +1,4 @@
1
- import WebSocket from 'isomorphic-ws'
2
- import type { MessageEvent } from 'isomorphic-ws'
1
+ import type { WebSocket, MessageEvent } from 'isomorphic-ws'
3
2
  import {
4
3
  HttpRequestError,
5
4
  RpcRequestError,
@@ -145,6 +144,7 @@ export async function getSocket(url_: string) {
145
144
  // If the socket already exists, return it.
146
145
  if (socket) return socket
147
146
 
147
+ const { WebSocket } = await import('isomorphic-ws')
148
148
  const webSocket = new WebSocket(url)
149
149
 
150
150
  // Set up a cache for incoming "synchronous" requests.
@@ -18,6 +18,12 @@ export type {
18
18
  } from './recoverMessageAddress.js'
19
19
  export { recoverMessageAddress } from './recoverMessageAddress.js'
20
20
 
21
+ export type {
22
+ RecoverPublicKeyParameters,
23
+ RecoverPublicKeyReturnType,
24
+ } from './recoverPublicKey.js'
25
+ export { recoverPublicKey } from './recoverPublicKey.js'
26
+
21
27
  export type {
22
28
  RecoverTypedDataAddressParameters,
23
29
  RecoverTypedDataAddressReturnType,
@@ -1,7 +1,6 @@
1
1
  import type { Address, ByteArray, Hex } from '../../types/index.js'
2
2
  import { publicKeyToAddress } from '../accounts.js'
3
- import { isHex } from '../data/index.js'
4
- import { hexToNumber, toHex } from '../encoding/index.js'
3
+ import { recoverPublicKey } from './recoverPublicKey.js'
5
4
 
6
5
  export type RecoverAddressParameters = {
7
6
  hash: Hex | ByteArray
@@ -13,19 +12,5 @@ export async function recoverAddress({
13
12
  hash,
14
13
  signature,
15
14
  }: RecoverAddressParameters): Promise<RecoverAddressReturnType> {
16
- const signatureHex = isHex(signature) ? signature : toHex(signature)
17
- const hashHex = isHex(hash) ? hash : toHex(hash)
18
-
19
- // Derive v = recoveryId + 27 from end of the signature (27 is added when signing the message)
20
- // The recoveryId represents the y-coordinate on the secp256k1 elliptic curve and can have a value [0, 1].
21
- const v = hexToNumber(`0x${signatureHex.slice(130)}`)
22
-
23
- const { secp256k1 } = await import('@noble/curves/secp256k1')
24
- const publicKey = secp256k1.Signature.fromCompact(
25
- signatureHex.substring(2, 130),
26
- )
27
- .addRecoveryBit(v - 27)
28
- .recoverPublicKey(hashHex.substring(2))
29
- .toHex(false)
30
- return publicKeyToAddress(`0x${publicKey}`)
15
+ return publicKeyToAddress(await recoverPublicKey({ hash: hash, signature }))
31
16
  }
@@ -0,0 +1,30 @@
1
+ import type { ByteArray, Hex } from '../../types/index.js'
2
+ import { isHex } from '../data/index.js'
3
+ import { hexToNumber, toHex } from '../encoding/index.js'
4
+
5
+ export type RecoverPublicKeyParameters = {
6
+ hash: Hex | ByteArray
7
+ signature: Hex | ByteArray
8
+ }
9
+ export type RecoverPublicKeyReturnType = Hex
10
+
11
+ export async function recoverPublicKey({
12
+ hash,
13
+ signature,
14
+ }: RecoverPublicKeyParameters): Promise<RecoverPublicKeyReturnType> {
15
+ const signatureHex = isHex(signature) ? signature : toHex(signature)
16
+ const hashHex = isHex(hash) ? hash : toHex(hash)
17
+
18
+ // Derive v = recoveryId + 27 from end of the signature (27 is added when signing the message)
19
+ // The recoveryId represents the y-coordinate on the secp256k1 elliptic curve and can have a value [0, 1].
20
+ const v = hexToNumber(`0x${signatureHex.slice(130)}`)
21
+
22
+ const { secp256k1 } = await import('@noble/curves/secp256k1')
23
+ const publicKey = secp256k1.Signature.fromCompact(
24
+ signatureHex.substring(2, 130),
25
+ )
26
+ .addRecoveryBit(v - 27)
27
+ .recoverPublicKey(hashHex.substring(2))
28
+ .toHex(false)
29
+ return `0x${publicKey}`
30
+ }