permissionless 0.0.16 → 0.0.18

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 (62) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/accounts/biconomy/abi/BiconomySmartAccountAbi.js +102 -0
  3. package/_cjs/accounts/biconomy/abi/BiconomySmartAccountAbi.js.map +1 -0
  4. package/_cjs/accounts/biconomy/privateKeyToBiconomySmartAccount.js +15 -0
  5. package/_cjs/accounts/biconomy/privateKeyToBiconomySmartAccount.js.map +1 -0
  6. package/_cjs/accounts/biconomy/signerToBiconomySmartAccount.js +195 -0
  7. package/_cjs/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -0
  8. package/_cjs/accounts/index.js +3 -1
  9. package/_cjs/accounts/index.js.map +1 -1
  10. package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js +5 -7
  11. package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
  12. package/_cjs/actions/bundler/waitForUserOperationReceipt.js +2 -2
  13. package/_cjs/actions/bundler/waitForUserOperationReceipt.js.map +1 -1
  14. package/_cjs/utils/deepHexlify.js +2 -2
  15. package/_cjs/utils/deepHexlify.js.map +1 -1
  16. package/_cjs/utils/index.js +3 -1
  17. package/_cjs/utils/index.js.map +1 -1
  18. package/_cjs/utils/walletClientToCustomSigner.js +22 -0
  19. package/_cjs/utils/walletClientToCustomSigner.js.map +1 -0
  20. package/_esm/accounts/biconomy/abi/BiconomySmartAccountAbi.js +105 -0
  21. package/_esm/accounts/biconomy/abi/BiconomySmartAccountAbi.js.map +1 -0
  22. package/_esm/accounts/biconomy/privateKeyToBiconomySmartAccount.js +17 -0
  23. package/_esm/accounts/biconomy/privateKeyToBiconomySmartAccount.js.map +1 -0
  24. package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js +231 -0
  25. package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -0
  26. package/_esm/accounts/index.js +2 -1
  27. package/_esm/accounts/index.js.map +1 -1
  28. package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js +6 -8
  29. package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
  30. package/_esm/actions/bundler/waitForUserOperationReceipt.js +2 -2
  31. package/_esm/actions/bundler/waitForUserOperationReceipt.js.map +1 -1
  32. package/_esm/utils/deepHexlify.js +2 -2
  33. package/_esm/utils/deepHexlify.js.map +1 -1
  34. package/_esm/utils/index.js +2 -1
  35. package/_esm/utils/index.js.map +1 -1
  36. package/_esm/utils/walletClientToCustomSigner.js +18 -0
  37. package/_esm/utils/walletClientToCustomSigner.js.map +1 -0
  38. package/_types/accounts/biconomy/abi/BiconomySmartAccountAbi.d.ts +59 -0
  39. package/_types/accounts/biconomy/abi/BiconomySmartAccountAbi.d.ts.map +1 -0
  40. package/_types/accounts/biconomy/privateKeyToBiconomySmartAccount.d.ts +13 -0
  41. package/_types/accounts/biconomy/privateKeyToBiconomySmartAccount.d.ts.map +1 -0
  42. package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts +23 -0
  43. package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts.map +1 -0
  44. package/_types/accounts/index.d.ts +2 -1
  45. package/_types/accounts/index.d.ts.map +1 -1
  46. package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts.map +1 -1
  47. package/_types/utils/deepHexlify.d.ts.map +1 -1
  48. package/_types/utils/index.d.ts +2 -1
  49. package/_types/utils/index.d.ts.map +1 -1
  50. package/_types/utils/walletClientToCustomSigner.d.ts +4 -0
  51. package/_types/utils/walletClientToCustomSigner.d.ts.map +1 -0
  52. package/accounts/biconomy/abi/BiconomySmartAccountAbi.ts +105 -0
  53. package/accounts/biconomy/privateKeyToBiconomySmartAccount.ts +40 -0
  54. package/accounts/biconomy/signerToBiconomySmartAccount.ts +364 -0
  55. package/accounts/index.ts +8 -1
  56. package/accounts/kernel/signerToEcdsaKernelSmartAccount.ts +6 -7
  57. package/actions/bundler/waitForUserOperationReceipt.ts +2 -2
  58. package/actions/smartAccount/prepareUserOperationRequest.ts +1 -1
  59. package/package.json +1 -1
  60. package/utils/deepHexlify.ts +6 -2
  61. package/utils/index.ts +2 -0
  62. package/utils/walletClientToCustomSigner.ts +42 -0
