@zerodev/sdk 5.2.0-alpha-1 → 5.2.0-alpha-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 (215) hide show
  1. package/README.md +3 -0
  2. package/_cjs/accounts/index.js +9 -2
  3. package/_cjs/accounts/index.js.map +1 -1
  4. package/_cjs/accounts/kernel/abi/EIP1271Abi.js +37 -0
  5. package/_cjs/accounts/kernel/abi/EIP1271Abi.js.map +1 -0
  6. package/_cjs/accounts/kernel/abi/SafeCreateCallAbi.js +9 -0
  7. package/_cjs/accounts/kernel/abi/SafeCreateCallAbi.js.map +1 -0
  8. package/_cjs/accounts/kernel/createKernelAccount.js +123 -364
  9. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  10. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeCallData.js +26 -0
  11. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeCallData.js.map +1 -0
  12. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.js +16 -0
  13. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.js.map +1 -0
  14. package/_cjs/accounts/kernel/utils/account/ep0_7/encodeCallData.js +30 -0
  15. package/_cjs/accounts/kernel/utils/account/ep0_7/encodeCallData.js.map +1 -0
  16. package/_cjs/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.js +18 -0
  17. package/_cjs/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.js.map +1 -0
  18. package/_cjs/accounts/kernel/utils/common/accountMetadata.js +46 -0
  19. package/_cjs/accounts/kernel/utils/common/accountMetadata.js.map +1 -0
  20. package/_cjs/accounts/kernel/utils/common/eip712WrapHash.js +28 -0
  21. package/_cjs/accounts/kernel/utils/common/eip712WrapHash.js.map +1 -0
  22. package/_cjs/accounts/kernel/utils/common/encodeSafeCreateCall.js +14 -0
  23. package/_cjs/accounts/kernel/utils/common/encodeSafeCreateCall.js.map +1 -0
  24. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.js +22 -0
  25. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.js.map +1 -0
  26. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.js +14 -0
  27. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.js.map +1 -0
  28. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.js +14 -0
  29. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.js.map +1 -0
  30. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.js +42 -0
  31. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.js.map +1 -0
  32. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteCall.js +29 -0
  33. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteCall.js.map +1 -0
  34. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.js +13 -0
  35. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.js.map +1 -0
  36. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.js +13 -0
  37. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.js.map +1 -0
  38. package/_cjs/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.js +9 -0
  39. package/_cjs/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.js.map +1 -0
  40. package/_cjs/accounts/kernel/utils/types.js +3 -0
  41. package/_cjs/accounts/kernel/utils/types.js.map +1 -0
  42. package/_cjs/accounts/kernel/v1/createKernelV1Account.js +1 -2
  43. package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  44. package/_cjs/accounts/kernel/v2/abi/KernelAccountV2Abi.js +377 -0
  45. package/_cjs/accounts/kernel/v2/abi/KernelAccountV2Abi.js.map +1 -0
  46. package/_cjs/accounts/kernel/v2/abi/KernelFactoryV2Abi.js +115 -0
  47. package/_cjs/accounts/kernel/v2/abi/KernelFactoryV2Abi.js.map +1 -0
  48. package/_cjs/accounts/kernel/v2/createKernelV2Account.js +226 -0
  49. package/_cjs/accounts/kernel/v2/createKernelV2Account.js.map +1 -0
  50. package/_cjs/accounts/utils/multisend.js.map +1 -0
  51. package/_cjs/accounts/utils/toKernelPluginManager.js +4 -4
  52. package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
  53. package/_cjs/constants.js +2 -1
  54. package/_cjs/constants.js.map +1 -1
  55. package/_cjs/index.js +3 -2
  56. package/_cjs/index.js.map +1 -1
  57. package/_cjs/types/kernel.js.map +1 -1
  58. package/_cjs/utils.js +1 -1
  59. package/_cjs/utils.js.map +1 -1
  60. package/_esm/accounts/index.js +5 -1
  61. package/_esm/accounts/index.js.map +1 -1
  62. package/_esm/accounts/kernel/abi/EIP1271Abi.js +34 -0
  63. package/_esm/accounts/kernel/abi/EIP1271Abi.js.map +1 -0
  64. package/_esm/accounts/kernel/abi/SafeCreateCallAbi.js +6 -0
  65. package/_esm/accounts/kernel/abi/SafeCreateCallAbi.js.map +1 -0
  66. package/_esm/accounts/kernel/createKernelAccount.js +136 -384
  67. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  68. package/_esm/accounts/kernel/utils/account/ep0_6/encodeCallData.js +23 -0
  69. package/_esm/accounts/kernel/utils/account/ep0_6/encodeCallData.js.map +1 -0
  70. package/_esm/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.js +13 -0
  71. package/_esm/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.js.map +1 -0
  72. package/_esm/accounts/kernel/utils/account/ep0_7/encodeCallData.js +28 -0
  73. package/_esm/accounts/kernel/utils/account/ep0_7/encodeCallData.js.map +1 -0
  74. package/_esm/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.js +15 -0
  75. package/_esm/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.js.map +1 -0
  76. package/_esm/accounts/kernel/utils/common/accountMetadata.js +42 -0
  77. package/_esm/accounts/kernel/utils/common/accountMetadata.js.map +1 -0
  78. package/_esm/accounts/kernel/utils/common/eip712WrapHash.js +24 -0
  79. package/_esm/accounts/kernel/utils/common/eip712WrapHash.js.map +1 -0
  80. package/_esm/accounts/kernel/utils/common/encodeSafeCreateCall.js +10 -0
  81. package/_esm/accounts/kernel/utils/common/encodeSafeCreateCall.js.map +1 -0
  82. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.js +18 -0
  83. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.js.map +1 -0
  84. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.js +10 -0
  85. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.js.map +1 -0
  86. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.js +10 -0
  87. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.js.map +1 -0
  88. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.js +38 -0
  89. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.js.map +1 -0
  90. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteCall.js +25 -0
  91. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteCall.js.map +1 -0
  92. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.js +9 -0
  93. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.js.map +1 -0
  94. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.js +9 -0
  95. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.js.map +1 -0
  96. package/_esm/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.js +5 -0
  97. package/_esm/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.js.map +1 -0
  98. package/_esm/accounts/kernel/utils/types.js +2 -0
  99. package/_esm/accounts/kernel/utils/types.js.map +1 -0
  100. package/_esm/accounts/kernel/v1/createKernelV1Account.js +1 -2
  101. package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  102. package/_esm/accounts/kernel/v2/abi/KernelAccountV2Abi.js +374 -0
  103. package/_esm/accounts/kernel/v2/abi/KernelAccountV2Abi.js.map +1 -0
  104. package/_esm/accounts/kernel/v2/abi/KernelFactoryV2Abi.js +112 -0
  105. package/_esm/accounts/kernel/v2/abi/KernelFactoryV2Abi.js.map +1 -0
  106. package/_esm/accounts/kernel/v2/createKernelV2Account.js +264 -0
  107. package/_esm/accounts/kernel/v2/createKernelV2Account.js.map +1 -0
  108. package/_esm/accounts/{kernel/v1 → utils}/multisend.js +1 -1
  109. package/_esm/accounts/utils/multisend.js.map +1 -0
  110. package/_esm/accounts/utils/toKernelPluginManager.js +4 -4
  111. package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
  112. package/_esm/constants.js +3 -0
  113. package/_esm/constants.js.map +1 -1
  114. package/_esm/index.js +1 -1
  115. package/_esm/index.js.map +1 -1
  116. package/_esm/types/kernel.js.map +1 -1
  117. package/_esm/utils.js +1 -1
  118. package/_esm/utils.js.map +1 -1
  119. package/_types/accounts/index.d.ts +5 -1
  120. package/_types/accounts/index.d.ts.map +1 -1
  121. package/_types/accounts/kernel/abi/EIP1271Abi.d.ts +54 -0
  122. package/_types/accounts/kernel/abi/EIP1271Abi.d.ts.map +1 -0
  123. package/_types/accounts/kernel/abi/SafeCreateCallAbi.d.ts +35 -0
  124. package/_types/accounts/kernel/abi/SafeCreateCallAbi.d.ts.map +1 -0
  125. package/_types/accounts/kernel/createKernelAccount.d.ts +0 -54
  126. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  127. package/_types/accounts/kernel/utils/account/ep0_6/encodeCallData.d.ts +4 -0
  128. package/_types/accounts/kernel/utils/account/ep0_6/encodeCallData.d.ts.map +1 -0
  129. package/_types/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.d.ts +3 -0
  130. package/_types/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.d.ts.map +1 -0
  131. package/_types/accounts/kernel/utils/account/ep0_7/encodeCallData.d.ts +4 -0
  132. package/_types/accounts/kernel/utils/account/ep0_7/encodeCallData.d.ts.map +1 -0
  133. package/_types/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.d.ts +3 -0
  134. package/_types/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.d.ts.map +1 -0
  135. package/_types/accounts/kernel/utils/common/accountMetadata.d.ts +10 -0
  136. package/_types/accounts/kernel/utils/common/accountMetadata.d.ts.map +1 -0
  137. package/_types/accounts/kernel/utils/common/eip712WrapHash.d.ts +4 -0
  138. package/_types/accounts/kernel/utils/common/eip712WrapHash.d.ts.map +1 -0
  139. package/_types/accounts/kernel/utils/common/encodeSafeCreateCall.d.ts +2 -0
  140. package/_types/accounts/kernel/utils/common/encodeSafeCreateCall.d.ts.map +1 -0
  141. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.d.ts +3 -0
  142. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.d.ts.map +1 -0
  143. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.d.ts +3 -0
  144. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.d.ts.map +1 -0
  145. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.d.ts +3 -0
  146. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.d.ts.map +1 -0
  147. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.d.ts +4 -0
  148. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.d.ts.map +1 -0
  149. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteCall.d.ts +16 -0
  150. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteCall.d.ts.map +1 -0
  151. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.d.ts +4 -0
  152. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.d.ts.map +1 -0
  153. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.d.ts +4 -0
  154. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.d.ts.map +1 -0
  155. package/_types/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.d.ts +3 -0
  156. package/_types/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.d.ts.map +1 -0
  157. package/_types/accounts/kernel/utils/types.d.ts +8 -0
  158. package/_types/accounts/kernel/utils/types.d.ts.map +1 -0
  159. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
  160. package/_types/accounts/kernel/v2/abi/KernelAccountV2Abi.d.ts +447 -0
  161. package/_types/accounts/kernel/v2/abi/KernelAccountV2Abi.d.ts.map +1 -0
  162. package/_types/accounts/kernel/v2/abi/KernelFactoryV2Abi.d.ts +109 -0
  163. package/_types/accounts/kernel/v2/abi/KernelFactoryV2Abi.d.ts.map +1 -0
  164. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts +33 -0
  165. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts.map +1 -0
  166. package/_types/accounts/{kernel/v1 → utils}/multisend.d.ts +1 -1
  167. package/_types/accounts/utils/multisend.d.ts.map +1 -0
  168. package/_types/accounts/utils/toKernelPluginManager.d.ts +1 -1
  169. package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
  170. package/_types/constants.d.ts +1 -0
  171. package/_types/constants.d.ts.map +1 -1
  172. package/_types/index.d.ts +1 -1
  173. package/_types/index.d.ts.map +1 -1
  174. package/_types/types/index.d.ts +1 -0
  175. package/_types/types/index.d.ts.map +1 -1
  176. package/_types/types/kernel.d.ts +1 -0
  177. package/_types/types/kernel.d.ts.map +1 -1
  178. package/_types/utils.d.ts +4 -1
  179. package/_types/utils.d.ts.map +1 -1
  180. package/accounts/index.ts +5 -2
  181. package/accounts/kernel/abi/EIP1271Abi.ts +33 -0
  182. package/accounts/kernel/abi/SafeCreateCallAbi.ts +6 -0
  183. package/accounts/kernel/createKernelAccount.ts +164 -502
  184. package/accounts/kernel/utils/account/ep0_6/encodeCallData.ts +32 -0
  185. package/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.ts +18 -0
  186. package/accounts/kernel/utils/account/ep0_7/encodeCallData.ts +40 -0
  187. package/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.ts +20 -0
  188. package/accounts/kernel/utils/common/accountMetadata.ts +62 -0
  189. package/accounts/kernel/utils/common/eip712WrapHash.ts +48 -0
  190. package/accounts/kernel/utils/common/encodeSafeCreateCall.ts +14 -0
  191. package/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.ts +19 -0
  192. package/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.ts +11 -0
  193. package/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.ts +11 -0
  194. package/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.ts +51 -0
  195. package/accounts/kernel/utils/ep0_7/encodeExecuteCall.ts +38 -0
  196. package/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.ts +16 -0
  197. package/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.ts +16 -0
  198. package/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.ts +11 -0
  199. package/accounts/kernel/utils/types.ts +8 -0
  200. package/accounts/kernel/v1/createKernelV1Account.ts +2 -3
  201. package/accounts/kernel/v2/abi/KernelAccountV2Abi.ts +373 -0
  202. package/accounts/kernel/v2/abi/KernelFactoryV2Abi.ts +111 -0
  203. package/accounts/kernel/v2/createKernelV2Account.ts +409 -0
  204. package/accounts/{kernel/v1 → utils}/multisend.ts +1 -1
  205. package/accounts/utils/toKernelPluginManager.ts +6 -7
  206. package/constants.ts +5 -0
  207. package/index.ts +2 -1
  208. package/package.json +1 -1
  209. package/types/index.ts +2 -0
  210. package/types/kernel.ts +1 -0
  211. package/utils.ts +7 -1
  212. package/_cjs/accounts/kernel/v1/multisend.js.map +0 -1
  213. package/_esm/accounts/kernel/v1/multisend.js.map +0 -1
  214. package/_types/accounts/kernel/v1/multisend.d.ts.map +0 -1
  215. /package/_cjs/accounts/{kernel/v1 → utils}/multisend.js +0 -0
