viem 2.46.2 → 2.47.0

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 (308) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/_cjs/actions/index.js +5 -3
  3. package/_cjs/actions/index.js.map +1 -1
  4. package/_cjs/actions/public/getDelegation.js +21 -0
  5. package/_cjs/actions/public/getDelegation.js.map +1 -0
  6. package/_cjs/actions/public/simulateCalls.js +1 -1
  7. package/_cjs/actions/public/simulateCalls.js.map +1 -1
  8. package/_cjs/actions/wallet/prepareTransactionRequest.js +12 -4
  9. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  10. package/_cjs/actions/wallet/sendRawTransactionSync.js +1 -2
  11. package/_cjs/actions/wallet/sendRawTransactionSync.js.map +1 -1
  12. package/_cjs/chains/definitions/krown.js +26 -0
  13. package/_cjs/chains/definitions/krown.js.map +1 -0
  14. package/_cjs/chains/definitions/polygon.js +1 -1
  15. package/_cjs/chains/definitions/polygon.js.map +1 -1
  16. package/_cjs/chains/definitions/saigon.js +3 -3
  17. package/_cjs/chains/definitions/saigon.js.map +1 -1
  18. package/_cjs/chains/definitions/sei.js +3 -3
  19. package/_cjs/chains/definitions/sei.js.map +1 -1
  20. package/_cjs/chains/definitions/seiTestnet.js +3 -2
  21. package/_cjs/chains/definitions/seiTestnet.js.map +1 -1
  22. package/_cjs/chains/index.js +7 -7
  23. package/_cjs/chains/index.js.map +1 -1
  24. package/_cjs/clients/decorators/public.js +2 -0
  25. package/_cjs/clients/decorators/public.js.map +1 -1
  26. package/_cjs/errors/version.js +1 -1
  27. package/_cjs/index.js.map +1 -1
  28. package/_cjs/tempo/Account.js +28 -15
  29. package/_cjs/tempo/Account.js.map +1 -1
  30. package/_cjs/tempo/Addresses.js +2 -1
  31. package/_cjs/tempo/Addresses.js.map +1 -1
  32. package/_cjs/tempo/Decorator.js +11 -0
  33. package/_cjs/tempo/Decorator.js.map +1 -1
  34. package/_cjs/tempo/actions/accessKey.js +251 -0
  35. package/_cjs/tempo/actions/accessKey.js.map +1 -0
  36. package/_cjs/tempo/actions/index.js +2 -1
  37. package/_cjs/tempo/actions/index.js.map +1 -1
  38. package/_cjs/tempo/index.js +2 -1
  39. package/_cjs/tempo/index.js.map +1 -1
  40. package/_cjs/utils/abi/parseEventLogs.js +8 -6
  41. package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
  42. package/_esm/actions/index.js +1 -0
  43. package/_esm/actions/index.js.map +1 -1
  44. package/_esm/actions/public/getDelegation.js +43 -0
  45. package/_esm/actions/public/getDelegation.js.map +1 -0
  46. package/_esm/actions/public/simulateCalls.js +1 -1
  47. package/_esm/actions/public/simulateCalls.js.map +1 -1
  48. package/_esm/actions/wallet/prepareTransactionRequest.js +12 -4
  49. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  50. package/_esm/actions/wallet/sendRawTransactionSync.js +1 -2
  51. package/_esm/actions/wallet/sendRawTransactionSync.js.map +1 -1
  52. package/_esm/chains/definitions/krown.js +23 -0
  53. package/_esm/chains/definitions/krown.js.map +1 -0
  54. package/_esm/chains/definitions/polygon.js +1 -1
  55. package/_esm/chains/definitions/polygon.js.map +1 -1
  56. package/_esm/chains/definitions/saigon.js +3 -3
  57. package/_esm/chains/definitions/saigon.js.map +1 -1
  58. package/_esm/chains/definitions/sei.js +3 -3
  59. package/_esm/chains/definitions/sei.js.map +1 -1
  60. package/_esm/chains/definitions/seiTestnet.js +3 -2
  61. package/_esm/chains/definitions/seiTestnet.js.map +1 -1
  62. package/_esm/chains/index.js +1 -1
  63. package/_esm/chains/index.js.map +1 -1
  64. package/_esm/clients/decorators/public.js +2 -0
  65. package/_esm/clients/decorators/public.js.map +1 -1
  66. package/_esm/errors/version.js +1 -1
  67. package/_esm/index.js.map +1 -1
  68. package/_esm/tempo/Account.js +28 -16
  69. package/_esm/tempo/Account.js.map +1 -1
  70. package/_esm/tempo/Addresses.js +1 -0
  71. package/_esm/tempo/Addresses.js.map +1 -1
  72. package/_esm/tempo/Decorator.js +11 -0
  73. package/_esm/tempo/Decorator.js.map +1 -1
  74. package/_esm/tempo/actions/accessKey.js +562 -0
  75. package/_esm/tempo/actions/accessKey.js.map +1 -0
  76. package/_esm/tempo/actions/index.js +1 -0
  77. package/_esm/tempo/actions/index.js.map +1 -1
  78. package/_esm/tempo/index.js +1 -1
  79. package/_esm/tempo/index.js.map +1 -1
  80. package/_esm/utils/abi/parseEventLogs.js +11 -6
  81. package/_esm/utils/abi/parseEventLogs.js.map +1 -1
  82. package/_types/actions/index.d.ts +1 -0
  83. package/_types/actions/index.d.ts.map +1 -1
  84. package/_types/actions/public/getDelegation.d.ts +46 -0
  85. package/_types/actions/public/getDelegation.d.ts.map +1 -0
  86. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  87. package/_types/actions/wallet/sendRawTransactionSync.d.ts +1 -1
  88. package/_types/actions/wallet/sendRawTransactionSync.d.ts.map +1 -1
  89. package/_types/chains/definitions/abstract.d.ts +1 -0
  90. package/_types/chains/definitions/abstract.d.ts.map +1 -1
  91. package/_types/chains/definitions/abstractTestnet.d.ts +1 -0
  92. package/_types/chains/definitions/abstractTestnet.d.ts.map +1 -1
  93. package/_types/chains/definitions/ancient8.d.ts +1 -0
  94. package/_types/chains/definitions/ancient8.d.ts.map +1 -1
  95. package/_types/chains/definitions/ancient8Sepolia.d.ts +1 -0
  96. package/_types/chains/definitions/ancient8Sepolia.d.ts.map +1 -1
  97. package/_types/chains/definitions/base.d.ts +2 -0
  98. package/_types/chains/definitions/base.d.ts.map +1 -1
  99. package/_types/chains/definitions/baseGoerli.d.ts +1 -0
  100. package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
  101. package/_types/chains/definitions/baseSepolia.d.ts +2 -0
  102. package/_types/chains/definitions/baseSepolia.d.ts.map +1 -1
  103. package/_types/chains/definitions/blast.d.ts +1 -0
  104. package/_types/chains/definitions/blast.d.ts.map +1 -1
  105. package/_types/chains/definitions/bob.d.ts +1 -0
  106. package/_types/chains/definitions/bob.d.ts.map +1 -1
  107. package/_types/chains/definitions/bobSepolia.d.ts +1 -0
  108. package/_types/chains/definitions/bobSepolia.d.ts.map +1 -1
  109. package/_types/chains/definitions/codex.d.ts +1 -0
  110. package/_types/chains/definitions/codex.d.ts.map +1 -1
  111. package/_types/chains/definitions/codexTestnet.d.ts +1 -0
  112. package/_types/chains/definitions/codexTestnet.d.ts.map +1 -1
  113. package/_types/chains/definitions/dchain.d.ts +1 -0
  114. package/_types/chains/definitions/dchain.d.ts.map +1 -1
  115. package/_types/chains/definitions/dchainTestnet.d.ts +1 -0
  116. package/_types/chains/definitions/dchainTestnet.d.ts.map +1 -1
  117. package/_types/chains/definitions/elysiumTestnet.d.ts +1 -0
  118. package/_types/chains/definitions/elysiumTestnet.d.ts.map +1 -1
  119. package/_types/chains/definitions/fraxtal.d.ts +1 -0
  120. package/_types/chains/definitions/fraxtal.d.ts.map +1 -1
  121. package/_types/chains/definitions/fraxtalTestnet.d.ts +1 -0
  122. package/_types/chains/definitions/fraxtalTestnet.d.ts.map +1 -1
  123. package/_types/chains/definitions/funkiMainnet.d.ts +1 -0
  124. package/_types/chains/definitions/funkiMainnet.d.ts.map +1 -1
  125. package/_types/chains/definitions/funkiSepolia.d.ts +1 -0
  126. package/_types/chains/definitions/funkiSepolia.d.ts.map +1 -1
  127. package/_types/chains/definitions/garnet.d.ts +1 -0
  128. package/_types/chains/definitions/garnet.d.ts.map +1 -1
  129. package/_types/chains/definitions/giwaSepolia.d.ts +2 -0
  130. package/_types/chains/definitions/giwaSepolia.d.ts.map +1 -1
  131. package/_types/chains/definitions/ink.d.ts +1 -0
  132. package/_types/chains/definitions/ink.d.ts.map +1 -1
  133. package/_types/chains/definitions/inkSepolia.d.ts +1 -0
  134. package/_types/chains/definitions/inkSepolia.d.ts.map +1 -1
  135. package/_types/chains/definitions/{seiDevnet.d.ts → krown.d.ts} +10 -10
  136. package/_types/chains/definitions/krown.d.ts.map +1 -0
  137. package/_types/chains/definitions/lisk.d.ts +1 -0
  138. package/_types/chains/definitions/lisk.d.ts.map +1 -1
  139. package/_types/chains/definitions/liskSepolia.d.ts +1 -0
  140. package/_types/chains/definitions/liskSepolia.d.ts.map +1 -1
  141. package/_types/chains/definitions/metalL2.d.ts +1 -0
  142. package/_types/chains/definitions/metalL2.d.ts.map +1 -1
  143. package/_types/chains/definitions/mode.d.ts +1 -0
  144. package/_types/chains/definitions/mode.d.ts.map +1 -1
  145. package/_types/chains/definitions/modeTestnet.d.ts +1 -0
  146. package/_types/chains/definitions/modeTestnet.d.ts.map +1 -1
  147. package/_types/chains/definitions/optimism.d.ts +1 -0
  148. package/_types/chains/definitions/optimism.d.ts.map +1 -1
  149. package/_types/chains/definitions/optimismGoerli.d.ts +1 -0
  150. package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
  151. package/_types/chains/definitions/optimismSepolia.d.ts +1 -0
  152. package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
  153. package/_types/chains/definitions/pgn.d.ts +1 -0
  154. package/_types/chains/definitions/pgn.d.ts.map +1 -1
  155. package/_types/chains/definitions/pgnTestnet.d.ts +1 -0
  156. package/_types/chains/definitions/pgnTestnet.d.ts.map +1 -1
  157. package/_types/chains/definitions/playfiAlbireo.d.ts +1 -0
  158. package/_types/chains/definitions/playfiAlbireo.d.ts.map +1 -1
  159. package/_types/chains/definitions/polygon.d.ts +1 -1
  160. package/_types/chains/definitions/pyrope.d.ts +1 -0
  161. package/_types/chains/definitions/pyrope.d.ts.map +1 -1
  162. package/_types/chains/definitions/redstone.d.ts +1 -0
  163. package/_types/chains/definitions/redstone.d.ts.map +1 -1
  164. package/_types/chains/definitions/rss3.d.ts +1 -0
  165. package/_types/chains/definitions/rss3.d.ts.map +1 -1
  166. package/_types/chains/definitions/rss3Sepolia.d.ts +1 -0
  167. package/_types/chains/definitions/rss3Sepolia.d.ts.map +1 -1
  168. package/_types/chains/definitions/saigon.d.ts +3 -3
  169. package/_types/chains/definitions/sei.d.ts +3 -3
  170. package/_types/chains/definitions/seiTestnet.d.ts +3 -2
  171. package/_types/chains/definitions/seiTestnet.d.ts.map +1 -1
  172. package/_types/chains/definitions/shape.d.ts +1 -0
  173. package/_types/chains/definitions/shape.d.ts.map +1 -1
  174. package/_types/chains/definitions/shapeSepolia.d.ts +1 -0
  175. package/_types/chains/definitions/shapeSepolia.d.ts.map +1 -1
  176. package/_types/chains/definitions/snax.d.ts +1 -0
  177. package/_types/chains/definitions/snax.d.ts.map +1 -1
  178. package/_types/chains/definitions/snaxTestnet.d.ts +1 -0
  179. package/_types/chains/definitions/snaxTestnet.d.ts.map +1 -1
  180. package/_types/chains/definitions/soneium.d.ts +1 -0
  181. package/_types/chains/definitions/soneium.d.ts.map +1 -1
  182. package/_types/chains/definitions/soneiumMinato.d.ts +1 -0
  183. package/_types/chains/definitions/soneiumMinato.d.ts.map +1 -1
  184. package/_types/chains/definitions/sophon.d.ts +1 -0
  185. package/_types/chains/definitions/sophon.d.ts.map +1 -1
  186. package/_types/chains/definitions/sophonTestnet.d.ts +1 -0
  187. package/_types/chains/definitions/sophonTestnet.d.ts.map +1 -1
  188. package/_types/chains/definitions/superseed.d.ts +1 -0
  189. package/_types/chains/definitions/superseed.d.ts.map +1 -1
  190. package/_types/chains/definitions/superseedSepolia.d.ts +1 -0
  191. package/_types/chains/definitions/superseedSepolia.d.ts.map +1 -1
  192. package/_types/chains/definitions/swellchain.d.ts +1 -0
  193. package/_types/chains/definitions/swellchain.d.ts.map +1 -1
  194. package/_types/chains/definitions/swellchainTestnet.d.ts +1 -0
  195. package/_types/chains/definitions/swellchainTestnet.d.ts.map +1 -1
  196. package/_types/chains/definitions/tempo.d.ts +2 -0
  197. package/_types/chains/definitions/tempo.d.ts.map +1 -1
  198. package/_types/chains/definitions/tempoAndantino.d.ts +2 -0
  199. package/_types/chains/definitions/tempoAndantino.d.ts.map +1 -1
  200. package/_types/chains/definitions/tempoDevnet.d.ts +2 -0
  201. package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
  202. package/_types/chains/definitions/tempoLocalnet.d.ts +2 -0
  203. package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
  204. package/_types/chains/definitions/tempoModerato.d.ts +2 -0
  205. package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
  206. package/_types/chains/definitions/treasure.d.ts +1 -0
  207. package/_types/chains/definitions/treasure.d.ts.map +1 -1
  208. package/_types/chains/definitions/treasureTopaz.d.ts +1 -0
  209. package/_types/chains/definitions/treasureTopaz.d.ts.map +1 -1
  210. package/_types/chains/definitions/unichain.d.ts +1 -0
  211. package/_types/chains/definitions/unichain.d.ts.map +1 -1
  212. package/_types/chains/definitions/unichainSepolia.d.ts +1 -0
  213. package/_types/chains/definitions/unichainSepolia.d.ts.map +1 -1
  214. package/_types/chains/definitions/worldchain.d.ts +1 -0
  215. package/_types/chains/definitions/worldchain.d.ts.map +1 -1
  216. package/_types/chains/definitions/worldchainSepolia.d.ts +1 -0
  217. package/_types/chains/definitions/worldchainSepolia.d.ts.map +1 -1
  218. package/_types/chains/definitions/zircuit.d.ts +1 -0
  219. package/_types/chains/definitions/zircuit.d.ts.map +1 -1
  220. package/_types/chains/definitions/zircuitGarfieldTestnet.d.ts +1 -0
  221. package/_types/chains/definitions/zircuitGarfieldTestnet.d.ts.map +1 -1
  222. package/_types/chains/definitions/zircuitTestnet.d.ts +1 -0
  223. package/_types/chains/definitions/zircuitTestnet.d.ts.map +1 -1
  224. package/_types/chains/definitions/zksync.d.ts +1 -0
  225. package/_types/chains/definitions/zksync.d.ts.map +1 -1
  226. package/_types/chains/definitions/zksyncInMemoryNode.d.ts +1 -0
  227. package/_types/chains/definitions/zksyncInMemoryNode.d.ts.map +1 -1
  228. package/_types/chains/definitions/zksyncLocalCustomHyperchain.d.ts +1 -0
  229. package/_types/chains/definitions/zksyncLocalCustomHyperchain.d.ts.map +1 -1
  230. package/_types/chains/definitions/zksyncLocalHyperchain.d.ts +1 -0
  231. package/_types/chains/definitions/zksyncLocalHyperchain.d.ts.map +1 -1
  232. package/_types/chains/definitions/zksyncLocalNode.d.ts +1 -0
  233. package/_types/chains/definitions/zksyncLocalNode.d.ts.map +1 -1
  234. package/_types/chains/definitions/zksyncSepoliaTestnet.d.ts +1 -0
  235. package/_types/chains/definitions/zksyncSepoliaTestnet.d.ts.map +1 -1
  236. package/_types/chains/definitions/zora.d.ts +1 -0
  237. package/_types/chains/definitions/zora.d.ts.map +1 -1
  238. package/_types/chains/definitions/zoraSepolia.d.ts +1 -0
  239. package/_types/chains/definitions/zoraSepolia.d.ts.map +1 -1
  240. package/_types/chains/definitions/zoraTestnet.d.ts +1 -0
  241. package/_types/chains/definitions/zoraTestnet.d.ts.map +1 -1
  242. package/_types/chains/index.d.ts +1 -1
  243. package/_types/chains/index.d.ts.map +1 -1
  244. package/_types/clients/decorators/public.d.ts +22 -0
  245. package/_types/clients/decorators/public.d.ts.map +1 -1
  246. package/_types/errors/version.d.ts +1 -1
  247. package/_types/index.d.ts +1 -0
  248. package/_types/index.d.ts.map +1 -1
  249. package/_types/op-stack/chainConfig.d.ts +1 -0
  250. package/_types/op-stack/chainConfig.d.ts.map +1 -1
  251. package/_types/op-stack/formatters.d.ts +1 -0
  252. package/_types/op-stack/formatters.d.ts.map +1 -1
  253. package/_types/tempo/Account.d.ts +20 -17
  254. package/_types/tempo/Account.d.ts.map +1 -1
  255. package/_types/tempo/Addresses.d.ts +1 -0
  256. package/_types/tempo/Addresses.d.ts.map +1 -1
  257. package/_types/tempo/Decorator.d.ts +340 -122
  258. package/_types/tempo/Decorator.d.ts.map +1 -1
  259. package/_types/tempo/WebAuthnP256.d.ts +2 -2
  260. package/_types/tempo/WebAuthnP256.d.ts.map +1 -1
  261. package/_types/tempo/actions/accessKey.d.ts +1174 -0
  262. package/_types/tempo/actions/accessKey.d.ts.map +1 -0
  263. package/_types/tempo/actions/index.d.ts +1 -0
  264. package/_types/tempo/actions/index.d.ts.map +1 -1
  265. package/_types/tempo/chainConfig.d.ts +1 -0
  266. package/_types/tempo/chainConfig.d.ts.map +1 -1
  267. package/_types/tempo/index.d.ts +1 -1
  268. package/_types/tempo/index.d.ts.map +1 -1
  269. package/_types/types/eip1193.d.ts +2 -2
  270. package/_types/types/eip1193.d.ts.map +1 -1
  271. package/_types/types/transaction.d.ts +2 -0
  272. package/_types/types/transaction.d.ts.map +1 -1
  273. package/_types/utils/abi/parseEventLogs.d.ts.map +1 -1
  274. package/_types/zksync/chainConfig.d.ts +1 -0
  275. package/_types/zksync/chainConfig.d.ts.map +1 -1
  276. package/_types/zksync/formatters.d.ts +1 -0
  277. package/_types/zksync/formatters.d.ts.map +1 -1
  278. package/actions/index.ts +6 -0
  279. package/actions/public/getDelegation.ts +80 -0
  280. package/actions/public/simulateCalls.ts +1 -1
  281. package/actions/wallet/prepareTransactionRequest.ts +12 -4
  282. package/actions/wallet/sendRawTransactionSync.ts +2 -5
  283. package/chains/definitions/krown.ts +23 -0
  284. package/chains/definitions/polygon.ts +1 -1
  285. package/chains/definitions/saigon.ts +3 -3
  286. package/chains/definitions/sei.ts +3 -3
  287. package/chains/definitions/seiTestnet.ts +3 -2
  288. package/chains/index.ts +1 -1
  289. package/clients/decorators/public.ts +29 -0
  290. package/errors/version.ts +1 -1
  291. package/index.ts +5 -0
  292. package/package.json +2 -2
  293. package/tempo/Account.ts +58 -39
  294. package/tempo/Addresses.ts +1 -0
  295. package/tempo/Decorator.ts +373 -122
  296. package/tempo/WebAuthnP256.ts +5 -2
  297. package/tempo/actions/accessKey.ts +857 -0
  298. package/tempo/actions/index.ts +1 -0
  299. package/tempo/index.ts +1 -1
  300. package/types/eip1193.ts +2 -2
  301. package/types/transaction.ts +2 -0
  302. package/utils/abi/parseEventLogs.ts +13 -6
  303. package/_cjs/chains/definitions/seiDevnet.js +0 -22
  304. package/_cjs/chains/definitions/seiDevnet.js.map +0 -1
  305. package/_esm/chains/definitions/seiDevnet.js +0 -19
  306. package/_esm/chains/definitions/seiDevnet.js.map +0 -1
  307. package/_types/chains/definitions/seiDevnet.d.ts.map +0 -1
  308. package/chains/definitions/seiDevnet.ts +0 -19
