@zerodev/sdk 5.2.0-alpha-3 → 5.2.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 (203) hide show
  1. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +115 -58
  2. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -1
  3. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.js +39 -0
  4. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.js.map +1 -0
  5. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js +203 -0
  6. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js.map +1 -0
  7. package/_cjs/accounts/kernel/createKernelAccount.js +43 -22
  8. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  9. package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +22 -0
  10. package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -0
  11. package/_cjs/accounts/kernel/utils/common/getActionSelector.js +19 -0
  12. package/_cjs/accounts/kernel/utils/common/getActionSelector.js.map +1 -0
  13. package/_cjs/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js +22 -0
  14. package/_cjs/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js.map +1 -0
  15. package/_cjs/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js +39 -0
  16. package/_cjs/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -0
  17. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js +21 -0
  18. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js.map +1 -0
  19. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +41 -0
  20. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -0
  21. package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +20 -0
  22. package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -0
  23. package/_cjs/accounts/kernel/v1/createKernelV1Account.js +5 -2
  24. package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  25. package/_cjs/accounts/kernel/v2/createKernelV2Account.js +9 -4
  26. package/_cjs/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
  27. package/_cjs/accounts/utils/getCustomNonceKeyFromString.js +19 -0
  28. package/_cjs/accounts/utils/getCustomNonceKeyFromString.js.map +1 -0
  29. package/_cjs/accounts/utils/index.js +3 -1
  30. package/_cjs/accounts/utils/index.js.map +1 -1
  31. package/_cjs/accounts/utils/toKernelPluginManager.js +120 -184
  32. package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
  33. package/_cjs/actions/account-client/getUserOperationGasPrice.js +15 -0
  34. package/_cjs/actions/account-client/getUserOperationGasPrice.js.map +1 -0
  35. package/_cjs/actions/index.js +3 -1
  36. package/_cjs/actions/index.js.map +1 -1
  37. package/_cjs/actions/paymaster/estimateGasInERC20.js +2 -2
  38. package/_cjs/actions/paymaster/estimateGasInERC20.js.map +1 -1
  39. package/_cjs/actions/paymaster/sponsorUserOperation.js +1 -2
  40. package/_cjs/actions/paymaster/sponsorUserOperation.js.map +1 -1
  41. package/_cjs/clients/decorators/kernel.js +3 -1
  42. package/_cjs/clients/decorators/kernel.js.map +1 -1
  43. package/_cjs/clients/kernelAccountClient.js +29 -3
  44. package/_cjs/clients/kernelAccountClient.js.map +1 -1
  45. package/_cjs/clients/paymasterClient.js +18 -1
  46. package/_cjs/clients/paymasterClient.js.map +1 -1
  47. package/_cjs/clients/utils.js +31 -0
  48. package/_cjs/clients/utils.js.map +1 -0
  49. package/_cjs/constants.js +5 -2
  50. package/_cjs/constants.js.map +1 -1
  51. package/_cjs/index.js +6 -1
  52. package/_cjs/index.js.map +1 -1
  53. package/_cjs/providers/KernelEIP1193Provider.js +37 -0
  54. package/_cjs/providers/KernelEIP1193Provider.js.map +1 -1
  55. package/_cjs/types/index.js.map +1 -1
  56. package/_cjs/types/kernel.js.map +1 -1
  57. package/_cjs/utils.js +1 -2
  58. package/_cjs/utils.js.map +1 -1
  59. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +115 -58
  60. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -1
  61. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.js +36 -0
  62. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.js.map +1 -0
  63. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js +200 -0
  64. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js.map +1 -0
  65. package/_esm/accounts/kernel/createKernelAccount.js +44 -23
  66. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  67. package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +18 -0
  68. package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -0
  69. package/_esm/accounts/kernel/utils/common/getActionSelector.js +15 -0
  70. package/_esm/accounts/kernel/utils/common/getActionSelector.js.map +1 -0
  71. package/_esm/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js +18 -0
  72. package/_esm/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js.map +1 -0
  73. package/_esm/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js +35 -0
  74. package/_esm/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -0
  75. package/_esm/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js +18 -0
  76. package/_esm/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js.map +1 -0
  77. package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +42 -0
  78. package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -0
  79. package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +16 -0
  80. package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -0
  81. package/_esm/accounts/kernel/v1/createKernelV1Account.js +6 -3
  82. package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  83. package/_esm/accounts/kernel/v2/createKernelV2Account.js +10 -5
  84. package/_esm/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
  85. package/_esm/accounts/utils/getCustomNonceKeyFromString.js +15 -0
  86. package/_esm/accounts/utils/getCustomNonceKeyFromString.js.map +1 -0
  87. package/_esm/accounts/utils/index.js +1 -0
  88. package/_esm/accounts/utils/index.js.map +1 -1
  89. package/_esm/accounts/utils/toKernelPluginManager.js +124 -188
  90. package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
  91. package/_esm/actions/account-client/getUserOperationGasPrice.js +11 -0
  92. package/_esm/actions/account-client/getUserOperationGasPrice.js.map +1 -0
  93. package/_esm/actions/index.js +1 -0
  94. package/_esm/actions/index.js.map +1 -1
  95. package/_esm/actions/paymaster/estimateGasInERC20.js +2 -2
  96. package/_esm/actions/paymaster/estimateGasInERC20.js.map +1 -1
  97. package/_esm/actions/paymaster/sponsorUserOperation.js +1 -2
  98. package/_esm/actions/paymaster/sponsorUserOperation.js.map +1 -1
  99. package/_esm/clients/decorators/kernel.js +3 -1
  100. package/_esm/clients/decorators/kernel.js.map +1 -1
  101. package/_esm/clients/kernelAccountClient.js +30 -4
  102. package/_esm/clients/kernelAccountClient.js.map +1 -1
  103. package/_esm/clients/paymasterClient.js +19 -2
  104. package/_esm/clients/paymasterClient.js.map +1 -1
  105. package/_esm/clients/utils.js +26 -0
  106. package/_esm/clients/utils.js.map +1 -0
  107. package/_esm/constants.js +4 -1
  108. package/_esm/constants.js.map +1 -1
  109. package/_esm/index.js +3 -1
  110. package/_esm/index.js.map +1 -1
  111. package/_esm/providers/KernelEIP1193Provider.js +37 -0
  112. package/_esm/providers/KernelEIP1193Provider.js.map +1 -1
  113. package/_esm/types/index.js.map +1 -1
  114. package/_esm/types/kernel.js.map +1 -1
  115. package/_esm/utils.js +2 -3
  116. package/_esm/utils.js.map +1 -1
  117. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts +110 -20
  118. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts.map +1 -1
  119. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.d.ts +60 -0
  120. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.d.ts.map +1 -0
  121. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.d.ts +215 -0
  122. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.d.ts.map +1 -0
  123. package/_types/accounts/kernel/createKernelAccount.d.ts +8 -4
  124. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  125. package/_types/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.d.ts +3 -0
  126. package/_types/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.d.ts.map +1 -0
  127. package/_types/accounts/kernel/utils/common/getActionSelector.d.ts +4 -0
  128. package/_types/accounts/kernel/utils/common/getActionSelector.d.ts.map +1 -0
  129. package/_types/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.d.ts +9 -0
  130. package/_types/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.d.ts.map +1 -0
  131. package/_types/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.d.ts +13 -0
  132. package/_types/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.d.ts.map +1 -0
  133. package/_types/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.d.ts +9 -0
  134. package/_types/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.d.ts.map +1 -0
  135. package/_types/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.d.ts +10 -0
  136. package/_types/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.d.ts.map +1 -0
  137. package/_types/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.d.ts +3 -0
  138. package/_types/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.d.ts.map +1 -0
  139. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts +1 -1
  140. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
  141. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts +3 -1
  142. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts.map +1 -1
  143. package/_types/accounts/utils/getCustomNonceKeyFromString.d.ts +3 -0
  144. package/_types/accounts/utils/getCustomNonceKeyFromString.d.ts.map +1 -0
  145. package/_types/accounts/utils/index.d.ts +1 -0
  146. package/_types/accounts/utils/index.d.ts.map +1 -1
  147. package/_types/accounts/utils/toKernelPluginManager.d.ts +1 -1
  148. package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
  149. package/_types/actions/account-client/getUserOperationGasPrice.d.ts +9 -0
  150. package/_types/actions/account-client/getUserOperationGasPrice.d.ts.map +1 -0
  151. package/_types/actions/index.d.ts +1 -0
  152. package/_types/actions/index.d.ts.map +1 -1
  153. package/_types/actions/paymaster/estimateGasInERC20.d.ts.map +1 -1
  154. package/_types/actions/paymaster/sponsorUserOperation.d.ts.map +1 -1
  155. package/_types/clients/decorators/kernel.d.ts +8 -1
  156. package/_types/clients/decorators/kernel.d.ts.map +1 -1
  157. package/_types/clients/kernelAccountClient.d.ts +12 -4
  158. package/_types/clients/kernelAccountClient.d.ts.map +1 -1
  159. package/_types/clients/paymasterClient.d.ts.map +1 -1
  160. package/_types/clients/utils.d.ts +3 -0
  161. package/_types/clients/utils.d.ts.map +1 -0
  162. package/_types/constants.d.ts +4 -1
  163. package/_types/constants.d.ts.map +1 -1
  164. package/_types/index.d.ts +3 -1
  165. package/_types/index.d.ts.map +1 -1
  166. package/_types/providers/KernelEIP1193Provider.d.ts +2 -0
  167. package/_types/providers/KernelEIP1193Provider.d.ts.map +1 -1
  168. package/_types/types/index.d.ts +1 -1
  169. package/_types/types/index.d.ts.map +1 -1
  170. package/_types/types/kernel.d.ts +32 -17
  171. package/_types/types/kernel.d.ts.map +1 -1
  172. package/_types/utils.d.ts.map +1 -1
  173. package/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.ts +115 -58
  174. package/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.ts +35 -0
  175. package/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.ts +199 -0
  176. package/accounts/kernel/createKernelAccount.ts +59 -26
  177. package/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.ts +24 -0
  178. package/accounts/kernel/utils/common/getActionSelector.ts +20 -0
  179. package/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.ts +39 -0
  180. package/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.ts +76 -0
  181. package/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.ts +47 -0
  182. package/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.ts +63 -0
  183. package/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.ts +23 -0
  184. package/accounts/kernel/v1/createKernelV1Account.ts +21 -8
  185. package/accounts/kernel/v2/createKernelV2Account.ts +17 -6
  186. package/accounts/utils/getCustomNonceKeyFromString.ts +21 -0
  187. package/accounts/utils/index.ts +2 -0
  188. package/accounts/utils/toKernelPluginManager.ts +155 -224
  189. package/actions/account-client/getUserOperationGasPrice.ts +26 -0
  190. package/actions/index.ts +5 -0
  191. package/actions/paymaster/estimateGasInERC20.ts +2 -3
  192. package/actions/paymaster/sponsorUserOperation.ts +1 -3
  193. package/clients/decorators/kernel.ts +22 -6
  194. package/clients/kernelAccountClient.ts +36 -3
  195. package/clients/paymasterClient.ts +24 -1
  196. package/clients/utils.ts +28 -0
  197. package/constants.ts +6 -2
  198. package/index.ts +6 -1
  199. package/package.json +4 -4
  200. package/providers/KernelEIP1193Provider.ts +51 -0
  201. package/types/index.ts +4 -2
  202. package/types/kernel.ts +52 -38
  203. package/utils.ts +2 -3