@@ -6,7 +6,8 @@ import {
6
6
  } from "permissionless"
7
7
  import {
8
8
  SignTransactionNotSupportedBySmartAccount,
9
- type SmartAccount
9
+ type SmartAccount,
10
+ toSmartAccount
10
11
  } from "permissionless/accounts"
11
12
  import type {
12
13
  ENTRYPOINT_ADDRESS_V06_TYPE,
@@ -17,55 +18,37 @@ import {
17
18
  type Address,
18
19
  type Chain,
19
20
  type Client,
20
- type EncodeDeployDataParameters,
21
- type Hash,
22
21
  type Hex,
23
22
  type Transport,
24
23
  type TypedDataDefinition,
25
24
  concatHex,
26
- decodeFunctionResult,
27
- encodeAbiParameters,
28
- encodeDeployData,
29
25
  encodeFunctionData,
30
26
  getTypesForEIP712Domain,
31
27
  hashMessage,
32
28
  hashTypedData,
33
- keccak256,
34
29
  pad,
35
- parseAbi,
36
- publicActions,
37
- stringToHex,
38
- toHex,
39
30
  validateTypedData,
40
31
  zeroAddress
41
32
  } from "viem"
42
- import { toAccount } from "viem/accounts"
43
- import { CALL_TYPE, EXEC_TYPE, KERNEL_NAME } from "../../constants.js"
44
33
  import type {
45
34
  KernelEncodeCallDataArgs,
46
35
  KernelPluginManager,
47
36
  KernelPluginManagerParams
48
37
  } from "../../types/kernel.js"
49
- import {
50
- KERNEL_FEATURES,
51
- getExecMode,
52
- getKernelVersion,
53
- hasKernelFeature
54
- } from "../../utils.js"
55
- import {
56
- getKernelImplementationAddress,
57
- wrapSignatureWith6492
58
- } from "../utils/6492.js"
38
+ import { KERNEL_FEATURES, hasKernelFeature } from "../../utils.js"
59
39
  import { parseFactoryAddressAndCallDataFromAccountInitCode } from "../utils/index.js"
60
40
  import {
61
41
  isKernelPluginManager,
62
42
  toKernelPluginManager
63
43
  } from "../utils/toKernelPluginManager.js"
64
- import { KernelExecuteAbi, KernelInitAbi } from "./abi/KernelAccountAbi.js"
65
- import {
66
- KernelV3ExecuteAbi,
67
- KernelV3InitAbi
68
- } from "./abi/kernel_v_3_0_0/KernelAccountAbi.js"
44
+ import { KernelInitAbi } from "./abi/KernelAccountAbi.js"
45
+ import { KernelV3InitAbi } from "./abi/kernel_v_3_0_0/KernelAccountAbi.js"
46
+ import { encodeCallData as encodeCallDataEpV06 } from "./utils/account/ep0_6/encodeCallData.js"
47
+ import { encodeDeployCallData as encodeDeployCallDataV06 } from "./utils/account/ep0_6/encodeDeployCallData.js"
48
+ import { encodeCallData as encodeCallDataEpV07 } from "./utils/account/ep0_7/encodeCallData.js"
49
+ import { encodeDeployCallData as encodeDeployCallDataV07 } from "./utils/account/ep0_7/encodeDeployCallData.js"
50
+ import { accountMetadata } from "./utils/common/accountMetadata.js"
51
+ import { eip712WrapHash } from "./utils/common/eip712WrapHash.js"
69
52
 
70
53
  export type KernelSmartAccount<
71
54
  entryPoint extends EntryPoint,
@@ -73,7 +56,6 @@ export type KernelSmartAccount<
73
56
  chain extends Chain | undefined = Chain | undefined
74
57
  > = SmartAccount<entryPoint, "kernelSmartAccount", transport, chain> & {
75
58
  kernelPluginManager: KernelPluginManager<entryPoint>
76
- generateInitCode: () => Promise<Hex>
77
59
  encodeCallData: (args: KernelEncodeCallDataArgs) => Promise<Hex>
78
60
  }
79
61
 
@@ -123,48 +105,6 @@ const createAccountAbi = [
123
105
  }
124
106
  ] as const
