@zerodev/sdk 5.2.0-alpha-4 → 5.2.1-alpha-1

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 (86) hide show
  1. package/_cjs/accounts/kernel/createKernelAccount.js +7 -12
  2. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  3. package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +22 -0
  4. package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -0
  5. package/_cjs/accounts/kernel/utils/common/getActionSelector.js +19 -0
  6. package/_cjs/accounts/kernel/utils/common/getActionSelector.js.map +1 -0
  7. package/_cjs/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js +22 -0
  8. package/_cjs/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js.map +1 -0
  9. package/_cjs/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js +39 -0
  10. package/_cjs/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -0
  11. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js +19 -0
  12. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js.map +1 -0
  13. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +44 -0
  14. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -0
  15. package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +20 -0
  16. package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -0
  17. package/_cjs/accounts/kernel/v1/createKernelV1Account.js +4 -2
  18. package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  19. package/_cjs/accounts/kernel/v2/createKernelV2Account.js +9 -4
  20. package/_cjs/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
  21. package/_cjs/accounts/utils/toKernelPluginManager.js +100 -182
  22. package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
  23. package/_cjs/types/kernel.js.map +1 -1
  24. package/_esm/accounts/kernel/createKernelAccount.js +7 -12
  25. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  26. package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +18 -0
  27. package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -0
  28. package/_esm/accounts/kernel/utils/common/getActionSelector.js +15 -0
  29. package/_esm/accounts/kernel/utils/common/getActionSelector.js.map +1 -0
  30. package/_esm/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js +18 -0
  31. package/_esm/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js.map +1 -0
  32. package/_esm/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js +35 -0
  33. package/_esm/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -0
  34. package/_esm/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js +15 -0
  35. package/_esm/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js.map +1 -0
  36. package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +40 -0
  37. package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -0
  38. package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +16 -0
  39. package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -0
  40. package/_esm/accounts/kernel/v1/createKernelV1Account.js +5 -3
  41. package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  42. package/_esm/accounts/kernel/v2/createKernelV2Account.js +10 -5
  43. package/_esm/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
  44. package/_esm/accounts/utils/toKernelPluginManager.js +105 -186
  45. package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
  46. package/_esm/types/kernel.js.map +1 -1
  47. package/_types/accounts/kernel/createKernelAccount.d.ts +2 -1
  48. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  49. package/_types/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.d.ts +3 -0
  50. package/_types/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.d.ts.map +1 -0
  51. package/_types/accounts/kernel/utils/common/getActionSelector.d.ts +4 -0
  52. package/_types/accounts/kernel/utils/common/getActionSelector.d.ts.map +1 -0
  53. package/_types/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.d.ts +9 -0
  54. package/_types/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.d.ts.map +1 -0
  55. package/_types/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.d.ts +13 -0
  56. package/_types/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.d.ts.map +1 -0
  57. package/_types/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.d.ts +9 -0
  58. package/_types/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.d.ts.map +1 -0
  59. package/_types/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.d.ts +10 -0
  60. package/_types/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.d.ts.map +1 -0
  61. package/_types/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.d.ts +3 -0
  62. package/_types/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.d.ts.map +1 -0
  63. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts +1 -1
  64. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
  65. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts +3 -1
  66. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts.map +1 -1
  67. package/_types/accounts/utils/toKernelPluginManager.d.ts +1 -1
  68. package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
  69. package/_types/types/index.d.ts +1 -1
  70. package/_types/types/index.d.ts.map +1 -1
  71. package/_types/types/kernel.d.ts +11 -17
  72. package/_types/types/kernel.d.ts.map +1 -1
  73. package/accounts/kernel/createKernelAccount.ts +12 -14
  74. package/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.ts +24 -0
  75. package/accounts/kernel/utils/common/getActionSelector.ts +20 -0
  76. package/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.ts +39 -0
  77. package/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.ts +76 -0
  78. package/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.ts +44 -0
  79. package/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.ts +61 -0
  80. package/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.ts +23 -0
  81. package/accounts/kernel/v1/createKernelV1Account.ts +20 -8
  82. package/accounts/kernel/v2/createKernelV2Account.ts +17 -6
  83. package/accounts/utils/toKernelPluginManager.ts +129 -222
  84. package/package.json +4 -4
  85. package/types/index.ts +1 -1
  86. package/types/kernel.ts +29 -38
