@zerodev/sdk 4.0.4 → 4.0.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.
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/kernel-zerodev/account.d.ts +2 -1
- package/dist/cjs/kernel-zerodev/account.js +6 -0
- package/dist/cjs/kernel-zerodev/account.js.map +1 -1
- package/dist/cjs/kernel-zerodev/constants.js +1 -2
- package/dist/cjs/kernel-zerodev/constants.js.map +1 -1
- package/dist/cjs/kernel-zerodev/ethers-provider/account-signer.d.ts +28 -0
- package/dist/cjs/kernel-zerodev/ethers-provider/account-signer.js +134 -0
- package/dist/cjs/kernel-zerodev/ethers-provider/account-signer.js.map +1 -0
- package/dist/cjs/kernel-zerodev/ethers-provider/ethers-provider.d.ts +3 -3
- package/dist/cjs/kernel-zerodev/ethers-provider/ethers-provider.js +2 -2
- package/dist/cjs/kernel-zerodev/ethers-provider/ethers-provider.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/base.d.ts +2 -1
- package/dist/cjs/kernel-zerodev/validator/base.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/ecdsa-validator.d.ts +2 -1
- package/dist/cjs/kernel-zerodev/validator/ecdsa-validator.js +4 -0
- package/dist/cjs/kernel-zerodev/validator/ecdsa-validator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/erc165-session-key-validator.d.ts +2 -1
- package/dist/cjs/kernel-zerodev/validator/erc165-session-key-validator.js +4 -0
- package/dist/cjs/kernel-zerodev/validator/erc165-session-key-validator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/kill-switch-validator.d.ts +2 -1
- package/dist/cjs/kernel-zerodev/validator/kill-switch-validator.js +4 -0
- package/dist/cjs/kernel-zerodev/validator/kill-switch-validator.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/kernel-zerodev/account.d.ts +2 -1
- package/dist/esm/kernel-zerodev/account.js +6 -0
- package/dist/esm/kernel-zerodev/account.js.map +1 -1
- package/dist/esm/kernel-zerodev/constants.js +1 -2
- package/dist/esm/kernel-zerodev/constants.js.map +1 -1
- package/dist/esm/kernel-zerodev/ethers-provider/account-signer.d.ts +28 -0
- package/dist/esm/kernel-zerodev/ethers-provider/account-signer.js +132 -0
- package/dist/esm/kernel-zerodev/ethers-provider/account-signer.js.map +1 -0
- package/dist/esm/kernel-zerodev/ethers-provider/ethers-provider.d.ts +3 -3
- package/dist/esm/kernel-zerodev/ethers-provider/ethers-provider.js +2 -2
- package/dist/esm/kernel-zerodev/ethers-provider/ethers-provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/base.d.ts +2 -1
- package/dist/esm/kernel-zerodev/validator/base.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/ecdsa-validator.d.ts +2 -1
- package/dist/esm/kernel-zerodev/validator/ecdsa-validator.js +4 -0
- package/dist/esm/kernel-zerodev/validator/ecdsa-validator.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/erc165-session-key-validator.d.ts +2 -1
- package/dist/esm/kernel-zerodev/validator/erc165-session-key-validator.js +4 -0
- package/dist/esm/kernel-zerodev/validator/erc165-session-key-validator.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/kill-switch-validator.d.ts +2 -1
- package/dist/esm/kernel-zerodev/validator/kill-switch-validator.js +4 -0
- package/dist/esm/kernel-zerodev/validator/kill-switch-validator.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/account.d.ts +2 -1
- package/dist/types/kernel-zerodev/account.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/constants.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/ethers-provider/account-signer.d.ts +29 -0
- package/dist/types/kernel-zerodev/ethers-provider/account-signer.d.ts.map +1 -0
- package/dist/types/kernel-zerodev/ethers-provider/ethers-provider.d.ts +5 -5
- package/dist/types/kernel-zerodev/ethers-provider/ethers-provider.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator/base.d.ts +2 -1
- package/dist/types/kernel-zerodev/validator/base.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator/ecdsa-validator.d.ts +2 -1
- package/dist/types/kernel-zerodev/validator/ecdsa-validator.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator/erc165-session-key-validator.d.ts +2 -1
- package/dist/types/kernel-zerodev/validator/erc165-session-key-validator.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator/kill-switch-validator.d.ts +2 -1
- package/dist/types/kernel-zerodev/validator/kill-switch-validator.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/kernel-zerodev/account.ts +8 -0
- package/src/kernel-zerodev/constants.ts +1 -2
- package/src/kernel-zerodev/ethers-provider/account-signer.ts +165 -0
- package/src/kernel-zerodev/ethers-provider/ethers-provider.ts +6 -6
- package/src/kernel-zerodev/validator/base.ts +4 -1
- package/src/kernel-zerodev/validator/ecdsa-validator.ts +6 -0
- package/src/kernel-zerodev/validator/erc165-session-key-validator.ts +6 -0
- package/src/kernel-zerodev/validator/kill-switch-validator.ts +6 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseSmartContractAccount,
|
|
3
|
+
resolveProperties,
|
|
4
|
+
type AccountMiddlewareFn,
|
|
5
|
+
type FeeDataMiddleware,
|
|
6
|
+
type GasEstimatorMiddleware,
|
|
7
|
+
type PaymasterAndDataMiddleware,
|
|
8
|
+
type PublicErc4337Client,
|
|
9
|
+
type SignTypedDataParams,
|
|
10
|
+
} from "@alchemy/aa-core";
|
|
11
|
+
import {
|
|
12
|
+
Signer,
|
|
13
|
+
type TypedDataSigner,
|
|
14
|
+
type TypedDataDomain,
|
|
15
|
+
type TypedDataField,
|
|
16
|
+
} from "@ethersproject/abstract-signer";
|
|
17
|
+
import { hexlify } from "@ethersproject/bytes";
|
|
18
|
+
import { _TypedDataEncoder } from "@ethersproject/hash";
|
|
19
|
+
import type { Deferrable } from "@ethersproject/properties";
|
|
20
|
+
import {
|
|
21
|
+
type TransactionRequest,
|
|
22
|
+
type TransactionResponse,
|
|
23
|
+
} from "@ethersproject/providers";
|
|
24
|
+
import { ZeroDevEthersProvider } from "./ethers-provider.js";
|
|
25
|
+
import type { SupportedValidators } from "../validator/types.js";
|
|
26
|
+
|
|
27
|
+
const hexlifyOptional = (value: any): `0x${string}` | undefined => {
|
|
28
|
+
if (value == null) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return hexlify(value) as `0x${string}`;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export class ZeroDevAccountSigner<V extends SupportedValidators>
|
|
36
|
+
extends Signer
|
|
37
|
+
implements TypedDataSigner
|
|
38
|
+
{
|
|
39
|
+
private account?: BaseSmartContractAccount;
|
|
40
|
+
|
|
41
|
+
sendUserOperation;
|
|
42
|
+
waitForUserOperationTransaction;
|
|
43
|
+
|
|
44
|
+
constructor(readonly provider: ZeroDevEthersProvider<V>) {
|
|
45
|
+
super();
|
|
46
|
+
this.account = this.provider.accountProvider.account;
|
|
47
|
+
|
|
48
|
+
this.sendUserOperation =
|
|
49
|
+
this.provider.accountProvider.sendUserOperation.bind(
|
|
50
|
+
this.provider.accountProvider
|
|
51
|
+
);
|
|
52
|
+
this.waitForUserOperationTransaction =
|
|
53
|
+
this.provider.accountProvider.waitForUserOperationTransaction.bind(
|
|
54
|
+
this.provider.accountProvider
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getAddress(): Promise<string> {
|
|
59
|
+
if (!this.account) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"connect the signer to a provider that has a connected account"
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return this.account.getAddress();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
signMessage(message: string | Uint8Array): Promise<string> {
|
|
69
|
+
if (!this.account) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"connect the signer to a provider that has a connected account"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return this.account.signMessage(message);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
signTypedData(params: SignTypedDataParams): Promise<string> {
|
|
79
|
+
if (!this.account) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
"connect the signer to a provider that has a connected account"
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (params.types) {
|
|
85
|
+
delete params.types["EIP712Domain"];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return this.account.signTypedData(params);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
_signTypedData(
|
|
92
|
+
domain: TypedDataDomain,
|
|
93
|
+
types: Record<string, Array<TypedDataField>>,
|
|
94
|
+
value: Record<string, any>
|
|
95
|
+
): Promise<string> {
|
|
96
|
+
if (!this.account) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
"connect the signer to a provider that has a connected account"
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const params = _TypedDataEncoder.getPayload(
|
|
102
|
+
domain,
|
|
103
|
+
types,
|
|
104
|
+
value
|
|
105
|
+
) as SignTypedDataParams;
|
|
106
|
+
if (params.types) {
|
|
107
|
+
delete params.types["EIP712Domain"];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return this.signTypedData(params);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
withPaymasterMiddleware = (overrides: {
|
|
114
|
+
dummyPaymasterDataMiddleware?: PaymasterAndDataMiddleware;
|
|
115
|
+
paymasterDataMiddleware?: PaymasterAndDataMiddleware;
|
|
116
|
+
}): this => {
|
|
117
|
+
this.provider.withPaymasterMiddleware(overrides);
|
|
118
|
+
return this;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
withGasEstimator = (override: GasEstimatorMiddleware): this => {
|
|
122
|
+
this.provider.withGasEstimator(override);
|
|
123
|
+
return this;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
withFeeDataGetter = (override: FeeDataMiddleware): this => {
|
|
127
|
+
this.provider.withFeeDataGetter(override);
|
|
128
|
+
return this;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
withCustomMiddleware = (override: AccountMiddlewareFn): this => {
|
|
132
|
+
this.provider.withCustomMiddleware(override);
|
|
133
|
+
return this;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
async sendTransaction(
|
|
137
|
+
transaction: Deferrable<TransactionRequest>
|
|
138
|
+
): Promise<TransactionResponse> {
|
|
139
|
+
const resolved = await resolveProperties(transaction);
|
|
140
|
+
const txHash = await this.provider.accountProvider.sendTransaction({
|
|
141
|
+
// TODO: need to support gas fields as well
|
|
142
|
+
from: (await this.getAddress()) as `0x${string}`,
|
|
143
|
+
to: resolved.to as `0x${string}` | undefined,
|
|
144
|
+
data: hexlifyOptional(resolved.data),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return this.provider.getTransaction(txHash);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
signTransaction(
|
|
151
|
+
_transaction: Deferrable<TransactionRequest>
|
|
152
|
+
): Promise<string> {
|
|
153
|
+
throw new Error(
|
|
154
|
+
"Transaction signing is not supported, use sendUserOperation instead"
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getPublicErc4337Client(): PublicErc4337Client {
|
|
159
|
+
return this.provider.getPublicErc4337Client();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
connect(provider: ZeroDevEthersProvider<V>): ZeroDevAccountSigner<V> {
|
|
163
|
+
return new ZeroDevAccountSigner(provider);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
type PaymasterAndDataMiddleware,
|
|
12
12
|
type PublicErc4337Client,
|
|
13
13
|
} from "@alchemy/aa-core";
|
|
14
|
-
import {
|
|
14
|
+
import { ZeroDevAccountSigner } from "./account-signer.js";
|
|
15
15
|
import { JsonRpcProvider } from "@ethersproject/providers";
|
|
16
16
|
import type { SupportedValidators } from "../validator/types.js";
|
|
17
17
|
import type { ValidatorProviderParamsMap } from "../validator-provider/types.js";
|
|
@@ -73,20 +73,20 @@ export class ZeroDevEthersProvider<
|
|
|
73
73
|
* Connects the Provider to an Account and returns a Signer
|
|
74
74
|
*
|
|
75
75
|
* @param fn - a function that takes the account provider's rpcClient and returns a BaseSmartContractAccount
|
|
76
|
-
* @returns an {@link
|
|
76
|
+
* @returns an {@link ZeroDevAccountSigner} that can be used to sign and send user operations
|
|
77
77
|
*/
|
|
78
78
|
connectToAccount(
|
|
79
79
|
fn: (rpcClient: PublicErc4337Client) => BaseSmartContractAccount
|
|
80
|
-
):
|
|
80
|
+
): ZeroDevAccountSigner<V> {
|
|
81
81
|
defineReadOnly(this, "accountProvider", this.accountProvider.connect(fn));
|
|
82
82
|
return this.getAccountSigner();
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* @returns an {@link
|
|
86
|
+
* @returns an {@link ZeroDevAccountSigner} using this as the underlying provider
|
|
87
87
|
*/
|
|
88
|
-
getAccountSigner():
|
|
89
|
-
return new
|
|
88
|
+
getAccountSigner(): ZeroDevAccountSigner<V> {
|
|
89
|
+
return new ZeroDevAccountSigner(this);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
withPaymasterMiddleware = (overrides: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type SignTypedDataParams,
|
|
2
3
|
type SmartAccountSigner,
|
|
3
4
|
type UserOperationRequest,
|
|
4
5
|
} from "@alchemy/aa-core";
|
|
@@ -91,6 +92,8 @@ export abstract class KernelBaseValidator {
|
|
|
91
92
|
|
|
92
93
|
abstract signMessage(message: Uint8Array | string | Hex): Promise<Hex>;
|
|
93
94
|
|
|
95
|
+
abstract signTypedData(params: SignTypedDataParams): Promise<Hex>;
|
|
96
|
+
|
|
94
97
|
abstract signUserOp(userOp: UserOperationRequest): Promise<Hex>;
|
|
95
98
|
|
|
96
99
|
abstract signer(): Promise<SmartAccountSigner>;
|
|
@@ -160,7 +163,7 @@ export abstract class KernelBaseValidator {
|
|
|
160
163
|
}
|
|
161
164
|
const sender = kernel;
|
|
162
165
|
const signer = await this.signer();
|
|
163
|
-
const ownerSig = await
|
|
166
|
+
const ownerSig = await signer.signTypedData({
|
|
164
167
|
domain: {
|
|
165
168
|
name: "Kernel",
|
|
166
169
|
version: "0.2.1",
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type Hex,
|
|
6
6
|
type SmartAccountSigner,
|
|
7
7
|
type UserOperationRequest,
|
|
8
|
+
type SignTypedDataParams,
|
|
8
9
|
} from "@alchemy/aa-core";
|
|
9
10
|
import { KernelBaseValidator, type KernelBaseValidatorParams } from "./base.js";
|
|
10
11
|
import { encodeFunctionData, toBytes } from "viem";
|
|
@@ -12,6 +13,7 @@ import { ECDSAValidatorAbi } from "../abis/ESCDAValidatorAbi.js";
|
|
|
12
13
|
import { getChainId } from "../api/index.js";
|
|
13
14
|
import { DUMMY_ECDSA_SIG } from "../constants.js";
|
|
14
15
|
import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
|
|
16
|
+
import { fixSignedData } from "../utils.js";
|
|
15
17
|
|
|
16
18
|
export interface ECDSAValidatorParams extends KernelBaseValidatorParams {
|
|
17
19
|
owner: SmartAccountSigner;
|
|
@@ -99,6 +101,10 @@ export class ECDSAValidator extends KernelBaseValidator {
|
|
|
99
101
|
return await this.owner.signMessage(message);
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
async signTypedData(params: SignTypedDataParams): Promise<Hex> {
|
|
105
|
+
return fixSignedData(await this.owner.signTypedData(params));
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
async signUserOp(userOp: UserOperationRequest): Promise<Hex> {
|
|
103
109
|
if (!this.chain) {
|
|
104
110
|
throw new Error("Validator uninitialized");
|
|
@@ -4,12 +4,14 @@ import {
|
|
|
4
4
|
type Hex,
|
|
5
5
|
type SmartAccountSigner,
|
|
6
6
|
type UserOperationRequest,
|
|
7
|
+
type SignTypedDataParams,
|
|
7
8
|
} from "@alchemy/aa-core";
|
|
8
9
|
import { KernelBaseValidator, type KernelBaseValidatorParams } from "./base.js";
|
|
9
10
|
import { encodeFunctionData, toBytes, concat, pad, toHex } from "viem";
|
|
10
11
|
import { ERC165SessionKeyValidatorAbi } from "../abis/ERC165SessionKeyValidatorAbi.js";
|
|
11
12
|
import { DUMMY_ECDSA_SIG } from "../constants.js";
|
|
12
13
|
import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
|
|
14
|
+
import { fixSignedData } from "../utils.js";
|
|
13
15
|
|
|
14
16
|
export interface ERC165SessionKeyValidatorParams
|
|
15
17
|
extends KernelBaseValidatorParams {
|
|
@@ -109,6 +111,10 @@ export class ERC165SessionKeyValidator extends KernelBaseValidator {
|
|
|
109
111
|
return await this.sessionKey.signMessage(message);
|
|
110
112
|
}
|
|
111
113
|
|
|
114
|
+
async signTypedData(params: SignTypedDataParams): Promise<Hex> {
|
|
115
|
+
return fixSignedData(await this.sessionKey.signTypedData(params));
|
|
116
|
+
}
|
|
117
|
+
|
|
112
118
|
async signUserOp(userOp: UserOperationRequest): Promise<Hex> {
|
|
113
119
|
if (!this.chain) {
|
|
114
120
|
throw new Error("Validator uninitialized");
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type Hex,
|
|
6
6
|
type SmartAccountSigner,
|
|
7
7
|
type UserOperationRequest,
|
|
8
|
+
type SignTypedDataParams,
|
|
8
9
|
} from "@alchemy/aa-core";
|
|
9
10
|
import { KernelBaseValidator, type KernelBaseValidatorParams } from "./base.js";
|
|
10
11
|
import {
|
|
@@ -21,6 +22,7 @@ import { KillSwitchValidatorAbi } from "../abis/KillSwitchValidatorAbi.js";
|
|
|
21
22
|
import { getChainId } from "../api/index.js";
|
|
22
23
|
import { DUMMY_ECDSA_SIG } from "../constants.js";
|
|
23
24
|
import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
|
|
25
|
+
import { fixSignedData } from "../utils.js";
|
|
24
26
|
|
|
25
27
|
export interface KillSwitchValidatorParams extends KernelBaseValidatorParams {
|
|
26
28
|
guardian: SmartAccountSigner;
|
|
@@ -116,6 +118,10 @@ export class KillSwitchValidator extends KernelBaseValidator {
|
|
|
116
118
|
return await this.guardian.signMessage(message);
|
|
117
119
|
}
|
|
118
120
|
|
|
121
|
+
async signTypedData(params: SignTypedDataParams): Promise<Hex> {
|
|
122
|
+
return fixSignedData(await this.guardian.signTypedData(params));
|
|
123
|
+
}
|
|
124
|
+
|
|
119
125
|
async signUserOp(userOp: UserOperationRequest): Promise<Hex> {
|
|
120
126
|
const pausedUntil = this.getPausedUntil();
|
|
121
127
|
if (!this.chain) {
|