@@ -0,0 +1,105 @@
1
+ /**
2
+ * The exeuctor abi, used to execute transactions on the Biconomy Modular Smart Account
3
+ */
4
+ export const BiconomyExecuteAbi = [
5
+ {
6
+ inputs: [
7
+ {
8
+ internalType: "address",
9
+ name: "dest",
10
+ type: "address"
11
+ },
12
+ {
13
+ internalType: "uint256",
14
+ name: "value",
15
+ type: "uint256"
16
+ },
17
+ {
18
+ internalType: "bytes",
19
+ name: "func",
20
+ type: "bytes"
21
+ }
22
+ ],
23
+ name: "execute_ncC",
24
+ outputs: [],
25
+ stateMutability: "nonpayable",
26
+ type: "function"
27
+ },
28
+ {
29
+ inputs: [
30
+ {
31
+ internalType: "address[]",
32
+ name: "dest",
33
+ type: "address[]"
34
+ },
35
+ {
36
+ internalType: "uint256[]",
37
+ name: "value",
38
+ type: "uint256[]"
39
+ },
40
+ {
41
+ internalType: "bytes[]",
42
+ name: "func",
43
+ type: "bytes[]"
44
+ }
45
+ ],
46
+ name: "executeBatch_y6U",
47
+ outputs: [],
48
+ stateMutability: "nonpayable",
49
+ type: "function"
50
+ }
51
+ ] as const
52
+
53
+ /**
54
+ * The init abi, used to initialise Biconomy Modular Smart Account / setup default ECDSA module
55
+ */
56
+ export const BiconomyInitAbi = [
57
+ {
58
+ inputs: [
59
+ {
60
+ internalType: "address",
61
+ name: "handler",
62
+ type: "address"
63
+ },
64
+ {
65
+ internalType: "address",
66
+ name: "moduleSetupContract",
67
+ type: "address"
68
+ },
69
+ {
70
+ internalType: "bytes",
71
+ name: "moduleSetupData",
72
+ type: "bytes"
73
+ }
74
+ ],
75
+ name: "init",
76
+ outputs: [
77
+ {
78
+ internalType: "address",
79
+ name: "",
80
+ type: "address"
81
+ }
82
+ ],
83
+ stateMutability: "nonpayable",
84
+ type: "function"
85
+ },
86
+ {
87
+ inputs: [
88
+ {
89
+ internalType: "address",
90
+ name: "eoaOwner",
91
+ type: "address"
92
+ }
93
+ ],
94
+ name: "initForSmartAccount",
95
+ outputs: [
96
+ {
97
+ internalType: "address",
98
+ name: "",
99
+ type: "address"
100
+ }
101
+ ],
102
+ stateMutability: "nonpayable",
103
+ type: "function"
104
+ }
105
+ ]
@@ -0,0 +1,40 @@
1
+ import {
2
+ type Address,
3
+ type Chain,
4
+ type Client,
5
+ type Hex,
6
+ type Transport
7
+ } from "viem"
8
+ import { privateKeyToAccount } from "viem/accounts"
9
+ import {
10
+ type BiconomySmartAccount,
11
+ signerToBiconomySmartAccount
12
+ } from "./signerToBiconomySmartAccount.js"
13
+
14
+ /**
15
+ * @description Creates a Biconomy Smart Account from a private key.
16
+ *
17
+ * @returns A Private Key Biconomy Smart Account using ECDSA as default validation module.
18
+ */
19
+ export async function privateKeyToBiconomySmartAccount<
20
+ TTransport extends Transport = Transport,
21
+ TChain extends Chain | undefined = Chain | undefined
22
+ >(
23
+ client: Client<TTransport, TChain>,
24
+ {
25
+ privateKey,
26
+ entryPoint,
27
+ index = 0n
28
+ }: {
29
+ privateKey: Hex
30
+ entryPoint: Address
31
+ index?: bigint
32
+ }
33
+ ): Promise<BiconomySmartAccount<TTransport, TChain>> {
34
+ const privateKeyAccount = privateKeyToAccount(privateKey)
35
+ return signerToBiconomySmartAccount(client, {
36
+ signer: privateKeyAccount,
37
+ entryPoint,
38
+ index
39
+ })
40
+ }
@@ -0,0 +1,364 @@
1
+ import {
2
+ type Address,
3
+ type Chain,
4
+ type Client,
5
+ type Hex,
6
+ type LocalAccount,
7
+ type Transport,
8
+ concatHex,
9
+ encodeAbiParameters,
10
+ encodeFunctionData,
11
+ encodePacked,
12
+ getContractAddress,
13
+ hexToBigInt,
14
+ keccak256,
15
+ parseAbiParameters
16
+ } from "viem"
17
+ import { toAccount } from "viem/accounts"
18
+ import {
19
+ getBytecode,
20
+ getChainId,
21
+ signMessage,
22
+ signTypedData
23
+ } from "viem/actions"
24
+ import { getAccountNonce } from "../../actions/public/getAccountNonce.js"
25
+ import { getUserOperationHash } from "../../utils/getUserOperationHash.js"
26
+ import {
27
+ SignTransactionNotSupportedBySmartAccount,
28
+ type SmartAccount,
29
+ type SmartAccountSigner
30
+ } from "../types.js"
31
+ import {
32
+ BiconomyExecuteAbi,
33
+ BiconomyInitAbi
34
+ } from "./abi/BiconomySmartAccountAbi.js"
35
+ // import Abis
36
+
37
+ export type BiconomySmartAccount<
38
+ transport extends Transport = Transport,
39
+ chain extends Chain | undefined = Chain | undefined
40
+ > = SmartAccount<"biconomySmartAccount", transport, chain>
41
+
42
+ /**
43
+ * The account creation ABI for Biconomy Smart Account (from the biconomy SmartAccountFactory)
44
+ */
45
+
46
+ const createAccountAbi = [
47
+ {
48
+ inputs: [
49
+ {
50
+ internalType: "address",
51
+ name: "moduleSetupContract",
52
+ type: "address"
53
+ },
54
+ {
55
+ internalType: "bytes",
56
+ name: "moduleSetupData",
57
+ type: "bytes"
58
+ },
59
+ {
60
+ internalType: "uint256",
61
+ name: "index",
62
+ type: "uint256"
63
+ }
64
+ ],
65
+ name: "deployCounterFactualAccount",
66
+ outputs: [
67
+ {
68
+ internalType: "address",
69
+ name: "proxy",
70
+ type: "address"
71
+ }
72
+ ],
73
+ stateMutability: "nonpayable",
74
+ type: "function"
75
+ }
76
+ ] as const
77
+
78
+ /**
79
+ * Default addresses for Biconomy Smart Account
80
+ */
81
+ const BICONOMY_ADDRESSES: {
82
+ ECDSA_OWNERSHIP_REGISTRY_MODULE: Address
83
+ ACCOUNT_V2_0_LOGIC: Address
84
+ FACTORY_ADDRESS: Address
85
+ DEFAULT_FALLBACK_HANDLER_ADDRESS: Address
86
+ } = {
87
+ ECDSA_OWNERSHIP_REGISTRY_MODULE:
88
+ "0x0000001c5b32F37F5beA87BDD5374eB2aC54eA8e",
89
+ ACCOUNT_V2_0_LOGIC: "0x0000002512019Dafb59528B82CB92D3c5D2423aC",
90
+ FACTORY_ADDRESS: "0x000000a56Aaca3e9a4C479ea6b6CD0DbcB6634F5",
91
+ DEFAULT_FALLBACK_HANDLER_ADDRESS:
92
+ "0x0bBa6d96BD616BedC6BFaa341742FD43c60b83C1"
93
+ }
94
+
95
+ const BICONOMY_PROXY_CREATION_CODE =
96
+ "0x6080346100aa57601f61012038819003918201601f19168301916001600160401b038311848410176100af578084926020946040528339810103126100aa57516001600160a01b0381168082036100aa5715610065573055604051605a90816100c68239f35b60405162461bcd60e51b815260206004820152601e60248201527f496e76616c696420696d706c656d656e746174696f6e206164647265737300006044820152606490fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe608060405230546000808092368280378136915af43d82803e156020573d90f35b3d90fdfea2646970667358221220a03b18dce0be0b4c9afe58a9eb85c35205e2cf087da098bbf1d23945bf89496064736f6c63430008110033"
97
+
98
+ /**
99
+ * Get the account initialization code for Biconomy smart account with ECDSA as default authorization module
100
+ * @param owner
101
+ * @param index
102
+ * @param factoryAddress
103
+ * @param ecdsaValidatorAddress
104
+ */
105
+ const getAccountInitCode = async ({
106
+ owner,
107
+ index,
108
+ factoryAddress,
109
+ ecdsaModuleAddress
110
+ }: {
111
+ owner: Address
112
+ index: bigint
113
+ factoryAddress: Address
114
+ ecdsaModuleAddress: Address
115
+ }): Promise<Hex> => {
116
+ if (!owner) throw new Error("Owner account not found")
117
+
118
+ // Build the module setup data
119
+ const ecdsaOwnershipInitData = encodeFunctionData({
120
+ abi: BiconomyInitAbi,
121
+ functionName: "initForSmartAccount",
122
+ args: [owner]
123
+ })
124
+
125
+ // Build the account init code
126
+ return concatHex([
127
+ factoryAddress,
128
+ encodeFunctionData({
129
+ abi: createAccountAbi,
130
+ functionName: "deployCounterFactualAccount",
131
+ args: [ecdsaModuleAddress, ecdsaOwnershipInitData, index]
132
+ }) as Hex
133
+ ])
134
+ }
135
+
136
+ const getAccountAddress = async ({
137
+ factoryAddress,
138
+ accountLogicAddress,
139
+ fallbackHandlerAddress,
140
+ ecdsaModuleAddress,
141
+ owner,
142
+ index = 0n
143
+ }: {
144
+ factoryAddress: Address
145
+ accountLogicAddress: Address
146
+ fallbackHandlerAddress: Address
147
+ ecdsaModuleAddress: Address
148
+ owner: Address
149
+ index?: bigint
150
+ }): Promise<Address> => {
151
+ // Build the module setup data
152
+ const ecdsaOwnershipInitData = encodeFunctionData({
153
+ abi: BiconomyInitAbi,
154
+ functionName: "initForSmartAccount",
155
+ args: [owner]
156
+ })
157
+
158
+ // Build account init code
159
+ const initialisationData = encodeFunctionData({
160
+ abi: BiconomyInitAbi,
161
+ functionName: "init",
162
+ args: [
163
+ fallbackHandlerAddress,
164
+ ecdsaModuleAddress,
165
+ ecdsaOwnershipInitData
166
+ ]
167
+ })
168
+
169
+ const deploymentCode = encodePacked(
170
+ ["bytes", "uint256"],
171
+ [BICONOMY_PROXY_CREATION_CODE, hexToBigInt(accountLogicAddress)]
172
+ )
173
+
174
+ const salt = keccak256(
175
+ encodePacked(
176
+ ["bytes32", "uint256"],
177
+ [keccak256(encodePacked(["bytes"], [initialisationData])), index]
178
+ )
179
+ )
180
+
181
+ return getContractAddress({
182
+ from: factoryAddress,
183
+ salt,
184
+ bytecode: deploymentCode,
185
+ opcode: "CREATE2"
186
+ })
187
+ }
188
+
189
+ /**
190
+ * Build a Biconomy modular smart account from a private key, that use the ECDSA signer behind the scene
191
+ * @param client
192
+ * @param privateKey
193
+ * @param entryPoint
194
+ * @param index
195
+ * @param factoryAddress
196
+ * @param accountLogicAddress
197
+ * @param ecdsaModuleAddress
198
+ */
199
+ export async function signerToBiconomySmartAccount<
200
+ TTransport extends Transport = Transport,
201
+ TChain extends Chain | undefined = Chain | undefined,
202
+ TSource extends string = "custom",
203
+ TAddress extends Address = Address
204
+ >(
205
+ client: Client<TTransport, TChain>,
206
+ {
207
+ signer,
208
+ entryPoint,
209
+ index = 0n,
210
+ factoryAddress = BICONOMY_ADDRESSES.FACTORY_ADDRESS,
211
+ accountLogicAddress = BICONOMY_ADDRESSES.ACCOUNT_V2_0_LOGIC,
212
+ fallbackHandlerAddress = BICONOMY_ADDRESSES.DEFAULT_FALLBACK_HANDLER_ADDRESS,
213
+ ecdsaModuleAddress = BICONOMY_ADDRESSES.ECDSA_OWNERSHIP_REGISTRY_MODULE
214
+ }: {
215
+ signer: SmartAccountSigner<TSource, TAddress>
216
+ entryPoint: Address
217
+ index?: bigint
218
+ factoryAddress?: Address
219
+ accountLogicAddress?: Address
220
+ fallbackHandlerAddress?: Address
221
+ ecdsaModuleAddress?: Address
222
+ }
223
+ ): Promise<BiconomySmartAccount<TTransport, TChain>> {
224
+ // Get the private key related account
225
+ const viemSigner: LocalAccount = {
226
+ ...signer,
227
+ signTransaction: (_, __) => {
228
+ throw new SignTransactionNotSupportedBySmartAccount()
229
+ }
230
+ } as LocalAccount
231
+
232
+ // Helper to generate the init code for the smart account
233
+ const generateInitCode = () =>
234
+ getAccountInitCode({
235
+ owner: viemSigner.address,
236
+ index,
237
+ factoryAddress,
238
+ ecdsaModuleAddress
239
+ })
240
+
241
+ // Fetch account address and chain id
242
+ const [accountAddress, chainId] = await Promise.all([
243
+ getAccountAddress({
244
+ owner: viemSigner.address,
245
+ ecdsaModuleAddress,
246
+ factoryAddress,
247
+ accountLogicAddress,
248
+ fallbackHandlerAddress,
249
+ index
250
+ }),
251
+ getChainId(client)
252
+ ])
253
+
254
+ if (!accountAddress) throw new Error("Account address not found")
255
+
256
+ // Build the EOA Signer
257
+ const account = toAccount({
258
+ address: accountAddress,
259
+ async signMessage({ message }) {
260
+ return signMessage(client, { account: viemSigner, message })
261
+ },
262
+ async signTransaction(_, __) {
263
+ throw new SignTransactionNotSupportedBySmartAccount()
264
+ },
265
+ async signTypedData(typedData) {
266
+ return signTypedData(client, { account: viemSigner, ...typedData })
267
+ }
268
+ })
269
+
270
+ return {
271
+ ...account,
272
+ client: client,
273
+ publicKey: accountAddress,
274
+ entryPoint: entryPoint,
275
+ source: "biconomySmartAccount",
276
+
277
+ // Get the nonce of the smart account
278
+ async getNonce() {
279
+ return getAccountNonce(client, {
280
+ sender: accountAddress,
281
+ entryPoint: entryPoint
282
+ })
283
+ },
284
+
285
+ // Sign a user operation
286
+ async signUserOperation(userOperation) {
287
+ const hash = getUserOperationHash({
288
+ userOperation: {
289
+ ...userOperation,
290
+ signature: "0x"
291
+ },
292
+ entryPoint: entryPoint,
293
+ chainId: chainId
294
+ })
295
+ const signature = await signMessage(client, {
296
+ account: viemSigner,
297
+ message: { raw: hash }
298
+ })
299
+ // userOp signature is encoded module signature + module address
300
+ const signatureWithModuleAddress = encodeAbiParameters(
301
+ parseAbiParameters("bytes, address"),
302
+ [signature, ecdsaModuleAddress]
303
+ )
304
+ return signatureWithModuleAddress
305
+ },
306
+
307
+ // Encode the init code
308
+ async getInitCode() {
309
+ const contractCode = await getBytecode(client, {
310
+ address: accountAddress
311
+ })
312
+
313
+ if ((contractCode?.length ?? 0) > 2) return "0x"
314
+
315
+ return generateInitCode()
316
+ },
317
+
318
+ // Encode the deploy call data
319
+ async encodeDeployCallData(_) {
320
+ throw new Error("Doesn't support account deployment")
321
+ },
322
+
323
+ // Encode a call
324
+ async encodeCallData(args) {
325
+ if (Array.isArray(args)) {
326
+ // Encode a batched call
327
+ const argsArray = args as {
328
+ to: Address
329
+ value: bigint
330
+ data: Hex
331
+ }[]
332
+
333
+ return encodeFunctionData({
334
+ abi: BiconomyExecuteAbi,
335
+ functionName: "executeBatch_y6U",
336
+ args: [
337
+ argsArray.map((a) => a.to),
338
+ argsArray.map((a) => a.value),
339
+ argsArray.map((a) => a.data)
340
+ ]
341
+ })
342
+ }
343
+ const { to, value, data } = args as {
344
+ to: Address
345
+ value: bigint
346
+ data: Hex
347
+ }
348
+ // Encode a simple call
349
+ return encodeFunctionData({
350
+ abi: BiconomyExecuteAbi,
351
+ functionName: "execute_ncC",
352
+ args: [to, value, data]
353
+ })
354
+ },
355
+
356
+ // Get simple dummy signature for ECDSA module authorization
357
+ async getDummySignature() {
358
+ const moduleAddress =
359
+ BICONOMY_ADDRESSES.ECDSA_OWNERSHIP_REGISTRY_MODULE
360
+ const dynamicPart = moduleAddress.substring(2).padEnd(40, "0")
361
+ return `0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000${dynamicPart}000000000000000000000000000000000000000000000000000000000000004181d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b00000000000000000000000000000000000000000000000000000000000000`
362
+ }
363
+ }
364
+ }
package/accounts/index.ts CHANGED
@@ -18,6 +18,11 @@ import {
18
18
  signerToEcdsaKernelSmartAccount
19
19
  } from "./kernel/signerToEcdsaKernelSmartAccount.js"
