@dynamic-labs/wallet-connector-core 3.0.0-alpha.4 → 3.0.0-alpha.41
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 +373 -0
- package/_virtual/_tslib.cjs +21 -0
- package/_virtual/_tslib.js +20 -1
- package/package.json +7 -7
- package/src/index.cjs +4 -0
- package/src/index.js +2 -0
- package/src/lib/IAccountAbstractionWalletConnector.d.ts +6 -2
- package/src/lib/ISessionKeyCompatibleWalletConnector.d.ts +6 -2
- package/src/lib/ITurnkeyWalletConnectorStamper.d.ts +18 -0
- package/src/lib/WalletConnector.cjs +75 -15
- package/src/lib/WalletConnector.d.ts +33 -24
- package/src/lib/WalletConnector.js +75 -15
- package/src/lib/index.d.ts +2 -0
- package/src/lib/wallets/Wallet/Wallet.cjs +160 -0
- package/src/lib/wallets/Wallet/Wallet.d.ts +87 -0
- package/src/lib/wallets/Wallet/Wallet.js +156 -0
- package/src/lib/wallets/Wallet/index.d.ts +1 -0
- package/src/lib/wallets/index.d.ts +1 -0
- package/src/utils/getMobileExperience/getMobileExperience.cjs +24 -0
- package/src/utils/getMobileExperience/getMobileExperience.d.ts +7 -0
- package/src/utils/getMobileExperience/getMobileExperience.js +20 -0
- package/src/utils/getMobileExperience/index.d.ts +1 -0
- package/src/utils/index.d.ts +1 -0
|
@@ -6,6 +6,10 @@ 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');
|
|
11
|
+
var isSameAddress = require('../utils/isSameAddress/isSameAddress.cjs');
|
|
12
|
+
var getMobileExperience = require('../utils/getMobileExperience/getMobileExperience.cjs');
|
|
9
13
|
var WalletBookSingleton = require('./WalletBookSingleton.cjs');
|
|
10
14
|
|
|
11
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -77,21 +81,11 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
|
|
|
77
81
|
*/
|
|
78
82
|
this.canConnectViaSocial = false;
|
|
79
83
|
/**
|
|
80
|
-
*
|
|
81
|
-
* If you would like to still get the ethers web3Provider,
|
|
82
|
-
* see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
|
|
84
|
+
* Flag if connector/provider is available
|
|
83
85
|
*
|
|
84
|
-
*
|
|
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
|
|
86
|
+
* @default true
|
|
93
87
|
*/
|
|
94
|
-
this.
|
|
88
|
+
this.isAvailable = true;
|
|
95
89
|
/**
|
|
96
90
|
* If the wallet generated by a valid embedded wallet provider
|
|
97
91
|
* For example: magic wallets
|
|
@@ -134,6 +128,11 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
|
|
|
134
128
|
if (_tslib.__classPrivateFieldGet(this, _WalletConnectorBase_registeredExtensions, "f").includes(extension.name)) {
|
|
135
129
|
throw new Error(`You can only register a single extension of: ${extension.name}`);
|
|
136
130
|
}
|
|
131
|
+
if (extension.name === 'global-wallet-extension') {
|
|
132
|
+
// only allow global wallet extension for evm embedded wallets
|
|
133
|
+
if (!this.isEmbeddedWallet || !this.supportedChains.includes('EVM'))
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
137
136
|
_tslib.__classPrivateFieldGet(this, _WalletConnectorBase_registeredExtensions, "f").push(extension.name);
|
|
138
137
|
extension.extend(this);
|
|
139
138
|
}
|
|
@@ -159,6 +158,13 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
|
|
|
159
158
|
return false;
|
|
160
159
|
}
|
|
161
160
|
}
|
|
161
|
+
get mobileExperience() {
|
|
162
|
+
return getMobileExperience.getMobileExperience({
|
|
163
|
+
mobileExperienceProp: this.constructorProps.mobileExperience,
|
|
164
|
+
walletBook: this.walletBook,
|
|
165
|
+
walletKey: this.key,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
162
168
|
connect() {
|
|
163
169
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
164
170
|
yield this.getAddress();
|
|
@@ -182,6 +188,25 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
|
|
|
182
188
|
getAddress(opts) {
|
|
183
189
|
return Promise.resolve(undefined);
|
|
184
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Parses a public address to ensure it follows a correct format.
|
|
193
|
+
*
|
|
194
|
+
* For instance, with EVM wallets, this might ensure it follows the EIP 55 format.
|
|
195
|
+
*
|
|
196
|
+
* @default string
|
|
197
|
+
*/
|
|
198
|
+
parseAddress(address) {
|
|
199
|
+
return address;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Whether this wallet connector is targeting a testnet.
|
|
203
|
+
* So far only supported for EVM connectors.
|
|
204
|
+
*
|
|
205
|
+
* @default Promise<false>
|
|
206
|
+
*/
|
|
207
|
+
isTestnet() {
|
|
208
|
+
return Promise.resolve(false);
|
|
209
|
+
}
|
|
185
210
|
/**
|
|
186
211
|
* Gets the additional addresses of the wallet, given the main address
|
|
187
212
|
*
|
|
@@ -203,7 +228,7 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
|
|
|
203
228
|
*
|
|
204
229
|
* @default Promise<undefined>
|
|
205
230
|
*/
|
|
206
|
-
getBalance() {
|
|
231
|
+
getBalance(address) {
|
|
207
232
|
return Promise.resolve(undefined);
|
|
208
233
|
}
|
|
209
234
|
/**
|
|
@@ -230,7 +255,7 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
|
|
|
230
255
|
*
|
|
231
256
|
* @default Promise<undefined>
|
|
232
257
|
*/
|
|
233
|
-
getNameService() {
|
|
258
|
+
getNameService(address) {
|
|
234
259
|
return Promise.resolve(undefined);
|
|
235
260
|
}
|
|
236
261
|
getPublicClient() {
|
|
@@ -327,6 +352,41 @@ class WalletConnectorBase extends EventEmitter__default["default"] {
|
|
|
327
352
|
setVerifiedCredentials(verifiedCredentials) {
|
|
328
353
|
return;
|
|
329
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Validates if the address is connected and active in the wallet app
|
|
357
|
+
*
|
|
358
|
+
* @throws {WalletAddressMismatchError} If the active address does not match the expected address.
|
|
359
|
+
* @returns {Promise<void>} A promise that resolves if the active address matches the expected address,
|
|
360
|
+
* otherwise rejects with an error.
|
|
361
|
+
*/
|
|
362
|
+
validateActiveWallet(expectedAddress) {
|
|
363
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
364
|
+
var _a, _b;
|
|
365
|
+
const [activeAddress] = yield this.getConnectedAccounts();
|
|
366
|
+
const isWalletActive = isSameAddress.isSameAddress(activeAddress, expectedAddress, this.connectedChain);
|
|
367
|
+
logger.logger.debug(`validateActiveWallet - wallet ${isWalletActive ? 'is' : 'is not'} active`, {
|
|
368
|
+
activeAddress,
|
|
369
|
+
expectedAddress,
|
|
370
|
+
});
|
|
371
|
+
const walletUiUtils = this.constructorProps
|
|
372
|
+
.walletUiUtils;
|
|
373
|
+
if (isWalletActive) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (!walletUiUtils) {
|
|
377
|
+
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}.`, {
|
|
378
|
+
activeAddress,
|
|
379
|
+
expectedAddress,
|
|
380
|
+
walletName: (_b = this.name) !== null && _b !== void 0 ? _b : this.key,
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return walletUiUtils.syncWallet({
|
|
384
|
+
activeAddress,
|
|
385
|
+
expectedAddress,
|
|
386
|
+
walletConnector: this,
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
}
|
|
330
390
|
}
|
|
331
391
|
_WalletConnectorBase_registeredExtensions = new WeakMap();
|
|
332
392
|
|
|
@@ -2,6 +2,7 @@ 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';
|
|
@@ -70,6 +71,7 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
|
|
|
70
71
|
initEventListener(): void;
|
|
71
72
|
get walletBook(): WalletBookSchema;
|
|
72
73
|
filter(): boolean;
|
|
74
|
+
get mobileExperience(): MobileExperience | undefined;
|
|
73
75
|
/**
|
|
74
76
|
* This flag corresponds to whether this wallet connector also requires its own email otp outside dynamic
|
|
75
77
|
* @default false
|
|
@@ -120,6 +122,21 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
|
|
|
120
122
|
* @default Promise<undefined>
|
|
121
123
|
*/
|
|
122
124
|
getAddress(opts?: GetAddressOpts): Promise<string | undefined>;
|
|
125
|
+
/**
|
|
126
|
+
* Parses a public address to ensure it follows a correct format.
|
|
127
|
+
*
|
|
128
|
+
* For instance, with EVM wallets, this might ensure it follows the EIP 55 format.
|
|
129
|
+
*
|
|
130
|
+
* @default string
|
|
131
|
+
*/
|
|
132
|
+
parseAddress(address: string): string;
|
|
133
|
+
/**
|
|
134
|
+
* Whether this wallet connector is targeting a testnet.
|
|
135
|
+
* So far only supported for EVM connectors.
|
|
136
|
+
*
|
|
137
|
+
* @default Promise<false>
|
|
138
|
+
*/
|
|
139
|
+
isTestnet(): Promise<boolean>;
|
|
123
140
|
/**
|
|
124
141
|
* Gets the additional addresses of the wallet, given the main address
|
|
125
142
|
*
|
|
@@ -137,7 +154,7 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
|
|
|
137
154
|
*
|
|
138
155
|
* @default Promise<undefined>
|
|
139
156
|
*/
|
|
140
|
-
getBalance(): Promise<string | undefined>;
|
|
157
|
+
getBalance(address: string): Promise<string | undefined>;
|
|
141
158
|
/**
|
|
142
159
|
* Get the address silently
|
|
143
160
|
*
|
|
@@ -161,7 +178,7 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
|
|
|
161
178
|
*
|
|
162
179
|
* @default Promise<undefined>
|
|
163
180
|
*/
|
|
164
|
-
getNameService(): Promise<NameServiceData | undefined>;
|
|
181
|
+
getNameService(address: string): Promise<NameServiceData | undefined>;
|
|
165
182
|
/**
|
|
166
183
|
* Get the RPC provider for the wallet
|
|
167
184
|
*
|
|
@@ -169,28 +186,6 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
|
|
|
169
186
|
*/
|
|
170
187
|
getPublicClient(): Promise<unknown>;
|
|
171
188
|
getPublicClient<T>(): Promise<T>;
|
|
172
|
-
/**
|
|
173
|
-
* @deprecated getWeb3Provider has been renamed to getWalletClient
|
|
174
|
-
* If you would like to still get the ethers web3Provider,
|
|
175
|
-
* see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
|
|
176
|
-
*
|
|
177
|
-
* Get the wallet provider
|
|
178
|
-
*/
|
|
179
|
-
getWeb3Provider: {
|
|
180
|
-
(chainId?: string): unknown;
|
|
181
|
-
<T>(chainId?: string): T;
|
|
182
|
-
};
|
|
183
|
-
/**
|
|
184
|
-
* @deprecated getRpcProvider has been renamed to getPublicClient
|
|
185
|
-
* If you would like to still get the ethers rpcProvider,
|
|
186
|
-
* see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
|
|
187
|
-
*
|
|
188
|
-
* Get the rpc provider
|
|
189
|
-
*/
|
|
190
|
-
getRpcProvider: {
|
|
191
|
-
(): Promise<unknown>;
|
|
192
|
-
<T>(): Promise<T>;
|
|
193
|
-
};
|
|
194
189
|
/**
|
|
195
190
|
* Get the session for the wallet
|
|
196
191
|
* @default Promise<undefined>
|
|
@@ -217,6 +212,12 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
|
|
|
217
212
|
* @default Promise<void>
|
|
218
213
|
*/
|
|
219
214
|
init(): Promise<void>;
|
|
215
|
+
/**
|
|
216
|
+
* Flag if connector/provider is available
|
|
217
|
+
*
|
|
218
|
+
* @default true
|
|
219
|
+
*/
|
|
220
|
+
isAvailable: boolean;
|
|
220
221
|
/**
|
|
221
222
|
* If the wallet generated by a valid embedded wallet provider
|
|
222
223
|
* For example: magic wallets
|
|
@@ -316,4 +317,12 @@ export declare abstract class WalletConnectorBase extends EventEmitter<WalletCon
|
|
|
316
317
|
* Receive the user verified credentials
|
|
317
318
|
*/
|
|
318
319
|
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
320
|
+
/**
|
|
321
|
+
* Validates if the address is connected and active in the wallet app
|
|
322
|
+
*
|
|
323
|
+
* @throws {WalletAddressMismatchError} If the active address does not match the expected address.
|
|
324
|
+
* @returns {Promise<void>} A promise that resolves if the active address matches the expected address,
|
|
325
|
+
* otherwise rejects with an error.
|
|
326
|
+
*/
|
|
327
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
319
328
|
}
|
|
@@ -2,6 +2,10 @@
|
|
|
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';
|
|
5
9
|
import { WalletBookSingleton } from './WalletBookSingleton.js';
|
|
6
10
|
|
|
7
11
|
/* eslint-disable @typescript-eslint/triple-slash-reference */
|
|
@@ -69,21 +73,11 @@ class WalletConnectorBase extends EventEmitter {
|
|
|
69
73
|
*/
|
|
70
74
|
this.canConnectViaSocial = false;
|
|
71
75
|
/**
|
|
72
|
-
*
|
|
73
|
-
* If you would like to still get the ethers web3Provider,
|
|
74
|
-
* see our docs for enabling ethers: https://docs.dynamic.xyz/ethers
|
|
76
|
+
* Flag if connector/provider is available
|
|
75
77
|
*
|
|
76
|
-
*
|
|
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
|
|
78
|
+
* @default true
|
|
85
79
|
*/
|
|
86
|
-
this.
|
|
80
|
+
this.isAvailable = true;
|
|
87
81
|
/**
|
|
88
82
|
* If the wallet generated by a valid embedded wallet provider
|
|
89
83
|
* For example: magic wallets
|
|
@@ -126,6 +120,11 @@ class WalletConnectorBase extends EventEmitter {
|
|
|
126
120
|
if (__classPrivateFieldGet(this, _WalletConnectorBase_registeredExtensions, "f").includes(extension.name)) {
|
|
127
121
|
throw new Error(`You can only register a single extension of: ${extension.name}`);
|
|
128
122
|
}
|
|
123
|
+
if (extension.name === 'global-wallet-extension') {
|
|
124
|
+
// only allow global wallet extension for evm embedded wallets
|
|
125
|
+
if (!this.isEmbeddedWallet || !this.supportedChains.includes('EVM'))
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
129
128
|
__classPrivateFieldGet(this, _WalletConnectorBase_registeredExtensions, "f").push(extension.name);
|
|
130
129
|
extension.extend(this);
|
|
131
130
|
}
|
|
@@ -151,6 +150,13 @@ class WalletConnectorBase extends EventEmitter {
|
|
|
151
150
|
return false;
|
|
152
151
|
}
|
|
153
152
|
}
|
|
153
|
+
get mobileExperience() {
|
|
154
|
+
return getMobileExperience({
|
|
155
|
+
mobileExperienceProp: this.constructorProps.mobileExperience,
|
|
156
|
+
walletBook: this.walletBook,
|
|
157
|
+
walletKey: this.key,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
154
160
|
connect() {
|
|
155
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
162
|
yield this.getAddress();
|
|
@@ -174,6 +180,25 @@ class WalletConnectorBase extends EventEmitter {
|
|
|
174
180
|
getAddress(opts) {
|
|
175
181
|
return Promise.resolve(undefined);
|
|
176
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Parses a public address to ensure it follows a correct format.
|
|
185
|
+
*
|
|
186
|
+
* For instance, with EVM wallets, this might ensure it follows the EIP 55 format.
|
|
187
|
+
*
|
|
188
|
+
* @default string
|
|
189
|
+
*/
|
|
190
|
+
parseAddress(address) {
|
|
191
|
+
return address;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Whether this wallet connector is targeting a testnet.
|
|
195
|
+
* So far only supported for EVM connectors.
|
|
196
|
+
*
|
|
197
|
+
* @default Promise<false>
|
|
198
|
+
*/
|
|
199
|
+
isTestnet() {
|
|
200
|
+
return Promise.resolve(false);
|
|
201
|
+
}
|
|
177
202
|
/**
|
|
178
203
|
* Gets the additional addresses of the wallet, given the main address
|
|
179
204
|
*
|
|
@@ -195,7 +220,7 @@ class WalletConnectorBase extends EventEmitter {
|
|
|
195
220
|
*
|
|
196
221
|
* @default Promise<undefined>
|
|
197
222
|
*/
|
|
198
|
-
getBalance() {
|
|
223
|
+
getBalance(address) {
|
|
199
224
|
return Promise.resolve(undefined);
|
|
200
225
|
}
|
|
201
226
|
/**
|
|
@@ -222,7 +247,7 @@ class WalletConnectorBase extends EventEmitter {
|
|
|
222
247
|
*
|
|
223
248
|
* @default Promise<undefined>
|
|
224
249
|
*/
|
|
225
|
-
getNameService() {
|
|
250
|
+
getNameService(address) {
|
|
226
251
|
return Promise.resolve(undefined);
|
|
227
252
|
}
|
|
228
253
|
getPublicClient() {
|
|
@@ -319,6 +344,41 @@ class WalletConnectorBase extends EventEmitter {
|
|
|
319
344
|
setVerifiedCredentials(verifiedCredentials) {
|
|
320
345
|
return;
|
|
321
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Validates if the address is connected and active in the wallet app
|
|
349
|
+
*
|
|
350
|
+
* @throws {WalletAddressMismatchError} If the active address does not match the expected address.
|
|
351
|
+
* @returns {Promise<void>} A promise that resolves if the active address matches the expected address,
|
|
352
|
+
* otherwise rejects with an error.
|
|
353
|
+
*/
|
|
354
|
+
validateActiveWallet(expectedAddress) {
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
var _a, _b;
|
|
357
|
+
const [activeAddress] = yield this.getConnectedAccounts();
|
|
358
|
+
const isWalletActive = isSameAddress(activeAddress, expectedAddress, this.connectedChain);
|
|
359
|
+
logger.debug(`validateActiveWallet - wallet ${isWalletActive ? 'is' : 'is not'} active`, {
|
|
360
|
+
activeAddress,
|
|
361
|
+
expectedAddress,
|
|
362
|
+
});
|
|
363
|
+
const walletUiUtils = this.constructorProps
|
|
364
|
+
.walletUiUtils;
|
|
365
|
+
if (isWalletActive) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (!walletUiUtils) {
|
|
369
|
+
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}.`, {
|
|
370
|
+
activeAddress,
|
|
371
|
+
expectedAddress,
|
|
372
|
+
walletName: (_b = this.name) !== null && _b !== void 0 ? _b : this.key,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
return walletUiUtils.syncWallet({
|
|
376
|
+
activeAddress,
|
|
377
|
+
expectedAddress,
|
|
378
|
+
walletConnector: this,
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
}
|
|
322
382
|
}
|
|
323
383
|
_WalletConnectorBase_registeredExtensions = new WeakMap();
|
|
324
384
|
|
package/src/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './IEmailWalletConnector';
|
|
|
3
3
|
export * from './WalletConnector';
|
|
4
4
|
export * from './types';
|
|
5
5
|
export * from './IPasskeyWalletConnector';
|
|
6
|
+
export * from './ITurnkeyWalletConnectorStamper';
|
|
6
7
|
export * from './SmartWalletConnector';
|
|
7
8
|
export * from './IAccountAbstractionWalletConnector';
|
|
8
9
|
export * from './IBitcoinWalletConnector';
|
|
@@ -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,160 @@
|
|
|
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
|
+
require('@dynamic-labs/utils');
|
|
10
|
+
require('@dynamic-labs/wallet-book');
|
|
11
|
+
|
|
12
|
+
var _Wallet_connector;
|
|
13
|
+
class Wallet extends types.BaseWallet {
|
|
14
|
+
constructor(_a) {
|
|
15
|
+
var { connector } = _a, props = _tslib.__rest(_a, ["connector"]);
|
|
16
|
+
super(props);
|
|
17
|
+
_Wallet_connector.set(this, void 0);
|
|
18
|
+
_tslib.__classPrivateFieldSet(this, _Wallet_connector, connector, "f");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets the wallet connector.
|
|
22
|
+
*/
|
|
23
|
+
get connector() {
|
|
24
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the balance of the wallet.
|
|
28
|
+
* @returns A promise that resolves to the balance of the wallet as a string,
|
|
29
|
+
* or undefined if the balance cannot be retrieved.
|
|
30
|
+
*/
|
|
31
|
+
getBalance() {
|
|
32
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getBalance(this.address);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves the name service data associated with the wallet.
|
|
38
|
+
* @returns A promise that resolves to the name service data of the wallet,
|
|
39
|
+
* or undefined if the data cannot be retrieved.
|
|
40
|
+
*/
|
|
41
|
+
getNameService() {
|
|
42
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getNameService(this.address);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the network that the wallet is connected to.
|
|
48
|
+
* @returns A promise that resolves to the network value as a string or number,
|
|
49
|
+
* or undefined if the network cannot be retrieved.
|
|
50
|
+
*/
|
|
51
|
+
getNetwork() {
|
|
52
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getNetwork();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves the rpc provider for the wallet.
|
|
58
|
+
* @returns A promise that resolves to the provider,
|
|
59
|
+
* or undefined if the provider cannot be retrieved.
|
|
60
|
+
*/
|
|
61
|
+
getPublicClient() {
|
|
62
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getPublicClient();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves the signer for the wallet.
|
|
68
|
+
* @returns A promise that resolves to the signer,
|
|
69
|
+
* or undefined if the signer cannot be retrieved.
|
|
70
|
+
*/
|
|
71
|
+
getSigner() {
|
|
72
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
yield this.sync();
|
|
74
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getSigner();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves the wallet client.
|
|
79
|
+
* @param chainId - (optional) Chain id to be used by the wallet client.
|
|
80
|
+
* @returns A promise that resolves to the wallet client,
|
|
81
|
+
* or undefined if the wallet client cannot be retrieved.
|
|
82
|
+
*/
|
|
83
|
+
getWalletClient(chainId) {
|
|
84
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
yield this.sync();
|
|
86
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getWalletClient(chainId);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* If the wallet is availble to use. A wallet is available if its provider is available.
|
|
91
|
+
* @returns True if the wallet is available, false otherwise.
|
|
92
|
+
*/
|
|
93
|
+
isAvailable() {
|
|
94
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").isAvailable;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* If the wallet is connected.
|
|
98
|
+
* @returns A promise that resolves to true the wallet is connected or false if it's not connected.
|
|
99
|
+
*/
|
|
100
|
+
isConnected() {
|
|
101
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
try {
|
|
103
|
+
const connectedAccounts = yield _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").getConnectedAccounts();
|
|
104
|
+
return connectedAccounts.includes(this.address);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
logger.logger.error('[Wallet] isConnected - Error detecting if wallet is connected', error);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Proves ownership of the wallet by signing a message.
|
|
114
|
+
* @param messageToSign - The message to sign.
|
|
115
|
+
* @returns A promise that resolves to the signature of the message as a string,
|
|
116
|
+
* or undefined if the message cannot be signed.
|
|
117
|
+
*/
|
|
118
|
+
proveOwnership(messageToSign) {
|
|
119
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
yield this.sync();
|
|
121
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").proveOwnership(messageToSign);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Signs a message using the wallet.
|
|
126
|
+
* @param messageToSign - The message to sign.
|
|
127
|
+
* @returns A promise that resolves to the signature of the message as a string,
|
|
128
|
+
* or undefined if the message cannot be signed.
|
|
129
|
+
*/
|
|
130
|
+
signMessage(messageToSign) {
|
|
131
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
yield this.sync();
|
|
133
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").signMessage(messageToSign);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Switches the network that the wallet is connected to.
|
|
138
|
+
* @param networkChainId - The chain id of the network to switch to.
|
|
139
|
+
* @returns A promise that resolves when the network is switched.
|
|
140
|
+
*/
|
|
141
|
+
switchNetwork(networkChainId) {
|
|
142
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").switchNetwork({
|
|
144
|
+
networkChainId,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Synchronizes the wallet with the connector.
|
|
150
|
+
* @returns A promise that resolves when the wallet is connected and active.
|
|
151
|
+
*/
|
|
152
|
+
sync() {
|
|
153
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
return _tslib.__classPrivateFieldGet(this, _Wallet_connector, "f").validateActiveWallet(this.address);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
_Wallet_connector = new WeakMap();
|
|
159
|
+
|
|
160
|
+
exports.Wallet = Wallet;
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
* If the wallet is availble to use. A wallet is available if its provider is available.
|
|
53
|
+
* @returns True if the wallet is available, false otherwise.
|
|
54
|
+
*/
|
|
55
|
+
isAvailable(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* If the wallet is connected.
|
|
58
|
+
* @returns A promise that resolves to true the wallet is connected or false if it's not connected.
|
|
59
|
+
*/
|
|
60
|
+
isConnected(): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Proves ownership of the wallet by signing a message.
|
|
63
|
+
* @param messageToSign - The message to sign.
|
|
64
|
+
* @returns A promise that resolves to the signature of the message as a string,
|
|
65
|
+
* or undefined if the message cannot be signed.
|
|
66
|
+
*/
|
|
67
|
+
proveOwnership(messageToSign: string): Promise<string | undefined>;
|
|
68
|
+
/**
|
|
69
|
+
* Signs a message using the wallet.
|
|
70
|
+
* @param messageToSign - The message to sign.
|
|
71
|
+
* @returns A promise that resolves to the signature of the message as a string,
|
|
72
|
+
* or undefined if the message cannot be signed.
|
|
73
|
+
*/
|
|
74
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
75
|
+
/**
|
|
76
|
+
* Switches the network that the wallet is connected to.
|
|
77
|
+
* @param networkChainId - The chain id of the network to switch to.
|
|
78
|
+
* @returns A promise that resolves when the network is switched.
|
|
79
|
+
*/
|
|
80
|
+
switchNetwork(networkChainId: number | string): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Synchronizes the wallet with the connector.
|
|
83
|
+
* @returns A promise that resolves when the wallet is connected and active.
|
|
84
|
+
*/
|
|
85
|
+
sync(): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
export {};
|