Skip to content

Fix/sign authorization #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 1 addition & 45 deletions packages/core/accounts/kernel/createKernelAccount.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
http,
type Address,
type Assign,
type EncodeDeployDataParameters,
Expand All @@ -8,7 +7,6 @@ import {
type TypedDataDefinition,
concatHex,
createNonceManager,
createWalletClient,
encodeFunctionData,
getTypesForEIP712Domain,
hashMessage,
Expand All @@ -28,11 +26,7 @@ import {
entryPoint07Address,
toSmartAccount
} from "viem/account-abstraction"
import {
type SignAuthorizationReturnType,
privateKeyToAccount
} from "viem/accounts"
import { getChainId, getCode, sendTransaction } from "viem/actions"
import { getChainId } from "viem/actions"
import { getAction } from "viem/utils"
import {
getAccountNonce,
Expand All @@ -52,10 +46,8 @@ import type {
KernelPluginManagerParams,
PluginMigrationData
} from "../../types/kernel.js"
import type { Signer } from "../../types/utils.js"
import { KERNEL_FEATURES, hasKernelFeature } from "../../utils.js"
import { validateKernelVersionWithEntryPoint } from "../../utils.js"
import { toSigner } from "../../utils/toSigner.js"
import {
isKernelPluginManager,
toKernelPluginManager
Expand Down Expand Up @@ -104,7 +96,6 @@ export type KernelSmartAccountImplementation<
bytecode
}: EncodeDeployDataParameters) => Promise<Hex>
signMessage: (parameters: SignMessageParameters) => Promise<Hex>
eip7702Auth?: SignAuthorizationReturnType
}
>

Expand All @@ -131,9 +122,6 @@ export type CreateKernelAccountParameters<
kernelVersion: GetKernelVersion<entryPointVersion>
initConfig?: KernelVerion extends "0.3.1" ? Hex[] : never
useMetaFactory?: boolean
eip7702?: boolean
eip7702Auth?: SignAuthorizationReturnType
eip7702SponsorAccount?: Signer
pluginMigrations?: PluginMigrationData[]
}

Expand Down Expand Up @@ -379,8 +367,6 @@ export async function createKernelAccount<
kernelVersion,
initConfig,
useMetaFactory: _useMetaFactory = true,
eip7702Auth,
eip7702SponsorAccount,
pluginMigrations
}: CreateKernelAccountParameters<entryPointVersion, KernelVersion>
): Promise<CreateKernelAccountReturnType<entryPointVersion>> {
Expand Down Expand Up @@ -489,35 +475,6 @@ export async function createKernelAccount<
version: entryPoint?.version ?? "0.7"
} as const

if (eip7702Auth) {
let code = await getCode(client, { address: accountAddress })
const isEip7702Authorized =
code?.length && code.length > 0 && code.startsWith("0xef")
if (!isEip7702Authorized) {
const sponsorAccount = eip7702SponsorAccount
? await toSigner({ signer: eip7702SponsorAccount })
: privateKeyToAccount(
// NOTE: Don't worry about this private key, it's just for testing
"0x688b84097239bc2bca41079d02fae599964a5844bc9e64f524206ad53a927bb9"
)
const sponsorWalletClient = createWalletClient({
account: sponsorAccount,
chain: client.chain,
transport: http(client.transport.url)
})
await sendTransaction(sponsorWalletClient, {
to: accountAddress,
data: "0x",
authorizationList: [eip7702Auth],
chain: client.chain
})
code = await getCode(client, { address: accountAddress })
while (code?.length === undefined || code.length === 0) {
code = await getCode(client, { address: accountAddress })
}
}
}

// Cache for plugin installation status
const pluginCache: PluginInstallationCache = {
pendingPlugins: pluginMigrations || [],
Expand Down Expand Up @@ -551,7 +508,6 @@ export async function createKernelAccount<
await checkPluginInstallationStatus()

return toSmartAccount<KernelSmartAccountImplementation<entryPointVersion>>({
eip7702Auth,
kernelVersion,
kernelPluginManager,
accountImplementationAddress,
Expand Down