@@ -1,4 +1,4 @@
1
- import { getAction, getEntryPointVersion } from "permissionless"
1
+ import { getEntryPointVersion } from "permissionless"
2
2
  import type { EntryPoint } from "permissionless/types/entrypoint"
3
3
  import {
4
4
  type Address,
@@ -8,25 +8,25 @@ import {
8
8
  type Transport,
9
9
  concat,
10
10
  concatHex,
11
- encodeAbiParameters,
12
- hexToBigInt,
13
11
  pad,
14
- parseAbiParameters,
15
- toFunctionSelector,
16
12
  toHex,
17
13
  zeroAddress
18
14
  } from "viem"
19
- import { getChainId, readContract } from "viem/actions"
15
+ import { getChainId } from "viem/actions"
20
16
  import { VALIDATOR_MODE, VALIDATOR_TYPE } from "../../constants.js"
21
17
  import {
22
18
  type KernelPluginManager,
23
19
  type KernelPluginManagerParams,
24
20
  ValidatorMode
25
21
  } from "../../types/kernel.js"
26
- import { getKernelVersion } from "../../utils.js"
27
- import { KernelV3AccountAbi } from "../kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js"
28
- import { KernelModuleIsInitializedAbi } from "../kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js"
29
- import { getKernelImplementationAddress } from "./6492.js"
22
+ import { getKernelV3Nonce } from "../kernel/utils/account/ep0_7/getKernelV3Nonce.js"
23
+ import { accountMetadata } from "../kernel/utils/common/accountMetadata.js"
24
+ import { getActionSelector } from "../kernel/utils/common/getActionSelector.js"
25
+ import { getEncodedPluginsData as getEncodedPluginsDataV1 } from "../kernel/utils/plugins/ep0_6/getEncodedPluginsData.js"
26
+ import { getPluginsEnableTypedData as getPluginsEnableTypedDataV1 } from "../kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js"
27
+ import { getEncodedPluginsData as getEncodedPluginsDataV2 } from "../kernel/utils/plugins/ep0_7/getEncodedPluginsData.js"
28
+ import { getPluginsEnableTypedData as getPluginsEnableTypedDataV2 } from "../kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js"
29
+ import { isPluginInitialized } from "../kernel/utils/plugins/ep0_7/isPluginInitialized.js"
30
30
 
31
31
  export function isKernelPluginManager<entryPoint extends EntryPoint>(
32
32
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -46,11 +46,9 @@ export async function toKernelPluginManager<
46
46
  regular,
47
47
  pluginEnableSignature,
48
48
  validatorInitData,
49
- executorData = {
50
- executor: zeroAddress,
51
- selector: toFunctionSelector(
52
- "execute(address, uint256, bytes, uint8)"
53
- )
49
+ action = {
50
+ selector: getActionSelector("v0.6"),
51
+ address: zeroAddress
54
52
  },
55
53
  validAfter = 0,
56
54
  validUntil = 0,
@@ -64,36 +62,38 @@ export async function toKernelPluginManager<
64
62
  if (!activeValidator) {
65
63
  throw new Error("One of `sudo` or `regular` validator must be set")
66
64
  }
67
- const getValidatorSignature = async (
65
+ action = {
66
+ selector: action?.selector ?? getActionSelector(entryPointVersion),
67
+ address: action?.address ?? zeroAddress
68
+ }
69
+ if (!action) {
70
+ throw new Error("Executor data must be set")
71
+ }
72
+
73
+ const getSignatureData = async (
68
74
  accountAddress: Address,
69
75
  selector: Hex,
70
- sig?: Hex
76
+ userOpSignature: Hex = "0x"
71
77
  ): Promise<Hex> => {
72
78
  if (entryPointVersion === "v0.6") {
73
79
  if (regular) {
74
- if (await regular.isEnabled(accountAddress, selector)) {
80
+ if (await isPluginEnabled(accountAddress, selector)) {
75
81
  return ValidatorMode.plugin
76
82
  }
77
83
 
78
84
  const enableSignature =
79
85
  await getPluginEnableSignature(accountAddress)
80
- const enableData = await regular.getEnableData(accountAddress)
81
- const enableDataLength = enableData.length / 2 - 1
82
86
  if (!enableSignature) {
83
87
  throw new Error("Enable signature not set")
84
88
  }
85
-
86
- return concat([
87
- ValidatorMode.enable,
88
- pad(toHex(validUntil), { size: 6 }), // 6 bytes 4 - 10
89
- pad(toHex(validAfter), { size: 6 }), // 6 bytes 10 - 16
90
- pad(regular.address, { size: 20 }), // 20 bytes 16 - 36
91
- pad(executorData.executor, { size: 20 }), // 20 bytes 36 - 56
92
- pad(toHex(enableDataLength), { size: 32 }), // 32 bytes 56 - 88
93
- enableData, // 88 - 88 + enableData.length
94
- pad(toHex(enableSignature.length / 2 - 1), { size: 32 }), // 32 bytes 88 + enableData.length - 120 + enableData.length
95
- enableSignature // 120 + enableData.length - 120 + enableData.length + enableSignature.length
96
- ])
89
+ return getEncodedPluginsDataV1({
90
+ accountAddress,
91
+ enableSignature,
92
+ action,
93
+ validator: regular,
94
+ validUntil,
95
+ validAfter
96
+ })
97
97
  } else if (sudo) {
98
98
  return ValidatorMode.sudo
99
99
  } else {
@@ -103,57 +103,34 @@ export async function toKernelPluginManager<
103
103
  }
104
104
  }
105
105
  if (regular) {
106
- if (
107
- (await isPluginInitialized_7579(accountAddress)) ||
108
- (await regular.isEnabled(accountAddress, selector))
109
- ) {
110
- return sig ?? "0x"
106
+ if (await isPluginEnabled(accountAddress, action.selector)) {
107
+ return userOpSignature
111
108
  }
112
- const enableData = await regular.getEnableData(accountAddress)
113
109
  const enableSignature =
114
110
  await getPluginEnableSignature(accountAddress)
115
- return concat([
116
- zeroAddress, // hook address 20 bytes
117
- encodeAbiParameters(
118
- parseAbiParameters(
119
- "bytes validatorData, bytes hookData, bytes selectorData, bytes enableSig, bytes userOpSig"
120
- ),
121
- [
122
- enableData,
123
- "0x",
124
- concat([
125
- executorData.selector,
126
- executorData.executor,
127
- zeroAddress,
128
- "0x"
129
- ]),
130
- enableSignature,
131
- sig ?? "0x"
132
- ]
133
- )
134
- ])
111
+ return getEncodedPluginsDataV2({
112
+ accountAddress,
113
+ action,
114
+ enableSignature,
115
+ userOpSignature,
116
+ validator: regular
117
+ })
135
118
  } else if (sudo) {
136
- return sig ?? "0x"
119
+ return userOpSignature
137
120
  } else {
138
121
  throw new Error("One of `sudo` or `regular` validator must be set")
139
122
  }
140
123
  }
141
124
 
142
- const isPluginInitialized_7579 = async (
143
- accountAddress: Address
144
- ): Promise<boolean> => {
145
- try {
146
- return await getAction(
147
- client,
148
- readContract
149
- )({
150
- abi: KernelModuleIsInitializedAbi,
151
- address: activeValidator.address,
152
- functionName: "isInitialized",
153
- args: [accountAddress]
154
- })
155
- } catch (error) {}
156
- return false
125
+ const isPluginEnabled = async (accountAddress: Address, selector: Hex) => {
126
+ if (!regular) throw new Error("regular validator not set")
127
+ if (entryPointVersion === "v0.6") {
128
+ return regular.isEnabled(accountAddress, selector)
129
+ }
130
+ return (
131
+ (await regular.isEnabled(accountAddress, action.selector)) ||
132
+ (await isPluginInitialized(client, accountAddress, regular.address))
133
+ )
157
134
  }
158
135
 
159
136
  const getPluginEnableSignature = async (accountAddress: Address) => {
@@ -164,153 +141,69 @@ export async function toKernelPluginManager<
164
141
  )
165
142
  if (!regular) throw new Error("regular validator not set")
166
143
 
167
- const kernelImplAddr = await getKernelImplementationAddress(
144
+ const { version } = await accountMetadata(
168
145
  client,
169
- accountAddress
146
+ accountAddress,
147
+ entryPointAddress
170
148
  )
171
- const _kernelVersion =
172
- kernelVersion ?? getKernelVersion(entryPointAddress, kernelImplAddr)
173
149
  let ownerSig: Hex
174
150
  if (entryPointVersion === "v0.6") {
175
- ownerSig = await sudo.signTypedData({
176
- domain: {
177
- name: "Kernel",
178
- version: _kernelVersion,
179
- chainId,
180
- verifyingContract: accountAddress
181
- },
182
- types: {
183
- ValidatorApproved: [
184
- { name: "sig", type: "bytes4" },
185
- { name: "validatorData", type: "uint256" },
186
- { name: "executor", type: "address" },
187
- { name: "enableData", type: "bytes" }
188
- ]
189
- },
190
- message: {
191
- sig: executorData.selector,
192
- validatorData: hexToBigInt(
193
- concatHex([
194
- pad(toHex(validUntil ?? 0), {
195
- size: 6
196
- }),
197
- pad(toHex(validAfter ?? 0), {
198
- size: 6
199
- }),
200
- regular.address
201
- ]),
202
- { size: 32 }
203
- ),
204
- executor: executorData.executor as Address,
205
- enableData: await regular.getEnableData(accountAddress)
206
- },
207
- primaryType: "ValidatorApproved"
151
+ const typeData = await getPluginsEnableTypedDataV1({
152
+ accountAddress,
153
+ chainId,
154
+ kernelVersion: version ?? kernelVersion,
155
+ action,
156
+ validator: regular,
157
+ validUntil,
158
+ validAfter
208
159
  })
160
+ ownerSig = await sudo.signTypedData(typeData)
209
161
  pluginEnableSignature = ownerSig
210
162
  return ownerSig
211
163
  }
212
- ownerSig = await sudo.signTypedData({
213
- domain: {
214
- name: "Kernel",
215
- version: _kernelVersion,
216
- chainId,
217
- verifyingContract: accountAddress
218
- },
219
- types: {
220
- Enable: [
221
- { name: "validationId", type: "bytes21" },
222
- { name: "nonce", type: "uint32" },
223
- { name: "hook", type: "address" },
224
- { name: "validatorData", type: "bytes" },
225
- { name: "hookData", type: "bytes" },
226
- { name: "selectorData", type: "bytes" }
227
- ]
228
- },
229
- message: {
230
- validationId: concat([
231
- activeValidator.isPermissionValidator
232
- ? VALIDATOR_TYPE.PERMISSION
233
- : VALIDATOR_TYPE.SECONDARY,
234
- activeValidator?.isPermissionValidator
235
- ? // @ts-ignore
236
- pad(regular.getPermissionId() as Hex, {
237
- size: 20,
238
- dir: "right"
239
- })
240
- : activeValidator.address
241
- ]),
242
- nonce: await getKernelV3Nonce(accountAddress),
243
- hook: zeroAddress,
244
- validatorData: await regular.getEnableData(accountAddress),
245
- hookData: "0x",
246
- selectorData: concat([
247
- executorData.selector,
248
- executorData.executor,
249
- zeroAddress,
250
- "0x"
251
- ])
252
- },
253
- primaryType: "Enable"
164
+ const validatorNonce = await getKernelV3Nonce(client, accountAddress)
165
+ const typedData = await getPluginsEnableTypedDataV2({
166
+ accountAddress,
167
+ chainId,
168
+ kernelVersion: version,
169
+ action,
170
+ validator: regular,
171
+ validatorNonce
254
172
  })
173
+ ownerSig = await sudo.signTypedData(typedData)
255
174
 
256
175
  return ownerSig
257
176
  }
258
-
259
- const getKernelV3Nonce = async (
260
- accountAddress: Address
261
- ): Promise<number> => {
262
- try {
263
- const nonce = await getAction(
264
- client,
265
- readContract
266
- )({
267
- abi: KernelV3AccountAbi,
268
- address: accountAddress,
269
- functionName: "currentNonce",
270
- args: []
271
- })
272
- return nonce
273
- } catch (error) {
274
- return 2
275
- }
177
+ const getIdentifier = (isSudo = false) => {
178
+ const validator = (isSudo ? sudo : regular) ?? activeValidator
179
+ return concat([
180
+ VALIDATOR_TYPE[validator.validatorType],
181
+ validator.getIdentifier()
182
+ ])
276
183
  }
277
184
 
278
185
  return {
279
186
  ...activeValidator,
280
- getValidationId: (isSudo = false) => {
281
- const validator = (isSudo ? sudo : regular) ?? activeValidator
282
- return concat([
283
- validator.isPermissionValidator
284
- ? VALIDATOR_TYPE.PERMISSION
285
- : VALIDATOR_TYPE.SECONDARY,
286
- validator?.isPermissionValidator
287
- ? // @ts-ignore
288
- pad(validator.getPermissionId() as Hex, {
289
- size: 20,
290
- dir: "right"
291
- })
292
- : validator.address
293
- ])
294
- },
187
+ getIdentifier,
295
188
  signUserOperation: async (userOperation) => {
296
189
  const userOpSig =
297
190
  await activeValidator.signUserOperation(userOperation)
298
191
  if (entryPointVersion === "v0.6") {
299
192
  return concatHex([
300
- await getValidatorSignature(
193
+ await getSignatureData(
301
194
  userOperation.sender,
302
195
  userOperation.callData.toString().slice(0, 10) as Hex
303
196
  ),
304
197
  userOpSig
305
198
  ])
306
199
  }
307
- return await getValidatorSignature(
200
+ return await getSignatureData(
308
201
  userOperation.sender,
309
202
  userOperation.callData.toString().slice(0, 10) as Hex,
310
203
  userOpSig
311
204
  )
312
205
  },
313
- getExecutorData: () => executorData,
206
+ getAction: () => action,
314
207
  getValidityData: () => ({
315
208
  validAfter,
316
209
  validUntil
@@ -320,53 +213,65 @@ export async function toKernelPluginManager<
320
213
  await activeValidator.getDummySignature(userOperation)
321
214
  if (entryPointVersion === "v0.6") {
322
215
  return concatHex([
323
- await getValidatorSignature(
216
+ await getSignatureData(
324
217
  userOperation.sender,
325
218
  userOperation.callData.toString().slice(0, 10) as Hex
326
219
  ),
327
220
  userOpSig
328
221
  ])
329
222
  }
330
- return await getValidatorSignature(
223
+ return await getSignatureData(
331
224
  userOperation.sender,
332
225
  userOperation.callData.toString().slice(0, 10) as Hex,
333
226
  userOpSig
334
227
  )
335
228
  },
336
- getNonceKey: async (accountAddress = zeroAddress) => {
229
+ getNonceKey: async (
230
+ accountAddress = zeroAddress,
231
+ customNonceKey = 0n
232
+ ) => {
337
233
  if (entryPointVersion === "v0.6")
338
- return await activeValidator.getNonceKey()
234
+ return await activeValidator.getNonceKey(
235
+ accountAddress,
236
+ customNonceKey
237
+ )
238
+
239
+ // when using v0.7 if customNonceKey is greater than 2 bytes, throw error
240
+ if (customNonceKey > 0xffffn)
241
+ throw new Error("Custom nonce key must be less than 2 bytes")
339
242
 
340
- return BigInt(
341
- pad(
342
- concatHex([
343
- !regular ||
344
- (await regular.isEnabled(
345
- accountAddress,
346
- executorData.selector
347
- )) ||
348
- (await isPluginInitialized_7579(accountAddress))
349
- ? VALIDATOR_MODE.DEFAULT
350
- : VALIDATOR_MODE.ENABLE, // 1 byte
351
- regular
352
- ? regular.isPermissionValidator
353
- ? VALIDATOR_TYPE.PERMISSION
354
- : VALIDATOR_TYPE.SECONDARY
355
- : VALIDATOR_TYPE.SUDO, // 1 byte
356
- regular?.isPermissionValidator
357
- ? // @ts-ignore
358
- pad(regular.getPermissionId(), {
359
- size: 20,
360
- dir: "right"
361
- })
362
- : activeValidator.address, // 20 bytes
363
- pad(toHex(await activeValidator.getNonceKey()), {
243
+ const validatorMode =
244
+ !regular ||
245
+ (await isPluginEnabled(accountAddress, action.selector))
246
+ ? VALIDATOR_MODE.DEFAULT
247
+ : VALIDATOR_MODE.ENABLE
248
+ const validatorType = regular
249
+ ? VALIDATOR_TYPE[regular.validatorType]
250
+ : VALIDATOR_TYPE.SUDO
251
+ const encoding = pad(
252
+ concatHex([
253
+ validatorMode, // 1 byte
254
+ validatorType, // 1 byte
255
+ pad(activeValidator.getIdentifier(), {
256
+ size: 20,
257
+ dir: "right"
258
+ }), // 20 bytes
259
+ pad(
260
+ toHex(
261
+ await activeValidator.getNonceKey(
262
+ accountAddress,
263
+ customNonceKey
264
+ )
265
+ ),
266
+ {
364
267
  size: 2
365
- }) // 10 byte
366
- ]),
367
- { size: 24 }
368
- )
268
+ }
269
+ ) // 2 byte
270
+ ]),
271
+ { size: 24 }
369
272
  )
273
+ const encodedNonceKey = BigInt(encoding)
274
+ return encodedNonceKey
370
275
  },
371
276
  getPluginEnableSignature,
372
277
  getValidatorInitData: async () => {
@@ -376,7 +281,9 @@ export async function toKernelPluginManager<
376
281
 
377
282
  enableData:
378
283
  (await sudo?.getEnableData()) ??
379
- (await activeValidator.getEnableData())
284
+ (await activeValidator.getEnableData()),
285
+
286
+ identifier: pad(getIdentifier(true), { size: 21, dir: "right" })
380
287
  }
381
288
  }
382
289
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/sdk",
3
- "version": "5.2.0-alpha-4",
3
+ "version": "5.2.1-alpha-1",
4
4
  "author": "ZeroDev",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
@@ -90,10 +90,10 @@
90
90
  }
91
91
  },
92
92
  "peerDependencies": {
93
- "viem": "^2.0.0"
93
+ "viem": "^2.0.0",
94
+ "permissionless": "^0.1.4"
94
95
  },
95
96
  "dependencies": {
96
- "semver": "^7.6.0",
97
- "permissionless": "^0.1.4"
97
+ "semver": "^7.6.0"
98
98
  }
99
99
  }
package/types/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type {
2
2
  KernelValidator,
3
3
  ZeroDevPaymasterRpcSchema,
4
- ExecutorData,
4
+ Action,
5
5
  KernelPluginManager,
6
6
  ValidatorInitData,
7
7
  CallType,
package/types/kernel.ts CHANGED
@@ -88,55 +88,46 @@ export type ZeroDevPaymasterRpcSchema<entryPoint extends EntryPoint> = [
88
88
  }
89
89
  ]
90
90
 
91
- export type ValidatorType = keyof typeof VALIDATOR_TYPE
91
+ export type ValidatorType = Extract<
92
+ keyof typeof VALIDATOR_TYPE,
93
+ "PERMISSION" | "SECONDARY"
94
+ >
92
95
 
93
96
  export type KernelValidator<
94
97
  entryPoint extends EntryPoint,
95
- Name extends string = string,
96
- type extends ValidatorType = "SUDO"
97
- > = type extends "PERMISSION"
98
- ? LocalAccount<Name> & {
99
- getNonceKey: (accountAddress?: Address) => Promise<bigint>
100
- getDummySignature(
101
- userOperation: UserOperation<GetEntryPointVersion<entryPoint>>,
102
- pluginEnableSignature?: Hex
103
- ): Promise<Hex>
104
- signUserOperation: (
105
- userOperation: UserOperation<GetEntryPointVersion<entryPoint>>,
106
- pluginEnableSignature?: Hex
107
- ) => Promise<Hex>
108
- getEnableData(accountAddress?: Address): Promise<Hex>
109
- isEnabled(accountAddress: Address, selector: Hex): Promise<boolean>
110
- isPermissionValidator: boolean
111
- getPermissionId: () => Hex
112
- }
113
- : LocalAccount<Name> & {
114
- getNonceKey: (accountAddress?: Address) => Promise<bigint>
115
- getDummySignature(
116
- userOperation: UserOperation<GetEntryPointVersion<entryPoint>>,
117
- pluginEnableSignature?: Hex
118
- ): Promise<Hex>
119
- signUserOperation: (
120
- userOperation: UserOperation<GetEntryPointVersion<entryPoint>>,
121
- pluginEnableSignature?: Hex
122
- ) => Promise<Hex>
123
- getEnableData(accountAddress?: Address): Promise<Hex>
124
- isEnabled(accountAddress: Address, selector: Hex): Promise<boolean>
125
- isPermissionValidator: boolean
126
- }
98
+ Name extends string = string
99
+ > = LocalAccount<Name> & {
100
+ validatorType: ValidatorType
101
+ getNonceKey: (
102
+ accountAddress?: Address,
103
+ customNonceKey?: bigint
104
+ ) => Promise<bigint>
105
+ getDummySignature(
106
+ userOperation: UserOperation<GetEntryPointVersion<entryPoint>>,
107
+ pluginEnableSignature?: Hex
108
+ ): Promise<Hex>
109
+ signUserOperation: (
110
+ userOperation: UserOperation<GetEntryPointVersion<entryPoint>>,
111
+ pluginEnableSignature?: Hex
112
+ ) => Promise<Hex>
113
+ getEnableData(accountAddress?: Address): Promise<Hex>
114
+ isEnabled(accountAddress: Address, selector: Hex): Promise<boolean>
115
+ getIdentifier: () => Hex
116
+ }
127
117
 
128
118
  export type ValidatorInitData = {
129
119
  validatorAddress: Address
130
120
  enableData: Hex
121
+ identifier: Hex
131
122
  }
132
123
 
133
124
  export type KernelPluginManager<entryPoint extends EntryPoint> =
134
125
  KernelValidator<entryPoint> & {
135
126
  getPluginEnableSignature(accountAddress: Address): Promise<Hex>
136
127
  getValidatorInitData(): Promise<ValidatorInitData>
137
- getExecutorData(): ExecutorData
128
+ getAction(): Action
138
129
  getValidityData(): PluginValidityData
139
- getValidationId(isSudo?: boolean): Hex
130
+ getIdentifier(isSudo?: boolean): Hex
140
131
  }
141
132
 
142
133
  export type KernelPluginManagerParams<entryPoint extends EntryPoint> = {
@@ -144,13 +135,13 @@ export type KernelPluginManagerParams<entryPoint extends EntryPoint> = {
144
135
  regular?: KernelValidator<entryPoint>
145
136
  pluginEnableSignature?: Hex
146
137
  validatorInitData?: ValidatorInitData
147
- executorData?: ExecutorData
138
+ action?: Action
148
139
  entryPoint: entryPoint
149
140
  kernelVersion?: string
150
141
  } & Partial<PluginValidityData>
151
142
 
152
- export type ExecutorData = {
153
- executor: Address
143
+ export type Action = {
144
+ address: Address
154
145
  selector: Hex
155
146
  }
156
147