@zerodev/permissions 5.4.10 → 5.5.0-beta.1

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.
Files changed (46) hide show
  1. package/_cjs/deserializePermissionAccount.js +9 -12
  2. package/_cjs/deserializePermissionAccount.js.map +1 -1
  3. package/_cjs/serializeMultiChainPermissionAccounts.js.map +1 -1
  4. package/_cjs/serializePermissionAccount.js.map +1 -1
  5. package/_cjs/signers/toECDSASigner.js +5 -11
  6. package/_cjs/signers/toECDSASigner.js.map +1 -1
  7. package/_cjs/signers/toWebAuthnSigner.js +3 -4
  8. package/_cjs/signers/toWebAuthnSigner.js.map +1 -1
  9. package/_cjs/toPermissionValidator.js +11 -8
  10. package/_cjs/toPermissionValidator.js.map +1 -1
  11. package/_cjs/utils.js.map +1 -1
  12. package/_esm/deserializePermissionAccount.js +9 -12
  13. package/_esm/deserializePermissionAccount.js.map +1 -1
  14. package/_esm/serializeMultiChainPermissionAccounts.js.map +1 -1
  15. package/_esm/serializePermissionAccount.js.map +1 -1
  16. package/_esm/signers/toECDSASigner.js +4 -10
  17. package/_esm/signers/toECDSASigner.js.map +1 -1
  18. package/_esm/signers/toWebAuthnSigner.js +1 -2
  19. package/_esm/signers/toWebAuthnSigner.js.map +1 -1
  20. package/_esm/toPermissionValidator.js +10 -7
  21. package/_esm/toPermissionValidator.js.map +1 -1
  22. package/_esm/utils.js.map +1 -1
  23. package/_types/deserializePermissionAccount.d.ts +262 -4
  24. package/_types/deserializePermissionAccount.d.ts.map +1 -1
  25. package/_types/serializeMultiChainPermissionAccounts.d.ts +5 -5
  26. package/_types/serializeMultiChainPermissionAccounts.d.ts.map +1 -1
  27. package/_types/serializePermissionAccount.d.ts +3 -3
  28. package/_types/serializePermissionAccount.d.ts.map +1 -1
  29. package/_types/signers/toECDSASigner.d.ts +4 -5
  30. package/_types/signers/toECDSASigner.d.ts.map +1 -1
  31. package/_types/signers/toWebAuthnSigner.d.ts.map +1 -1
  32. package/_types/toPermissionValidator.d.ts +3 -3
  33. package/_types/toPermissionValidator.d.ts.map +1 -1
  34. package/_types/types.d.ts +6 -6
  35. package/_types/types.d.ts.map +1 -1
  36. package/_types/utils.d.ts +1 -2
  37. package/_types/utils.d.ts.map +1 -1
  38. package/deserializePermissionAccount.ts +16 -37
  39. package/package.json +4 -5
  40. package/serializeMultiChainPermissionAccounts.ts +9 -12
  41. package/serializePermissionAccount.ts +4 -4
  42. package/signers/toECDSASigner.ts +11 -23
  43. package/signers/toWebAuthnSigner.ts +3 -2
  44. package/toPermissionValidator.ts +18 -16
  45. package/types.ts +8 -8
  46. package/utils.ts +2 -3
@@ -1,41 +1,29 @@
1
- import { constants, fixSignedData } from "@zerodev/sdk"
1
+ import { constants, fixSignedData, toSigner } from "@zerodev/sdk"
2
+ import type { Signer } from "@zerodev/sdk/types"
2
3
  import type { TypedData } from "abitype"
3
- import {
4
- SignTransactionNotSupportedBySmartAccount,
5
- type SmartAccountSigner
6
- } from "permissionless/accounts"
7
- import type { Address, LocalAccount, TypedDataDefinition } from "viem"
4
+ import type { TypedDataDefinition } from "viem"
8
5
  import { toAccount } from "viem/accounts"
9
6
  import { ECDSA_SIGNER_CONTRACT } from "../constants.js"
10
7
  import type { ModularSigner, ModularSignerParams } from "../types.js"
11
8
 
