permissionless 0.1.4 → 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 (43) hide show
  1. package/CHANGELOG.md +6 -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/_esm/accounts/biconomy/signerToBiconomySmartAccount.js +21 -10
  15. package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -1
  16. package/_esm/accounts/index.js +2 -1
  17. package/_esm/accounts/index.js.map +1 -1
  18. package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js +4 -8
  19. package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
  20. package/_esm/accounts/safe/signerToSafeSmartAccount.js +4 -7
  21. package/_esm/accounts/safe/signerToSafeSmartAccount.js.map +1 -1
  22. package/_esm/accounts/simple/signerToSimpleSmartAccount.js +12 -17
  23. package/_esm/accounts/simple/signerToSimpleSmartAccount.js.map +1 -1
  24. package/_esm/accounts/toSmartAccount.js +80 -0
  25. package/_esm/accounts/toSmartAccount.js.map +1 -0
  26. package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts.map +1 -1
  27. package/_types/accounts/index.d.ts +2 -1
  28. package/_types/accounts/index.d.ts.map +1 -1
  29. package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts.map +1 -1
  30. package/_types/accounts/safe/signerToSafeSmartAccount.d.ts.map +1 -1
  31. package/_types/accounts/simple/signerToSimpleSmartAccount.d.ts.map +1 -1
  32. package/_types/accounts/toSmartAccount.d.ts +26 -0
  33. package/_types/accounts/toSmartAccount.d.ts.map +1 -0
  34. package/_types/accounts/types.d.ts +1 -1
  35. package/_types/accounts/types.d.ts.map +1 -1
  36. package/accounts/biconomy/signerToBiconomySmartAccount.ts +34 -16
  37. package/accounts/index.ts +3 -0
  38. package/accounts/kernel/signerToEcdsaKernelSmartAccount.ts +4 -9
  39. package/accounts/safe/signerToSafeSmartAccount.ts +216 -207
  40. package/accounts/simple/signerToSimpleSmartAccount.ts +12 -28
  41. package/accounts/toSmartAccount.ts +167 -0
  42. package/accounts/types.ts +2 -2
  43. package/package.json +1 -1
@@ -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>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "permissionless",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "author": "Pimlico",
5
5
  "homepage": "https://docs.pimlico.io/permissionless",
6
6
  "repository": "github:pimlicolabs/permissionless.js",