@zerodev/sdk 5.4.35 → 5.4.36
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 +88 -43
- package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_cjs/accounts/kernel/utils/common/accountMetadata.js +1 -6
- package/_cjs/accounts/kernel/utils/common/accountMetadata.js.map +1 -1
- package/_cjs/accounts/utils/signerTo7702Validator.js +66 -0
- package/_cjs/accounts/utils/signerTo7702Validator.js.map +1 -0
- package/_cjs/accounts/utils/toKernelPluginManager.js +1 -1
- package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_cjs/clients/kernelAccountClient.js +29 -0
- package/_cjs/clients/kernelAccountClient.js.map +1 -1
- package/_esm/accounts/kernel/createKernelAccount.js +93 -49
- package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_esm/accounts/kernel/utils/common/accountMetadata.js +1 -6
- package/_esm/accounts/kernel/utils/common/accountMetadata.js.map +1 -1
- package/_esm/accounts/utils/signerTo7702Validator.js +66 -0
- package/_esm/accounts/utils/signerTo7702Validator.js.map +1 -0
- package/_esm/accounts/utils/toKernelPluginManager.js +1 -1
- package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_esm/clients/kernelAccountClient.js +30 -1
- package/_esm/clients/kernelAccountClient.js.map +1 -1
- package/_types/accounts/kernel/createKernelAccount.d.ts +12 -8
- package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
- package/_types/accounts/kernel/utils/common/accountMetadata.d.ts.map +1 -1
- package/_types/accounts/utils/signerTo7702Validator.d.ts +9 -0
- package/_types/accounts/utils/signerTo7702Validator.d.ts.map +1 -0
- package/_types/clients/kernelAccountClient.d.ts.map +1 -1
- package/accounts/kernel/createKernelAccount.ts +145 -68
- package/accounts/kernel/utils/common/accountMetadata.ts +1 -7
- package/accounts/utils/signerTo7702Validator.ts +107 -0
- package/accounts/utils/toKernelPluginManager.ts +1 -1
- package/clients/kernelAccountClient.ts +41 -0
- package/package.json +123 -124
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { satisfies } from "semver"
|
|
1
2
|
import {
|
|
2
|
-
http,
|
|
3
3
|
type Address,
|
|
4
4
|
type Assign,
|
|
5
5
|
type EncodeDeployDataParameters,
|
|
6
6
|
type Hex,
|
|
7
|
+
type LocalAccount,
|
|
7
8
|
type SignableMessage,
|
|
8
9
|
type TypedDataDefinition,
|
|
9
10
|
concatHex,
|
|
10
11
|
createNonceManager,
|
|
11
|
-
createWalletClient,
|
|
12
12
|
encodeFunctionData,
|
|
13
13
|
getTypesForEIP712Domain,
|
|
14
14
|
hashMessage,
|
|
@@ -28,12 +28,16 @@ import {
|
|
|
28
28
|
entryPoint07Address,
|
|
29
29
|
toSmartAccount
|
|
30
30
|
} from "viem/account-abstraction"
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
import type {
|
|
32
|
+
PrivateKeyAccount,
|
|
33
|
+
SignAuthorizationReturnType
|
|
34
34
|
} from "viem/accounts"
|
|
35
|
-
import {
|
|
36
|
-
|
|
35
|
+
import {
|
|
36
|
+
getChainId,
|
|
37
|
+
getCode,
|
|
38
|
+
signAuthorization as signAuthorizationAction
|
|
39
|
+
} from "viem/actions"
|
|
40
|
+
import { getAction, verifyAuthorization } from "viem/utils"
|
|
37
41
|
import {
|
|
38
42
|
getAccountNonce,
|
|
39
43
|
getSenderAddress,
|
|
@@ -50,12 +54,15 @@ import type {
|
|
|
50
54
|
GetKernelVersion,
|
|
51
55
|
KernelPluginManager,
|
|
52
56
|
KernelPluginManagerParams,
|
|
57
|
+
KernelValidator,
|
|
53
58
|
PluginMigrationData
|
|
54
59
|
} from "../../types/kernel.js"
|
|
55
60
|
import type { Signer } from "../../types/utils.js"
|
|
56
61
|
import { KERNEL_FEATURES, hasKernelFeature } from "../../utils.js"
|
|
57
62
|
import { validateKernelVersionWithEntryPoint } from "../../utils.js"
|
|
58
63
|
import { toSigner } from "../../utils/toSigner.js"
|
|
64
|
+
import { addressToEmptyAccount } from "../addressToEmptyAccount.js"
|
|
65
|
+
import { signerTo7702Validator } from "../utils/signerTo7702Validator.js"
|
|
59
66
|
import {
|
|
60
67
|
isKernelPluginManager,
|
|
61
68
|
toKernelPluginManager
|
|
@@ -107,7 +114,9 @@ export type KernelSmartAccountImplementation<
|
|
|
107
114
|
bytecode
|
|
108
115
|
}: EncodeDeployDataParameters) => Promise<Hex>
|
|
109
116
|
signMessage: (parameters: SignMessageParameters) => Promise<Hex>
|
|
110
|
-
|
|
117
|
+
eip7702Authorization?:
|
|
118
|
+
| (() => Promise<SignAuthorizationReturnType | undefined>)
|
|
119
|
+
| undefined
|
|
111
120
|
}
|
|
112
121
|
>
|
|
113
122
|
|
|
@@ -119,12 +128,6 @@ export type CreateKernelAccountParameters<
|
|
|
119
128
|
entryPointVersion extends EntryPointVersion,
|
|
120
129
|
KernelVerion extends GetKernelVersion<entryPointVersion>
|
|
121
130
|
> = {
|
|
122
|
-
plugins:
|
|
123
|
-
| Omit<
|
|
124
|
-
KernelPluginManagerParams<entryPointVersion>,
|
|
125
|
-
"entryPoint" | "kernelVersion"
|
|
126
|
-
>
|
|
127
|
-
| KernelPluginManager<entryPointVersion>
|
|
128
131
|
entryPoint: EntryPointType<entryPointVersion>
|
|
129
132
|
index?: bigint
|
|
130
133
|
factoryAddress?: Address
|
|
@@ -134,11 +137,30 @@ export type CreateKernelAccountParameters<
|
|
|
134
137
|
kernelVersion: GetKernelVersion<entryPointVersion>
|
|
135
138
|
initConfig?: KernelVerion extends "0.3.1" ? Hex[] : never
|
|
136
139
|
useMetaFactory?: boolean
|
|
137
|
-
eip7702?: boolean
|
|
138
|
-
eip7702Auth?: SignAuthorizationReturnType
|
|
139
|
-
eip7702SponsorAccount?: Signer
|
|
140
140
|
pluginMigrations?: PluginMigrationData[]
|
|
141
|
-
}
|
|
141
|
+
} & (
|
|
142
|
+
| {
|
|
143
|
+
eip7702Auth?: SignAuthorizationReturnType | undefined
|
|
144
|
+
eip7702Account: Signer
|
|
145
|
+
plugins?:
|
|
146
|
+
| Omit<
|
|
147
|
+
KernelPluginManagerParams<entryPointVersion>,
|
|
148
|
+
"entryPoint" | "kernelVersion"
|
|
149
|
+
>
|
|
150
|
+
| KernelPluginManager<entryPointVersion>
|
|
151
|
+
| undefined
|
|
152
|
+
}
|
|
153
|
+
| {
|
|
154
|
+
eip7702Auth?: SignAuthorizationReturnType | undefined
|
|
155
|
+
eip7702Account?: Signer | undefined
|
|
156
|
+
plugins:
|
|
157
|
+
| Omit<
|
|
158
|
+
KernelPluginManagerParams<entryPointVersion>,
|
|
159
|
+
"entryPoint" | "kernelVersion"
|
|
160
|
+
>
|
|
161
|
+
| KernelPluginManager<entryPointVersion>
|
|
162
|
+
}
|
|
163
|
+
)
|
|
142
164
|
|
|
143
165
|
/**
|
|
144
166
|
* The account creation ABI for a kernel smart account (from the KernelFactory)
|
|
@@ -383,10 +405,26 @@ export async function createKernelAccount<
|
|
|
383
405
|
initConfig,
|
|
384
406
|
useMetaFactory: _useMetaFactory = true,
|
|
385
407
|
eip7702Auth,
|
|
386
|
-
|
|
408
|
+
eip7702Account,
|
|
387
409
|
pluginMigrations
|
|
388
410
|
}: CreateKernelAccountParameters<entryPointVersion, KernelVersion>
|
|
389
411
|
): Promise<CreateKernelAccountReturnType<entryPointVersion>> {
|
|
412
|
+
const isEip7702 = !!eip7702Account || !!eip7702Auth
|
|
413
|
+
if (isEip7702 && !satisfies(kernelVersion, ">=0.3.3")) {
|
|
414
|
+
throw new Error("EIP-7702 is recommended for kernel version >=0.3.3")
|
|
415
|
+
}
|
|
416
|
+
const localAccount = eip7702Account
|
|
417
|
+
? await toSigner({ signer: eip7702Account, address })
|
|
418
|
+
: undefined
|
|
419
|
+
|
|
420
|
+
let eip7702Validator: KernelValidator<"EIP7702Validator"> | undefined
|
|
421
|
+
if (localAccount) {
|
|
422
|
+
eip7702Validator = await signerTo7702Validator(client, {
|
|
423
|
+
signer: localAccount,
|
|
424
|
+
entryPoint,
|
|
425
|
+
kernelVersion
|
|
426
|
+
})
|
|
427
|
+
}
|
|
390
428
|
let useMetaFactory = _useMetaFactory
|
|
391
429
|
const { accountImplementationAddress, factoryAddress, metaFactoryAddress } =
|
|
392
430
|
getDefaultAddresses(entryPoint.version, kernelVersion, {
|
|
@@ -422,11 +460,11 @@ export async function createKernelAccount<
|
|
|
422
460
|
)
|
|
423
461
|
? plugins
|
|
424
462
|
: await toKernelPluginManager<entryPointVersion>(client, {
|
|
425
|
-
sudo: plugins
|
|
426
|
-
regular: plugins
|
|
427
|
-
hook: plugins
|
|
428
|
-
action: plugins
|
|
429
|
-
pluginEnableSignature: plugins
|
|
463
|
+
sudo: localAccount ? eip7702Validator : plugins?.sudo,
|
|
464
|
+
regular: plugins?.regular,
|
|
465
|
+
hook: plugins?.hook,
|
|
466
|
+
action: plugins?.action,
|
|
467
|
+
pluginEnableSignature: plugins?.pluginEnableSignature,
|
|
430
468
|
entryPoint,
|
|
431
469
|
kernelVersion,
|
|
432
470
|
chainId: await getMemoizedChainId()
|
|
@@ -439,11 +477,14 @@ export async function createKernelAccount<
|
|
|
439
477
|
? plugins.hook &&
|
|
440
478
|
plugins.getIdentifier() ===
|
|
441
479
|
plugins.sudoValidator?.getIdentifier()
|
|
442
|
-
: plugins
|
|
480
|
+
: plugins?.hook && !plugins?.regular
|
|
443
481
|
)
|
|
444
482
|
|
|
445
483
|
// Helper to generate the init code for the smart account
|
|
446
484
|
const generateInitCode = async () => {
|
|
485
|
+
if (isEip7702) {
|
|
486
|
+
return "0x" as `0x${string}`
|
|
487
|
+
}
|
|
447
488
|
if (!accountImplementationAddress || !factoryAddress)
|
|
448
489
|
throw new Error("Missing account logic address or factory address")
|
|
449
490
|
return getAccountInitCode<entryPointVersion>({
|
|
@@ -460,6 +501,12 @@ export async function createKernelAccount<
|
|
|
460
501
|
}
|
|
461
502
|
|
|
462
503
|
const getFactoryArgs = async () => {
|
|
504
|
+
if (isEip7702) {
|
|
505
|
+
return {
|
|
506
|
+
factory: undefined,
|
|
507
|
+
factoryData: undefined
|
|
508
|
+
}
|
|
509
|
+
}
|
|
463
510
|
return {
|
|
464
511
|
factory:
|
|
465
512
|
entryPoint.version === "0.6" || useMetaFactory === false
|
|
@@ -472,16 +519,21 @@ export async function createKernelAccount<
|
|
|
472
519
|
// Fetch account address
|
|
473
520
|
let accountAddress =
|
|
474
521
|
address ??
|
|
475
|
-
(
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
522
|
+
(isEip7702
|
|
523
|
+
? (localAccount?.address ?? zeroAddress)
|
|
524
|
+
: await (async () => {
|
|
525
|
+
const { factory, factoryData } = await getFactoryArgs()
|
|
526
|
+
if (!factory || !factoryData) {
|
|
527
|
+
throw new Error("Missing factory address or factory data")
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Get the sender address based on the init code
|
|
531
|
+
return await getSenderAddress(client, {
|
|
532
|
+
factory,
|
|
533
|
+
factoryData,
|
|
534
|
+
entryPointAddress: entryPoint.address
|
|
535
|
+
})
|
|
536
|
+
})())
|
|
485
537
|
|
|
486
538
|
// If account is zeroAddress try without meta factory
|
|
487
539
|
if (isAddressEqual(accountAddress, zeroAddress) && useMetaFactory) {
|
|
@@ -504,35 +556,6 @@ export async function createKernelAccount<
|
|
|
504
556
|
version: entryPoint?.version ?? "0.7"
|
|
505
557
|
} as const
|
|
506
558
|
|
|
507
|
-
if (eip7702Auth) {
|
|
508
|
-
let code = await getCode(client, { address: accountAddress })
|
|
509
|
-
const isEip7702Authorized =
|
|
510
|
-
code?.length && code.length > 0 && code.startsWith("0xef")
|
|
511
|
-
if (!isEip7702Authorized) {
|
|
512
|
-
const sponsorAccount = eip7702SponsorAccount
|
|
513
|
-
? await toSigner({ signer: eip7702SponsorAccount })
|
|
514
|
-
: privateKeyToAccount(
|
|
515
|
-
// NOTE: Don't worry about this private key, it's just for testing
|
|
516
|
-
"0x688b84097239bc2bca41079d02fae599964a5844bc9e64f524206ad53a927bb9"
|
|
517
|
-
)
|
|
518
|
-
const sponsorWalletClient = createWalletClient({
|
|
519
|
-
account: sponsorAccount,
|
|
520
|
-
chain: client.chain,
|
|
521
|
-
transport: http(client.transport.url)
|
|
522
|
-
})
|
|
523
|
-
await sendTransaction(sponsorWalletClient, {
|
|
524
|
-
to: accountAddress,
|
|
525
|
-
data: "0x",
|
|
526
|
-
authorizationList: [eip7702Auth],
|
|
527
|
-
chain: client.chain
|
|
528
|
-
})
|
|
529
|
-
code = await getCode(client, { address: accountAddress })
|
|
530
|
-
while (code?.length === undefined || code.length === 0) {
|
|
531
|
-
code = await getCode(client, { address: accountAddress })
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
559
|
// Cache for plugin installation status
|
|
537
560
|
const pluginCache: PluginInstallationCache = {
|
|
538
561
|
pendingPlugins: pluginMigrations || [],
|
|
@@ -563,14 +586,64 @@ export async function createKernelAccount<
|
|
|
563
586
|
pluginCache.allInstalled = pluginCache.pendingPlugins.length === 0
|
|
564
587
|
}
|
|
565
588
|
|
|
589
|
+
const signAuthorization = async () => {
|
|
590
|
+
const code = await getCode(client, { address: accountAddress })
|
|
591
|
+
// check if account has not activated 7702 with implementation address
|
|
592
|
+
if (
|
|
593
|
+
!code ||
|
|
594
|
+
code.length === 0 ||
|
|
595
|
+
!code
|
|
596
|
+
.toLowerCase()
|
|
597
|
+
.startsWith(
|
|
598
|
+
`0xef0100${accountImplementationAddress.slice(2).toLowerCase()}`
|
|
599
|
+
)
|
|
600
|
+
) {
|
|
601
|
+
if (
|
|
602
|
+
eip7702Auth &&
|
|
603
|
+
!isAddressEqual(
|
|
604
|
+
eip7702Auth.address,
|
|
605
|
+
accountImplementationAddress
|
|
606
|
+
)
|
|
607
|
+
) {
|
|
608
|
+
throw new Error(
|
|
609
|
+
"EIP-7702 authorization delegate address does not match account implementation address"
|
|
610
|
+
)
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const auth =
|
|
614
|
+
eip7702Auth ??
|
|
615
|
+
(await signAuthorizationAction(client, {
|
|
616
|
+
account: localAccount as LocalAccount,
|
|
617
|
+
address: accountImplementationAddress as `0x${string}`,
|
|
618
|
+
chainId: await getMemoizedChainId()
|
|
619
|
+
}))
|
|
620
|
+
const verified = await verifyAuthorization({
|
|
621
|
+
authorization: auth,
|
|
622
|
+
address: accountAddress
|
|
623
|
+
})
|
|
624
|
+
if (!verified) {
|
|
625
|
+
throw new Error("Authorization verification failed")
|
|
626
|
+
}
|
|
627
|
+
return auth
|
|
628
|
+
}
|
|
629
|
+
return undefined
|
|
630
|
+
}
|
|
631
|
+
|
|
566
632
|
await checkPluginInstallationStatus()
|
|
567
633
|
|
|
568
634
|
return toSmartAccount<KernelSmartAccountImplementation<entryPointVersion>>({
|
|
569
|
-
|
|
635
|
+
authorization: isEip7702
|
|
636
|
+
? {
|
|
637
|
+
account:
|
|
638
|
+
(localAccount as PrivateKeyAccount) ??
|
|
639
|
+
addressToEmptyAccount(accountAddress),
|
|
640
|
+
address: accountImplementationAddress
|
|
641
|
+
}
|
|
642
|
+
: undefined,
|
|
570
643
|
kernelVersion,
|
|
571
644
|
kernelPluginManager,
|
|
572
645
|
accountImplementationAddress,
|
|
573
|
-
factoryAddress: (await getFactoryArgs()).factory,
|
|
646
|
+
factoryAddress: (await getFactoryArgs()).factory as Address,
|
|
574
647
|
generateInitCode,
|
|
575
648
|
encodeModuleInstallCallData: async () => {
|
|
576
649
|
return await kernelPluginManager.encodeModuleInstallCallData(
|
|
@@ -587,6 +660,9 @@ export async function createKernelAccount<
|
|
|
587
660
|
if (accountAddress) return accountAddress
|
|
588
661
|
|
|
589
662
|
const { factory, factoryData } = await getFactoryArgs()
|
|
663
|
+
if (!factory || !factoryData) {
|
|
664
|
+
throw new Error("Missing factory address or factory data")
|
|
665
|
+
}
|
|
590
666
|
|
|
591
667
|
// Get the sender address based on the init code
|
|
592
668
|
accountAddress = await getSenderAddress(client, {
|
|
@@ -624,7 +700,7 @@ export async function createKernelAccount<
|
|
|
624
700
|
return encodeCallDataEpV07(
|
|
625
701
|
[...calls, ...pluginInstallCalls],
|
|
626
702
|
callType,
|
|
627
|
-
plugins
|
|
703
|
+
plugins?.hook ? true : undefined
|
|
628
704
|
)
|
|
629
705
|
}
|
|
630
706
|
|
|
@@ -639,11 +715,12 @@ export async function createKernelAccount<
|
|
|
639
715
|
return encodeCallDataEpV06(calls, callType)
|
|
640
716
|
}
|
|
641
717
|
|
|
642
|
-
if (plugins
|
|
718
|
+
if (plugins?.hook) {
|
|
643
719
|
return encodeCallDataEpV07(calls, callType, true)
|
|
644
720
|
}
|
|
645
721
|
return encodeCallDataEpV07(calls, callType)
|
|
646
722
|
},
|
|
723
|
+
eip7702Authorization: signAuthorization,
|
|
647
724
|
async sign({ hash }) {
|
|
648
725
|
return this.signMessage({ message: hash })
|
|
649
726
|
},
|
|
@@ -49,13 +49,7 @@ export const accountMetadata = async (
|
|
|
49
49
|
} catch (error) {}
|
|
50
50
|
return {
|
|
51
51
|
name: KERNEL_NAME,
|
|
52
|
-
version:
|
|
53
|
-
kernelVersion === "0.3.0"
|
|
54
|
-
? "0.3.0-beta"
|
|
55
|
-
: // TODO: remove this once 0.3.3 is released
|
|
56
|
-
kernelVersion === "0.3.3"
|
|
57
|
-
? "0.3.2"
|
|
58
|
-
: kernelVersion,
|
|
52
|
+
version: kernelVersion === "0.3.0" ? "0.3.0-beta" : kernelVersion,
|
|
59
53
|
chainId: BigInt(
|
|
60
54
|
chainId ??
|
|
61
55
|
(client.chain
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { TypedData } from "abitype"
|
|
2
|
+
import type { Address, Client, Hex, TypedDataDefinition } from "viem"
|
|
3
|
+
import {
|
|
4
|
+
type EntryPointVersion,
|
|
5
|
+
type UserOperation,
|
|
6
|
+
getUserOperationHash
|
|
7
|
+
} from "viem/account-abstraction"
|
|
8
|
+
import { toAccount } from "viem/accounts"
|
|
9
|
+
import { getChainId, signMessage } from "viem/actions"
|
|
10
|
+
import type {
|
|
11
|
+
EntryPointType,
|
|
12
|
+
GetKernelVersion,
|
|
13
|
+
KernelValidator,
|
|
14
|
+
Signer
|
|
15
|
+
} from "../../types/index.js"
|
|
16
|
+
import { toSigner } from "../../utils/toSigner.js"
|
|
17
|
+
|
|
18
|
+
export async function signerTo7702Validator<
|
|
19
|
+
entryPointVersion extends EntryPointVersion
|
|
20
|
+
>(
|
|
21
|
+
client: Client,
|
|
22
|
+
{
|
|
23
|
+
signer,
|
|
24
|
+
entryPoint,
|
|
25
|
+
kernelVersion
|
|
26
|
+
}: {
|
|
27
|
+
signer: Signer
|
|
28
|
+
entryPoint: EntryPointType<entryPointVersion>
|
|
29
|
+
kernelVersion: GetKernelVersion<entryPointVersion>
|
|
30
|
+
}
|
|
31
|
+
): Promise<KernelValidator<"EIP7702Validator">> {
|
|
32
|
+
const viemSigner = await toSigner({ signer })
|
|
33
|
+
|
|
34
|
+
// Fetch chain id
|
|
35
|
+
const chainId = client.chain?.id ?? (await getChainId(client))
|
|
36
|
+
|
|
37
|
+
// Build the EOA Signer
|
|
38
|
+
const account = toAccount({
|
|
39
|
+
address: viemSigner.address,
|
|
40
|
+
async signMessage({ message }) {
|
|
41
|
+
return signMessage(client, { account: viemSigner, message })
|
|
42
|
+
},
|
|
43
|
+
async signTransaction(_, __) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
"Smart account signer doesn't need to sign transactions"
|
|
46
|
+
)
|
|
47
|
+
},
|
|
48
|
+
async signTypedData<
|
|
49
|
+
const TTypedData extends TypedData | Record<string, unknown>,
|
|
50
|
+
TPrimaryType extends
|
|
51
|
+
| keyof TTypedData
|
|
52
|
+
| "EIP712Domain" = keyof TTypedData
|
|
53
|
+
>(typedData: TypedDataDefinition<TTypedData, TPrimaryType>) {
|
|
54
|
+
return viemSigner.signTypedData(typedData)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...account,
|
|
60
|
+
supportedKernelVersions: kernelVersion,
|
|
61
|
+
validatorType: "SECONDARY",
|
|
62
|
+
address: viemSigner.address,
|
|
63
|
+
source: "EIP7702Validator",
|
|
64
|
+
getIdentifier() {
|
|
65
|
+
return "0x"
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
async getEnableData() {
|
|
69
|
+
return viemSigner.address
|
|
70
|
+
},
|
|
71
|
+
async getNonceKey(_accountAddress?: Address, customNonceKey?: bigint) {
|
|
72
|
+
if (customNonceKey) {
|
|
73
|
+
return customNonceKey
|
|
74
|
+
}
|
|
75
|
+
return 0n
|
|
76
|
+
},
|
|
77
|
+
// Sign a user operation
|
|
78
|
+
async signUserOperation(userOperation) {
|
|
79
|
+
const hash = getUserOperationHash({
|
|
80
|
+
userOperation: {
|
|
81
|
+
...userOperation,
|
|
82
|
+
signature: "0x"
|
|
83
|
+
} as UserOperation<entryPointVersion>,
|
|
84
|
+
entryPointAddress: entryPoint.address,
|
|
85
|
+
entryPointVersion: entryPoint.version,
|
|
86
|
+
chainId: chainId
|
|
87
|
+
})
|
|
88
|
+
const signature = await signMessage(client, {
|
|
89
|
+
account: viemSigner,
|
|
90
|
+
message: { raw: hash }
|
|
91
|
+
})
|
|
92
|
+
return signature
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
// Get simple dummy signature
|
|
96
|
+
async getStubSignature() {
|
|
97
|
+
return "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
async isEnabled(
|
|
101
|
+
_kernelAccountAddress: Address,
|
|
102
|
+
_selector: Hex
|
|
103
|
+
): Promise<boolean> {
|
|
104
|
+
return false
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -39,7 +39,7 @@ export function isKernelPluginManager<
|
|
|
39
39
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
40
40
|
plugin: any
|
|
41
41
|
): plugin is KernelPluginManager<entryPointVersion> {
|
|
42
|
-
return plugin
|
|
42
|
+
return plugin?.getPluginEnableSignature !== undefined
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export async function toKernelPluginManager<
|
|
@@ -21,8 +21,10 @@ import {
|
|
|
21
21
|
type SmartAccount,
|
|
22
22
|
type UserOperationRequest,
|
|
23
23
|
bundlerActions,
|
|
24
|
+
prepareUserOperation,
|
|
24
25
|
type prepareUserOperation as viemPrepareUserOperation
|
|
25
26
|
} from "viem/account-abstraction"
|
|
27
|
+
import type { KernelSmartAccountImplementation } from "../accounts/index.js"
|
|
26
28
|
import { getUserOperationGasPrice } from "../actions/index.js"
|
|
27
29
|
import {
|
|
28
30
|
type KernelAccountClientActions,
|
|
@@ -256,5 +258,44 @@ export function createKernelAccountClient(
|
|
|
256
258
|
|
|
257
259
|
return client
|
|
258
260
|
.extend(bundlerActions)
|
|
261
|
+
.extend((_client) => ({
|
|
262
|
+
prepareUserOperation: async (
|
|
263
|
+
args: PrepareUserOperationParameters
|
|
264
|
+
) => {
|
|
265
|
+
let _args = args
|
|
266
|
+
if (_client.account?.authorization) {
|
|
267
|
+
const authorization =
|
|
268
|
+
args.authorization ||
|
|
269
|
+
(await (
|
|
270
|
+
_client.account as SmartAccount<KernelSmartAccountImplementation>
|
|
271
|
+
)?.eip7702Authorization?.())
|
|
272
|
+
_args = {
|
|
273
|
+
...args,
|
|
274
|
+
authorization
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return await prepareUserOperation(_client, _args)
|
|
278
|
+
}
|
|
279
|
+
}))
|
|
280
|
+
.extend(bundlerActions)
|
|
281
|
+
.extend((_client) => ({
|
|
282
|
+
prepareUserOperation: async (
|
|
283
|
+
args: PrepareUserOperationParameters
|
|
284
|
+
) => {
|
|
285
|
+
let _args = args
|
|
286
|
+
if (_client.account?.authorization) {
|
|
287
|
+
const authorization =
|
|
288
|
+
args.authorization ||
|
|
289
|
+
(await (
|
|
290
|
+
_client.account as SmartAccount<KernelSmartAccountImplementation>
|
|
291
|
+
)?.eip7702Authorization?.())
|
|
292
|
+
_args = {
|
|
293
|
+
...args,
|
|
294
|
+
authorization
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return await prepareUserOperation(_client, _args)
|
|
298
|
+
}
|
|
299
|
+
}))
|
|
259
300
|
.extend(kernelAccountClientActions()) as KernelAccountClient
|
|
260
301
|
}
|