@dynamic-labs/wallet-connector-core 3.0.0-alpha.13 → 3.0.0-alpha.15

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,50 @@
1
1
 
2
+ ## [3.0.0-alpha.15](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.14...v3.0.0-alpha.15) (2024-07-11)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * catch third party wallet construction errors ([#6268](https://github.com/dynamic-labs/DynamicAuth/issues/6268)) ([badef39](https://github.com/dynamic-labs/DynamicAuth/commit/badef39d753c7d29925c6c8680053027bd99b69b))
8
+ * decode all solana transactions ([#6294](https://github.com/dynamic-labs/DynamicAuth/issues/6294)) ([5220ab2](https://github.com/dynamic-labs/DynamicAuth/commit/5220ab29381f3a7f1afc7043332b5a018b47eb0a))
9
+ * passkey cta ([#6255](https://github.com/dynamic-labs/DynamicAuth/issues/6255)) ([1b1b152](https://github.com/dynamic-labs/DynamicAuth/commit/1b1b152a24b409c5d941a9c92a003daf0bbe48a1))
10
+
11
+ ## [3.0.0-alpha.14](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.13...v3.0.0-alpha.14) (2024-07-09)
12
+
13
+
14
+ ### ⚠ BREAKING CHANGES
15
+
16
+ * remove setPrimaryWallet in favor of useSwitchWallet (#6212)
17
+ * move getBalance method to wallet so it can be fetched for any wallet not just the active one (#6200)
18
+ * make Wallet a class instead of just a type (#6094)
19
+
20
+ ### Features
21
+
22
+ * add @dynamic-labs/solana-extension ([#6140](https://github.com/dynamic-labs/DynamicAuth/issues/6140)) ([c0e2a06](https://github.com/dynamic-labs/DynamicAuth/commit/c0e2a067dd83163094b58a15696df8654da47c65))
23
+ * add solana support for multi-asset ([#6222](https://github.com/dynamic-labs/DynamicAuth/issues/6222)) ([9660d79](https://github.com/dynamic-labs/DynamicAuth/commit/9660d7962f1fb01011d68397bb367fdfc5335ca9))
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * allow closing re-connect wallet modal ([#6250](https://github.com/dynamic-labs/DynamicAuth/issues/6250)) ([55ba25b](https://github.com/dynamic-labs/DynamicAuth/commit/55ba25bd3e907629aaa26e788885bfa38f8fe350))
29
+ * move getBalance method to wallet so it can be fetched for any wallet not just the active one ([#6200](https://github.com/dynamic-labs/DynamicAuth/issues/6200)) ([ee94773](https://github.com/dynamic-labs/DynamicAuth/commit/ee94773df9b31462a325666760fcf1fc70dec68a))
30
+ * move getNameService method to wallet so name service data can be fetched for any wallet ([#6205](https://github.com/dynamic-labs/DynamicAuth/issues/6205)) ([6671ae9](https://github.com/dynamic-labs/DynamicAuth/commit/6671ae92532ffc1889e24519e75f47d336ac0da6))
31
+ * relax phone number length validation ([#6226](https://github.com/dynamic-labs/DynamicAuth/issues/6226)) ([f0969b4](https://github.com/dynamic-labs/DynamicAuth/commit/f0969b4fbdafde07125cddecb16b4bfd011ea65e))
32
+ * sdkHasLoaded flipping back to false with otp ([#6242](https://github.com/dynamic-labs/DynamicAuth/issues/6242)) ([32ad9dd](https://github.com/dynamic-labs/DynamicAuth/commit/32ad9dd2dae7775f494506773fb343fe1a249c65))
33
+ * send transaction demo undefined address/value ([#6248](https://github.com/dynamic-labs/DynamicAuth/issues/6248)) ([036a511](https://github.com/dynamic-labs/DynamicAuth/commit/036a511fb848ef461edd9b7a5d79d478b0f1cf23))
34
+ * set last active account on accountChange request ([#6218](https://github.com/dynamic-labs/DynamicAuth/issues/6218)) ([05797d2](https://github.com/dynamic-labs/DynamicAuth/commit/05797d292aab8b4de02555594d4d1bbd4c9543eb))
35
+ * show ledger toggle when linking wallet ([#6202](https://github.com/dynamic-labs/DynamicAuth/issues/6202)) ([a449c0b](https://github.com/dynamic-labs/DynamicAuth/commit/a449c0bfc4e3a75ccd7084b930c48fbd6c14f691))
36
+ * show user wallet in profile view on single wallet mode even if it's not primary ([#6187](https://github.com/dynamic-labs/DynamicAuth/issues/6187)) ([ffaaeb2](https://github.com/dynamic-labs/DynamicAuth/commit/ffaaeb2c6cbb2868a381d85451ae5574024156bb))
37
+ * stop auto-switching to connected secondary wallet if primary wallet is not connected ([#6196](https://github.com/dynamic-labs/DynamicAuth/issues/6196)) ([4e8bcd2](https://github.com/dynamic-labs/DynamicAuth/commit/4e8bcd2d02d3fca54a0ed29c45b386ae99266b84))
38
+ * stop coinbase and solflare popups when secondary ([#6225](https://github.com/dynamic-labs/DynamicAuth/issues/6225)) ([7e9c104](https://github.com/dynamic-labs/DynamicAuth/commit/7e9c1049a09c9fd513c9a2a746d6baac916f1bf4))
39
+ * stop sending double sign request on network switch ([e325709](https://github.com/dynamic-labs/DynamicAuth/commit/e325709bb5d2d1331fe16cc705398fc7b1cc292a))
40
+ * tunrkey solana signer accept uint8array message ([#6137](https://github.com/dynamic-labs/DynamicAuth/issues/6137)) ([70f89ce](https://github.com/dynamic-labs/DynamicAuth/commit/70f89ce0dafa4c99b318c9c5adce59083cd6d284))
41
+ * update formatting of phantom bitcoin publickey ([#6210](https://github.com/dynamic-labs/DynamicAuth/issues/6210)) ([f58cea9](https://github.com/dynamic-labs/DynamicAuth/commit/f58cea99333fd7c6af8f56f637ee32f1f7ce8d76))
42
+ * use white color in farcaster qr code when in dark mode ([#6245](https://github.com/dynamic-labs/DynamicAuth/issues/6245)) ([a91958d](https://github.com/dynamic-labs/DynamicAuth/commit/a91958d8773be138da8f54791c4c67866257bbad))
43
+
44
+
45
+ * make Wallet a class instead of just a type ([#6094](https://github.com/dynamic-labs/DynamicAuth/issues/6094)) ([6dc4672](https://github.com/dynamic-labs/DynamicAuth/commit/6dc4672951cfadc22a6c569e74eae3485bd472f3))
46
+ * remove setPrimaryWallet in favor of useSwitchWallet ([#6212](https://github.com/dynamic-labs/DynamicAuth/issues/6212)) ([de125e1](https://github.com/dynamic-labs/DynamicAuth/commit/de125e1ebbc20507e4ec07f337f5f5fd13aabcbe))
47
+
2
48
  ## [3.0.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.12...v3.0.0-alpha.13) (2024-06-27)
3
49
 
4
50
 
@@ -18,6 +18,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
18
  PERFORMANCE OF THIS SOFTWARE.
19
19
  ***************************************************************************** */
20
20
 
21
+ function __rest(s, e) {
22
+ var t = {};
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
24
+ t[p] = s[p];
25
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
26
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
27
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
28
+ t[p[i]] = s[p[i]];
29
+ }
30
+ return t;
31
+ }
32
+
21
33
  function __awaiter(thisArg, _arguments, P, generator) {
22
34
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
35
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,6 +46,13 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
34
46
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
47
  }
36
48
 
49
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
50
+ if (kind === "m") throw new TypeError("Private method is not writable");
51
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
52
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
53
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
54
+ }
55
+
37
56
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
38
57
  var e = new Error(message);
39
58
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -41,3 +60,5 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
41
60
 
42
61
  exports.__awaiter = __awaiter;
43
62
  exports.__classPrivateFieldGet = __classPrivateFieldGet;
63
+ exports.__classPrivateFieldSet = __classPrivateFieldSet;
64
+ exports.__rest = __rest;
@@ -14,6 +14,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
15
  ***************************************************************************** */
16
16
 
17
+ function __rest(s, e) {
18
+ var t = {};
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
20
+ t[p] = s[p];
21
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
22
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
23
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
24
+ t[p[i]] = s[p[i]];
25
+ }
26
+ return t;
27
+ }
28
+
17
29
  function __awaiter(thisArg, _arguments, P, generator) {
18
30
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
31
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -30,9 +42,16 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
30
42
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
31
43
  }
32
44
 
45
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
46
+ if (kind === "m") throw new TypeError("Private method is not writable");
47
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
48
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
49
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
50
+ }
51
+
33
52
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
34
53
  var e = new Error(message);
35
54
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
36
55
  };
37
56
 
38
- export { __awaiter, __classPrivateFieldGet };
57
+ export { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet, __rest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/wallet-connector-core",
3
- "version": "3.0.0-alpha.13",
3
+ "version": "3.0.0-alpha.15",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
@@ -29,11 +29,11 @@
29
29
  "@dynamic-labs/sdk-api-core": "0.0.470"
30
30
  },
31
31
  "peerDependencies": {
32
- "@dynamic-labs/logger": "3.0.0-alpha.13",
33
- "@dynamic-labs/rpc-providers": "3.0.0-alpha.13",
34
- "@dynamic-labs/types": "3.0.0-alpha.13",
35
- "@dynamic-labs/utils": "3.0.0-alpha.13",
36
- "@dynamic-labs/wallet-book": "3.0.0-alpha.13",
32
+ "@dynamic-labs/logger": "3.0.0-alpha.15",
33
+ "@dynamic-labs/rpc-providers": "3.0.0-alpha.15",
34
+ "@dynamic-labs/types": "3.0.0-alpha.15",
35
+ "@dynamic-labs/utils": "3.0.0-alpha.15",
36
+ "@dynamic-labs/wallet-book": "3.0.0-alpha.15",
37
37
  "eventemitter3": "5.0.1"
38
38
  }
39
39
  }
package/src/index.cjs CHANGED
@@ -4,6 +4,7 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var WalletConnector = require('./lib/WalletConnector.cjs');
7
+ var Wallet = require('./lib/wallets/Wallet/Wallet.cjs');
7
8
  var logger = require('./utils/logger.cjs');
8
9
  var ProviderLookup = require('./utils/ProviderLookup/ProviderLookup.cjs');
9
10
  var getChainInfo = require('./utils/getChainInfo/getChainInfo.cjs');
@@ -38,6 +39,7 @@ var isSessionKeyCompatibleWalletConnector = require('./utils/isSessionKeyCompati
38
39
  exports.Chains = WalletConnector.Chains;
39
40
  exports.WalletConnectorBase = WalletConnector.WalletConnectorBase;
40
41
  exports.socialProviders = WalletConnector.socialProviders;
42
+ exports.Wallet = Wallet.Wallet;
41
43
  exports.logger = logger.logger;
42
44
  exports.ProviderLookup = ProviderLookup.ProviderLookup;
43
45
  exports.getChainInfo = getChainInfo.getChainInfo;
package/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use client'
2
2
  export { Chains, WalletConnectorBase, socialProviders } from './lib/WalletConnector.js';
3
+ export { Wallet } from './lib/wallets/Wallet/Wallet.js';
3
4
  export { logger } from './utils/logger.js';
4
5
  export { ProviderLookup } from './utils/ProviderLookup/ProviderLookup.js';
5
6
  export { getChainInfo } from './utils/getChainInfo/getChainInfo.js';
@@ -7,9 +7,13 @@ export interface ISessionKeyCompatibleWalletConnector extends WalletConnectorBas
7
7
  isSessionKeyCompatible(): boolean;
8
8
  isSessionActive(): Promise<boolean>;
9
9
  sessionKeys?: SessionKeys;
10
- setSessionKeyFetcher(fetcher: () => Promise<SessionKeys>): void;
10
+ setSessionKeyFetcher(fetcher: ({ ignoreRestore, }: {
11
+ ignoreRestore?: boolean;
12
+ }) => Promise<SessionKeys>): void;
11
13
  setSessionKeyRemoveFunction(fetcher: () => void): void;
12
- createOrRestoreSession(): Promise<string | undefined>;
14
+ createOrRestoreSession({ ignoreRestore, }?: {
15
+ ignoreRestore?: boolean;
16
+ }): Promise<string | undefined>;
13
17
  removeSessionKeys: (() => Promise<void>) | undefined;
14
18
  }
15
19
  export {};
@@ -6,6 +6,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var _tslib = require('../../_virtual/_tslib.cjs');
7
7
  var EventEmitter = require('eventemitter3');
8
8
  var walletBook = require('@dynamic-labs/wallet-book');
9
+ var utils = require('@dynamic-labs/utils');
10
+ var logger = require('../utils/logger.cjs');
9
11
  var WalletBookSingleton = require('./WalletBookSingleton.cjs');
10
12
 
11
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -76,22 +78,6 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
76
78
  * @default false
77
79
  */
78
80
  this.canConnectViaSocial = false;
79
- /**
80
- * @deprecated getWeb3Provider has been renamed to getWalletClient
81
- * If you would like to still get the ethers web3Provider,
82
- * see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
83
- *
84
- * Get the wallet provider
85
- */
86
- this.getWeb3Provider = this.getWalletClient;
87
- /**
88
- * @deprecated getRpcProvider has been renamed to getPublicClient
89
- * If you would like to still get the ethers rpcProvider,
90
- * see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
91
- *
92
- * Get the rpc provider
93
- */
94
- this.getRpcProvider = this.getPublicClient;
95
81
  /**
96
82
  * Flag if connector/provider is available
97
83
  *
@@ -228,7 +214,7 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
228
214
  *
229
215
  * @default Promise<undefined>
230
216
  */
231
- getBalance() {
217
+ getBalance(address) {
232
218
  return Promise.resolve(undefined);
233
219
  }
234
220
  /**
@@ -255,7 +241,7 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
255
241
  *
256
242
  * @default Promise<undefined>
257
243
  */
258
- getNameService() {
244
+ getNameService(address) {
259
245
  return Promise.resolve(undefined);
260
246
  }
261
247
  getPublicClient() {
@@ -352,6 +338,41 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
352
338
  setVerifiedCredentials(verifiedCredentials) {
353
339
  return;
354
340
  }
341
+ /**
342
+ * Validates if the address is connected and active in the wallet app
343
+ *
344
+ * @throws {WalletAddressMismatchError} If the active address does not match the expected address.
345
+ * @returns {Promise<void>} A promise that resolves if the active address matches the expected address,
346
+ * otherwise rejects with an error.
347
+ */
348
+ validateActiveWallet(expectedAddress) {
349
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
350
+ var _a, _b;
351
+ const [activeAddress] = yield this.getConnectedAccounts();
352
+ const isWalletActive = activeAddress === expectedAddress;
353
+ logger.logger.debug(`validateActiveWallet - wallet ${isWalletActive ? 'is' : 'is not'} active`, {
354
+ activeAddress,
355
+ expectedAddress,
356
+ });
357
+ const walletUiUtils = this.constructorProps
358
+ .walletUiUtils;
359
+ if (isWalletActive) {
360
+ return;
361
+ }
362
+ if (!walletUiUtils) {
363
+ throw new utils.WalletAddressMismatchError(`Wallet ${expectedAddress !== null && expectedAddress !== void 0 ? expectedAddress : ''} is not currently active in ${(_a = this.name) !== null && _a !== void 0 ? _a : this.key}.`, {
364
+ activeAddress,
365
+ expectedAddress,
366
+ walletName: (_b = this.name) !== null && _b !== void 0 ? _b : this.key,
367
+ });
368
+ }
369
+ return walletUiUtils.syncWallet({
370
+ activeAddress,
371
+ expectedAddress,
372
+ walletConnector: this,
373
+ });
374
+ });
375
+ }
355
376
  }
356
377
  _WalletConnectorBase_registeredExtensions = new WeakMap();
357
378
 
@@ -152,7 +152,7 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
152
152
  *
153
153
  * @default Promise<undefined>
154
154
  */
155
- getBalance(): Promise<string | undefined>;
155
+ getBalance(address: string): Promise<string | undefined>;
156
156
  /**
157
157
  * Get the address silently
158
158
  *
@@ -176,7 +176,7 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
176
176
  *
177
177
  * @default Promise<undefined>
178
178
  */
179
- getNameService(): Promise<NameServiceData | undefined>;
179
+ getNameService(address: string): Promise<NameServiceData | undefined>;
180
180
  /**
181
181
  * Get the RPC provider for the wallet
182
182
  *
@@ -184,28 +184,6 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
184
184
  */
185
185
  getPublicClient(): Promise<unknown>;
186
186
  getPublicClient<T>(): Promise<T>;
187
- /**
188
- * @deprecated getWeb3Provider has been renamed to getWalletClient
189
- * If you would like to still get the ethers web3Provider,
190
- * see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
191
- *
192
- * Get the wallet provider
193
- */
194
- getWeb3Provider: {
195
- (chainId?: string): unknown;
196
- <T>(chainId?: string): T;
197
- };
198
- /**
199
- * @deprecated getRpcProvider has been renamed to getPublicClient
200
- * If you would like to still get the ethers rpcProvider,
201
- * see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
202
- *
203
- * Get the rpc provider
204
- */
205
- getRpcProvider: {
206
- (): Promise<unknown>;
207
- <T>(): Promise<T>;
208
- };
209
187
  /**
210
188
  * Get the session for the wallet
211
189
  * @default Promise<undefined>
@@ -337,4 +315,12 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
337
315
  * Receive the user verified credentials
338
316
  */
339
317
  setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
318
+ /**
319
+ * Validates if the address is connected and active in the wallet app
320
+ *
321
+ * @throws {WalletAddressMismatchError} If the active address does not match the expected address.
322
+ * @returns {Promise<void>} A promise that resolves if the active address matches the expected address,
323
+ * otherwise rejects with an error.
324
+ */
325
+ validateActiveWallet(expectedAddress: string): Promise<void>;
340
326
  }
@@ -2,6 +2,8 @@
2
2
  import { __classPrivateFieldGet, __awaiter } from '../../_virtual/_tslib.js';
3
3
  import EventEmitter from 'eventemitter3';
4
4
  import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
5
+ import { WalletAddressMismatchError } from '@dynamic-labs/utils';
6
+ import { logger } from '../utils/logger.js';
5
7
  import { WalletBookSingleton } from './WalletBookSingleton.js';
6
8
 
7
9
  /* eslint-disable @typescript-eslint/triple-slash-reference */
@@ -68,22 +70,6 @@ class WalletConnectorBase extends EventEmitter {
68
70
  * @default false
69
71
  */
70
72
  this.canConnectViaSocial = false;
71
- /**
72
- * @deprecated getWeb3Provider has been renamed to getWalletClient
73
- * If you would like to still get the ethers web3Provider,
74
- * see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
75
- *
76
- * Get the wallet provider
77
- */
78
- this.getWeb3Provider = this.getWalletClient;
79
- /**
80
- * @deprecated getRpcProvider has been renamed to getPublicClient
81
- * If you would like to still get the ethers rpcProvider,
82
- * see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
83
- *
84
- * Get the rpc provider
85
- */
86
- this.getRpcProvider = this.getPublicClient;
87
73
  /**
88
74
  * Flag if connector/provider is available
89
75
  *
@@ -220,7 +206,7 @@ class WalletConnectorBase extends EventEmitter {
220
206
  *
221
207
  * @default Promise<undefined>
222
208
  */
223
- getBalance() {
209
+ getBalance(address) {
224
210
  return Promise.resolve(undefined);
225
211
  }
226
212
  /**
@@ -247,7 +233,7 @@ class WalletConnectorBase extends EventEmitter {
247
233
  *
248
234
  * @default Promise<undefined>
249
235
  */
250
- getNameService() {
236
+ getNameService(address) {
251
237
  return Promise.resolve(undefined);
252
238
  }
253
239
  getPublicClient() {
@@ -344,6 +330,41 @@ class WalletConnectorBase extends EventEmitter {
344
330
  setVerifiedCredentials(verifiedCredentials) {
345
331
  return;
346
332
  }
333
+ /**
334
+ * Validates if the address is connected and active in the wallet app
335
+ *
336
+ * @throws {WalletAddressMismatchError} If the active address does not match the expected address.
337
+ * @returns {Promise<void>} A promise that resolves if the active address matches the expected address,
338
+ * otherwise rejects with an error.
339
+ */
340
+ validateActiveWallet(expectedAddress) {
341
+ return __awaiter(this, void 0, void 0, function* () {
342
+ var _a, _b;
343
+ const [activeAddress] = yield this.getConnectedAccounts();
344
+ const isWalletActive = activeAddress === expectedAddress;
345
+ logger.debug(`validateActiveWallet - wallet ${isWalletActive ? 'is' : 'is not'} active`, {
346
+ activeAddress,
347
+ expectedAddress,
348
+ });
349
+ const walletUiUtils = this.constructorProps
350
+ .walletUiUtils;
351
+ if (isWalletActive) {
352
+ return;
353
+ }
354
+ if (!walletUiUtils) {
355
+ throw new WalletAddressMismatchError(`Wallet ${expectedAddress !== null && expectedAddress !== void 0 ? expectedAddress : ''} is not currently active in ${(_a = this.name) !== null && _a !== void 0 ? _a : this.key}.`, {
356
+ activeAddress,
357
+ expectedAddress,
358
+ walletName: (_b = this.name) !== null && _b !== void 0 ? _b : this.key,
359
+ });
360
+ }
361
+ return walletUiUtils.syncWallet({
362
+ activeAddress,
363
+ expectedAddress,
364
+ walletConnector: this,
365
+ });
366
+ });
367
+ }
347
368
  }
348
369
  _WalletConnectorBase_registeredExtensions = new WeakMap();
349
370
 
@@ -13,3 +13,4 @@ export * from './IWalletConnectConnector';
13
13
  export * from './ISendBalanceWalletConnector';
14
14
  export * from './ISessionKeyCompatibleWalletConnector';
15
15
  export * from './ISMSWalletConnector';
16
+ export * from './wallets';
@@ -0,0 +1,145 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../_virtual/_tslib.cjs');
7
+ var types = require('@dynamic-labs/types');
8
+
9
+ var _Wallet_connector;
10
+ class Wallet extends types.BaseWallet {
11
+ constructor(_a) {
12
+ var { connector } = _a, props = _tslib.__rest(_a, ["connector"]);
13
+ super(props);
14
+ _Wallet_connector.set(this, void 0);
15
+ _tslib.__classPrivateFieldSet(this, _Wallet_connector, connector, "f");
16
+ }
17
+ /**
18
+ * Gets the wallet connector.
19
+ */
20
+ get connector() {
21
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f");
22
+ }
23
+ /**
24
+ * Retrieves the balance of the wallet.
25
+ * @returns A promise that resolves to the balance of the wallet as a string,
26
+ * or undefined if the balance cannot be retrieved.
27
+ */
28
+ getBalance() {
29
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
30
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getBalance(this.address);
31
+ });
32
+ }
33
+ /**
34
+ * Retrieves the name service data associated with the wallet.
35
+ * @returns A promise that resolves to the name service data of the wallet,
36
+ * or undefined if the data cannot be retrieved.
37
+ */
38
+ getNameService() {
39
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
40
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getNameService(this.address);
41
+ });
42
+ }
43
+ /**
44
+ * Retrieves the network that the wallet is connected to.
45
+ * @returns A promise that resolves to the network value as a string or number,
46
+ * or undefined if the network cannot be retrieved.
47
+ */
48
+ getNetwork() {
49
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
50
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getNetwork();
51
+ });
52
+ }
53
+ /**
54
+ * Retrieves the rpc provider for the wallet.
55
+ * @returns A promise that resolves to the provider,
56
+ * or undefined if the provider cannot be retrieved.
57
+ */
58
+ getPublicClient() {
59
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
60
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getPublicClient();
61
+ });
62
+ }
63
+ /**
64
+ * Retrieves the signer for the wallet.
65
+ * @returns A promise that resolves to the signer,
66
+ * or undefined if the signer cannot be retrieved.
67
+ */
68
+ getSigner() {
69
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
70
+ yield this.sync();
71
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getSigner();
72
+ });
73
+ }
74
+ /**
75
+ * Retrieves the wallet client.
76
+ * @param chainId - (optional) Chain id to be used by the wallet client.
77
+ * @returns A promise that resolves to the wallet client,
78
+ * or undefined if the wallet client cannot be retrieved.
79
+ */
80
+ getWalletClient(chainId) {
81
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
82
+ yield this.sync();
83
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getWalletClient(chainId);
84
+ });
85
+ }
86
+ // TODO: Add this method once we remove the isConnected prop from BaseWallet
87
+ // public async isConnected(): Promise<boolean> {
88
+ // try {
89
+ // const connectedAccounts = await this.#connector.getConnectedAccounts();
90
+ // return connectedAccounts.includes(this.address);
91
+ // } catch (error) {
92
+ // console.error('[Wallet] isConnected - Error detecting if wallet is connected', error);
93
+ // return false;
94
+ // }
95
+ // }
96
+ //
97
+ /**
98
+ * Proves ownership of the wallet by signing a message.
99
+ * @param messageToSign - The message to sign.
100
+ * @returns A promise that resolves to the signature of the message as a string,
101
+ * or undefined if the message cannot be signed.
102
+ */
103
+ proveOwnership(messageToSign) {
104
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
105
+ yield this.sync();
106
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").proveOwnership(messageToSign);
107
+ });
108
+ }
109
+ /**
110
+ * Signs a message using the wallet.
111
+ * @param messageToSign - The message to sign.
112
+ * @returns A promise that resolves to the signature of the message as a string,
113
+ * or undefined if the message cannot be signed.
114
+ */
115
+ signMessage(messageToSign) {
116
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
117
+ yield this.sync();
118
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").signMessage(messageToSign);
119
+ });
120
+ }
121
+ /**
122
+ * Switches the network that the wallet is connected to.
123
+ * @param networkChainId - The chain id of the network to switch to.
124
+ * @returns A promise that resolves when the network is switched.
125
+ */
126
+ switchNetwork(networkChainId) {
127
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
128
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").switchNetwork({
129
+ networkChainId,
130
+ });
131
+ });
132
+ }
133
+ /**
134
+ * Synchronizes the wallet with the connector.
135
+ * @returns A promise that resolves when the wallet is connected and active.
136
+ */
137
+ sync() {
138
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
139
+ return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").validateActiveWallet(this.address);
140
+ });
141
+ }
142
+ }
143
+ _Wallet_connector = new WeakMap();
144
+
145
+ exports.Wallet = Wallet;
@@ -0,0 +1,77 @@
1
+ import type { BaseWalletProps } from '@dynamic-labs/types';
2
+ import { BaseWallet } from '@dynamic-labs/types';
3
+ import { NameServiceData, WalletConnector } from '../../';
4
+ type WalletProps = BaseWalletProps & {
5
+ connector: WalletConnector;
6
+ };
7
+ export declare class Wallet extends BaseWallet {
8
+ #private;
9
+ constructor({ connector, ...props }: WalletProps);
10
+ /**
11
+ * Gets the wallet connector.
12
+ */
13
+ get connector(): WalletConnector;
14
+ /**
15
+ * Retrieves the balance of the wallet.
16
+ * @returns A promise that resolves to the balance of the wallet as a string,
17
+ * or undefined if the balance cannot be retrieved.
18
+ */
19
+ getBalance(): Promise<string | undefined>;
20
+ /**
21
+ * Retrieves the name service data associated with the wallet.
22
+ * @returns A promise that resolves to the name service data of the wallet,
23
+ * or undefined if the data cannot be retrieved.
24
+ */
25
+ getNameService(): Promise<NameServiceData | undefined>;
26
+ /**
27
+ * Retrieves the network that the wallet is connected to.
28
+ * @returns A promise that resolves to the network value as a string or number,
29
+ * or undefined if the network cannot be retrieved.
30
+ */
31
+ getNetwork(): Promise<string | number | undefined>;
32
+ /**
33
+ * Retrieves the rpc provider for the wallet.
34
+ * @returns A promise that resolves to the provider,
35
+ * or undefined if the provider cannot be retrieved.
36
+ */
37
+ getPublicClient<T>(): Promise<T>;
38
+ /**
39
+ * Retrieves the signer for the wallet.
40
+ * @returns A promise that resolves to the signer,
41
+ * or undefined if the signer cannot be retrieved.
42
+ */
43
+ getSigner<T>(): Promise<T>;
44
+ /**
45
+ * Retrieves the wallet client.
46
+ * @param chainId - (optional) Chain id to be used by the wallet client.
47
+ * @returns A promise that resolves to the wallet client,
48
+ * or undefined if the wallet client cannot be retrieved.
49
+ */
50
+ getWalletClient<T>(chainId?: string): Promise<T>;
51
+ /**
52
+ * Proves ownership of the wallet by signing a message.
53
+ * @param messageToSign - The message to sign.
54
+ * @returns A promise that resolves to the signature of the message as a string,
55
+ * or undefined if the message cannot be signed.
56
+ */
57
+ proveOwnership(messageToSign: string): Promise<string | undefined>;
58
+ /**
59
+ * Signs a message using the wallet.
60
+ * @param messageToSign - The message to sign.
61
+ * @returns A promise that resolves to the signature of the message as a string,
62
+ * or undefined if the message cannot be signed.
63
+ */
64
+ signMessage(messageToSign: string): Promise<string | undefined>;
65
+ /**
66
+ * Switches the network that the wallet is connected to.
67
+ * @param networkChainId - The chain id of the network to switch to.
68
+ * @returns A promise that resolves when the network is switched.
69
+ */
70
+ switchNetwork(networkChainId: number | string): Promise<void>;
71
+ /**
72
+ * Synchronizes the wallet with the connector.
73
+ * @returns A promise that resolves when the wallet is connected and active.
74
+ */
75
+ sync(): Promise<void>;
76
+ }
77
+ export {};
@@ -0,0 +1,141 @@
1
+ 'use client'
2
+ import { __rest, __classPrivateFieldSet, __classPrivateFieldGet, __awaiter } from '../../../../_virtual/_tslib.js';
3
+ import { BaseWallet } from '@dynamic-labs/types';
4
+
5
+ var _Wallet_connector;
6
+ class Wallet extends BaseWallet {
7
+ constructor(_a) {
8
+ var { connector } = _a, props = __rest(_a, ["connector"]);
9
+ super(props);
10
+ _Wallet_connector.set(this, void 0);
11
+ __classPrivateFieldSet(this, _Wallet_connector, connector, "f");
12
+ }
13
+ /**
14
+ * Gets the wallet connector.
15
+ */
16
+ get connector() {
17
+ return __classPrivateFieldGet(this, _Wallet_connector, "f");
18
+ }
19
+ /**
20
+ * Retrieves the balance of the wallet.
21
+ * @returns A promise that resolves to the balance of the wallet as a string,
22
+ * or undefined if the balance cannot be retrieved.
23
+ */
24
+ getBalance() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").getBalance(this.address);
27
+ });
28
+ }
29
+ /**
30
+ * Retrieves the name service data associated with the wallet.
31
+ * @returns A promise that resolves to the name service data of the wallet,
32
+ * or undefined if the data cannot be retrieved.
33
+ */
34
+ getNameService() {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").getNameService(this.address);
37
+ });
38
+ }
39
+ /**
40
+ * Retrieves the network that the wallet is connected to.
41
+ * @returns A promise that resolves to the network value as a string or number,
42
+ * or undefined if the network cannot be retrieved.
43
+ */
44
+ getNetwork() {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").getNetwork();
47
+ });
48
+ }
49
+ /**
50
+ * Retrieves the rpc provider for the wallet.
51
+ * @returns A promise that resolves to the provider,
52
+ * or undefined if the provider cannot be retrieved.
53
+ */
54
+ getPublicClient() {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").getPublicClient();
57
+ });
58
+ }
59
+ /**
60
+ * Retrieves the signer for the wallet.
61
+ * @returns A promise that resolves to the signer,
62
+ * or undefined if the signer cannot be retrieved.
63
+ */
64
+ getSigner() {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ yield this.sync();
67
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").getSigner();
68
+ });
69
+ }
70
+ /**
71
+ * Retrieves the wallet client.
72
+ * @param chainId - (optional) Chain id to be used by the wallet client.
73
+ * @returns A promise that resolves to the wallet client,
74
+ * or undefined if the wallet client cannot be retrieved.
75
+ */
76
+ getWalletClient(chainId) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ yield this.sync();
79
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").getWalletClient(chainId);
80
+ });
81
+ }
82
+ // TODO: Add this method once we remove the isConnected prop from BaseWallet
83
+ // public async isConnected(): Promise<boolean> {
84
+ // try {
85
+ // const connectedAccounts = await this.#connector.getConnectedAccounts();
86
+ // return connectedAccounts.includes(this.address);
87
+ // } catch (error) {
88
+ // console.error('[Wallet] isConnected - Error detecting if wallet is connected', error);
89
+ // return false;
90
+ // }
91
+ // }
92
+ //
93
+ /**
94
+ * Proves ownership of the wallet by signing a message.
95
+ * @param messageToSign - The message to sign.
96
+ * @returns A promise that resolves to the signature of the message as a string,
97
+ * or undefined if the message cannot be signed.
98
+ */
99
+ proveOwnership(messageToSign) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ yield this.sync();
102
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").proveOwnership(messageToSign);
103
+ });
104
+ }
105
+ /**
106
+ * Signs a message using the wallet.
107
+ * @param messageToSign - The message to sign.
108
+ * @returns A promise that resolves to the signature of the message as a string,
109
+ * or undefined if the message cannot be signed.
110
+ */
111
+ signMessage(messageToSign) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ yield this.sync();
114
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").signMessage(messageToSign);
115
+ });
116
+ }
117
+ /**
118
+ * Switches the network that the wallet is connected to.
119
+ * @param networkChainId - The chain id of the network to switch to.
120
+ * @returns A promise that resolves when the network is switched.
121
+ */
122
+ switchNetwork(networkChainId) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").switchNetwork({
125
+ networkChainId,
126
+ });
127
+ });
128
+ }
129
+ /**
130
+ * Synchronizes the wallet with the connector.
131
+ * @returns A promise that resolves when the wallet is connected and active.
132
+ */
133
+ sync() {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ return __classPrivateFieldGet(this, _Wallet_connector, "f").validateActiveWallet(this.address);
136
+ });
137
+ }
138
+ }
139
+ _Wallet_connector = new WeakMap();
140
+
141
+ export { Wallet };
@@ -0,0 +1 @@
1
+ export * from './Wallet';
@@ -0,0 +1 @@
1
+ export * from './Wallet';