@@ -0,0 +1,23 @@
1
+ import { getAction } from "permissionless"
2
+ import type { Address, Client } from "viem"
3
+ import { readContract } from "viem/actions"
4
+ import { KernelModuleIsInitializedAbi } from "../../../abi/kernel_v_3_0_0/KernelModuleAbi.js"
5
+
6
+ export const isPluginInitialized = async (
7
+ client: Client,
8
+ accountAddress: Address,
9
+ pluginAddress: Address
10
+ ) => {
11
+ try {
12
+ return await getAction(
13
+ client,
14
+ readContract
15
+ )({
16
+ abi: KernelModuleIsInitializedAbi,
17
+ address: pluginAddress,
18
+ functionName: "isInitialized",
19
+ args: [accountAddress]
20
+ })
21
+ } catch (error) {}
22
+ return false
23
+ }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  ENTRYPOINT_ADDRESS_V06,
3
3
  getAccountNonce,
4
+ getEntryPointVersion,
4
5
  getSenderAddress,
5
6
  getUserOperationHash,
6
7
  isSmartAccountDeployed
@@ -9,7 +10,10 @@ import {
9
10
  SignTransactionNotSupportedBySmartAccount,
10
11
  type SmartAccountSigner
11
12
  } from "permissionless/accounts"
