@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
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ENTRYPOINT_ADDRESS_V06_TYPE,
|
|
3
|
+
EntryPoint
|
|
4
|
+
} from "permissionless/types/entrypoint"
|
|
5
|
+
import {
|
|
6
|
+
type Address,
|
|
7
|
+
type Hex,
|
|
8
|
+
concat,
|
|
9
|
+
encodeAbiParameters,
|
|
10
|
+
parseAbiParameters,
|
|
11
|
+
zeroAddress
|
|
12
|
+
} from "viem"
|
|
13
|
+
import type { Kernel2_0_plugins } from "../ep0_6/getPluginsEnableTypedData.js"
|
|
14
|
+
|
|
15
|
+
export const getEncodedPluginsData = async <
|
|
16
|
+
entryPoint extends EntryPoint = ENTRYPOINT_ADDRESS_V06_TYPE
|
|
17
|
+
>({
|
|
18
|
+
accountAddress,
|
|
19
|
+
enableSignature,
|
|
20
|
+
userOpSignature,
|
|
21
|
+
action,
|
|
22
|
+
validator
|
|
23
|
+
}: {
|
|
24
|
+
accountAddress: Address
|
|
25
|
+
enableSignature: Hex
|
|
26
|
+
userOpSignature: Hex
|
|
27
|
+
} & Kernel2_0_plugins<entryPoint>) => {
|
|
28
|
+
const enableData = await validator.getEnableData(accountAddress)
|
|
29
|
+
return concat([
|
|
30
|
+
zeroAddress, // hook address 20 bytes
|
|
31
|
+
encodeAbiParameters(
|
|
32
|
+
parseAbiParameters(
|
|
33
|
+
"bytes validatorData, bytes hookData, bytes selectorData, bytes enableSig, bytes userOpSig"
|
|
34
|
+
),
|
|
35
|
+
[
|
|
36
|
+
enableData,
|
|
37
|
+
"0x",
|
|
38
|
+
concat([action.selector, action.address, zeroAddress, "0x"]),
|
|
39
|
+
enableSignature,
|
|
40
|
+
userOpSignature
|
|
41
|
+
]
|
|
42
|
+
)
|
|
43
|
+
])
|
|
44
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ENTRYPOINT_ADDRESS_V07_TYPE,
|
|
3
|
+
EntryPoint
|
|
4
|
+
} from "permissionless/types/entrypoint"
|
|
5
|
+
import { type Address, type CustomSource, concat, pad, zeroAddress } from "viem"
|
|
6
|
+
import { VALIDATOR_TYPE } from "../../../../../constants.js"
|
|
7
|
+
import type { Kernel2_0_plugins } from "../ep0_6/getPluginsEnableTypedData.js"
|
|
8
|
+
|
|
9
|
+
export const getPluginsEnableTypedData = async <
|
|
10
|
+
entryPoint extends EntryPoint = ENTRYPOINT_ADDRESS_V07_TYPE
|
|
11
|
+
>({
|
|
12
|
+
accountAddress,
|
|
13
|
+
chainId,
|
|
14
|
+
kernelVersion,
|
|
15
|
+
action,
|
|
16
|
+
validator,
|
|
17
|
+
validatorNonce
|
|
18
|
+
}: {
|
|
19
|
+
accountAddress: Address
|
|
20
|
+
chainId: number
|
|
21
|
+
kernelVersion: string
|
|
22
|
+
validatorNonce: number
|
|
23
|
+
} & Kernel2_0_plugins<entryPoint>): Promise<
|
|
24
|
+
Parameters<CustomSource["signTypedData"]>[0]
|
|
25
|
+
> => {
|
|
26
|
+
return {
|
|
27
|
+
domain: {
|
|
28
|
+
name: "Kernel",
|
|
29
|
+
version: kernelVersion,
|
|
30
|
+
chainId,
|
|
31
|
+
verifyingContract: accountAddress
|
|
32
|
+
},
|
|
33
|
+
types: {
|
|
34
|
+
Enable: [
|
|
35
|
+
{ name: "validationId", type: "bytes21" },
|
|
36
|
+
{ name: "nonce", type: "uint32" },
|
|
37
|
+
{ name: "hook", type: "address" },
|
|
38
|
+
{ name: "validatorData", type: "bytes" },
|
|
39
|
+
{ name: "hookData", type: "bytes" },
|
|
40
|
+
{ name: "selectorData", type: "bytes" }
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
message: {
|
|
44
|
+
validationId: concat([
|
|
45
|
+
VALIDATOR_TYPE[validator.validatorType],
|
|
46
|
+
pad(validator.getIdentifier(), { size: 20, dir: "right" })
|
|
47
|
+
]),
|
|
48
|
+
nonce: validatorNonce,
|
|
49
|
+
hook: zeroAddress,
|
|
50
|
+
validatorData: await validator.getEnableData(accountAddress),
|
|
51
|
+
hookData: "0x",
|
|
52
|
+
selectorData: concat([
|
|
53
|
+
action.selector,
|
|
54
|
+
action.address,
|
|
55
|
+
zeroAddress,
|
|
56
|
+
"0x"
|
|
57
|
+
])
|
|
58
|
+
},
|
|
59
|
+
primaryType: "Enable"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -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 {
|
|
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
|
|
103
|
+
entrypoint: entryPointAddress,
|
|
100
104
|
index = 0n
|
|
101
105
|
}: {
|
|
102
106
|
signer: SmartAccountSigner<TSource, TAddress>
|
|
103
|
-
entrypoint
|
|
107
|
+
entrypoint: entryPoint
|
|
104
108
|
index?: bigint
|
|
105
109
|
}
|
|
106
110
|
): Promise<KernelV1SmartAccount<entryPoint, TTransport, TChain>> {
|
|
107
|
-
|
|
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(
|
|
134
|
-
|
|
135
|
-
|
|
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
|
|
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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,
|