permissionless 0.0.11 → 0.0.13

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 (306) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/_cjs/accounts/index.js +14 -0
  3. package/_cjs/accounts/index.js.map +1 -0
  4. package/_cjs/accounts/privateKeyToSafeSmartAccount.js +24 -0
  5. package/_cjs/accounts/privateKeyToSafeSmartAccount.js.map +1 -0
  6. package/_cjs/accounts/privateKeyToSimpleSmartAccount.js +16 -0
  7. package/_cjs/accounts/privateKeyToSimpleSmartAccount.js.map +1 -0
  8. package/_cjs/accounts/signerToSafeSmartAccount.js +492 -0
  9. package/_cjs/accounts/signerToSafeSmartAccount.js.map +1 -0
  10. package/_cjs/accounts/signerToSimpleSmartAccount.js +190 -0
  11. package/_cjs/accounts/signerToSimpleSmartAccount.js.map +1 -0
  12. package/_cjs/accounts/types.js +23 -0
  13. package/_cjs/accounts/types.js.map +1 -0
  14. package/_cjs/actions/bundler/chainId.js.map +1 -1
  15. package/_cjs/actions/bundler/estimateUserOperationGas.js +4 -1
  16. package/_cjs/actions/bundler/estimateUserOperationGas.js.map +1 -1
  17. package/_cjs/actions/bundler/getUserOperationByHash.js.map +1 -1
  18. package/_cjs/actions/bundler/getUserOperationReceipt.js.map +1 -1
  19. package/_cjs/actions/bundler/sendUserOperation.js +4 -1
  20. package/_cjs/actions/bundler/sendUserOperation.js.map +1 -1
  21. package/_cjs/actions/bundler/supportedEntryPoints.js.map +1 -1
  22. package/_cjs/actions/bundler/waitForUserOperationReceipt.js +7 -2
  23. package/_cjs/actions/bundler/waitForUserOperationReceipt.js.map +1 -1
  24. package/_cjs/actions/index.js.map +1 -1
  25. package/_cjs/actions/pimlico/getUserOperationGasPrice.js.map +1 -1
  26. package/_cjs/actions/pimlico/getUserOperationStatus.js.map +1 -1
  27. package/_cjs/actions/pimlico/sponsorUserOperation.js +4 -1
  28. package/_cjs/actions/pimlico/sponsorUserOperation.js.map +1 -1
  29. package/_cjs/actions/pimlico.js.map +1 -1
  30. package/_cjs/actions/public/getAccountNonce.js +4 -2
  31. package/_cjs/actions/public/getAccountNonce.js.map +1 -1
  32. package/_cjs/actions/public/getSenderAddress.js +7 -3
  33. package/_cjs/actions/public/getSenderAddress.js.map +1 -1
  34. package/_cjs/actions/smartAccount/deployContract.js +38 -0
  35. package/_cjs/actions/smartAccount/deployContract.js.map +1 -0
  36. package/_cjs/actions/smartAccount/prepareUserOperationRequest.js +73 -0
  37. package/_cjs/actions/smartAccount/prepareUserOperationRequest.js.map +1 -0
  38. package/_cjs/actions/smartAccount/sendTransaction.js +44 -0
  39. package/_cjs/actions/smartAccount/sendTransaction.js.map +1 -0
  40. package/_cjs/actions/smartAccount/sendTransactions.js +46 -0
  41. package/_cjs/actions/smartAccount/sendTransactions.js.map +1 -0
  42. package/_cjs/actions/smartAccount/sendUserOperation.js +22 -0
  43. package/_cjs/actions/smartAccount/sendUserOperation.js.map +1 -0
  44. package/_cjs/actions/smartAccount/signMessage.js +16 -0
  45. package/_cjs/actions/smartAccount/signMessage.js.map +1 -0
  46. package/_cjs/actions/smartAccount/signTypedData.js +34 -0
  47. package/_cjs/actions/smartAccount/signTypedData.js.map +1 -0
  48. package/_cjs/actions/smartAccount/writeContract.js +21 -0
  49. package/_cjs/actions/smartAccount/writeContract.js.map +1 -0
  50. package/_cjs/actions/smartAccount.js +18 -0
  51. package/_cjs/actions/smartAccount.js.map +1 -0
  52. package/_cjs/actions/stackup/sponsorUserOperation.js +5 -1
  53. package/_cjs/actions/stackup/sponsorUserOperation.js.map +1 -1
  54. package/_cjs/clients/{bundler.js → createBundlerClient.js} +1 -1
  55. package/_cjs/clients/createBundlerClient.js.map +1 -0
  56. package/_cjs/clients/createSmartAccountClient.js +20 -0
  57. package/_cjs/clients/createSmartAccountClient.js.map +1 -0
  58. package/_cjs/clients/decorators/bundler.js.map +1 -1
  59. package/_cjs/clients/decorators/pimlico.js.map +1 -1
  60. package/_cjs/clients/decorators/smartAccount.js +33 -0
  61. package/_cjs/clients/decorators/smartAccount.js.map +1 -0
  62. package/_cjs/clients/decorators/stackup.js.map +1 -1
  63. package/_cjs/clients/pimlico.js.map +1 -1
  64. package/_cjs/clients/stackup.js.map +1 -1
  65. package/_cjs/index.js +9 -5
  66. package/_cjs/index.js.map +1 -1
  67. package/_cjs/utils/deepHexlify.js +4 -4
  68. package/_cjs/utils/deepHexlify.js.map +1 -1
  69. package/_cjs/utils/getAction.js +8 -0
  70. package/_cjs/utils/getAction.js.map +1 -0
  71. package/_cjs/utils/getUserOperationHash.js.map +1 -1
  72. package/_cjs/utils/index.js +7 -1
  73. package/_cjs/utils/index.js.map +1 -1
  74. package/_cjs/utils/observe.js +7 -2
  75. package/_cjs/utils/observe.js.map +1 -1
  76. package/_cjs/utils/signUserOperationHashWithECDSA.js +7 -7
  77. package/_cjs/utils/signUserOperationHashWithECDSA.js.map +1 -1
  78. package/_esm/accounts/index.js +7 -0
  79. package/_esm/accounts/index.js.map +1 -0
  80. package/_esm/accounts/privateKeyToSafeSmartAccount.js +26 -0
  81. package/_esm/accounts/privateKeyToSafeSmartAccount.js.map +1 -0
  82. package/_esm/accounts/privateKeyToSimpleSmartAccount.js +18 -0
  83. package/_esm/accounts/privateKeyToSimpleSmartAccount.js.map +1 -0
  84. package/_esm/accounts/signerToSafeSmartAccount.js +499 -0
  85. package/_esm/accounts/signerToSafeSmartAccount.js.map +1 -0
  86. package/_esm/accounts/signerToSimpleSmartAccount.js +191 -0
  87. package/_esm/accounts/signerToSimpleSmartAccount.js.map +1 -0
  88. package/_esm/accounts/types.js +20 -0
  89. package/_esm/accounts/types.js.map +1 -0
  90. package/_esm/actions/bundler/chainId.js.map +1 -1
  91. package/_esm/actions/bundler/estimateUserOperationGas.js +4 -1
  92. package/_esm/actions/bundler/estimateUserOperationGas.js.map +1 -1
  93. package/_esm/actions/bundler/getUserOperationByHash.js.map +1 -1
  94. package/_esm/actions/bundler/getUserOperationReceipt.js.map +1 -1
  95. package/_esm/actions/bundler/sendUserOperation.js +4 -3
  96. package/_esm/actions/bundler/sendUserOperation.js.map +1 -1
  97. package/_esm/actions/bundler/supportedEntryPoints.js.map +1 -1
  98. package/_esm/actions/bundler/waitForUserOperationReceipt.js +7 -2
  99. package/_esm/actions/bundler/waitForUserOperationReceipt.js.map +1 -1
  100. package/_esm/actions/index.js.map +1 -1
  101. package/_esm/actions/pimlico/getUserOperationGasPrice.js +2 -2
  102. package/_esm/actions/pimlico/getUserOperationGasPrice.js.map +1 -1
  103. package/_esm/actions/pimlico/getUserOperationStatus.js +1 -1
  104. package/_esm/actions/pimlico/getUserOperationStatus.js.map +1 -1
  105. package/_esm/actions/pimlico/sponsorUserOperation.js +4 -1
  106. package/_esm/actions/pimlico/sponsorUserOperation.js.map +1 -1
  107. package/_esm/actions/pimlico.js.map +1 -1
  108. package/_esm/actions/public/getAccountNonce.js +7 -5
  109. package/_esm/actions/public/getAccountNonce.js.map +1 -1
  110. package/_esm/actions/public/getSenderAddress.js +8 -5
  111. package/_esm/actions/public/getSenderAddress.js.map +1 -1
  112. package/_esm/actions/smartAccount/deployContract.js +64 -0
  113. package/_esm/actions/smartAccount/deployContract.js.map +1 -0
  114. package/_esm/actions/smartAccount/prepareUserOperationRequest.js +69 -0
  115. package/_esm/actions/smartAccount/prepareUserOperationRequest.js.map +1 -0
  116. package/_esm/actions/smartAccount/sendTransaction.js +88 -0
  117. package/_esm/actions/smartAccount/sendTransaction.js.map +1 -0
  118. package/_esm/actions/smartAccount/sendTransactions.js +90 -0
  119. package/_esm/actions/smartAccount/sendTransactions.js.map +1 -0
  120. package/_esm/actions/smartAccount/sendUserOperation.js +18 -0
  121. package/_esm/actions/smartAccount/sendUserOperation.js.map +1 -0
  122. package/_esm/actions/smartAccount/signMessage.js +59 -0
  123. package/_esm/actions/smartAccount/signMessage.js.map +1 -0
  124. package/_esm/actions/smartAccount/signTypedData.js +129 -0
  125. package/_esm/actions/smartAccount/signTypedData.js.map +1 -0
  126. package/_esm/actions/smartAccount/writeContract.js +19 -0
  127. package/_esm/actions/smartAccount/writeContract.js.map +1 -0
  128. package/_esm/actions/smartAccount.js +9 -0
  129. package/_esm/actions/smartAccount.js.map +1 -0
  130. package/_esm/actions/stackup/accounts.js +1 -1
  131. package/_esm/actions/stackup/sponsorUserOperation.js +6 -2
  132. package/_esm/actions/stackup/sponsorUserOperation.js.map +1 -1
  133. package/_esm/clients/{bundler.js → createBundlerClient.js} +1 -1
  134. package/_esm/clients/createBundlerClient.js.map +1 -0
  135. package/_esm/clients/createSmartAccountClient.js +38 -0
  136. package/_esm/clients/createSmartAccountClient.js.map +1 -0
  137. package/_esm/clients/decorators/bundler.js.map +1 -1
  138. package/_esm/clients/decorators/pimlico.js +1 -1
  139. package/_esm/clients/decorators/pimlico.js.map +1 -1
  140. package/_esm/clients/decorators/smartAccount.js +29 -0
  141. package/_esm/clients/decorators/smartAccount.js.map +1 -0
  142. package/_esm/clients/decorators/stackup.js.map +1 -1
  143. package/_esm/clients/pimlico.js +1 -1
  144. package/_esm/clients/pimlico.js.map +1 -1
  145. package/_esm/clients/stackup.js +1 -1
  146. package/_esm/clients/stackup.js.map +1 -1
  147. package/_esm/index.js +5 -2
  148. package/_esm/index.js.map +1 -1
  149. package/_esm/utils/deepHexlify.js +6 -4
  150. package/_esm/utils/deepHexlify.js.map +1 -1
  151. package/_esm/utils/getAction.js +6 -0
  152. package/_esm/utils/getAction.js.map +1 -0
  153. package/_esm/utils/getUserOperationHash.js.map +1 -1
  154. package/_esm/utils/index.js +5 -0
  155. package/_esm/utils/index.js.map +1 -1
  156. package/_esm/utils/observe.js +7 -2
  157. package/_esm/utils/observe.js.map +1 -1
  158. package/_esm/utils/signUserOperationHashWithECDSA.js +7 -6
  159. package/_esm/utils/signUserOperationHashWithECDSA.js.map +1 -1
  160. package/_types/accounts/index.d.ts +7 -0
  161. package/_types/accounts/index.d.ts.map +1 -0
  162. package/_types/accounts/privateKeyToSafeSmartAccount.d.ts +26 -0
  163. package/_types/accounts/privateKeyToSafeSmartAccount.d.ts.map +1 -0
  164. package/_types/accounts/privateKeyToSimpleSmartAccount.d.ts +14 -0
  165. package/_types/accounts/privateKeyToSimpleSmartAccount.d.ts.map +1 -0
  166. package/_types/accounts/signerToSafeSmartAccount.d.ts +28 -0
  167. package/_types/accounts/signerToSafeSmartAccount.d.ts.map +1 -0
  168. package/_types/accounts/signerToSimpleSmartAccount.d.ts +15 -0
  169. package/_types/accounts/signerToSimpleSmartAccount.d.ts.map +1 -0
  170. package/_types/accounts/types.d.ts +32 -0
  171. package/_types/accounts/types.d.ts.map +1 -0
  172. package/_types/actions/bundler/chainId.d.ts +3 -2
  173. package/_types/actions/bundler/chainId.d.ts.map +1 -1
  174. package/_types/actions/bundler/estimateUserOperationGas.d.ts +3 -3
  175. package/_types/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
  176. package/_types/actions/bundler/getUserOperationByHash.d.ts +3 -3
  177. package/_types/actions/bundler/getUserOperationByHash.d.ts.map +1 -1
  178. package/_types/actions/bundler/getUserOperationReceipt.d.ts +3 -3
  179. package/_types/actions/bundler/getUserOperationReceipt.d.ts.map +1 -1
  180. package/_types/actions/bundler/sendUserOperation.d.ts +3 -5
  181. package/_types/actions/bundler/sendUserOperation.d.ts.map +1 -1
  182. package/_types/actions/bundler/supportedEntryPoints.d.ts +3 -3
  183. package/_types/actions/bundler/supportedEntryPoints.d.ts.map +1 -1
  184. package/_types/actions/bundler/waitForUserOperationReceipt.d.ts +2 -3
  185. package/_types/actions/bundler/waitForUserOperationReceipt.d.ts.map +1 -1
  186. package/_types/actions/index.d.ts.map +1 -1
  187. package/_types/actions/pimlico/getUserOperationGasPrice.d.ts +5 -4
  188. package/_types/actions/pimlico/getUserOperationGasPrice.d.ts.map +1 -1
  189. package/_types/actions/pimlico/getUserOperationStatus.d.ts +4 -5
  190. package/_types/actions/pimlico/getUserOperationStatus.d.ts.map +1 -1
  191. package/_types/actions/pimlico/sponsorUserOperation.d.ts +3 -3
  192. package/_types/actions/pimlico/sponsorUserOperation.d.ts.map +1 -1
  193. package/_types/actions/pimlico.d.ts.map +1 -1
  194. package/_types/actions/public/getAccountNonce.d.ts +5 -5
  195. package/_types/actions/public/getAccountNonce.d.ts.map +1 -1
  196. package/_types/actions/public/getSenderAddress.d.ts +3 -4
  197. package/_types/actions/public/getSenderAddress.d.ts.map +1 -1
  198. package/_types/actions/smartAccount/deployContract.d.ts +34 -0
  199. package/_types/actions/smartAccount/deployContract.d.ts.map +1 -0
  200. package/_types/actions/smartAccount/prepareUserOperationRequest.d.ts +20 -0
  201. package/_types/actions/smartAccount/prepareUserOperationRequest.d.ts.map +1 -0
  202. package/_types/actions/smartAccount/sendTransaction.d.ts +52 -0
  203. package/_types/actions/smartAccount/sendTransaction.d.ts.map +1 -0
  204. package/_types/actions/smartAccount/sendTransactions.d.ts +63 -0
  205. package/_types/actions/smartAccount/sendTransactions.d.ts.map +1 -0
  206. package/_types/actions/smartAccount/sendUserOperation.d.ts +10 -0
  207. package/_types/actions/smartAccount/sendUserOperation.d.ts.map +1 -0
  208. package/_types/actions/smartAccount/signMessage.d.ts +50 -0
  209. package/_types/actions/smartAccount/signMessage.d.ts.map +1 -0
  210. package/_types/actions/smartAccount/signTypedData.d.ts +104 -0
  211. package/_types/actions/smartAccount/signTypedData.d.ts.map +1 -0
  212. package/_types/actions/smartAccount/writeContract.d.ts +57 -0
  213. package/_types/actions/smartAccount/writeContract.d.ts.map +1 -0
  214. package/_types/actions/smartAccount.d.ts +9 -0
  215. package/_types/actions/smartAccount.d.ts.map +1 -0
  216. package/_types/actions/stackup/accounts.d.ts +1 -1
  217. package/_types/actions/stackup/sponsorUserOperation.d.ts +1 -1
  218. package/_types/actions/stackup/sponsorUserOperation.d.ts.map +1 -1
  219. package/_types/clients/{bundler.d.ts → createBundlerClient.d.ts} +1 -1
  220. package/_types/clients/createBundlerClient.d.ts.map +1 -0
  221. package/_types/clients/createSmartAccountClient.d.ts +282 -0
  222. package/_types/clients/createSmartAccountClient.d.ts.map +1 -0
  223. package/_types/clients/decorators/bundler.d.ts +1 -1
  224. package/_types/clients/decorators/bundler.d.ts.map +1 -1
  225. package/_types/clients/decorators/pimlico.d.ts +3 -3
  226. package/_types/clients/decorators/pimlico.d.ts.map +1 -1
  227. package/_types/clients/decorators/smartAccount.d.ts +327 -0
  228. package/_types/clients/decorators/smartAccount.d.ts.map +1 -0
  229. package/_types/clients/decorators/stackup.d.ts.map +1 -1
  230. package/_types/clients/pimlico.d.ts +1 -1
  231. package/_types/clients/pimlico.d.ts.map +1 -1
  232. package/_types/clients/stackup.d.ts +1 -1
  233. package/_types/clients/stackup.d.ts.map +1 -1
  234. package/_types/index.d.ts +6 -3
  235. package/_types/index.d.ts.map +1 -1
  236. package/_types/types/bundler.d.ts +4 -1
  237. package/_types/types/bundler.d.ts.map +1 -1
  238. package/_types/types/index.d.ts +20 -0
  239. package/_types/types/index.d.ts.map +1 -1
  240. package/_types/types/pimlico.d.ts.map +1 -1
  241. package/_types/types/stackup.d.ts.map +1 -1
  242. package/_types/utils/deepHexlify.d.ts.map +1 -1
  243. package/_types/utils/getAction.d.ts +3 -0
  244. package/_types/utils/getAction.d.ts.map +1 -0
  245. package/_types/utils/getUserOperationHash.d.ts.map +1 -1
  246. package/_types/utils/index.d.ts +2 -0
  247. package/_types/utils/index.d.ts.map +1 -1
  248. package/_types/utils/observe.d.ts.map +1 -1
  249. package/_types/utils/signUserOperationHashWithECDSA.d.ts +3 -11
  250. package/_types/utils/signUserOperationHashWithECDSA.d.ts.map +1 -1
  251. package/accounts/index.ts +33 -0
  252. package/accounts/privateKeyToSafeSmartAccount.ts +73 -0
  253. package/accounts/privateKeyToSimpleSmartAccount.ts +44 -0
  254. package/accounts/signerToSafeSmartAccount.ts +775 -0
  255. package/accounts/signerToSimpleSmartAccount.ts +267 -0
  256. package/accounts/types.ts +64 -0
  257. package/actions/bundler/chainId.ts +10 -2
  258. package/actions/bundler/estimateUserOperationGas.ts +17 -6
  259. package/actions/bundler/getUserOperationByHash.ts +16 -5
  260. package/actions/bundler/getUserOperationReceipt.ts +17 -4
  261. package/actions/bundler/sendUserOperation.ts +19 -7
  262. package/actions/bundler/supportedEntryPoints.ts +10 -3
  263. package/actions/bundler/waitForUserOperationReceipt.ts +64 -26
  264. package/actions/index.ts +4 -1
  265. package/actions/pimlico/getUserOperationGasPrice.ts +13 -6
  266. package/actions/pimlico/getUserOperationStatus.ts +12 -5
  267. package/actions/pimlico/sponsorUserOperation.ts +20 -7
  268. package/actions/pimlico.ts +8 -2
  269. package/actions/public/getAccountNonce.ts +20 -8
  270. package/actions/public/getSenderAddress.ts +25 -8
  271. package/actions/smartAccount/deployContract.ts +110 -0
  272. package/actions/smartAccount/prepareUserOperationRequest.ts +140 -0
  273. package/actions/smartAccount/sendTransaction.ts +138 -0
  274. package/actions/smartAccount/sendTransactions.ts +141 -0
  275. package/actions/smartAccount/sendUserOperation.ts +70 -0
  276. package/actions/smartAccount/signMessage.ts +79 -0
  277. package/actions/smartAccount/signTypedData.ts +161 -0
  278. package/actions/smartAccount/writeContract.ts +126 -0
  279. package/actions/smartAccount.ts +49 -0
  280. package/actions/stackup/accounts.ts +1 -1
  281. package/actions/stackup/sponsorUserOperation.ts +14 -4
  282. package/clients/{bundler.ts → createBundlerClient.ts} +14 -3
  283. package/clients/createSmartAccountClient.ts +95 -0
  284. package/clients/decorators/bundler.ts +20 -10
  285. package/clients/decorators/pimlico.ts +21 -9
  286. package/clients/decorators/smartAccount.ts +451 -0
  287. package/clients/decorators/stackup.ts +12 -4
  288. package/clients/pimlico.ts +20 -5
  289. package/clients/stackup.ts +17 -4
  290. package/index.ts +20 -3
  291. package/package.json +12 -2
  292. package/types/bundler.ts +4 -1
  293. package/types/index.ts +29 -0
  294. package/types/pimlico.ts +12 -2
  295. package/types/stackup.ts +4 -1
  296. package/utils/deepHexlify.test.ts +13 -7
  297. package/utils/deepHexlify.ts +5 -4
  298. package/utils/getAction.ts +15 -0
  299. package/utils/getUserOperationHash.ts +10 -2
  300. package/utils/index.ts +15 -2
  301. package/utils/observe.ts +18 -5
  302. package/utils/signUserOperationHashWithECDSA.ts +17 -20
  303. package/_cjs/clients/bundler.js.map +0 -1
  304. package/_esm/clients/bundler.js.map +0 -1
  305. package/_types/clients/bundler.d.ts.map +0 -1
  306. package/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,267 @@
