viem 2.57.14 → 2.57.16

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 (363) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
  3. package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
  4. package/_cjs/actions/public/estimateGas.js +5 -2
  5. package/_cjs/actions/public/estimateGas.js.map +1 -1
  6. package/_cjs/actions/public/fillTransaction.js +2 -0
  7. package/_cjs/actions/public/fillTransaction.js.map +1 -1
  8. package/_cjs/actions/public/getFilterChanges.js +1 -0
  9. package/_cjs/actions/public/getFilterChanges.js.map +1 -1
  10. package/_cjs/actions/public/getFilterLogs.js +1 -0
  11. package/_cjs/actions/public/getFilterLogs.js.map +1 -1
  12. package/_cjs/actions/public/watchBlockNumber.js +3 -1
  13. package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
  14. package/_cjs/actions/public/watchBlocks.js +20 -8
  15. package/_cjs/actions/public/watchBlocks.js.map +1 -1
  16. package/_cjs/actions/public/watchContractEvent.js +10 -3
  17. package/_cjs/actions/public/watchContractEvent.js.map +1 -1
  18. package/_cjs/actions/public/watchEvent.js +5 -0
  19. package/_cjs/actions/public/watchEvent.js.map +1 -1
  20. package/_cjs/actions/wallet/prepareTransactionRequest.js +3 -2
  21. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  22. package/_cjs/actions/wallet/sendTransaction.js +4 -2
  23. package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
  24. package/_cjs/actions/wallet/sendTransactionSync.js +48 -7
  25. package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
  26. package/_cjs/chains/definitions/hashKeyChain.js +4 -4
  27. package/_cjs/chains/definitions/hashKeyChain.js.map +1 -1
  28. package/_cjs/chains/definitions/hashkeyChainTestnet.js +4 -4
  29. package/_cjs/chains/definitions/hashkeyChainTestnet.js.map +1 -1
  30. package/_cjs/chains/definitions/turkchain.js +26 -0
  31. package/_cjs/chains/definitions/turkchain.js.map +1 -0
  32. package/_cjs/chains/definitions/zksync.js +1 -1
  33. package/_cjs/chains/definitions/zksync.js.map +1 -1
  34. package/_cjs/chains/index.js +4 -2
  35. package/_cjs/chains/index.js.map +1 -1
  36. package/_cjs/clients/createClient.js.map +1 -1
  37. package/_cjs/clients/transports/fallback.js +5 -0
  38. package/_cjs/clients/transports/fallback.js.map +1 -1
  39. package/_cjs/errors/node.js +10 -4
  40. package/_cjs/errors/node.js.map +1 -1
  41. package/_cjs/errors/typedData.js +4 -2
  42. package/_cjs/errors/typedData.js.map +1 -1
  43. package/_cjs/errors/version.js +1 -1
  44. package/_cjs/index.js +5 -4
  45. package/_cjs/index.js.map +1 -1
  46. package/_cjs/tempo/Account.js +85 -12
  47. package/_cjs/tempo/Account.js.map +1 -1
  48. package/_cjs/tempo/Gateway.js +195 -0
  49. package/_cjs/tempo/Gateway.js.map +1 -0
  50. package/_cjs/tempo/GatewayDecorator.js +168 -0
  51. package/_cjs/tempo/GatewayDecorator.js.map +1 -0
  52. package/_cjs/tempo/Transaction.js +2 -1
  53. package/_cjs/tempo/Transaction.js.map +1 -1
  54. package/_cjs/tempo/actions/ai.js +69 -0
  55. package/_cjs/tempo/actions/ai.js.map +1 -0
  56. package/_cjs/tempo/actions/bucket.js +85 -0
  57. package/_cjs/tempo/actions/bucket.js.map +1 -0
  58. package/_cjs/tempo/actions/compute.js +165 -0
  59. package/_cjs/tempo/actions/compute.js.map +1 -0
  60. package/_cjs/tempo/actions/gateway.js +8 -0
  61. package/_cjs/tempo/actions/gateway.js.map +1 -0
  62. package/_cjs/tempo/actions/index.js +6 -1
  63. package/_cjs/tempo/actions/index.js.map +1 -1
  64. package/_cjs/tempo/actions/kv.js +44 -0
  65. package/_cjs/tempo/actions/kv.js.map +1 -0
  66. package/_cjs/tempo/chainConfig.js +4 -12
  67. package/_cjs/tempo/chainConfig.js.map +1 -1
  68. package/_cjs/tempo/index.js +4 -1
  69. package/_cjs/tempo/index.js.map +1 -1
  70. package/_cjs/tempo/internal/ndjson.js +43 -0
  71. package/_cjs/tempo/internal/ndjson.js.map +1 -0
  72. package/_cjs/tempo/internal/relay/feePayer.js +18 -5
  73. package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
  74. package/_cjs/utils/abi/decodeEventLog.js +57 -7
  75. package/_cjs/utils/abi/decodeEventLog.js.map +1 -1
  76. package/_cjs/utils/abi/getAbiItem.js +27 -6
  77. package/_cjs/utils/abi/getAbiItem.js.map +1 -1
  78. package/_cjs/utils/abi/parseEventLogs.js +27 -4
  79. package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
  80. package/_cjs/utils/authorization/recoverAuthorizationAddress.js +9 -2
  81. package/_cjs/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
  82. package/_cjs/utils/authorization/verifyAuthorization.js +14 -4
  83. package/_cjs/utils/authorization/verifyAuthorization.js.map +1 -1
  84. package/_cjs/utils/buildRequest.js +4 -0
  85. package/_cjs/utils/buildRequest.js.map +1 -1
  86. package/_cjs/utils/ccip.js +134 -28
  87. package/_cjs/utils/ccip.js.map +1 -1
  88. package/_cjs/utils/ccipTunnel.js +5 -1
  89. package/_cjs/utils/ccipTunnel.js.map +1 -1
  90. package/_cjs/utils/ens/localBatchGatewayRequest.js +55 -5
  91. package/_cjs/utils/ens/localBatchGatewayRequest.js.map +1 -1
  92. package/_cjs/utils/hash/toSignatureHash.js +10 -1
  93. package/_cjs/utils/hash/toSignatureHash.js.map +1 -1
  94. package/_cjs/utils/internal/http.js +79 -0
  95. package/_cjs/utils/internal/http.js.map +1 -0
  96. package/_cjs/utils/nonceManager.js.map +1 -1
  97. package/_cjs/utils/rpc/http.js +9 -76
  98. package/_cjs/utils/rpc/http.js.map +1 -1
  99. package/_cjs/utils/rpc/socket.js +20 -9
  100. package/_cjs/utils/rpc/socket.js.map +1 -1
  101. package/_cjs/utils/transaction/assertRequest.js +2 -2
  102. package/_cjs/utils/transaction/assertRequest.js.map +1 -1
  103. package/_cjs/utils/transaction/assertTransaction.js +2 -2
  104. package/_cjs/utils/transaction/assertTransaction.js.map +1 -1
  105. package/_cjs/utils/transaction/parseTransaction.js +21 -7
  106. package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
  107. package/_cjs/utils/typedData.js +19 -6
  108. package/_cjs/utils/typedData.js.map +1 -1
  109. package/_cjs/zksync/actions/finalizeWithdrawal.js +4 -2
  110. package/_cjs/zksync/actions/finalizeWithdrawal.js.map +1 -1
  111. package/_cjs/zksync/actions/isWithdrawalFinalized.js +4 -5
  112. package/_cjs/zksync/actions/isWithdrawalFinalized.js.map +1 -1
  113. package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
  114. package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
  115. package/_esm/actions/public/estimateGas.js +10 -5
  116. package/_esm/actions/public/estimateGas.js.map +1 -1
  117. package/_esm/actions/public/fillTransaction.js +2 -0
  118. package/_esm/actions/public/fillTransaction.js.map +1 -1
  119. package/_esm/actions/public/getFilterChanges.js +1 -0
  120. package/_esm/actions/public/getFilterChanges.js.map +1 -1
  121. package/_esm/actions/public/getFilterLogs.js +1 -0
  122. package/_esm/actions/public/getFilterLogs.js.map +1 -1
  123. package/_esm/actions/public/watchBlockNumber.js +5 -1
  124. package/_esm/actions/public/watchBlockNumber.js.map +1 -1
  125. package/_esm/actions/public/watchBlocks.js +28 -8
  126. package/_esm/actions/public/watchBlocks.js.map +1 -1
  127. package/_esm/actions/public/watchContractEvent.js +15 -5
  128. package/_esm/actions/public/watchContractEvent.js.map +1 -1
  129. package/_esm/actions/public/watchEvent.js +11 -2
  130. package/_esm/actions/public/watchEvent.js.map +1 -1
  131. package/_esm/actions/wallet/prepareTransactionRequest.js +3 -2
  132. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  133. package/_esm/actions/wallet/sendTransaction.js +6 -2
  134. package/_esm/actions/wallet/sendTransaction.js.map +1 -1
  135. package/_esm/actions/wallet/sendTransactionSync.js +59 -8
  136. package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
  137. package/_esm/chains/definitions/hashKeyChain.js +4 -4
  138. package/_esm/chains/definitions/hashKeyChain.js.map +1 -1
  139. package/_esm/chains/definitions/hashkeyChainTestnet.js +4 -4
  140. package/_esm/chains/definitions/hashkeyChainTestnet.js.map +1 -1
  141. package/_esm/chains/definitions/turkchain.js +23 -0
  142. package/_esm/chains/definitions/turkchain.js.map +1 -0
  143. package/_esm/chains/definitions/zksync.js +1 -1
  144. package/_esm/chains/definitions/zksync.js.map +1 -1
  145. package/_esm/chains/index.js +1 -0
  146. package/_esm/chains/index.js.map +1 -1
  147. package/_esm/clients/createClient.js.map +1 -1
  148. package/_esm/clients/transports/fallback.js +8 -0
  149. package/_esm/clients/transports/fallback.js.map +1 -1
  150. package/_esm/errors/node.js +10 -4
  151. package/_esm/errors/node.js.map +1 -1
  152. package/_esm/errors/typedData.js +5 -2
  153. package/_esm/errors/typedData.js.map +1 -1
  154. package/_esm/errors/version.js +1 -1
  155. package/_esm/index.js +1 -1
  156. package/_esm/index.js.map +1 -1
  157. package/_esm/tempo/Account.js +122 -11
  158. package/_esm/tempo/Account.js.map +1 -1
  159. package/_esm/tempo/Gateway.js +294 -0
  160. package/_esm/tempo/Gateway.js.map +1 -0
  161. package/_esm/tempo/GatewayDecorator.js +207 -0
  162. package/_esm/tempo/GatewayDecorator.js.map +1 -0
  163. package/_esm/tempo/Transaction.js +2 -0
  164. package/_esm/tempo/Transaction.js.map +1 -1
  165. package/_esm/tempo/actions/ai.js +132 -0
  166. package/_esm/tempo/actions/ai.js.map +1 -0
  167. package/_esm/tempo/actions/bucket.js +181 -0
  168. package/_esm/tempo/actions/bucket.js.map +1 -0
  169. package/_esm/tempo/actions/compute.js +424 -0
  170. package/_esm/tempo/actions/compute.js.map +1 -0
  171. package/_esm/tempo/actions/gateway.js +22 -0
  172. package/_esm/tempo/actions/gateway.js.map +1 -0
  173. package/_esm/tempo/actions/index.js +10 -0
  174. package/_esm/tempo/actions/index.js.map +1 -1
  175. package/_esm/tempo/actions/kv.js +124 -0
  176. package/_esm/tempo/actions/kv.js.map +1 -0
  177. package/_esm/tempo/chainConfig.js +13 -15
  178. package/_esm/tempo/chainConfig.js.map +1 -1
  179. package/_esm/tempo/index.js +9 -0
  180. package/_esm/tempo/index.js.map +1 -1
  181. package/_esm/tempo/internal/ndjson.js +45 -0
  182. package/_esm/tempo/internal/ndjson.js.map +1 -0
  183. package/_esm/tempo/internal/relay/feePayer.js +24 -7
  184. package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
  185. package/_esm/utils/abi/decodeEventLog.js +69 -7
  186. package/_esm/utils/abi/decodeEventLog.js.map +1 -1
  187. package/_esm/utils/abi/getAbiItem.js +34 -6
  188. package/_esm/utils/abi/getAbiItem.js.map +1 -1
  189. package/_esm/utils/abi/parseEventLogs.js +43 -10
  190. package/_esm/utils/abi/parseEventLogs.js.map +1 -1
  191. package/_esm/utils/authorization/recoverAuthorizationAddress.js +11 -2
  192. package/_esm/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
  193. package/_esm/utils/authorization/verifyAuthorization.js +15 -4
  194. package/_esm/utils/authorization/verifyAuthorization.js.map +1 -1
  195. package/_esm/utils/buildRequest.js +6 -0
  196. package/_esm/utils/buildRequest.js.map +1 -1
  197. package/_esm/utils/ccip.js +163 -31
  198. package/_esm/utils/ccip.js.map +1 -1
  199. package/_esm/utils/ccipTunnel.js +5 -1
  200. package/_esm/utils/ccipTunnel.js.map +1 -1
  201. package/_esm/utils/ens/localBatchGatewayRequest.js +69 -4
  202. package/_esm/utils/ens/localBatchGatewayRequest.js.map +1 -1
  203. package/_esm/utils/hash/toSignatureHash.js +11 -1
  204. package/_esm/utils/hash/toSignatureHash.js.map +1 -1
  205. package/_esm/utils/internal/http.js +83 -0
  206. package/_esm/utils/internal/http.js.map +1 -0
  207. package/_esm/utils/nonceManager.js.map +1 -1
  208. package/_esm/utils/rpc/http.js +12 -78
  209. package/_esm/utils/rpc/http.js.map +1 -1
  210. package/_esm/utils/rpc/socket.js +24 -9
  211. package/_esm/utils/rpc/socket.js.map +1 -1
  212. package/_esm/utils/transaction/assertRequest.js +2 -2
  213. package/_esm/utils/transaction/assertRequest.js.map +1 -1
  214. package/_esm/utils/transaction/assertTransaction.js +2 -2
  215. package/_esm/utils/transaction/assertTransaction.js.map +1 -1
  216. package/_esm/utils/transaction/parseTransaction.js +24 -7
  217. package/_esm/utils/transaction/parseTransaction.js.map +1 -1
  218. package/_esm/utils/typedData.js +25 -8
  219. package/_esm/utils/typedData.js.map +1 -1
  220. package/_esm/zksync/actions/finalizeWithdrawal.js +5 -2
  221. package/_esm/zksync/actions/finalizeWithdrawal.js.map +1 -1
  222. package/_esm/zksync/actions/isWithdrawalFinalized.js +5 -5
  223. package/_esm/zksync/actions/isWithdrawalFinalized.js.map +1 -1
  224. package/_types/account-abstraction/utils/formatters/userOperationReceipt.d.ts.map +1 -1
  225. package/_types/actions/public/estimateGas.d.ts.map +1 -1
  226. package/_types/actions/public/fillTransaction.d.ts.map +1 -1
  227. package/_types/actions/public/getFilterChanges.d.ts.map +1 -1
  228. package/_types/actions/public/getFilterLogs.d.ts.map +1 -1
  229. package/_types/actions/public/watchBlockNumber.d.ts +6 -2
  230. package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
  231. package/_types/actions/public/watchBlocks.d.ts +7 -2
  232. package/_types/actions/public/watchBlocks.d.ts.map +1 -1
  233. package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
  234. package/_types/actions/public/watchEvent.d.ts.map +1 -1
  235. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  236. package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
  237. package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
  238. package/_types/chains/definitions/hashKeyChain.d.ts +4 -4
  239. package/_types/chains/definitions/hashkeyChainTestnet.d.ts +4 -4
  240. package/_types/chains/definitions/turkchain.d.ts +53 -0
  241. package/_types/chains/definitions/turkchain.d.ts.map +1 -0
  242. package/_types/chains/definitions/zksync.d.ts +1 -1
  243. package/_types/chains/index.d.ts +1 -0
  244. package/_types/chains/index.d.ts.map +1 -1
  245. package/_types/clients/createClient.d.ts +6 -0
  246. package/_types/clients/createClient.d.ts.map +1 -1
  247. package/_types/clients/transports/fallback.d.ts.map +1 -1
  248. package/_types/errors/node.d.ts.map +1 -1
  249. package/_types/errors/typedData.d.ts.map +1 -1
  250. package/_types/errors/version.d.ts +1 -1
  251. package/_types/index.d.ts +1 -1
  252. package/_types/index.d.ts.map +1 -1
  253. package/_types/tempo/Account.d.ts +77 -4
  254. package/_types/tempo/Account.d.ts.map +1 -1
  255. package/_types/tempo/Gateway.d.ts +337 -0
  256. package/_types/tempo/Gateway.d.ts.map +1 -0
  257. package/_types/tempo/GatewayDecorator.d.ts +635 -0
  258. package/_types/tempo/GatewayDecorator.d.ts.map +1 -0
  259. package/_types/tempo/Relay.d.ts +1 -1
  260. package/_types/tempo/Relay.d.ts.map +1 -1
  261. package/_types/tempo/Transaction.d.ts +2 -0
  262. package/_types/tempo/Transaction.d.ts.map +1 -1
  263. package/_types/tempo/actions/ai.d.ts +145 -0
  264. package/_types/tempo/actions/ai.d.ts.map +1 -0
  265. package/_types/tempo/actions/bucket.d.ts +210 -0
  266. package/_types/tempo/actions/bucket.d.ts.map +1 -0
  267. package/_types/tempo/actions/compute.d.ts +628 -0
  268. package/_types/tempo/actions/compute.d.ts.map +1 -0
  269. package/_types/tempo/actions/gateway.d.ts +25 -0
  270. package/_types/tempo/actions/gateway.d.ts.map +1 -0
  271. package/_types/tempo/actions/index.d.ts +10 -0
  272. package/_types/tempo/actions/index.d.ts.map +1 -1
  273. package/_types/tempo/actions/kv.d.ts +167 -0
  274. package/_types/tempo/actions/kv.d.ts.map +1 -0
  275. package/_types/tempo/chainConfig.d.ts.map +1 -1
  276. package/_types/tempo/index.d.ts +11 -0
  277. package/_types/tempo/index.d.ts.map +1 -1
  278. package/_types/tempo/internal/ndjson.d.ts +9 -0
  279. package/_types/tempo/internal/ndjson.d.ts.map +1 -0
  280. package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
  281. package/_types/tempo/internal/relay/utils.d.ts +8 -8
  282. package/_types/utils/abi/decodeEventLog.d.ts +13 -1
  283. package/_types/utils/abi/decodeEventLog.d.ts.map +1 -1
  284. package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
  285. package/_types/utils/abi/parseEventLogs.d.ts.map +1 -1
  286. package/_types/utils/authorization/recoverAuthorizationAddress.d.ts +2 -1
  287. package/_types/utils/authorization/recoverAuthorizationAddress.d.ts.map +1 -1
  288. package/_types/utils/authorization/verifyAuthorization.d.ts.map +1 -1
  289. package/_types/utils/buildRequest.d.ts.map +1 -1
  290. package/_types/utils/ccip.d.ts +24 -4
  291. package/_types/utils/ccip.d.ts.map +1 -1
  292. package/_types/utils/ccipTunnel.d.ts.map +1 -1
  293. package/_types/utils/ens/localBatchGatewayRequest.d.ts +26 -0
  294. package/_types/utils/ens/localBatchGatewayRequest.d.ts.map +1 -1
  295. package/_types/utils/hash/toSignatureHash.d.ts +1 -1
  296. package/_types/utils/hash/toSignatureHash.d.ts.map +1 -1
  297. package/_types/utils/internal/http.d.ts +16 -0
  298. package/_types/utils/internal/http.d.ts.map +1 -0
  299. package/_types/utils/nonceManager.d.ts +15 -1
  300. package/_types/utils/nonceManager.d.ts.map +1 -1
  301. package/_types/utils/rpc/http.d.ts.map +1 -1
  302. package/_types/utils/rpc/socket.d.ts.map +1 -1
  303. package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
  304. package/_types/utils/typedData.d.ts.map +1 -1
  305. package/account-abstraction/utils/formatters/userOperationReceipt.ts +1 -0
  306. package/actions/public/estimateGas.ts +12 -5
  307. package/actions/public/fillTransaction.ts +2 -0
  308. package/actions/public/getFilterChanges.ts +1 -0
  309. package/actions/public/getFilterLogs.ts +1 -0
  310. package/actions/public/watchBlockNumber.ts +11 -2
  311. package/actions/public/watchBlocks.ts +46 -14
  312. package/actions/public/watchContractEvent.ts +22 -4
  313. package/actions/public/watchEvent.ts +17 -1
  314. package/actions/wallet/prepareTransactionRequest.ts +6 -2
  315. package/actions/wallet/sendTransaction.ts +9 -3
  316. package/actions/wallet/sendTransactionSync.ts +74 -12
  317. package/chains/definitions/hashKeyChain.ts +4 -4
  318. package/chains/definitions/hashkeyChainTestnet.ts +4 -4
  319. package/chains/definitions/turkchain.ts +23 -0
  320. package/chains/definitions/zksync.ts +1 -1
  321. package/chains/index.ts +1 -0
  322. package/clients/createClient.ts +6 -0
  323. package/clients/transports/fallback.ts +11 -0
  324. package/errors/node.ts +11 -5
  325. package/errors/typedData.ts +5 -2
  326. package/errors/version.ts +1 -1
  327. package/index.ts +2 -0
  328. package/package.json +5 -1
  329. package/tempo/Account.ts +202 -16
  330. package/tempo/Gateway.ts +477 -0
  331. package/tempo/GatewayDecorator.ts +909 -0
  332. package/tempo/Relay.ts +1 -1
  333. package/tempo/Transaction.ts +3 -0
  334. package/tempo/actions/ai.ts +250 -0
  335. package/tempo/actions/bucket.ts +324 -0
  336. package/tempo/actions/compute.ts +894 -0
  337. package/tempo/actions/gateway.ts +33 -0
  338. package/tempo/actions/index.ts +10 -0
  339. package/tempo/actions/kv.ts +229 -0
  340. package/tempo/chainConfig.ts +13 -15
  341. package/tempo/index.ts +12 -0
  342. package/tempo/internal/ndjson.ts +51 -0
  343. package/tempo/internal/relay/feePayer.ts +30 -7
  344. package/utils/abi/decodeEventLog.ts +97 -10
  345. package/utils/abi/getAbiItem.ts +35 -5
  346. package/utils/abi/parseEventLogs.ts +48 -11
  347. package/utils/authorization/recoverAuthorizationAddress.ts +18 -2
  348. package/utils/authorization/verifyAuthorization.ts +12 -7
  349. package/utils/buildRequest.ts +4 -0
  350. package/utils/ccip.ts +199 -33
  351. package/utils/ccipTunnel.ts +5 -1
  352. package/utils/ens/localBatchGatewayRequest.ts +82 -4
  353. package/utils/hash/toSignatureHash.ts +12 -2
  354. package/utils/internal/http.ts +92 -0
  355. package/utils/nonceManager.ts +16 -1
  356. package/utils/rpc/http.ts +12 -86
  357. package/utils/rpc/socket.ts +28 -15
  358. package/utils/transaction/assertRequest.ts +2 -2
  359. package/utils/transaction/assertTransaction.ts +2 -2
  360. package/utils/transaction/parseTransaction.ts +32 -7
  361. package/utils/typedData.ts +31 -8
  362. package/zksync/actions/finalizeWithdrawal.ts +5 -2
  363. package/zksync/actions/isWithdrawalFinalized.ts +5 -5
