@dynamic-labs/aleo 4.69.0 → 4.70.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 CHANGED
@@ -1,4 +1,25 @@
1
1
 
2
+ ## [4.70.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.69.0...v4.70.0) (2026-03-23)
3
+
4
+
5
+ ### Features
6
+
7
+ * add step-up auth for passkey and TOTP device deletion ([#10688](https://github.com/dynamic-labs/dynamic-auth/issues/10688)) ([aeae325](https://github.com/dynamic-labs/dynamic-auth/commit/aeae32551d3e29c59a1d183984f1d9f00f1df2cb))
8
+ * add stepup authMode to useSocialAuth for OAuth step-up authentication ([#10701](https://github.com/dynamic-labs/dynamic-auth/issues/10701)) ([f8ac0e4](https://github.com/dynamic-labs/dynamic-auth/commit/f8ac0e4a6a039e61d1c83e434e2f678981ff3911))
9
+ * add StepUpReauthSocialView and wire social option in step-up reauth UI ([#10703](https://github.com/dynamic-labs/dynamic-auth/issues/10703)) ([a49393f](https://github.com/dynamic-labs/dynamic-auth/commit/a49393f54a8f210f9cbca892339c3012d38cc5c2))
10
+ * add useStepUpSocial and extend step-up auth for OAuth reauthentication ([#10702](https://github.com/dynamic-labs/dynamic-auth/issues/10702)) ([fb7e21d](https://github.com/dynamic-labs/dynamic-auth/commit/fb7e21d47b3e40659ae3b8ca9321efe1d4401e60))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * aleo defaulting to testnet when connecting ([#10726](https://github.com/dynamic-labs/dynamic-auth/issues/10726)) ([24b0378](https://github.com/dynamic-labs/dynamic-auth/commit/24b0378a25902f5a134940aeeadc9846058d6fb1))
16
+ * override basic-ftp to >=5.2.0 (CVE-2026-27699) ([#10715](https://github.com/dynamic-labs/dynamic-auth/issues/10715)) ([b68a405](https://github.com/dynamic-labs/dynamic-auth/commit/b68a405453f0ea7e04c14492c195b46fbf25b47e))
17
+ * override minimatch to patched versions (CVE-2026-26996) ([#10718](https://github.com/dynamic-labs/dynamic-auth/issues/10718)) ([a69aaee](https://github.com/dynamic-labs/dynamic-auth/commit/a69aaee0859b7e1292a244abde7084f7c4cfdb72))
18
+ * override simple-git to >=3.32.3 (CVE-2026-28292) ([#10717](https://github.com/dynamic-labs/dynamic-auth/issues/10717)) ([8b86545](https://github.com/dynamic-labs/dynamic-auth/commit/8b865453737e4ff0ef9e8d0fbb99ea5f0359af3b))
19
+ * revert session chaining PR to fix IndexedDB webview crash ([#10710](https://github.com/dynamic-labs/dynamic-auth/issues/10710)) ([c4dfe66](https://github.com/dynamic-labs/dynamic-auth/commit/c4dfe66f73e6b9b7115260b06fd90fc0a167e139)), closes [#10706](https://github.com/dynamic-labs/dynamic-auth/issues/10706) [#10423](https://github.com/dynamic-labs/dynamic-auth/issues/10423) [#10423](https://github.com/dynamic-labs/dynamic-auth/issues/10423) [#10706](https://github.com/dynamic-labs/dynamic-auth/issues/10706) [#10423](https://github.com/dynamic-labs/dynamic-auth/issues/10423)
20
+ * update tar, serialize-javascript, svgo overrides ([#10727](https://github.com/dynamic-labs/dynamic-auth/issues/10727)) ([3c764f7](https://github.com/dynamic-labs/dynamic-auth/commit/3c764f71ce2870075eaa800389719a46d8dac233))
21
+ * upgrade rollup to patched versions (CVE-2026-27606) ([#10724](https://github.com/dynamic-labs/dynamic-auth/issues/10724)) ([735133e](https://github.com/dynamic-labs/dynamic-auth/commit/735133e6d4129cad20ae82b86f9507ab9227b36e))
22
+
2
23
  ## [4.69.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.68.0...v4.69.0) (2026-03-19)
3
24
 
4
25
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.69.0";
6
+ var version = "4.70.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.69.0";
2
+ var version = "4.70.0";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/aleo",
3
- "version": "4.69.0",
3
+ "version": "4.70.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",
@@ -18,15 +18,15 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/assert-package-version": "4.69.0",
21
+ "@dynamic-labs/assert-package-version": "4.70.0",
22
22
  "@provablehq/aleo-wallet-adaptor-core": "0.3.0-alpha.3",
23
23
  "@provablehq/aleo-wallet-adaptor-shield": "0.3.0-alpha.3",
24
24
  "@provablehq/aleo-wallet-standard": "0.3.0-alpha.3",
25
25
  "@provablehq/aleo-types": "0.3.0-alpha.3",
26
- "@dynamic-labs/types": "4.69.0",
27
- "@dynamic-labs/utils": "4.69.0",
28
- "@dynamic-labs/wallet-book": "4.69.0",
29
- "@dynamic-labs/wallet-connector-core": "4.69.0"
26
+ "@dynamic-labs/types": "4.70.0",
27
+ "@dynamic-labs/utils": "4.70.0",
28
+ "@dynamic-labs/wallet-book": "4.70.0",
29
+ "@dynamic-labs/wallet-connector-core": "4.70.0"
30
30
  },
31
31
  "peerDependencies": {}
32
32
  }
@@ -25,6 +25,10 @@ const adapterRegistry = {
25
25
  };
26
26
  const WALLET_NOT_CONNECTED = 'Wallet not connected';
27
27
  const MICROCREDITS_PER_CREDIT = 1000000;
28
+ const NETWORK_STORAGE_PRIORITY = {
29
+ priority: ['localStorage'],
30
+ };
31
+ const getAleoNetworkStorageKey = (overrideKey) => `dynamic_aleo_${overrideKey}_selected_chain_id`;
28
32
  /**
29
33
  * Connector for Aleo wallets that use a direct adapter interface rather than
30
34
  * the @provablehq/aleo-wallet-standard StandardWallet feature-map API.
@@ -38,6 +42,58 @@ const MICROCREDITS_PER_CREDIT = 1000000;
38
42
  * ```
39
43
  */
40
44
  class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector {
45
+ /**
46
+ * Resolved Aleo network for RPC/adapter calls: in-memory selection, then
47
+ * StorageService (localStorage first), then first configured aleo network.
48
+ */
49
+ get selectedNetwork() {
50
+ return this.getResolvedNetwork();
51
+ }
52
+ getNetworkStorageKey() {
53
+ return getAleoNetworkStorageKey(this.overrideKey);
54
+ }
55
+ isChainIdEnabled(chainId) {
56
+ return this.aleoNetworks.some((n) => Number(n.chainId) === chainId);
57
+ }
58
+ getResolvedNetwork() {
59
+ var _a, _b;
60
+ const networkForEnabledChainId = (chainId) => {
61
+ if (!this.isChainIdEnabled(chainId)) {
62
+ return undefined;
63
+ }
64
+ return getNetworkByChainId.getNetworkByChainId(chainId);
65
+ };
66
+ // In-memory chain (switchNetwork or adapter networkChange). Adapter-reported
67
+ // chains must match operations even when not in aleoNetworks; only persist
68
+ // when isChainIdEnabled (see switchNetwork / networkChange).
69
+ if (this.selectedChainId !== undefined) {
70
+ const fromMemory = getNetworkByChainId.getNetworkByChainId(this.selectedChainId);
71
+ if (fromMemory) {
72
+ return fromMemory;
73
+ }
74
+ this.selectedChainId = undefined;
75
+ }
76
+ const stored = utils.StorageService.getItem(this.getNetworkStorageKey(), NETWORK_STORAGE_PRIORITY);
77
+ if (stored !== null && stored !== undefined && stored !== '') {
78
+ const parsed = Number(stored);
79
+ if (!Number.isNaN(parsed)) {
80
+ const fromStorage = networkForEnabledChainId(parsed);
81
+ if (fromStorage) {
82
+ this.selectedChainId = parsed;
83
+ return fromStorage;
84
+ }
85
+ }
86
+ }
87
+ const fallbackChainId = Number((_b = (_a = this.aleoNetworks[0]) === null || _a === void 0 ? void 0 : _a.chainId) !== null && _b !== void 0 ? _b : -1);
88
+ return getNetworkByChainId.getNetworkByChainId(fallbackChainId) || aleoTypes.Network.MAINNET;
89
+ }
90
+ persistSelectedChainId(chainId) {
91
+ utils.StorageService.setItem(this.getNetworkStorageKey(), String(chainId), NETWORK_STORAGE_PRIORITY);
92
+ }
93
+ clearStoredNetworkSelection() {
94
+ utils.StorageService.removeItem(this.getNetworkStorageKey(), NETWORK_STORAGE_PRIORITY);
95
+ this.selectedChainId = undefined;
96
+ }
41
97
  /**
42
98
  * Register an adapter constructor for a given wallet key.
43
99
  * This is the primary extension point for non-standard wallets.
@@ -81,17 +137,16 @@ class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector
81
137
  const network = getNetworkByChainId.getNetworkByChainId(chainIdNum);
82
138
  if (network && this.adapter) {
83
139
  yield this.adapter.switchNetwork(network);
140
+ this.selectedChainId = chainIdNum;
141
+ this.persistSelectedChainId(chainIdNum);
84
142
  this.emit('chainChange', { chain: String(chainIdNum) });
85
143
  }
86
144
  });
87
145
  }
88
146
  getNetwork() {
89
147
  return _tslib.__awaiter(this, void 0, void 0, function* () {
90
- var _a;
91
- if (!((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network)) {
92
- return undefined;
93
- }
94
- const id = getNetworkByChainId.ALEO_NETWORK_TO_ID_MAP[this.adapter.network];
148
+ const network = this.selectedNetwork;
149
+ const id = getNetworkByChainId.ALEO_NETWORK_TO_ID_MAP[network];
95
150
  return id !== undefined ? String(id) : undefined;
96
151
  });
97
152
  }
@@ -100,7 +155,6 @@ class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector
100
155
  connect: { get: () => super.connect }
101
156
  });
102
157
  return _tslib.__awaiter(this, void 0, void 0, function* () {
103
- var _a, _b, _c;
104
158
  if (!this.adapter) {
105
159
  this.adapter = this.createAdapter();
106
160
  }
@@ -112,9 +166,7 @@ class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector
112
166
  return;
113
167
  }
114
168
  try {
115
- yield this.adapter.connect(((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network) ||
116
- getNetworkByChainId.getNetworkByChainId(Number((_c = (_b = this.aleoNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId) !== null && _c !== void 0 ? _c : -1)) ||
117
- aleoTypes.Network.MAINNET, aleoWalletStandard.WalletDecryptPermission.UponRequest);
169
+ yield this.adapter.connect(this.selectedNetwork, aleoWalletStandard.WalletDecryptPermission.UponRequest);
118
170
  }
119
171
  catch (error) {
120
172
  throw new utils.DynamicError(`Failed to connect to ${this.name}: ${error}`);
@@ -122,22 +174,20 @@ class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector
122
174
  });
123
175
  }
124
176
  getAddress() {
125
- const _super = Object.create(null, {
126
- getAddress: { get: () => super.getAddress }
127
- });
128
177
  return _tslib.__awaiter(this, void 0, void 0, function* () {
129
- var _a, _b, _c, _d;
178
+ var _a;
130
179
  if (!this.adapter) {
131
- return _super.getAddress.call(this);
180
+ this.adapter = this.createAdapter();
181
+ }
182
+ if (!this.adapter) {
183
+ throw new utils.DynamicError('No adapter found');
132
184
  }
133
185
  const { account } = this.adapter;
134
186
  if (account === null || account === void 0 ? void 0 : account.address) {
135
187
  return account.address;
136
188
  }
137
- const result = yield this.adapter.connect(((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network) ||
138
- getNetworkByChainId.getNetworkByChainId(Number((_c = (_b = this.aleoNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId) !== null && _c !== void 0 ? _c : -1)) ||
139
- aleoTypes.Network.MAINNET, aleoWalletStandard.WalletDecryptPermission.UponRequest);
140
- return (_d = result === null || result === void 0 ? void 0 : result.address) !== null && _d !== void 0 ? _d : '';
189
+ const result = yield this.adapter.connect(this.selectedNetwork, aleoWalletStandard.WalletDecryptPermission.UponRequest);
190
+ return (_a = result === null || result === void 0 ? void 0 : result.address) !== null && _a !== void 0 ? _a : '';
141
191
  });
142
192
  }
143
193
  getConnectedAccounts() {
@@ -176,7 +226,7 @@ class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector
176
226
  }
177
227
  getBalance(address) {
178
228
  return _tslib.__awaiter(this, void 0, void 0, function* () {
179
- var _a, _b;
229
+ var _a;
180
230
  if (!this.adapter) {
181
231
  return '0';
182
232
  }
@@ -187,7 +237,7 @@ class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector
187
237
  if (!resolvedAddress) {
188
238
  return '0';
189
239
  }
190
- const network = (_b = this.adapter.network) !== null && _b !== void 0 ? _b : aleoTypes.Network.MAINNET;
240
+ const network = this.selectedNetwork;
191
241
  let totalMicrocredits = BigInt(0);
192
242
  try {
193
243
  totalMicrocredits += yield fetchPublicBalance.fetchPublicBalance(resolvedAddress, network);
@@ -264,6 +314,7 @@ class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector
264
314
  endSession: { get: () => super.endSession }
265
315
  });
266
316
  return _tslib.__awaiter(this, void 0, void 0, function* () {
317
+ this.clearStoredNetworkSelection();
267
318
  if (!this.adapter) {
268
319
  return _super.endSession.call(this);
269
320
  }
@@ -291,10 +342,27 @@ class AleoWalletAdapterConnector extends AleoWalletConnector.AleoWalletConnector
291
342
  accounts: address ? [address] : [],
292
343
  });
293
344
  }));
294
- this.adapter.on('networkChange', (network) => {
345
+ this.adapter.on('networkChange', (networkFromEvent) => {
295
346
  var _a;
296
- const newNetwork = getNetworkByChainId.ALEO_NETWORK_TO_ID_MAP[network];
297
- this.emit('chainChange', { chain: (_a = newNetwork === null || newNetwork === void 0 ? void 0 : newNetwork.toString()) !== null && _a !== void 0 ? _a : '' });
347
+ const chainIdFromNetwork = (n) => n !== undefined ? getNetworkByChainId.ALEO_NETWORK_TO_ID_MAP[n] : undefined;
348
+ // Prefer the event payload; if it does not map (stale/unknown value), use
349
+ // adapter.network so we stay aligned with the wallet.
350
+ let chainId = chainIdFromNetwork(networkFromEvent);
351
+ if (chainId === undefined) {
352
+ chainId = chainIdFromNetwork((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network);
353
+ }
354
+ // Only emit chainChange when we can map the wallet network to a chain id and
355
+ // mirror that in selectedChainId. Emitting with an empty/mismatched chain
356
+ // while selectedNetwork still reflects the previous network breaks listeners
357
+ // and downstream connect()/getBalance() which use selectedNetwork.
358
+ if (chainId === undefined) {
359
+ return;
360
+ }
361
+ this.selectedChainId = chainId;
362
+ if (this.isChainIdEnabled(chainId)) {
363
+ this.persistSelectedChainId(chainId);
364
+ }
365
+ this.emit('chainChange', { chain: String(chainId) });
298
366
  });
299
367
  this.adapter.on('disconnect', () => {
300
368
  this.emit('disconnect');
@@ -1,4 +1,5 @@
1
1
  import { type BaseAleoWalletAdapter } from '@provablehq/aleo-wallet-adaptor-core';
2
+ import { Network } from '@provablehq/aleo-types';
2
3
  import { AleoWalletConnector, AleoWalletConnectorOpts } from '../AleoWalletConnector';
3
4
  import type { AleoTransaction } from '../../types';
4
5
  /**
@@ -24,6 +25,20 @@ export type AleoWalletAdapterConnectorOpts = AleoWalletConnectorOpts;
24
25
  */
25
26
  export declare abstract class AleoWalletAdapterConnector extends AleoWalletConnector {
26
27
  protected adapter: BaseAleoWalletAdapter | undefined;
28
+ /**
29
+ * In-memory selection (session). Mirrors StellarWalletConnector.selectedNetwork.
30
+ */
31
+ private selectedChainId;
32
+ /**
33
+ * Resolved Aleo network for RPC/adapter calls: in-memory selection, then
34
+ * StorageService (localStorage first), then first configured aleo network.
35
+ */
36
+ get selectedNetwork(): Network;
37
+ private getNetworkStorageKey;
38
+ private isChainIdEnabled;
39
+ private getResolvedNetwork;
40
+ private persistSelectedChainId;
41
+ private clearStoredNetworkSelection;
27
42
  /**
28
43
  * Register an adapter constructor for a given wallet key.
29
44
  * This is the primary extension point for non-standard wallets.
@@ -3,7 +3,7 @@ import { __awaiter } from '../../../_virtual/_tslib.js';
3
3
  import { WalletReadyState, WalletDecryptPermission } from '@provablehq/aleo-wallet-standard';
4
4
  import { ShieldWalletAdapter } from '@provablehq/aleo-wallet-adaptor-shield';
5
5
  import { Network } from '@provablehq/aleo-types';
6
- import { DynamicError } from '@dynamic-labs/utils';
6
+ import { StorageService, DynamicError } from '@dynamic-labs/utils';
7
7
  import { logger } from '@dynamic-labs/wallet-connector-core';
8
8
  import { getNetworkByChainId, ALEO_NETWORK_TO_ID_MAP } from '../../utils/getNetworkByChainId/getNetworkByChainId.js';
9
9
  import { fetchPrivateBalance } from '../../utils/fetchPrivateBalance/fetchPrivateBalance.js';
@@ -21,6 +21,10 @@ const adapterRegistry = {
21
21
  };
22
22
  const WALLET_NOT_CONNECTED = 'Wallet not connected';
23
23
  const MICROCREDITS_PER_CREDIT = 1000000;
24
+ const NETWORK_STORAGE_PRIORITY = {
25
+ priority: ['localStorage'],
26
+ };
27
+ const getAleoNetworkStorageKey = (overrideKey) => `dynamic_aleo_${overrideKey}_selected_chain_id`;
24
28
  /**
25
29
  * Connector for Aleo wallets that use a direct adapter interface rather than
26
30
  * the @provablehq/aleo-wallet-standard StandardWallet feature-map API.
@@ -34,6 +38,58 @@ const MICROCREDITS_PER_CREDIT = 1000000;
34
38
  * ```
35
39
  */
36
40
  class AleoWalletAdapterConnector extends AleoWalletConnector {
41
+ /**
42
+ * Resolved Aleo network for RPC/adapter calls: in-memory selection, then
43
+ * StorageService (localStorage first), then first configured aleo network.
44
+ */
45
+ get selectedNetwork() {
46
+ return this.getResolvedNetwork();
47
+ }
48
+ getNetworkStorageKey() {
49
+ return getAleoNetworkStorageKey(this.overrideKey);
50
+ }
51
+ isChainIdEnabled(chainId) {
52
+ return this.aleoNetworks.some((n) => Number(n.chainId) === chainId);
53
+ }
54
+ getResolvedNetwork() {
55
+ var _a, _b;
56
+ const networkForEnabledChainId = (chainId) => {
57
+ if (!this.isChainIdEnabled(chainId)) {
58
+ return undefined;
59
+ }
60
+ return getNetworkByChainId(chainId);
61
+ };
62
+ // In-memory chain (switchNetwork or adapter networkChange). Adapter-reported
63
+ // chains must match operations even when not in aleoNetworks; only persist
64
+ // when isChainIdEnabled (see switchNetwork / networkChange).
65
+ if (this.selectedChainId !== undefined) {
66
+ const fromMemory = getNetworkByChainId(this.selectedChainId);
67
+ if (fromMemory) {
68
+ return fromMemory;
69
+ }
70
+ this.selectedChainId = undefined;
71
+ }
72
+ const stored = StorageService.getItem(this.getNetworkStorageKey(), NETWORK_STORAGE_PRIORITY);
73
+ if (stored !== null && stored !== undefined && stored !== '') {
74
+ const parsed = Number(stored);
75
+ if (!Number.isNaN(parsed)) {
76
+ const fromStorage = networkForEnabledChainId(parsed);
77
+ if (fromStorage) {
78
+ this.selectedChainId = parsed;
79
+ return fromStorage;
80
+ }
81
+ }
82
+ }
83
+ const fallbackChainId = Number((_b = (_a = this.aleoNetworks[0]) === null || _a === void 0 ? void 0 : _a.chainId) !== null && _b !== void 0 ? _b : -1);
84
+ return getNetworkByChainId(fallbackChainId) || Network.MAINNET;
85
+ }
86
+ persistSelectedChainId(chainId) {
87
+ StorageService.setItem(this.getNetworkStorageKey(), String(chainId), NETWORK_STORAGE_PRIORITY);
88
+ }
89
+ clearStoredNetworkSelection() {
90
+ StorageService.removeItem(this.getNetworkStorageKey(), NETWORK_STORAGE_PRIORITY);
91
+ this.selectedChainId = undefined;
92
+ }
37
93
  /**
38
94
  * Register an adapter constructor for a given wallet key.
39
95
  * This is the primary extension point for non-standard wallets.
@@ -77,17 +133,16 @@ class AleoWalletAdapterConnector extends AleoWalletConnector {
77
133
  const network = getNetworkByChainId(chainIdNum);
78
134
  if (network && this.adapter) {
79
135
  yield this.adapter.switchNetwork(network);
136
+ this.selectedChainId = chainIdNum;
137
+ this.persistSelectedChainId(chainIdNum);
80
138
  this.emit('chainChange', { chain: String(chainIdNum) });
81
139
  }
82
140
  });
83
141
  }
84
142
  getNetwork() {
85
143
  return __awaiter(this, void 0, void 0, function* () {
86
- var _a;
87
- if (!((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network)) {
88
- return undefined;
89
- }
90
- const id = ALEO_NETWORK_TO_ID_MAP[this.adapter.network];
144
+ const network = this.selectedNetwork;
145
+ const id = ALEO_NETWORK_TO_ID_MAP[network];
91
146
  return id !== undefined ? String(id) : undefined;
92
147
  });
93
148
  }
@@ -96,7 +151,6 @@ class AleoWalletAdapterConnector extends AleoWalletConnector {
96
151
  connect: { get: () => super.connect }
97
152
  });
98
153
  return __awaiter(this, void 0, void 0, function* () {
99
- var _a, _b, _c;
100
154
  if (!this.adapter) {
101
155
  this.adapter = this.createAdapter();
102
156
  }
@@ -108,9 +162,7 @@ class AleoWalletAdapterConnector extends AleoWalletConnector {
108
162
  return;
109
163
  }
110
164
  try {
111
- yield this.adapter.connect(((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network) ||
112
- getNetworkByChainId(Number((_c = (_b = this.aleoNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId) !== null && _c !== void 0 ? _c : -1)) ||
113
- Network.MAINNET, WalletDecryptPermission.UponRequest);
165
+ yield this.adapter.connect(this.selectedNetwork, WalletDecryptPermission.UponRequest);
114
166
  }
115
167
  catch (error) {
116
168
  throw new DynamicError(`Failed to connect to ${this.name}: ${error}`);
@@ -118,22 +170,20 @@ class AleoWalletAdapterConnector extends AleoWalletConnector {
118
170
  });
119
171
  }
120
172
  getAddress() {
121
- const _super = Object.create(null, {
122
- getAddress: { get: () => super.getAddress }
123
- });
124
173
  return __awaiter(this, void 0, void 0, function* () {
125
- var _a, _b, _c, _d;
174
+ var _a;
126
175
  if (!this.adapter) {
127
- return _super.getAddress.call(this);
176
+ this.adapter = this.createAdapter();
177
+ }
178
+ if (!this.adapter) {
179
+ throw new DynamicError('No adapter found');
128
180
  }
129
181
  const { account } = this.adapter;
130
182
  if (account === null || account === void 0 ? void 0 : account.address) {
131
183
  return account.address;
132
184
  }
133
- const result = yield this.adapter.connect(((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network) ||
134
- getNetworkByChainId(Number((_c = (_b = this.aleoNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId) !== null && _c !== void 0 ? _c : -1)) ||
135
- Network.MAINNET, WalletDecryptPermission.UponRequest);
136
- return (_d = result === null || result === void 0 ? void 0 : result.address) !== null && _d !== void 0 ? _d : '';
185
+ const result = yield this.adapter.connect(this.selectedNetwork, WalletDecryptPermission.UponRequest);
186
+ return (_a = result === null || result === void 0 ? void 0 : result.address) !== null && _a !== void 0 ? _a : '';
137
187
  });
138
188
  }
139
189
  getConnectedAccounts() {
@@ -172,7 +222,7 @@ class AleoWalletAdapterConnector extends AleoWalletConnector {
172
222
  }
173
223
  getBalance(address) {
174
224
  return __awaiter(this, void 0, void 0, function* () {
175
- var _a, _b;
225
+ var _a;
176
226
  if (!this.adapter) {
177
227
  return '0';
178
228
  }
@@ -183,7 +233,7 @@ class AleoWalletAdapterConnector extends AleoWalletConnector {
183
233
  if (!resolvedAddress) {
184
234
  return '0';
185
235
  }
186
- const network = (_b = this.adapter.network) !== null && _b !== void 0 ? _b : Network.MAINNET;
236
+ const network = this.selectedNetwork;
187
237
  let totalMicrocredits = BigInt(0);
188
238
  try {
189
239
  totalMicrocredits += yield fetchPublicBalance(resolvedAddress, network);
@@ -260,6 +310,7 @@ class AleoWalletAdapterConnector extends AleoWalletConnector {
260
310
  endSession: { get: () => super.endSession }
261
311
  });
262
312
  return __awaiter(this, void 0, void 0, function* () {
313
+ this.clearStoredNetworkSelection();
263
314
  if (!this.adapter) {
264
315
  return _super.endSession.call(this);
265
316
  }
@@ -287,10 +338,27 @@ class AleoWalletAdapterConnector extends AleoWalletConnector {
287
338
  accounts: address ? [address] : [],
288
339
  });
289
340
  }));
290
- this.adapter.on('networkChange', (network) => {
341
+ this.adapter.on('networkChange', (networkFromEvent) => {
291
342
  var _a;
292
- const newNetwork = ALEO_NETWORK_TO_ID_MAP[network];
293
- this.emit('chainChange', { chain: (_a = newNetwork === null || newNetwork === void 0 ? void 0 : newNetwork.toString()) !== null && _a !== void 0 ? _a : '' });
343
+ const chainIdFromNetwork = (n) => n !== undefined ? ALEO_NETWORK_TO_ID_MAP[n] : undefined;
344
+ // Prefer the event payload; if it does not map (stale/unknown value), use
345
+ // adapter.network so we stay aligned with the wallet.
346
+ let chainId = chainIdFromNetwork(networkFromEvent);
347
+ if (chainId === undefined) {
348
+ chainId = chainIdFromNetwork((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.network);
349
+ }
350
+ // Only emit chainChange when we can map the wallet network to a chain id and
351
+ // mirror that in selectedChainId. Emitting with an empty/mismatched chain
352
+ // while selectedNetwork still reflects the previous network breaks listeners
353
+ // and downstream connect()/getBalance() which use selectedNetwork.
354
+ if (chainId === undefined) {
355
+ return;
356
+ }
357
+ this.selectedChainId = chainId;
358
+ if (this.isChainIdEnabled(chainId)) {
359
+ this.persistSelectedChainId(chainId);
360
+ }
361
+ this.emit('chainChange', { chain: String(chainId) });
294
362
  });
295
363
  this.adapter.on('disconnect', () => {
296
364
  this.emit('disconnect');