@dynamic-labs/ethereum-aa 4.15.0 → 4.17.0
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 +24 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +12 -12
- package/src/ZeroDevConnector.cjs +35 -9
- package/src/ZeroDevConnector.d.ts +14 -6
- package/src/ZeroDevConnector.js +36 -10
- package/src/utils/createEcdsaKernelAccountClient.cjs +6 -6
- package/src/utils/createEcdsaKernelAccountClient.d.ts +3 -2
- package/src/utils/createEcdsaKernelAccountClient.js +6 -6
- package/src/utils/hasSmartAccount.cjs +20 -0
- package/src/utils/hasSmartAccount.d.ts +2 -0
- package/src/utils/hasSmartAccount.js +16 -0
- package/src/utils/index.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.17.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.16.0...v4.17.0) (2025-05-06)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add chain id option to create kernel client in react-native ([#8650](https://github.com/dynamic-labs/dynamic-auth/issues/8650)) ([1450bea](https://github.com/dynamic-labs/dynamic-auth/commit/1450bea6f979a82ed4880700aff14fa1ead9dc60))
|
|
8
|
+
* add sendCalls method to EthereumWallet ([#8634](https://github.com/dynamic-labs/dynamic-auth/issues/8634)) ([7c9aef9](https://github.com/dynamic-labs/dynamic-auth/commit/7c9aef95382b4823a40279bebfb084de32c25610))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* 7702 do not override existing old aa ([#8630](https://github.com/dynamic-labs/dynamic-auth/issues/8630)) ([a731d9e](https://github.com/dynamic-labs/dynamic-auth/commit/a731d9e77ecd9e1dec3a7704a63989b5f2741a57))
|
|
14
|
+
* improve error message when email login fails ([#8649](https://github.com/dynamic-labs/dynamic-auth/issues/8649)) ([e1c03ac](https://github.com/dynamic-labs/dynamic-auth/commit/e1c03ac6dc83386c63d63db59d31355bc4fe2959))
|
|
15
|
+
* improve react-native stability on android ([#8652](https://github.com/dynamic-labs/dynamic-auth/issues/8652)) ([1617546](https://github.com/dynamic-labs/dynamic-auth/commit/1617546e6053c2ab32f7d385336c47df185d077f))
|
|
16
|
+
|
|
17
|
+
## [4.16.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.15.0...v4.16.0) (2025-05-03)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* (GVTY-3020) add send balance to waas sui connector ([#8638](https://github.com/dynamic-labs/dynamic-auth/issues/8638)) ([97f0af0](https://github.com/dynamic-labs/dynamic-auth/commit/97f0af0504a0079ebf0958fde1f8edc34c035927))
|
|
23
|
+
* add isAtomicSupported and isPaymasterServiceSupported methods to EthereumWallet ([#8627](https://github.com/dynamic-labs/dynamic-auth/issues/8627)) ([df82b9e](https://github.com/dynamic-labs/dynamic-auth/commit/df82b9e86eafea9dd6c505227722450bc56d7c57))
|
|
24
|
+
* add solana mpc to global wallets ([#8605](https://github.com/dynamic-labs/dynamic-auth/issues/8605)) ([6261bf9](https://github.com/dynamic-labs/dynamic-auth/commit/6261bf9bec45b1d1afa13869cf5d10cda215783e))
|
|
25
|
+
|
|
2
26
|
## [4.15.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.14.0...v4.15.0) (2025-04-30)
|
|
3
27
|
|
|
4
28
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum-aa",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.17.0",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@dynamic-labs/sdk-api-core": "0.0.660",
|
|
22
|
-
"@zerodev/ecdsa-validator": "5.4.
|
|
23
|
-
"@zerodev/multi-chain-ecdsa-validator": "5.4.
|
|
24
|
-
"@zerodev/sdk": "5.4.
|
|
25
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
26
|
-
"@dynamic-labs/ethereum-aa-core": "4.
|
|
27
|
-
"@dynamic-labs/ethereum-core": "4.
|
|
28
|
-
"@dynamic-labs/logger": "4.
|
|
29
|
-
"@dynamic-labs/types": "4.
|
|
30
|
-
"@dynamic-labs/utils": "4.
|
|
31
|
-
"@dynamic-labs/wallet-book": "4.
|
|
32
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
22
|
+
"@zerodev/ecdsa-validator": "5.4.8",
|
|
23
|
+
"@zerodev/multi-chain-ecdsa-validator": "5.4.5",
|
|
24
|
+
"@zerodev/sdk": "5.4.34",
|
|
25
|
+
"@dynamic-labs/assert-package-version": "4.17.0",
|
|
26
|
+
"@dynamic-labs/ethereum-aa-core": "4.17.0",
|
|
27
|
+
"@dynamic-labs/ethereum-core": "4.17.0",
|
|
28
|
+
"@dynamic-labs/logger": "4.17.0",
|
|
29
|
+
"@dynamic-labs/types": "4.17.0",
|
|
30
|
+
"@dynamic-labs/utils": "4.17.0",
|
|
31
|
+
"@dynamic-labs/wallet-book": "4.17.0",
|
|
32
|
+
"@dynamic-labs/wallet-connector-core": "4.17.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"viem": "^2.21.60"
|
package/src/ZeroDevConnector.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var viem = require('viem');
|
|
|
8
8
|
var accounts = require('viem/accounts');
|
|
9
9
|
var constants$1 = require('@zerodev/sdk/constants');
|
|
10
10
|
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
11
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
11
12
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
12
13
|
var utils = require('@dynamic-labs/utils');
|
|
13
14
|
var ethereumAaCore = require('@dynamic-labs/ethereum-aa-core');
|
|
@@ -18,6 +19,7 @@ var getEcdsaValidator = require('./utils/getEcdsaValidator.cjs');
|
|
|
18
19
|
var getEntryPoint = require('./utils/getEntryPoint.cjs');
|
|
19
20
|
var getKernelVersion = require('./utils/getKernelVersion.cjs');
|
|
20
21
|
var isEVMAuthorizationCapable = require('./utils/isEVMAuthorizationCapable.cjs');
|
|
22
|
+
var hasSmartAccount = require('./utils/hasSmartAccount.cjs');
|
|
21
23
|
|
|
22
24
|
class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
23
25
|
constructor(opts) {
|
|
@@ -41,9 +43,15 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
41
43
|
},
|
|
42
44
|
name: 'ZeroDev',
|
|
43
45
|
};
|
|
46
|
+
this.hasExistingSmartAccount = false;
|
|
47
|
+
/**
|
|
48
|
+
* Flag for EIP-7702 mode, enabled when EIP-7702 is enabled and no smart account exists
|
|
49
|
+
*/
|
|
50
|
+
this.shouldUseEIP7702Mode = false;
|
|
44
51
|
this._walletUiUtils = opts.walletUiUtils;
|
|
45
52
|
this.providersConfig = (_a = opts.providersConfig) !== null && _a !== void 0 ? _a : {};
|
|
46
|
-
this.
|
|
53
|
+
this.is7702EnabledOnDashboard =
|
|
54
|
+
(_c = (_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.enableEIP7702) !== null && _c !== void 0 ? _c : false;
|
|
47
55
|
this.entryPoint = getEntryPoint.getEntryPoint((_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.entryPointVersion);
|
|
48
56
|
this.kernelVersion = getKernelVersion.getKernelVersion((_e = opts.apiProviders.zerodev) === null || _e === void 0 ? void 0 : _e.kernelVersion, this.entryPoint);
|
|
49
57
|
this.enableKernelV3Migration =
|
|
@@ -120,17 +128,22 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
120
128
|
});
|
|
121
129
|
}
|
|
122
130
|
initialize(_a) {
|
|
123
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, }) {
|
|
131
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, verifiedCredentials, }) {
|
|
124
132
|
yield this.registerEoa(Object.assign({ eoaAddress,
|
|
125
133
|
eoaConnector,
|
|
126
134
|
shouldSetEoaConnector,
|
|
127
|
-
smartWalletAddress
|
|
135
|
+
smartWalletAddress,
|
|
136
|
+
verifiedCredentials }, properties));
|
|
128
137
|
});
|
|
129
138
|
}
|
|
130
139
|
registerEoa(_a) {
|
|
131
140
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
var { smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false } = _a, properties = _tslib.__rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "shouldSetEoaConnector"]);
|
|
133
|
-
if (
|
|
141
|
+
var { smartWalletAddress, eoaAddress, eoaConnector, verifiedCredentials, shouldSetEoaConnector = false } = _a, properties = _tslib.__rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "verifiedCredentials", "shouldSetEoaConnector"]);
|
|
142
|
+
if (!eoaConnector) {
|
|
143
|
+
throw new utils.DynamicError('No EOA connector');
|
|
144
|
+
}
|
|
145
|
+
this.determineSmartAccountStatus(eoaConnector, verifiedCredentials);
|
|
146
|
+
if (this.shouldUseEIP7702Mode) {
|
|
134
147
|
// In EIP-7702, addresses must match
|
|
135
148
|
if (smartWalletAddress !== eoaAddress) {
|
|
136
149
|
throw new Error('In EIP-7702 mode, smart wallet and EOA addresses must be the same');
|
|
@@ -158,6 +171,14 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
158
171
|
}
|
|
159
172
|
});
|
|
160
173
|
}
|
|
174
|
+
determineSmartAccountStatus(eoaConnector, verifiedCredentials) {
|
|
175
|
+
if (walletConnectorCore.getWalletProvider(eoaConnector) !== sdkApiCore.WalletProviderEnum.EmbeddedWallet) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this.hasExistingSmartAccount = hasSmartAccount.hasSmartAccount(verifiedCredentials);
|
|
179
|
+
this.shouldUseEIP7702Mode =
|
|
180
|
+
this.is7702EnabledOnDashboard && !this.hasExistingSmartAccount;
|
|
181
|
+
}
|
|
161
182
|
getOrCreateAuthorization() {
|
|
162
183
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
163
184
|
var _a;
|
|
@@ -231,7 +252,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
231
252
|
}
|
|
232
253
|
const signer = yield this.eoaConnector.getSigner();
|
|
233
254
|
signer.account = accounts.toAccount(eoaAddress);
|
|
234
|
-
if (this.
|
|
255
|
+
if (this.shouldUseEIP7702Mode) {
|
|
235
256
|
this.authorization = yield this.getOrCreateAuthorization();
|
|
236
257
|
}
|
|
237
258
|
yield this.generateProviderMap(signer);
|
|
@@ -296,6 +317,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
296
317
|
}
|
|
297
318
|
createKernelClient(_a) {
|
|
298
319
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, authorization, }) {
|
|
320
|
+
var _b;
|
|
299
321
|
if (chainId && this.providerMap[chainId]) {
|
|
300
322
|
return paymaster === 'SPONSOR'
|
|
301
323
|
? this.providerMap[chainId].kernelClientWithSponsorship
|
|
@@ -305,8 +327,10 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
305
327
|
if (!eoaConnector)
|
|
306
328
|
throw new utils.DynamicError('No EOA connector');
|
|
307
329
|
const chain = ethereumCore.chainsMap[chainId];
|
|
330
|
+
const network = this.evmNetworks.find((network) => network.chainId === utils.parseChainId(chainId));
|
|
331
|
+
const publicClientRpc = (_b = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _b === void 0 ? void 0 : _b[0];
|
|
308
332
|
let kernelClient;
|
|
309
|
-
if (this.
|
|
333
|
+
if (this.shouldUseEIP7702Mode) {
|
|
310
334
|
kernelClient = yield createEcdsaKernelAccountClient.createEcdsaKernelAccountClientWith7702({
|
|
311
335
|
authorization,
|
|
312
336
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
@@ -319,6 +343,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
319
343
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
320
344
|
projectId,
|
|
321
345
|
provider: ZeroDevConnector.bundlerProvider,
|
|
346
|
+
publicClientRpc,
|
|
322
347
|
signer,
|
|
323
348
|
});
|
|
324
349
|
}
|
|
@@ -334,6 +359,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
334
359
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
335
360
|
projectId,
|
|
336
361
|
provider: ZeroDevConnector.bundlerProvider,
|
|
362
|
+
publicClientRpc,
|
|
337
363
|
signer,
|
|
338
364
|
});
|
|
339
365
|
}
|
|
@@ -347,7 +373,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
347
373
|
getAddress() {
|
|
348
374
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
349
375
|
var _a, _b, _c;
|
|
350
|
-
if (this.
|
|
376
|
+
if (this.shouldUseEIP7702Mode) {
|
|
351
377
|
return this.eoaAddress;
|
|
352
378
|
}
|
|
353
379
|
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
@@ -568,7 +594,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
568
594
|
}
|
|
569
595
|
validateActiveWallet(expectedAddress) {
|
|
570
596
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
571
|
-
if (this.
|
|
597
|
+
if (this.shouldUseEIP7702Mode) {
|
|
572
598
|
const currentAddress = yield this.getAddress();
|
|
573
599
|
if (currentAddress !== expectedAddress) {
|
|
574
600
|
throw new utils.DynamicError('Invalid active wallet');
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { KernelAccountClient } from '@zerodev/sdk/clients';
|
|
2
2
|
import { SmartAccount, EntryPointVersion } from 'viem/account-abstraction';
|
|
3
|
-
import { Client, PublicClient, RpcSchema, Transport, WalletClient } from 'viem';
|
|
3
|
+
import { Account, Client, PublicClient, RpcSchema, Transport, WalletClient } from 'viem';
|
|
4
4
|
import { SignAuthorizationReturnType } from 'viem/accounts';
|
|
5
5
|
import { type Chain as ViemChain } from 'viem/chains';
|
|
6
6
|
import { EntryPointType, KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
|
|
7
7
|
import { EthereumWallet, RegisterEvmProvidersConfig } from '@dynamic-labs/ethereum-core';
|
|
8
|
-
import { EcdsaValidatorOptions, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders, SmartWalletProperties } from '@dynamic-labs/sdk-api-core';
|
|
8
|
+
import { EcdsaValidatorOptions, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders, SmartWalletProperties, JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
|
|
9
9
|
import { Chain, InternalWalletConnector, IZeroDevConnector } from '@dynamic-labs/wallet-connector-core';
|
|
10
10
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
11
11
|
import { GenericNetwork, TransactionReceipt, WalletUiUtils } from '@dynamic-labs/types';
|
|
@@ -60,8 +60,13 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
60
60
|
};
|
|
61
61
|
name: string;
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
is7702EnabledOnDashboard: boolean;
|
|
64
64
|
private authorization?;
|
|
65
|
+
private hasExistingSmartAccount;
|
|
66
|
+
/**
|
|
67
|
+
* Flag for EIP-7702 mode, enabled when EIP-7702 is enabled and no smart account exists
|
|
68
|
+
*/
|
|
69
|
+
private shouldUseEIP7702Mode;
|
|
65
70
|
constructor(opts: ZeroDevConnectorProps);
|
|
66
71
|
confirmTransactionStatus(): Promise<TransactionReceipt>;
|
|
67
72
|
get currentNetworkProvider(): {
|
|
@@ -79,22 +84,25 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
79
84
|
withSponsorship?: boolean;
|
|
80
85
|
}): T;
|
|
81
86
|
endSession(): Promise<void>;
|
|
82
|
-
initialize({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, }: {
|
|
87
|
+
initialize({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, verifiedCredentials, }: {
|
|
83
88
|
smartWalletAddress: string;
|
|
84
89
|
eoaAddress: string;
|
|
85
90
|
eoaConnector: InternalWalletConnector;
|
|
86
91
|
shouldSetEoaConnector: boolean;
|
|
87
92
|
properties?: SmartWalletProperties;
|
|
93
|
+
verifiedCredentials: JwtVerifiedCredential[];
|
|
88
94
|
}): Promise<void>;
|
|
89
|
-
registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, ...properties }: {
|
|
95
|
+
registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, verifiedCredentials, shouldSetEoaConnector, ...properties }: {
|
|
90
96
|
smartWalletAddress: string;
|
|
91
97
|
eoaAddress: string;
|
|
92
98
|
eoaConnector: InternalWalletConnector;
|
|
99
|
+
verifiedCredentials: JwtVerifiedCredential[];
|
|
93
100
|
shouldSetEoaConnector: boolean;
|
|
94
101
|
ecdsaProviderType?: EcdsaValidatorOptions;
|
|
95
102
|
kernelVersion?: ProviderKernelVersionEnum;
|
|
96
103
|
entryPointVersion?: ProviderEntryPointVersionEnum;
|
|
97
104
|
}): Promise<void>;
|
|
105
|
+
private determineSmartAccountStatus;
|
|
98
106
|
private getOrCreateAuthorization;
|
|
99
107
|
private setEoaConnector;
|
|
100
108
|
private warnIfProjectChainNotEnabled;
|
|
@@ -110,7 +118,7 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
110
118
|
getConnectedAccounts(): Promise<string[]>;
|
|
111
119
|
getNetwork(): Promise<number | undefined>;
|
|
112
120
|
private getTransport;
|
|
113
|
-
getWalletClient(chainId?: string): WalletClient<Transport, ViemChain> | undefined;
|
|
121
|
+
getWalletClient(chainId?: string): WalletClient<Transport, ViemChain, Account> | undefined;
|
|
114
122
|
getPublicClient(): Promise<void | PublicClient<Transport, ViemChain> | undefined>;
|
|
115
123
|
formatUserOperation(params: any): Promise<{
|
|
116
124
|
callData: any;
|
package/src/ZeroDevConnector.js
CHANGED
|
@@ -4,7 +4,8 @@ import { publicActions, custom, createWalletClient, toHex, formatEther } from 'v
|
|
|
4
4
|
import { toAccount } from 'viem/accounts';
|
|
5
5
|
import { KERNEL_V3_3_BETA, KernelVersionToAddressesMap, getEntryPoint as getEntryPoint$1 } from '@zerodev/sdk/constants';
|
|
6
6
|
import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction } from '@dynamic-labs/ethereum-core';
|
|
7
|
-
import {
|
|
7
|
+
import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
8
|
+
import { eventListenerHandlers, getWalletProvider } from '@dynamic-labs/wallet-connector-core';
|
|
8
9
|
import { parseEvmNetworks, StorageService, DynamicError, DeferredPromise, parseChainId, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
9
10
|
import { AccountAbstractionBaseConnector } from '@dynamic-labs/ethereum-aa-core';
|
|
10
11
|
import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
|
|
@@ -14,6 +15,7 @@ import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
|
|
|
14
15
|
import { getEntryPoint } from './utils/getEntryPoint.js';
|
|
15
16
|
import { getKernelVersion } from './utils/getKernelVersion.js';
|
|
16
17
|
import { isEVMAuthorizationCapable } from './utils/isEVMAuthorizationCapable.js';
|
|
18
|
+
import { hasSmartAccount } from './utils/hasSmartAccount.js';
|
|
17
19
|
|
|
18
20
|
class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
19
21
|
constructor(opts) {
|
|
@@ -37,9 +39,15 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
37
39
|
},
|
|
38
40
|
name: 'ZeroDev',
|
|
39
41
|
};
|
|
42
|
+
this.hasExistingSmartAccount = false;
|
|
43
|
+
/**
|
|
44
|
+
* Flag for EIP-7702 mode, enabled when EIP-7702 is enabled and no smart account exists
|
|
45
|
+
*/
|
|
46
|
+
this.shouldUseEIP7702Mode = false;
|
|
40
47
|
this._walletUiUtils = opts.walletUiUtils;
|
|
41
48
|
this.providersConfig = (_a = opts.providersConfig) !== null && _a !== void 0 ? _a : {};
|
|
42
|
-
this.
|
|
49
|
+
this.is7702EnabledOnDashboard =
|
|
50
|
+
(_c = (_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.enableEIP7702) !== null && _c !== void 0 ? _c : false;
|
|
43
51
|
this.entryPoint = getEntryPoint((_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.entryPointVersion);
|
|
44
52
|
this.kernelVersion = getKernelVersion((_e = opts.apiProviders.zerodev) === null || _e === void 0 ? void 0 : _e.kernelVersion, this.entryPoint);
|
|
45
53
|
this.enableKernelV3Migration =
|
|
@@ -116,17 +124,22 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
116
124
|
});
|
|
117
125
|
}
|
|
118
126
|
initialize(_a) {
|
|
119
|
-
return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, }) {
|
|
127
|
+
return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, verifiedCredentials, }) {
|
|
120
128
|
yield this.registerEoa(Object.assign({ eoaAddress,
|
|
121
129
|
eoaConnector,
|
|
122
130
|
shouldSetEoaConnector,
|
|
123
|
-
smartWalletAddress
|
|
131
|
+
smartWalletAddress,
|
|
132
|
+
verifiedCredentials }, properties));
|
|
124
133
|
});
|
|
125
134
|
}
|
|
126
135
|
registerEoa(_a) {
|
|
127
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
var { smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false } = _a, properties = __rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "shouldSetEoaConnector"]);
|
|
129
|
-
if (
|
|
137
|
+
var { smartWalletAddress, eoaAddress, eoaConnector, verifiedCredentials, shouldSetEoaConnector = false } = _a, properties = __rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "verifiedCredentials", "shouldSetEoaConnector"]);
|
|
138
|
+
if (!eoaConnector) {
|
|
139
|
+
throw new DynamicError('No EOA connector');
|
|
140
|
+
}
|
|
141
|
+
this.determineSmartAccountStatus(eoaConnector, verifiedCredentials);
|
|
142
|
+
if (this.shouldUseEIP7702Mode) {
|
|
130
143
|
// In EIP-7702, addresses must match
|
|
131
144
|
if (smartWalletAddress !== eoaAddress) {
|
|
132
145
|
throw new Error('In EIP-7702 mode, smart wallet and EOA addresses must be the same');
|
|
@@ -154,6 +167,14 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
154
167
|
}
|
|
155
168
|
});
|
|
156
169
|
}
|
|
170
|
+
determineSmartAccountStatus(eoaConnector, verifiedCredentials) {
|
|
171
|
+
if (getWalletProvider(eoaConnector) !== WalletProviderEnum.EmbeddedWallet) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.hasExistingSmartAccount = hasSmartAccount(verifiedCredentials);
|
|
175
|
+
this.shouldUseEIP7702Mode =
|
|
176
|
+
this.is7702EnabledOnDashboard && !this.hasExistingSmartAccount;
|
|
177
|
+
}
|
|
157
178
|
getOrCreateAuthorization() {
|
|
158
179
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
180
|
var _a;
|
|
@@ -227,7 +248,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
227
248
|
}
|
|
228
249
|
const signer = yield this.eoaConnector.getSigner();
|
|
229
250
|
signer.account = toAccount(eoaAddress);
|
|
230
|
-
if (this.
|
|
251
|
+
if (this.shouldUseEIP7702Mode) {
|
|
231
252
|
this.authorization = yield this.getOrCreateAuthorization();
|
|
232
253
|
}
|
|
233
254
|
yield this.generateProviderMap(signer);
|
|
@@ -292,6 +313,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
292
313
|
}
|
|
293
314
|
createKernelClient(_a) {
|
|
294
315
|
return __awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, authorization, }) {
|
|
316
|
+
var _b;
|
|
295
317
|
if (chainId && this.providerMap[chainId]) {
|
|
296
318
|
return paymaster === 'SPONSOR'
|
|
297
319
|
? this.providerMap[chainId].kernelClientWithSponsorship
|
|
@@ -301,8 +323,10 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
301
323
|
if (!eoaConnector)
|
|
302
324
|
throw new DynamicError('No EOA connector');
|
|
303
325
|
const chain = chainsMap[chainId];
|
|
326
|
+
const network = this.evmNetworks.find((network) => network.chainId === parseChainId(chainId));
|
|
327
|
+
const publicClientRpc = (_b = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _b === void 0 ? void 0 : _b[0];
|
|
304
328
|
let kernelClient;
|
|
305
|
-
if (this.
|
|
329
|
+
if (this.shouldUseEIP7702Mode) {
|
|
306
330
|
kernelClient = yield createEcdsaKernelAccountClientWith7702({
|
|
307
331
|
authorization,
|
|
308
332
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
@@ -315,6 +339,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
315
339
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
316
340
|
projectId,
|
|
317
341
|
provider: ZeroDevConnector.bundlerProvider,
|
|
342
|
+
publicClientRpc,
|
|
318
343
|
signer,
|
|
319
344
|
});
|
|
320
345
|
}
|
|
@@ -330,6 +355,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
330
355
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
331
356
|
projectId,
|
|
332
357
|
provider: ZeroDevConnector.bundlerProvider,
|
|
358
|
+
publicClientRpc,
|
|
333
359
|
signer,
|
|
334
360
|
});
|
|
335
361
|
}
|
|
@@ -343,7 +369,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
343
369
|
getAddress() {
|
|
344
370
|
return __awaiter(this, void 0, void 0, function* () {
|
|
345
371
|
var _a, _b, _c;
|
|
346
|
-
if (this.
|
|
372
|
+
if (this.shouldUseEIP7702Mode) {
|
|
347
373
|
return this.eoaAddress;
|
|
348
374
|
}
|
|
349
375
|
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
@@ -564,7 +590,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
564
590
|
}
|
|
565
591
|
validateActiveWallet(expectedAddress) {
|
|
566
592
|
return __awaiter(this, void 0, void 0, function* () {
|
|
567
|
-
if (this.
|
|
593
|
+
if (this.shouldUseEIP7702Mode) {
|
|
568
594
|
const currentAddress = yield this.getAddress();
|
|
569
595
|
if (currentAddress !== expectedAddress) {
|
|
570
596
|
throw new DynamicError('Invalid active wallet');
|
|
@@ -26,10 +26,10 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
|
|
|
26
26
|
return rpc;
|
|
27
27
|
};
|
|
28
28
|
const isERC20 = (value) => viem.isAddress(value);
|
|
29
|
-
const createPublicAndPaymasterClients = (bundlerRpc, paymasterRpc, chain) => {
|
|
29
|
+
const createPublicAndPaymasterClients = (bundlerRpc, paymasterRpc, chain, publicClientRpc) => {
|
|
30
30
|
const publicClient = viem.createPublicClient({
|
|
31
31
|
chain,
|
|
32
|
-
transport: viem.http(bundlerRpc),
|
|
32
|
+
transport: publicClientRpc ? viem.http(publicClientRpc) : viem.http(bundlerRpc),
|
|
33
33
|
});
|
|
34
34
|
const zerodevPaymaster = clients.createZeroDevPaymasterClient({
|
|
35
35
|
chain,
|
|
@@ -65,10 +65,10 @@ const createKernelClientConfig = (account, bundlerRpc, chain, publicClient, paym
|
|
|
65
65
|
estimateFeesPerGas: (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ bundlerClient }) { return actions.getUserOperationGasPrice(bundlerClient); }),
|
|
66
66
|
},
|
|
67
67
|
});
|
|
68
|
-
const createEcdsaKernelAccountClient = (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator: ecdsaValidator$1, enableKernelV3Migration, }) {
|
|
68
|
+
const createEcdsaKernelAccountClient = (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator: ecdsaValidator$1, enableKernelV3Migration, publicClientRpc, }) {
|
|
69
69
|
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
70
70
|
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
71
|
-
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
|
|
71
|
+
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain, publicClientRpc);
|
|
72
72
|
const validator = yield ecdsaValidator$1(publicClient, {
|
|
73
73
|
entryPoint,
|
|
74
74
|
kernelVersion,
|
|
@@ -97,10 +97,10 @@ const createEcdsaKernelAccountClient = (_b) => _tslib.__awaiter(void 0, [_b], vo
|
|
|
97
97
|
const clientConfig = createKernelClientConfig(selectedAccount, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
98
98
|
return clients.createKernelAccountClient(clientConfig);
|
|
99
99
|
});
|
|
100
|
-
const createEcdsaKernelAccountClientWith7702 = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, }) {
|
|
100
|
+
const createEcdsaKernelAccountClientWith7702 = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, publicClientRpc, }) {
|
|
101
101
|
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
102
102
|
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
103
|
-
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
|
|
103
|
+
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain, publicClientRpc);
|
|
104
104
|
const validator = yield ecdsaValidator(publicClient, {
|
|
105
105
|
entryPoint,
|
|
106
106
|
kernelVersion,
|
|
@@ -21,9 +21,10 @@ type CommonClientParams<TChain extends Chain | undefined = Chain | undefined> =
|
|
|
21
21
|
kernelVersion: GetKernelVersion<EntryPointVersion>;
|
|
22
22
|
ecdsaValidator: any;
|
|
23
23
|
enableKernelV3Migration: boolean;
|
|
24
|
+
publicClientRpc?: string;
|
|
24
25
|
};
|
|
25
|
-
export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPointVersion, TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster, entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, }: CommonClientParams<TChain>) => Promise<KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>>;
|
|
26
|
-
export declare const createEcdsaKernelAccountClientWith7702: <TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster, entryPoint, kernelVersion, ecdsaValidator, }: CommonClientParams<TChain> & {
|
|
26
|
+
export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPointVersion, TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster, entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, publicClientRpc, }: CommonClientParams<TChain>) => Promise<KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>>;
|
|
27
|
+
export declare const createEcdsaKernelAccountClientWith7702: <TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster, entryPoint, kernelVersion, ecdsaValidator, publicClientRpc, }: CommonClientParams<TChain> & {
|
|
27
28
|
authorization?: SignAuthorizationReturnType;
|
|
28
29
|
}) => Promise<KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>>;
|
|
29
30
|
export {};
|
|
@@ -22,10 +22,10 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
|
|
|
22
22
|
return rpc;
|
|
23
23
|
};
|
|
24
24
|
const isERC20 = (value) => isAddress(value);
|
|
25
|
-
const createPublicAndPaymasterClients = (bundlerRpc, paymasterRpc, chain) => {
|
|
25
|
+
const createPublicAndPaymasterClients = (bundlerRpc, paymasterRpc, chain, publicClientRpc) => {
|
|
26
26
|
const publicClient = createPublicClient({
|
|
27
27
|
chain,
|
|
28
|
-
transport: http(bundlerRpc),
|
|
28
|
+
transport: publicClientRpc ? http(publicClientRpc) : http(bundlerRpc),
|
|
29
29
|
});
|
|
30
30
|
const zerodevPaymaster = createZeroDevPaymasterClient({
|
|
31
31
|
chain,
|
|
@@ -61,10 +61,10 @@ const createKernelClientConfig = (account, bundlerRpc, chain, publicClient, paym
|
|
|
61
61
|
estimateFeesPerGas: (_a) => __awaiter(void 0, [_a], void 0, function* ({ bundlerClient }) { return getUserOperationGasPrice(bundlerClient); }),
|
|
62
62
|
},
|
|
63
63
|
});
|
|
64
|
-
const createEcdsaKernelAccountClient = (_b) => __awaiter(void 0, [_b], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, }) {
|
|
64
|
+
const createEcdsaKernelAccountClient = (_b) => __awaiter(void 0, [_b], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, publicClientRpc, }) {
|
|
65
65
|
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
66
66
|
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
67
|
-
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
|
|
67
|
+
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain, publicClientRpc);
|
|
68
68
|
const validator = yield ecdsaValidator(publicClient, {
|
|
69
69
|
entryPoint,
|
|
70
70
|
kernelVersion,
|
|
@@ -93,10 +93,10 @@ const createEcdsaKernelAccountClient = (_b) => __awaiter(void 0, [_b], void 0, f
|
|
|
93
93
|
const clientConfig = createKernelClientConfig(selectedAccount, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
94
94
|
return createKernelAccountClient(clientConfig);
|
|
95
95
|
});
|
|
96
|
-
const createEcdsaKernelAccountClientWith7702 = (_c) => __awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, }) {
|
|
96
|
+
const createEcdsaKernelAccountClientWith7702 = (_c) => __awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, publicClientRpc, }) {
|
|
97
97
|
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
98
98
|
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
99
|
-
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
|
|
99
|
+
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain, publicClientRpc);
|
|
100
100
|
const validator = yield ecdsaValidator(publicClient, {
|
|
101
101
|
entryPoint,
|
|
102
102
|
kernelVersion,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const hasSmartAccount = (verifiedCredentials) => {
|
|
7
|
+
const embeddedWallet = verifiedCredentials.find((vc) => vc.walletProvider === 'embeddedWallet' &&
|
|
8
|
+
(vc.walletName === 'dynamicwaas' ||
|
|
9
|
+
vc.walletName === 'turnkey' ||
|
|
10
|
+
vc.walletName === 'turnkeyhd'));
|
|
11
|
+
if (!embeddedWallet)
|
|
12
|
+
return false;
|
|
13
|
+
const hasSmartContractWallet = verifiedCredentials.find((vc) => vc.walletProvider === 'smartContractWallet' &&
|
|
14
|
+
vc.signerRefId === embeddedWallet.id);
|
|
15
|
+
if (!hasSmartContractWallet)
|
|
16
|
+
return false;
|
|
17
|
+
return !hasSmartContractWallet.id.includes('zerodev');
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.hasSmartAccount = hasSmartAccount;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const hasSmartAccount = (verifiedCredentials) => {
|
|
3
|
+
const embeddedWallet = verifiedCredentials.find((vc) => vc.walletProvider === 'embeddedWallet' &&
|
|
4
|
+
(vc.walletName === 'dynamicwaas' ||
|
|
5
|
+
vc.walletName === 'turnkey' ||
|
|
6
|
+
vc.walletName === 'turnkeyhd'));
|
|
7
|
+
if (!embeddedWallet)
|
|
8
|
+
return false;
|
|
9
|
+
const hasSmartContractWallet = verifiedCredentials.find((vc) => vc.walletProvider === 'smartContractWallet' &&
|
|
10
|
+
vc.signerRefId === embeddedWallet.id);
|
|
11
|
+
if (!hasSmartContractWallet)
|
|
12
|
+
return false;
|
|
13
|
+
return !hasSmartContractWallet.id.includes('zerodev');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { hasSmartAccount };
|
package/src/utils/index.d.ts
CHANGED