20
20
 
21
+ import {
22
+ type BiconomySmartAccount,
23
+ signerToBiconomySmartAccount
24
+ } from "./biconomy/signerToBiconomySmartAccount.js"
25
+
21
26
  import {
22
27
  SignTransactionNotSupportedBySmartAccount,
23
28
  type SmartAccount,
@@ -36,5 +41,7 @@ export {
36
41
  type SmartAccount,
37
42
  privateKeyToSafeSmartAccount,
38
43
  type KernelEcdsaSmartAccount,
39
- signerToEcdsaKernelSmartAccount
44
+ signerToEcdsaKernelSmartAccount,
45
+ type BiconomySmartAccount,
46
+ signerToBiconomySmartAccount
40
47
  }
@@ -344,14 +344,13 @@ export async function signerToEcdsaKernelSmartAccount<
344
344
  }))
345
345
  ]
346
346
  })
347
- } else {
348
- // Encode a simple call
349
- return encodeFunctionData({
350
- abi: KernelExecuteAbi,
351
- functionName: "execute",
352
- args: [_tx.to, _tx.value, _tx.data, 0]
353
- })
354
347
  }
348
+ // Encode a simple call
349
+ return encodeFunctionData({
350
+ abi: KernelExecuteAbi,
351
+ functionName: "execute",
352
+ args: [_tx.to, _tx.value, _tx.data, 0]
353
+ })
355
354
  },
