viem 2.21.50 → 2.21.52

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/_cjs/chains/definitions/boolBetaMainnet.js +24 -0
  3. package/_cjs/chains/definitions/boolBetaMainnet.js.map +1 -0
  4. package/_cjs/chains/definitions/corn.js +32 -0
  5. package/_cjs/chains/definitions/corn.js.map +1 -0
  6. package/_cjs/chains/definitions/cornTestnet.js +33 -0
  7. package/_cjs/chains/definitions/cornTestnet.js.map +1 -0
  8. package/_cjs/chains/definitions/redbellyMainnet.js +27 -0
  9. package/_cjs/chains/definitions/redbellyMainnet.js.map +1 -0
  10. package/_cjs/chains/definitions/redbellyTestnet.js +3 -3
  11. package/_cjs/chains/definitions/redbellyTestnet.js.map +1 -1
  12. package/_cjs/chains/definitions/sonicTestnet.js +24 -0
  13. package/_cjs/chains/definitions/sonicTestnet.js.map +1 -0
  14. package/_cjs/chains/definitions/swissdlt.js +26 -0
  15. package/_cjs/chains/definitions/swissdlt.js.map +1 -0
  16. package/_cjs/chains/definitions/worldLand.js +26 -0
  17. package/_cjs/chains/definitions/worldLand.js.map +1 -0
  18. package/_cjs/chains/index.js +23 -9
  19. package/_cjs/chains/index.js.map +1 -1
  20. package/_cjs/errors/version.js +1 -1
  21. package/_cjs/experimental/eip7702/actions/prepareAuthorization.js +44 -0
  22. package/_cjs/experimental/eip7702/actions/prepareAuthorization.js.map +1 -0
  23. package/_cjs/experimental/eip7702/actions/signAuthorization.js +3 -30
  24. package/_cjs/experimental/eip7702/actions/signAuthorization.js.map +1 -1
  25. package/_cjs/experimental/eip7702/decorators/eip7702.js +2 -0
  26. package/_cjs/experimental/eip7702/decorators/eip7702.js.map +1 -1
  27. package/_cjs/experimental/index.js +3 -1
  28. package/_cjs/experimental/index.js.map +1 -1
  29. package/_cjs/utils/observe.js +4 -1
  30. package/_cjs/utils/observe.js.map +1 -1
  31. package/_esm/chains/definitions/boolBetaMainnet.js +21 -0
  32. package/_esm/chains/definitions/boolBetaMainnet.js.map +1 -0
  33. package/_esm/chains/definitions/corn.js +29 -0
  34. package/_esm/chains/definitions/corn.js.map +1 -0
  35. package/_esm/chains/definitions/cornTestnet.js +30 -0
  36. package/_esm/chains/definitions/cornTestnet.js.map +1 -0
  37. package/_esm/chains/definitions/redbellyMainnet.js +24 -0
  38. package/_esm/chains/definitions/redbellyMainnet.js.map +1 -0
  39. package/_esm/chains/definitions/redbellyTestnet.js +3 -3
  40. package/_esm/chains/definitions/redbellyTestnet.js.map +1 -1
  41. package/_esm/chains/definitions/sonicTestnet.js +21 -0
  42. package/_esm/chains/definitions/sonicTestnet.js.map +1 -0
  43. package/_esm/chains/definitions/swissdlt.js +23 -0
  44. package/_esm/chains/definitions/swissdlt.js.map +1 -0
  45. package/_esm/chains/definitions/worldLand.js +23 -0
  46. package/_esm/chains/definitions/worldLand.js.map +1 -0
  47. package/_esm/chains/index.js +8 -0
  48. package/_esm/chains/index.js.map +1 -1
  49. package/_esm/errors/version.js +1 -1
  50. package/_esm/experimental/eip7702/actions/prepareAuthorization.js +82 -0
  51. package/_esm/experimental/eip7702/actions/prepareAuthorization.js.map +1 -0
  52. package/_esm/experimental/eip7702/actions/signAuthorization.js +3 -30
  53. package/_esm/experimental/eip7702/actions/signAuthorization.js.map +1 -1
  54. package/_esm/experimental/eip7702/decorators/eip7702.js +2 -0
  55. package/_esm/experimental/eip7702/decorators/eip7702.js.map +1 -1
  56. package/_esm/experimental/index.js +1 -0
  57. package/_esm/experimental/index.js.map +1 -1
  58. package/_esm/utils/observe.js +4 -1
  59. package/_esm/utils/observe.js.map +1 -1
  60. package/_types/chains/definitions/boolBetaMainnet.d.ts +37 -0
  61. package/_types/chains/definitions/boolBetaMainnet.d.ts.map +1 -0
  62. package/_types/chains/definitions/corn.d.ts +34 -0
  63. package/_types/chains/definitions/corn.d.ts.map +1 -0
  64. package/_types/chains/definitions/cornTestnet.d.ts +34 -0
  65. package/_types/chains/definitions/cornTestnet.d.ts.map +1 -0
  66. package/_types/chains/definitions/redbellyMainnet.d.ts +38 -0
  67. package/_types/chains/definitions/redbellyMainnet.d.ts.map +1 -0
  68. package/_types/chains/definitions/redbellyTestnet.d.ts +3 -3
  69. package/_types/chains/definitions/redbellyTestnet.d.ts.map +1 -1
  70. package/_types/chains/definitions/sonicTestnet.d.ts +37 -0
  71. package/_types/chains/definitions/sonicTestnet.d.ts.map +1 -0
  72. package/_types/chains/definitions/swissdlt.d.ts +37 -0
  73. package/_types/chains/definitions/swissdlt.d.ts.map +1 -0
  74. package/_types/chains/definitions/worldLand.d.ts +37 -0
  75. package/_types/chains/definitions/worldLand.d.ts.map +1 -0
  76. package/_types/chains/index.d.ts +8 -0
  77. package/_types/chains/index.d.ts.map +1 -1
  78. package/_types/errors/version.d.ts +1 -1
  79. package/_types/experimental/eip7702/actions/prepareAuthorization.d.ts +66 -0
  80. package/_types/experimental/eip7702/actions/prepareAuthorization.d.ts.map +1 -0
  81. package/_types/experimental/eip7702/actions/signAuthorization.d.ts +3 -15
  82. package/_types/experimental/eip7702/actions/signAuthorization.d.ts.map +1 -1
  83. package/_types/experimental/eip7702/decorators/eip7702.d.ts +45 -0
  84. package/_types/experimental/eip7702/decorators/eip7702.d.ts.map +1 -1
  85. package/_types/experimental/index.d.ts +1 -0
  86. package/_types/experimental/index.d.ts.map +1 -1
  87. package/_types/utils/observe.d.ts.map +1 -1
  88. package/chains/definitions/boolBetaMainnet.ts +21 -0
  89. package/chains/definitions/corn.ts +31 -0
  90. package/chains/definitions/cornTestnet.ts +32 -0
  91. package/chains/definitions/redbellyMainnet.ts +25 -0
  92. package/chains/definitions/redbellyTestnet.ts +4 -3
  93. package/chains/definitions/sonicTestnet.ts +21 -0
  94. package/chains/definitions/swissdlt.ts +23 -0
  95. package/chains/definitions/worldLand.ts +23 -0
  96. package/chains/index.ts +8 -0
  97. package/errors/version.ts +1 -1
  98. package/experimental/eip7702/actions/prepareAuthorization.ts +141 -0
  99. package/experimental/eip7702/actions/signAuthorization.ts +9 -60
  100. package/experimental/eip7702/decorators/eip7702.ts +53 -0
  101. package/experimental/index.ts +6 -0
  102. package/package.json +1 -1
  103. package/utils/observe.ts +3 -1
