@zerodev/sdk 4.3.3 → 4.3.4
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/kernel-zerodev/account.js +1 -1
- package/dist/cjs/kernel-zerodev/account.js.map +1 -1
- package/dist/cjs/kernel-zerodev/constants.js +2 -0
- package/dist/cjs/kernel-zerodev/constants.js.map +1 -1
- package/dist/cjs/kernel-zerodev/ethers-provider/ethers-provider.js +4 -2
- package/dist/cjs/kernel-zerodev/ethers-provider/ethers-provider.js.map +1 -1
- package/dist/cjs/kernel-zerodev/middleware/gas-estimator.js +11 -5
- package/dist/cjs/kernel-zerodev/middleware/gas-estimator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/owner/getCustodialOwner.d.ts +2 -2
- package/dist/cjs/kernel-zerodev/owner/getCustodialOwner.js +48 -93
- package/dist/cjs/kernel-zerodev/owner/getCustodialOwner.js.map +1 -1
- package/dist/cjs/kernel-zerodev/owner/passkey/utils.js +2 -2
- package/dist/cjs/kernel-zerodev/owner/passkey/utils.js.map +1 -1
- package/dist/cjs/kernel-zerodev/paymaster/types.d.ts +1 -1
- package/dist/cjs/kernel-zerodev/paymaster/types.js.map +1 -1
- package/dist/cjs/kernel-zerodev/provider.js +19 -9
- package/dist/cjs/kernel-zerodev/provider.js.map +1 -1
- package/dist/cjs/kernel-zerodev/utils/custom-chains.d.ts +58 -0
- package/dist/cjs/kernel-zerodev/utils/custom-chains.js +57 -0
- package/dist/cjs/kernel-zerodev/utils/custom-chains.js.map +1 -0
- package/dist/cjs/kernel-zerodev/utils.d.ts +2 -0
- package/dist/cjs/kernel-zerodev/utils.js +35 -1
- package/dist/cjs/kernel-zerodev/utils.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/ecdsa-validator.js +1 -1
- package/dist/cjs/kernel-zerodev/validator/ecdsa-validator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/erc165-session-key-validator.js +1 -1
- package/dist/cjs/kernel-zerodev/validator/erc165-session-key-validator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/kill-switch-validator.js +1 -1
- package/dist/cjs/kernel-zerodev/validator/kill-switch-validator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/recovery-validator.js +1 -2
- package/dist/cjs/kernel-zerodev/validator/recovery-validator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/session-key-validator.js +1 -1
- package/dist/cjs/kernel-zerodev/validator/session-key-validator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator-provider/base.js +2 -1
- package/dist/cjs/kernel-zerodev/validator-provider/base.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator-provider/ecdsa-provider.js +3 -3
- package/dist/cjs/kernel-zerodev/validator-provider/ecdsa-provider.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator-provider/erc165-session-key-provider.js +3 -3
- package/dist/cjs/kernel-zerodev/validator-provider/erc165-session-key-provider.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator-provider/kill-switch-provider.js +3 -3
- package/dist/cjs/kernel-zerodev/validator-provider/kill-switch-provider.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator-provider/recovery-provider.js +2 -3
- package/dist/cjs/kernel-zerodev/validator-provider/recovery-provider.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator-provider/session-key-provider.js +2 -2
- package/dist/cjs/kernel-zerodev/validator-provider/session-key-provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/account.js +2 -2
- package/dist/esm/kernel-zerodev/account.js.map +1 -1
- package/dist/esm/kernel-zerodev/constants.js +2 -0
- package/dist/esm/kernel-zerodev/constants.js.map +1 -1
- package/dist/esm/kernel-zerodev/ethers-provider/ethers-provider.js +4 -2
- package/dist/esm/kernel-zerodev/ethers-provider/ethers-provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/middleware/gas-estimator.js +11 -5
- package/dist/esm/kernel-zerodev/middleware/gas-estimator.js.map +1 -1
- package/dist/esm/kernel-zerodev/owner/getCustodialOwner.d.ts +2 -2
- package/dist/esm/kernel-zerodev/owner/getCustodialOwner.js +48 -70
- package/dist/esm/kernel-zerodev/owner/getCustodialOwner.js.map +1 -1
- package/dist/esm/kernel-zerodev/owner/passkey/utils.js +2 -2
- package/dist/esm/kernel-zerodev/owner/passkey/utils.js.map +1 -1
- package/dist/esm/kernel-zerodev/paymaster/types.d.ts +1 -1
- package/dist/esm/kernel-zerodev/paymaster/types.js.map +1 -1
- package/dist/esm/kernel-zerodev/provider.js +19 -9
- package/dist/esm/kernel-zerodev/provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/utils/custom-chains.d.ts +58 -0
- package/dist/esm/kernel-zerodev/utils/custom-chains.js +54 -0
- package/dist/esm/kernel-zerodev/utils/custom-chains.js.map +1 -0
- package/dist/esm/kernel-zerodev/utils.d.ts +2 -0
- package/dist/esm/kernel-zerodev/utils.js +10 -0
- package/dist/esm/kernel-zerodev/utils.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/ecdsa-validator.js +2 -2
- package/dist/esm/kernel-zerodev/validator/ecdsa-validator.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/erc165-session-key-validator.js +2 -2
- package/dist/esm/kernel-zerodev/validator/erc165-session-key-validator.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/kill-switch-validator.js +2 -2
- package/dist/esm/kernel-zerodev/validator/kill-switch-validator.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/recovery-validator.js +2 -2
- package/dist/esm/kernel-zerodev/validator/recovery-validator.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/session-key-validator.js +2 -2
- package/dist/esm/kernel-zerodev/validator/session-key-validator.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator-provider/base.js +2 -1
- package/dist/esm/kernel-zerodev/validator-provider/base.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator-provider/ecdsa-provider.js +1 -1
- package/dist/esm/kernel-zerodev/validator-provider/ecdsa-provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator-provider/erc165-session-key-provider.js +1 -1
- package/dist/esm/kernel-zerodev/validator-provider/erc165-session-key-provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator-provider/kill-switch-provider.js +1 -1
- package/dist/esm/kernel-zerodev/validator-provider/kill-switch-provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator-provider/recovery-provider.js +2 -2
- package/dist/esm/kernel-zerodev/validator-provider/recovery-provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator-provider/session-key-provider.js +2 -2
- package/dist/esm/kernel-zerodev/validator-provider/session-key-provider.js.map +1 -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/ethers-provider.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/middleware/gas-estimator.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/owner/getCustodialOwner.d.ts +2 -2
- package/dist/types/kernel-zerodev/owner/getCustodialOwner.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/paymaster/types.d.ts +1 -1
- package/dist/types/kernel-zerodev/paymaster/types.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/provider.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/utils/custom-chains.d.ts +59 -0
- package/dist/types/kernel-zerodev/utils/custom-chains.d.ts.map +1 -0
- package/dist/types/kernel-zerodev/utils.d.ts +2 -0
- package/dist/types/kernel-zerodev/utils.d.ts.map +1 -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.map +1 -1
- package/dist/types/kernel-zerodev/validator/kill-switch-validator.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator/recovery-validator.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator/session-key-validator.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator-provider/base.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator-provider/recovery-provider.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator-provider/session-key-provider.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/kernel-zerodev/account.ts +1 -2
- package/src/kernel-zerodev/constants.ts +2 -0
- package/src/kernel-zerodev/ethers-provider/ethers-provider.ts +3 -2
- package/src/kernel-zerodev/middleware/gas-estimator.ts +13 -7
- package/src/kernel-zerodev/owner/getCustodialOwner.ts +63 -175
- package/src/kernel-zerodev/owner/passkey/utils.ts +2 -2
- package/src/kernel-zerodev/paymaster/types.ts +5 -1
- package/src/kernel-zerodev/provider.ts +22 -9
- package/src/kernel-zerodev/utils/custom-chains.ts +55 -0
- package/src/kernel-zerodev/utils.ts +21 -0
- package/src/kernel-zerodev/validator/ecdsa-validator.ts +1 -2
- package/src/kernel-zerodev/validator/erc165-session-key-validator.ts +1 -2
- package/src/kernel-zerodev/validator/kill-switch-validator.ts +1 -2
- package/src/kernel-zerodev/validator/recovery-validator.ts +1 -2
- package/src/kernel-zerodev/validator/session-key-validator.ts +1 -2
- package/src/kernel-zerodev/validator-provider/base.ts +2 -1
- package/src/kernel-zerodev/validator-provider/ecdsa-provider.ts +1 -1
- package/src/kernel-zerodev/validator-provider/erc165-session-key-provider.ts +1 -1
- package/src/kernel-zerodev/validator-provider/kill-switch-provider.ts +1 -1
- package/src/kernel-zerodev/validator-provider/recovery-provider.ts +2 -6
- package/src/kernel-zerodev/validator-provider/session-key-provider.ts +1 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getChainId } from "../api/index.js";
|
|
2
2
|
import {
|
|
3
|
-
getChain,
|
|
4
3
|
BaseSmartContractAccount,
|
|
5
4
|
defineReadOnly,
|
|
6
5
|
type AccountMiddlewareFn,
|
|
@@ -18,6 +17,7 @@ import type {
|
|
|
18
17
|
} from "../validator-provider/types.js";
|
|
19
18
|
import { ValidatorProviders } from "../validator-provider/index.js";
|
|
20
19
|
import { withZeroDevPaymasterAndData } from "../middleware/paymaster.js";
|
|
20
|
+
import { getChain } from "../utils.js";
|
|
21
21
|
|
|
22
22
|
export class ZeroDevEthersProvider<
|
|
23
23
|
V extends SupportedValidators
|
|
@@ -27,7 +27,8 @@ export class ZeroDevEthersProvider<
|
|
|
27
27
|
super();
|
|
28
28
|
let bundlerProvider = params.bundlerProvider;
|
|
29
29
|
const shouldUsePaymaster =
|
|
30
|
-
params.usePaymaster === undefined || params.usePaymaster
|
|
30
|
+
(params.usePaymaster === undefined || params.usePaymaster) &&
|
|
31
|
+
bundlerProvider !== "GELATO";
|
|
31
32
|
if (
|
|
32
33
|
params.opts?.paymasterConfig &&
|
|
33
34
|
params.opts?.paymasterConfig.policy === "TOKEN_PAYMASTER" &&
|
|
@@ -16,10 +16,14 @@ export const withZeroDevGasEstimator = (
|
|
|
16
16
|
): ZeroDevProvider => {
|
|
17
17
|
provider.withFeeDataGetter(async (struct) => {
|
|
18
18
|
let overrides = await resolveProperties({
|
|
19
|
-
maxFeePerGas: struct.maxFeePerGas
|
|
20
|
-
maxPriorityFeePerGas: struct.maxPriorityFeePerGas
|
|
19
|
+
maxFeePerGas: struct.maxFeePerGas,
|
|
20
|
+
maxPriorityFeePerGas: struct.maxPriorityFeePerGas,
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
+
if (provider.bundlerProvider === "GELATO") {
|
|
24
|
+
return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
let maxFeePerGas, maxPriorityFeePerGas;
|
|
24
28
|
|
|
25
29
|
try {
|
|
@@ -40,11 +44,12 @@ export const withZeroDevGasEstimator = (
|
|
|
40
44
|
: 0n;
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if (overrides.maxFeePerGas || overrides.maxPriorityFeePerGas) {
|
|
48
|
+
return {
|
|
49
|
+
maxFeePerGas: overrides.maxFeePerGas ?? maxFeePerGas,
|
|
50
|
+
maxPriorityFeePerGas:
|
|
51
|
+
overrides.maxPriorityFeePerGas ?? maxPriorityFeePerGas,
|
|
52
|
+
};
|
|
48
53
|
}
|
|
49
54
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
50
55
|
});
|
|
@@ -128,6 +133,7 @@ export const GAS_PRICE_RPC_METHODS_BY_BUNDLER: {
|
|
|
128
133
|
STACKUP: "eth_maxPriorityFeePerGas",
|
|
129
134
|
ALCHEMY: "rundler_maxPriorityFeePerGas",
|
|
130
135
|
PIMLICO: "pimlico_getUserOperationGasPrice",
|
|
136
|
+
GELATO: "eth_maxPriorityFeePerGas",
|
|
131
137
|
};
|
|
132
138
|
|
|
133
139
|
export const eip1559GasPrice = async (provider: ZeroDevProvider) => {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { SignTypedDataParams, SmartAccountSigner } from "@alchemy/aa-core";
|
|
2
2
|
import { API_URL } from "../constants.js";
|
|
3
3
|
import axios from "axios";
|
|
4
|
-
import { memo, tryit } from "radash";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Params to get a custodial owner
|
|
8
7
|
* Priv / pub key combo or custodial file path should be in different types
|
|
9
8
|
*/
|
|
10
|
-
type GetCustodialOwnerParams =
|
|
9
|
+
type GetCustodialOwnerParams = {
|
|
11
10
|
// ZeroDev api url
|
|
12
11
|
apiUrl?: string;
|
|
13
12
|
// Turnkey client (if the client want to reuse it
|
|
@@ -20,7 +19,7 @@ type GetCustodialOwnerParams = Readonly<{
|
|
|
20
19
|
|
|
21
20
|
// Or read them from the custodial file path
|
|
22
21
|
custodialFilePath?: string;
|
|
23
|
-
}
|
|
22
|
+
};
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Returns a signer for a custodial wallet via TurnKey
|
|
@@ -38,40 +37,80 @@ export async function getCustodialOwner(
|
|
|
38
37
|
): Promise<SmartAccountSigner | undefined> {
|
|
39
38
|
// Extract data from the custodial file path if provided
|
|
40
39
|
if (custodialFilePath) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
let fsModule;
|
|
41
|
+
try {
|
|
42
|
+
fsModule = require.resolve("fs") && require("fs");
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.log("FS module not available. Skipping FS operation...");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const data = fsModule.readFileSync(custodialFilePath, "utf8");
|
|
48
|
+
const values = data.split("\n");
|
|
49
|
+
// Override the values, if they are provided, to the one from the custodial file
|
|
50
|
+
[privateKey, publicKey, keyId] = values;
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
// Ensure we have the required values
|
|
47
|
-
if (!keyId) {
|
|
48
|
-
throw new Error(
|
|
54
|
+
if (!privateKey || !publicKey || !keyId) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"Must provide custodialFilePath or privateKey, publicKey, and keyId."
|
|
57
|
+
);
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
// Get our turnkey client (build it if needed)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
if (!turnKeyClient) {
|
|
62
|
+
// Try to fetch turnkey client & api key stamper
|
|
63
|
+
let TurnkeyClient;
|
|
64
|
+
let ApiKeyStamper;
|
|
65
|
+
// TODO: Would be cleaner with something like radash and a tryit function?
|
|
66
|
+
try {
|
|
67
|
+
TurnkeyClient =
|
|
68
|
+
require.resolve("@turnkey/http") &&
|
|
69
|
+
require("@turnkey/http").TurnkeyClient;
|
|
70
|
+
ApiKeyStamper =
|
|
71
|
+
require.resolve("@turnkey/api-key-stamper") &&
|
|
72
|
+
require("@turnkey/api-key-stamper").ApiKeyStamper;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.log(
|
|
75
|
+
"@turnkey/http or @turnkey/api-key-stamper module not available. Skipping FS operation..."
|
|
76
|
+
);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Build the turnkey client
|
|
81
|
+
turnKeyClient = new TurnkeyClient(
|
|
82
|
+
{
|
|
83
|
+
baseUrl: "https://api.turnkey.com",
|
|
84
|
+
},
|
|
85
|
+
new ApiKeyStamper({
|
|
86
|
+
apiPublicKey: publicKey,
|
|
87
|
+
apiPrivateKey: privateKey,
|
|
88
|
+
})
|
|
61
89
|
);
|
|
62
90
|
}
|
|
63
91
|
|
|
64
92
|
// Get the wallet identifier from the API
|
|
65
|
-
const response = await
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
const response = await axios.post<any, { data: { walletId: string } }>(
|
|
94
|
+
`${apiUrl}/wallets/${identifier}`,
|
|
95
|
+
{
|
|
96
|
+
keyId,
|
|
97
|
+
}
|
|
98
|
+
);
|
|
69
99
|
|
|
70
100
|
// Build the turnkey viem account
|
|
71
|
-
|
|
72
|
-
|
|
101
|
+
let createAccount;
|
|
102
|
+
try {
|
|
103
|
+
createAccount =
|
|
104
|
+
require.resolve("@turnkey/viem") &&
|
|
105
|
+
require("@turnkey/viem").createAccount;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.log("@turnkey/viem module not available. Skipping FS operation...");
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const turnkeySigner = await createAccount({
|
|
111
|
+
client: turnKeyClient,
|
|
112
|
+
organizationId: keyId,
|
|
73
113
|
privateKeyId: response.data.walletId,
|
|
74
|
-
turnkeyClient: ensuredTurnkeyClient,
|
|
75
114
|
});
|
|
76
115
|
|
|
77
116
|
// Return an alchemy AA signer from the turnkey signer
|
|
@@ -90,154 +129,3 @@ export async function getCustodialOwner(
|
|
|
90
129
|
turnkeySigner.signTypedData(params),
|
|
91
130
|
};
|
|
92
131
|
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Try to load sign data from a local custodial file path
|
|
96
|
-
*/
|
|
97
|
-
const loadSignDataFromCustodialFile = memo(
|
|
98
|
-
async (custodialFilePath: string) => {
|
|
99
|
-
const [, fsModule] = await tryit(() => import("fs"))();
|
|
100
|
-
if (!fsModule) {
|
|
101
|
-
console.error("FS module not available");
|
|
102
|
-
throw new Error(
|
|
103
|
-
"FS module not available, you must provide each keys or install this module"
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
const data = fsModule.readFileSync(custodialFilePath, "utf8");
|
|
107
|
-
return data.split("\n");
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
// TTL of 1min in the memory cache
|
|
111
|
-
ttl: 1000 * 60,
|
|
112
|
-
// The key in the cache
|
|
113
|
-
key: (custodialFilePath: string) => `${custodialFilePath}`,
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get our default turnkey client
|
|
119
|
-
*/
|
|
120
|
-
const getDefaultTurnkeyClient = memo(
|
|
121
|
-
async ({
|
|
122
|
-
privateKey,
|
|
123
|
-
publicKey,
|
|
124
|
-
}: {
|
|
125
|
-
privateKey: string;
|
|
126
|
-
publicKey: string;
|
|
127
|
-
}) => {
|
|
128
|
-
// Try to fetch turnkey client & api key stamper
|
|
129
|
-
const [, turnkeyHttp] = await tryit(() => import("@turnkey/http"))();
|
|
130
|
-
const [, turnkeyApiKeyStamper] = await tryit(
|
|
131
|
-
() => import("@turnkey/api-key-stamper")
|
|
132
|
-
)();
|
|
133
|
-
if (!turnkeyHttp || !turnkeyApiKeyStamper) {
|
|
134
|
-
console.error(
|
|
135
|
-
"@turnkey/http or @turnkey/api-key-stamper module not available."
|
|
136
|
-
);
|
|
137
|
-
throw new Error(
|
|
138
|
-
"Turnkey http or api-key-stamper modules not available, you must provide a turnkey client or install this modules"
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Build the turnkey client
|
|
143
|
-
return new turnkeyHttp.TurnkeyClient(
|
|
144
|
-
{
|
|
145
|
-
baseUrl: "https://api.turnkey.com",
|
|
146
|
-
},
|
|
147
|
-
new turnkeyApiKeyStamper.ApiKeyStamper({
|
|
148
|
-
apiPublicKey: publicKey,
|
|
149
|
-
apiPrivateKey: privateKey,
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
// TTL of 1min in the memory cache
|
|
155
|
-
ttl: 1000 * 60,
|
|
156
|
-
// The key in the cache
|
|
157
|
-
key: ({
|
|
158
|
-
privateKey,
|
|
159
|
-
publicKey,
|
|
160
|
-
}: {
|
|
161
|
-
privateKey: string;
|
|
162
|
-
publicKey: string;
|
|
163
|
-
}) => `${privateKey}-${publicKey}`,
|
|
164
|
-
}
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Simple function used to fetch the wallet id from the API using an identifier
|
|
169
|
-
*/
|
|
170
|
-
const fetchWallet = memo(
|
|
171
|
-
({
|
|
172
|
-
identifier,
|
|
173
|
-
keyId,
|
|
174
|
-
apiUrl,
|
|
175
|
-
}: {
|
|
176
|
-
identifier: string;
|
|
177
|
-
keyId: string;
|
|
178
|
-
apiUrl: string;
|
|
179
|
-
}) => {
|
|
180
|
-
return axios.post<any, { data: { walletId: string } }>(
|
|
181
|
-
`${apiUrl}/wallets/${identifier}`,
|
|
182
|
-
{
|
|
183
|
-
keyId,
|
|
184
|
-
}
|
|
185
|
-
);
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
// TTL of 1min in the memory cache
|
|
189
|
-
ttl: 1000 * 60,
|
|
190
|
-
// The key in the cache
|
|
191
|
-
key: ({
|
|
192
|
-
identifier,
|
|
193
|
-
keyId,
|
|
194
|
-
apiUrl,
|
|
195
|
-
}: {
|
|
196
|
-
identifier: string;
|
|
197
|
-
keyId: string;
|
|
198
|
-
apiUrl: string;
|
|
199
|
-
}) => `${identifier}-${keyId}-${apiUrl}`,
|
|
200
|
-
}
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Get a turnkey signer
|
|
205
|
-
*/
|
|
206
|
-
const getTurnkeySigner = memo(
|
|
207
|
-
async ({
|
|
208
|
-
keyId,
|
|
209
|
-
privateKeyId,
|
|
210
|
-
turnkeyClient,
|
|
211
|
-
}: {
|
|
212
|
-
keyId: string;
|
|
213
|
-
privateKeyId: string;
|
|
214
|
-
turnkeyClient: unknown;
|
|
215
|
-
}) => {
|
|
216
|
-
// Get the turnkey viem account
|
|
217
|
-
const [, turnkeyViem] = await tryit(() => import("@turnkey/viem"))();
|
|
218
|
-
if (!turnkeyViem) {
|
|
219
|
-
console.error("@turnkey/viem module not available");
|
|
220
|
-
throw new Error(
|
|
221
|
-
"Turnkey viem module not available, can't create a turnkey signer for the custodial owner"
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
return turnkeyViem.createAccount({
|
|
225
|
-
client: turnkeyClient as any,
|
|
226
|
-
organizationId: keyId,
|
|
227
|
-
privateKeyId,
|
|
228
|
-
});
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
// TTL of 1min in the memory cache
|
|
232
|
-
ttl: 1000 * 60,
|
|
233
|
-
// The key in the cache
|
|
234
|
-
key: ({
|
|
235
|
-
keyId,
|
|
236
|
-
privateKeyId,
|
|
237
|
-
}: {
|
|
238
|
-
keyId: string;
|
|
239
|
-
privateKeyId: string;
|
|
240
|
-
turnkeyClient: unknown;
|
|
241
|
-
}) => `${keyId}-${privateKeyId}`,
|
|
242
|
-
}
|
|
243
|
-
);
|
|
@@ -47,10 +47,10 @@ export const signMessageImplementation = async (
|
|
|
47
47
|
const signedRequest = await TurnkeyApi.signSignRawPayload(
|
|
48
48
|
{
|
|
49
49
|
body: {
|
|
50
|
-
type: "
|
|
50
|
+
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD",
|
|
51
51
|
organizationId: id,
|
|
52
52
|
parameters: {
|
|
53
|
-
|
|
53
|
+
privateKeyId: walletId,
|
|
54
54
|
payload: msg,
|
|
55
55
|
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
56
56
|
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
@@ -2,7 +2,11 @@ import type { Hex } from "viem";
|
|
|
2
2
|
import type { Paymaster } from "./base.js";
|
|
3
3
|
import type { ZeroDevProvider } from "../provider.js";
|
|
4
4
|
|
|
5
|
-
export type PaymasterAndBundlerProviders =
|
|
5
|
+
export type PaymasterAndBundlerProviders =
|
|
6
|
+
| "ALCHEMY"
|
|
7
|
+
| "STACKUP"
|
|
8
|
+
| "PIMLICO"
|
|
9
|
+
| "GELATO";
|
|
6
10
|
|
|
7
11
|
export type SupportedGasToken = "USDC" | "PEPE" | "TEST_ERC20";
|
|
8
12
|
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
deepHexlify,
|
|
13
13
|
resolveProperties,
|
|
14
14
|
type SmartAccountProviderOpts,
|
|
15
|
-
getChain,
|
|
16
15
|
type UserOperationCallData,
|
|
17
16
|
type BatchUserOperationCallData,
|
|
18
17
|
type SendUserOperationResult,
|
|
@@ -43,6 +42,7 @@ import type {
|
|
|
43
42
|
PaymasterConfig,
|
|
44
43
|
PaymasterPolicy,
|
|
45
44
|
} from "./paymaster/types.js";
|
|
45
|
+
import { getChain } from "./utils.js";
|
|
46
46
|
|
|
47
47
|
export type ZeroDevProviderConfig = {
|
|
48
48
|
projectId: string;
|
|
@@ -373,14 +373,27 @@ export class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {
|
|
|
373
373
|
waitForUserOperationTransaction = async (hash: Hash): Promise<Hash> => {
|
|
374
374
|
let blockNumber = await this.rpcClient.getBlockNumber();
|
|
375
375
|
for (let i = 0; i < this._txMaxRetries; i++) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
376
|
+
if (this.bundlerProvider === "GELATO") {
|
|
377
|
+
const receipt = await this.getUserOperationReceipt(
|
|
378
|
+
hash as `0x${string}`
|
|
379
|
+
)
|
|
380
|
+
// TODO: should maybe log the error?
|
|
381
|
+
.catch(() => null);
|
|
382
|
+
if (receipt) {
|
|
383
|
+
return this.getTransaction(receipt.receipt.transactionHash).then(
|
|
384
|
+
(x) => x.hash
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
} else {
|
|
388
|
+
const logs = await this.rpcClient.getLogs({
|
|
389
|
+
address: ENTRYPOINT_ADDRESS,
|
|
390
|
+
event: getAbiItem({ abi: EntryPointAbi, name: "UserOperationEvent" }),
|
|
391
|
+
args: { userOpHash: hash },
|
|
392
|
+
fromBlock: blockNumber - 100n,
|
|
393
|
+
});
|
|
394
|
+
if (logs.length) {
|
|
395
|
+
return logs[0].transactionHash;
|
|
396
|
+
}
|
|
384
397
|
}
|
|
385
398
|
await new Promise((resolve) =>
|
|
386
399
|
setTimeout(resolve, this._txRetryIntervalMs)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { defineChain } from "viem";
|
|
2
|
+
|
|
3
|
+
export const gelatoOPTestnet = defineChain({
|
|
4
|
+
id: 42069,
|
|
5
|
+
name: "Gelato OPTestnet",
|
|
6
|
+
network: "gelatoOPTestnet",
|
|
7
|
+
nativeCurrency: {
|
|
8
|
+
decimals: 18,
|
|
9
|
+
name: "Ether",
|
|
10
|
+
symbol: "ETH",
|
|
11
|
+
},
|
|
12
|
+
rpcUrls: {
|
|
13
|
+
default: {
|
|
14
|
+
http: ["https://rpc.op-testnet.gelato.digital"],
|
|
15
|
+
webSocket: [],
|
|
16
|
+
},
|
|
17
|
+
public: {
|
|
18
|
+
http: ["https://rpc.op-testnet.gelato.digital"],
|
|
19
|
+
webSocket: [],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
blockExplorers: {
|
|
23
|
+
default: {
|
|
24
|
+
name: "Explorer",
|
|
25
|
+
url: "https://blockscout.op-testnet.gelato.digital",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const astarZKatana = defineChain({
|
|
31
|
+
id: 1261120,
|
|
32
|
+
name: "Astar zKatana",
|
|
33
|
+
network: "astarZKatana",
|
|
34
|
+
nativeCurrency: {
|
|
35
|
+
decimals: 18,
|
|
36
|
+
name: "Ether",
|
|
37
|
+
symbol: "ETH",
|
|
38
|
+
},
|
|
39
|
+
rpcUrls: {
|
|
40
|
+
default: {
|
|
41
|
+
http: ["https://rpc.zkatana.gelato.digital"],
|
|
42
|
+
webSocket: ["https://ws.zkatana.gelato.digital"],
|
|
43
|
+
},
|
|
44
|
+
public: {
|
|
45
|
+
http: ["https://rpc.zkatana.gelato.digital"],
|
|
46
|
+
webSocket: ["https://ws.zkatana.gelato.digital"],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
blockExplorers: {
|
|
50
|
+
default: {
|
|
51
|
+
name: "Explorer",
|
|
52
|
+
url: "https://zkatana.blockscout.com",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
hexToSignature,
|
|
10
10
|
signatureToHex,
|
|
11
11
|
} from "viem";
|
|
12
|
+
import * as chains from "viem/chains";
|
|
13
|
+
import * as customChains from "./utils/custom-chains.js";
|
|
12
14
|
import type {
|
|
13
15
|
SignTypedDataParams,
|
|
14
16
|
SmartAccountSigner,
|
|
@@ -132,3 +134,22 @@ export const fixSignedData = (sig: Hex): Hex => {
|
|
|
132
134
|
const joined = signatureToHex({ r, s, v });
|
|
133
135
|
return joined;
|
|
134
136
|
};
|
|
137
|
+
|
|
138
|
+
// Modified from @alchemy/aa-core
|
|
139
|
+
/**
|
|
140
|
+
* Utility method for converting a chainId to a {@link chains.Chain} object
|
|
141
|
+
*
|
|
142
|
+
* @param chainId
|
|
143
|
+
* @returns a {@link chains.Chain} object for the given chainId
|
|
144
|
+
* @throws if the chainId is not found
|
|
145
|
+
*/
|
|
146
|
+
export const getChain = (chainId: number): chains.Chain => {
|
|
147
|
+
for (const chain of Object.values(chains).concat(
|
|
148
|
+
Object.values(customChains)
|
|
149
|
+
)) {
|
|
150
|
+
if (chain.id === chainId) {
|
|
151
|
+
return chain;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
throw new Error("could not find chain");
|
|
155
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getChain,
|
|
3
2
|
getUserOperationHash,
|
|
4
3
|
type Address,
|
|
5
4
|
type Hex,
|
|
@@ -13,7 +12,7 @@ import { ECDSAValidatorAbi } from "../abis/ESCDAValidatorAbi.js";
|
|
|
13
12
|
import { getChainId } from "../api/index.js";
|
|
14
13
|
import { DUMMY_ECDSA_SIG } from "../constants.js";
|
|
15
14
|
import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
|
|
16
|
-
import { fixSignedData } from "../utils.js";
|
|
15
|
+
import { fixSignedData, getChain } from "../utils.js";
|
|
17
16
|
|
|
18
17
|
export interface ECDSAValidatorParams extends KernelBaseValidatorParams {
|
|
19
18
|
owner: SmartAccountSigner;
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
type Hex,
|
|
5
5
|
type SmartAccountSigner,
|
|
6
6
|
type UserOperationRequest,
|
|
7
|
-
getChain,
|
|
8
7
|
type SignTypedDataParams,
|
|
9
8
|
} from "@alchemy/aa-core";
|
|
10
9
|
import {
|
|
@@ -17,7 +16,7 @@ import { ERC165SessionKeyValidatorAbi } from "../abis/ERC165SessionKeyValidatorA
|
|
|
17
16
|
import { DUMMY_ECDSA_SIG } from "../constants.js";
|
|
18
17
|
import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
|
|
19
18
|
import { getChainId } from "../api/index.js";
|
|
20
|
-
import { fixSignedData } from "../utils.js";
|
|
19
|
+
import { fixSignedData, getChain } from "../utils.js";
|
|
21
20
|
|
|
22
21
|
export interface ERC165SessionKeyValidatorParams
|
|
23
22
|
extends KernelBaseValidatorParams {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getChain,
|
|
3
2
|
getUserOperationHash,
|
|
4
3
|
type Address,
|
|
5
4
|
type Hex,
|
|
@@ -26,7 +25,7 @@ import { KillSwitchValidatorAbi } from "../abis/KillSwitchValidatorAbi.js";
|
|
|
26
25
|
import { getChainId } from "../api/index.js";
|
|
27
26
|
import { DUMMY_ECDSA_SIG } from "../constants.js";
|
|
28
27
|
import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
|
|
29
|
-
import { fixSignedData } from "../utils.js";
|
|
28
|
+
import { fixSignedData, getChain } from "../utils.js";
|
|
30
29
|
|
|
31
30
|
export interface KillSwitchValidatorParams extends KernelBaseValidatorParams {
|
|
32
31
|
guardian: SmartAccountSigner;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getChain,
|
|
3
2
|
type Address,
|
|
4
3
|
type Hex,
|
|
5
4
|
type SmartAccountSigner,
|
|
@@ -38,7 +37,7 @@ import {
|
|
|
38
37
|
RECOVERY_VALIDATOR_ADDRESS,
|
|
39
38
|
} from "../constants.js";
|
|
40
39
|
import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
|
|
41
|
-
import { fixSignedData } from "../utils.js";
|
|
40
|
+
import { fixSignedData, getChain } from "../utils.js";
|
|
42
41
|
import type { EthereumProvider } from "./types.js";
|
|
43
42
|
import { polygonMumbai } from "viem/chains";
|
|
44
43
|
import { RecoveryActionAbi } from "../abis/RecoveryActionAbi.js";
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
type Hex,
|
|
5
5
|
type SmartAccountSigner,
|
|
6
6
|
type UserOperationRequest,
|
|
7
|
-
getChain,
|
|
8
7
|
type SignTypedDataParams,
|
|
9
8
|
type Abi,
|
|
10
9
|
} from "@alchemy/aa-core";
|
|
@@ -35,7 +34,7 @@ import { DUMMY_ECDSA_SIG } from "../constants.js";
|
|
|
35
34
|
import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
|
|
36
35
|
import { MerkleTree } from "merkletreejs";
|
|
37
36
|
import { getChainId } from "../api/index.js";
|
|
38
|
-
import { fixSignedData } from "../utils.js";
|
|
37
|
+
import { fixSignedData, getChain } from "../utils.js";
|
|
39
38
|
import type { GetAbiItemReturnType } from "viem/dist/types/utils/abi/getAbiItem.js";
|
|
40
39
|
import { type AbiFunction } from "abitype";
|
|
41
40
|
import type {
|
|
@@ -59,7 +59,8 @@ export abstract class ValidatorProvider<
|
|
|
59
59
|
) {
|
|
60
60
|
let bundlerProvider = params.bundlerProvider;
|
|
61
61
|
const shouldUsePaymaster =
|
|
62
|
-
params.usePaymaster === undefined || params.usePaymaster
|
|
62
|
+
(params.usePaymaster === undefined || params.usePaymaster) &&
|
|
63
|
+
bundlerProvider !== "GELATO";
|
|
63
64
|
if (
|
|
64
65
|
params.opts?.paymasterConfig &&
|
|
65
66
|
params.opts?.paymasterConfig.policy === "TOKEN_PAYMASTER" &&
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
ECDSAValidator,
|
|
7
7
|
type ECDSAValidatorParams,
|
|
8
8
|
} from "../validator/ecdsa-validator.js";
|
|
9
|
-
import { getChain } from "@alchemy/aa-core";
|
|
10
9
|
import { getChainId } from "../api/index.js";
|
|
11
10
|
import { polygonMumbai } from "viem/chains";
|
|
11
|
+
import { getChain } from "../utils.js";
|
|
12
12
|
|
|
13
13
|
export class ECDSAProvider extends ValidatorProvider<
|
|
14
14
|
ECDSAValidator,
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
ERC165SessionKeyValidator,
|
|
7
7
|
type ERC165SessionKeyValidatorParams,
|
|
8
8
|
} from "../validator/erc165-session-key-validator.js";
|
|
9
|
-
import { getChain } from "@alchemy/aa-core";
|
|
10
9
|
import { getChainId } from "../api/index.js";
|
|
11
10
|
import { polygonMumbai } from "viem/chains";
|
|
12
11
|
import { ERC165_SESSION_KEY_VALIDATOR_ADDRESS } from "../constants.js";
|
|
12
|
+
import { getChain } from "../utils.js";
|
|
13
13
|
|
|
14
14
|
export class ERC165SessionKeyProvider extends ValidatorProvider<
|
|
15
15
|
ERC165SessionKeyValidator,
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
KillSwitchValidator,
|
|
7
7
|
type KillSwitchValidatorParams,
|
|
8
8
|
} from "../validator/kill-switch-validator.js";
|
|
9
|
-
import { getChain } from "@alchemy/aa-core";
|
|
10
9
|
import { getChainId } from "../api/index.js";
|
|
11
10
|
import { polygonMumbai } from "viem/chains";
|
|
12
11
|
import { KILL_SWITCH_VALIDATOR_ADDRESS } from "../constants.js";
|
|
12
|
+
import { getChain } from "../utils.js";
|
|
13
13
|
|
|
14
14
|
export class KillSwitchProvider extends ValidatorProvider<
|
|
15
15
|
KillSwitchValidator,
|
|
@@ -7,11 +7,7 @@ import {
|
|
|
7
7
|
type RecoveryConfig,
|
|
8
8
|
type RecoveryValidatorParams,
|
|
9
9
|
} from "../validator/recovery-validator.js";
|
|
10
|
-
import {
|
|
11
|
-
getChain,
|
|
12
|
-
type Address,
|
|
13
|
-
type SendUserOperationResult,
|
|
14
|
-
} from "@alchemy/aa-core";
|
|
10
|
+
import { type Address, type SendUserOperationResult } from "@alchemy/aa-core";
|
|
15
11
|
import {
|
|
16
12
|
getChainId,
|
|
17
13
|
getRecoveryData,
|
|
@@ -33,7 +29,7 @@ import {
|
|
|
33
29
|
} from "viem";
|
|
34
30
|
import { RecoveryActionAbi } from "../abis/RecoveryActionAbi.js";
|
|
35
31
|
import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
|
|
36
|
-
import { base64ToBytes, bytesToBase64 } from "../utils.js";
|
|
32
|
+
import { base64ToBytes, bytesToBase64, getChain } from "../utils.js";
|
|
37
33
|
|
|
38
34
|
export interface RecoveryProviderParams
|
|
39
35
|
extends ExtendedValidatorProviderParams<RecoveryValidatorParams> {
|