@dynamic-labs/wallet-connector-core 3.0.0-alpha.8 → 3.0.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +622 -0
  2. package/_virtual/_tslib.cjs +13 -0
  3. package/_virtual/_tslib.js +13 -1
  4. package/package.json +7 -7
  5. package/src/index.cjs +11 -3
  6. package/src/index.d.ts +3 -3
  7. package/src/index.js +6 -3
  8. package/src/lib/IAccountAbstractionWalletConnector.d.ts +11 -2
  9. package/src/lib/IBitcoinWalletConnector.d.ts +1 -0
  10. package/src/lib/IHardwareWalletConnector.d.ts +2 -1
  11. package/src/lib/ISendBalanceWalletConnector.d.ts +2 -1
  12. package/src/lib/ISessionKeyCompatibleWalletConnector.d.ts +6 -2
  13. package/src/lib/ITurnkeyWalletConnector.d.ts +49 -0
  14. package/src/lib/ITurnkeyWalletConnectorStamper.d.ts +18 -0
  15. package/src/lib/WalletConnector.cjs +124 -21
  16. package/src/lib/WalletConnector.d.ts +47 -30
  17. package/src/lib/WalletConnector.js +124 -21
  18. package/src/lib/WalletConnectorExtension.d.ts +2 -2
  19. package/src/lib/index.d.ts +3 -1
  20. package/src/lib/wallets/Wallet/Wallet.cjs +119 -0
  21. package/src/lib/wallets/Wallet/Wallet.d.ts +65 -0
  22. package/src/lib/wallets/Wallet/Wallet.js +115 -0
  23. package/src/lib/wallets/Wallet/index.d.ts +1 -0
  24. package/src/lib/wallets/index.d.ts +1 -0
  25. package/src/utils/getChainInfo/getChainInfo.cjs +25 -0
  26. package/src/utils/getChainInfo/getChainInfo.d.ts +6 -0
  27. package/src/utils/getChainInfo/getChainInfo.js +24 -1
  28. package/src/utils/getChainInfo/index.d.ts +1 -1
  29. package/src/utils/getMobileExperience/getMobileExperience.cjs +24 -0
  30. package/src/utils/getMobileExperience/getMobileExperience.d.ts +7 -0
  31. package/src/utils/getMobileExperience/getMobileExperience.js +20 -0
  32. package/src/utils/getMobileExperience/index.d.ts +1 -0
  33. package/src/utils/getWalletConnectorByKey.d.ts +2 -2
  34. package/src/utils/index.d.ts +3 -2
  35. package/src/utils/isAccountAbstractionConnector/index.d.ts +1 -1
  36. package/src/utils/isConnectorMethodSupported/index.d.ts +1 -0
  37. package/src/utils/isConnectorMethodSupported/isConnectorMethodSupported.cjs +14 -0
  38. package/src/utils/isConnectorMethodSupported/isConnectorMethodSupported.d.ts +3 -0
  39. package/src/utils/isConnectorMethodSupported/isConnectorMethodSupported.js +10 -0
  40. package/src/utils/isHardwareWalletConnector/isHardwareWalletConnector.d.ts +1 -1
  41. package/src/utils/isSessionKeyCompatible/index.d.ts +2 -0
  42. package/src/utils/isSessionKeyCompatible/isSessionKeyCompatibleWallet/index.d.ts +1 -0
  43. package/src/utils/isSessionKeyCompatible/isSessionKeyCompatibleWallet/isSessionKeyCompatibleWallet.cjs +10 -0
  44. package/src/utils/isSessionKeyCompatible/isSessionKeyCompatibleWallet/isSessionKeyCompatibleWallet.d.ts +2 -0
  45. package/src/utils/isSessionKeyCompatible/isSessionKeyCompatibleWallet/isSessionKeyCompatibleWallet.js +6 -0
  46. package/src/utils/{isSessionKeyCompatibleWalletConnector → isSessionKeyCompatible/isSessionKeyCompatibleWalletConnector}/isSessionKeyCompatibleWalletConnector.d.ts +2 -1
  47. package/src/utils/isTurnkeyWalletConnector/index.d.ts +1 -0
  48. package/src/utils/isTurnkeyWalletConnector/isTurnkeyWalletConnector.cjs +17 -0
  49. package/src/utils/isTurnkeyWalletConnector/isTurnkeyWalletConnector.d.ts +2 -0
  50. package/src/utils/isTurnkeyWalletConnector/isTurnkeyWalletConnector.js +13 -0
  51. package/src/lib/SmartWalletConnector.d.ts +0 -4
  52. package/src/utils/isSmartWalletConnector/index.d.ts +0 -1
  53. package/src/utils/isSmartWalletConnector/isSmartWalletConnector.cjs +0 -8
  54. package/src/utils/isSmartWalletConnector/isSmartWalletConnector.d.ts +0 -2
  55. package/src/utils/isSmartWalletConnector/isSmartWalletConnector.js +0 -4
  56. /package/src/utils/{isSessionKeyCompatibleWalletConnector → isSessionKeyCompatible/isSessionKeyCompatibleWalletConnector}/index.d.ts +0 -0
  57. /package/src/utils/{isSessionKeyCompatibleWalletConnector → isSessionKeyCompatible/isSessionKeyCompatibleWalletConnector}/isSessionKeyCompatibleWalletConnector.cjs +0 -0
  58. /package/src/utils/{isSessionKeyCompatibleWalletConnector → isSessionKeyCompatible/isSessionKeyCompatibleWalletConnector}/isSessionKeyCompatibleWalletConnector.js +0 -0