1
+ import {
2
+ type Account,
3
+ type Address,
4
+ type Chain,
5
+ type Client,
6
+ type Hex,
7
+ type Transport,
8
+ concatHex,
9
+ encodeFunctionData
10
+ } from "viem"
11
+ import { toAccount } from "viem/accounts"
12
+ import {
13
+ getBytecode,
14
+ getChainId,
15
+ signMessage,
16
+ signTypedData
17
+ } from "viem/actions"
18
+ import { getAccountNonce } from "../actions/public/getAccountNonce.js"
19
+ import { getSenderAddress } from "../actions/public/getSenderAddress.js"
20
+ import { getUserOperationHash } from "../utils/getUserOperationHash.js"
21
+ import {
22
+ SignTransactionNotSupportedBySmartAccount,
23
+ type SmartAccount,
24
+ type SmartAccountSigner
25
+ } from "./types.js"
26
+
27
+ export type SimpleSmartAccount<
28
+ transport extends Transport = Transport,
29
+ chain extends Chain | undefined = Chain | undefined
30
+ > = SmartAccount<"SimpleSmartAccount", transport, chain>
31
+
32
+ const getAccountInitCode = async (
33
+ factoryAddress: Address,
34
+ owner: Address,
35
+ index = 0n
36
+ ): Promise<Hex> => {
37
+ if (!owner) throw new Error("Owner account not found")
38
+
39
+ return concatHex([
40
+ factoryAddress,
41
+ encodeFunctionData({
42
+ abi: [
43
+ {
44
+ inputs: [
45
+ {
46
+ internalType: "address",
47
+ name: "owner",
48
+ type: "address"
49
+ },
50
+ {
51
+ internalType: "uint256",
52
+ name: "salt",
53
+ type: "uint256"
54
+ }
55
+ ],
56
+ name: "createAccount",
57
+ outputs: [
58
+ {
59
+ internalType: "contract SimpleAccount",
60
+ name: "ret",
61
+ type: "address"
62
+ }
63
+ ],
64
+ stateMutability: "nonpayable",
65
+ type: "function"
66
+ }
67
+ ],
68
+ functionName: "createAccount",
69
+ args: [owner, index]
70
+ }) as Hex
71
+ ])
72
+ }
73
+
74
+ const getAccountAddress = async <
75
+ TTransport extends Transport = Transport,
76
+ TChain extends Chain | undefined = Chain | undefined
77
+ >({
78
+ client,
79
+ factoryAddress,
80
+ entryPoint,
81
+ owner,
82
+ index = 0n
83
+ }: {
84
+ client: Client<TTransport, TChain>
85
+ factoryAddress: Address
86
+ owner: Address
87
+ entryPoint: Address
88
+ index?: bigint
89
+ }): Promise<Address> => {
90
+ const initCode = await getAccountInitCode(factoryAddress, owner, index)
91
+
92
+ return getSenderAddress(client, {
93
+ initCode,
94
+ entryPoint
95
+ })
96
+ }
97
+
98
+ /**
99
+ * @description Creates an Simple Account from a private key.
100
+ *
101
+ * @returns A Private Key Simple Account.
102
+ */
103
+ export async function signerToSimpleSmartAccount<
104
+ TTransport extends Transport = Transport,
105
+ TChain extends Chain | undefined = Chain | undefined
106
+ >(
107
+ client: Client<TTransport, TChain>,
108
+ {
109
+ signer,
110
+ factoryAddress,
111
+ entryPoint,
112
+ index = 0n
113
+ }: {
114
+ signer: SmartAccountSigner
115
+ factoryAddress: Address
116
+ entryPoint: Address
117
+ index?: bigint
118
+ }
119
+ ): Promise<SimpleSmartAccount<TTransport, TChain>> {
120
+ const viemSigner: Account =
121
+ signer.type === "local"
122
+ ? ({
123
+ ...signer,
124
+ signTransaction: (_, __) => {
125
+ throw new SignTransactionNotSupportedBySmartAccount()
126
+ }
127
+ } as Account)
128
+ : (signer as Account)
129
+
130
+ const [accountAddress, chainId] = await Promise.all([
131
+ getAccountAddress<TTransport, TChain>({
132
+ client,
133
+ factoryAddress,
134
+ entryPoint,
135
+ owner: viemSigner.address,
136
+ index
137
+ }),
138
+ getChainId(client)
139
+ ])
140
+
141
+ if (!accountAddress) throw new Error("Account address not found")
142
+
143
+ const account = toAccount({
144
+ address: accountAddress,
145
+ async signMessage({ message }) {
146
+ return signMessage(client, { account: viemSigner, message })
147
+ },
148
+ async signTransaction(_, __) {
149
+ throw new SignTransactionNotSupportedBySmartAccount()
150
+ },
151
+ async signTypedData(typedData) {
152
+ return signTypedData(client, { account: viemSigner, ...typedData })
153
+ }
154
+ })
155
+
156
+ return {
157
+ ...account,
158
+ client: client,
159
+ publicKey: accountAddress,
160
+ entryPoint: entryPoint,
161
+ source: "SimpleSmartAccount",
162
+ async getNonce() {
163
+ return getAccountNonce(client, {
164
+ sender: accountAddress,
165
+ entryPoint: entryPoint
166
+ })
167
+ },
168
+ async signUserOperation(userOperation) {
169
+ return account.signMessage({
170
+ message: {
171
+ raw: getUserOperationHash({
172
+ userOperation,
173
+ entryPoint: entryPoint,
174
+ chainId: chainId
175
+ })
176
+ }
177
+ })
178
+ },
179
+ async getInitCode() {
180
+ const contractCode = await getBytecode(client, {
181
+ address: accountAddress
182
+ })
183
+
184
+ if ((contractCode?.length ?? 0) > 2) return "0x"
185
+
186
+ return getAccountInitCode(factoryAddress, viemSigner.address, index)
187
+ },
188
+ async encodeDeployCallData(_) {
189
+ throw new Error("Simple account doesn't support account deployment")
190
+ },
191
+ async encodeCallData(args) {
192
+ if (Array.isArray(args)) {
193
+ const argsArray = args as {
194
+ to: Address
195
+ value: bigint
196
+ data: Hex
197
+ }[]
198
+ return encodeFunctionData({
199
+ abi: [
200
+ {
201
+ inputs: [
202
+ {
203
+ internalType: "address[]",
204
+ name: "dest",
205
+ type: "address[]"
206
+ },
207
+ {
208
+ internalType: "bytes[]",
209
+ name: "func",
210
+ type: "bytes[]"
211
+ }
212
+ ],
213
+ name: "executeBatch",
214
+ outputs: [],
215
+ stateMutability: "nonpayable",
216
+ type: "function"
217
+ }
218
+ ],
219
+ functionName: "executeBatch",
220
+ args: [
221
+ argsArray.map((a) => a.to),
222
+ argsArray.map((a) => a.data)
223
+ ]
224
+ })
225
+ }
226
+
227
+ const { to, value, data } = args as {
228
+ to: Address
229
+ value: bigint
230
+ data: Hex
231
+ }
232
+
233
+ return encodeFunctionData({
234
+ abi: [
235
+ {
236
+ inputs: [
237
+ {
238
+ internalType: "address",
239
+ name: "dest",
240
+ type: "address"
241
+ },
242
+ {
243
+ internalType: "uint256",
244
+ name: "value",
245
+ type: "uint256"
246
+ },
247
+ {
248
+ internalType: "bytes",
249
+ name: "func",
250
+ type: "bytes"
251
+ }
252
+ ],
253
+ name: "execute",
254
+ outputs: [],
255
+ stateMutability: "nonpayable",
256
+ type: "function"
257
+ }
258
+ ],
259
+ functionName: "execute",
260
+ args: [to, value, data]
261
+ })
262
+ },
263
+ async getDummySignature() {
264
+ return "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
265
+ }
266
+ }
267
+ }
@@ -0,0 +1,64 @@
1
+ import {
2
+ type Abi,
3
+ type Account,
4
+ type Address,
5
+ BaseError,
6
+ type Client,
7
+ type GetConstructorArgs,
8
+ type Hex,
9
+ type LocalAccount
10
+ } from "viem"
11
+ import type { Chain, Transport } from "viem"
12
+ import { type UserOperation } from "../types/index.js"
13
+
14
+ export class SignTransactionNotSupportedBySmartAccount extends BaseError {
15
+ override name = "SignTransactionNotSupportedBySmartAccount"
16
+ constructor({ docsPath }: { docsPath?: string } = {}) {
17
+ super(
18
+ [
19
+ "A smart account cannot sign or send transaction, it can only sign message or userOperation.",
20
+ "Please send user operation instead."
21
+ ].join("\n"),
22
+ {
23
+ docsPath,
24
+ docsSlug: "account"
25
+ }
26
+ )
27
+ }
28
+ }
29
+
30
+ export type SmartAccount<
31
+ Name extends string = string,
32
+ transport extends Transport = Transport,
33
+ chain extends Chain | undefined = Chain | undefined
34
+ > = LocalAccount<Name> & {
35
+ client: Client<transport, chain>
36
+ entryPoint: Address
37
+ getNonce: () => Promise<bigint>
38
+ getInitCode: () => Promise<Hex>
39
+ encodeCallData: (
40
+ args:
41
+ | {
42
+ to: Address
43
+ value: bigint
44
+ data: Hex
45
+ }
46
+ | {
47
+ to: Address
48
+ value: bigint
49
+ data: Hex
50
+ }[]
51
+ ) => Promise<Hex>
52
+ getDummySignature(): Promise<Hex>
53
+ encodeDeployCallData: <TAbi extends Abi | readonly unknown[] = Abi>({
54
+ abi,
55
+ args,
56
+ bytecode
57
+ }: { abi: TAbi; bytecode: Hex } & GetConstructorArgs<TAbi>) => Promise<Hex>
58
+ signUserOperation: (UserOperation: UserOperation) => Promise<Hex>
59
+ }
60
+
61
+ export type SmartAccountSigner<TAddress extends Address = Address> = Omit<
62
+ Account<TAddress>,
63
+ "signTransaction"
64
+ >
@@ -1,4 +1,6 @@
1
- import type { BundlerClient } from "../../clients/bundler.js"
1
+ import type { Account, Chain, Client, Transport } from "viem"
2
+ import type { BundlerClient } from "../../clients/createBundlerClient.js"
3
+ import type { BundlerRpcSchema } from "../../types/bundler.js"
2
4
 
