@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.
- package/_cjs/accounts/kernel/createKernelAccount.js +7 -12
- package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +22 -0
- package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -0
- package/_cjs/accounts/kernel/utils/common/getActionSelector.js +19 -0
- package/_cjs/accounts/kernel/utils/common/getActionSelector.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js +22 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js +39 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js +19 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +44 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +20 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -0
- package/_cjs/accounts/kernel/v1/createKernelV1Account.js +4 -2
- package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
- package/_cjs/accounts/kernel/v2/createKernelV2Account.js +9 -4
- package/_cjs/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
- package/_cjs/accounts/utils/toKernelPluginManager.js +100 -182
- package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_cjs/types/kernel.js.map +1 -1
- package/_esm/accounts/kernel/createKernelAccount.js +7 -12
- package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +18 -0
- package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -0
- package/_esm/accounts/kernel/utils/common/getActionSelector.js +15 -0
- package/_esm/accounts/kernel/utils/common/getActionSelector.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js +18 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js +35 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js +15 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +40 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +16 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -0
- package/_esm/accounts/kernel/v1/createKernelV1Account.js +5 -3
- package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
- package/_esm/accounts/kernel/v2/createKernelV2Account.js +10 -5
- package/_esm/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
- package/_esm/accounts/utils/toKernelPluginManager.js +105 -186
- package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_esm/types/kernel.js.map +1 -1
- package/_types/accounts/kernel/createKernelAccount.d.ts +2 -1
- package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
- package/_types/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.d.ts +3 -0
- package/_types/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/common/getActionSelector.d.ts +4 -0
- package/_types/accounts/kernel/utils/common/getActionSelector.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.d.ts +9 -0
- package/_types/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.d.ts +13 -0
- package/_types/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.d.ts +9 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.d.ts +10 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.d.ts +3 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.d.ts.map +1 -0
- package/_types/accounts/kernel/v1/createKernelV1Account.d.ts +1 -1
- package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
- package/_types/accounts/kernel/v2/createKernelV2Account.d.ts +3 -1
- package/_types/accounts/kernel/v2/createKernelV2Account.d.ts.map +1 -1
- package/_types/accounts/utils/toKernelPluginManager.d.ts +1 -1
- package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
- package/_types/types/index.d.ts +1 -1
- package/_types/types/index.d.ts.map +1 -1
- package/_types/types/kernel.d.ts +11 -17
- package/_types/types/kernel.d.ts.map +1 -1
- package/accounts/kernel/createKernelAccount.ts +12 -14
- package/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.ts +24 -0
- package/accounts/kernel/utils/common/getActionSelector.ts +20 -0
- package/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.ts +39 -0
- package/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.ts +76 -0
- package/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.ts +44 -0
- package/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.ts +61 -0
- package/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.ts +23 -0
- package/accounts/kernel/v1/createKernelV1Account.ts +20 -8
- package/accounts/kernel/v2/createKernelV2Account.ts +17 -6
- package/accounts/utils/toKernelPluginManager.ts +129 -222
- package/package.json +4 -4
- package/types/index.ts +1 -1
- package/types/kernel.ts +29 -38
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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 {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
|
|
76
|
+
userOpSignature: Hex = "0x"
|
|
71
77
|
): Promise<Hex> => {
|
|
72
78
|
if (entryPointVersion === "v0.6") {
|
|
73
79
|
if (regular) {
|
|
74
|
-
if (await
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
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
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
|
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
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)
|
|
150
|
-
|
|
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
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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 (
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
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.
|
|
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
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 =
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
128
|
+
getAction(): Action
|
|
138
129
|
getValidityData(): PluginValidityData
|
|
139
|
-
|
|
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
|
-
|
|
138
|
+
action?: Action
|
|
148
139
|
entryPoint: entryPoint
|
|
149
140
|
kernelVersion?: string
|
|
150
141
|
} & Partial<PluginValidityData>
|
|
151
142
|
|
|
152
|
-
export type
|
|
153
|
-
|
|
143
|
+
export type Action = {
|
|
144
|
+
address: Address
|
|
154
145
|
selector: Hex
|
|
155
146
|
}
|
|
156
147
|
|