@zerodev/sdk 5.4.0-beta.0 → 5.4.0-beta.2

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 (116) hide show
  1. package/_cjs/accounts/kernel/createKernelAccount.js +5 -3
  2. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  3. package/_cjs/accounts/kernel/v1/createKernelAccountV1.js +4 -2
  4. package/_cjs/accounts/kernel/v1/createKernelAccountV1.js.map +1 -1
  5. package/_cjs/accounts/kernel/v2/createKernelAccountV0_2.js +4 -2
  6. package/_cjs/accounts/kernel/v2/createKernelAccountV0_2.js.map +1 -1
  7. package/_cjs/actions/account-client/changeSudoValidator.js.map +1 -1
  8. package/_cjs/actions/index.js +2 -0
  9. package/_cjs/actions/index.js.map +1 -1
  10. package/_cjs/actions/paymaster/sponsorUserOperation.js.map +1 -1
  11. package/_cjs/actions/public/index.js +3 -1
  12. package/_cjs/actions/public/index.js.map +1 -1
  13. package/_cjs/actions/public/isSmartAccountDeployed.js +14 -0
  14. package/_cjs/actions/public/isSmartAccountDeployed.js.map +1 -0
  15. package/_cjs/clients/decorators/kernel.js.map +1 -1
  16. package/_cjs/clients/paymasterClient.js.map +1 -1
  17. package/_cjs/constants.js +14 -1
  18. package/_cjs/constants.js.map +1 -1
  19. package/_cjs/errors/index.js +9 -1
  20. package/_cjs/errors/index.js.map +1 -1
  21. package/_cjs/index.js +2 -0
  22. package/_cjs/index.js.map +1 -1
  23. package/_cjs/types/index.js.map +1 -1
  24. package/_cjs/types/kernel.js.map +1 -1
  25. package/_cjs/types/utils.js +3 -0
  26. package/_cjs/types/utils.js.map +1 -0
  27. package/_cjs/utils/index.js +5 -0
  28. package/_cjs/utils/index.js.map +1 -0
  29. package/_cjs/utils/toSigner.js +58 -0
  30. package/_cjs/utils/toSigner.js.map +1 -0
  31. package/_esm/accounts/kernel/createKernelAccount.js +5 -3
  32. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  33. package/_esm/accounts/kernel/v1/createKernelAccountV1.js +4 -2
  34. package/_esm/accounts/kernel/v1/createKernelAccountV1.js.map +1 -1
  35. package/_esm/accounts/kernel/v2/createKernelAccountV0_2.js +4 -2
  36. package/_esm/accounts/kernel/v2/createKernelAccountV0_2.js.map +1 -1
  37. package/_esm/actions/account-client/changeSudoValidator.js.map +1 -1
  38. package/_esm/actions/index.js +1 -0
  39. package/_esm/actions/index.js.map +1 -1
  40. package/_esm/actions/paymaster/sponsorUserOperation.js.map +1 -1
  41. package/_esm/actions/public/index.js +1 -0
  42. package/_esm/actions/public/index.js.map +1 -1
  43. package/_esm/actions/public/isSmartAccountDeployed.js +10 -0
  44. package/_esm/actions/public/isSmartAccountDeployed.js.map +1 -0
  45. package/_esm/clients/decorators/kernel.js.map +1 -1
  46. package/_esm/clients/paymasterClient.js.map +1 -1
  47. package/_esm/constants.js +12 -0
  48. package/_esm/constants.js.map +1 -1
  49. package/_esm/errors/index.js +7 -0
  50. package/_esm/errors/index.js.map +1 -1
  51. package/_esm/index.js +2 -0
  52. package/_esm/index.js.map +1 -1
  53. package/_esm/types/index.js.map +1 -1
  54. package/_esm/types/kernel.js.map +1 -1
  55. package/_esm/types/utils.js +2 -0
  56. package/_esm/types/utils.js.map +1 -0
  57. package/_esm/utils/index.js +2 -0
  58. package/_esm/utils/index.js.map +1 -0
  59. package/_esm/utils/toSigner.js +56 -0
  60. package/_esm/utils/toSigner.js.map +1 -0
  61. package/_types/accounts/kernel/createKernelAccount.d.ts +3 -6
  62. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  63. package/_types/accounts/kernel/v1/createKernelAccountV1.d.ts.map +1 -1
  64. package/_types/accounts/kernel/v2/createKernelAccountV0_2.d.ts +2 -2
  65. package/_types/accounts/kernel/v2/createKernelAccountV0_2.d.ts.map +1 -1
  66. package/_types/actions/account-client/changeSudoValidator.d.ts.map +1 -1
  67. package/_types/actions/index.d.ts +1 -0
  68. package/_types/actions/index.d.ts.map +1 -1
  69. package/_types/actions/paymaster/sponsorUserOperation.d.ts +3 -6
  70. package/_types/actions/paymaster/sponsorUserOperation.d.ts.map +1 -1
  71. package/_types/actions/public/index.d.ts +1 -0
  72. package/_types/actions/public/index.d.ts.map +1 -1
  73. package/_types/actions/public/isSmartAccountDeployed.d.ts +3 -0
  74. package/_types/actions/public/isSmartAccountDeployed.d.ts.map +1 -0
  75. package/_types/clients/decorators/kernel.d.ts +5 -19
  76. package/_types/clients/decorators/kernel.d.ts.map +1 -1
  77. package/_types/clients/paymasterClient.d.ts +3 -6
  78. package/_types/clients/paymasterClient.d.ts.map +1 -1
  79. package/_types/constants.d.ts +3 -1
  80. package/_types/constants.d.ts.map +1 -1
  81. package/_types/errors/index.d.ts +3 -0
  82. package/_types/errors/index.d.ts.map +1 -1
  83. package/_types/index.d.ts +2 -0
  84. package/_types/index.d.ts.map +1 -1
  85. package/_types/types/index.d.ts +2 -1
  86. package/_types/types/index.d.ts.map +1 -1
  87. package/_types/types/kernel.d.ts +5 -4
  88. package/_types/types/kernel.d.ts.map +1 -1
  89. package/_types/types/utils.d.ts +3 -0
  90. package/_types/types/utils.d.ts.map +1 -0
  91. package/_types/utils/index.d.ts +2 -0
  92. package/_types/utils/index.d.ts.map +1 -0
  93. package/_types/utils/toSigner.d.ts +7 -0
  94. package/_types/utils/toSigner.d.ts.map +1 -0
  95. package/_types/utils.d.ts +2 -5
  96. package/_types/utils.d.ts.map +1 -1
  97. package/accounts/kernel/createKernelAccount.ts +10 -11
  98. package/accounts/kernel/v1/createKernelAccountV1.ts +7 -5
  99. package/accounts/kernel/v2/createKernelAccountV0_2.ts +9 -20
  100. package/actions/account-client/changeSudoValidator.ts +1 -1
  101. package/actions/index.ts +2 -0
  102. package/actions/paymaster/sponsorUserOperation.ts +2 -5
  103. package/actions/public/index.ts +1 -0
  104. package/actions/public/isSmartAccountDeployed.ts +18 -0
  105. package/clients/decorators/kernel.ts +4 -5
  106. package/clients/paymasterClient.ts +5 -6
  107. package/constants.ts +20 -0
  108. package/errors/index.ts +8 -0
  109. package/index.ts +2 -0
  110. package/package.json +1 -1
  111. package/types/index.ts +5 -1
  112. package/types/kernel.ts +6 -4
  113. package/types/utils.ts +15 -0
  114. package/utils/index.ts +1 -0
  115. package/utils/toSigner.ts +106 -0
  116. package/utils.ts +2 -2
