permissionless 0.1.3 → 0.1.5

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 (78) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/_cjs/accounts/biconomy/signerToBiconomySmartAccount.js +21 -9
  3. package/_cjs/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -1
  4. package/_cjs/accounts/index.js +3 -1
  5. package/_cjs/accounts/index.js.map +1 -1
  6. package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js +4 -7
  7. package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
  8. package/_cjs/accounts/safe/signerToSafeSmartAccount.js +4 -7
  9. package/_cjs/accounts/safe/signerToSafeSmartAccount.js.map +1 -1
  10. package/_cjs/accounts/simple/signerToSimpleSmartAccount.js +11 -16
  11. package/_cjs/accounts/simple/signerToSimpleSmartAccount.js.map +1 -1
  12. package/_cjs/accounts/toSmartAccount.js +84 -0
  13. package/_cjs/accounts/toSmartAccount.js.map +1 -0
  14. package/_cjs/actions/smartAccount/prepareUserOperationRequest.js +2 -6
  15. package/_cjs/actions/smartAccount/prepareUserOperationRequest.js.map +1 -1
  16. package/_cjs/clients/decorators/pimlico.js +5 -2
  17. package/_cjs/clients/decorators/pimlico.js.map +1 -1
  18. package/_cjs/clients/pimlico.js +1 -1
  19. package/_cjs/clients/pimlico.js.map +1 -1
  20. package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js +21 -10
  21. package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -1
  22. package/_esm/accounts/index.js +2 -1
  23. package/_esm/accounts/index.js.map +1 -1
  24. package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js +4 -8
  25. package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
  26. package/_esm/accounts/safe/signerToSafeSmartAccount.js +4 -7
  27. package/_esm/accounts/safe/signerToSafeSmartAccount.js.map +1 -1
  28. package/_esm/accounts/simple/signerToSimpleSmartAccount.js +12 -17
  29. package/_esm/accounts/simple/signerToSimpleSmartAccount.js.map +1 -1
  30. package/_esm/accounts/toSmartAccount.js +80 -0
  31. package/_esm/accounts/toSmartAccount.js.map +1 -0
  32. package/_esm/actions/pimlico/sendCompressedUserOperation.js +1 -1
  33. package/_esm/actions/smartAccount/prepareUserOperationRequest.js +2 -6
  34. package/_esm/actions/smartAccount/prepareUserOperationRequest.js.map +1 -1
  35. package/_esm/clients/decorators/pimlico.js +5 -2
  36. package/_esm/clients/decorators/pimlico.js.map +1 -1
  37. package/_esm/clients/pimlico.js +1 -1
  38. package/_esm/clients/pimlico.js.map +1 -1
  39. package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts +2 -2
  40. package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts.map +1 -1
  41. package/_types/accounts/index.d.ts +2 -1
  42. package/_types/accounts/index.d.ts.map +1 -1
  43. package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts +2 -2
  44. package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts.map +1 -1
  45. package/_types/accounts/safe/signerToSafeSmartAccount.d.ts +2 -2
  46. package/_types/accounts/safe/signerToSafeSmartAccount.d.ts.map +1 -1
  47. package/_types/accounts/simple/signerToSimpleSmartAccount.d.ts +2 -2
  48. package/_types/accounts/simple/signerToSimpleSmartAccount.d.ts.map +1 -1
  49. package/_types/accounts/toSmartAccount.d.ts +26 -0
  50. package/_types/accounts/toSmartAccount.d.ts.map +1 -0
  51. package/_types/accounts/types.d.ts +1 -1
  52. package/_types/accounts/types.d.ts.map +1 -1
  53. package/_types/actions/bundler/estimateUserOperationGas.d.ts +2 -2
  54. package/_types/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
  55. package/_types/actions/pimlico/sendCompressedUserOperation.d.ts +1 -1
  56. package/_types/actions/pimlico/sponsorUserOperation.d.ts +6 -6
  57. package/_types/actions/smartAccount/prepareUserOperationRequest.d.ts.map +1 -1
  58. package/_types/clients/decorators/pimlico.d.ts +3 -3
  59. package/_types/clients/decorators/pimlico.d.ts.map +1 -1
  60. package/_types/types/bundler.d.ts +3 -3
  61. package/_types/types/bundler.d.ts.map +1 -1
  62. package/_types/types/userOperation.d.ts +6 -6
  63. package/_types/types/userOperation.d.ts.map +1 -1
  64. package/accounts/biconomy/signerToBiconomySmartAccount.ts +36 -18
  65. package/accounts/index.ts +3 -0
  66. package/accounts/kernel/signerToEcdsaKernelSmartAccount.ts +6 -11
  67. package/accounts/safe/signerToSafeSmartAccount.ts +218 -209
  68. package/accounts/simple/signerToSimpleSmartAccount.ts +14 -30
  69. package/accounts/toSmartAccount.ts +167 -0
  70. package/accounts/types.ts +2 -2
  71. package/actions/bundler/estimateUserOperationGas.ts +4 -4
  72. package/actions/pimlico/sendCompressedUserOperation.ts +1 -1
  73. package/actions/smartAccount/prepareUserOperationRequest.ts +2 -6
  74. package/clients/decorators/pimlico.ts +35 -21
  75. package/clients/pimlico.ts +1 -1
  76. package/package.json +1 -1
  77. package/types/bundler.ts +3 -3
  78. package/types/userOperation.ts +6 -6