356
355
 
357
356
  // Get simple dummy signature
@@ -87,7 +87,7 @@ export const waitForUserOperationReceipt = <
87
87
  )
88
88
  }
89
89
 
90
- const _unobserve = observe(
90
+ const unobserve = observe(
91
91
  observerId,
92
92
  { resolve, reject },
93
93
  async (emit) => {
@@ -95,7 +95,7 @@ export const waitForUserOperationReceipt = <
95
95
  const done = (fn: () => void) => {
96
96
  clearInterval(_removeInterval)
97
97
  fn()
98
- _unobserve()
98
+ unobserve()
99
99
  }
100
100
 
101
101
  const _userOperationReceipt = await getAction(
@@ -26,7 +26,7 @@ export type SponsorUserOperationMiddleware = {
26
26
  }
27
27
 
28
28
  export type PrepareUserOperationRequestParameters<
29
- TAccount extends SmartAccount | undefined = SmartAccount | undefined,
29
+ TAccount extends SmartAccount | undefined = SmartAccount | undefined
30
30
  > = {
31
31
  userOperation: PartialBy<
32
32
  UserOperation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "permissionless",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "author": "Pimlico",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
@@ -12,9 +12,13 @@ export function deepHexlify(obj: any): any {
12
12
  }
13
13
  if (obj == null || typeof obj === "string" || typeof obj === "boolean") {
14
14
  return obj
15
- } else if (typeof obj === "bigint") {
15
+ }
16
+
17
+ if (typeof obj === "bigint") {
16
18
  return toHex(obj)
17
- } else if (obj._isBigNumber != null || typeof obj !== "object") {
19
+ }
20
+
21
+ if (obj._isBigNumber != null || typeof obj !== "object") {
18
22
  return toHex(obj).replace(/^0x0/, "0x")
19
23
  }
20
24
  if (Array.isArray(obj)) {
package/utils/index.ts CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  AccountOrClientNotFoundError,
12
12
  signUserOperationHashWithECDSA
13
13
  } from "./signUserOperationHashWithECDSA.js"
14
+ import { walletClientToCustomSigner } from "./walletClientToCustomSigner.js"
14
15
 
15
16
  export function parseAccount(account: Address | Account): Account {
16
17
  if (typeof account === "string")
@@ -21,6 +22,7 @@ export function parseAccount(account: Address | Account): Account {
21
22
  export {
22
23
  getUserOperationHash,
23
24
  getRequiredPrefund,
25
+ walletClientToCustomSigner,
24
26
  type GetRequiredPrefundReturnType,
25
27
  type GetUserOperationHashParams,
26
28
  signUserOperationHashWithECDSA,
@@ -0,0 +1,42 @@
1
+ import type {
2
+ Account,
3
+ Address,
4
+ Chain,
5
+ Hex,
6
+ SignableMessage,
7
+ Transport,
8
+ TypedData,
9
+ TypedDataDefinition,
10
+ WalletClient
11
+ } from "viem"
12
+
13
+ import type { SmartAccountSigner } from "../accounts/types.js"
14
+
15
+ export function walletClientToCustomSigner<
16
+ TChain extends Chain | undefined = Chain | undefined
17
+ >(
18
+ walletClient: WalletClient<Transport, TChain, Account>
19
+ ): SmartAccountSigner<"custom", Address> {
20
+ return {
21
+ address: walletClient.account.address,
22
+ type: "local",
23
+ source: "custom",
24
+ publicKey: walletClient.account.address,
25
+ signMessage: async ({
26
+ message
27
+ }: { message: SignableMessage }): Promise<Hex> => {
28
+ return walletClient.signMessage({ message })
29
+ },
30
+ signTypedData: async <
31
+ const TTypedData extends TypedData | { [key: string]: unknown },
32
+ TPrimaryType extends string = string
33
+ >(
34
+ typedData: TypedDataDefinition<TTypedData, TPrimaryType>
35
+ ): Promise<Hex> => {
36
+ return walletClient.signTypedData({
37
+ account: walletClient.account,
38
+ ...typedData
39
+ })
40
+ }
41
+ }
42
+ }