3
5
  /**
4
6
  * Returns the supported chain id by the bundler service
@@ -22,7 +24,13 @@ import type { BundlerClient } from "../../clients/bundler.js"
22
24
  * // Return 5n for Goerli
23
25
  *
24
26
  */
25
- export const chainId = async (client: BundlerClient) => {
27
+ export const chainId = async <
28
+ TTransport extends Transport = Transport,
29
+ TChain extends Chain | undefined = Chain | undefined,
30
+ TAccount extends Account | undefined = Account | undefined
31
+ >(
32
+ client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>
33
+ ) => {
26
34
  return Number(
27
35
  await client.request({
28
36
  method: "eth_chainId",
@@ -1,12 +1,16 @@
1
- import type { Address } from "viem"
1
+ import type { Account, Address, Chain, Client, Transport } from "viem"
2
2
  import type { PartialBy } from "viem/types/utils"
3
- import type { BundlerClient } from "../../clients/bundler.js"
3
+ import type { BundlerClient } from "../../clients/createBundlerClient.js"
4
+ import type { BundlerRpcSchema } from "../../types/bundler.js"
4
5
  import type { UserOperation } from "../../types/userOperation.js"
5
6
  import type { UserOperationWithBigIntAsHex } from "../../types/userOperation.js"
6
7
  import { deepHexlify } from "../../utils/deepHexlify.js"
7
8
 
8
9
  export type EstimateUserOperationGasParameters = {
9
- userOperation: PartialBy<UserOperation, "callGasLimit" | "preVerificationGas" | "verificationGasLimit">
10
+ userOperation: PartialBy<
11
+ UserOperation,
12
+ "callGasLimit" | "preVerificationGas" | "verificationGasLimit"
13
+ >
10
14
  entryPoint: Address
11
15
  }
12
16
 
@@ -43,15 +47,22 @@ export type EstimateUserOperationGasReturnType = {
43
47
  * // Return {preVerificationGas: 43492n, verificationGasLimit: 59436n, callGasLimit: 9000n}
44
48
  *
45
49
  */
46
- export const estimateUserOperationGas = async (
47
- client: BundlerClient,
50
+ export const estimateUserOperationGas = async <
51
+ TTransport extends Transport = Transport,
52
+ TChain extends Chain | undefined = Chain | undefined,
53
+ TAccount extends Account | undefined = Account | undefined
54
+ >(
55
+ client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>,
48
56
  args: EstimateUserOperationGasParameters
49
57
  ): Promise<EstimateUserOperationGasReturnType> => {
50
58
  const { userOperation, entryPoint } = args
51
59
 
52
60
  const response = await client.request({
53
61
  method: "eth_estimateUserOperationGas",
54
- params: [deepHexlify(userOperation) as UserOperationWithBigIntAsHex, entryPoint as Address]
62
+ params: [
63
+ deepHexlify(userOperation) as UserOperationWithBigIntAsHex,
64
+ entryPoint as Address
65
+ ]
55
66
  })
56
67
 
57
68
  return {
@@ -1,5 +1,6 @@
1
- import type { Address, Hash } from "viem"
2
- import type { BundlerClient } from "../../clients/bundler.js"
1
+ import type { Account, Address, Chain, Client, Hash, Transport } from "viem"
2
+ import type { BundlerClient } from "../../clients/createBundlerClient.js"
3
+ import type { BundlerRpcSchema } from "../../types/bundler.js"
3
4
  import type { UserOperation } from "../../types/userOperation.js"
4
5
 
5
6
  export type GetUserOperationByHashParameters = {
@@ -36,8 +37,12 @@ export type GetUserOperationByHashReturnType = {
36
37
  * getUserOperationByHash(bundlerClient, {hash: userOpHash})
37
38
  *
38
39
  */
39
- export const getUserOperationByHash = async (
40
- client: BundlerClient,
40
+ export const getUserOperationByHash = async <
41
+ TTransport extends Transport = Transport,
42
+ TChain extends Chain | undefined = Chain | undefined,
43
+ TAccount extends Account | undefined = Account | undefined
44
+ >(
45
+ client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>,
41
46
  { hash }: GetUserOperationByHashParameters
42
47
  ): Promise<GetUserOperationByHashReturnType> => {
43
48
  const params: [Hash] = [hash]
@@ -49,7 +54,13 @@ export const getUserOperationByHash = async (
49
54
 
50
55
  if (!response) return null
51
56
 
52
- const { userOperation, entryPoint, transactionHash, blockHash, blockNumber } = response
57
+ const {
58
+ userOperation,
59
+ entryPoint,
60
+ transactionHash,
61
+ blockHash,
62
+ blockNumber
63
+ } = response
53
64
 
54
65
  return {
55
66
  userOperation: {
@@ -1,5 +1,14 @@
1
- import type { Address, Hash, Hex } from "viem"
2
- import type { BundlerClient } from "../../clients/bundler.js"
1
+ import type {
2
+ Account,
3
+ Address,
4
+ Chain,
5
+ Client,
6
+ Hash,
7
+ Hex,
8
+ Transport
9
+ } from "viem"
10
+ import type { BundlerClient } from "../../clients/createBundlerClient.js"
11
+ import type { BundlerRpcSchema } from "../../types/bundler.js"
3
12
  import type { TStatus } from "../../types/userOperation.js"
4
13
  import { transactionReceiptStatus } from "../../utils/deepHexlify.js"
5
14
 
@@ -62,8 +71,12 @@ export type GetUserOperationReceiptReturnType = {
62
71
  * getUserOperationReceipt(bundlerClient, {hash: userOpHash})
63
72
  *
64
73
  */
65
- export const getUserOperationReceipt = async (
66
- client: BundlerClient,
74
+ export const getUserOperationReceipt = async <
75
+ TTransport extends Transport = Transport,
76
+ TChain extends Chain | undefined = Chain | undefined,
77
+ TAccount extends Account | undefined = Account | undefined
78
+ >(
79
+ client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>,
67
80
  { hash }: GetUserOperationReceiptParameters
68
81
  ): Promise<GetUserOperationReceiptReturnType | null> => {
69
82
  const params: [Hash] = [hash]
@@ -1,6 +1,10 @@
1
- import type { Address, Hash } from "viem"
2
- import type { BundlerClient } from "../../clients/bundler.js"
3
- import type { UserOperation, UserOperationWithBigIntAsHex } from "../../types/userOperation.js"
1
+ import type { Account, Address, Chain, Client, Hash, Transport } from "viem"
2
+ import type { BundlerClient } from "../../clients/createBundlerClient.js"
3
+ import type { BundlerRpcSchema } from "../../types/bundler.js"
4
+ import type {
5
+ UserOperation,
6
+ UserOperationWithBigIntAsHex
7
+ } from "../../types/userOperation.js"
4
8
  import { deepHexlify } from "../../utils/deepHexlify.js"
5
9
 
6
10
  export type SendUserOperationParameters = {
@@ -17,7 +21,6 @@ export type SendUserOperationParameters = {
17
21
  * @param args {@link SendUserOperationParameters}.
18
22
  * @returns UserOpHash that you can use to track user operation as {@link Hash}.
19
23
  *
20
- *
21
24
  * @example
22
25
  * import { createClient } from "viem"
23
26
  * import { sendUserOperation } from "permissionless/actions"
@@ -33,13 +36,22 @@ export type SendUserOperationParameters = {
33
36
  * })
34
37
  *
35
38
  * // Return '0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34'
36
- *
37
39
  */
38
- export const sendUserOperation = async (client: BundlerClient, args: SendUserOperationParameters): Promise<Hash> => {
40
+ export const sendUserOperation = async <
41
+ TTransport extends Transport = Transport,
42
+ TChain extends Chain | undefined = Chain | undefined,
43
+ TAccount extends Account | undefined = Account | undefined
44
+ >(
45
+ client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>,
46
+ args: SendUserOperationParameters
47
+ ): Promise<Hash> => {
39
48
  const { userOperation, entryPoint } = args
40
49
 
41
50
  return client.request({
42
51
  method: "eth_sendUserOperation",
43
- params: [deepHexlify(userOperation) as UserOperationWithBigIntAsHex, entryPoint as Address]
52
+ params: [
53
+ deepHexlify(userOperation) as UserOperationWithBigIntAsHex,
54
+ entryPoint as Address
55
+ ]
44
56
  })
45
57
  }
@@ -1,5 +1,6 @@
1
- import type { Address } from "viem"
2
- import type { BundlerClient } from "../../clients/bundler.js"
1
+ import type { Account, Address, Chain, Client, Transport } from "viem"
2
+ import type { BundlerClient } from "../../clients/createBundlerClient.js"
3
+ import type { BundlerRpcSchema } from "../../types/bundler.js"
3
4
 
4
5
  /**
5
6
  * Returns the supported entrypoints by the bundler service
@@ -23,7 +24,13 @@ import type { BundlerClient } from "../../clients/bundler.js"
23
24
  * // Return ['0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789']
24
25
  *
25
26
  */
26
- export const supportedEntryPoints = async (client: BundlerClient): Promise<Address[]> => {
27
+ export const supportedEntryPoints = async <
28
+ TTransport extends Transport = Transport,
29
+ TChain extends Chain | undefined = Chain | undefined,
30
+ TAccount extends Account | undefined = Account | undefined
31
+ >(
32
+ client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>
33
+ ): Promise<Address[]> => {
27
34
  return client.request({
28
35
  method: "eth_supportedEntryPoints",
29
36
  params: []
@@ -1,12 +1,25 @@
1
- import { BaseError, type Chain, type Hash, stringify } from "viem"
2
- import type { BundlerClient } from "../../clients/bundler.js"
1
+ import {
2
+ type Account,
3
+ BaseError,
4
+ type Chain,
5
+ type Client,
6
+ type Hash,
7
+ type Transport,
8
+ stringify
9
+ } from "viem"
10
+ import { getAction } from "../../utils/getAction.js"
3
11
  import { observe } from "../../utils/observe.js"
4
- import { type GetUserOperationReceiptReturnType, getUserOperationReceipt } from "./getUserOperationReceipt.js"
12
+ import {
13
+ type GetUserOperationReceiptReturnType,
14
+ getUserOperationReceipt
15
+ } from "./getUserOperationReceipt.js"
5
16
 
6
17
  export class WaitForUserOperationReceiptTimeoutError extends BaseError {
7
18
  override name = "WaitForUserOperationReceiptTimeoutError"
8
19
  constructor({ hash }: { hash: Hash }) {
9
- super(`Timed out while waiting for transaction with hash "${hash}" to be confirmed.`)
20
+ super(
21
+ `Timed out while waiting for transaction with hash "${hash}" to be confirmed.`
22
+ )
10
23
  }
11
24
  }
12
25
 
@@ -43,38 +56,63 @@ export type WaitForUserOperationReceiptParameters = {
43
56
  * hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
44
57
  * })
45
58
  */
46
- export const waitForUserOperationReceipt = <TChain extends Chain | undefined>(
47
- bundlerClient: BundlerClient<TChain>,
48
- { hash, pollingInterval = bundlerClient.pollingInterval, timeout }: WaitForUserOperationReceiptParameters
59
+ export const waitForUserOperationReceipt = <
60
+ TTransport extends Transport = Transport,
61
+ TChain extends Chain | undefined = Chain | undefined,
62
+ TAccount extends Account | undefined = Account | undefined
63
+ >(
64
+ bundlerClient: Client<TTransport, TChain, TAccount>,
65
+ {
66
+ hash,
67
+ pollingInterval = bundlerClient.pollingInterval,
68
+ timeout
69
+ }: WaitForUserOperationReceiptParameters
49
70
  ): Promise<GetUserOperationReceiptReturnType> => {
50
- const observerId = stringify(["waitForUserOperationReceipt", bundlerClient.uid, hash])
71
+ const observerId = stringify([
72
+ "waitForUserOperationReceipt",
73
+ bundlerClient.uid,
74
+ hash
75
+ ])
51
76
 
52
77
  let userOperationReceipt: GetUserOperationReceiptReturnType
53
78
 
54
79
  return new Promise((resolve, reject) => {
55
80
  if (timeout) {
56
- setTimeout(() => reject(new WaitForUserOperationReceiptTimeoutError({ hash })), timeout)
81
+ setTimeout(
82
+ () =>
83
+ reject(
84
+ new WaitForUserOperationReceiptTimeoutError({ hash })
85
+ ),
86
+ timeout
87
+ )
57
88
  }
58
89
 
59
- const _unobserve = observe(observerId, { resolve, reject }, async (emit) => {
60
- const _removeInterval = setInterval(async () => {
61
- const done = (fn: () => void) => {
62
- clearInterval(_removeInterval)
63
- fn()
64
- _unobserve()
65
- }
90
+ const _unobserve = observe(
91
+ observerId,
92
+ { resolve, reject },
93
+ async (emit) => {
94
+ const _removeInterval = setInterval(async () => {
95
+ const done = (fn: () => void) => {
96
+ clearInterval(_removeInterval)
97
+ fn()
98
+ _unobserve()
99
+ }
66
100
 
67
- const _userOperationReceipt = await getUserOperationReceipt(bundlerClient, { hash })
101
+ const _userOperationReceipt = await getAction(
102
+ bundlerClient,
103
+ getUserOperationReceipt
104
+ )({ hash })
68
105
 
69
- if (_userOperationReceipt !== null) {
70
- userOperationReceipt = _userOperationReceipt
71
- }
106
+ if (_userOperationReceipt !== null) {
107
+ userOperationReceipt = _userOperationReceipt
108
+ }
72
109
 
73
- if (userOperationReceipt) {
74
- done(() => emit.resolve(userOperationReceipt))
75
- return
76
- }
77
- }, pollingInterval)
78
- })
110
+ if (userOperationReceipt) {
111
+ done(() => emit.resolve(userOperationReceipt))
112
+ return
113
+ }
114
+ }, pollingInterval)
115
+ }
116
+ )
79
117
  })
80
118
  }
package/actions/index.ts CHANGED
@@ -11,7 +11,10 @@ import type {
11
11
  import type { SendUserOperationParameters } from "./bundler/sendUserOperation.js"
12
12
 
13
13
  import type { GetSenderAddressParams } from "./public/getSenderAddress.js"
14
- import { InvalidEntryPointError, getSenderAddress } from "./public/getSenderAddress.js"
14
+ import {
15
+ InvalidEntryPointError,
16
+ getSenderAddress
17
+ } from "./public/getSenderAddress.js"
15
18
 
16
19
  import { chainId } from "./bundler/chainId.js"
17
20
  import { estimateUserOperationGas } from "./bundler/estimateUserOperationGas.js"