permissionless 0.1.4 → 0.1.6

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 (48) hide show
  1. package/CHANGELOG.md +12 -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/clients/createSmartAccountClient.js.map +1 -1
  15. package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js +21 -10
  16. package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -1
  17. package/_esm/accounts/index.js +2 -1
  18. package/_esm/accounts/index.js.map +1 -1
  19. package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js +4 -8
  20. package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
  21. package/_esm/accounts/safe/signerToSafeSmartAccount.js +4 -7
  22. package/_esm/accounts/safe/signerToSafeSmartAccount.js.map +1 -1
  23. package/_esm/accounts/simple/signerToSimpleSmartAccount.js +12 -17
  24. package/_esm/accounts/simple/signerToSimpleSmartAccount.js.map +1 -1
  25. package/_esm/accounts/toSmartAccount.js +80 -0
  26. package/_esm/accounts/toSmartAccount.js.map +1 -0
  27. package/_esm/clients/createSmartAccountClient.js.map +1 -1
  28. package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts.map +1 -1
  29. package/_types/accounts/index.d.ts +2 -1
  30. package/_types/accounts/index.d.ts.map +1 -1
  31. package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts.map +1 -1
  32. package/_types/accounts/safe/signerToSafeSmartAccount.d.ts.map +1 -1
  33. package/_types/accounts/simple/signerToSimpleSmartAccount.d.ts.map +1 -1
  34. package/_types/accounts/toSmartAccount.d.ts +26 -0
  35. package/_types/accounts/toSmartAccount.d.ts.map +1 -0
  36. package/_types/accounts/types.d.ts +1 -1
  37. package/_types/accounts/types.d.ts.map +1 -1
  38. package/_types/clients/createSmartAccountClient.d.ts +5 -5
  39. package/_types/clients/createSmartAccountClient.d.ts.map +1 -1
  40. package/accounts/biconomy/signerToBiconomySmartAccount.ts +34 -16
  41. package/accounts/index.ts +3 -0
  42. package/accounts/kernel/signerToEcdsaKernelSmartAccount.ts +4 -9
  43. package/accounts/safe/signerToSafeSmartAccount.ts +216 -207
  44. package/accounts/simple/signerToSimpleSmartAccount.ts +12 -28
  45. package/accounts/toSmartAccount.ts +167 -0
  46. package/accounts/types.ts +2 -2
  47. package/clients/createSmartAccountClient.ts +14 -13
  48. package/package.json +1 -1