125
107
 
126
- // Safe's library for create and create2: https://github.com/safe-global/safe-contracts/blob/0acdd35a203299585438f53885df630f9d486a86/contracts/libraries/CreateCall.sol
127
- // Address was found here: https://github.com/safe-global/safe-deployments/blob/926ec6bbe2ebcac3aa2c2c6c0aff74aa590cbc6a/src/assets/v1.4.1/create_call.json
128
- const createCallAddress = "0x9b35Af71d77eaf8d7e40252370304687390A1A52"
129
-
130
- const createCallAbi = parseAbi([
131
- "function performCreate(uint256 value, bytes memory deploymentData) public returns (address newContract)",
132
- "function performCreate2(uint256 value, bytes memory deploymentData, bytes32 salt) public returns (address newContract)"
133
- ])
134
-
135
- export const EIP1271ABI = [
136
- {
137
- type: "function",
138
- name: "eip712Domain",
139
- inputs: [],
140
- outputs: [
141
- { name: "fields", type: "bytes1", internalType: "bytes1" },
142
- { name: "name", type: "string", internalType: "string" },
143
- { name: "version", type: "string", internalType: "string" },
144
- { name: "chainId", type: "uint256", internalType: "uint256" },
145
- {
146
- name: "verifyingContract",
147
- type: "address",
148
- internalType: "address"
149
- },
150
- { name: "salt", type: "bytes32", internalType: "bytes32" },
151
- { name: "extensions", type: "uint256[]", internalType: "uint256[]" }
152
- ],
153
- stateMutability: "view"
154
- },
155
- {
156
- type: "function",
157
- name: "isValidSignature",
158
- inputs: [
159
- { name: "data", type: "bytes32", internalType: "bytes32" },
160
- { name: "signature", type: "bytes", internalType: "bytes" }
161
- ],
162
- outputs: [
163
- { name: "magicValue", type: "bytes4", internalType: "bytes4" }
164
- ],
165
- stateMutability: "view"
166
- }
167
- ] as const
168
108
  /**
169
109
  * Default addresses for kernel smart account
170
110
  */