@@ -2,9 +2,11 @@ import EventEmitter from 'eventemitter3';
2
2
  import { WalletBookSchema, WalletSchema } from '@dynamic-labs/wallet-book';
3
3
  import type { JwtVerifiedCredential, WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core';
4
4
  import { IChainRpcProviders } from '@dynamic-labs/rpc-providers';
5
+ import { MobileExperience } from '@dynamic-labs/types';
5
6
  import { WalletBookSingleton } from './WalletBookSingleton';
6
7
  import { WalletConnectorExtension } from './WalletConnectorExtension';
7
8
  import { WalletConnectorCore } from './types';
9
+ import { WalletConstructor, WalletProps } from './wallets';
8
10
  export declare const Chains: readonly ["ETH", "FLOW", "SOL", "EVM", "ALGO", "STARK", "ATOM", "COSMOS", "BTC"];
9
11
  export type Chain = typeof Chains[number];
10
12
  export declare const socialProviders: readonly ["google", "facebook", "apple", "github", "bitbucket", "gitlab", "linkedin", "twitter", "discord", "twitch", "microsoft"];
@@ -32,9 +34,10 @@ declare module './types' {
32
34
  }
33
35
  }
34
36
  }
35
- export type WalletConnector = WalletConnectorCore.WalletConnector;
37
+ export type InternalWalletConnector = WalletConnectorCore.WalletConnector;
38
+ export type WalletConnector = Pick<InternalWalletConnector, 'canConnectViaCustodialService' | 'canConnectViaQrCode' | 'canConnectViaSocial' | 'chainRpcProviders' | 'connect' | 'connectedChain' | 'createWallet' | 'constructorProps' | 'endSession' | 'getAddress' | 'getAdditionalAddresses' | 'getConnectedAccounts' | 'getDeepLink' | 'getMobileOrInstalledWallet' | 'getNetwork' | 'getSession' | 'initEventListener' | 'isAvailable' | 'isEmbeddedWallet' | 'isInitialized' | 'isInstalledOnBrowser' | 'isTestnet' | 'isWalletConnect' | 'key' | 'name' | 'parseAddress' | 'proveOwnership' | 'providerResources' | 'supportedChains' | 'supportsNetworkSwitching' | 'switchNetwork' | 'switchNetworkOnlyFromWallet' | 'teardownEventListeners'> & EventEmitter<WalletConnectorEventTypes>;
36
39
  export interface WalletConnectorConstructor {
37
- new (props?: any): WalletConnector;
40
+ new (props?: any): InternalWalletConnector;
38
41
  }
39
42
  export type WalletConnectorsMethod = (props?: any) => WalletConnectorConstructor[];
40
43
  export type WalletConnectorEventTypes = {
@@ -46,12 +49,15 @@ export type WalletConnectorEventTypes = {
46
49
  }) => void;
47
50
  disconnect: () => void;
48
51
  };
