@dynamic-labs-wallet/browser 0.0.16 → 0.0.17
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/index.cjs.js +174 -48
- package/index.esm.js +146 -20
- package/package.json +4 -3
- package/src/client.d.ts +18 -15
- package/src/client.d.ts.map +1 -1
- package/src/constants.d.ts +8 -0
- package/src/constants.d.ts.map +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.d.ts.map +1 -1
- package/src/localStorage.d.ts +32 -0
- package/src/localStorage.d.ts.map +1 -0
- package/src/logger.d.ts +3 -0
- package/src/logger.d.ts.map +1 -0
- package/src/mpc/index.d.ts +1 -0
- package/src/mpc/index.d.ts.map +1 -1
- package/src/services/localStorage.d.ts +32 -0
- package/src/services/localStorage.d.ts.map +1 -0
- package/src/services/logger.d.ts +3 -0
- package/src/services/logger.d.ts.map +1 -0
- package/src/types.d.ts +21 -0
- package/src/types.d.ts.map +1 -0
- package/src/utils.d.ts +1 -0
- package/src/utils.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@dynamic-labs-wallet/core');
|
|
4
4
|
var libMpcWeb = require('@dynamic-labs-wallet/lib-mpc-web');
|
|
5
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
6
|
+
|
|
7
|
+
function _extends() {
|
|
8
|
+
_extends = Object.assign || function assign(target) {
|
|
9
|
+
for(var i = 1; i < arguments.length; i++){
|
|
10
|
+
var source = arguments[i];
|
|
11
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
12
|
+
}
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
return _extends.apply(this, arguments);
|
|
16
|
+
}
|
|
5
17
|
|
|
6
18
|
const getMPCSignatureScheme = ({ signingAlgorithm, baseRelayUrl = core.MPC_RELAY_PROD_API_URL })=>{
|
|
7
19
|
switch(signingAlgorithm){
|
|
@@ -24,17 +36,6 @@ const getMPCSigner = ({ chainName, baseRelayUrl })=>{
|
|
|
24
36
|
return signatureScheme;
|
|
25
37
|
};
|
|
26
38
|
|
|
27
|
-
function _extends() {
|
|
28
|
-
_extends = Object.assign || function assign(target) {
|
|
29
|
-
for(var i = 1; i < arguments.length; i++){
|
|
30
|
-
var source = arguments[i];
|
|
31
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
32
|
-
}
|
|
33
|
-
return target;
|
|
34
|
-
};
|
|
35
|
-
return _extends.apply(this, arguments);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
39
|
const bytesToBase64 = (arr)=>{
|
|
39
40
|
return btoa(Array.from(arr, (b)=>String.fromCharCode(b)).join(''));
|
|
40
41
|
};
|
|
@@ -48,6 +49,7 @@ const base64ToBytes = (base64)=>{
|
|
|
48
49
|
const ensureBase64Padding = (str)=>{
|
|
49
50
|
return str.padEnd(Math.ceil(str.length / 4) * 4, '=');
|
|
50
51
|
};
|
|
52
|
+
const isBrowser = ()=>typeof window !== 'undefined';
|
|
51
53
|
|
|
52
54
|
const getKey = async ({ password, salt })=>{
|
|
53
55
|
const passwordBytes = stringToBytes(password);
|
|
@@ -190,9 +192,108 @@ const downloadFileFromGoogleDrive = async ({ accessToken, name })=>{
|
|
|
190
192
|
return fileRawData;
|
|
191
193
|
};
|
|
192
194
|
|
|
195
|
+
const DEFAULT_LOG_LEVEL = 'INFO';
|
|
196
|
+
const STORAGE_KEY = 'dynamic-waas-wallet-client';
|
|
193
197
|
const BACKUP_FILENAME = 'dynamicWalletSecretBackup.json';
|
|
194
198
|
|
|
199
|
+
const localStorageWriteTest = {
|
|
200
|
+
tested: false,
|
|
201
|
+
writable: false
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Checks whether localStorage is supported on this browser.
|
|
205
|
+
*/ const supportsLocalStorage = ()=>{
|
|
206
|
+
if (!isBrowser()) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
if (typeof globalThis.localStorage !== 'object') {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
} catch (e) {
|
|
214
|
+
// DOM exception when accessing `localStorage`
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
if (localStorageWriteTest.tested) {
|
|
218
|
+
return localStorageWriteTest.writable;
|
|
219
|
+
}
|
|
220
|
+
const randomKey = `lswt-${Math.random()}${Math.random()}`;
|
|
221
|
+
try {
|
|
222
|
+
globalThis.localStorage.setItem(randomKey, randomKey);
|
|
223
|
+
globalThis.localStorage.removeItem(randomKey);
|
|
224
|
+
localStorageWriteTest.tested = true;
|
|
225
|
+
localStorageWriteTest.writable = true;
|
|
226
|
+
} catch (e) {
|
|
227
|
+
// localStorage can't be written to
|
|
228
|
+
localStorageWriteTest.tested = true;
|
|
229
|
+
localStorageWriteTest.writable = false;
|
|
230
|
+
}
|
|
231
|
+
return localStorageWriteTest.writable;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Provides safe access to the globalThis.localStorage property.
|
|
235
|
+
*/ const localStorageAdapter = {
|
|
236
|
+
getItem: (key)=>{
|
|
237
|
+
if (!supportsLocalStorage()) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
return globalThis.localStorage.getItem(key);
|
|
241
|
+
},
|
|
242
|
+
removeItem: (key)=>{
|
|
243
|
+
if (!supportsLocalStorage()) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
globalThis.localStorage.removeItem(key);
|
|
247
|
+
},
|
|
248
|
+
setItem: (key, value)=>{
|
|
249
|
+
if (!supportsLocalStorage()) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
globalThis.localStorage.setItem(key, value);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Returns a localStorage-like object that stores the key-value pairs in
|
|
257
|
+
* memory.
|
|
258
|
+
*/ const memoryLocalStorageAdapter = (store = {})=>({
|
|
259
|
+
getItem: (key)=>store[key] || null,
|
|
260
|
+
removeItem: (key)=>{
|
|
261
|
+
delete store[key];
|
|
262
|
+
},
|
|
263
|
+
setItem: (key, value)=>{
|
|
264
|
+
store[key] = value;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const logger = new logger$1.Logger('DynamicWaasWalletClient');
|
|
269
|
+
|
|
195
270
|
class DynamicWalletClient {
|
|
271
|
+
async initialize() {
|
|
272
|
+
if (this.initializePromise) {
|
|
273
|
+
return await this.initializePromise;
|
|
274
|
+
}
|
|
275
|
+
this.logger.debug('Initializing Dynamic Waas Wallet SDK');
|
|
276
|
+
this.initializePromise = this._initialize();
|
|
277
|
+
const result = await this.initializePromise;
|
|
278
|
+
this.logger.debug('Dynamic Waas Wallet SDK initialized');
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Client initialization logic
|
|
283
|
+
*/ async _initialize() {
|
|
284
|
+
try {
|
|
285
|
+
const initializePromises = [];
|
|
286
|
+
initializePromises.push(this.restoreWallets());
|
|
287
|
+
await Promise.all(initializePromises);
|
|
288
|
+
return {
|
|
289
|
+
error: null
|
|
290
|
+
};
|
|
291
|
+
} catch (error) {
|
|
292
|
+
return {
|
|
293
|
+
error
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
196
297
|
async serverInitializeKeyGen({ chainName, clientKeygenIds, thresholdSignatureScheme }) {
|
|
197
298
|
// Initilize keygen, create room, and create the wallet account on the server
|
|
198
299
|
const data = await this.apiClient.createWalletAccount({
|
|
@@ -280,7 +381,7 @@ class DynamicWalletClient {
|
|
|
280
381
|
clientKeyShares
|
|
281
382
|
};
|
|
282
383
|
} catch (error) {
|
|
283
|
-
|
|
384
|
+
this.logger.error('Error creating wallet account', error);
|
|
284
385
|
throw new Error('Error creating wallet account');
|
|
285
386
|
}
|
|
286
387
|
}
|
|
@@ -317,7 +418,7 @@ class DynamicWalletClient {
|
|
|
317
418
|
const signature = await mpcSigner.sign(roomId, keyShare, formattedMessage, derivationPath);
|
|
318
419
|
return signature;
|
|
319
420
|
} catch (error) {
|
|
320
|
-
|
|
421
|
+
this.logger.error('Error in clientSign:', error);
|
|
321
422
|
throw error;
|
|
322
423
|
}
|
|
323
424
|
}
|
|
@@ -325,6 +426,7 @@ class DynamicWalletClient {
|
|
|
325
426
|
const wallet = await this.getWallet({
|
|
326
427
|
accountAddress
|
|
327
428
|
});
|
|
429
|
+
this.logger.debug('signing wallet', wallet);
|
|
328
430
|
// Perform the server sign
|
|
329
431
|
const data = await this.serverSign({
|
|
330
432
|
walletId: wallet.walletId,
|
|
@@ -412,8 +514,8 @@ class DynamicWalletClient {
|
|
|
412
514
|
data.serverKeygenId,
|
|
413
515
|
newPartyInitKeygenId
|
|
414
516
|
];
|
|
415
|
-
|
|
416
|
-
|
|
517
|
+
this.logger.debug('newClientPrimaryKeygenIds', newClientPrimaryKeygenIds);
|
|
518
|
+
this.logger.debug('clientSecondaryKeygenIds', clientSecondaryKeygenIds);
|
|
417
519
|
const keygenResults = await Promise.all([
|
|
418
520
|
mpcSigner.reshareNewParty(roomId, mpcConfig.threshold, mpcConfig.threshold, newPartyInitKeygen, newClientPrimaryKeygenIds),
|
|
419
521
|
mpcSigner.reshareRemainingParty(roomId, mpcConfig.threshold, wallet.clientKeyShares[1], clientSecondaryKeygenIds)
|
|
@@ -542,7 +644,15 @@ class DynamicWalletClient {
|
|
|
542
644
|
});
|
|
543
645
|
return decryptedKeyShares;
|
|
544
646
|
}
|
|
545
|
-
|
|
647
|
+
async restoreWallets() {
|
|
648
|
+
const wallets = await this.storage.getItem(this.storageKey);
|
|
649
|
+
console.log('local storage wallets', wallets);
|
|
650
|
+
if (!wallets) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
this.walletMap = JSON.parse(wallets);
|
|
654
|
+
}
|
|
655
|
+
async restoreBackupShare({ walletId, accountAddress, chainName, keyShare, thresholdSignatureScheme }) {
|
|
546
656
|
var _this_walletMap_accountAddress;
|
|
547
657
|
this.walletMap[accountAddress] = {
|
|
548
658
|
walletId,
|
|
@@ -554,6 +664,7 @@ class DynamicWalletClient {
|
|
|
554
664
|
],
|
|
555
665
|
thresholdSignatureScheme
|
|
556
666
|
};
|
|
667
|
+
await this.storage.setItem(this.storageKey, JSON.stringify(this.walletMap));
|
|
557
668
|
}
|
|
558
669
|
async backupFileToGoogleDrive({ oauthAccountId, fileName = BACKUP_FILENAME, jsonData, password }) {
|
|
559
670
|
const encryptedKeyShare = await this.encryptKeyShare({
|
|
@@ -657,16 +768,17 @@ class DynamicWalletClient {
|
|
|
657
768
|
var _user_verifiedCredentials;
|
|
658
769
|
const user = await this.apiClient.getUser();
|
|
659
770
|
const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? undefined : _user_verifiedCredentials.find((vc)=>vc.address === accountAddress);
|
|
771
|
+
this.logger.debug('need to restore wallet', wallet);
|
|
660
772
|
console.log('need to restore wallet', wallet);
|
|
661
773
|
const clientShares = wallet.walletProperties.keyShares.filter((ks)=>ks.backupLocation === 'dynamic');
|
|
662
|
-
|
|
774
|
+
this.logger.debug('clientShares', clientShares);
|
|
663
775
|
// restore backup
|
|
664
776
|
const decryptedKeyShares = await this.recoverEncryptedBackupByWallet({
|
|
665
777
|
accountAddress,
|
|
666
778
|
password: this.environmentId
|
|
667
779
|
});
|
|
668
780
|
//todo: check to see if their are other backups ie google drive, etc
|
|
669
|
-
|
|
781
|
+
this.logger.debug('recovery decryptedKeyShares', decryptedKeyShares);
|
|
670
782
|
}
|
|
671
783
|
}
|
|
672
784
|
const walletCount = Object.keys(this.walletMap).length;
|
|
@@ -704,74 +816,88 @@ class DynamicWalletClient {
|
|
|
704
816
|
}, {});
|
|
705
817
|
return wallets;
|
|
706
818
|
}
|
|
707
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl }){
|
|
819
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug }){
|
|
820
|
+
this.initializePromise = null;
|
|
821
|
+
this.logger = logger;
|
|
708
822
|
this.walletMap = {} // todo: store in session storage
|
|
709
823
|
;
|
|
824
|
+
this.memoryStorage = null;
|
|
710
825
|
this.environmentId = environmentId;
|
|
826
|
+
this.storageKey = `${STORAGE_KEY}-${storageKey != null ? storageKey : environmentId}`;
|
|
711
827
|
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
712
828
|
this.apiClient = new core.DynamicApiClient({
|
|
713
829
|
environmentId,
|
|
714
830
|
authToken,
|
|
715
831
|
baseApiUrl
|
|
716
832
|
});
|
|
717
|
-
this.
|
|
833
|
+
this.debug = Boolean(debug);
|
|
834
|
+
this.logger.setLogLevel(this.debug ? 'DEBUG' : DEFAULT_LOG_LEVEL);
|
|
835
|
+
// setup storage
|
|
836
|
+
if (supportsLocalStorage()) {
|
|
837
|
+
this.storage = localStorageAdapter;
|
|
838
|
+
} else {
|
|
839
|
+
this.memoryStorage = {};
|
|
840
|
+
this.storage = memoryLocalStorageAdapter(this.memoryStorage);
|
|
841
|
+
}
|
|
842
|
+
// initialize the client
|
|
843
|
+
this.initialize();
|
|
718
844
|
}
|
|
719
845
|
}
|
|
720
846
|
|
|
721
847
|
Object.defineProperty(exports, "BIP340", {
|
|
722
|
-
|
|
723
|
-
|
|
848
|
+
enumerable: true,
|
|
849
|
+
get: function () { return libMpcWeb.BIP340; }
|
|
724
850
|
});
|
|
725
851
|
Object.defineProperty(exports, "BIP340InitKeygenResult", {
|
|
726
|
-
|
|
727
|
-
|
|
852
|
+
enumerable: true,
|
|
853
|
+
get: function () { return libMpcWeb.BIP340InitKeygenResult; }
|
|
728
854
|
});
|
|
729
855
|
Object.defineProperty(exports, "BIP340KeygenResult", {
|
|
730
|
-
|
|
731
|
-
|
|
856
|
+
enumerable: true,
|
|
857
|
+
get: function () { return libMpcWeb.BIP340KeygenResult; }
|
|
732
858
|
});
|
|
733
859
|
Object.defineProperty(exports, "Ecdsa", {
|
|
734
|
-
|
|
735
|
-
|
|
860
|
+
enumerable: true,
|
|
861
|
+
get: function () { return libMpcWeb.Ecdsa; }
|
|
736
862
|
});
|
|
737
863
|
Object.defineProperty(exports, "EcdsaInitKeygenResult", {
|
|
738
|
-
|
|
739
|
-
|
|
864
|
+
enumerable: true,
|
|
865
|
+
get: function () { return libMpcWeb.EcdsaInitKeygenResult; }
|
|
740
866
|
});
|
|
741
867
|
Object.defineProperty(exports, "EcdsaKeygenResult", {
|
|
742
|
-
|
|
743
|
-
|
|
868
|
+
enumerable: true,
|
|
869
|
+
get: function () { return libMpcWeb.EcdsaKeygenResult; }
|
|
744
870
|
});
|
|
745
871
|
Object.defineProperty(exports, "EcdsaPublicKey", {
|
|
746
|
-
|
|
747
|
-
|
|
872
|
+
enumerable: true,
|
|
873
|
+
get: function () { return libMpcWeb.EcdsaPublicKey; }
|
|
748
874
|
});
|
|
749
875
|
Object.defineProperty(exports, "EcdsaSignature", {
|
|
750
|
-
|
|
751
|
-
|
|
876
|
+
enumerable: true,
|
|
877
|
+
get: function () { return libMpcWeb.EcdsaSignature; }
|
|
752
878
|
});
|
|
753
879
|
Object.defineProperty(exports, "Ed25519", {
|
|
754
|
-
|
|
755
|
-
|
|
880
|
+
enumerable: true,
|
|
881
|
+
get: function () { return libMpcWeb.Ed25519; }
|
|
756
882
|
});
|
|
757
883
|
Object.defineProperty(exports, "Ed25519InitKeygenResult", {
|
|
758
|
-
|
|
759
|
-
|
|
884
|
+
enumerable: true,
|
|
885
|
+
get: function () { return libMpcWeb.Ed25519InitKeygenResult; }
|
|
760
886
|
});
|
|
761
887
|
Object.defineProperty(exports, "Ed25519KeygenResult", {
|
|
762
|
-
|
|
763
|
-
|
|
888
|
+
enumerable: true,
|
|
889
|
+
get: function () { return libMpcWeb.Ed25519KeygenResult; }
|
|
764
890
|
});
|
|
765
891
|
Object.defineProperty(exports, "MessageHash", {
|
|
766
|
-
|
|
767
|
-
|
|
892
|
+
enumerable: true,
|
|
893
|
+
get: function () { return libMpcWeb.MessageHash; }
|
|
768
894
|
});
|
|
769
895
|
exports.DynamicWalletClient = DynamicWalletClient;
|
|
770
896
|
exports.getMPCSignatureScheme = getMPCSignatureScheme;
|
|
771
897
|
exports.getMPCSigner = getMPCSigner;
|
|
772
898
|
Object.keys(core).forEach(function (k) {
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
899
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
900
|
+
enumerable: true,
|
|
901
|
+
get: function () { return core[k]; }
|
|
902
|
+
});
|
|
777
903
|
});
|
package/index.esm.js
CHANGED
|
@@ -2,6 +2,18 @@ import { SigningAlgorithm, MPC_RELAY_PROD_API_URL, getMPCChainConfig, getClientT
|
|
|
2
2
|
export * from '@dynamic-labs-wallet/core';
|
|
3
3
|
import { BIP340, Ed25519, Ecdsa, MessageHash, EcdsaKeygenResult, Ed25519KeygenResult, BIP340KeygenResult } from '@dynamic-labs-wallet/lib-mpc-web';
|
|
4
4
|
export { BIP340, BIP340InitKeygenResult, BIP340KeygenResult, Ecdsa, EcdsaInitKeygenResult, EcdsaKeygenResult, EcdsaPublicKey, EcdsaSignature, Ed25519, Ed25519InitKeygenResult, Ed25519KeygenResult, MessageHash } from '@dynamic-labs-wallet/lib-mpc-web';
|
|
5
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
6
|
+
|
|
7
|
+
function _extends() {
|
|
8
|
+
_extends = Object.assign || function assign(target) {
|
|
9
|
+
for(var i = 1; i < arguments.length; i++){
|
|
10
|
+
var source = arguments[i];
|
|
11
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
12
|
+
}
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
return _extends.apply(this, arguments);
|
|
16
|
+
}
|
|
5
17
|
|
|
6
18
|
const getMPCSignatureScheme = ({ signingAlgorithm, baseRelayUrl = MPC_RELAY_PROD_API_URL })=>{
|
|
7
19
|
switch(signingAlgorithm){
|
|
@@ -24,17 +36,6 @@ const getMPCSigner = ({ chainName, baseRelayUrl })=>{
|
|
|
24
36
|
return signatureScheme;
|
|
25
37
|
};
|
|
26
38
|
|
|
27
|
-
function _extends() {
|
|
28
|
-
_extends = Object.assign || function assign(target) {
|
|
29
|
-
for(var i = 1; i < arguments.length; i++){
|
|
30
|
-
var source = arguments[i];
|
|
31
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
32
|
-
}
|
|
33
|
-
return target;
|
|
34
|
-
};
|
|
35
|
-
return _extends.apply(this, arguments);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
39
|
const bytesToBase64 = (arr)=>{
|
|
39
40
|
return btoa(Array.from(arr, (b)=>String.fromCharCode(b)).join(''));
|
|
40
41
|
};
|
|
@@ -48,6 +49,7 @@ const base64ToBytes = (base64)=>{
|
|
|
48
49
|
const ensureBase64Padding = (str)=>{
|
|
49
50
|
return str.padEnd(Math.ceil(str.length / 4) * 4, '=');
|
|
50
51
|
};
|
|
52
|
+
const isBrowser = ()=>typeof window !== 'undefined';
|
|
51
53
|
|
|
52
54
|
const getKey = async ({ password, salt })=>{
|
|
53
55
|
const passwordBytes = stringToBytes(password);
|
|
@@ -190,9 +192,108 @@ const downloadFileFromGoogleDrive = async ({ accessToken, name })=>{
|
|
|
190
192
|
return fileRawData;
|
|
191
193
|
};
|
|
192
194
|
|
|
195
|
+
const DEFAULT_LOG_LEVEL = 'INFO';
|
|
196
|
+
const STORAGE_KEY = 'dynamic-waas-wallet-client';
|
|
193
197
|
const BACKUP_FILENAME = 'dynamicWalletSecretBackup.json';
|
|
194
198
|
|
|
199
|
+
const localStorageWriteTest = {
|
|
200
|
+
tested: false,
|
|
201
|
+
writable: false
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Checks whether localStorage is supported on this browser.
|
|
205
|
+
*/ const supportsLocalStorage = ()=>{
|
|
206
|
+
if (!isBrowser()) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
if (typeof globalThis.localStorage !== 'object') {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
} catch (e) {
|
|
214
|
+
// DOM exception when accessing `localStorage`
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
if (localStorageWriteTest.tested) {
|
|
218
|
+
return localStorageWriteTest.writable;
|
|
219
|
+
}
|
|
220
|
+
const randomKey = `lswt-${Math.random()}${Math.random()}`;
|
|
221
|
+
try {
|
|
222
|
+
globalThis.localStorage.setItem(randomKey, randomKey);
|
|
223
|
+
globalThis.localStorage.removeItem(randomKey);
|
|
224
|
+
localStorageWriteTest.tested = true;
|
|
225
|
+
localStorageWriteTest.writable = true;
|
|
226
|
+
} catch (e) {
|
|
227
|
+
// localStorage can't be written to
|
|
228
|
+
localStorageWriteTest.tested = true;
|
|
229
|
+
localStorageWriteTest.writable = false;
|
|
230
|
+
}
|
|
231
|
+
return localStorageWriteTest.writable;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Provides safe access to the globalThis.localStorage property.
|
|
235
|
+
*/ const localStorageAdapter = {
|
|
236
|
+
getItem: (key)=>{
|
|
237
|
+
if (!supportsLocalStorage()) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
return globalThis.localStorage.getItem(key);
|
|
241
|
+
},
|
|
242
|
+
removeItem: (key)=>{
|
|
243
|
+
if (!supportsLocalStorage()) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
globalThis.localStorage.removeItem(key);
|
|
247
|
+
},
|
|
248
|
+
setItem: (key, value)=>{
|
|
249
|
+
if (!supportsLocalStorage()) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
globalThis.localStorage.setItem(key, value);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Returns a localStorage-like object that stores the key-value pairs in
|
|
257
|
+
* memory.
|
|
258
|
+
*/ const memoryLocalStorageAdapter = (store = {})=>({
|
|
259
|
+
getItem: (key)=>store[key] || null,
|
|
260
|
+
removeItem: (key)=>{
|
|
261
|
+
delete store[key];
|
|
262
|
+
},
|
|
263
|
+
setItem: (key, value)=>{
|
|
264
|
+
store[key] = value;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const logger = new Logger('DynamicWaasWalletClient');
|
|
269
|
+
|
|
195
270
|
class DynamicWalletClient {
|
|
271
|
+
async initialize() {
|
|
272
|
+
if (this.initializePromise) {
|
|
273
|
+
return await this.initializePromise;
|
|
274
|
+
}
|
|
275
|
+
this.logger.debug('Initializing Dynamic Waas Wallet SDK');
|
|
276
|
+
this.initializePromise = this._initialize();
|
|
277
|
+
const result = await this.initializePromise;
|
|
278
|
+
this.logger.debug('Dynamic Waas Wallet SDK initialized');
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Client initialization logic
|
|
283
|
+
*/ async _initialize() {
|
|
284
|
+
try {
|
|
285
|
+
const initializePromises = [];
|
|
286
|
+
initializePromises.push(this.restoreWallets());
|
|
287
|
+
await Promise.all(initializePromises);
|
|
288
|
+
return {
|
|
289
|
+
error: null
|
|
290
|
+
};
|
|
291
|
+
} catch (error) {
|
|
292
|
+
return {
|
|
293
|
+
error
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
196
297
|
async serverInitializeKeyGen({ chainName, clientKeygenIds, thresholdSignatureScheme }) {
|
|
197
298
|
// Initilize keygen, create room, and create the wallet account on the server
|
|
198
299
|
const data = await this.apiClient.createWalletAccount({
|
|
@@ -280,7 +381,7 @@ class DynamicWalletClient {
|
|
|
280
381
|
clientKeyShares
|
|
281
382
|
};
|
|
282
383
|
} catch (error) {
|
|
283
|
-
|
|
384
|
+
this.logger.error('Error creating wallet account', error);
|
|
284
385
|
throw new Error('Error creating wallet account');
|
|
285
386
|
}
|
|
286
387
|
}
|
|
@@ -317,7 +418,7 @@ class DynamicWalletClient {
|
|
|
317
418
|
const signature = await mpcSigner.sign(roomId, keyShare, formattedMessage, derivationPath);
|
|
318
419
|
return signature;
|
|
319
420
|
} catch (error) {
|
|
320
|
-
|
|
421
|
+
this.logger.error('Error in clientSign:', error);
|
|
321
422
|
throw error;
|
|
322
423
|
}
|
|
323
424
|
}
|
|
@@ -325,6 +426,7 @@ class DynamicWalletClient {
|
|
|
325
426
|
const wallet = await this.getWallet({
|
|
326
427
|
accountAddress
|
|
327
428
|
});
|
|
429
|
+
this.logger.debug('signing wallet', wallet);
|
|
328
430
|
// Perform the server sign
|
|
329
431
|
const data = await this.serverSign({
|
|
330
432
|
walletId: wallet.walletId,
|
|
@@ -412,8 +514,8 @@ class DynamicWalletClient {
|
|
|
412
514
|
data.serverKeygenId,
|
|
413
515
|
newPartyInitKeygenId
|
|
414
516
|
];
|
|
415
|
-
|
|
416
|
-
|
|
517
|
+
this.logger.debug('newClientPrimaryKeygenIds', newClientPrimaryKeygenIds);
|
|
518
|
+
this.logger.debug('clientSecondaryKeygenIds', clientSecondaryKeygenIds);
|
|
417
519
|
const keygenResults = await Promise.all([
|
|
418
520
|
mpcSigner.reshareNewParty(roomId, mpcConfig.threshold, mpcConfig.threshold, newPartyInitKeygen, newClientPrimaryKeygenIds),
|
|
419
521
|
mpcSigner.reshareRemainingParty(roomId, mpcConfig.threshold, wallet.clientKeyShares[1], clientSecondaryKeygenIds)
|
|
@@ -542,7 +644,15 @@ class DynamicWalletClient {
|
|
|
542
644
|
});
|
|
543
645
|
return decryptedKeyShares;
|
|
544
646
|
}
|
|
545
|
-
|
|
647
|
+
async restoreWallets() {
|
|
648
|
+
const wallets = await this.storage.getItem(this.storageKey);
|
|
649
|
+
console.log('local storage wallets', wallets);
|
|
650
|
+
if (!wallets) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
this.walletMap = JSON.parse(wallets);
|
|
654
|
+
}
|
|
655
|
+
async restoreBackupShare({ walletId, accountAddress, chainName, keyShare, thresholdSignatureScheme }) {
|
|
546
656
|
var _this_walletMap_accountAddress;
|
|
547
657
|
this.walletMap[accountAddress] = {
|
|
548
658
|
walletId,
|
|
@@ -554,6 +664,7 @@ class DynamicWalletClient {
|
|
|
554
664
|
],
|
|
555
665
|
thresholdSignatureScheme
|
|
556
666
|
};
|
|
667
|
+
await this.storage.setItem(this.storageKey, JSON.stringify(this.walletMap));
|
|
557
668
|
}
|
|
558
669
|
async backupFileToGoogleDrive({ oauthAccountId, fileName = BACKUP_FILENAME, jsonData, password }) {
|
|
559
670
|
const encryptedKeyShare = await this.encryptKeyShare({
|
|
@@ -657,16 +768,17 @@ class DynamicWalletClient {
|
|
|
657
768
|
var _user_verifiedCredentials;
|
|
658
769
|
const user = await this.apiClient.getUser();
|
|
659
770
|
const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? undefined : _user_verifiedCredentials.find((vc)=>vc.address === accountAddress);
|
|
771
|
+
this.logger.debug('need to restore wallet', wallet);
|
|
660
772
|
console.log('need to restore wallet', wallet);
|
|
661
773
|
const clientShares = wallet.walletProperties.keyShares.filter((ks)=>ks.backupLocation === 'dynamic');
|
|
662
|
-
|
|
774
|
+
this.logger.debug('clientShares', clientShares);
|
|
663
775
|
// restore backup
|
|
664
776
|
const decryptedKeyShares = await this.recoverEncryptedBackupByWallet({
|
|
665
777
|
accountAddress,
|
|
666
778
|
password: this.environmentId
|
|
667
779
|
});
|
|
668
780
|
//todo: check to see if their are other backups ie google drive, etc
|
|
669
|
-
|
|
781
|
+
this.logger.debug('recovery decryptedKeyShares', decryptedKeyShares);
|
|
670
782
|
}
|
|
671
783
|
}
|
|
672
784
|
const walletCount = Object.keys(this.walletMap).length;
|
|
@@ -704,17 +816,31 @@ class DynamicWalletClient {
|
|
|
704
816
|
}, {});
|
|
705
817
|
return wallets;
|
|
706
818
|
}
|
|
707
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl }){
|
|
819
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug }){
|
|
820
|
+
this.initializePromise = null;
|
|
821
|
+
this.logger = logger;
|
|
708
822
|
this.walletMap = {} // todo: store in session storage
|
|
709
823
|
;
|
|
824
|
+
this.memoryStorage = null;
|
|
710
825
|
this.environmentId = environmentId;
|
|
826
|
+
this.storageKey = `${STORAGE_KEY}-${storageKey != null ? storageKey : environmentId}`;
|
|
711
827
|
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
712
828
|
this.apiClient = new DynamicApiClient({
|
|
713
829
|
environmentId,
|
|
714
830
|
authToken,
|
|
715
831
|
baseApiUrl
|
|
716
832
|
});
|
|
717
|
-
this.
|
|
833
|
+
this.debug = Boolean(debug);
|
|
834
|
+
this.logger.setLogLevel(this.debug ? 'DEBUG' : DEFAULT_LOG_LEVEL);
|
|
835
|
+
// setup storage
|
|
836
|
+
if (supportsLocalStorage()) {
|
|
837
|
+
this.storage = localStorageAdapter;
|
|
838
|
+
} else {
|
|
839
|
+
this.memoryStorage = {};
|
|
840
|
+
this.storage = memoryLocalStorageAdapter(this.memoryStorage);
|
|
841
|
+
}
|
|
842
|
+
// initialize the client
|
|
843
|
+
this.initialize();
|
|
718
844
|
}
|
|
719
845
|
}
|
|
720
846
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/browser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@dynamic-labs-wallet/core": "0.0.
|
|
6
|
-
"@dynamic-labs-wallet/lib-mpc-web": "0.0.
|
|
5
|
+
"@dynamic-labs-wallet/core": "0.0.17",
|
|
6
|
+
"@dynamic-labs-wallet/lib-mpc-web": "0.0.17",
|
|
7
|
+
"@dynamic-labs/logger": "^4.5.1"
|
|
7
8
|
},
|
|
8
9
|
"nx": {
|
|
9
10
|
"sourceRoot": "packages/browser/src",
|
package/src/client.d.ts
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import { ThresholdSignatureScheme, DynamicApiClient } from '@dynamic-labs-wallet/core';
|
|
2
2
|
import { EcdsaPublicKey, EcdsaKeygenResult, Ed25519KeygenResult, BIP340KeygenResult, EcdsaSignature } from '@dynamic-labs-wallet/lib-mpc-web';
|
|
3
3
|
import { ClientInitKeygenResult, ClientKeyShare } from './mpc/types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
walletId: string;
|
|
7
|
-
accountAddress: string;
|
|
8
|
-
clientKeyShares: ClientKeyShare[];
|
|
9
|
-
thresholdSignatureScheme?: ThresholdSignatureScheme;
|
|
10
|
-
}
|
|
4
|
+
import { SupportedStorage } from './services/localStorage';
|
|
5
|
+
import { DynamicWalletClientProps, InitializeResult, WalletProperties } from './types';
|
|
11
6
|
export declare class DynamicWalletClient {
|
|
12
7
|
environmentId: string;
|
|
8
|
+
storageKey: string;
|
|
9
|
+
debug: boolean;
|
|
10
|
+
protected initializePromise: Promise<InitializeResult> | null;
|
|
11
|
+
protected logger: import("@dynamic-labs/logger").Logger;
|
|
13
12
|
protected apiClient: DynamicApiClient;
|
|
14
13
|
protected walletMap: Record<string, WalletProperties>;
|
|
14
|
+
protected storage: SupportedStorage;
|
|
15
|
+
protected memoryStorage: {
|
|
16
|
+
[key: string]: string;
|
|
17
|
+
} | null;
|
|
15
18
|
protected baseMPCRelayApiUrl?: string;
|
|
16
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, }:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, }: DynamicWalletClientProps);
|
|
20
|
+
initialize(): Promise<InitializeResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Client initialization logic
|
|
23
|
+
*/
|
|
24
|
+
private _initialize;
|
|
22
25
|
serverInitializeKeyGen({ chainName, clientKeygenIds, thresholdSignatureScheme, }: {
|
|
23
26
|
chainName: string;
|
|
24
27
|
clientKeygenIds: string[];
|
|
@@ -109,13 +112,14 @@ export declare class DynamicWalletClient {
|
|
|
109
112
|
password?: string;
|
|
110
113
|
keyShareIds?: string[];
|
|
111
114
|
}): Promise<any[]>;
|
|
115
|
+
restoreWallets(): Promise<void>;
|
|
112
116
|
restoreBackupShare({ walletId, accountAddress, chainName, keyShare, thresholdSignatureScheme, }: {
|
|
113
117
|
walletId: string;
|
|
114
118
|
accountAddress: string;
|
|
115
119
|
chainName: string;
|
|
116
120
|
keyShare: ClientKeyShare;
|
|
117
121
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
118
|
-
}): void
|
|
122
|
+
}): Promise<void>;
|
|
119
123
|
backupFileToGoogleDrive({ oauthAccountId, fileName, jsonData, password, }: {
|
|
120
124
|
oauthAccountId: string;
|
|
121
125
|
fileName?: string;
|
|
@@ -146,5 +150,4 @@ export declare class DynamicWalletClient {
|
|
|
146
150
|
}): Promise<WalletProperties>;
|
|
147
151
|
getWallets(): Promise<any>;
|
|
148
152
|
}
|
|
149
|
-
export {};
|
|
150
153
|
//# sourceMappingURL=client.d.ts.map
|
package/src/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../packages/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wBAAwB,EACxB,gBAAgB,EAGjB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAIL,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAElB,cAAc,EACf,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../packages/src/client.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B,UAAU,EAAE,MAAM,CAAC;QACnB,wBAAwB,EAAE,wBAAwB,CAAC;KACpD,GAAG,OAAO,CAAC;QACV,YAAY,EAAE,cAAc,GAAG,UAAU,GAAG,SAAS,CAAC;QACtD,eAAe,EAAE,cAAc,EAAE,CAAC;KACnC,CAAC;IA6DI,qBAAqB,CAAC,EAAE,cAAc,EAAE,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE;IAarE,kBAAkB,CAAC,EAAE,cAAc,EAAE,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE;IAKlE,SAAS,CAAC,EAAE,cAAc,EAAE,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE;IA6CzD,UAAU;CA0BjB"}
|
package/src/constants.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
export declare const DEFAULT_LOG_LEVEL = "INFO";
|
|
2
|
+
export declare const STORAGE_KEY = "dynamic-waas-wallet-client";
|
|
1
3
|
export declare const BACKUP_FILENAME = "dynamicWalletSecretBackup.json";
|
|
4
|
+
export declare const ChainEnumToVerifiedCredentialName: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const VerifiedCredentialNameToChainEnum: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
2
10
|
//# sourceMappingURL=constants.d.ts.map
|
package/src/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../packages/src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,mCAAmC,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../packages/src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,SAAS,CAAC;AAExC,eAAO,MAAM,WAAW,+BAA+B,CAAC;AAExD,eAAO,MAAM,eAAe,mCAAmC,CAAC;AAEhE,eAAO,MAAM,iCAAiC,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAKtE,CAAC;AAEF,eAAO,MAAM,iCAAiC,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAItE,CAAC"}
|
package/src/index.d.ts
CHANGED
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAE1C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAE1C,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AAExB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type AnyFunction = (...args: any[]) => any;
|
|
2
|
+
type MaybePromisify<T> = T | Promise<T>;
|
|
3
|
+
type PromisifyMethods<T> = {
|
|
4
|
+
[K in keyof T]: T[K] extends AnyFunction ? (...args: Parameters<T[K]>) => MaybePromisify<ReturnType<T[K]>> : T[K];
|
|
5
|
+
};
|
|
6
|
+
export type SupportedStorage = PromisifyMethods<Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>> & {
|
|
7
|
+
/**
|
|
8
|
+
* If set to `true` signals to the library that the storage medium is used
|
|
9
|
+
* on a server and the values may not be authentic, such as reading from
|
|
10
|
+
* request cookies. Implementations should not set this to true if the client
|
|
11
|
+
* is used on a server that reads storage information from authenticated
|
|
12
|
+
* sources, such as a secure database or file.
|
|
13
|
+
*/
|
|
14
|
+
isServer?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Checks whether localStorage is supported on this browser.
|
|
18
|
+
*/
|
|
19
|
+
export declare const supportsLocalStorage: () => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Provides safe access to the globalThis.localStorage property.
|
|
22
|
+
*/
|
|
23
|
+
export declare const localStorageAdapter: SupportedStorage;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a localStorage-like object that stores the key-value pairs in
|
|
26
|
+
* memory.
|
|
27
|
+
*/
|
|
28
|
+
export declare const memoryLocalStorageAdapter: (store?: {
|
|
29
|
+
[key: string]: string;
|
|
30
|
+
}) => SupportedStorage;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=localStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../packages/src/localStorage.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAC3C,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAExC,KAAK,gBAAgB,CAAC,CAAC,IAAI;KACxB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,WAAW,GACpC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC/D,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAC7C,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC,CACpD,GAAG;IACF;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,oBAAoB,eAiChC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAsBjC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,WAC7B;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,KAC/B,gBAUD,CAAC"}
|
package/src/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../packages/src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,eAAO,MAAM,MAAM,QAAwC,CAAC"}
|
package/src/mpc/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Ecdsa, Ed25519, BIP340, BIP340KeygenResult, EcdsaPublicKey, Ed25519KeygenResult, EcdsaKeygenResult, MessageHash, EcdsaInitKeygenResult, Ed25519InitKeygenResult, BIP340InitKeygenResult, EcdsaSignature } from '@dynamic-labs-wallet/lib-mpc-web';
|
|
2
2
|
export { Ecdsa, Ed25519, BIP340, EcdsaPublicKey, EcdsaKeygenResult, Ed25519KeygenResult, BIP340KeygenResult, MessageHash, EcdsaInitKeygenResult, Ed25519InitKeygenResult, BIP340InitKeygenResult, EcdsaSignature, };
|
|
3
3
|
export * from './mpc';
|
|
4
|
+
export * from './types';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/src/mpc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACf,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,GACf,CAAC;AAEF,cAAc,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACf,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,GACf,CAAC;AAEF,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type AnyFunction = (...args: any[]) => any;
|
|
2
|
+
type MaybePromisify<T> = T | Promise<T>;
|
|
3
|
+
type PromisifyMethods<T> = {
|
|
4
|
+
[K in keyof T]: T[K] extends AnyFunction ? (...args: Parameters<T[K]>) => MaybePromisify<ReturnType<T[K]>> : T[K];
|
|
5
|
+
};
|
|
6
|
+
export type SupportedStorage = PromisifyMethods<Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>> & {
|
|
7
|
+
/**
|
|
8
|
+
* If set to `true` signals to the library that the storage medium is used
|
|
9
|
+
* on a server and the values may not be authentic, such as reading from
|
|
10
|
+
* request cookies. Implementations should not set this to true if the client
|
|
11
|
+
* is used on a server that reads storage information from authenticated
|
|
12
|
+
* sources, such as a secure database or file.
|
|
13
|
+
*/
|
|
14
|
+
isServer?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Checks whether localStorage is supported on this browser.
|
|
18
|
+
*/
|
|
19
|
+
export declare const supportsLocalStorage: () => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Provides safe access to the globalThis.localStorage property.
|
|
22
|
+
*/
|
|
23
|
+
export declare const localStorageAdapter: SupportedStorage;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a localStorage-like object that stores the key-value pairs in
|
|
26
|
+
* memory.
|
|
27
|
+
*/
|
|
28
|
+
export declare const memoryLocalStorageAdapter: (store?: {
|
|
29
|
+
[key: string]: string;
|
|
30
|
+
}) => SupportedStorage;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=localStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../src/services/localStorage.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAC3C,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAExC,KAAK,gBAAgB,CAAC,CAAC,IAAI;KACxB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,WAAW,GACpC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC/D,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAC7C,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC,CACpD,GAAG;IACF;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,oBAAoB,eAiChC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAsBjC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,WAC7B;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,KAC/B,gBAUD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/services/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,eAAO,MAAM,MAAM,QAAwC,CAAC"}
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ThresholdSignatureScheme } from '.';
|
|
2
|
+
import { ClientKeyShare } from './mpc/types';
|
|
3
|
+
export type InitializeResult = {
|
|
4
|
+
error: unknown | null;
|
|
5
|
+
};
|
|
6
|
+
export interface WalletProperties {
|
|
7
|
+
chainName: string;
|
|
8
|
+
walletId: string;
|
|
9
|
+
accountAddress: string;
|
|
10
|
+
clientKeyShares: ClientKeyShare[];
|
|
11
|
+
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
12
|
+
}
|
|
13
|
+
export interface DynamicWalletClientProps {
|
|
14
|
+
environmentId: string;
|
|
15
|
+
authToken: string;
|
|
16
|
+
baseApiUrl?: string;
|
|
17
|
+
storageKey?: string;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
baseMPCRelayApiUrl?: string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../packages/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,GAAG,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,CAAC;AAEzD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,wBAAwB,EAAE,wBAAwB,CAAC;CACpD;AAED,MAAM,WAAW,wBAAwB;IACvC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B"}
|
package/src/utils.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export declare const bytesToBase64: (arr: Uint8Array) => string;
|
|
|
2
2
|
export declare const stringToBytes: (str: string) => Uint8Array;
|
|
3
3
|
export declare const base64ToBytes: (base64: string) => Uint8Array;
|
|
4
4
|
export declare const ensureBase64Padding: (str: string) => string;
|
|
5
|
+
export declare const isBrowser: () => boolean;
|
|
5
6
|
//# sourceMappingURL=utils.d.ts.map
|
package/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAAS,UAAU,WAE5C,CAAC;AAEF,eAAO,MAAM,aAAa,QAAS,MAAM,eAExC,CAAC;AAEF,eAAO,MAAM,aAAa,WAAY,MAAM,eAE3C,CAAC;AAGF,eAAO,MAAM,mBAAmB,QAAS,MAAM,KAAG,MAEjD,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAAS,UAAU,WAE5C,CAAC;AAEF,eAAO,MAAM,aAAa,QAAS,MAAM,eAExC,CAAC;AAEF,eAAO,MAAM,aAAa,WAAY,MAAM,eAE3C,CAAC;AAGF,eAAO,MAAM,mBAAmB,QAAS,MAAM,KAAG,MAEjD,CAAC;AAEF,eAAO,MAAM,SAAS,eAAsC,CAAC"}
|