@@ -1,4 +1,3 @@
1
- import type { TypedData } from "viem"
2
1
  import {
3
2
  type Address,
4
3
  type Chain,
@@ -6,12 +5,10 @@ import {
6
5
  type Hex,
7
6
  type LocalAccount,
8
7
  type Transport,
9
- type TypedDataDefinition,
10
8
  concatHex,
11
9
  encodeFunctionData
12
10
  } from "viem"
13
- import { toAccount } from "viem/accounts"
14
- import { getChainId, signMessage, signTypedData } from "viem/actions"
11
+ import { getChainId, signMessage } from "viem/actions"
15
12
  import { getAccountNonce } from "../../actions/public/getAccountNonce"
16
13
  import { getSenderAddress } from "../../actions/public/getSenderAddress"
17
14
  import type {
@@ -23,6 +20,7 @@ import type { EntryPoint } from "../../types/entrypoint"
23
20
  import { getEntryPointVersion } from "../../utils"
24
21
  import { getUserOperationHash } from "../../utils/getUserOperationHash"
25
22
  import { isSmartAccountDeployed } from "../../utils/isSmartAccountDeployed"
23
+ import { toSmartAccount } from "../toSmartAccount"
26
24
  import {
27
25
  SignTransactionNotSupportedBySmartAccount,
28
26
  type SmartAccount,
@@ -165,32 +163,17 @@ export async function signerToSimpleSmartAccount<
165
163
  accountAddress
166
164
  )
167
165
 
168
- const account = toAccount({
166
+ return toSmartAccount({
169
167
  address: accountAddress,
170
- async signMessage({ message }) {
171
- return signMessage(client, { account: viemSigner, message })
168
+ signMessage: async (_) => {
169
+ throw new Error("Simple account isn't 1271 compliant")
172
170
  },
173
- async signTransaction(_, __) {
171
+ signTransaction: (_, __) => {
174
172
  throw new SignTransactionNotSupportedBySmartAccount()
175
173
  },
176
- async signTypedData<
177
- const TTypedData extends TypedData | Record<string, unknown>,
178
- TPrimaryType extends
179
- | keyof TTypedData
180
- | "EIP712Domain" = keyof TTypedData
181
- >(typedData: TypedDataDefinition<TTypedData, TPrimaryType>) {
182
- return signTypedData<TTypedData, TPrimaryType, TChain, undefined>(
183
- client,
184
- {
185
- account: viemSigner,
186
- ...typedData
187
- }
188
- )
189
- }
190
- })
191
-
192
- return {
193
- ...account,
174
+ signTypedData: async (_) => {
175
+ throw new Error("Simple account isn't 1271 compliant")
176
+ },
194
177
  client: client,
195
178
  publicKey: accountAddress,
196
179
  entryPoint: entryPointAddress,
@@ -202,7 +185,8 @@ export async function signerToSimpleSmartAccount<
202
185
  })
203
186
  },
204
187
  async signUserOperation(userOperation) {
205
- return account.signMessage({
188
+ return signMessage(client, {
189
+ account: viemSigner,
206
190
  message: {
207
191
  raw: getUserOperationHash({
208
192
  userOperation,
@@ -359,5 +343,5 @@ export async function signerToSimpleSmartAccount<
359
343
  async getDummySignature(_userOperation) {
360
344
  return "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
361
345
  }
362
- }
346
+ })
363
347
  }
@@ -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>
@@ -49,11 +49,12 @@ export type SmartAccountClientConfig<
49
49
  Pick<
50
50
  ClientConfig<transport, chain, account>,
51
51
  "cacheTime" | "chain" | "key" | "name" | "pollingInterval"
52
- > & {
53
- account?: account
54
- bundlerTransport: Transport
55
- } & Middleware<entryPoint> & {
56
- entryPoint: entryPoint
52
+ > &
53
+ Middleware<entryPoint> & {
54
+ account: account
55
+ bundlerTransport: Transport
56
+ } & {
57
+ entryPoint?: entryPoint
57
58
  }
58
59
  >
59
60
 
@@ -78,20 +79,20 @@ export type SmartAccountClientConfig<
78
79
  */
79
80
 
80
81
  export function createSmartAccountClient<
81
- entryPoint extends EntryPoint,
82
- TSmartAccount extends SmartAccount<entryPoint> | undefined =
83
- | SmartAccount<entryPoint>
84
- | undefined,
82
+ TSmartAccount extends SmartAccount<TEntryPoint> | undefined,
85
83
  TTransport extends Transport = Transport,
86
- TChain extends Chain | undefined = undefined
84
+ TChain extends Chain | undefined = undefined,
85
+ TEntryPoint extends EntryPoint = TSmartAccount extends SmartAccount<infer U>
86
+ ? U
87
+ : never
87
88
  >(
88
89
  parameters: SmartAccountClientConfig<
89
- entryPoint,
90
+ TEntryPoint,
90
91
  TTransport,
91
92
  TChain,
92
93
  TSmartAccount
93
94
  >
94
- ): SmartAccountClient<entryPoint, TTransport, TChain, TSmartAccount> {
95
+ ): SmartAccountClient<TEntryPoint, TTransport, TChain, TSmartAccount> {
95
96
  const {
96
97
  key = "Account",
97
98
  name = "Smart Account Client",
@@ -109,5 +110,5 @@ export function createSmartAccountClient<
109
110
  smartAccountActions({
110
111
  middleware: parameters.middleware
111
112
  })
112
- ) as SmartAccountClient<entryPoint, TTransport, TChain, TSmartAccount>
113
+ ) as SmartAccountClient<TEntryPoint, TTransport, TChain, TSmartAccount>
113
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "permissionless",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "author": "Pimlico",
5
5
  "homepage": "https://docs.pimlico.io/permissionless",
6
6
  "repository": "github:pimlicolabs/permissionless.js",