@zerodev/sdk 5.2.0-alpha-3 → 5.2.1-alpha-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.
- package/_cjs/accounts/kernel/createKernelAccount.js +6 -10
- 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 +1 -0
- package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
- package/_cjs/accounts/kernel/v2/createKernelV2Account.js +2 -1
- package/_cjs/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
- package/_cjs/accounts/utils/toKernelPluginManager.js +88 -177
- package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_cjs/types/kernel.js.map +1 -1
- package/_esm/accounts/kernel/createKernelAccount.js +6 -10
- 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 +1 -0
- package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
- package/_esm/accounts/kernel/v2/createKernelV2Account.js +2 -1
- package/_esm/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
- package/_esm/accounts/utils/toKernelPluginManager.js +92 -181
- package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_esm/types/kernel.js.map +1 -1
- package/_types/accounts/kernel/createKernelAccount.d.ts +1 -0
- 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.map +1 -1
- package/_types/accounts/kernel/v2/createKernelV2Account.d.ts +1 -0
- 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 +10 -16
- package/_types/types/kernel.d.ts.map +1 -1
- package/accounts/kernel/createKernelAccount.ts +7 -10
- 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 +1 -0
- package/accounts/kernel/v2/createKernelV2Account.ts +3 -1
- package/accounts/utils/toKernelPluginManager.ts +99 -213
- package/package.json +4 -4
- package/types/index.ts +1 -1
- package/types/kernel.ts +26 -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,14 +213,14 @@ 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
|
|
@@ -337,32 +230,23 @@ export async function toKernelPluginManager<
|
|
|
337
230
|
if (entryPointVersion === "v0.6")
|
|
338
231
|
return await activeValidator.getNonceKey()
|
|
339
232
|
|
|
233
|
+
const validatorMode =
|
|
234
|
+
!regular ||
|
|
235
|
+
(await isPluginEnabled(accountAddress, action.selector))
|
|
236
|
+
? VALIDATOR_MODE.DEFAULT
|
|
237
|
+
: VALIDATOR_MODE.ENABLE
|
|
238
|
+
const validatorType = regular
|
|
239
|
+
? VALIDATOR_TYPE[regular.validatorType]
|
|
240
|
+
: VALIDATOR_TYPE.SUDO
|
|
340
241
|
return BigInt(
|
|
341
242
|
pad(
|
|
342
243
|
concatHex([
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
|
244
|
+
validatorMode, // 1 byte
|
|
245
|
+
validatorType, // 1 byte
|
|
246
|
+
activeValidator.getIdentifier(), // 20 bytes
|
|
363
247
|
pad(toHex(await activeValidator.getNonceKey()), {
|
|
364
248
|
size: 2
|
|
365
|
-
}) //
|
|
249
|
+
}) // 2 byte
|
|
366
250
|
]),
|
|
367
251
|
{ size: 24 }
|
|
368
252
|
)
|
|
@@ -376,7 +260,9 @@ export async function toKernelPluginManager<
|
|
|
376
260
|
|
|
377
261
|
enableData:
|
|
378
262
|
(await sudo?.getEnableData()) ??
|
|
379
|
-
(await activeValidator.getEnableData())
|
|
263
|
+
(await activeValidator.getEnableData()),
|
|
264
|
+
|
|
265
|
+
identifier: getIdentifier(true)
|
|
380
266
|
}
|
|
381
267
|
}
|
|
382
268
|
}
|
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-0",
|
|
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,43 @@ 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
|
-
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: (accountAddress?: Address) => Promise<bigint>
|
|
102
|
+
getDummySignature(
|
|
103
|
+
userOperation: UserOperation<GetEntryPointVersion<entryPoint>>,
|
|
104
|
+
pluginEnableSignature?: Hex
|
|
105
|
+
): Promise<Hex>
|
|
106
|
+
signUserOperation: (
|
|
107
|
+
userOperation: UserOperation<GetEntryPointVersion<entryPoint>>,
|
|
108
|
+
pluginEnableSignature?: Hex
|
|
109
|
+
) => Promise<Hex>
|
|
110
|
+
getEnableData(accountAddress?: Address): Promise<Hex>
|
|
111
|
+
isEnabled(accountAddress: Address, selector: Hex): Promise<boolean>
|
|
112
|
+
getIdentifier: () => Hex
|
|
113
|
+
}
|
|
127
114
|
|
|
128
115
|
export type ValidatorInitData = {
|
|
129
116
|
validatorAddress: Address
|
|
130
117
|
enableData: Hex
|
|
118
|
+
identifier: Hex
|
|
131
119
|
}
|
|
132
120
|
|
|
133
121
|
export type KernelPluginManager<entryPoint extends EntryPoint> =
|
|
134
122
|
KernelValidator<entryPoint> & {
|
|
135
123
|
getPluginEnableSignature(accountAddress: Address): Promise<Hex>
|
|
136
124
|
getValidatorInitData(): Promise<ValidatorInitData>
|
|
137
|
-
|
|
125
|
+
getAction(): Action
|
|
138
126
|
getValidityData(): PluginValidityData
|
|
139
|
-
|
|
127
|
+
getIdentifier(isSudo?: boolean): Hex
|
|
140
128
|
}
|
|
141
129
|
|
|
142
130
|
export type KernelPluginManagerParams<entryPoint extends EntryPoint> = {
|
|
@@ -144,13 +132,13 @@ export type KernelPluginManagerParams<entryPoint extends EntryPoint> = {
|
|
|
144
132
|
regular?: KernelValidator<entryPoint>
|
|
145
133
|
pluginEnableSignature?: Hex
|
|
146
134
|
validatorInitData?: ValidatorInitData
|
|
147
|
-
|
|
135
|
+
action?: Action
|
|
148
136
|
entryPoint: entryPoint
|
|
149
137
|
kernelVersion?: string
|
|
150
138
|
} & Partial<PluginValidityData>
|
|
151
139
|
|
|
152
|
-
export type
|
|
153
|
-
|
|
140
|
+
export type Action = {
|
|
141
|
+
address: Address
|
|
154
142
|
selector: Hex
|
|
155
143
|
}
|
|
156
144
|
|