@zerodev/permissions 5.4.10 → 5.5.0-beta.0
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/deserializePermissionAccount.js +8 -11
- package/_cjs/deserializePermissionAccount.js.map +1 -1
- package/_cjs/serializeMultiChainPermissionAccounts.js.map +1 -1
- package/_cjs/serializePermissionAccount.js.map +1 -1
- package/_cjs/signers/toECDSASigner.js +4 -5
- package/_cjs/signers/toECDSASigner.js.map +1 -1
- package/_cjs/signers/toWebAuthnSigner.js +3 -4
- package/_cjs/signers/toWebAuthnSigner.js.map +1 -1
- package/_cjs/toPermissionValidator.js +11 -8
- package/_cjs/toPermissionValidator.js.map +1 -1
- package/_cjs/utils.js.map +1 -1
- package/_esm/deserializePermissionAccount.js +8 -11
- package/_esm/deserializePermissionAccount.js.map +1 -1
- package/_esm/serializeMultiChainPermissionAccounts.js.map +1 -1
- package/_esm/serializePermissionAccount.js.map +1 -1
- package/_esm/signers/toECDSASigner.js +2 -3
- package/_esm/signers/toECDSASigner.js.map +1 -1
- package/_esm/signers/toWebAuthnSigner.js +1 -2
- package/_esm/signers/toWebAuthnSigner.js.map +1 -1
- package/_esm/toPermissionValidator.js +10 -7
- package/_esm/toPermissionValidator.js.map +1 -1
- package/_esm/utils.js.map +1 -1
- package/_types/deserializePermissionAccount.d.ts +264 -3
- package/_types/deserializePermissionAccount.d.ts.map +1 -1
- package/_types/serializeMultiChainPermissionAccounts.d.ts +5 -5
- package/_types/serializeMultiChainPermissionAccounts.d.ts.map +1 -1
- package/_types/serializePermissionAccount.d.ts +3 -3
- package/_types/serializePermissionAccount.d.ts.map +1 -1
- package/_types/signers/toECDSASigner.d.ts +4 -5
- package/_types/signers/toECDSASigner.d.ts.map +1 -1
- package/_types/signers/toWebAuthnSigner.d.ts.map +1 -1
- package/_types/toPermissionValidator.d.ts +3 -3
- package/_types/toPermissionValidator.d.ts.map +1 -1
- package/_types/types.d.ts +8 -5
- package/_types/types.d.ts.map +1 -1
- package/_types/utils.d.ts +1 -2
- package/_types/utils.d.ts.map +1 -1
- package/deserializePermissionAccount.ts +14 -36
- package/package.json +4 -5
- package/serializeMultiChainPermissionAccounts.ts +9 -12
- package/serializePermissionAccount.ts +4 -4
- package/signers/toECDSASigner.ts +11 -17
- package/signers/toWebAuthnSigner.ts +3 -2
- package/toPermissionValidator.ts +18 -16
- package/types.ts +7 -8
- package/utils.ts +2 -3
package/signers/toECDSASigner.ts
CHANGED
|
@@ -1,32 +1,24 @@
|
|
|
1
1
|
import { constants, fixSignedData } from "@zerodev/sdk"
|
|
2
2
|
import type { TypedData } from "abitype"
|
|
3
|
-
import {
|
|
4
|
-
SignTransactionNotSupportedBySmartAccount,
|
|
5
|
-
type SmartAccountSigner
|
|
6
|
-
} from "permissionless/accounts"
|
|
7
|
-
import type { Address, LocalAccount, TypedDataDefinition } from "viem"
|
|
3
|
+
import type { LocalAccount, TypedDataDefinition } from "viem"
|
|
8
4
|
import { toAccount } from "viem/accounts"
|
|
9
5
|
import { ECDSA_SIGNER_CONTRACT } from "../constants.js"
|
|
10
6
|
import type { ModularSigner, ModularSignerParams } from "../types.js"
|
|
11
7
|
|
|
12
|
-
export type ECDSAModularSignerParams
|
|
13
|
-
|
|
14
|
-
TAddress extends Address = Address
|
|
15
|
-
> = ModularSignerParams & {
|
|
16
|
-
signer: SmartAccountSigner<TSource, TAddress>
|
|
8
|
+
export type ECDSAModularSignerParams = ModularSignerParams & {
|
|
9
|
+
signer: LocalAccount
|
|
17
10
|
}
|
|
18
11
|
|
|
19
|
-
export function toECDSASigner
|
|
20
|
-
TSource extends string = "custom",
|
|
21
|
-
TAddress extends Address = Address
|
|
22
|
-
>({
|
|
12
|
+
export function toECDSASigner({
|
|
23
13
|
signer,
|
|
24
14
|
signerContractAddress = ECDSA_SIGNER_CONTRACT
|
|
25
|
-
}: ECDSAModularSignerParams
|
|
15
|
+
}: ECDSAModularSignerParams): ModularSigner {
|
|
26
16
|
const viemSigner: LocalAccount = {
|
|
27
17
|
...signer,
|
|
28
18
|
signTransaction: (_, __) => {
|
|
29
|
-
throw new
|
|
19
|
+
throw new Error(
|
|
20
|
+
"Smart account signer doesn't need to sign transactions"
|
|
21
|
+
)
|
|
30
22
|
}
|
|
31
23
|
} as LocalAccount
|
|
32
24
|
const account = toAccount({
|
|
@@ -35,7 +27,9 @@ export function toECDSASigner<
|
|
|
35
27
|
return fixSignedData(await viemSigner.signMessage({ message }))
|
|
36
28
|
},
|
|
37
29
|
async signTransaction(_, __) {
|
|
38
|
-
throw new
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Smart account signer doesn't need to sign transactions"
|
|
32
|
+
)
|
|
39
33
|
},
|
|
40
34
|
async signTypedData<
|
|
41
35
|
const TTypedData extends TypedData | Record<string, unknown>,
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
uint8ArrayToHexString
|
|
11
11
|
} from "@zerodev/webauthn-key"
|
|
12
12
|
import type { TypedData } from "abitype"
|
|
13
|
-
import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts"
|
|
14
13
|
import {
|
|
15
14
|
type Address,
|
|
16
15
|
type Chain,
|
|
@@ -161,7 +160,9 @@ export const toWebAuthnSigner = async <
|
|
|
161
160
|
])
|
|
162
161
|
},
|
|
163
162
|
async signTransaction(_, __) {
|
|
164
|
-
throw new
|
|
163
|
+
throw new Error(
|
|
164
|
+
"Smart account signer doesn't need to sign transactions"
|
|
165
|
+
)
|
|
165
166
|
},
|
|
166
167
|
async signTypedData<
|
|
167
168
|
const TTypedData extends TypedData | Record<string, unknown>,
|
package/toPermissionValidator.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { KernelV3AccountAbi } from "@zerodev/sdk"
|
|
2
|
-
import { getEntryPointVersion, getUserOperationHash } from "permissionless"
|
|
3
|
-
import type { EntryPoint } from "permissionless/types/entrypoint"
|
|
4
2
|
import {
|
|
5
3
|
type Address,
|
|
6
|
-
type Chain,
|
|
7
4
|
type Client,
|
|
8
5
|
type Hex,
|
|
9
|
-
type Transport,
|
|
10
6
|
concat,
|
|
11
7
|
encodeAbiParameters,
|
|
12
8
|
keccak256,
|
|
@@ -23,25 +19,27 @@ import type {
|
|
|
23
19
|
PermissionPlugin,
|
|
24
20
|
PermissionPluginParams
|
|
25
21
|
} from "./types.js"
|
|
22
|
+
import {
|
|
23
|
+
getUserOperationHash,
|
|
24
|
+
type UserOperation,
|
|
25
|
+
type EntryPointVersion
|
|
26
|
+
} from "viem/account-abstraction"
|
|
26
27
|
|
|
27
28
|
export async function toPermissionValidator<
|
|
28
|
-
|
|
29
|
-
TTransport extends Transport = Transport,
|
|
30
|
-
TChain extends Chain | undefined = Chain | undefined
|
|
29
|
+
entryPointVersion extends EntryPointVersion
|
|
31
30
|
>(
|
|
32
|
-
client: Client
|
|
31
|
+
client: Client,
|
|
33
32
|
{
|
|
34
33
|
signer,
|
|
35
34
|
policies,
|
|
36
|
-
entryPoint
|
|
35
|
+
entryPoint,
|
|
37
36
|
kernelVersion: _,
|
|
38
37
|
flag = PolicyFlags.FOR_ALL_VALIDATION
|
|
39
|
-
}: PermissionPluginParams<
|
|
40
|
-
): Promise<PermissionPlugin
|
|
38
|
+
}: PermissionPluginParams<entryPointVersion>
|
|
39
|
+
): Promise<PermissionPlugin> {
|
|
41
40
|
const chainId = await getChainId(client)
|
|
42
|
-
const entryPointVersion = getEntryPointVersion(entryPointAddress)
|
|
43
41
|
|
|
44
|
-
if (
|
|
42
|
+
if (entryPoint.version !== "0.7") {
|
|
45
43
|
throw new Error("Only EntryPoint 0.7 is supported")
|
|
46
44
|
}
|
|
47
45
|
|
|
@@ -101,8 +99,12 @@ export async function toPermissionValidator<
|
|
|
101
99
|
|
|
102
100
|
signUserOperation: async (userOperation): Promise<Hex> => {
|
|
103
101
|
const userOpHash = getUserOperationHash({
|
|
104
|
-
userOperation: {
|
|
105
|
-
|
|
102
|
+
userOperation: {
|
|
103
|
+
...userOperation,
|
|
104
|
+
signature: "0x"
|
|
105
|
+
} as UserOperation<entryPointVersion>,
|
|
106
|
+
entryPointAddress: entryPoint.address,
|
|
107
|
+
entryPointVersion: entryPoint.version,
|
|
106
108
|
chainId
|
|
107
109
|
})
|
|
108
110
|
|
|
@@ -119,7 +121,7 @@ export async function toPermissionValidator<
|
|
|
119
121
|
return 0n
|
|
120
122
|
},
|
|
121
123
|
|
|
122
|
-
async
|
|
124
|
+
async getStubSignature(_userOperation) {
|
|
123
125
|
return concat(["0xff", signer.getDummySignature()])
|
|
124
126
|
},
|
|
125
127
|
getPluginSerializationParams: (): PermissionData => {
|
package/types.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type {
|
|
|
4
4
|
GetKernelVersion,
|
|
5
5
|
PluginValidityData
|
|
6
6
|
} from "@zerodev/sdk/types"
|
|
7
|
-
import type { EntryPoint } from "permissionless/types/entrypoint"
|
|
8
7
|
import type { Abi, Address, Hex, LocalAccount } from "viem"
|
|
9
8
|
import type { PolicyFlags } from "./constants.js"
|
|
10
9
|
import type {
|
|
@@ -15,11 +14,9 @@ import type {
|
|
|
15
14
|
SudoPolicyParams,
|
|
16
15
|
TimestampPolicyParams
|
|
17
16
|
} from "./policies/index.js"
|
|
17
|
+
import type { EntryPointVersion } from "viem/account-abstraction"
|
|
18
18
|
|
|
19
|
-
export type PermissionPlugin
|
|
20
|
-
entryPoint,
|
|
21
|
-
"PermissionValidator"
|
|
22
|
-
> & {
|
|
19
|
+
export type PermissionPlugin = KernelValidator<"PermissionValidator"> & {
|
|
23
20
|
getPluginSerializationParams: () => PermissionData
|
|
24
21
|
}
|
|
25
22
|
|
|
@@ -53,11 +50,13 @@ export type Policy = {
|
|
|
53
50
|
| (TimestampPolicyParams & { type: "timestamp" })
|
|
54
51
|
}
|
|
55
52
|
|
|
56
|
-
export type PermissionPluginParams<
|
|
53
|
+
export type PermissionPluginParams<
|
|
54
|
+
entryPointVersion extends EntryPointVersion
|
|
55
|
+
> = {
|
|
57
56
|
signer: ModularSigner
|
|
58
57
|
policies: Policy[]
|
|
59
|
-
entryPoint:
|
|
60
|
-
kernelVersion: GetKernelVersion<
|
|
58
|
+
entryPoint: { address: Address; version: entryPointVersion }
|
|
59
|
+
kernelVersion: GetKernelVersion<entryPointVersion>
|
|
61
60
|
flag?: PolicyFlags
|
|
62
61
|
}
|
|
63
62
|
|
package/utils.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { EntryPoint } from "permissionless/types"
|
|
2
1
|
import type { PermissionAccountParams, PermissionPlugin } from "./types.js"
|
|
3
2
|
|
|
4
3
|
export function base64ToBytes(base64: string) {
|
|
@@ -11,10 +10,10 @@ export function bytesToBase64(bytes: Uint8Array) {
|
|
|
11
10
|
return btoa(binString)
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
export function isPermissionValidatorPlugin
|
|
13
|
+
export function isPermissionValidatorPlugin(
|
|
15
14
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
16
15
|
plugin: any
|
|
17
|
-
): plugin is PermissionPlugin
|
|
16
|
+
): plugin is PermissionPlugin {
|
|
18
17
|
return plugin?.getPluginSerializationParams !== undefined
|
|
19
18
|
}
|
|
20
19
|
|