@@ -0,0 +1,857 @@
1
+ import type { Address } from 'abitype'
2
+ import type { Account } from '../../accounts/types.js'
3
+ import { parseAccount } from '../../accounts/utils/parseAccount.js'
4
+ import type { ReadContractReturnType } from '../../actions/public/readContract.js'
5
+ import { readContract } from '../../actions/public/readContract.js'
6
+ import { sendTransaction } from '../../actions/wallet/sendTransaction.js'
7
+ import { sendTransactionSync } from '../../actions/wallet/sendTransactionSync.js'
8
+ import type { WriteContractReturnType } from '../../actions/wallet/writeContract.js'
9
+ import { writeContract } from '../../actions/wallet/writeContract.js'
10
+ import { writeContractSync } from '../../actions/wallet/writeContractSync.js'
11
+ import type { Client } from '../../clients/createClient.js'
12
+ import type { Transport } from '../../clients/transports/createTransport.js'
13
+ import type { BaseErrorType } from '../../errors/base.js'
14
+ import type { Chain } from '../../types/chain.js'
15
+ import type { GetEventArgs } from '../../types/contract.js'
16
+ import type { Log } from '../../types/log.js'
17
+ import type { Compute } from '../../types/utils.js'
18
+ import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
19
+ import * as Abis from '../Abis.js'
20
+ import type { AccessKeyAccount } from '../Account.js'
21
+ import { signKeyAuthorization } from '../Account.js'
22
+ import * as Addresses from '../Addresses.js'
23
+ import type {
24
+ GetAccountParameter,
25
+ ReadParameters,
26
+ WriteParameters,
27
+ } from '../internal/types.js'
28
+ import { defineCall } from '../internal/utils.js'
29
+ import type { TransactionReceipt } from '../Transaction.js'
30
+
31
+ /** @internal */
32
+ const signatureTypes = {
33
+ 0: 'secp256k1',
34
+ 1: 'p256',
35
+ 2: 'webAuthn',
36
+ } as const satisfies Record<number, string>
37
+
38
+ /** @internal */
39
+ const spendPolicies = {
40
+ true: 'limited',
41
+ false: 'unlimited',
42
+ } as const
43
+
44
+ /**
45
+ * Authorizes an access key by signing a key authorization and sending a transaction.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { createClient, http } from 'viem'
50
+ * import { tempo } from 'viem/chains'
51
+ * import { Actions, Account } from 'viem/tempo'
52
+ * import { generatePrivateKey } from 'viem/accounts'
53
+ *
54
+ * const account = Account.from({ privateKey: '0x...' })
55
+ * const client = createClient({
56
+ * account,
57
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
58
+ * transport: http(),
59
+ * })
60
+ *
61
+ * const accessKey = Account.fromP256(generatePrivateKey(), {
62
+ * access: account,
63
+ * })
64
+ *
65
+ * const hash = await Actions.accessKey.authorize(client, {
66
+ * accessKey,
67
+ * expiry: Math.floor((Date.now() + 30_000) / 1000),
68
+ * })
69
+ * ```
70
+ *
71
+ * @param client - Client.
72
+ * @param parameters - Parameters.
73
+ * @returns The transaction hash.
74
+ */
75
+ export async function authorize<
76
+ chain extends Chain | undefined,
77
+ account extends Account | undefined,
78
+ >(
79
+ client: Client<Transport, chain, account>,
80
+ parameters: authorize.Parameters<chain, account>,
81
+ ): Promise<authorize.ReturnValue> {
82
+ return authorize.inner(sendTransaction, client, parameters)
83
+ }
84
+
85
+ export namespace authorize {
86
+ export type Parameters<
87
+ chain extends Chain | undefined = Chain | undefined,
88
+ account extends Account | undefined = Account | undefined,
89
+ > = WriteParameters<chain, account> & Args
90
+
91
+ export type Args = {
92
+ /** The access key to authorize. */
93
+ accessKey: Pick<AccessKeyAccount, 'accessKeyAddress' | 'keyType'>
94
+ /** The chain ID. */
95
+ chainId?: number | undefined
96
+ /** Unix timestamp when the key expires. */
97
+ expiry?: number | undefined
98
+ /** Spending limits per token. */
99
+ limits?: { token: Address; limit: bigint }[] | undefined
100
+ }
101
+
102
+ export type ReturnValue = WriteContractReturnType
103
+
104
+ // TODO: exhaustive error type
105
+ export type ErrorType = BaseErrorType
106
+
107
+ /** @internal */
108
+ export async function inner<
109
+ action extends typeof sendTransaction | typeof sendTransactionSync,
110
+ chain extends Chain | undefined,
111
+ account extends Account | undefined,
112
+ >(
113
+ action: action,
114
+ client: Client<Transport, chain, account>,
115
+ parameters: authorize.Parameters<chain, account>,
116
+ ): Promise<ReturnType<action>> {
117
+ const {
118
+ accessKey,
119
+ chainId = client.chain?.id,
120
+ expiry,
121
+ limits,
122
+ ...rest
123
+ } = parameters
124
+ const account_ = rest.account ?? client.account
125
+ if (!account_) throw new Error('account is required.')
126
+ if (!chainId) throw new Error('chainId is required.')
127
+ const parsed = parseAccount(account_)
128
+ const keyAuthorization = await signKeyAuthorization(parsed as never, {
129
+ chainId: BigInt(chainId),
130
+ key: accessKey,
131
+ expiry,
132
+ limits,
133
+ })
134
+ return (await action(client, {
135
+ ...rest,
136
+ keyAuthorization,
137
+ } as never)) as never
138
+ }
139
+
140
+ export function extractEvent(logs: Log[]) {
141
+ const [log] = parseEventLogs({
142
+ abi: Abis.accountKeychain,
143
+ logs,
144
+ eventName: 'KeyAuthorized',
145
+ strict: true,
146
+ })
147
+ if (!log) throw new Error('`KeyAuthorized` event not found.')
148
+ return log
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Authorizes an access key and waits for the transaction receipt.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * import { createClient, http } from 'viem'
158
+ * import { tempo } from 'viem/chains'
159
+ * import { Actions, Account } from 'viem/tempo'
160
+ * import { generatePrivateKey } from 'viem/accounts'
161
+ *
162
+ * const account = Account.from({ privateKey: '0x...' })
163
+ * const client = createClient({
164
+ * account,
165
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
166
+ * transport: http(),
167
+ * })
168
+ *
169
+ * const accessKey = Account.fromP256(generatePrivateKey(), {
170
+ * access: account,
171
+ * })
172
+ *
173
+ * const { receipt, ...result } = await Actions.accessKey.authorizeSync(client, {
174
+ * accessKey,
175
+ * expiry: Math.floor((Date.now() + 30_000) / 1000),
176
+ * })
177
+ * ```
178
+ *
179
+ * @param client - Client.
180
+ * @param parameters - Parameters.
181
+ * @returns The transaction receipt and event data.
182
+ */
183
+ export async function authorizeSync<
184
+ chain extends Chain | undefined,
185
+ account extends Account | undefined,
186
+ >(
187
+ client: Client<Transport, chain, account>,
188
+ parameters: authorizeSync.Parameters<chain, account>,
189
+ ): Promise<authorizeSync.ReturnValue> {
190
+ const { throwOnReceiptRevert = true, ...rest } = parameters
191
+ const receipt = await authorize.inner(sendTransactionSync, client, {
192
+ ...rest,
193
+ throwOnReceiptRevert,
194
+ } as never)
195
+ const { args } = authorize.extractEvent(receipt.logs)
196
+ return {
197
+ ...args,
198
+ receipt,
199
+ } as never
200
+ }
201
+
202
+ export namespace authorizeSync {
203
+ export type Parameters<
204
+ chain extends Chain | undefined = Chain | undefined,
205
+ account extends Account | undefined = Account | undefined,
206
+ > = authorize.Parameters<chain, account>
207
+
208
+ export type Args = authorize.Args
209
+
210
+ export type ReturnValue = Compute<
211
+ GetEventArgs<
212
+ typeof Abis.accountKeychain,
213
+ 'KeyAuthorized',
214
+ { IndexedOnly: false; Required: true }
215
+ > & {
216
+ receipt: TransactionReceipt
217
+ }
218
+ >
219
+
220
+ // TODO: exhaustive error type
221
+ export type ErrorType = BaseErrorType
222
+ }
223
+
224
+ /**
225
+ * Revokes an authorized access key.
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * import { createClient, http } from 'viem'
230
+ * import { tempo } from 'viem/chains'
231
+ * import { Actions } from 'viem/tempo'
232
+ * import { privateKeyToAccount } from 'viem/accounts'
233
+ *
234
+ * const client = createClient({
235
+ * account: privateKeyToAccount('0x...'),
236
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
237
+ * transport: http(),
238
+ * })
239
+ *
240
+ * const hash = await Actions.accessKey.revoke(client, {
241
+ * accessKey: '0x...',
242
+ * })
243
+ * ```
244
+ *
245
+ * @param client - Client.
246
+ * @param parameters - Parameters.
247
+ * @returns The transaction hash.
248
+ */
249
+ export async function revoke<
250
+ chain extends Chain | undefined,
251
+ account extends Account | undefined,
252
+ >(
253
+ client: Client<Transport, chain, account>,
254
+ parameters: revoke.Parameters<chain, account>,
255
+ ): Promise<revoke.ReturnValue> {
256
+ return revoke.inner(writeContract, client, parameters)
257
+ }
258
+
259
+ export namespace revoke {
260
+ export type Parameters<
261
+ chain extends Chain | undefined = Chain | undefined,
262
+ account extends Account | undefined = Account | undefined,
263
+ > = WriteParameters<chain, account> & Args
264
+
265
+ export type Args = {
266
+ /** The access key to revoke. */
267
+ accessKey: Address | AccessKeyAccount
268
+ }
269
+
270
+ export type ReturnValue = WriteContractReturnType
271
+
272
+ // TODO: exhaustive error type
273
+ export type ErrorType = BaseErrorType
274
+
275
+ /** @internal */
276
+ export async function inner<
277
+ action extends typeof writeContract | typeof writeContractSync,
278
+ chain extends Chain | undefined,
279
+ account extends Account | undefined,
280
+ >(
281
+ action: action,
282
+ client: Client<Transport, chain, account>,
283
+ parameters: revoke.Parameters<chain, account>,
284
+ ): Promise<ReturnType<action>> {
285
+ const { accessKey, ...rest } = parameters
286
+ const call = revoke.call({ accessKey })
287
+ return (await action(client, {
288
+ ...rest,
289
+ ...call,
290
+ } as never)) as never
291
+ }
292
+
293
+ /**
294
+ * Defines a call to the `revokeKey` function.
295
+ *
296
+ * Can be passed as a parameter to:
297
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
298
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
299
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
300
+ *
301
+ * @example
302
+ * ```ts
303
+ * import { createClient, http, walletActions } from 'viem'
304
+ * import { tempo } from 'viem/chains'
305
+ * import { Actions } from 'viem/tempo'
306
+ *
307
+ * const client = createClient({
308
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
309
+ * transport: http(),
310
+ * }).extend(walletActions)
311
+ *
312
+ * const hash = await client.sendTransaction({
313
+ * calls: [
314
+ * Actions.accessKey.revoke.call({ accessKey: '0x...' }),
315
+ * ],
316
+ * })
317
+ * ```
318
+ *
319
+ * @param args - Arguments.
320
+ * @returns The call.
321
+ */
322
+ export function call(args: Args) {
323
+ const { accessKey } = args
324
+ return defineCall({
325
+ address: Addresses.accountKeychain,
326
+ abi: Abis.accountKeychain,
327
+ functionName: 'revokeKey',
328
+ args: [resolveAccessKey(accessKey)],
329
+ })
330
+ }
331
+
332
+ export function extractEvent(logs: Log[]) {
333
+ const [log] = parseEventLogs({
334
+ abi: Abis.accountKeychain,
335
+ logs,
336
+ eventName: 'KeyRevoked',
337
+ strict: true,
338
+ })
339
+ if (!log) throw new Error('`KeyRevoked` event not found.')
340
+ return log
341
+ }
342
+ }
343
+
344
+ /**
345
+ * Revokes an authorized access key and waits for the transaction receipt.
346
+ *
347
+ * @example
348
+ * ```ts
349
+ * import { createClient, http } from 'viem'
350
+ * import { tempo } from 'viem/chains'
351
+ * import { Actions } from 'viem/tempo'
352
+ * import { privateKeyToAccount } from 'viem/accounts'
353
+ *
354
+ * const client = createClient({
355
+ * account: privateKeyToAccount('0x...'),
356
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
357
+ * transport: http(),
358
+ * })
359
+ *
360
+ * const result = await Actions.accessKey.revokeSync(client, {
361
+ * accessKey: '0x...',
362
+ * })
363
+ * ```
364
+ *
365
+ * @param client - Client.
366
+ * @param parameters - Parameters.
367
+ * @returns The transaction receipt and event data.
368
+ */
369
+ export async function revokeSync<
370
+ chain extends Chain | undefined,
371
+ account extends Account | undefined,
372
+ >(
373
+ client: Client<Transport, chain, account>,
374
+ parameters: revokeSync.Parameters<chain, account>,
375
+ ): Promise<revokeSync.ReturnValue> {
376
+ const { throwOnReceiptRevert = true, ...rest } = parameters
377
+ const receipt = await revoke.inner(writeContractSync, client, {
378
+ ...rest,
379
+ throwOnReceiptRevert,
380
+ } as never)
381
+ const { args } = revoke.extractEvent(receipt.logs)
382
+ return {
383
+ ...args,
384
+ receipt,
385
+ } as never
386
+ }
387
+
388
+ export namespace revokeSync {
389
+ export type Parameters<
390
+ chain extends Chain | undefined = Chain | undefined,
391
+ account extends Account | undefined = Account | undefined,
392
+ > = revoke.Parameters<chain, account>
393
+
394
+ export type Args = revoke.Args
395
+
396
+ export type ReturnValue = Compute<
397
+ GetEventArgs<
398
+ typeof Abis.accountKeychain,
399
+ 'KeyRevoked',
400
+ { IndexedOnly: false; Required: true }
401
+ > & {
402
+ receipt: TransactionReceipt
403
+ }
404
+ >
405
+
406
+ // TODO: exhaustive error type
407
+ export type ErrorType = BaseErrorType
408
+ }
409
+
410
+ /**
411
+ * Updates the spending limit for a specific token on an authorized access key.
412
+ *
413
+ * @example
414
+ * ```ts
415
+ * import { createClient, http } from 'viem'
416
+ * import { tempo } from 'viem/chains'
417
+ * import { Actions } from 'viem/tempo'
418
+ * import { privateKeyToAccount } from 'viem/accounts'
419
+ *
420
+ * const client = createClient({
421
+ * account: privateKeyToAccount('0x...'),
422
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
423
+ * transport: http(),
424
+ * })
425
+ *
426
+ * const hash = await Actions.accessKey.updateLimit(client, {
427
+ * accessKey: '0x...',
428
+ * token: '0x...',
429
+ * limit: 1000000000000000000n,
430
+ * })
431
+ * ```
432
+ *
433
+ * @param client - Client.
434
+ * @param parameters - Parameters.
435
+ * @returns The transaction hash.
436
+ */
437
+ export async function updateLimit<
438
+ chain extends Chain | undefined,
439
+ account extends Account | undefined,
440
+ >(
441
+ client: Client<Transport, chain, account>,
442
+ parameters: updateLimit.Parameters<chain, account>,
443
+ ): Promise<updateLimit.ReturnValue> {
444
+ return updateLimit.inner(writeContract, client, parameters)
445
+ }
446
+
447
+ export namespace updateLimit {
448
+ export type Parameters<
449
+ chain extends Chain | undefined = Chain | undefined,
450
+ account extends Account | undefined = Account | undefined,
451
+ > = WriteParameters<chain, account> & Args
452
+
453
+ export type Args = {
454
+ /** The access key to update. */
455
+ accessKey: Address | AccessKeyAccount
456
+ /** The token address. */
457
+ token: Address
458
+ /** The new spending limit. */
459
+ limit: bigint
460
+ }
461
+
462
+ export type ReturnValue = WriteContractReturnType
463
+
464
+ // TODO: exhaustive error type
465
+ export type ErrorType = BaseErrorType
466
+
467
+ /** @internal */
468
+ export async function inner<
469
+ action extends typeof writeContract | typeof writeContractSync,
470
+ chain extends Chain | undefined,
471
+ account extends Account | undefined,
472
+ >(
473
+ action: action,
474
+ client: Client<Transport, chain, account>,
475
+ parameters: updateLimit.Parameters<chain, account>,
476
+ ): Promise<ReturnType<action>> {
477
+ const { accessKey, token, limit, ...rest } = parameters
478
+ const call = updateLimit.call({ accessKey, token, limit })
479
+ return (await action(client, {
480
+ ...rest,
481
+ ...call,
482
+ } as never)) as never
483
+ }
484
+
485
+ /**
486
+ * Defines a call to the `updateSpendingLimit` function.
487
+ *
488
+ * Can be passed as a parameter to:
489
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
490
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
491
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
492
+ *
493
+ * @example
494
+ * ```ts
495
+ * import { createClient, http, walletActions } from 'viem'
496
+ * import { tempo } from 'viem/chains'
497
+ * import { Actions } from 'viem/tempo'
498
+ *
499
+ * const client = createClient({
500
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
501
+ * transport: http(),
502
+ * }).extend(walletActions)
503
+ *
504
+ * const hash = await client.sendTransaction({
505
+ * calls: [
506
+ * Actions.accessKey.updateLimit.call({
507
+ * accessKey: '0x...',
508
+ * token: '0x...',
509
+ * limit: 1000000000000000000n,
510
+ * }),
511
+ * ],
512
+ * })
513
+ * ```
514
+ *
515
+ * @param args - Arguments.
516
+ * @returns The call.
517
+ */
518
+ export function call(args: Args) {
519
+ const { accessKey, token, limit } = args
520
+ return defineCall({
521
+ address: Addresses.accountKeychain,
522
+ abi: Abis.accountKeychain,
523
+ functionName: 'updateSpendingLimit',
524
+ args: [resolveAccessKey(accessKey), token, limit],
525
+ })
526
+ }
527
+
528
+ export function extractEvent(logs: Log[]) {
529
+ const [log] = parseEventLogs({
530
+ abi: Abis.accountKeychain,
531
+ logs,
532
+ eventName: 'SpendingLimitUpdated',
533
+ strict: true,
534
+ })
535
+ if (!log) throw new Error('`SpendingLimitUpdated` event not found.')
536
+ return log
537
+ }
538
+ }
539
+
540
+ /**
541
+ * Updates the spending limit and waits for the transaction receipt.
542
+ *
543
+ * @example
544
+ * ```ts
545
+ * import { createClient, http } from 'viem'
546
+ * import { tempo } from 'viem/chains'
547
+ * import { Actions } from 'viem/tempo'
548
+ * import { privateKeyToAccount } from 'viem/accounts'
549
+ *
550
+ * const client = createClient({
551
+ * account: privateKeyToAccount('0x...'),
552
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
553
+ * transport: http(),
554
+ * })
555
+ *
556
+ * const result = await Actions.accessKey.updateLimitSync(client, {
557
+ * accessKey: '0x...',
558
+ * token: '0x...',
559
+ * limit: 1000000000000000000n,
560
+ * })
561
+ * ```
562
+ *
563
+ * @param client - Client.
564
+ * @param parameters - Parameters.
565
+ * @returns The transaction receipt and event data.
566
+ */
567
+ export async function updateLimitSync<
568
+ chain extends Chain | undefined,
569
+ account extends Account | undefined,
570
+ >(
571
+ client: Client<Transport, chain, account>,
572
+ parameters: updateLimitSync.Parameters<chain, account>,
573
+ ): Promise<updateLimitSync.ReturnValue> {
574
+ const { throwOnReceiptRevert = true, ...rest } = parameters
575
+ const receipt = await updateLimit.inner(writeContractSync, client, {
576
+ ...rest,
577
+ throwOnReceiptRevert,
578
+ } as never)
579
+ const { args } = updateLimit.extractEvent(receipt.logs)
580
+ return {
581
+ account: args.account,
582
+ publicKey: args.publicKey,
583
+ token: args.token,
584
+ limit: args.newLimit,
585
+ receipt,
586
+ }
587
+ }
588
+
589
+ export namespace updateLimitSync {
590
+ export type Parameters<
591
+ chain extends Chain | undefined = Chain | undefined,
592
+ account extends Account | undefined = Account | undefined,
593
+ > = updateLimit.Parameters<chain, account>
594
+
595
+ export type Args = updateLimit.Args
596
+
597
+ export type ReturnValue = {
598
+ /** The account that owns the key. */
599
+ account: Address
600
+ /** The access key address. */
601
+ publicKey: Address
602
+ /** The token address. */
603
+ token: Address
604
+ /** The new spending limit. */
605
+ limit: bigint
606
+ /** The transaction receipt. */
607
+ receipt: TransactionReceipt
608
+ }
609
+
610
+ // TODO: exhaustive error type
611
+ export type ErrorType = BaseErrorType
612
+ }
613
+
614
+ /**
615
+ * Gets access key information.
616
+ *
617
+ * @example
618
+ * ```ts
619
+ * import { createClient, http } from 'viem'
620
+ * import { tempo } from 'viem/chains'
621
+ * import { Actions } from 'viem/tempo'
622
+ *
623
+ * const client = createClient({
624
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
625
+ * transport: http(),
626
+ * })
627
+ *
628
+ * const key = await Actions.accessKey.getMetadata(client, {
629
+ * account: '0x...',
630
+ * accessKey: '0x...',
631
+ * })
632
+ * ```
633
+ *
634
+ * @param client - Client.
635
+ * @param parameters - Parameters.
636
+ * @returns The key information.
637
+ */
638
+ export async function getMetadata<
639
+ chain extends Chain | undefined,
640
+ account extends Account | undefined,
641
+ >(
642
+ client: Client<Transport, chain, account>,
643
+ parameters: getMetadata.Parameters<account>,
644
+ ): Promise<getMetadata.ReturnValue> {
645
+ const { account: account_ = client.account, accessKey, ...rest } = parameters
646
+ if (!account_) throw new Error('account is required.')
647
+ const account = parseAccount(account_)
648
+ const result = await readContract(client, {
649
+ ...rest,
650
+ ...getMetadata.call({ account: account.address, accessKey }),
651
+ })
652
+ return {
653
+ address: result.keyId,
654
+ keyType:
655
+ signatureTypes[result.signatureType as keyof typeof signatureTypes] ??
656
+ 'secp256k1',
657
+ expiry: result.expiry,
658
+ spendPolicy: spendPolicies[`${result.enforceLimits}`],
659
+ isRevoked: result.isRevoked,
660
+ }
661
+ }
662
+
663
+ export namespace getMetadata {
664
+ export type Parameters<
665
+ account extends Account | undefined = Account | undefined,
666
+ > = ReadParameters & GetAccountParameter<account> & Pick<Args, 'accessKey'>
667
+
668
+ export type Args = {
669
+ /** Account address. */
670
+ account: Address
671
+ /** The access key. */
672
+ accessKey: Address | AccessKeyAccount
673
+ }
674
+
675
+ export type ReturnValue = {
676
+ /** The access key address. */
677
+ address: Address
678
+ /** The key type. */
679
+ keyType: 'secp256k1' | 'p256' | 'webAuthn'
680
+ /** The expiry timestamp. */
681
+ expiry: bigint
682
+ /** The spending policy. */
683
+ spendPolicy: 'limited' | 'unlimited'
684
+ /** Whether the key is revoked. */
685
+ isRevoked: boolean
686
+ }
687
+
688
+ /**
689
+ * Defines a call to the `getKey` function.
690
+ *
691
+ * @param args - Arguments.
692
+ * @returns The call.
693
+ */
694
+ export function call(args: Args) {
695
+ const { account, accessKey } = args
696
+ return defineCall({
697
+ address: Addresses.accountKeychain,
698
+ abi: Abis.accountKeychain,
699
+ functionName: 'getKey',
700
+ args: [account, resolveAccessKey(accessKey)],
701
+ })
702
+ }
703
+ }
704
+
705
+ /**
706
+ * Gets the remaining spending limit for a key-token pair.
707
+ *
708
+ * @example
709
+ * ```ts
710
+ * import { createClient, http } from 'viem'
711
+ * import { tempo } from 'viem/chains'
712
+ * import { Actions } from 'viem/tempo'
713
+ *
714
+ * const client = createClient({
715
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
716
+ * transport: http(),
717
+ * })
718
+ *
719
+ * const remaining = await Actions.accessKey.getRemainingLimit(client, {
720
+ * account: '0x...',
721
+ * accessKey: '0x...',
722
+ * token: '0x...',
723
+ * })
724
+ * ```
725
+ *
726
+ * @param client - Client.
727
+ * @param parameters - Parameters.
728
+ * @returns The remaining spending amount.
729
+ */
730
+ export async function getRemainingLimit<
731
+ chain extends Chain | undefined,
732
+ account extends Account | undefined,
733
+ >(
734
+ client: Client<Transport, chain, account>,
735
+ parameters: getRemainingLimit.Parameters<account>,
736
+ ): Promise<getRemainingLimit.ReturnValue> {
737
+ const {
738
+ account: account_ = client.account,
739
+ accessKey,
740
+ token,
741
+ ...rest
742
+ } = parameters
743
+ if (!account_) throw new Error('account is required.')
744
+ const account = parseAccount(account_)
745
+ return readContract(client, {
746
+ ...rest,
747
+ ...getRemainingLimit.call({ account: account.address, accessKey, token }),
748
+ })
749
+ }
750
+
751
+ export namespace getRemainingLimit {
752
+ export type Parameters<
753
+ account extends Account | undefined = Account | undefined,
754
+ > = ReadParameters &
755
+ GetAccountParameter<account> &
756
+ Pick<Args, 'accessKey' | 'token'>
757
+
758
+ export type Args = {
759
+ /** Account address. */
760
+ account: Address
761
+ /** The access key. */
762
+ accessKey: Address | AccessKeyAccount
763
+ /** The token address. */
764
+ token: Address
765
+ }
766
+
767
+ export type ReturnValue = ReadContractReturnType<
768
+ typeof Abis.accountKeychain,
769
+ 'getRemainingLimit',
770
+ never
771
+ >
772
+
773
+ /**
774
+ * Defines a call to the `getRemainingLimit` function.
775
+ *
776
+ * @param args - Arguments.
777
+ * @returns The call.
778
+ */
779
+ export function call(args: Args) {
780
+ const { account, accessKey, token } = args
781
+ return defineCall({
782
+ address: Addresses.accountKeychain,
783
+ abi: Abis.accountKeychain,
784
+ functionName: 'getRemainingLimit',
785
+ args: [account, resolveAccessKey(accessKey), token],
786
+ })
787
+ }
788
+ }
789
+
790
+ /**
791
+ * Signs a key authorization for an access key.
792
+ *
793
+ * @example
794
+ * ```ts
795
+ * import { generatePrivateKey } from 'viem/accounts'
796
+ * import { Account, Actions } from 'viem/tempo'
797
+ *
798
+ * const account = Account.from({ privateKey: '0x...' })
799
+ * const accessKey = Account.fromP256(generatePrivateKey(), {
800
+ * access: account,
801
+ * })
802
+ *
803
+ * const keyAuthorization = await Actions.accessKey.signAuthorization(
804
+ * client,
805
+ * {
806
+ * account,
807
+ * accessKey,
808
+ * expiry: Math.floor((Date.now() + 30_000) / 1000),
809
+ * },
810
+ * )
811
+ * ```
812
+ *
813
+ * @param client - Client.
814
+ * @param parameters - Parameters.
815
+ * @returns The signed key authorization.
816
+ */
817
+ export async function signAuthorization<
818
+ chain extends Chain | undefined,
819
+ account extends Account | undefined,
820
+ >(
821
+ client: Client<Transport, chain, account>,
822
+ parameters: signAuthorization.Parameters<account>,
823
+ ): Promise<signAuthorization.ReturnValue> {
824
+ const { accessKey, chainId = client.chain?.id, ...rest } = parameters
825
+ const account_ = rest.account ?? client.account
826
+ if (!account_) throw new Error('account is required.')
827
+ if (!chainId) throw new Error('chainId is required.')
828
+ const parsed = parseAccount(account_)
829
+ return signKeyAuthorization(parsed as never, {
830
+ chainId: BigInt(chainId),
831
+ key: accessKey,
832
+ ...rest,
833
+ })
834
+ }
835
+
836
+ export namespace signAuthorization {
837
+ export type Parameters<
838
+ account extends Account | undefined = Account | undefined,
839
+ > = GetAccountParameter<account> & {
840
+ /** The access key to authorize. */
841
+ accessKey: Pick<AccessKeyAccount, 'accessKeyAddress' | 'keyType'>
842
+ /** The chain ID. */
843
+ chainId?: number | undefined
844
+ /** Unix timestamp when the key expires. */
845
+ expiry?: number | undefined
846
+ /** Spending limits per token. */
847
+ limits?: { token: Address; limit: bigint }[] | undefined
848
+ }
849
+
850
+ export type ReturnValue = Awaited<ReturnType<typeof signKeyAuthorization>>
851
+ }
852
+
853
+ /** @internal */
854
+ function resolveAccessKey(accessKey: Address | AccessKeyAccount): Address {
855
+ if (typeof accessKey === 'string') return accessKey
856
+ return accessKey.accessKeyAddress
857
+ }