@@ -364,146 +304,91 @@ export async function createKernelAccount<
364
304
  accountAddress
365
305
  )
366
306
 
367
- const signHashedMessage = async (messageHash: Hex): Promise<Hex> => {
368
- const kernelImplAddr = await getKernelImplementationAddress(
307
+ return {
308
+ kernelPluginManager,
309
+ ...toSmartAccount({
310
+ address: accountAddress,
311
+ publicKey: accountAddress,
312
+ source: "kernelSmartAccount",
369
313
  client,
370
- accountAddress
371
- )
372
- const kernelVersion = getKernelVersion(
373
- entryPointAddress,
374
- kernelImplAddr
375
- )
376
- if (
377
- !hasKernelFeature(
378
- KERNEL_FEATURES.ERC1271_SIG_WRAPPER,
379
- kernelVersion
380
- )
381
- ) {
382
- return kernelPluginManager.signMessage({
383
- message: {
384
- raw: messageHash
314
+ entryPoint: entryPointAddress,
315
+ // Encode the deploy call data
316
+ async encodeDeployCallData(_tx) {
317
+ if (entryPointVersion === "v0.6") {
318
+ return encodeDeployCallDataV06(_tx)
385
319
  }
386
- })
387
- }
388
-
389
- const domain = await client.request({
390
- method: "eth_call",
391
- params: [
392
- {
393
- to: accountAddress,
394
- data: encodeFunctionData({
395
- abi: EIP1271ABI,
396
- functionName: "eip712Domain"
397
- })
398
- },
399
- "latest"
400
- ]
401
- })
320
+ return encodeDeployCallDataV07(_tx)
321
+ },
322
+ async encodeCallData(_tx) {
323
+ const tx = _tx as KernelEncodeCallDataArgs
324
+ if (
325
+ !Array.isArray(tx) &&
326
+ tx.callType === "call" &&
327
+ tx.to.toLowerCase() === accountAddress.toLowerCase()
328
+ ) {
329
+ return tx.data
330
+ }
331
+ if (entryPointVersion === "v0.6") {
332
+ return encodeCallDataEpV06(tx)
333
+ }
334
+ return encodeCallDataEpV07(tx)
335
+ },
336
+ async getFactory() {
337
+ if (smartAccountDeployed) return undefined
402
338
 
403
- let name: string
404
- let version: string
405
- let chainId: bigint
406
-
407
- if (domain !== "0x") {
408
- const decoded = decodeFunctionResult({
409
- abi: [...EIP1271ABI],
410
- functionName: "eip712Domain",
411
- data: domain
412
- })
413
-
414
- name = decoded[1]
415
- version = decoded[2]
416
- chainId = decoded[3]
417
- } else {
418
- name = KERNEL_NAME
419
- version = kernelVersion
420
- chainId = client.chain
421
- ? BigInt(client.chain.id)
422
- : BigInt(await client.extend(publicActions).getChainId())
423
- }
424
-
425
- const encoded = encodeAbiParameters(
426
- [
427
- { type: "bytes32" },
428
- { type: "bytes32" },
429
- { type: "bytes32" },
430
- { type: "uint256" },
431
- { type: "address" }
432
- ],
433
- [
434
- keccak256(
435
- stringToHex(
436
- "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
437
- )
438
- ),
439
- keccak256(stringToHex(name)),
440
- keccak256(stringToHex(version)),
441
- BigInt(chainId),
442
- accountAddress
443
- ]
444
- )
445
-
446
- const domainSeparator = keccak256(encoded)
447
-
448
- let finalMessageHash = messageHash
449
- if (
450
- hasKernelFeature(
451
- KERNEL_FEATURES.ERC1271_SIG_WRAPPER_WITH_WRAPPED_HASH,
452
- kernelVersion
453
- )
454
- ) {
455
- finalMessageHash = keccak256(
456
- encodeAbiParameters(
457
- [{ type: "bytes32" }, { type: "bytes32" }],
458
- [
459
- keccak256(stringToHex("Kernel(bytes32 hash)")),
460
- messageHash
461
- ]
339
+ smartAccountDeployed = await isSmartAccountDeployed(
340
+ client,
341
+ accountAddress
462
342
  )
463
- )
464
- }
465
-
466
- const digest = keccak256(
467
- concatHex(["0x1901", domainSeparator, finalMessageHash])
468
- )
469
- return kernelPluginManager.signMessage({
470
- message: {
471
- raw: digest
472
- }
473
- })
474
- }
475
343
 
476
- // Build the EOA Signer
477
- const account = toAccount({
478
- address: accountAddress,
479
- async signMessage({ message }) {
480
- const messageHash = hashMessage(message)
481
- const [isDeployed, signature] = await Promise.all([
482
- isSmartAccountDeployed(client, accountAddress),
483
- signHashedMessage(messageHash)
484
- ])
485
- const kernelImplAddr = await getKernelImplementationAddress(
486
- client,
487
- accountAddress
488
- )
489
- const kernelVersion = getKernelVersion(
490
- entryPointAddress,
491
- kernelImplAddr
492
- )
493
- if (
494
- !hasKernelFeature(
495
- KERNEL_FEATURES.ERC1271_WITH_VALIDATOR,
496
- kernelVersion
344
+ if (smartAccountDeployed) return undefined
345
+
346
+ return factoryAddress
347
+ },
348
+
349
+ async getFactoryData() {
350
+ if (smartAccountDeployed) return undefined
351
+
352
+ smartAccountDeployed = await isSmartAccountDeployed(
353
+ client,
354
+ accountAddress
497
355
  )
498
- ) {
499
- return create6492Signature(isDeployed, signature)
500
- }
501
356
 
502
- const validatorInitData =
503
- await kernelPluginManager.getValidatorInitData()
504
- return create6492Signature(
505
- isDeployed,
506
- concatHex([
357
+ if (smartAccountDeployed) return undefined
358
+
359
+ return parseFactoryAddressAndCallDataFromAccountInitCode(
360
+ await generateInitCode()
361
+ )[1]
362
+ },
363
+ async signMessage({ message }) {
364
+ const messageHash = hashMessage(message)
365
+ const { name, chainId, version } = await accountMetadata(
366
+ client,
367
+ accountAddress,
368
+ entryPointAddress
369
+ )
370
+ const wrappedMessageHash = await eip712WrapHash(messageHash, {
371
+ name,
372
+ chainId: Number(chainId),
373
+ version,
374
+ verifyingContract: accountAddress
375
+ })
376
+ const signature = await kernelPluginManager.signMessage({
377
+ message: { raw: wrappedMessageHash }
378
+ })
379
+
380
+ if (
381
+ !hasKernelFeature(
382
+ KERNEL_FEATURES.ERC1271_WITH_VALIDATOR,
383
+ version
384
+ )
385
+ ) {
386
+ return signature
387
+ }
388
+
389
+ const validatorInitData =
390
+ await kernelPluginManager.getValidatorInitData()
391
+ return concatHex([
507
392
  pad(
508
393
  concatHex(["0x1", validatorInitData.validatorAddress]),
509
394
  {
@@ -513,54 +398,54 @@ export async function createKernelAccount<
513
398
  ),
514
399
  signature
515
400
  ])
516
- )
517
- },
518
- async signTransaction(_, __) {
519
- throw new SignTransactionNotSupportedBySmartAccount()
520
- },
521
- async signTypedData(typedData) {
522
- const kernelImplAddr = await getKernelImplementationAddress(
523
- client,
524
- accountAddress
525
- )
526
- const kernelVersion = getKernelVersion(
527
- entryPointAddress,
528
- kernelImplAddr
529
- )
530
- const types = {
531
- EIP712Domain: getTypesForEIP712Domain({
532
- domain: typedData.domain
533
- }),
534
- ...typedData.types
535
- }
401
+ },
402
+ async signTransaction(_, __) {
403
+ throw new SignTransactionNotSupportedBySmartAccount()
404
+ },
405
+ async signTypedData(typedData) {
406
+ const types = {
407
+ EIP712Domain: getTypesForEIP712Domain({
408
+ domain: typedData.domain
409
+ }),
410
+ ...typedData.types
411
+ }
536
412
 
537
- // Need to do a runtime validation check on addresses, byte ranges, integer ranges, etc
538
- // as we can't statically check this with TypeScript.
539
- validateTypedData({
540
- domain: typedData.domain,
541
- message: typedData.message,
542
- primaryType: typedData.primaryType,
543
- types: types
544
- } as TypedDataDefinition)
545
-
546
- const typedHash = hashTypedData(typedData)
547
- const [isDeployed, signature] = await Promise.all([
548
- isSmartAccountDeployed(client, accountAddress),
549
- signHashedMessage(typedHash)
550
- ])
551
- if (
552
- !hasKernelFeature(
553
- KERNEL_FEATURES.ERC1271_WITH_VALIDATOR,
554
- kernelVersion
413
+ // Need to do a runtime validation check on addresses, byte ranges, integer ranges, etc
414
+ // as we can't statically check this with TypeScript.
415
+ validateTypedData({
416
+ domain: typedData.domain,
417
+ message: typedData.message,
418
+ primaryType: typedData.primaryType,
419
+ types: types
420
+ } as TypedDataDefinition)
421
+
422
+ const typedHash = hashTypedData(typedData)
423
+
424
+ const { name, chainId, version } = await accountMetadata(
425
+ client,
426
+ accountAddress,
427
+ entryPointAddress
555
428
  )
556
- ) {
557
- return create6492Signature(isDeployed, signature)
558
- }
559
- const validatorInitData =
560
- await kernelPluginManager.getValidatorInitData()
561
- return create6492Signature(
562
- isDeployed,
563
- concatHex([
429
+ const wrappedMessageHash = await eip712WrapHash(typedHash, {
430
+ name,
431
+ chainId: Number(chainId),
432
+ version,
433
+ verifyingContract: accountAddress
434
+ })
435
+ const signature = await kernelPluginManager.signMessage({
436
+ message: { raw: wrappedMessageHash }
437
+ })
438
+ if (
439
+ !hasKernelFeature(
440
+ KERNEL_FEATURES.ERC1271_WITH_VALIDATOR,
441
+ version
442
+ )
443
+ ) {
444
+ return signature
445
+ }
446
+ const validatorInitData =
447
+ await kernelPluginManager.getValidatorInitData()
448
+ return concatHex([
564
449
  pad(
565
450
  // [TODO] - Make the Validator type dynamic to support permission validators
566
451
  concatHex(["0x1", validatorInitData.validatorAddress]),
@@ -571,263 +456,40 @@ export async function createKernelAccount<
571
456
  ),
572
457
  signature
573
458
  ])
574
- )
575
- }
576
- })
577
-
578
- const create6492Signature = async (
579
- isDeployed: boolean,
580
- signature: Hash
581
- ): Promise<Hash> => {
582
- if (isDeployed) {
583
- return signature
584
- }
585
-
586
- const [factoryAddress, factoryCalldata] =
587
- parseFactoryAddressAndCallDataFromAccountInitCode(
588
- await generateInitCode()
589
- )
590
-
591
- return wrapSignatureWith6492({
592
- factoryAddress,
593
- factoryCalldata,
594
- signature
595
- })
596
- }
597
-
598
- return {
599
- ...account,
600
- client: client,
601
- publicKey: accountAddress,
602
- entryPoint: entryPointAddress,
603
- source: "kernelSmartAccount",
604
- kernelPluginManager,
605
- generateInitCode,
606
-
607
- async getFactory() {
608
- if (smartAccountDeployed) return undefined
609
-
610
- smartAccountDeployed = await isSmartAccountDeployed(
611
- client,
612
- accountAddress
613
- )
614
-
615
- if (smartAccountDeployed) return undefined
616
-
617
- return factoryAddress
618
- },
619
-
620
- async getFactoryData() {
621
- if (smartAccountDeployed) return undefined
622
-
623
- smartAccountDeployed = await isSmartAccountDeployed(
624
- client,
625
- accountAddress
626
- )
627
-
628
- if (smartAccountDeployed) return undefined
629
-
630
- return parseFactoryAddressAndCallDataFromAccountInitCode(
631
- await generateInitCode()
632
- )[1]
633
- },
634
-
635
- // Get the nonce of the smart account
636
- async getNonce() {
637
- const key = await kernelPluginManager.getNonceKey(accountAddress)
638
- return getAccountNonce(client, {
639
- sender: accountAddress,
640
- entryPoint: entryPointAddress,
641
- key
642
- })
643
- },
644
-
645
- // Sign a user operation
646
- async signUserOperation(userOperation) {
647
- return kernelPluginManager.signUserOperation(userOperation)
648
- },
649
-
650
- // Encode the init code
651
- async getInitCode() {
652
- if (smartAccountDeployed) return "0x"
653
-
654
- smartAccountDeployed = await isSmartAccountDeployed(
655
- client,
656
- accountAddress
657
- )
658
-
659
- if (smartAccountDeployed) return "0x"
660
- return generateInitCode()
661
- },
662
-
663
- // [TODO] - CLeanup the encoding functions
664
-
665
- // Encode the deploy call data
666
- async encodeDeployCallData(_tx) {
667
- if (entryPointVersion === "v0.6") {
668
- return encodeFunctionData({
669
- abi: KernelExecuteAbi,
670
- functionName: "executeDelegateCall",
671
- args: [
672
- createCallAddress,
673
- encodeFunctionData({
674
- abi: createCallAbi,
675
- functionName: "performCreate",
676
- args: [
677
- 0n,
678
- encodeDeployData({
679
- abi: _tx.abi,
680
- bytecode: _tx.bytecode,
681
- args: _tx.args
682
- } as EncodeDeployDataParameters)
683
- ]
684
- })
685
- ]
459
+ },
460
+ // Get the nonce of the smart account
461
+ async getNonce() {
462
+ const key =
463
+ await kernelPluginManager.getNonceKey(accountAddress)
464
+ return getAccountNonce(client, {
465
+ sender: accountAddress,
466
+ entryPoint: entryPointAddress,
467
+ key
686
468
  })
687
- }
469
+ },
688
470
 
689
- return encodeFunctionData({
690
- abi: KernelV3ExecuteAbi,
691
- functionName: "execute",
692
- args: [
693
- getExecMode(CALL_TYPE.DELEGATE_CALL, EXEC_TYPE.DEFAULT),
694
- concatHex([
695
- createCallAddress,
696
- encodeFunctionData({
697
- abi: createCallAbi,
698
- functionName: "performCreate",
699
- args: [
700
- 0n,
701
- encodeDeployData({
702
- abi: _tx.abi,
703
- bytecode: _tx.bytecode,
704
- args: _tx.args
705
- } as EncodeDeployDataParameters)
706
- ]
707
- })
708
- ])
709
- ]
710
- })
711
- },
712
-
713
- // Encode a call
714
- async encodeCallData(_tx) {
715
- const tx = _tx as KernelEncodeCallDataArgs
716
- if (Array.isArray(tx)) {
717
- // Encode a batched call
718
- if (entryPointVersion === "v0.6") {
719
- return encodeFunctionData({
720
- abi: KernelExecuteAbi,
721
- functionName: "executeBatch",
722
- args: [
723
- tx.map((txn) => {
724
- if (txn.callType === "delegatecall") {
725
- throw new Error("Cannot batch delegatecall")
726
- }
727
- return {
728
- to: txn.to,
729
- value: txn.value,
730
- data: txn.data
731
- }
732
- })
733
- ]
734
- })
735
- }
736
- return encodeFunctionData({
737
- abi: KernelV3ExecuteAbi,
738
- functionName: "execute",
739
- args: [
740
- getExecMode(CALL_TYPE.BATCH, EXEC_TYPE.DEFAULT),
741
- encodeAbiParameters(
742
- [
743
- {
744
- name: "executionBatch",
745
- type: "tuple[]",
746
- components: [
747
- {
748
- name: "target",
749
- type: "address"
750
- },
751
- {
752
- name: "value",
753
- type: "uint256"
754
- },
755
- {
756
- name: "callData",
757
- type: "bytes"
758
- }
759
- ]
760
- }
761
- ],
762
- [
763
- tx.map((txn) => {
764
- if (txn.callType === "delegatecall") {
765
- throw new Error(
766
- "Cannot batch delegatecall"
767
- )
768
- }
769
- return {
770
- target: txn.to,
771
- value: txn.value,
772
- callData: txn.data
773
- }
774
- })
775
- ]
776
- )
777
- ]
778
- })
779
- }
471
+ // Sign a user operation
472
+ async signUserOperation(userOperation) {
473
+ return kernelPluginManager.signUserOperation(userOperation)
474
+ },
780
475
 
781
- // Default to `call`
782
- if (!tx.callType || tx.callType === "call") {
783
- if (tx.to.toLowerCase() === accountAddress.toLowerCase()) {
784
- return tx.data
785
- }
786
- if (entryPointVersion === "v0.6") {
787
- return encodeFunctionData({
788
- abi: KernelExecuteAbi,
789
- functionName: "execute",
790
- args: [tx.to, tx.value, tx.data, 0]
791
- })
792
- }
793
- return encodeFunctionData({
794
- abi: KernelV3ExecuteAbi,
795
- functionName: "execute",
796
- args: [
797
- getExecMode(CALL_TYPE.SINGLE, EXEC_TYPE.DEFAULT),
798
- concatHex([
799
- tx.to,
800
- pad(toHex(tx.value), { size: 32 }),
801
- tx.data
802
- ])
803
- ]
804
- })
805
- }
476
+ // Get simple dummy signature
477
+ async getDummySignature(userOperation) {
478
+ return kernelPluginManager.getDummySignature(userOperation)
479
+ },
806
480
 
807
- if (tx.callType === "delegatecall") {
808
- if (entryPointVersion === "v0.6") {
809
- return encodeFunctionData({
810
- abi: KernelExecuteAbi,
811
- functionName: "executeDelegateCall",
812
- args: [tx.to, tx.data]
813
- })
814
- }
815
- return encodeFunctionData({
816
- abi: KernelV3ExecuteAbi,
817
- functionName: "execute",
818
- args: [
819
- getExecMode(CALL_TYPE.DELEGATE_CALL, EXEC_TYPE.DEFAULT),
820
- concatHex([tx.to, tx.data])
821
- ]
822
- })
823
- }
481
+ // Encode the init code
482
+ async getInitCode() {
483
+ if (smartAccountDeployed) return "0x"
824
484
 
825
- throw new Error("Invalid call type")
826
- },
485
+ smartAccountDeployed = await isSmartAccountDeployed(
486
+ client,
487
+ accountAddress
488
+ )
827
489
 
828
- // Get simple dummy signature
829
- async getDummySignature(userOperation) {
830
- return kernelPluginManager.getDummySignature(userOperation)
831
- }
490
+ if (smartAccountDeployed) return "0x"
491
+ return generateInitCode()
492
+ }
493
+ })
832
494
  }
833
495
  }