@dynamic-labs/ethereum-aa 3.4.2 → 3.4.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/CHANGELOG.md CHANGED
@@ -1,4 +1,18 @@
1
1
 
2
+ ### [3.4.4](https://github.com/dynamic-labs/DynamicAuth/compare/v3.4.3...v3.4.4) (2024-10-24)
3
+
4
+ ### [3.4.3](https://github.com/dynamic-labs/DynamicAuth/compare/v3.4.2...v3.4.3) (2024-10-23)
5
+
6
+
7
+ ### Features
8
+
9
+ * add mobile wallet redirect view ([#7168](https://github.com/dynamic-labs/DynamicAuth/issues/7168)) ([#7194](https://github.com/dynamic-labs/DynamicAuth/issues/7194)) ([1d25423](https://github.com/dynamic-labs/DynamicAuth/commit/1d254236e8609847e9ad8a390593ce7741fc10a6))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * sdkHasLoaded should check if primaryWallet has finished loading ([#7193](https://github.com/dynamic-labs/DynamicAuth/issues/7193)) ([1b9a0de](https://github.com/dynamic-labs/DynamicAuth/commit/1b9a0de0e279804f808f36a4945a8b2500cc2b7a))
15
+
2
16
  ### [3.4.2](https://github.com/dynamic-labs/DynamicAuth/compare/v3.4.1...v3.4.2) (2024-10-18)
3
17
 
4
18
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "3.4.2";
6
+ var version = "3.4.4";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "3.4.2";
2
+ var version = "3.4.4";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum-aa",
3
- "version": "3.4.2",
3
+ "version": "3.4.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
@@ -31,13 +31,13 @@
31
31
  "@zerodev/multi-chain-validator": "5.3.3",
32
32
  "@zerodev/sdk": "5.3.4",
33
33
  "permissionless": "^0.1.20",
34
- "@dynamic-labs/assert-package-version": "3.4.2",
35
- "@dynamic-labs/ethereum-core": "3.4.2",
36
- "@dynamic-labs/logger": "3.4.2",
37
- "@dynamic-labs/types": "3.4.2",
38
- "@dynamic-labs/utils": "3.4.2",
39
- "@dynamic-labs/wallet-book": "3.4.2",
40
- "@dynamic-labs/wallet-connector-core": "3.4.2"
34
+ "@dynamic-labs/assert-package-version": "3.4.4",
35
+ "@dynamic-labs/ethereum-core": "3.4.4",
36
+ "@dynamic-labs/logger": "3.4.4",
37
+ "@dynamic-labs/types": "3.4.4",
38
+ "@dynamic-labs/utils": "3.4.4",
39
+ "@dynamic-labs/wallet-book": "3.4.4",
40
+ "@dynamic-labs/wallet-connector-core": "3.4.4"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "viem": "^2.7.6"
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../_virtual/_tslib.cjs');
7
7
  var viem = require('viem');
8
+ var accounts = require('viem/accounts');
8
9
  var utils$1 = require('permissionless/utils');
9
10
  var ethereumCore = require('@dynamic-labs/ethereum-core');
10
11
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
@@ -20,7 +21,10 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
20
21
  constructor(opts) {
21
22
  var _a, _b, _c, _d;
22
23
  super(opts);
24
+ // provider map maintains the kernel clients per chain
23
25
  this.providerMap = {};
26
+ // eoa connector map maintains the eoa address and connector for each smart wallet address
27
+ this.eoaConnectorMap = {};
24
28
  this.ChainWallet = ethereumCore.EthereumWallet;
25
29
  this.connectedChain = 'EVM';
26
30
  this.supportedChains = ['ETH', 'EVM'];
@@ -113,7 +117,19 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
113
117
  utils.StorageService.removeItem(constants.ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
114
118
  });
115
119
  }
116
- setEoaConnector(connector) {
120
+ registerEoa(_a) {
121
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false, }) {
122
+ this.eoaConnectorMap[smartWalletAddress] = {
123
+ eoaAddress,
124
+ eoaConnector,
125
+ };
126
+ // if this is the primary wallet, set the eoa connector and kernel clients
127
+ if (shouldSetEoaConnector && this.eoaAddress !== eoaAddress) {
128
+ yield this.setEoaConnector(eoaAddress, eoaConnector);
129
+ }
130
+ });
131
+ }
132
+ setEoaConnector(eoaAddress, connector) {
117
133
  return _tslib.__awaiter(this, void 0, void 0, function* () {
118
134
  if (!connector) {
119
135
  logger.logger.error('No EOA connector provided');
@@ -121,15 +137,13 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
121
137
  }
122
138
  this.kernelClientDeferredPromise = new utils.DeferredPromise();
123
139
  this.eoaConnector = connector;
140
+ this.eoaAddress = eoaAddress;
124
141
  if (ethereumCore.isEthWalletConnector(this.eoaConnector) &&
125
142
  !this.eoaConnector.getActiveAccount()) {
126
143
  yield this.eoaConnector.getConnectedAccounts();
127
144
  }
128
145
  const signer = yield this.eoaConnector.getSigner();
129
- if (!(signer === null || signer === void 0 ? void 0 : signer.account)) {
130
- logger.logger.error('No signer account found');
131
- return;
132
- }
146
+ signer.account = accounts.toAccount(eoaAddress);
133
147
  yield this.generateProviderMap(signer);
134
148
  this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
135
149
  this.kernelClientDeferredPromise.resolve();
@@ -151,6 +165,8 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
151
165
  }
152
166
  generateProviderMap(signer) {
153
167
  return _tslib.__awaiter(this, void 0, void 0, function* () {
168
+ // reset the chains provider map when eoa connector changes
169
+ this.providerMap = {};
154
170
  for (const provider of this.providersFromApi) {
155
171
  if (!this.providerMap[provider.chain]) {
156
172
  this.providerMap[provider.chain] = {
@@ -394,23 +410,14 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
394
410
  });
395
411
  }
396
412
  validateActiveWallet(expectedAddress) {
397
- const _super = Object.create(null, {
398
- validateActiveWallet: { get: () => super.validateActiveWallet }
399
- });
400
413
  return _tslib.__awaiter(this, void 0, void 0, function* () {
401
- var _a;
402
- const eoaConnector = this === null || this === void 0 ? void 0 : this.eoaConnector;
403
- if (eoaConnector && walletConnectorCore.isTurnkeyWalletConnector(eoaConnector)) {
404
- const verifiedCredentials = eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.verifiedCredentials;
405
- const expectedEoaAddress = (_a = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find((vc) => vc.smartWalletRefAddress === expectedAddress)) === null || _a === void 0 ? void 0 : _a.address;
406
- if (!expectedEoaAddress) {
407
- throw new utils.DynamicError('No EOA connector');
408
- }
409
- yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.validateActiveWallet(expectedEoaAddress));
410
- }
411
- else {
412
- yield _super.validateActiveWallet.call(this, expectedAddress);
414
+ const eoa = this.eoaConnectorMap[expectedAddress];
415
+ if (!eoa) {
416
+ throw new utils.DynamicError('No EOA connector');
413
417
  }
418
+ const { eoaAddress, eoaConnector } = eoa;
419
+ yield eoaConnector.validateActiveWallet(eoaAddress);
420
+ yield this.setEoaConnector(eoaAddress, eoaConnector);
414
421
  });
415
422
  }
416
423
  }
@@ -24,7 +24,9 @@ type KernelClient = KernelAccountClient<EntryPoint, Transport, ViemChain, Kernel
24
24
  export declare class ZeroDevConnector extends WalletConnectorBase<typeof EthereumWallet> implements IZeroDevConnector {
25
25
  clientId: string;
26
26
  eoaConnector: InternalWalletConnector | undefined;
27
+ eoaAddress: string | undefined;
27
28
  private providerMap;
29
+ private eoaConnectorMap;
28
30
  ChainWallet: typeof EthereumWallet;
29
31
  connectedChain: Chain;
30
32
  supportedChains: Chain[];
@@ -76,7 +78,13 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
76
78
  withSponsorship?: boolean;
77
79
  }): KernelClient | undefined;
78
80
  endSession(): Promise<void>;
79
- setEoaConnector(connector: InternalWalletConnector): Promise<void>;
81
+ registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, }: {
82
+ smartWalletAddress: string;
83
+ eoaAddress: string;
84
+ eoaConnector: InternalWalletConnector;
85
+ shouldSetEoaConnector: boolean;
86
+ }): Promise<void>;
87
+ private setEoaConnector;
80
88
  private warnIfProjectChainNotEnabled;
81
89
  private generateProviderMap;
82
90
  private getKernelClientWithoutSponsorshipValidation;
@@ -1,9 +1,10 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../_virtual/_tslib.js';
3
3
  import { publicActions, custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
4
+ import { toAccount } from 'viem/accounts';
4
5
  import { walletClientToSmartAccountSigner } from 'permissionless/utils';
5
6
  import { EthereumWallet, confirmationTransport, chainsMap, isEthWalletConnector, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
6
- import { WalletConnectorBase, eventListenerHandlers, isTurnkeyWalletConnector } from '@dynamic-labs/wallet-connector-core';
7
+ import { WalletConnectorBase, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
7
8
  import { parseEvmNetworks, StorageService, DeferredPromise, parseChainId, DynamicError, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
8
9
  import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
9
10
  import { logger } from './utils/logger.js';
@@ -16,7 +17,10 @@ class ZeroDevConnector extends WalletConnectorBase {
16
17
  constructor(opts) {
17
18
  var _a, _b, _c, _d;
18
19
  super(opts);
20
+ // provider map maintains the kernel clients per chain
19
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'];
@@ -109,7 +113,19 @@ class ZeroDevConnector extends WalletConnectorBase {
109
113
  StorageService.removeItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
110
114
  });
111
115
  }
112
- setEoaConnector(connector) {
116
+ registerEoa(_a) {
117
+ return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false, }) {
118
+ this.eoaConnectorMap[smartWalletAddress] = {
119
+ eoaAddress,
120
+ eoaConnector,
121
+ };
122
+ // if this is the primary wallet, set the eoa connector and kernel clients
123
+ if (shouldSetEoaConnector && this.eoaAddress !== eoaAddress) {
124
+ yield this.setEoaConnector(eoaAddress, eoaConnector);
125
+ }
126
+ });
127
+ }
128
+ setEoaConnector(eoaAddress, connector) {
113
129
  return __awaiter(this, void 0, void 0, function* () {
114
130
  if (!connector) {
115
131
  logger.error('No EOA connector provided');
@@ -117,15 +133,13 @@ class ZeroDevConnector extends WalletConnectorBase {
117
133
  }
118
134
  this.kernelClientDeferredPromise = new DeferredPromise();
119
135
  this.eoaConnector = connector;
136
+ this.eoaAddress = eoaAddress;
120
137
  if (isEthWalletConnector(this.eoaConnector) &&
121
138
  !this.eoaConnector.getActiveAccount()) {
122
139
  yield this.eoaConnector.getConnectedAccounts();
123
140
  }
124
141
  const signer = yield this.eoaConnector.getSigner();
125
- if (!(signer === null || signer === void 0 ? void 0 : signer.account)) {
126
- logger.error('No signer account found');
127
- return;
128
- }
142
+ signer.account = toAccount(eoaAddress);
129
143
  yield this.generateProviderMap(signer);
130
144
  this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
131
145
  this.kernelClientDeferredPromise.resolve();
@@ -147,6 +161,8 @@ class ZeroDevConnector extends WalletConnectorBase {
147
161
  }
148
162
  generateProviderMap(signer) {
149
163
  return __awaiter(this, void 0, void 0, function* () {
164
+ // reset the chains provider map when eoa connector changes
165
+ this.providerMap = {};
150
166
  for (const provider of this.providersFromApi) {
151
167
  if (!this.providerMap[provider.chain]) {
152
168
  this.providerMap[provider.chain] = {
@@ -390,23 +406,14 @@ class ZeroDevConnector extends WalletConnectorBase {
390
406
  });
391
407
  }
392
408
  validateActiveWallet(expectedAddress) {
393
- const _super = Object.create(null, {
394
- validateActiveWallet: { get: () => super.validateActiveWallet }
395
- });
396
409
  return __awaiter(this, void 0, void 0, function* () {
397
- var _a;
398
- const eoaConnector = this === null || this === void 0 ? void 0 : this.eoaConnector;
399
- if (eoaConnector && isTurnkeyWalletConnector(eoaConnector)) {
400
- const verifiedCredentials = eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.verifiedCredentials;
401
- const expectedEoaAddress = (_a = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find((vc) => vc.smartWalletRefAddress === expectedAddress)) === null || _a === void 0 ? void 0 : _a.address;
402
- if (!expectedEoaAddress) {
403
- throw new DynamicError('No EOA connector');
404
- }
405
- yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.validateActiveWallet(expectedEoaAddress));
406
- }
407
- else {
408
- yield _super.validateActiveWallet.call(this, expectedAddress);
410
+ const eoa = this.eoaConnectorMap[expectedAddress];
411
+ if (!eoa) {
412
+ throw new DynamicError('No EOA connector');
409
413
  }
414
+ const { eoaAddress, eoaConnector } = eoa;
415
+ yield eoaConnector.validateActiveWallet(eoaAddress);
416
+ yield this.setEoaConnector(eoaAddress, eoaConnector);
410
417
  });
411
418
  }
412
419
  }