@@ -0,0 +1,477 @@
1
+ import type { Address } from 'abitype'
2
+ import { BaseError } from '../errors/base.js'
3
+ import { formatUnits } from '../utils/unit/formatUnits.js'
4
+
5
+ /**
6
+ * Free discovery document of a Gateway.
7
+ *
8
+ * @experimental
9
+ */
10
+ export type Capabilities = {
11
+ /** Chain the Gateway accepts payments on. */
12
+ chainId: number
13
+ /** Sandboxed compute. */
14
+ compute: {
15
+ /** Whether this Gateway offers compute. */
16
+ available: boolean
17
+ /** Price per CPU core-second in currency units. */
18
+ cpuPerSecond: number
19
+ /** Defaults of `compute.create`. */
20
+ defaults: {
21
+ /** CPU cores. */
22
+ cpu: number
23
+ /** Container image. */
24
+ image: string
25
+ /** Memory in MiB. */
26
+ memory: number
27
+ /** Seconds the sandbox may live. */
28
+ timeout: number
29
+ }
30
+ /** Price per GPU-second in currency units, by GPU type. */
31
+ gpusPerSecond: Record<string, number>
32
+ /** Price per GiB-second of memory in currency units. */
33
+ memoryGiBPerSecond: number
34
+ }
35
+ /** Payment currencies by name. */
36
+ currencies: Record<string, Address>
37
+ /** Request and storage limits. */
38
+ limits: {
39
+ /** Maximum CPU cores per sandbox. */
40
+ cpu: number
41
+ /** Maximum `compute.exec` timeout in seconds. */
42
+ execSeconds: number
43
+ /** Maximum GPUs per sandbox. */
44
+ gpuCount: number
45
+ /** Maximum key size in bytes. */
46
+ keyBytes: number
47
+ /** Maximum page size of `list` actions. */
48
+ listLimit: number
49
+ /** Maximum `maxOutputTokens` of `ai.generateText`. */
50
+ maxOutputTokens: number
51
+ /** Maximum sandbox memory in MiB. */
52
+ memory: number
53
+ /** Maximum object size in bytes. */
54
+ objectBytes: number
55
+ /** Maximum retention or TTL in seconds. */
56
+ retentionSeconds: number
57
+ /** Maximum sandbox lifetime in seconds. */
58
+ sandboxSeconds: number
59
+ /** Maximum `compute.stream` timeout in seconds. */
60
+ streamSeconds: number
61
+ /** Maximum serialized key-value size in bytes. */
62
+ valueBytes: number
63
+ }
64
+ /** Operations priced per token instead of per request. */
65
+ metered: readonly string[]
66
+ /** Supported models by operation. */
67
+ models: {
68
+ /** Embedding models. */
69
+ embed: readonly string[]
70
+ /** Text generation models. */
71
+ generate: readonly string[]
72
+ }
73
+ /**
74
+ * Price of each operation in human-readable currency units. Metered
75
+ * operations list their minimum.
76
+ */
77
+ prices: Record<string, string>
78
+ /** Payment recipient. */
79
+ recipient: Address
80
+ /**
81
+ * Price of metered AI operations per million tokens, by model. A request
82
+ * reserves the most it can cost and the unused part is refunded.
83
+ */
84
+ tokens: Record<string, { input: number; output: number }>
85
+ /** Pricing version. */
86
+ version: string
87
+ }
88
+
89
+ /**
90
+ * Fetch function, such as `globalThis.fetch` or `mppx`'s payment-aware fetch.
91
+ *
92
+ * @experimental
93
+ */
94
+ export type Fetch = (input: string, init: RequestInit) => Promise<Response>
95
+
96
+ /**
97
+ * Connection to a Tempo Gateway: the service URL, the app namespace, and the
98
+ * payment-aware `fetch` that pays for each request.
99
+ *
100
+ * @experimental
101
+ */
102
+ export type Gateway = {
103
+ /** App namespace sent as `Gateway-App`. Data is scoped by chain, payer, and app. */
104
+ app: string
105
+ /** Fetch function used for every request. */
106
+ fetch: Fetch
107
+ /** Gateway origin, without the `/v1` version path. */
108
+ url: string
109
+ }
110
+
111
+ const defaultUrl = 'https://gateway.tempo-dev.workers.dev'
112
+
113
+ /**
114
+ * Creates a {@link Gateway} connection.
115
+ *
116
+ * Viem does not pay for requests: pass a payment-aware `fetch`, such as
117
+ * `mppx`'s client fetch, to pay for each operation. A plain `fetch` reaches
118
+ * only the free routes; paid routes throw {@link PaymentRequiredError}.
119
+ *
120
+ * @experimental
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import { Mppx, tempo } from 'mppx/client'
125
+ * import { privateKeyToAccount } from 'viem/accounts'
126
+ * import { Gateway } from 'viem/tempo'
127
+ *
128
+ * const mppx = Mppx.create({
129
+ * methods: [tempo({ account: privateKeyToAccount('0x...') })],
130
+ * polyfill: false,
131
+ * })
132
+ *
133
+ * const gateway = Gateway.from({ fetch: mppx.fetch })
134
+ * ```
135
+ *
136
+ * @param options - Options.
137
+ * @returns The Gateway connection.
138
+ */
139
+ export function from(options: from.Options = {}): Gateway {
140
+ const { app = 'default', url = defaultUrl } = options
141
+ if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(app)) throw new InvalidAppError({ app })
142
+ return {
143
+ app,
144
+ fetch: options.fetch ?? ((input, init) => globalThis.fetch(input, init)),
145
+ url: trimSlashes(url),
146
+ }
147
+ }
148
+
149
+ function trimSlashes(url: string) {
150
+ let end = url.length
151
+ while (end > 0 && url[end - 1] === '/') end--
152
+ return url.slice(0, end)
153
+ }
154
+
155
+ export declare namespace from {
156
+ type Options = {
157
+ /**
158
+ * App namespace. Must match `[a-z0-9][a-z0-9-]{0,62}`.
159
+ *
160
+ * @default 'default'
161
+ */
162
+ app?: string | undefined
163
+ /**
164
+ * Fetch function used for every request. Pass a payment-aware fetch to pay
165
+ * for operations.
166
+ *
167
+ * @default globalThis.fetch
168
+ */
169
+ fetch?: Fetch | undefined
170
+ /**
171
+ * Gateway origin, without the `/v1` version path.
172
+ *
173
+ * @default 'https://gateway.tempo-dev.workers.dev'
174
+ */
175
+ url?: string | undefined
176
+ }
177
+
178
+ type ErrorType = InvalidAppError
179
+ }
180
+
181
+ /**
182
+ * Reads the free discovery document of a Gateway: chain, currencies, prices,
183
+ * limits, and models.
184
+ *
185
+ * @experimental
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * import { Gateway } from 'viem/tempo'
190
+ *
191
+ * const gateway = Gateway.from()
192
+ * const capabilities = await Gateway.getCapabilities(gateway)
193
+ * ```
194
+ *
195
+ * @param gateway - Gateway connection.
196
+ * @param options - Options.
197
+ * @returns The Gateway capabilities.
198
+ */
199
+ export async function getCapabilities(
200
+ gateway: Gateway,
201
+ options: getCapabilities.Options = {},
202
+ ): Promise<Capabilities> {
203
+ const response = await request(gateway, {
204
+ method: 'GET',
205
+ path: '/capabilities',
206
+ signal: options.signal,
207
+ })
208
+ return (await response.json()) as Capabilities
209
+ }
210
+
211
+ export declare namespace getCapabilities {
212
+ type Options = {
213
+ /** Signal to abort the request. */
214
+ signal?: AbortSignal | undefined
215
+ }
216
+
217
+ type ErrorType = request.ErrorType
218
+ }
219
+
220
+ /**
221
+ * Sends a request to a Gateway route under `/v1` and returns the successful
222
+ * response. Problem responses throw a {@link RequestError}.
223
+ *
224
+ * Prefer the typed `ai`, `bucket`, `compute`, and `kv` actions.
225
+ *
226
+ * @experimental
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * import { Gateway } from 'viem/tempo'
231
+ *
232
+ * const gateway = Gateway.from()
233
+ * const response = await Gateway.request(gateway, {
234
+ * body: JSON.stringify({ key: 'greeting' }),
235
+ * path: '/kv/get',
236
+ * })
237
+ * ```
238
+ *
239
+ * @param gateway - Gateway connection.
240
+ * @param options - Options.
241
+ * @returns The successful response.
242
+ */
243
+ export async function request(
244
+ gateway: Gateway,
245
+ options: request.Options,
246
+ ): Promise<Response> {
247
+ const { body, method = 'POST', path, signal } = options
248
+ const url = `${gateway.url}/v1${path}`
249
+ const headers = new Headers(options.headers)
250
+ if (!headers.has('gateway-app')) headers.set('gateway-app', gateway.app)
251
+ if (typeof body === 'string' && !headers.has('content-type'))
252
+ headers.set('content-type', 'application/json')
253
+ const response = await gateway.fetch(url, {
254
+ method,
255
+ headers,
256
+ ...(body !== undefined ? { body } : {}),
257
+ ...(signal ? { signal } : {}),
258
+ })
259
+ if (response.ok) return response
260
+
261
+ const text = await response.text().catch(() => '')
262
+ const problem = (() => {
263
+ try {
264
+ return JSON.parse(text) as { code?: unknown; detail?: unknown }
265
+ } catch {
266
+ return {}
267
+ }
268
+ })()
269
+ const parameters = {
270
+ code: (() => {
271
+ if (typeof problem.code === 'string') return problem.code
272
+ if (response.status === 402) return 'payment_required'
273
+ return 'unknown'
274
+ })(),
275
+ detail: typeof problem.detail === 'string' ? problem.detail : text,
276
+ status: response.status,
277
+ url,
278
+ }
279
+ if (response.status === 402) throw new PaymentRequiredError(parameters)
280
+ if (parameters.code === 'version_conflict')
281
+ throw new VersionConflictError(parameters)
282
+ throw new RequestError(parameters)
283
+ }
284
+
285
+ export declare namespace request {
286
+ type Options = {
287
+ /** Request body. */
288
+ body?: BodyInit | undefined
289
+ /** Extra request headers. */
290
+ headers?: Record<string, string> | undefined
291
+ /**
292
+ * HTTP method.
293
+ *
294
+ * @default 'POST'
295
+ */
296
+ method?: 'GET' | 'POST' | undefined
297
+ /** Route under `/v1`, such as `/kv/get`. */
298
+ path: string
299
+ /** Signal to abort the request. */
300
+ signal?: AbortSignal | undefined
301
+ }
302
+
303
+ type ErrorType = PaymentRequiredError | RequestError | VersionConflictError
304
+ }
305
+
306
+ /**
307
+ * Thrown when an app namespace does not match `[a-z0-9][a-z0-9-]{0,62}`.
308
+ *
309
+ * @experimental
310
+ */
311
+ export class InvalidAppError extends BaseError {
312
+ constructor({ app }: { app: string }) {
313
+ super(`App "${app}" is not a valid Gateway app namespace.`, {
314
+ metaMessages: ['Use 1 to 63 lowercase letters, digits, or hyphens.'],
315
+ name: 'Gateway.InvalidAppError',
316
+ })
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Thrown when a Gateway responds with a problem.
322
+ *
323
+ * @experimental
324
+ */
325
+ export class RequestError extends BaseError {
326
+ /** Stable problem code, such as `not_found` or `invalid_request`. */
327
+ code: string
328
+ /** Problem detail. */
329
+ detail: string
330
+ /** HTTP status. */
331
+ status: number
332
+ /** Request URL. */
333
+ url: string
334
+
335
+ constructor(
336
+ parameters: RequestError.Parameters,
337
+ options: RequestError.Options = {},
338
+ ) {
339
+ const { code, detail, status, url } = parameters
340
+ super(options.shortMessage ?? 'Gateway request failed.', {
341
+ details: detail,
342
+ metaMessages: [`Code: ${code}`, `Status: ${status}`, `URL: ${url}`],
343
+ name: options.name ?? 'Gateway.RequestError',
344
+ })
345
+ this.code = code
346
+ this.detail = detail
347
+ this.status = status
348
+ this.url = url
349
+ }
350
+ }
351
+
352
+ export declare namespace RequestError {
353
+ type Parameters = {
354
+ /** Stable problem code. */
355
+ code: string
356
+ /** Problem detail. */
357
+ detail: string
358
+ /** HTTP status. */
359
+ status: number
360
+ /** Request URL. */
361
+ url: string
362
+ }
363
+
364
+ type Options = {
365
+ /** Error name. */
366
+ name?: string | undefined
367
+ /** Short message. */
368
+ shortMessage?: string | undefined
369
+ }
370
+ }
371
+
372
+ /**
373
+ * Thrown when a Gateway asks for payment that the supplied `fetch` did not
374
+ * provide. Pass a payment-aware `fetch` to {@link from}.
375
+ *
376
+ * @experimental
377
+ */
378
+ export class PaymentRequiredError extends RequestError {
379
+ constructor(parameters: RequestError.Parameters) {
380
+ super(parameters, {
381
+ name: 'Gateway.PaymentRequiredError',
382
+ shortMessage:
383
+ 'Gateway requires payment. Give the Client an account (with mppx installed), or pass a payment-aware fetch to gatewayActions.',
384
+ })
385
+ }
386
+ }
387
+
388
+ /**
389
+ * Thrown when the Client's account holds too little of the Gateway's
390
+ * currencies to pay for a request.
391
+ *
392
+ * @experimental
393
+ */
394
+ export class InsufficientFundsError extends BaseError {
395
+ /** The paying account. */
396
+ address: Address
397
+ /** The account's balance of each Gateway currency, in base units. */
398
+ balances: InsufficientFundsError.Parameters['balances']
399
+
400
+ constructor({ address, balances, cause }: InsufficientFundsError.Parameters) {
401
+ const held = balances
402
+ .map(({ amount, symbol }) => `${formatUnits(amount, 6)} ${symbol}`)
403
+ .join(' and ')
404
+ super(
405
+ `The account ${address} can't pay the Gateway${held ? `: it holds ${held}` : ''}.`,
406
+ {
407
+ ...(cause ? { cause } : {}),
408
+ metaMessages: [
409
+ 'Fund it with OUSD (send it from any wallet), or with MACH through Tempo Wallet (wallet.deposit). MACH cannot be transferred to a new address.',
410
+ ],
411
+ name: 'Gateway.InsufficientFundsError',
412
+ },
413
+ )
414
+ this.address = address
415
+ this.balances = balances
416
+ }
417
+ }
418
+
419
+ export declare namespace InsufficientFundsError {
420
+ type Parameters = {
421
+ address: Address
422
+ balances: readonly { amount: bigint; currency: Address; symbol: string }[]
423
+ cause?: Error | undefined
424
+ }
425
+ }
426
+
427
+ /**
428
+ * Thrown when the Gateway asks for payment on a different chain than the
429
+ * Client's.
430
+ *
431
+ * @experimental
432
+ */
433
+ export class ChainMismatchError extends BaseError {
434
+ constructor({ chainId, expected }: { chainId: number; expected: number }) {
435
+ super(
436
+ `The Gateway asks for payment on chain ${chainId}, but the Client is on chain ${expected}.`,
437
+ {
438
+ metaMessages: [
439
+ 'Create the Client on the chain the Gateway is paid on (see getCapabilities().chainId).',
440
+ ],
441
+ name: 'Gateway.ChainMismatchError',
442
+ },
443
+ )
444
+ }
445
+ }
446
+
447
+ /**
448
+ * Thrown when a Client with an account pays the Gateway but `mppx` is not
449
+ * installed.
450
+ *
451
+ * @experimental
452
+ */
453
+ export class MppxNotInstalledError extends BaseError {
454
+ constructor({ cause }: { cause?: Error | undefined } = {}) {
455
+ super('mppx is required to pay the Gateway with the Client account.', {
456
+ cause,
457
+ metaMessages: [
458
+ 'Install it (npm i mppx), or pass a payment-aware fetch to gatewayActions.',
459
+ ],
460
+ name: 'Gateway.MppxNotInstalledError',
461
+ })
462
+ }
463
+ }
464
+
465
+ /**
466
+ * Thrown when `kv.set` with `ifVersion` does not match the stored version.
467
+ *
468
+ * @experimental
469
+ */
470
+ export class VersionConflictError extends RequestError {
471
+ constructor(parameters: RequestError.Parameters) {
472
+ super(parameters, {
473
+ name: 'Gateway.VersionConflictError',
474
+ shortMessage: 'Stored version does not match ifVersion.',
475
+ })
476
+ }
477
+ }