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.
- package/CHANGELOG.md +15 -0
- package/_cjs/accounts/biconomy/signerToBiconomySmartAccount.js +21 -9
- package/_cjs/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -1
- package/_cjs/accounts/index.js +3 -1
- package/_cjs/accounts/index.js.map +1 -1
- package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js +4 -7
- package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
- package/_cjs/accounts/safe/signerToSafeSmartAccount.js +4 -7
- package/_cjs/accounts/safe/signerToSafeSmartAccount.js.map +1 -1
- package/_cjs/accounts/simple/signerToSimpleSmartAccount.js +11 -16
- package/_cjs/accounts/simple/signerToSimpleSmartAccount.js.map +1 -1
- package/_cjs/accounts/toSmartAccount.js +84 -0
- package/_cjs/accounts/toSmartAccount.js.map +1 -0
- package/_cjs/actions/smartAccount/prepareUserOperationRequest.js +2 -6
- package/_cjs/actions/smartAccount/prepareUserOperationRequest.js.map +1 -1
- package/_cjs/clients/decorators/pimlico.js +5 -2
- package/_cjs/clients/decorators/pimlico.js.map +1 -1
- package/_cjs/clients/pimlico.js +1 -1
- package/_cjs/clients/pimlico.js.map +1 -1
- package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js +21 -10
- package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -1
- package/_esm/accounts/index.js +2 -1
- package/_esm/accounts/index.js.map +1 -1
- package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js +4 -8
- package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
- package/_esm/accounts/safe/signerToSafeSmartAccount.js +4 -7
- package/_esm/accounts/safe/signerToSafeSmartAccount.js.map +1 -1
- package/_esm/accounts/simple/signerToSimpleSmartAccount.js +12 -17
- package/_esm/accounts/simple/signerToSimpleSmartAccount.js.map +1 -1
- package/_esm/accounts/toSmartAccount.js +80 -0
- package/_esm/accounts/toSmartAccount.js.map +1 -0
- package/_esm/actions/pimlico/sendCompressedUserOperation.js +1 -1
- package/_esm/actions/smartAccount/prepareUserOperationRequest.js +2 -6
- package/_esm/actions/smartAccount/prepareUserOperationRequest.js.map +1 -1
- package/_esm/clients/decorators/pimlico.js +5 -2
- package/_esm/clients/decorators/pimlico.js.map +1 -1
- package/_esm/clients/pimlico.js +1 -1
- package/_esm/clients/pimlico.js.map +1 -1
- package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts +2 -2
- package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts.map +1 -1
- package/_types/accounts/index.d.ts +2 -1
- package/_types/accounts/index.d.ts.map +1 -1
- package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts +2 -2
- package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts.map +1 -1
- package/_types/accounts/safe/signerToSafeSmartAccount.d.ts +2 -2
- package/_types/accounts/safe/signerToSafeSmartAccount.d.ts.map +1 -1
- package/_types/accounts/simple/signerToSimpleSmartAccount.d.ts +2 -2
- package/_types/accounts/simple/signerToSimpleSmartAccount.d.ts.map +1 -1
- package/_types/accounts/toSmartAccount.d.ts +26 -0
- package/_types/accounts/toSmartAccount.d.ts.map +1 -0
- package/_types/accounts/types.d.ts +1 -1
- package/_types/accounts/types.d.ts.map +1 -1
- package/_types/actions/bundler/estimateUserOperationGas.d.ts +2 -2
- package/_types/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
- package/_types/actions/pimlico/sendCompressedUserOperation.d.ts +1 -1
- package/_types/actions/pimlico/sponsorUserOperation.d.ts +6 -6
- package/_types/actions/smartAccount/prepareUserOperationRequest.d.ts.map +1 -1
- package/_types/clients/decorators/pimlico.d.ts +3 -3
- package/_types/clients/decorators/pimlico.d.ts.map +1 -1
- package/_types/types/bundler.d.ts +3 -3
- package/_types/types/bundler.d.ts.map +1 -1
- package/_types/types/userOperation.d.ts +6 -6
- package/_types/types/userOperation.d.ts.map +1 -1
- package/accounts/biconomy/signerToBiconomySmartAccount.ts +36 -18
- package/accounts/index.ts +3 -0
- package/accounts/kernel/signerToEcdsaKernelSmartAccount.ts +6 -11
- package/accounts/safe/signerToSafeSmartAccount.ts +218 -209
- package/accounts/simple/signerToSimpleSmartAccount.ts +14 -30
- package/accounts/toSmartAccount.ts +167 -0
- package/accounts/types.ts +2 -2
- package/actions/bundler/estimateUserOperationGas.ts +4 -4
- package/actions/pimlico/sendCompressedUserOperation.ts +1 -1
- package/actions/smartAccount/prepareUserOperationRequest.ts +2 -6
- package/clients/decorators/pimlico.ts +35 -21
- package/clients/pimlico.ts +1 -1
- package/package.json +1 -1
- package/types/bundler.ts +3 -3
- 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
|
-
|
|
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<
|
|
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
|
|
52
|
-
paymasterPostOpGasLimit
|
|
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
|
|
135
|
-
paymasterPostOpGasLimit
|
|
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
|
|
273
|
-
factoryData: factoryData
|
|
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<
|
|
97
|
+
args: Prettify<
|
|
98
|
+
Omit<SendCompressedUserOperationParameters, "entryPoint">
|
|
99
|
+
>
|
|
98
100
|
) => Promise<Hash>
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
export const pimlicoBundlerActions =
|
|
102
|
-
|
|
103
|
-
): PimlicoBundlerActions => ({
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
args
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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<
|
|
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
|
|
227
|
+
validateSponsorshipPolicies(
|
|
214
228
|
client as PimlicoPaymasterClient<entryPoint>,
|
|
215
229
|
{ ...args, entryPoint: entryPointAddress }
|
|
216
230
|
)
|
package/clients/pimlico.ts
CHANGED
package/package.json
CHANGED
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
|
|
48
|
-
paymasterVerificationGasLimit
|
|
49
|
-
paymasterPostOpGasLimit
|
|
47
|
+
callGasLimit?: Hex | null
|
|
48
|
+
paymasterVerificationGasLimit?: Hex | null
|
|
49
|
+
paymasterPostOpGasLimit?: Hex | null
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
{
|
package/types/userOperation.ts
CHANGED
|
@@ -70,18 +70,18 @@ export type UserOperation<entryPointVersion extends EntryPointVersion> =
|
|
|
70
70
|
: {
|
|
71
71
|
sender: Address
|
|
72
72
|
nonce: bigint
|
|
73
|
-
factory
|
|
74
|
-
factoryData
|
|
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
|
|
82
|
-
paymasterVerificationGasLimit
|
|
83
|
-
paymasterPostOpGasLimit
|
|
84
|
-
paymasterData
|
|
81
|
+
paymaster?: Address
|
|
82
|
+
paymasterVerificationGasLimit?: bigint
|
|
83
|
+
paymasterPostOpGasLimit?: bigint
|
|
84
|
+
paymasterData?: Hex
|
|
85
85
|
signature: Hex
|
|
86
86
|
initCode?: never
|
|
87
87
|
paymasterAndData?: never
|