Skip to content

Commit aefd7e4

Browse files
Merge pull request #514 from pimlicolabs/tedim52/main
Expose utils for generating ERC-1271 signatures
2 parents aa83175 + 66ba553 commit aefd7e4

15 files changed

Lines changed: 216 additions & 41 deletions

File tree

.changeset/shaggy-falcons-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"permissionless": patch
3+
---
4+
5+
Added namespace exports for each smart account and exposed Kernel's ERC-1271 helpers.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { toBiconomySmartAccount } from "./toBiconomySmartAccount.js"
2+
3+
export const BiconomySmartAccount = {
4+
toBiconomySmartAccount
5+
}
6+
7+
export type {
8+
BiconomySmartAccountImplementation,
9+
ToBiconomySmartAccountParameters,
10+
ToBiconomySmartAccountReturnType
11+
} from "./toBiconomySmartAccount.js"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { toEtherspotSmartAccount } from "./toEtherspotSmartAccount.js"
2+
3+
export const EtherspotSmartAccount = {
4+
toEtherspotSmartAccount
5+
}
6+
7+
export type {
8+
EtherspotSmartAccountImplementation,
9+
ToEtherspotSmartAccountParameters,
10+
ToEtherspotSmartAccountReturnType
11+
} from "./toEtherspotSmartAccount.js"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { to7702KernelSmartAccount } from "./to7702KernelSmartAccount.js"
2+
import { toKernelSmartAccount } from "./toKernelSmartAccount.js"
3+
import { isKernelV2 } from "./utils/isKernelV2.js"
4+
import { signMessage } from "./utils/signMessage.js"
5+
import { signTypedData } from "./utils/signTypedData.js"
6+
import { wrapMessageHash } from "./utils/wrapMessageHash.js"
7+
8+
export const KernelSmartAccount = {
9+
toKernelSmartAccount,
10+
to7702KernelSmartAccount,
11+
wrapMessageHash,
12+
signMessage,
13+
signTypedData,
14+
isKernelV2
15+
}
16+
17+
export type {
18+
KernelSmartAccountImplementation,
19+
KernelVersion,
20+
ToKernelSmartAccountParameters,
21+
ToKernelSmartAccountReturnType
22+
} from "./toKernelSmartAccount.js"
23+
export type {
24+
EcdsaKernelSmartAccountImplementation,
25+
ToEcdsaKernelSmartAccountParameters,
26+
ToEcdsaKernelSmartAccountReturnType
27+
} from "./toEcdsaKernelSmartAccount.js"
28+
export type {
29+
To7702KernelSmartAccountImplementation,
30+
To7702KernelSmartAccountParameters,
31+
To7702KernelSmartAccountReturnType
32+
} from "./to7702KernelSmartAccount.js"
33+
export type { WrapMessageHashParams } from "./utils/wrapMessageHash.js"

packages/permissionless/accounts/kernel/toKernelSmartAccount.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,8 @@ export async function toKernelSmartAccount<
901901
const signature = await signMessage({
902902
owner,
903903
message,
904-
accountAddress: await this.getAddress(),
905-
kernelVersion: kernelVersion,
904+
address: await this.getAddress(),
905+
version: kernelVersion,
906906
chainId: await getMemoizedChainId(),
907907
eip7702: eip7702
908908
})
@@ -931,8 +931,8 @@ export async function toKernelSmartAccount<
931931
owner: owner,
932932
chainId: await getMemoizedChainId(),
933933
...(typedData as TypedDataDefinition),
934-
accountAddress: await this.getAddress(),
935-
kernelVersion: kernelVersion,
934+
address: await this.getAddress(),
935+
version: kernelVersion,
936936
eip7702
937937
})
938938