12
- import type { EntryPoint } from "permissionless/types/entrypoint.js"
13
+ import type {
14
+ ENTRYPOINT_ADDRESS_V06_TYPE,
15
+ EntryPoint
16
+ } from "permissionless/types/entrypoint.js"
13
17
  import {
14
18
  type Address,
15
19
  type Chain,
@@ -96,15 +100,20 @@ export async function createKernelV1Account<
96
100
  client: Client<TTransport, TChain, undefined>,
97
101
  {
98
102
  signer,
99
- entrypoint: entryPointAddress = ENTRYPOINT_ADDRESS_V06 as entryPoint,
103
+ entrypoint: entryPointAddress,
100
104
  index = 0n
101
105
  }: {
102
106
  signer: SmartAccountSigner<TSource, TAddress>
103
- entrypoint?: entryPoint
107
+ entrypoint: entryPoint
104
108
  index?: bigint
105
109
  }
106
110
  ): Promise<KernelV1SmartAccount<entryPoint, TTransport, TChain>> {
107
- if (entryPointAddress !== ENTRYPOINT_ADDRESS_V06) {
111
+ const entryPointVersion = getEntryPointVersion(entryPointAddress)
112
+
113
+ if (
114
+ entryPointVersion !== "v0.6" ||
115
+ entryPointAddress !== ENTRYPOINT_ADDRESS_V06
116
+ ) {
108
117
  throw new Error("Only EntryPoint 0.6 is supported")
109
118
  }
110
119
 
@@ -130,10 +139,13 @@ export async function createKernelV1Account<
130
139
  }
131
140
 
132
141
  const initCode = await generateInitCode()
133
- const accountAddress = await getSenderAddress(client, {
134
- initCode,
135
- entryPoint: entryPointAddress
136
- })
142
+ const accountAddress = await getSenderAddress<ENTRYPOINT_ADDRESS_V06_TYPE>(
143
+ client,
144
+ {
145
+ initCode,
146
+ entryPoint: entryPointAddress
147
+ }
148
+ )
137
149
 
138
150
  if (!accountAddress) throw new Error("Account address not found")
139
151
 
@@ -200,6 +212,7 @@ export async function createKernelV1Account<
200
212
 
201
213
  return {
202
214
  ...account,
215
+ generateInitCode,
203
216
  client: client,
204
217
  publicKey: accountAddress,
205
218
  entryPoint: entryPointAddress,
@@ -1,6 +1,6 @@
1
1
  import {
2
- ENTRYPOINT_ADDRESS_V06,
3
2
  getAccountNonce,
3
+ getEntryPointVersion,
4
4
  getSenderAddress,
5
5
  isSmartAccountDeployed
6
6
  } from "permissionless"
@@ -56,6 +56,8 @@ export type KernelSmartAccount<
56
56
  chain extends Chain | undefined = Chain | undefined
57
57
  > = SmartAccount<entryPoint, "kernelSmartAccount", transport, chain> & {
58
58
  kernelPluginManager: KernelPluginManager<entryPoint>
59
+ getNonce: (customNonceKey?: bigint) => Promise<bigint>
60
+ generateInitCode: () => Promise<Hex>
59
61
  encodeCallData: (args: KernelEncodeCallDataArgs) => Promise<Hex>
60
62
  }
61
63
 
@@ -154,7 +156,7 @@ export async function createKernelV2Account<
154
156
  client: Client<TTransport, TChain, undefined>,
155
157
  {
156
158
  plugins,
157
- entryPoint: entryPointAddress = ENTRYPOINT_ADDRESS_V06 as entryPoint,
159
+ entryPoint: entryPointAddress,
158
160
  index = 0n,
159
161
  factoryAddress = KERNEL_ADDRESSES.FACTORY_ADDRESS,
160
162
  deployedAccountAddress
@@ -162,18 +164,23 @@ export async function createKernelV2Account<
162
164
  plugins:
163
165
  | KernelPluginManagerParams<entryPoint>
164
166
  | KernelPluginManager<entryPoint>
165
- entryPoint?: entryPoint
167
+ entryPoint: entryPoint
166
168
  index?: bigint
167
169
  factoryAddress?: Address
168
170
  deployedAccountAddress?: Address
169
171
  }
170
172
  ): Promise<KernelSmartAccount<entryPoint, TTransport, TChain>> {
173
+ const entryPointVersion = getEntryPointVersion(entryPointAddress)
174
+
175
+ if (entryPointVersion !== "v0.6") {
176
+ throw new Error("Only EntryPoint 0.6 is supported")
177
+ }
171
178
  const kernelPluginManager = isKernelPluginManager<entryPoint>(plugins)
172
179
  ? plugins
173
180
  : await toKernelPluginManager(client, {
174
181
  sudo: plugins.sudo,
175
182
  regular: plugins.regular,
176
- executorData: plugins.executorData,
183
+ action: plugins.action,
177
184
  pluginEnableSignature: plugins.pluginEnableSignature,
178
185
  kernelVersion: "0.0.2" ?? plugins.kernelVersion,
179
186
  entryPoint: entryPointAddress
@@ -281,6 +288,7 @@ export async function createKernelV2Account<
281
288
  entryPoint: entryPointAddress,
282
289
  source: "kernelSmartAccount",
283
290
  kernelPluginManager,
291
+ generateInitCode,
284
292
  async getFactory() {
285
293
  if (smartAccountDeployed) return undefined
286
294
 
@@ -310,8 +318,11 @@ export async function createKernelV2Account<
310
318
  },
311
319
 
312
320
  // Get the nonce of the smart account
313
- async getNonce() {
314
- const key = await kernelPluginManager.getNonceKey()
321
+ async getNonce(customNonceKey?: bigint) {
322
+ const key = await kernelPluginManager.getNonceKey(
323
+ accountAddress,
324
+ customNonceKey
325
+ )
315
326
  return getAccountNonce(client, {
316
327
  sender: accountAddress,
317
328
  entryPoint: entryPointAddress,
@@ -0,0 +1,21 @@
1
+ import { getEntryPointVersion } from "permissionless"
2
+ import type { EntryPoint } from "permissionless/types"
3
+ import { keccak256, toHex } from "viem"
4
+
5
+ const hashAndTruncate = (input: string, byteSize: number): bigint => {
6
+ const hash = keccak256(toHex(input))
7
+ const truncatedHash = hash.substring(2, byteSize * 2 + 2) // 2 hex characters per byte
8
+ return BigInt(`0x${truncatedHash}`)
9
+ }
10
+
11
+ export const getCustomNonceKeyFromString = (
12
+ input: string,
13
+ entryPoint: EntryPoint
14
+ ) => {
15
+ const entryPointVersion = getEntryPointVersion(entryPoint)
16
+
17
+ if (entryPointVersion === "v0.6") {
18
+ return hashAndTruncate(input, 24) // 24 bytes for v0.6
19
+ }
20
+ return hashAndTruncate(input, 2) // 2 bytes for v0.7
21
+ }
@@ -10,3 +10,5 @@ export const parseFactoryAddressAndCallDataFromAccountInitCode = (
10
10
  const factoryCalldata = `0x${initCode.substring(42)}` as Hex
11
11
  return [factoryAddress, factoryCalldata]
12
12
  }
13
+
14
+ export { getCustomNonceKeyFromString } from "./getCustomNonceKeyFromString.js"