@@ -2,6 +2,11 @@ import type { Client } from '../../../clients/createClient.js'
2
2
  import type { Transport } from '../../../clients/transports/createTransport.js'
3
3
  import type { Account } from '../../../types/account.js'
4
4
  import type { Chain } from '../../../types/chain.js'
5
+ import {
6
+ type PrepareAuthorizationParameters,
7
+ type PrepareAuthorizationReturnType,
8
+ prepareAuthorization,
9
+ } from '../actions/prepareAuthorization.js'
5
10
  import {
6
11
  type SignAuthorizationParameters,
7
12
  type SignAuthorizationReturnType,
@@ -11,6 +16,52 @@ import {
11
16
  export type Eip7702Actions<
12
17
  account extends Account | undefined = Account | undefined,
13
18
  > = {
19
+ /**
20
+ * Prepares an [EIP-7702 Authorization](https://eips.ethereum.org/EIPS/eip-7702) object for signing.
21
+ * This Action will fill the required fields of the Authorization object if they are not provided (e.g. `nonce` and `chainId`).
22
+ *
23
+ * With the prepared Authorization object, you can use [`signAuthorization`](https://viem.sh/experimental/eip7702/signAuthorization) to sign over the Authorization object.
24
+ *
25
+ * @param client - Client to use
26
+ * @param parameters - {@link PrepareAuthorizationParameters}
27
+ * @returns The prepared Authorization object. {@link PrepareAuthorizationReturnType}
28
+ *
29
+ * @example
30
+ * import { createClient, http } from 'viem'
31
+ * import { privateKeyToAccount } from 'viem/accounts'
32
+ * import { mainnet } from 'viem/chains'
33
+ * import { eip7702Actions } from 'viem/experimental'
34
+ *
35
+ * const client = createClient({
36
+ * chain: mainnet,
37
+ * transport: http(),
38
+ * }).extend(eip7702Actions())
39
+ *
40
+ * const authorization = await client.prepareAuthorization({
41
+ * account: privateKeyToAccount('0x..'),
42
+ * contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
43
+ * })
44
+ *
45
+ * @example
46
+ * // Account Hoisting
47
+ * import { createClient, http } from 'viem'
48
+ * import { privateKeyToAccount } from 'viem/accounts'
49
+ * import { mainnet } from 'viem/chains'
50
+ * import { eip7702Actions } from 'viem/experimental'
51
+ *
52
+ * const client = createClient({
53
+ * account: privateKeyToAccount('0x…'),
54
+ * chain: mainnet,
55
+ * transport: http(),
56
+ * }).extend(eip7702Actions())
57
+ *
58
+ * const authorization = await client.prepareAuthorization({
59
+ * contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
60
+ * })
61
+ */
62
+ prepareAuthorization: (
63
+ parameters: PrepareAuthorizationParameters<account>,
64
+ ) => Promise<PrepareAuthorizationReturnType>
14
65
  /**
15
66
  * Signs an [EIP-7702 Authorization](https://eips.ethereum.org/EIPS/eip-7702) object.
16
67
  *
@@ -80,6 +131,8 @@ export function eip7702Actions() {
80
131
  client: Client<Transport, Chain | undefined, account>,
81
132
  ): Eip7702Actions<account> => {
82
133
  return {
134
+ prepareAuthorization: (parameters) =>
135
+ prepareAuthorization(client, parameters),
83
136
  signAuthorization: (parameters) => signAuthorization(client, parameters),
84
137
  }
85
138
  }
@@ -43,6 +43,12 @@ export {
43
43
  type Eip7702Actions,
44
44
  eip7702Actions,
45
45
  } from './eip7702/decorators/eip7702.js'
46
+ export {
47
+ type PrepareAuthorizationParameters,
48
+ type PrepareAuthorizationReturnType,
49
+ type PrepareAuthorizationErrorType,
50
+ prepareAuthorization,
51
+ } from './eip7702/actions/prepareAuthorization.js'
46
52
  export {
47
53
  type SignAuthorizationParameters,
48
54
  type SignAuthorizationReturnType,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.21.50",
4
+ "version": "2.21.52",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/utils/observe.ts CHANGED
@@ -43,8 +43,10 @@ export function observe<callbacks extends Callbacks>(
43
43
  }
44
44
 
45
45
  const unwatch = () => {
46
+ const listeners = getListeners()
47
+ if (!listeners.some((cb: any) => cb.id === callbackId)) return
46
48
  const cleanup = cleanupCache.get(observerId)
47
- if (getListeners().length === 1 && cleanup) cleanup()
49
+ if (listeners.length === 1 && cleanup) cleanup()
48
50
  unsubscribe()
49
51
  }
50
52