@@ -966,8 +966,8 @@ export async function toKernelSmartAccount<
966966
owner,
967967
message: { raw: hash },
968968
chainId,
969-
accountAddress: await this.getAddress(),
970-
kernelVersion,
969+
address: await this.getAddress(),
970+
version: kernelVersion,
971971
eip7702: false
972972
})
973973
: await owner.signMessage({

packages/permissionless/accounts/kernel/utils/signMessage.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
type Hash,
33
type LocalAccount,
4+
type Prettify,
45
type SignMessageReturnType,
56
type SignableMessage,
67
encodeAbiParameters,
@@ -18,23 +19,25 @@ import {
1819
export async function signMessage({
1920
message,
2021
owner,
21-
accountAddress,
22-
kernelVersion: accountVersion,
22+
address: accountAddress,
23+
version: accountVersion,
2324
chainId,
24-
eip7702
25-
}: {
26-
chainId: number
27-
message: SignableMessage
28-
owner: LocalAccount | WebAuthnAccount
29-
eip7702: boolean
30-
} & WrapMessageHashParams): Promise<SignMessageReturnType> {
25+
eip7702 = false
26+
}: Prettify<
27+
{
28+
message: SignableMessage
29+
owner: LocalAccount | WebAuthnAccount
30+
eip7702?: boolean
31+
} & WrapMessageHashParams
32+
>): Promise<SignMessageReturnType> {
3133
if (isWebAuthnAccount(owner)) {
3234
let messageContent: string
3335
if (typeof message === "string") {
3436
// message is a string
35-
messageContent = wrapMessageHash(hashMessage(message), {
36-
kernelVersion: accountVersion,
37-
accountAddress,
37+
messageContent = wrapMessageHash({
38+
hash: hashMessage(message),
39+
version: accountVersion,
40+
address: accountAddress,
3841
chainId
3942
// chainId: client.chain
4043
// ? client.chain.id
@@ -100,9 +103,10 @@ export async function signMessage({
100103
})
101104
}
102105

103-
const wrappedMessageHash = wrapMessageHash(hashMessage(message), {
104-
kernelVersion: accountVersion,
105-
accountAddress,
106+
const wrappedMessageHash = wrapMessageHash({
107+
hash: hashMessage(message),
108+
version: accountVersion,
109+
address: accountAddress,
106110
chainId
107111
// chainId: client.chain
108112
// ? client.chain.id

packages/permissionless/accounts/kernel/utils/signTypedData.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
type LocalAccount,
3+
type Prettify,
34
type SignTypedDataReturnType,
45
type TypedDataDefinition,
56
getTypesForEIP712Domain,
@@ -15,18 +16,19 @@ import {
1516
} from "./wrapMessageHash.js"
1617

1718
export async function signTypedData(
18-
parameters: TypedDataDefinition &
19+
parameters: Prettify<
1920
WrapMessageHashParams & {
2021
owner: LocalAccount | WebAuthnAccount
21-
eip7702: boolean
22-
}
22+
eip7702?: boolean
23+
} & TypedDataDefinition
24+
>
2325
): Promise<SignTypedDataReturnType> {
2426
const {
2527
owner,
26-
accountAddress,
27-
kernelVersion: accountVersion,
28+
address: accountAddress,
29+
version: accountVersion,
2830
chainId,
29-
eip7702,
31+
eip7702 = false,
3032
...typedData
3133
} = parameters
3234

@@ -74,18 +76,19 @@ export async function signTypedData(
7476
})
7577
}
7678

77-
const wrappedMessageHash = wrapMessageHash(typedHash, {
78-
kernelVersion: accountVersion,
79-
accountAddress,
79+
const wrappedMessageHash = wrapMessageHash({
80+
hash: typedHash,
81+
version: accountVersion,
82+
address: accountAddress,
8083
chainId: chainId
8184
})
8285

8386
if (isWebAuthnAccount(owner)) {
8487
return signMessage({
8588
message: { raw: wrappedMessageHash },
8689
owner,
87-
accountAddress,
88-
kernelVersion: accountVersion,
90+
address: accountAddress,
91+
version: accountVersion,
8992
chainId,
9093
eip7702: false
9194
})

packages/permissionless/accounts/kernel/utils/wrapMessageHash.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
type Address,
33
type Hex,
4+
type Prettify,
45
concatHex,
56
domainSeparator,
67
encodeAbiParameters,
@@ -11,15 +12,17 @@ import type { KernelVersion } from "../toKernelSmartAccount.js"
1112
import { isKernelV2 } from "./isKernelV2.js"
1213

1314
export type WrapMessageHashParams = {
14-
kernelVersion: KernelVersion<"0.6" | "0.7">
15-
accountAddress: Address
15+
version: KernelVersion<"0.6" | "0.7">
16+
address: Address
1617
chainId: number
1718
}
1819

19-
export const wrapMessageHash = (
20-
messageHash: Hex,
21-
{ accountAddress, kernelVersion, chainId }: WrapMessageHashParams
22-
) => {
20+
export const wrapMessageHash = ({
21+
hash,
22+
address: accountAddress,
23+
version: kernelVersion,
24+
chainId
25+
}: Prettify<{ hash: Hex } & WrapMessageHashParams>) => {
2326
const _domainSeparator = domainSeparator({
2427
domain: {
2528
name: "Kernel",
@@ -29,11 +32,11 @@ export const wrapMessageHash = (
2932
}
3033
})
3134
const wrappedMessageHash = isKernelV2(kernelVersion)
32-
? messageHash
35+
? hash
3336
: keccak256(
3437
encodeAbiParameters(
3538
[{ type: "bytes32" }, { type: "bytes32" }],
36-
[keccak256(stringToHex("Kernel(bytes32 hash)")), messageHash]
39+
[keccak256(stringToHex("Kernel(bytes32 hash)")), hash]
3740
)
3841
)
3942

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { toLightSmartAccount } from "./toLightSmartAccount.js"
2+
3+
export const LightSmartAccount = {
4+
toLightSmartAccount
5+
}
6+
7+
export type {
8+
LightAccountVersion,
9+
LightSmartAccountImplementation,
10+
ToLightSmartAccountParameters,
11+
ToLightSmartAccountReturnType
12+
} from "./toLightSmartAccount.js"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { toNexusSmartAccount } from "./toNexusSmartAccount.js"
2+
3+
export const NexusSmartAccount = {
4+
toNexusSmartAccount
5+
}
6+
7+
export type {
8+
NexusSmartAccountImplementation,
9+
ToNexusSmartAccountParameters,
10+
ToNexusSmartAccountReturnType
11+
} from "./toNexusSmartAccount.js"

0 commit comments

Comments
 (0)