@@ -0,0 +1,106 @@
1
+ // Copied from: https://github.com/pimlicolabs/permissionless.js/blob/main/packages/permissionless/utils/toOwner.ts
2
+ import {
3
+ type Account,
4
+ type Address,
5
+ type Chain,
6
+ type EIP1193Provider,
7
+ type EIP1193RequestFn,
8
+ type EIP1474Methods,
9
+ type LocalAccount,
10
+ type Transport,
11
+ type TypedData,
12
+ type TypedDataDefinition,
13
+ type WalletClient,
14
+ createWalletClient,
15
+ custom
16
+ } from "viem"
17
+ import { toAccount } from "viem/accounts"
18
+
19
+ import { signMessage, signTypedData } from "viem/actions"
20
+ import type { Signer } from "../types"
21
+
22
+ export async function toSigner({
23
+ signer,
24
+ address
25
+ }: {
26
+ signer: Signer
27
+ address?: Address
28
+ }): Promise<LocalAccount> {
29
+ if ("type" in signer && signer.type === "local") {
30
+ return signer as LocalAccount
31
+ }
32
+
33
+ let walletClient:
34
+ | WalletClient<Transport, Chain | undefined, Account>
35
+ | undefined = undefined
36
+
37
+ if ("request" in signer) {
38
+ if (!address) {
39
+ try {
40
+ ;[address] = await (
41
+ signer.request as EIP1193RequestFn<EIP1474Methods>
42
+ )({
43
+ method: "eth_requestAccounts"
44
+ })
45
+ } catch {
46
+ ;[address] = await (
47
+ signer.request as EIP1193RequestFn<EIP1474Methods>
48
+ )({
49
+ method: "eth_accounts"
50
+ })
51
+ }
52
+ }
53
+ if (!address) {
54
+ // For TS to be happy
55
+ throw new Error("address is required")
56
+ }
57
+ walletClient = createWalletClient({
58
+ account: address,
59
+ transport: custom(signer as EIP1193Provider)
60
+ })
61
+ }
62
+
63
+ if (!walletClient) {
64
+ walletClient = signer as WalletClient<
65
+ Transport,
66
+ Chain | undefined,
67
+ Account
68
+ >
69
+ }
70
+
71
+ return toAccount({
72
+ address: walletClient.account.address,
73
+ async signMessage({ message }) {
74
+ return signMessage(
75
+ walletClient as WalletClient<
76
+ Transport,
77
+ Chain | undefined,
78
+ Account
79
+ >,
80
+ { message }
81
+ )
82
+ },
83
+ async signTypedData(typedData) {
84
+ const { primaryType, domain, message, types } =
85
+ typedData as TypedDataDefinition<TypedData, string>
86
+ return signTypedData(
87
+ walletClient as WalletClient<
88
+ Transport,
89
+ Chain | undefined,
90
+ Account
91
+ >,
92
+ {
93
+ primaryType,
94
+ domain,
95
+ message,
96
+ types
97
+ }
98
+ )
99
+ },
100
+ async signTransaction(_) {
101
+ throw new Error(
102
+ "Smart account signer doesn't need to sign transactions"
103
+ )
104
+ }
105
+ }) as LocalAccount
106
+ }
package/utils.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  import type { EntryPointVersion } from "viem/account-abstraction"
15
15
  import type { ZeroDevPaymasterClient } from "./clients/paymasterClient.js"
16
16
  import type { CALL_TYPE, EXEC_TYPE } from "./constants.js"
17
- import type { GetKernelVersion } from "./types/kernel.js"
17
+ import type { EntryPointType, GetKernelVersion } from "./types/kernel.js"
18
18
 
19
19
  export enum KERNEL_FEATURES {
20
20
  ERC1271_SIG_WRAPPER = "ERC1271_SIG_WRAPPER",
@@ -50,7 +50,7 @@ export const getERC20PaymasterApproveCall = async <
50
50
  }: {
51
51
  gasToken: Address
52
52
  approveAmount: bigint
53
- entryPoint: { address: Address; version: entryPointVersion }
53
+ entryPoint: EntryPointType<entryPointVersion>
54
54
  }
55
55
  ): Promise<{ to: Address; value: bigint; data: Hex }> => {
56
56
  const response = await client.request({