@dynamic-labs/ethereum-aa 4.0.0-alpha.4 → 4.0.0-alpha.41
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 +361 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +10 -17
- package/src/ZeroDevConnector.cjs +186 -107
- package/src/ZeroDevConnector.d.ts +108 -87
- package/src/ZeroDevConnector.js +189 -110
- package/src/constants.cjs +8 -0
- package/src/constants.d.ts +1 -0
- package/src/constants.js +4 -0
- package/src/index.cjs +13 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +8 -0
- package/src/utils/createEcsdaKernelAccountClient.d.ts +1 -1
- package/src/utils/{fetchChain.cjs → fetchZeroDevChain.cjs} +2 -2
- package/src/utils/{fetchChain.d.ts → fetchZeroDevChain.d.ts} +1 -1
- package/src/utils/{fetchChain.js → fetchZeroDevChain.js} +2 -2
- package/src/utils/getEcdsaValidator.cjs +21 -0
- package/src/utils/getEcdsaValidator.d.ts +3 -0
- package/src/utils/getEcdsaValidator.js +17 -0
- package/src/utils/getEntryPoint.cjs +24 -0
- package/src/utils/getEntryPoint.d.ts +1 -0
- package/src/utils/getEntryPoint.js +20 -0
- package/src/utils/getKernelVersion.cjs +31 -0
- package/src/utils/getKernelVersion.d.ts +4 -0
- package/src/utils/getKernelVersion.js +27 -0
- package/src/utils/index.d.ts +4 -1
package/src/ZeroDevConnector.js
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
-
import { toMultiChainECDSAValidator } from '@zerodev/multi-chain-validator';
|
|
4
3
|
import { publicActions, custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { parseEvmNetworks, DynamicError, DeferredPromise, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
12
|
-
import { cachedChainIdKey, fetchChain } from './utils/fetchChain.js';
|
|
4
|
+
import { toAccount } from 'viem/accounts';
|
|
5
|
+
import { walletClientToSmartAccountSigner } from 'permissionless/utils';
|
|
6
|
+
import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
7
|
+
import { WalletConnectorBase, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
|
|
8
|
+
import { parseEvmNetworks, StorageService, DeferredPromise, parseChainId, DynamicError, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
9
|
+
import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
|
|
13
10
|
import { logger } from './utils/logger.js';
|
|
14
11
|
import { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
|
|
12
|
+
import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
|
|
13
|
+
import { getEntryPoint } from './utils/getEntryPoint.js';
|
|
14
|
+
import { getKernelVersion } from './utils/getKernelVersion.js';
|
|
15
15
|
|
|
16
16
|
class ZeroDevConnector extends WalletConnectorBase {
|
|
17
17
|
constructor(opts) {
|
|
18
18
|
var _a, _b, _c, _d;
|
|
19
19
|
super(opts);
|
|
20
|
+
// provider map maintains the kernel clients per chain
|
|
21
|
+
this.providerMap = {};
|
|
22
|
+
// eoa connector map maintains the eoa address and connector for each smart wallet address
|
|
23
|
+
this.eoaConnectorMap = {};
|
|
20
24
|
this.ChainWallet = EthereumWallet;
|
|
21
25
|
this.connectedChain = 'EVM';
|
|
22
26
|
this.supportedChains = ['ETH', 'EVM'];
|
|
23
27
|
this.isGasSponsorshipDisabled = false;
|
|
24
28
|
this.isEmbeddedWallet = true;
|
|
29
|
+
this.providersFromApi = [];
|
|
25
30
|
this.name = 'ZeroDev';
|
|
26
31
|
this.overrideKey = 'zerodev';
|
|
27
32
|
this.walletFallback = {
|
|
@@ -31,59 +36,64 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
31
36
|
},
|
|
32
37
|
name: 'ZeroDev',
|
|
33
38
|
};
|
|
34
|
-
const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
|
|
35
|
-
if (!zeroDevProjectId) {
|
|
36
|
-
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
37
|
-
}
|
|
38
|
-
this.projectId = zeroDevProjectId;
|
|
39
39
|
this._walletUiUtils = opts.walletUiUtils;
|
|
40
40
|
this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
|
|
41
|
-
this.entryPoint =
|
|
42
|
-
this.kernelVersion =
|
|
41
|
+
this.entryPoint = getEntryPoint((_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.entryPointVersion);
|
|
42
|
+
this.kernelVersion = getKernelVersion((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.kernelVersion, this.entryPoint);
|
|
43
|
+
// this is the list of providers from the api that are used for multi-chain account abstraction
|
|
44
|
+
this.providersFromApi =
|
|
45
|
+
((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.multichainAccountAbstractionProviders) || [];
|
|
46
|
+
const [defaultProvider] = this.providersFromApi;
|
|
47
|
+
this.clientId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.clientId;
|
|
48
|
+
if (!this.clientId) {
|
|
49
|
+
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
50
|
+
}
|
|
51
|
+
this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
|
|
43
52
|
this.ecdsaProviderType = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.ecdsaProviderType;
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
if
|
|
47
|
-
|
|
48
|
-
return
|
|
54
|
+
get currentNetworkProvider() {
|
|
55
|
+
// check if the last used chain id is in the provider map
|
|
56
|
+
if (this.providerMap[this.lastUsedChainId]) {
|
|
57
|
+
return this.providerMap[this.lastUsedChainId];
|
|
49
58
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else {
|
|
54
|
-
logger.error('Invalid entry point version', entryPoint);
|
|
55
|
-
return ENTRYPOINT_ADDRESS_V07;
|
|
59
|
+
// if not, check if the default chain id is in the provider map
|
|
60
|
+
if (this.defaultChainId) {
|
|
61
|
+
return this.providerMap[this.defaultChainId];
|
|
56
62
|
}
|
|
63
|
+
// if no chain id is found, return undefined
|
|
64
|
+
return undefined;
|
|
57
65
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
else if (kernelVersion === ProviderKernelVersionEnum.V30) {
|
|
65
|
-
return KERNEL_V3_0;
|
|
66
|
-
}
|
|
67
|
-
else if (kernelVersion === ProviderKernelVersionEnum.V24 ||
|
|
68
|
-
this.entryPoint === ENTRYPOINT_ADDRESS_V06 // v0.6 only supports v2.4
|
|
69
|
-
) {
|
|
70
|
-
return KERNEL_V2_4;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
logger.error('Invalid kernel version', kernelVersion);
|
|
74
|
-
return KERNEL_V3_1;
|
|
75
|
-
}
|
|
66
|
+
get lastUsedChainId() {
|
|
67
|
+
var _a;
|
|
68
|
+
const storedChainId = StorageService.getItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
|
|
69
|
+
// returning string of unknown if no chain id is found to result in undefined provider lookup
|
|
70
|
+
return (_a = storedChainId !== null && storedChainId !== void 0 ? storedChainId : this.defaultChainId) !== null && _a !== void 0 ? _a : 'unknown';
|
|
76
71
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
get kernelClient() {
|
|
73
|
+
var _a;
|
|
74
|
+
return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClient;
|
|
75
|
+
}
|
|
76
|
+
get kernelClientWithSponsorship() {
|
|
77
|
+
var _a;
|
|
78
|
+
return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClientWithSponsorship;
|
|
79
|
+
}
|
|
80
|
+
supportsNetworkSwitching() {
|
|
81
|
+
return (Object.keys(this.providerMap).length > 1 && this.evmNetworks.length > 1);
|
|
82
|
+
}
|
|
83
|
+
switchNetwork(_a) {
|
|
84
|
+
return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
85
|
+
if (!this.supportsNetworkSwitching())
|
|
86
|
+
return;
|
|
87
|
+
if (!networkChainId)
|
|
88
|
+
return;
|
|
89
|
+
const chainId = networkChainId.toString();
|
|
90
|
+
if (!this.providerMap[chainId]) {
|
|
91
|
+
throw new Error(`No provider found for chainId: ${chainId}`);
|
|
92
|
+
}
|
|
93
|
+
StorageService.setItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY, chainId);
|
|
94
|
+
const { handleChainChange } = eventListenerHandlers(this);
|
|
95
|
+
handleChainChange(chainId);
|
|
96
|
+
});
|
|
87
97
|
}
|
|
88
98
|
/**
|
|
89
99
|
* @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
|
|
@@ -100,35 +110,120 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
100
110
|
}
|
|
101
111
|
endSession() {
|
|
102
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
|
|
113
|
+
StorageService.removeItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
|
|
104
114
|
});
|
|
105
115
|
}
|
|
106
|
-
|
|
107
|
-
return __awaiter(this,
|
|
116
|
+
registerEoa(_a) {
|
|
117
|
+
return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false, ecdsaProviderType, kernelVersion, entryPointVersion, }) {
|
|
118
|
+
const properties = {
|
|
119
|
+
ecdsaProviderType,
|
|
120
|
+
entryPointVersion,
|
|
121
|
+
kernelVersion,
|
|
122
|
+
};
|
|
123
|
+
this.eoaConnectorMap[smartWalletAddress] = {
|
|
124
|
+
eoaAddress,
|
|
125
|
+
eoaConnector,
|
|
126
|
+
properties,
|
|
127
|
+
};
|
|
128
|
+
// if this is the primary wallet, set the eoa connector and kernel clients
|
|
129
|
+
if (shouldSetEoaConnector && this.eoaAddress !== eoaAddress) {
|
|
130
|
+
yield this.setEoaConnector({
|
|
131
|
+
connector: eoaConnector,
|
|
132
|
+
eoaAddress,
|
|
133
|
+
properties,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
setEoaConnector(_a) {
|
|
139
|
+
return __awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
|
|
140
|
+
var _b;
|
|
108
141
|
if (!connector) {
|
|
109
142
|
logger.error('No EOA connector provided');
|
|
110
143
|
return;
|
|
111
144
|
}
|
|
112
145
|
this.kernelClientDeferredPromise = new DeferredPromise();
|
|
113
146
|
this.eoaConnector = connector;
|
|
147
|
+
this.eoaAddress = eoaAddress;
|
|
148
|
+
if (properties) {
|
|
149
|
+
this.ecdsaProviderType =
|
|
150
|
+
(_b = properties.ecdsaProviderType) !== null && _b !== void 0 ? _b : this.ecdsaProviderType;
|
|
151
|
+
this.entryPoint = properties.entryPointVersion
|
|
152
|
+
? getEntryPoint(properties.entryPointVersion)
|
|
153
|
+
: this.entryPoint;
|
|
154
|
+
this.kernelVersion = properties.entryPointVersion
|
|
155
|
+
? getKernelVersion(properties.kernelVersion, this.entryPoint)
|
|
156
|
+
: this.kernelVersion;
|
|
157
|
+
}
|
|
114
158
|
if (isEthWalletConnector(this.eoaConnector) &&
|
|
115
159
|
!this.eoaConnector.getActiveAccount()) {
|
|
116
160
|
yield this.eoaConnector.getConnectedAccounts();
|
|
117
161
|
}
|
|
118
162
|
const signer = yield this.eoaConnector.getSigner();
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
163
|
+
signer.account = toAccount(eoaAddress);
|
|
164
|
+
yield this.generateProviderMap(signer);
|
|
165
|
+
this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
|
|
166
|
+
this.kernelClientDeferredPromise.resolve();
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
warnIfProjectChainNotEnabled(chainId) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
var _a;
|
|
172
|
+
let chainIdToCheck = chainId;
|
|
173
|
+
if (!chainIdToCheck) {
|
|
174
|
+
const client = yield this.getPublicClient();
|
|
175
|
+
chainIdToCheck = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.id;
|
|
176
|
+
}
|
|
177
|
+
const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainIdToCheck);
|
|
178
|
+
if (!isProjectChainEnabled) {
|
|
179
|
+
logger.error(`Please make sure to enable (${chainIdToCheck}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
generateProviderMap(signer) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
// reset the chains provider map when eoa connector changes
|
|
186
|
+
this.providerMap = {};
|
|
187
|
+
yield Promise.all(this.providersFromApi.map((provider) => __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
if (!this.providerMap[provider.chain]) {
|
|
189
|
+
const [kernelClient, kernelClientWithSponsorship] = yield Promise.all([
|
|
190
|
+
this.getKernelClientWithoutSponsorshipValidation({
|
|
191
|
+
chainId: provider.chain,
|
|
192
|
+
projectId: provider.clientId,
|
|
193
|
+
signer,
|
|
194
|
+
}),
|
|
195
|
+
this.getKernelClientWithSponsorshipValidation({
|
|
196
|
+
chainId: provider.chain,
|
|
197
|
+
projectId: provider.clientId,
|
|
198
|
+
signer,
|
|
199
|
+
}),
|
|
200
|
+
]);
|
|
201
|
+
this.providerMap[provider.chain] = {
|
|
202
|
+
kernelClient,
|
|
203
|
+
kernelClientWithSponsorship,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
yield this.warnIfProjectChainNotEnabled(parseChainId(provider.chain));
|
|
207
|
+
})));
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
getKernelClientWithoutSponsorshipValidation(_a) {
|
|
211
|
+
return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
|
|
212
|
+
if (chainId && this.providerMap[chainId]) {
|
|
213
|
+
return this.providerMap[chainId].kernelClient;
|
|
122
214
|
}
|
|
215
|
+
const { eoaConnector } = this;
|
|
216
|
+
if (!eoaConnector)
|
|
217
|
+
throw new DynamicError('No EOA connector');
|
|
123
218
|
const kernelClient = yield createEcdsaKernelAccountClient({
|
|
124
219
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
125
|
-
chain:
|
|
126
|
-
ecdsaValidator:
|
|
220
|
+
chain: chainsMap[chainId],
|
|
221
|
+
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
127
222
|
entryPointAddress: this.entryPoint,
|
|
128
223
|
kernelVersion: this.kernelVersion,
|
|
129
224
|
paymaster: 'NONE',
|
|
130
225
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
131
|
-
projectId
|
|
226
|
+
projectId,
|
|
132
227
|
provider: ZeroDevConnector.bundlerProvider,
|
|
133
228
|
signer: walletClientToSmartAccountSigner(signer),
|
|
134
229
|
});
|
|
@@ -136,51 +231,34 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
136
231
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
137
232
|
return original(...args);
|
|
138
233
|
});
|
|
139
|
-
|
|
140
|
-
// set the provider with sponsorship enabled
|
|
141
|
-
yield this.getKernelClientWithSponsorshipValidation();
|
|
142
|
-
yield this.checkIsProjectChainEnabled();
|
|
143
|
-
this.kernelClientDeferredPromise.resolve();
|
|
234
|
+
return kernelClient;
|
|
144
235
|
});
|
|
145
236
|
}
|
|
146
|
-
|
|
147
|
-
return __awaiter(this,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
|
|
151
|
-
const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
|
|
152
|
-
const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
|
|
153
|
-
if (!isProjectChainEnabled) {
|
|
154
|
-
logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
getKernelClientWithSponsorshipValidation() {
|
|
159
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
if (this.kernelClientWithSponsorship) {
|
|
161
|
-
return this.kernelClientWithSponsorship;
|
|
237
|
+
getKernelClientWithSponsorshipValidation(_a) {
|
|
238
|
+
return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
|
|
239
|
+
if (chainId && this.providerMap[chainId]) {
|
|
240
|
+
return this.providerMap[chainId].kernelClientWithSponsorship;
|
|
162
241
|
}
|
|
163
242
|
const { eoaConnector } = this;
|
|
164
243
|
if (!eoaConnector)
|
|
165
244
|
throw new DynamicError('No EOA connector');
|
|
166
|
-
const
|
|
167
|
-
this.kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
|
|
245
|
+
const kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
|
|
168
246
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
169
|
-
chain:
|
|
170
|
-
ecdsaValidator:
|
|
247
|
+
chain: chainsMap[chainId],
|
|
248
|
+
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
171
249
|
entryPointAddress: this.entryPoint,
|
|
172
250
|
kernelVersion: this.kernelVersion,
|
|
173
251
|
paymaster: 'SPONSOR',
|
|
174
252
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
175
|
-
projectId
|
|
253
|
+
projectId,
|
|
176
254
|
provider: ZeroDevConnector.bundlerProvider,
|
|
177
255
|
signer: walletClientToSmartAccountSigner(signer),
|
|
178
256
|
});
|
|
179
|
-
wrapMethodWithCallback(
|
|
257
|
+
wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
|
|
180
258
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
181
259
|
return original(...args);
|
|
182
260
|
});
|
|
183
|
-
return
|
|
261
|
+
return kernelClientWithSponsorship;
|
|
184
262
|
});
|
|
185
263
|
}
|
|
186
264
|
getAddress() {
|
|
@@ -221,7 +299,10 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
221
299
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
222
300
|
const effectiveProvider = this.isGasSponsorshipDisabled
|
|
223
301
|
? provider
|
|
224
|
-
:
|
|
302
|
+
: this.kernelClientWithSponsorship;
|
|
303
|
+
if (!effectiveProvider) {
|
|
304
|
+
throw new DynamicError('No provider');
|
|
305
|
+
}
|
|
225
306
|
const response = yield effectiveProvider.sendTransaction(unFormatTransaction(transaction));
|
|
226
307
|
return response;
|
|
227
308
|
}
|
|
@@ -259,7 +340,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
259
340
|
var _a;
|
|
260
341
|
const provider = this.kernelClient;
|
|
261
342
|
if (!provider)
|
|
262
|
-
|
|
343
|
+
return undefined;
|
|
263
344
|
const transport = this.getTransport(provider);
|
|
264
345
|
const address = (_a = provider.account) === null || _a === void 0 ? void 0 : _a.address;
|
|
265
346
|
const walletClient = createWalletClient({
|
|
@@ -274,7 +355,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
274
355
|
var _a;
|
|
275
356
|
const provider = (_a = this.kernelClient) === null || _a === void 0 ? void 0 : _a.extend(publicActions);
|
|
276
357
|
if (!provider)
|
|
277
|
-
|
|
358
|
+
return undefined;
|
|
278
359
|
return provider;
|
|
279
360
|
});
|
|
280
361
|
}
|
|
@@ -286,7 +367,10 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
286
367
|
canSponsorTransactionGas(transaction) {
|
|
287
368
|
return __awaiter(this, void 0, void 0, function* () {
|
|
288
369
|
try {
|
|
289
|
-
const kernelClientWithSponsorship =
|
|
370
|
+
const { kernelClientWithSponsorship } = this;
|
|
371
|
+
if (!kernelClientWithSponsorship) {
|
|
372
|
+
throw new DynamicError('No kernel client with sponsorship found');
|
|
373
|
+
}
|
|
290
374
|
const userOperation = {
|
|
291
375
|
callData: yield kernelClientWithSponsorship.account.encodeCallData({
|
|
292
376
|
data: transaction.data ? transaction.data : '0x',
|
|
@@ -347,23 +431,18 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
347
431
|
});
|
|
348
432
|
}
|
|
349
433
|
validateActiveWallet(expectedAddress) {
|
|
350
|
-
const _super = Object.create(null, {
|
|
351
|
-
validateActiveWallet: { get: () => super.validateActiveWallet }
|
|
352
|
-
});
|
|
353
434
|
return __awaiter(this, void 0, void 0, function* () {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const verifiedCredentials = eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.verifiedCredentials;
|
|
358
|
-
const expectedEoaAddress = (_a = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find((vc) => vc.smartWalletRefAddress === expectedAddress)) === null || _a === void 0 ? void 0 : _a.address;
|
|
359
|
-
if (!expectedEoaAddress) {
|
|
360
|
-
throw new DynamicError('No EOA connector');
|
|
361
|
-
}
|
|
362
|
-
yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.validateActiveWallet(expectedEoaAddress));
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
yield _super.validateActiveWallet.call(this, expectedAddress);
|
|
435
|
+
const eoa = this.eoaConnectorMap[expectedAddress];
|
|
436
|
+
if (!eoa) {
|
|
437
|
+
throw new DynamicError('No EOA connector');
|
|
366
438
|
}
|
|
439
|
+
const { eoaAddress, eoaConnector, properties } = eoa;
|
|
440
|
+
yield eoaConnector.validateActiveWallet(eoaAddress);
|
|
441
|
+
yield this.setEoaConnector({
|
|
442
|
+
connector: eoaConnector,
|
|
443
|
+
eoaAddress,
|
|
444
|
+
properties,
|
|
445
|
+
});
|
|
367
446
|
});
|
|
368
447
|
}
|
|
369
448
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ZERO_DEV_LAST_USED_CHAIN_ID_KEY = "dynamic_zerodev_last_used_chain_id";
|
package/src/constants.js
ADDED
package/src/index.cjs
CHANGED
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
+
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
|
+
var _package = require('../package.cjs');
|
|
6
8
|
var ZeroDevConnector = require('./ZeroDevConnector.cjs');
|
|
9
|
+
var createEcsdaKernelAccountClient = require('./utils/createEcsdaKernelAccountClient.cjs');
|
|
10
|
+
var fetchZeroDevChain = require('./utils/fetchZeroDevChain.cjs');
|
|
11
|
+
var getEcdsaValidator = require('./utils/getEcdsaValidator.cjs');
|
|
12
|
+
var getEntryPoint = require('./utils/getEntryPoint.cjs');
|
|
13
|
+
var getKernelVersion = require('./utils/getKernelVersion.cjs');
|
|
7
14
|
var ethereumAa = require('./ethereum-aa.cjs');
|
|
8
15
|
var isZeroDevConnector = require('./utils/isZeroDevConnector.cjs');
|
|
9
16
|
|
|
17
|
+
assertPackageVersion.assertPackageVersion('@dynamic-labs/ethereum-aa', _package.version);
|
|
10
18
|
const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, bundlerRpc, paymasterRpc, } = {}) => {
|
|
11
19
|
ZeroDevConnector.ZeroDevConnector.bundlerProvider = bundlerProvider;
|
|
12
20
|
ZeroDevConnector.ZeroDevConnector.bundlerRpc = bundlerRpc;
|
|
@@ -21,6 +29,11 @@ const ZeroDevSmartWalletConnectors = (props) => {
|
|
|
21
29
|
return [];
|
|
22
30
|
};
|
|
23
31
|
|
|
32
|
+
exports.createEcdsaKernelAccountClient = createEcsdaKernelAccountClient.createEcdsaKernelAccountClient;
|
|
33
|
+
exports.fetchZeroDevChain = fetchZeroDevChain.fetchZeroDevChain;
|
|
34
|
+
exports.getEcdsaValidator = getEcdsaValidator.getEcdsaValidator;
|
|
35
|
+
exports.getEntryPoint = getEntryPoint.getEntryPoint;
|
|
36
|
+
exports.getKernelVersion = getKernelVersion.getKernelVersion;
|
|
24
37
|
exports.EthereumAaConnector = ethereumAa.EthereumAaConnector;
|
|
25
38
|
exports.isZeroDevConnector = isZeroDevConnector.isZeroDevConnector;
|
|
26
39
|
exports.ZeroDevSmartWalletConnectors = ZeroDevSmartWalletConnectors;
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
2
2
|
import { BundlerProvider } from './utils';
|
|
3
|
+
export { createEcdsaKernelAccountClient, type BundlerProvider, type PaymasterType, } from './utils/createEcsdaKernelAccountClient';
|
|
4
|
+
export { fetchZeroDevChain } from './utils/fetchZeroDevChain';
|
|
5
|
+
export { getEcdsaValidator } from './utils/getEcdsaValidator';
|
|
6
|
+
export { getEntryPoint } from './utils/getEntryPoint';
|
|
7
|
+
export { getKernelVersion } from './utils/getKernelVersion';
|
|
3
8
|
export * from './ethereum-aa';
|
|
4
9
|
export { isZeroDevConnector } from './utils/isZeroDevConnector';
|
|
5
10
|
export declare const ZeroDevSmartWalletConnectorsWithConfig: ({ bundlerProvider, bundlerRpc, paymasterRpc, }?: {
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
|
+
import { version } from '../package.js';
|
|
2
4
|
import { ZeroDevConnector } from './ZeroDevConnector.js';
|
|
5
|
+
export { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
|
|
6
|
+
export { fetchZeroDevChain } from './utils/fetchZeroDevChain.js';
|
|
7
|
+
export { getEcdsaValidator } from './utils/getEcdsaValidator.js';
|
|
8
|
+
export { getEntryPoint } from './utils/getEntryPoint.js';
|
|
9
|
+
export { getKernelVersion } from './utils/getKernelVersion.js';
|
|
3
10
|
export { EthereumAaConnector } from './ethereum-aa.js';
|
|
4
11
|
export { isZeroDevConnector } from './utils/isZeroDevConnector.js';
|
|
5
12
|
|
|
13
|
+
assertPackageVersion('@dynamic-labs/ethereum-aa', version);
|
|
6
14
|
const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, bundlerRpc, paymasterRpc, } = {}) => {
|
|
7
15
|
ZeroDevConnector.bundlerProvider = bundlerProvider;
|
|
8
16
|
ZeroDevConnector.bundlerRpc = bundlerRpc;
|
|
@@ -21,4 +21,4 @@ export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPo
|
|
|
21
21
|
index?: bigint;
|
|
22
22
|
kernelVersion: GetKernelVersion<entryPoint>;
|
|
23
23
|
ecdsaValidator: any;
|
|
24
|
-
}) => Promise<KernelAccountClient<entryPoint, HttpTransport, TChain, KernelSmartAccount<entryPoint
|
|
24
|
+
}) => Promise<KernelAccountClient<entryPoint, HttpTransport, TChain, KernelSmartAccount<entryPoint>>>;
|
|
@@ -8,7 +8,7 @@ var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
|
8
8
|
var logger = require('./logger.cjs');
|
|
9
9
|
|
|
10
10
|
const cachedChainIdKey = 'dynamic_zd_chain_id';
|
|
11
|
-
const
|
|
11
|
+
const fetchZeroDevChain = (projectId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
12
12
|
try {
|
|
13
13
|
const cachedChainId = localStorage.getItem(cachedChainIdKey);
|
|
14
14
|
if (cachedChainId) {
|
|
@@ -26,4 +26,4 @@ const fetchChain = (projectId) => _tslib.__awaiter(void 0, void 0, void 0, funct
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
exports.cachedChainIdKey = cachedChainIdKey;
|
|
29
|
-
exports.
|
|
29
|
+
exports.fetchZeroDevChain = fetchZeroDevChain;
|
|
@@ -4,7 +4,7 @@ import { chainsMap } from '@dynamic-labs/ethereum-core';
|
|
|
4
4
|
import { logger } from './logger.js';
|
|
5
5
|
|
|
6
6
|
const cachedChainIdKey = 'dynamic_zd_chain_id';
|
|
7
|
-
const
|
|
7
|
+
const fetchZeroDevChain = (projectId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
8
|
try {
|
|
9
9
|
const cachedChainId = localStorage.getItem(cachedChainIdKey);
|
|
10
10
|
if (cachedChainId) {
|
|
@@ -21,4 +21,4 @@ const fetchChain = (projectId) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
export { cachedChainIdKey,
|
|
24
|
+
export { cachedChainIdKey, fetchZeroDevChain };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var ecdsaValidator = require('@zerodev/ecdsa-validator');
|
|
7
|
+
var multiChainValidator = require('@zerodev/multi-chain-validator');
|
|
8
|
+
|
|
9
|
+
const getEcdsaValidator = (ecdsaProviderType) => {
|
|
10
|
+
if (ecdsaProviderType === 'zerodev_signer_to_ecdsa') {
|
|
11
|
+
return ecdsaValidator.signerToEcdsaValidator;
|
|
12
|
+
}
|
|
13
|
+
else if (ecdsaProviderType === 'zerodev_multi_chain') {
|
|
14
|
+
return multiChainValidator.toMultiChainECDSAValidator;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return ecdsaValidator.signerToEcdsaValidator;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.getEcdsaValidator = getEcdsaValidator;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
|
|
2
|
+
import { toMultiChainECDSAValidator } from '@zerodev/multi-chain-validator';
|
|
3
|
+
export declare const getEcdsaValidator: (ecdsaProviderType: string | undefined) => typeof signerToEcdsaValidator | typeof toMultiChainECDSAValidator;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
|
|
3
|
+
import { toMultiChainECDSAValidator } from '@zerodev/multi-chain-validator';
|
|
4
|
+
|
|
5
|
+
const getEcdsaValidator = (ecdsaProviderType) => {
|
|
6
|
+
if (ecdsaProviderType === 'zerodev_signer_to_ecdsa') {
|
|
7
|
+
return signerToEcdsaValidator;
|
|
8
|
+
}
|
|
9
|
+
else if (ecdsaProviderType === 'zerodev_multi_chain') {
|
|
10
|
+
return toMultiChainECDSAValidator;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return signerToEcdsaValidator;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { getEcdsaValidator };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var permissionless = require('permissionless');
|
|
7
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
8
|
+
var logger = require('./logger.cjs');
|
|
9
|
+
|
|
10
|
+
const getEntryPoint = (entryPoint) => {
|
|
11
|
+
if (entryPoint === undefined ||
|
|
12
|
+
entryPoint === sdkApiCore.ProviderEntryPointVersionEnum.V7) {
|
|
13
|
+
return permissionless.ENTRYPOINT_ADDRESS_V07;
|
|
14
|
+
}
|
|
15
|
+
else if (entryPoint === sdkApiCore.ProviderEntryPointVersionEnum.V6) {
|
|
16
|
+
return permissionless.ENTRYPOINT_ADDRESS_V06;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
logger.logger.error('Invalid entry point version', entryPoint);
|
|
20
|
+
return permissionless.ENTRYPOINT_ADDRESS_V07;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.getEntryPoint = getEntryPoint;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getEntryPoint: (entryPoint: string | undefined) => "0x0000000071727De22E5E9d8BAf0edAc6f37da032" | "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { ENTRYPOINT_ADDRESS_V07, ENTRYPOINT_ADDRESS_V06 } from 'permissionless';
|
|
3
|
+
import { ProviderEntryPointVersionEnum } from '@dynamic-labs/sdk-api-core';
|
|
4
|
+
import { logger } from './logger.js';
|
|
5
|
+
|
|
6
|
+
const getEntryPoint = (entryPoint) => {
|
|
7
|
+
if (entryPoint === undefined ||
|
|
8
|
+
entryPoint === ProviderEntryPointVersionEnum.V7) {
|
|
9
|
+
return ENTRYPOINT_ADDRESS_V07;
|
|
10
|
+
}
|
|
11
|
+
else if (entryPoint === ProviderEntryPointVersionEnum.V6) {
|
|
12
|
+
return ENTRYPOINT_ADDRESS_V06;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
logger.error('Invalid entry point version', entryPoint);
|
|
16
|
+
return ENTRYPOINT_ADDRESS_V07;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { getEntryPoint };
|