49
- export declare abstract class WalletConnectorBase extends EventEmitter<WalletConnectorEventTypes> {
52
+ export declare abstract class WalletConnectorBase<C extends WalletConstructor<any> = WalletConstructor<any>> extends EventEmitter<WalletConnectorEventTypes> {
50
53
  #private;
54
+ abstract ChainWallet: C;
55
+ createWallet(props: WalletProps<InternalWalletConnector>): import("./wallets").Wallet<any>;
51
56
  chainRpcProviders: IChainRpcProviders | undefined;
52
57
  constructorProps: any;
53
58
  _walletBookInstance: WalletBookSingleton;
54
59
  walletFallback: WalletSchema | undefined;
60
+ isGlobalTransaction: boolean;
55
61
  /**
56
62
  * We store the constructor props so that we can use them later on
57
63
  * in getMobileOrInstalledWallet which may fall back to a different class
@@ -70,6 +76,7 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
70
76
  initEventListener(): void;
71
77
  get walletBook(): WalletBookSchema;
72
78
  filter(): boolean;
79
+ get mobileExperience(): MobileExperience | undefined;
73
80
  /**
74
81
  * This flag corresponds to whether this wallet connector also requires its own email otp outside dynamic
75
82
  * @default false
@@ -92,6 +99,11 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
92
99
  * @default false
93
100
  */
94
101
  canConnectViaSocial: boolean;
102
+ /**
103
+ * Prompt the user to choose accounts to connect (see behavior in MM)
104
+ * @default Promise<[]>
105
+ */
106
+ chooseAccountsToConnect(): Promise<string[]>;
95
107
  /**
96
108
  * Connect to the wallet or custodial service
97
109
  *
@@ -152,7 +164,7 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
152
164
  *
153
165
  * @default Promise<undefined>
154
166
  */
155
- getBalance(): Promise<string | undefined>;
167
+ getBalance(address: string): Promise<string | undefined>;
156
168
  /**
157
169
  * Get the address silently
158
170
  *
@@ -176,7 +188,7 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
176
188
  *
177
189
  * @default Promise<undefined>
178
190
  */
179
- getNameService(): Promise<NameServiceData | undefined>;
191
+ getNameService(address: string): Promise<NameServiceData | undefined>;
180
192
  /**
181
193
  * Get the RPC provider for the wallet
182
194
  *
@@ -184,28 +196,6 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
184
196
  */
185
197
  getPublicClient(): Promise<unknown>;
186
198
  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
199
  /**
210
200
  * Get the session for the wallet
211
201
  * @default Promise<undefined>
@@ -275,13 +265,13 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
275
265
  * @returns WalletConnector
276
266
  * @default this
277
267
  */
278
- getMobileOrInstalledWallet(): WalletConnector;
268
+ getMobileOrInstalledWallet(): InternalWalletConnector;
279
269
  /**
280
270
  * In most cases this is an alias for `signMessage`
281
271
  *
282
272
  * @default Promise<undefined>
283
273
  */
284
- proveOwnership(messageToSign: string): Promise<string | undefined>;
274
+ proveOwnership(address: string, messageToSign: string): Promise<string | undefined>;
285
275
  /**
286
276
  * Additional resources to add to the message to be signed
287
277
  *
@@ -299,7 +289,7 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
299
289
  *
300
290
  * @default Promise<undefined>
301
291
  */
302
- signMessage(messageToSign: string): Promise<string | undefined>;
292
+ signMessage(messageToSign: string, withAddress?: string): Promise<string | undefined>;
303
293
  /**
304
294
  * List of supported chains for this wallet
305
295
  */
@@ -337,4 +327,31 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
337
327
  * Receive the user verified credentials
338
328
  */
339
329
  setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
330
+ /**
331
+ * Whether the wallet allow for getting the address in the
332
+ * current chain.
333
+ * This is used for multi chain wallets.
334
+ * @default true
335
+ */
336
+ canGetChainAddress(): boolean;
337
+ /**
338
+ * Prompts the user to make expected wallet active
339
+ *
340
+ * @throws {WalletAddressMismatchError} If the active address does not match the expected address.
341
+ * @returns {Promise<void>} A promise that resolves when the active address matches the expected address,
342
+ * otherwise rejects with an error.
343
+ */
344
+ handleWalletNotActive({ activeAddress, expectedAddress, reconnectedAddress, }: {
345
+ expectedAddress: string;
346
+ activeAddress?: string;
347
+ reconnectedAddress?: string;
348
+ }): Promise<void>;
349
+ /**
350
+ * Validates if the address is connected and active in the wallet app
351
+ *
352
+ * @throws {WalletAddressMismatchError} If the active address does not match the expected address.
353
+ * @returns {Promise<void>} A promise that resolves if the active address matches the expected address,
354
+ * otherwise rejects with an error.
355
+ */
356
+ validateActiveWallet(expectedAddress: string): Promise<void>;
340
357
  }
@@ -2,6 +2,11 @@
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';
7
+ import { isSameAddress } from '../utils/isSameAddress/isSameAddress.js';
8
+ import { getMobileExperience } from '../utils/getMobileExperience/getMobileExperience.js';
9
+ import { isConnectorMethodSupported } from '../utils/isConnectorMethodSupported/isConnectorMethodSupported.js';
5
10
  import { WalletBookSingleton } from './WalletBookSingleton.js';
6
11
 
7
12
  /* eslint-disable @typescript-eslint/triple-slash-reference */
@@ -35,6 +40,10 @@ const socialProviders = [
35
40
  'microsoft',
36
41
  ];
37
42
  class WalletConnectorBase extends EventEmitter {
43
+ createWallet(props) {
44
+ const wallet = new this.ChainWallet(props);
45
+ return wallet;
46
+ }
38
47
  /**
39
48
  * We store the constructor props so that we can use them later on
40
49
  * in getMobileOrInstalledWallet which may fall back to a different class
@@ -44,6 +53,7 @@ class WalletConnectorBase extends EventEmitter {
44
53
  constructor(props) {
45
54
  super();
46
55
  this.chainRpcProviders = undefined;
56
+ this.isGlobalTransaction = false;
47
57
  _WalletConnectorBase_registeredExtensions.set(this, []);
48
58
  this.didSetup = false;
49
59
  /**
@@ -68,22 +78,6 @@ class WalletConnectorBase extends EventEmitter {
68
78
  * @default false
69
79
  */
70
80
  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
81
  /**
88
82
  * Flag if connector/provider is available
89
83
  *
@@ -132,6 +126,11 @@ class WalletConnectorBase extends EventEmitter {
132
126
  if (__classPrivateFieldGet(this, _WalletConnectorBase_registeredExtensions, "f").includes(extension.name)) {
133
127
  throw new Error(`You can only register a single extension of: ${extension.name}`);
134
128
  }
129
+ if (extension.name === 'global-wallet-extension') {
130
+ // only allow global wallet extension for evm embedded wallets
131
+ if (!this.isEmbeddedWallet || !this.supportedChains.includes('EVM'))
132
+ return;
133
+ }
135
134
  __classPrivateFieldGet(this, _WalletConnectorBase_registeredExtensions, "f").push(extension.name);
136
135
  extension.extend(this);
137
136
  }
@@ -157,6 +156,20 @@ class WalletConnectorBase extends EventEmitter {
157
156
  return false;
158
157
  }
159
158
  }
159
+ get mobileExperience() {
160
+ return getMobileExperience({
161
+ mobileExperienceProp: this.constructorProps.mobileExperience,
162
+ walletBook: this.walletBook,
163
+ walletKey: this.key,
164
+ });
165
+ }
166
+ /**
167
+ * Prompt the user to choose accounts to connect (see behavior in MM)
168
+ * @default Promise<[]>
169
+ */
170
+ chooseAccountsToConnect() {
171
+ return Promise.resolve([]);
172
+ }
160
173
  connect() {
161
174
  return __awaiter(this, void 0, void 0, function* () {
162
175
  yield this.getAddress();
@@ -220,7 +233,7 @@ class WalletConnectorBase extends EventEmitter {
220
233
  *
221
234
  * @default Promise<undefined>
222
235
  */
223
- getBalance() {
236
+ getBalance(address) {
224
237
  return Promise.resolve(undefined);
225
238
  }
226
239
  /**
@@ -247,7 +260,7 @@ class WalletConnectorBase extends EventEmitter {
247
260
  *
248
261
  * @default Promise<undefined>
249
262
  */
250
- getNameService() {
263
+ getNameService(address) {
251
264
  return Promise.resolve(undefined);
252
265
  }
253
266
  getPublicClient() {
@@ -301,8 +314,11 @@ class WalletConnectorBase extends EventEmitter {
301
314
  *
302
315
  * @default Promise<undefined>
303
316
  */
304
- proveOwnership(messageToSign) {
305
- return this.signMessage(messageToSign);
317
+ proveOwnership(address, messageToSign) {
318
+ return __awaiter(this, void 0, void 0, function* () {
319
+ yield this.validateActiveWallet(address);
320
+ return this.signMessage(messageToSign);
321
+ });
306
322
  }
307
323
  /**
308
324
  * Set up event listeners for the wallet
@@ -317,7 +333,7 @@ class WalletConnectorBase extends EventEmitter {
317
333
  *
318
334
  * @default Promise<undefined>
319
335
  */
320
- signMessage(messageToSign) {
336
+ signMessage(messageToSign, withAddress) {
321
337
  return Promise.resolve(undefined);
322
338
  }
323
339
  /**
@@ -344,6 +360,93 @@ class WalletConnectorBase extends EventEmitter {
344
360
  setVerifiedCredentials(verifiedCredentials) {
345
361
  return;
346
362
  }
363
+ /**
364
+ * Whether the wallet allow for getting the address in the
365
+ * current chain.
366
+ * This is used for multi chain wallets.
367
+ * @default true
368
+ */
369
+ canGetChainAddress() {
370
+ return true;
371
+ }
372
+ /**
373
+ * Prompts the user to make expected wallet active
374
+ *
375
+ * @throws {WalletAddressMismatchError} If the active address does not match the expected address.
376
+ * @returns {Promise<void>} A promise that resolves when the active address matches the expected address,
377
+ * otherwise rejects with an error.
378
+ */
379
+ handleWalletNotActive(_a) {
380
+ return __awaiter(this, arguments, void 0, function* ({ activeAddress, expectedAddress, reconnectedAddress, }) {
381
+ logger.debug('validateActiveWallet - wallet is not active', {
382
+ activeAddress,
383
+ expectedAddress,
384
+ reconnectedAddress,
385
+ });
386
+ const currentActiveAddress = activeAddress || reconnectedAddress || '';
387
+ const walletUiUtils = this.constructorProps
388
+ .walletUiUtils;
389
+ if (!walletUiUtils) {
390
+ throw new WalletAddressMismatchError(`Wallet ${expectedAddress !== null && expectedAddress !== void 0 ? expectedAddress : ''} is not currently active in ${this.name || this.key}.`, {
391
+ activeAddress: currentActiveAddress,
392
+ expectedAddress,
393
+ walletName: this.name || this.key,
394
+ });
395
+ }
396
+ return walletUiUtils.syncWallet({
397
+ activeAddress: currentActiveAddress,
398
+ expectedAddress,
399
+ walletConnector: this,
400
+ });
401
+ });
402
+ }
403
+ /**
404
+ * Validates if the address is connected and active in the wallet app
405
+ *
406
+ * @throws {WalletAddressMismatchError} If the active address does not match the expected address.
407
+ * @returns {Promise<void>} A promise that resolves if the active address matches the expected address,
408
+ * otherwise rejects with an error.
409
+ */
410
+ validateActiveWallet(expectedAddress) {
411
+ return __awaiter(this, void 0, void 0, function* () {
412
+ logger.debug('validateActiveWallet - validating wallet', expectedAddress);
413
+ const canFetchConnectedAccounts = isConnectorMethodSupported(this, 'getConnectedAccounts', 'browserExtension');
414
+ logger.debug('validateActiveWallet - getting connected accounts', {
415
+ canFetchConnectedAccounts,
416
+ });
417
+ const [activeAddress] = canFetchConnectedAccounts
418
+ ? yield this.getConnectedAccounts()
419
+ : [];
420
+ const isWalletActive = activeAddress &&
421
+ isSameAddress(activeAddress, expectedAddress, this.connectedChain);
422
+ if (isWalletActive) {
423
+ logger.debug('validateActiveWallet - wallet is active');
424
+ return;
425
+ }
426
+ logger.debug('validateActiveWallet - trying to reconnect wallet...');
427
+ const getReconnectedAddress = () => __awaiter(this, void 0, void 0, function* () {
428
+ if (this.isWalletConnect || !this.canGetChainAddress()) {
429
+ return undefined;
430
+ }
431
+ return this.getAddress().catch((err) => {
432
+ logger.debug('validateActiveWallet - error getting address', err);
433
+ return undefined;
434
+ });
435
+ });
436
+ // not possible to auto-reconnect walletconnect
437
+ const reconnectedAddress = yield getReconnectedAddress();
438
+ if (reconnectedAddress &&
439
+ isSameAddress(reconnectedAddress, expectedAddress, this.connectedChain)) {
440
+ logger.debug('validateActiveWallet - wallet reconnected successfuly');
441
+ return;
442
+ }
443
+ return this.handleWalletNotActive({
444
+ activeAddress,
445
+ expectedAddress,
446
+ reconnectedAddress,
447
+ });
448
+ });
449
+ }
347
450
  }
348
451
  _WalletConnectorBase_registeredExtensions = new WeakMap();
349
452
 
@@ -1,5 +1,5 @@
1
- import { WalletConnector } from '.';
1
+ import { InternalWalletConnector } from '.';
2
2
  export interface WalletConnectorExtension {
3
- extend(connector: WalletConnector): void;
3
+ extend(connector: InternalWalletConnector): void;
4
4
  name: string;
5
5
  }
@@ -3,7 +3,8 @@ export * from './IEmailWalletConnector';
3
3
  export * from './WalletConnector';
4
4
  export * from './types';
5
5
  export * from './IPasskeyWalletConnector';
6
- export * from './SmartWalletConnector';
6
+ export * from './ITurnkeyWalletConnector';
7
+ export * from './ITurnkeyWalletConnectorStamper';
7
8
  export * from './IAccountAbstractionWalletConnector';
8
9
  export * from './IBitcoinWalletConnector';
9
10
  export * from './IHardwareWalletConnector';
@@ -13,3 +14,4 @@ export * from './IWalletConnectConnector';
13
14
  export * from './ISendBalanceWalletConnector';
14
15
  export * from './ISessionKeyCompatibleWalletConnector';
15
16
  export * from './ISMSWalletConnector';
17
+ export * from './wallets';
@@ -0,0 +1,119 @@
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
+ var logger = require('../../../utils/logger.cjs');
9
+ var normalizeAddress = require('../../../utils/isSameAddress/utils/normalizeAddress/normalizeAddress.cjs');
10
+ require('@dynamic-labs/utils');
11
+ require('@dynamic-labs/wallet-book');
12
+
13
+ class Wallet extends types.BaseWallet {
14
+ constructor(_a) {
15
+ var { connector } = _a, props = _tslib.__rest(_a, ["connector"]);
16
+ super(props);
17
+ this._connector = connector;
18
+ }
19
+ /**
20
+ * Gets the wallet connector.
21
+ */
22
+ get connector() {
23
+ return this._connector;
24
+ }
25
+ /**
26
+ * Retrieves the balance of the wallet.
27
+ * @returns A promise that resolves to the balance of the wallet as a string,
28
+ * or undefined if the balance cannot be retrieved.
29
+ */
30
+ getBalance() {
31
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
32
+ return this._connector.getBalance(this.address);
33
+ });
34
+ }
35
+ /**
36
+ * Retrieves the name service data associated with the wallet.
37
+ * @returns A promise that resolves to the name service data of the wallet,
38
+ * or undefined if the data cannot be retrieved.
39
+ */
40
+ getNameService() {
41
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
42
+ return this._connector.getNameService(this.address);
43
+ });
44
+ }
45
+ /**
46
+ * Retrieves the network that the wallet is connected to.
47
+ * @returns A promise that resolves to the network value as a string or number,
48
+ * or undefined if the network cannot be retrieved.
49
+ */
50
+ getNetwork() {
51
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
52
+ return this._connector.getNetwork();
53
+ });
54
+ }
55
+ /**
56
+ * If the wallet is connected.
57
+ * @returns A promise that resolves to true the wallet is connected or false if it's not connected.
58
+ */
59
+ isConnected() {
60
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
61
+ try {
62
+ const connectedAccounts = yield this._connector.getConnectedAccounts();
63
+ return connectedAccounts
64
+ .map((address) => normalizeAddress.normalizeAddress(address, this.chain))
65
+ .includes(normalizeAddress.normalizeAddress(this.address, this.chain));
66
+ }
67
+ catch (error) {
68
+ logger.logger.error('[Wallet] isConnected - Error detecting if wallet is connected', error);
69
+ return false;
70
+ }
71
+ });
72
+ }
73
+ /**
74
+ * Proves ownership of the wallet by signing a message.
75
+ * @param messageToSign - The message to sign.
76
+ * @returns A promise that resolves to the signature of the message as a string,
77
+ * or undefined if the message cannot be signed.
78
+ */
79
+ proveOwnership(messageToSign) {
80
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
81
+ return this._connector.proveOwnership(this.address, messageToSign);
82
+ });
83
+ }
84
+ /**
85
+ * Signs a message using the wallet.
86
+ * @param messageToSign - The message to sign.
87
+ * @returns A promise that resolves to the signature of the message as a string,
88
+ * or undefined if the message cannot be signed.
89
+ */
90
+ signMessage(messageToSign) {
91
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
92
+ yield this.sync();
93
+ return this._connector.signMessage(messageToSign, this.address);
94
+ });
95
+ }
96
+ /**
97
+ * Switches the network that the wallet is connected to.
98
+ * @param networkChainId - The chain id of the network to switch to.
99
+ * @returns A promise that resolves when the network is switched.
100
+ */
101
+ switchNetwork(networkChainId) {
102
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
103
+ return this._connector.switchNetwork({
104
+ networkChainId,
105
+ });
106
+ });
107
+ }
108
+ /**
109
+ * Synchronizes the wallet with the connector.
110
+ * @returns A promise that resolves when the wallet is connected and active.
111
+ */
112
+ sync() {
113
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
114
+ return this._connector.validateActiveWallet(this.address);
115
+ });
116
+ }
117
+ }
118
+
119
+ exports.Wallet = Wallet;
@@ -0,0 +1,65 @@
1
+ import type { BaseWalletProps } from '@dynamic-labs/types';
2
+ import { BaseWallet } from '@dynamic-labs/types';
3
+ import { WalletConnector, NameServiceData, InternalWalletConnector } from '../../';
4
+ export type WalletProps<T extends InternalWalletConnector = InternalWalletConnector> = BaseWalletProps & {
5
+ connector: T;
6
+ };
7
+ export declare class Wallet<T extends InternalWalletConnector = InternalWalletConnector> extends BaseWallet {
8
+ protected _connector: T;
9
+ constructor({ connector, ...props }: WalletProps<T>);
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
+ * If the wallet is connected.
34
+ * @returns A promise that resolves to true the wallet is connected or false if it's not connected.
35
+ */
36
+ isConnected(): Promise<boolean>;
37
+ /**
38
+ * Proves ownership of the wallet by signing a message.
39
+ * @param messageToSign - The message to sign.
40
+ * @returns A promise that resolves to the signature of the message as a string,
41
+ * or undefined if the message cannot be signed.
42
+ */
43
+ proveOwnership(messageToSign: string): Promise<string | undefined>;
44
+ /**
45
+ * Signs a message using the wallet.
46
+ * @param messageToSign - The message to sign.
47
+ * @returns A promise that resolves to the signature of the message as a string,
48
+ * or undefined if the message cannot be signed.
49
+ */
50
+ signMessage(messageToSign: string): Promise<string | undefined>;
51
+ /**
52
+ * Switches the network that the wallet is connected to.
53
+ * @param networkChainId - The chain id of the network to switch to.
54
+ * @returns A promise that resolves when the network is switched.
55
+ */
56
+ switchNetwork(networkChainId: number | string): Promise<void>;
57
+ /**
58
+ * Synchronizes the wallet with the connector.
59
+ * @returns A promise that resolves when the wallet is connected and active.
60
+ */
61
+ sync(): Promise<void>;
62
+ }
63
+ export interface WalletConstructor<T extends InternalWalletConnector> {
64
+ new (props: WalletProps<T>): Wallet<T>;
65
+ }