12
- export type ECDSAModularSignerParams<
13
- TSource extends string = "custom",
14
- TAddress extends Address = Address
15
- > = ModularSignerParams & {
16
- signer: SmartAccountSigner<TSource, TAddress>
9
+ export type ECDSAModularSignerParams = ModularSignerParams & {
10
+ signer: Signer
17
11
  }
18
12
 
19
- export function toECDSASigner<
20
- TSource extends string = "custom",
21
- TAddress extends Address = Address
22
- >({
13
+ export async function toECDSASigner({
23
14
  signer,
24
15
  signerContractAddress = ECDSA_SIGNER_CONTRACT
25
- }: ECDSAModularSignerParams<TSource, TAddress>): ModularSigner {
26
- const viemSigner: LocalAccount = {
27
- ...signer,
28
- signTransaction: (_, __) => {
29
- throw new SignTransactionNotSupportedBySmartAccount()
30
- }
31
- } as LocalAccount
16
+ }: ECDSAModularSignerParams): Promise<ModularSigner> {
17
+ const viemSigner = await toSigner({ signer })
32
18
  const account = toAccount({
33
19
  address: viemSigner.address,
34
20
  async signMessage({ message }) {
35
21
  return fixSignedData(await viemSigner.signMessage({ message }))
36
22
  },
37
23
  async signTransaction(_, __) {
38
- throw new SignTransactionNotSupportedBySmartAccount()
24
+ throw new Error(
25
+ "Smart account signer doesn't need to sign transactions"
26
+ )
39
27
  },
40
28
  async signTypedData<
41
29
  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 SignTransactionNotSupportedBySmartAccount()
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>,
@@ -1,18 +1,19 @@
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,
13
9
  slice,
14
10
  zeroAddress
15
11
  } from "viem"
12
+ import {
13
+ type EntryPointVersion,
14
+ type UserOperation,
15
+ getUserOperationHash
16
+ } from "viem/account-abstraction"
16
17
  import { getChainId, readContract } from "viem/actions"
17
18
  import { getAction } from "viem/utils"
18
19
  import { PolicyFlags } from "./constants.js"
@@ -25,23 +26,20 @@ import type {
25
26
  } from "./types.js"
26
27
 
27
28
  export async function toPermissionValidator<
28
- entryPoint extends EntryPoint,
29
- TTransport extends Transport = Transport,
30
- TChain extends Chain | undefined = Chain | undefined
29
+ entryPointVersion extends EntryPointVersion
31
30
  >(
32
- client: Client<TTransport, TChain, undefined>,
31
+ client: Client,
33
32
  {
34
33
  signer,
35
34
  policies,
36
- entryPoint: entryPointAddress,
35
+ entryPoint,
37
36
  kernelVersion: _,
38
37
  flag = PolicyFlags.FOR_ALL_VALIDATION
39
- }: PermissionPluginParams<entryPoint>
40
- ): Promise<PermissionPlugin<entryPoint>> {
38
+ }: PermissionPluginParams<entryPointVersion>
39
+ ): Promise<PermissionPlugin> {
41
40
  const chainId = await getChainId(client)
42
- const entryPointVersion = getEntryPointVersion(entryPointAddress)
43
41
 
44
- if (entryPointVersion !== "v0.7") {
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: { ...userOperation, signature: "0x" },
105
- entryPoint: entryPointAddress,
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 getDummySignature(_userOperation) {
124
+ async getStubSignature(_userOperation) {
123
125
  return concat(["0xff", signer.getDummySignature()])
124
126
  },
125
127
  getPluginSerializationParams: (): PermissionData => {
package/types.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { KernelValidator } from "@zerodev/sdk"
2
2
  import type {
3
3
  Action,
4
+ EntryPointType,
4
5
  GetKernelVersion,
5
6
  PluginValidityData
6
7
  } from "@zerodev/sdk/types"
7
- import type { EntryPoint } from "permissionless/types/entrypoint"
8
8
  import type { Abi, Address, Hex, LocalAccount } from "viem"
9
+ import type { EntryPointVersion } from "viem/account-abstraction"
9
10
  import type { PolicyFlags } from "./constants.js"
10
11
  import type {
11
12
  CallPolicyParams,
@@ -16,10 +17,7 @@ import type {
16
17
  TimestampPolicyParams
17
18
  } from "./policies/index.js"
18
19
 
19
- export type PermissionPlugin<entryPoint extends EntryPoint> = KernelValidator<
20
- entryPoint,
21
- "PermissionValidator"
22
- > & {
20
+ export type PermissionPlugin = KernelValidator<"PermissionValidator"> & {
23
21
  getPluginSerializationParams: () => PermissionData
24
22
  }
25
23
 
@@ -53,11 +51,13 @@ export type Policy = {
53
51
  | (TimestampPolicyParams & { type: "timestamp" })
54
52
  }
55
53
 
56
- export type PermissionPluginParams<entryPoint extends EntryPoint> = {
54
+ export type PermissionPluginParams<
55
+ entryPointVersion extends EntryPointVersion
56
+ > = {
57
57
  signer: ModularSigner
58
58
  policies: Policy[]
59
- entryPoint: entryPoint
60
- kernelVersion: GetKernelVersion<entryPoint>
59
+ entryPoint: EntryPointType<entryPointVersion>
60
+ kernelVersion: GetKernelVersion<entryPointVersion>
61
61
  flag?: PolicyFlags
62
62
  }
63
63
 
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<entryPoint extends EntryPoint>(
13
+ export function isPermissionValidatorPlugin(
15
14
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
16
15
  plugin: any
17
- ): plugin is PermissionPlugin<entryPoint> {
16
+ ): plugin is PermissionPlugin {
18
17
  return plugin?.getPluginSerializationParams !== undefined
19
18
  }
20
19