permissionless 0.1.19 → 0.1.21
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/CHANGELOG.md +12 -0
- package/_cjs/accounts/kernel/abi/KernelV3AccountAbi.js +91 -0
- package/_cjs/accounts/kernel/abi/KernelV3AccountAbi.js.map +1 -0
- package/_cjs/accounts/kernel/abi/KernelV3MetaFactoryAbi.js +21 -0
- package/_cjs/accounts/kernel/abi/KernelV3MetaFactoryAbi.js.map +1 -0
- package/_cjs/accounts/kernel/constants.js +27 -0
- package/_cjs/accounts/kernel/constants.js.map +1 -0
- package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js +138 -45
- package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
- package/_cjs/accounts/kernel/utils/encodeCallData.js +89 -0
- package/_cjs/accounts/kernel/utils/encodeCallData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/getExecMode.js +15 -0
- package/_cjs/accounts/kernel/utils/getExecMode.js.map +1 -0
- package/_cjs/accounts/kernel/utils/getNonceKey.js +24 -0
- package/_cjs/accounts/kernel/utils/getNonceKey.js.map +1 -0
- package/_cjs/accounts/kernel/utils/signMessage.js +28 -0
- package/_cjs/accounts/kernel/utils/signMessage.js.map +1 -0
- package/_cjs/accounts/kernel/utils/signTypedData.js +40 -0
- package/_cjs/accounts/kernel/utils/signTypedData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/wrapMessageHash.js +20 -0
- package/_cjs/accounts/kernel/utils/wrapMessageHash.js.map +1 -0
- package/_esm/accounts/kernel/abi/KernelV3AccountAbi.js +88 -0
- package/_esm/accounts/kernel/abi/KernelV3AccountAbi.js.map +1 -0
- package/_esm/accounts/kernel/abi/KernelV3MetaFactoryAbi.js +18 -0
- package/_esm/accounts/kernel/abi/KernelV3MetaFactoryAbi.js.map +1 -0
- package/_esm/accounts/kernel/constants.js +24 -0
- package/_esm/accounts/kernel/constants.js.map +1 -0
- package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js +165 -52
- package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
- package/_esm/accounts/kernel/utils/encodeCallData.js +89 -0
- package/_esm/accounts/kernel/utils/encodeCallData.js.map +1 -0
- package/_esm/accounts/kernel/utils/getExecMode.js +12 -0
- package/_esm/accounts/kernel/utils/getExecMode.js.map +1 -0
- package/_esm/accounts/kernel/utils/getNonceKey.js +21 -0
- package/_esm/accounts/kernel/utils/getNonceKey.js.map +1 -0
- package/_esm/accounts/kernel/utils/signMessage.js +24 -0
- package/_esm/accounts/kernel/utils/signMessage.js.map +1 -0
- package/_esm/accounts/kernel/utils/signTypedData.js +38 -0
- package/_esm/accounts/kernel/utils/signTypedData.js.map +1 -0
- package/_esm/accounts/kernel/utils/wrapMessageHash.js +16 -0
- package/_esm/accounts/kernel/utils/wrapMessageHash.js.map +1 -0
- package/_types/accounts/kernel/abi/KernelV3AccountAbi.d.ts +108 -0
- package/_types/accounts/kernel/abi/KernelV3AccountAbi.d.ts.map +1 -0
- package/_types/accounts/kernel/abi/KernelV3MetaFactoryAbi.d.ts +24 -0
- package/_types/accounts/kernel/abi/KernelV3MetaFactoryAbi.d.ts.map +1 -0
- package/_types/accounts/kernel/constants.d.ts +21 -0
- package/_types/accounts/kernel/constants.d.ts.map +1 -0
- package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts +18 -5
- package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts.map +1 -1
- package/_types/accounts/kernel/utils/encodeCallData.d.ts +12 -0
- package/_types/accounts/kernel/utils/encodeCallData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/getExecMode.d.ts +7 -0
- package/_types/accounts/kernel/utils/getExecMode.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/getNonceKey.d.ts +4 -0
- package/_types/accounts/kernel/utils/getNonceKey.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/signMessage.d.ts +4 -0
- package/_types/accounts/kernel/utils/signMessage.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/signTypedData.d.ts +4 -0
- package/_types/accounts/kernel/utils/signTypedData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/wrapMessageHash.d.ts +9 -0
- package/_types/accounts/kernel/utils/wrapMessageHash.d.ts.map +1 -0
- package/accounts/kernel/abi/KernelV3AccountAbi.ts +88 -0
- package/accounts/kernel/abi/KernelV3MetaFactoryAbi.ts +17 -0
- package/accounts/kernel/constants.ts +21 -0
- package/accounts/kernel/signerToEcdsaKernelSmartAccount.ts +252 -71
- package/accounts/kernel/utils/encodeCallData.ts +114 -0
- package/accounts/kernel/utils/getExecMode.ts +18 -0
- package/accounts/kernel/utils/getNonceKey.ts +32 -0
- package/accounts/kernel/utils/signMessage.ts +48 -0
- package/accounts/kernel/utils/signTypedData.ts +74 -0
- package/accounts/kernel/utils/wrapMessageHash.ts +38 -0
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Address, concatHex, maxUint16, pad, toHex } from "viem"
|
|
2
|
+
import { VALIDATOR_MODE, VALIDATOR_TYPE } from "../constants"
|
|
3
|
+
import { type KernelVersion } from "../signerToEcdsaKernelSmartAccount"
|
|
4
|
+
|
|
5
|
+
export const getNonceKeyWithEncoding = (
|
|
6
|
+
accountVerion: KernelVersion,
|
|
7
|
+
validatorAddress: Address,
|
|
8
|
+
nonceKey = 0n
|
|
9
|
+
) => {
|
|
10
|
+
if (accountVerion === "0.2.2") {
|
|
11
|
+
return nonceKey
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (nonceKey > maxUint16)
|
|
15
|
+
throw new Error(
|
|
16
|
+
`nonce key must be equal or less than 2 bytes(maxUint16) for Kernel version ${accountVerion}`
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
const validatorMode = VALIDATOR_MODE.DEFAULT
|
|
20
|
+
const validatorType = VALIDATOR_TYPE.ROOT
|
|
21
|
+
const encoding = pad(
|
|
22
|
+
concatHex([
|
|
23
|
+
validatorMode, // 1 byte
|
|
24
|
+
validatorType, // 1 byte
|
|
25
|
+
validatorAddress, // 20 bytes
|
|
26
|
+
toHex(nonceKey, { size: 2 }) // 2 byte
|
|
27
|
+
]),
|
|
28
|
+
{ size: 24 }
|
|
29
|
+
) // 24 bytes
|
|
30
|
+
const encodedNonceKey = BigInt(encoding)
|
|
31
|
+
return encodedNonceKey
|
|
32
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Chain,
|
|
4
|
+
type Client,
|
|
5
|
+
type LocalAccount,
|
|
6
|
+
type SignMessageParameters,
|
|
7
|
+
type SignMessageReturnType,
|
|
8
|
+
type Transport,
|
|
9
|
+
hashMessage,
|
|
10
|
+
publicActions
|
|
11
|
+
} from "viem"
|
|
12
|
+
import { signMessage as _signMessage } from "viem/actions"
|
|
13
|
+
import { type WrapMessageHashParams, wrapMessageHash } from "./wrapMessageHash"
|
|
14
|
+
|
|
15
|
+
export async function signMessage<
|
|
16
|
+
TChain extends Chain | undefined,
|
|
17
|
+
TAccount extends Account | undefined
|
|
18
|
+
>(
|
|
19
|
+
client: Client<Transport, TChain, TAccount>,
|
|
20
|
+
{
|
|
21
|
+
account: account_ = client.account,
|
|
22
|
+
message,
|
|
23
|
+
accountAddress,
|
|
24
|
+
accountVersion
|
|
25
|
+
}: SignMessageParameters<TAccount> & WrapMessageHashParams
|
|
26
|
+
): Promise<SignMessageReturnType> {
|
|
27
|
+
if (accountVersion === "0.2.2") {
|
|
28
|
+
return _signMessage(client, {
|
|
29
|
+
account: account_ as LocalAccount,
|
|
30
|
+
message
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const wrappedMessageHash = wrapMessageHash(hashMessage(message), {
|
|
35
|
+
accountVersion,
|
|
36
|
+
accountAddress,
|
|
37
|
+
chainId: client.chain
|
|
38
|
+
? client.chain.id
|
|
39
|
+
: await client.extend(publicActions).getChainId()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const signature = await _signMessage(client, {
|
|
43
|
+
account: account_ as LocalAccount,
|
|
44
|
+
message: { raw: wrappedMessageHash }
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return signature
|
|
48
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Chain,
|
|
4
|
+
type Client,
|
|
5
|
+
type LocalAccount,
|
|
6
|
+
type SignTypedDataParameters,
|
|
7
|
+
type SignTypedDataReturnType,
|
|
8
|
+
type Transport,
|
|
9
|
+
type TypedData,
|
|
10
|
+
getTypesForEIP712Domain,
|
|
11
|
+
hashTypedData,
|
|
12
|
+
publicActions,
|
|
13
|
+
validateTypedData
|
|
14
|
+
} from "viem"
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
signMessage as _signMessage,
|
|
18
|
+
signTypedData as _signTypedData
|
|
19
|
+
} from "viem/actions"
|
|
20
|
+
import { type WrapMessageHashParams, wrapMessageHash } from "./wrapMessageHash"
|
|
21
|
+
|
|
22
|
+
export async function signTypedData<
|
|
23
|
+
const typedData extends TypedData | Record<string, unknown>,
|
|
24
|
+
primaryType extends keyof typedData | "EIP712Domain",
|
|
25
|
+
chain extends Chain | undefined,
|
|
26
|
+
account extends Account | undefined
|
|
27
|
+
>(
|
|
28
|
+
client: Client<Transport, chain, account>,
|
|
29
|
+
parameters: SignTypedDataParameters<typedData, primaryType, account> &
|
|
30
|
+
WrapMessageHashParams
|
|
31
|
+
): Promise<SignTypedDataReturnType> {
|
|
32
|
+
const {
|
|
33
|
+
account: account_,
|
|
34
|
+
accountAddress,
|
|
35
|
+
accountVersion,
|
|
36
|
+
...typedData
|
|
37
|
+
} = parameters as unknown as SignTypedDataParameters & WrapMessageHashParams
|
|
38
|
+
if (accountVersion === "0.2.2") {
|
|
39
|
+
return _signTypedData(client, { account: account_, ...typedData })
|
|
40
|
+
}
|
|
41
|
+
const { message, primaryType, types: _types, domain } = typedData
|
|
42
|
+
const types = {
|
|
43
|
+
EIP712Domain: getTypesForEIP712Domain({
|
|
44
|
+
domain: domain
|
|
45
|
+
}),
|
|
46
|
+
..._types
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Need to do a runtime validation check on addresses, byte ranges, integer ranges, etc
|
|
50
|
+
// as we can't statically check this with TypeScript.
|
|
51
|
+
validateTypedData({
|
|
52
|
+
domain,
|
|
53
|
+
message,
|
|
54
|
+
primaryType,
|
|
55
|
+
types
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const typedHash = hashTypedData({ message, primaryType, types, domain })
|
|
59
|
+
|
|
60
|
+
const wrappedMessageHash = wrapMessageHash(typedHash, {
|
|
61
|
+
accountVersion,
|
|
62
|
+
accountAddress,
|
|
63
|
+
chainId: client.chain
|
|
64
|
+
? client.chain.id
|
|
65
|
+
: await client.extend(publicActions).getChainId()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const signature = await _signMessage(client, {
|
|
69
|
+
account: account_ as LocalAccount,
|
|
70
|
+
message: { raw: wrappedMessageHash }
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
return signature
|
|
74
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Hex,
|
|
3
|
+
concatHex,
|
|
4
|
+
encodeAbiParameters,
|
|
5
|
+
keccak256,
|
|
6
|
+
stringToHex
|
|
7
|
+
} from "viem"
|
|
8
|
+
import { type Address, domainSeparator } from "viem"
|
|
9
|
+
|
|
10
|
+
export type WrapMessageHashParams = {
|
|
11
|
+
accountVersion: string
|
|
12
|
+
accountAddress: Address
|
|
13
|
+
chainId?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const wrapMessageHash = (
|
|
17
|
+
messageHash: Hex,
|
|
18
|
+
{ accountAddress, accountVersion, chainId }: WrapMessageHashParams
|
|
19
|
+
) => {
|
|
20
|
+
const _domainSeparator = domainSeparator({
|
|
21
|
+
domain: {
|
|
22
|
+
name: "Kernel",
|
|
23
|
+
version: accountVersion,
|
|
24
|
+
chainId,
|
|
25
|
+
verifyingContract: accountAddress
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
const wrappedMessageHash = keccak256(
|
|
29
|
+
encodeAbiParameters(
|
|
30
|
+
[{ type: "bytes32" }, { type: "bytes32" }],
|
|
31
|
+
[keccak256(stringToHex("Kernel(bytes32 hash)")), messageHash]
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
const digest = keccak256(
|
|
35
|
+
concatHex(["0x1901", _domainSeparator, wrappedMessageHash])
|
|
36
|
+
)
|
|
37
|
+
return digest
|
|
38
|
+
}
|