@@ -0,0 +1,167 @@
1
+ import {
2
+ type Abi,
3
+ type Address,
4
+ type Chain,
5
+ type Client,
6
+ type CustomSource,
7
+ type EncodeDeployDataParameters,
8
+ type Hex,
9
+ type SignableMessage,
10
+ type Transport,
11
+ type TypedDataDefinition,
12
+ concat,
13
+ encodeAbiParameters
14
+ } from "viem"
15
+ import { toAccount } from "viem/accounts"
16
+ import type { UserOperation } from "../types"
17
+ import type { EntryPoint, GetEntryPointVersion } from "../types/entrypoint"
18
+ import { isSmartAccountDeployed } from "../utils"
19
+ import {
20
+ SignTransactionNotSupportedBySmartAccount,
21
+ type SmartAccount
22
+ } from "./types"
23
+
24
+ const MAGIC_BYTES =
25
+ "0x6492649264926492649264926492649264926492649264926492649264926492"
26
+
27
+ export function toSmartAccount<
28
+ TAccountSource extends CustomSource,
29
+ TEntryPoint extends EntryPoint,
30
+ TSource extends string = string,
31
+ transport extends Transport = Transport,
32
+ chain extends Chain | undefined = Chain | undefined,
33
+ TAbi extends Abi | readonly unknown[] = Abi
34
+ >({
35
+ address,
36
+ client,
37
+ source,
38
+ entryPoint,
39
+ getNonce,
40
+ getInitCode,
41
+ getFactory,
42
+ getFactoryData,
43
+ encodeCallData,
44
+ getDummySignature,
45
+ encodeDeployCallData,
46
+ signUserOperation,
47
+ signMessage,
48
+ signTypedData
49
+ }: TAccountSource & {
50
+ source: TSource
51
+ client: Client<transport, chain>
52
+ entryPoint: TEntryPoint
53
+ getNonce: () => Promise<bigint>
54
+ getInitCode: () => Promise<Hex>
55
+ getFactory: () => Promise<Address | undefined>
56
+ getFactoryData: () => Promise<Hex | undefined>
57
+ encodeCallData: (
58
+ args:
59
+ | {
60
+ to: Address
61
+ value: bigint
62
+ data: Hex
63
+ }
64
+ | {
65
+ to: Address
66
+ value: bigint
67
+ data: Hex
68
+ }[]
69
+ ) => Promise<Hex>
70
+ getDummySignature(
71
+ userOperation: UserOperation<GetEntryPointVersion<TEntryPoint>>
72
+ ): Promise<Hex>
73
+ encodeDeployCallData: ({
74
+ abi,
75
+ args,
76
+ bytecode
77
+ }: EncodeDeployDataParameters<TAbi>) => Promise<Hex>
78
+ signUserOperation: (
79
+ userOperation: UserOperation<GetEntryPointVersion<TEntryPoint>>
80
+ ) => Promise<Hex>
81
+ }): SmartAccount<TEntryPoint, TSource, transport, chain, TAbi> {
82
+ const account = toAccount({
83
+ address: address,
84
+ signMessage: async ({ message }: { message: SignableMessage }) => {
85
+ const isDeployed = await isSmartAccountDeployed(client, address)
86
+ const signature = await signMessage({ message })
87
+
88
+ if (isDeployed) return signature
89
+
90
+ const abiEncodedMessage = encodeAbiParameters(
91
+ [
92
+ {
93
+ type: "address",
94
+ name: "create2Factory"
95
+ },
96
+ {
97
+ type: "bytes",
98
+ name: "factoryCalldata"
99
+ },
100
+ {
101
+ type: "bytes",
102
+ name: "originalERC1271Signature"
103
+ }
104
+ ],
105
+ [
106
+ (await getFactory()) ?? "0x", // "0x should never happen if it's deployed"
107
+ (await getFactoryData()) ?? "0x", // "0x should never happen if it's deployed"
108
+ signature
109
+ ]
110
+ )
111
+
112
+ return concat([abiEncodedMessage, MAGIC_BYTES])
113
+ },
114
+ signTypedData: async (typedData) => {
115
+ const isDeployed = await isSmartAccountDeployed(client, address)
116
+ const signature = await signTypedData(
117
+ typedData as TypedDataDefinition
118
+ )
119
+
120
+ if (isDeployed) return signature
121
+
122
+ const abiEncodedMessage = encodeAbiParameters(
123
+ [
124
+ {
125
+ type: "address",
126
+ name: "create2Factory"
127
+ },
128
+ {
129
+ type: "bytes",
130
+ name: "factoryCalldata"
131
+ },
132
+ {
133
+ type: "bytes",
134
+ name: "originalERC1271Signature"
135
+ }
136
+ ],
137
+ [
138
+ (await getFactory()) ?? "0x", // "0x should never happen if it's deployed"
139
+ (await getFactoryData()) ?? "0x", // "0x should never happen if it's deployed"
140
+ signature
141
+ ]
142
+ )
143
+
144
+ return concat([abiEncodedMessage, MAGIC_BYTES])
145
+ },
146
+ async signTransaction(_, __) {
147
+ throw new SignTransactionNotSupportedBySmartAccount()
148
+ }
149
+ })
150
+
151
+ return {
152
+ ...account,
153
+ source,
154
+ client,
155
+ type: "local",
156
+ entryPoint,
157
+ publicKey: address,
158
+ getNonce,
159
+ getInitCode,
160
+ getFactory,
161
+ getFactoryData,
162
+ encodeCallData,
163
+ getDummySignature,
164
+ encodeDeployCallData,
165
+ signUserOperation
166
+ } as SmartAccount<TEntryPoint, TSource, transport, chain, TAbi>
167
+ }
package/accounts/types.ts CHANGED
@@ -28,11 +28,11 @@ export class SignTransactionNotSupportedBySmartAccount extends BaseError {
28
28
 
29
29
  export type SmartAccount<
30
30
  entryPoint extends EntryPoint,
31
- Name extends string = string,
31
+ TSource extends string = string,
32
32
  transport extends Transport = Transport,
33
33
  chain extends Chain | undefined = Chain | undefined,
34
34
  TAbi extends Abi | readonly unknown[] = Abi
35
- > = LocalAccount<Name> & {
35
+ > = LocalAccount<TSource> & {
36
36
  client: Client<transport, chain>
37
37
  entryPoint: entryPoint
38
38
  getNonce: () => Promise<bigint>
@@ -48,8 +48,8 @@ export type EstimateUserOperationGasReturnType<entryPoint extends EntryPoint> =
48
48
  preVerificationGas: bigint
49
49
  verificationGasLimit: bigint
50
50
  callGasLimit: bigint
51
- paymasterVerificationGasLimit: bigint | undefined
52
- paymasterPostOpGasLimit: bigint | undefined
51
+ paymasterVerificationGasLimit?: bigint
52
+ paymasterPostOpGasLimit?: bigint
53
53
  }
54
54
 
55
55
  export type EstimateUserOperationErrorType<entryPoint extends EntryPoint> =
@@ -131,8 +131,8 @@ export const estimateUserOperationGas = async <
131
131
  preVerificationGas: Hex
132
132
  verificationGasLimit: Hex
133
133
  callGasLimit: Hex
134
- paymasterVerificationGasLimit: Hex | undefined
135
- paymasterPostOpGasLimit: Hex | undefined
134
+ paymasterVerificationGasLimit?: Hex
135
+ paymasterPostOpGasLimit?: Hex
136
136
  }
137
137
 
138
138
  return {
@@ -32,7 +32,7 @@ export type SendCompressedUserOperationParameters = {
32
32
  * const bundlerClient = createClient({
33
33
  * chain: goerli,
34
34
  * transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
35
- * }).extend(pimlicoBundlerActions)
35
+ * }).extend(pimlicoBundlerActions(entryPoint))
36
36
  *
37
37
  * const userOpHash = await sendCompressedUserOperation(bundlerClient, {
38
38
  * compressedUserOperation,
@@ -269,8 +269,8 @@ async function prepareUserOperationRequestEntryPointV07<
269
269
  const userOperation: UserOperation<"v0.7"> = {
270
270
  sender,
271
271
  nonce,
272
- factory: factory || undefined,
273
- factoryData: factoryData || undefined,
272
+ factory: factory,
273
+ factoryData: factoryData,
274
274
  callData,
275
275
  callGasLimit: partialUserOperation.callGasLimit || 0n,
276
276
  verificationGasLimit: partialUserOperation.verificationGasLimit || 0n,
@@ -283,10 +283,6 @@ async function prepareUserOperationRequestEntryPointV07<
283
283
  partialUserOperation.maxPriorityFeePerGas ||
284
284
  gasEstimation?.maxPriorityFeePerGas ||
285
285
  0n,
286
- paymaster: undefined,
287
- paymasterVerificationGasLimit: undefined,
288
- paymasterPostOpGasLimit: undefined,
289
- paymasterData: undefined,
290
286
  signature: partialUserOperation.signature || "0x"
291
287
  }
292
288
 
@@ -94,28 +94,37 @@ export type PimlicoBundlerActions = {
94
94
  * // Return '0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34'
95
95
  */
96
96
  sendCompressedUserOperation: (
97
- args: Prettify<SendCompressedUserOperationParameters>
97
+ args: Prettify<
98
+ Omit<SendCompressedUserOperationParameters, "entryPoint">
99
+ >
98
100
  ) => Promise<Hash>
99
101
  }
100
102
 
101
- export const pimlicoBundlerActions = <entryPoint extends EntryPoint>(
102
- client: Client
103
- ): PimlicoBundlerActions => ({
104
- getUserOperationGasPrice: async () =>
105
- getUserOperationGasPrice(client as PimlicoBundlerClient<entryPoint>),
106
- getUserOperationStatus: async (args: GetUserOperationStatusParameters) =>
107
- getUserOperationStatus(
108
- client as PimlicoBundlerClient<entryPoint>,
109
- args
110
- ),
111
- sendCompressedUserOperation: async (
112
- args: SendCompressedUserOperationParameters
113
- ) =>
114
- sendCompressedUserOperation(
115
- client as PimlicoBundlerClient<entryPoint>,
116
- args
117
- )
118
- })
103
+ export const pimlicoBundlerActions =
104
+ <entryPoint extends EntryPoint>(entryPointAddress: entryPoint) =>
105
+ (client: Client): PimlicoBundlerActions => ({
106
+ getUserOperationGasPrice: async () =>
107
+ getUserOperationGasPrice(
108
+ client as PimlicoBundlerClient<entryPoint>
109
+ ),
110
+ getUserOperationStatus: async (
111
+ args: GetUserOperationStatusParameters
112
+ ) =>
113
+ getUserOperationStatus(
114
+ client as PimlicoBundlerClient<entryPoint>,
115
+ args
116
+ ),
117
+ sendCompressedUserOperation: async (
118
+ args: Omit<SendCompressedUserOperationParameters, "entryPoint">
119
+ ) =>
120
+ sendCompressedUserOperation(
121
+ client as PimlicoBundlerClient<entryPoint>,
122
+ {
123
+ ...args,
124
+ entryPoint: entryPointAddress
125
+ }
126
+ )
127
+ })
119
128
 
120
129
  export type PimlicoPaymasterClientActions<entryPoint extends EntryPoint> = {
121
130
  /**
@@ -149,7 +158,12 @@ export type PimlicoPaymasterClientActions<entryPoint extends EntryPoint> = {
149
158
  ) => Promise<Prettify<SponsorUserOperationReturnType<entryPoint>>>
150
159
 
151
160
  validateSponsorshipPolicies: (
152
- args: Prettify<ValidateSponsorshipPoliciesParameters<entryPoint>>
161
+ args: Prettify<
162
+ Omit<
163
+ ValidateSponsorshipPoliciesParameters<entryPoint>,
164
+ "entryPoint"
165
+ >
166
+ >
153
167
  ) => Promise<Prettify<ValidateSponsorshipPolicies>[]>
154
168
  }
155
169
 
@@ -210,7 +224,7 @@ export const pimlicoPaymasterActions =
210
224
  "entryPoint"
211
225
  >
212
226
  ) =>
213
- validateSponsorshipPolicies<entryPoint>(
227
+ validateSponsorshipPolicies(
214
228
  client as PimlicoPaymasterClient<entryPoint>,
215
229
  { ...args, entryPoint: entryPointAddress }
216
230
  )
@@ -72,7 +72,7 @@ export const createPimlicoBundlerClient = <
72
72
  })
73
73
  return client
74
74
  .extend(bundlerActions(parameters.entryPoint))
75
- .extend(pimlicoBundlerActions)
75
+ .extend(pimlicoBundlerActions(parameters.entryPoint))
76
76
  }
77
77
 
78
78
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "permissionless",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "author": "Pimlico",
5
5
  "homepage": "https://docs.pimlico.io/permissionless",
6
6
  "repository": "github:pimlicolabs/permissionless.js",
package/types/bundler.ts CHANGED
@@ -44,9 +44,9 @@ export type BundlerRpcSchema<entryPoint extends EntryPoint> = [
44
44
  : {
45
45
  preVerificationGas: Hex
46
46
  verificationGasLimit: Hex
47
- callGasLimit: Hex | null | undefined
48
- paymasterVerificationGasLimit: Hex | null | undefined
49
- paymasterPostOpGasLimit: Hex | null | undefined
47
+ callGasLimit?: Hex | null
48
+ paymasterVerificationGasLimit?: Hex | null
49
+ paymasterPostOpGasLimit?: Hex | null
50
50
  }
51
51
  },
52
52
  {
@@ -70,18 +70,18 @@ export type UserOperation<entryPointVersion extends EntryPointVersion> =
70
70
  : {
71
71
  sender: Address
72
72
  nonce: bigint
73
- factory: Address | undefined
74
- factoryData: Hex | undefined
73
+ factory?: Address
74
+ factoryData?: Hex
75
75
  callData: Hex
76
76
  callGasLimit: bigint
77
77
  verificationGasLimit: bigint
78
78
  preVerificationGas: bigint
79
79
  maxFeePerGas: bigint
80
80
  maxPriorityFeePerGas: bigint
81
- paymaster: Address | undefined
82
- paymasterVerificationGasLimit: bigint | undefined
83
- paymasterPostOpGasLimit: bigint | undefined
84
- paymasterData: Hex | undefined
81
+ paymaster?: Address
82
+ paymasterVerificationGasLimit?: bigint
83
+ paymasterPostOpGasLimit?: bigint
84
+ paymasterData?: Hex
85
85
  signature: Hex
86
86
  initCode?: never
87
87
  paymasterAndData?: never