@dynamic-labs-wallet/browser 0.0.95 → 0.0.98
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 +249 -209
- package/index.esm.js +249 -209
- package/package.json +5 -3
- package/src/client.d.ts +1 -0
- package/src/client.d.ts.map +1 -1
- package/src/errorConstants.d.ts +1 -1
- package/src/errorConstants.d.ts.map +1 -1
- package/src/services/logger.d.ts +12 -2
- package/src/services/logger.d.ts.map +1 -1
package/index.esm.js
CHANGED
|
@@ -2,6 +2,7 @@ import { SigningAlgorithm, MPC_RELAY_PROD_API_URL, getMPCChainConfig, BackupLoca
|
|
|
2
2
|
export * from '@dynamic-labs-wallet/core';
|
|
3
3
|
import { BIP340, ExportableEd25519, Ecdsa, MessageHash, EcdsaKeygenResult, ExportableEd25519KeygenResult, BIP340KeygenResult } from './internal/web';
|
|
4
4
|
export { BIP340, BIP340InitKeygenResult, BIP340KeygenResult, Ecdsa, EcdsaInitKeygenResult, EcdsaKeygenResult, EcdsaPublicKey, EcdsaSignature, Ed25519, Ed25519InitKeygenResult, Ed25519KeygenResult, MessageHash } from './internal/web';
|
|
5
|
+
import jwt from 'jsonwebtoken';
|
|
5
6
|
import { LogLevel, Logger } from '@dynamic-labs/logger';
|
|
6
7
|
import { ProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
7
8
|
import { AxiosError } from 'axios';
|
|
@@ -43,9 +44,52 @@ const DEFAULT_LOG_LEVEL = LogLevel.DEBUG; //todo: change back to info when done
|
|
|
43
44
|
const STORAGE_KEY = 'dynamic-waas-wallet-client';
|
|
44
45
|
const CLIENT_KEYSHARE_EXPORT_FILENAME_PREFIX = 'dynamicWalletKeyShareBackup';
|
|
45
46
|
|
|
47
|
+
const handleAxiosError = (error, message, context)=>{
|
|
48
|
+
var _error_response, _error_response1;
|
|
49
|
+
logger.debug("[DynamicWaasWalletClient] Axios error: " + message, {
|
|
50
|
+
error: (_error_response = error.response) == null ? void 0 : _error_response.status,
|
|
51
|
+
message: error.message,
|
|
52
|
+
context
|
|
53
|
+
});
|
|
54
|
+
switch((_error_response1 = error.response) == null ? void 0 : _error_response1.status){
|
|
55
|
+
case 400:
|
|
56
|
+
throw createHttpError(400, 'Invalid request');
|
|
57
|
+
case 401:
|
|
58
|
+
throw createHttpError(401, 'Authorization header or cookie is required');
|
|
59
|
+
case 403:
|
|
60
|
+
throw createHttpError(403, 'Forbidden');
|
|
61
|
+
case 422:
|
|
62
|
+
throw createHttpError(422, 'Unprocessable content');
|
|
63
|
+
case 500:
|
|
64
|
+
throw createHttpError(500, 'Internal server error');
|
|
65
|
+
default:
|
|
66
|
+
throw createHttpError(500, 'Internal server error');
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
46
70
|
const logger = new Logger('DynamicWaasWalletClient', LogLevel.DEBUG);
|
|
47
|
-
const
|
|
48
|
-
|
|
71
|
+
const setLoggerContext = ({ environmentId, sessionId, userId, verifiedCredentials })=>{
|
|
72
|
+
try {
|
|
73
|
+
Logger.setEnvironmentId(environmentId);
|
|
74
|
+
Logger.globalMetaData.set('sid', sessionId);
|
|
75
|
+
Logger.globalMetaData.set('user_id', userId);
|
|
76
|
+
Logger.globalMetaData.set('verified_credentials', verifiedCredentials);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
logError({
|
|
79
|
+
message: '[DynamicWaasWalletClient] Error setting logger context',
|
|
80
|
+
error: error,
|
|
81
|
+
context: {}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const logError = ({ message, error, context })=>{
|
|
86
|
+
if (error instanceof AxiosError) {
|
|
87
|
+
handleAxiosError(error, message, context);
|
|
88
|
+
}
|
|
89
|
+
logger.error(message, {
|
|
90
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
91
|
+
context
|
|
92
|
+
});
|
|
49
93
|
};
|
|
50
94
|
|
|
51
95
|
const bytesToBase64 = (arr)=>{
|
|
@@ -429,29 +473,6 @@ const downloadFileFromGoogleDrive = async ({ accessToken, fileName })=>{
|
|
|
429
473
|
}
|
|
430
474
|
};
|
|
431
475
|
|
|
432
|
-
const handleAxiosError = (error, message, context)=>{
|
|
433
|
-
var _error_response, _error_response1;
|
|
434
|
-
logger.debug("[DynamicWaasWalletClient] Axios error: " + message, {
|
|
435
|
-
error: (_error_response = error.response) == null ? void 0 : _error_response.status,
|
|
436
|
-
message: error.message,
|
|
437
|
-
context
|
|
438
|
-
});
|
|
439
|
-
switch((_error_response1 = error.response) == null ? void 0 : _error_response1.status){
|
|
440
|
-
case 400:
|
|
441
|
-
throw createHttpError(400, 'Invalid request');
|
|
442
|
-
case 401:
|
|
443
|
-
throw createHttpError(401, 'Authorization header or cookie is required');
|
|
444
|
-
case 403:
|
|
445
|
-
throw createHttpError(403, 'Forbidden');
|
|
446
|
-
case 422:
|
|
447
|
-
throw createHttpError(422, 'Unprocessable content');
|
|
448
|
-
case 500:
|
|
449
|
-
throw createHttpError(500, 'Internal server error');
|
|
450
|
-
default:
|
|
451
|
-
throw createHttpError(500, 'Internal server error');
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
|
|
455
476
|
const localStorageWriteTest = {
|
|
456
477
|
tested: false,
|
|
457
478
|
writable: false
|
|
@@ -522,11 +543,34 @@ const localStorageWriteTest = {
|
|
|
522
543
|
});
|
|
523
544
|
|
|
524
545
|
class DynamicWalletClient {
|
|
546
|
+
async initLoggerContext(authToken) {
|
|
547
|
+
try {
|
|
548
|
+
const payload = jwt.decode(authToken);
|
|
549
|
+
if (!payload || typeof payload !== 'object') {
|
|
550
|
+
throw new Error('Invalid JWT payload');
|
|
551
|
+
}
|
|
552
|
+
const userId = payload['sub'];
|
|
553
|
+
const sessionId = payload['sid'];
|
|
554
|
+
const verifiedCredentials = payload['verified_credentials'];
|
|
555
|
+
setLoggerContext({
|
|
556
|
+
environmentId: this.environmentId,
|
|
557
|
+
sessionId,
|
|
558
|
+
userId: userId || 'unknown',
|
|
559
|
+
verifiedCredentials
|
|
560
|
+
});
|
|
561
|
+
} catch (error) {
|
|
562
|
+
logError({
|
|
563
|
+
message: '[DynamicWaasWalletClient] Error initializing auth token',
|
|
564
|
+
error: error,
|
|
565
|
+
context: {}
|
|
566
|
+
});
|
|
567
|
+
throw error;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
525
570
|
async initialize() {
|
|
526
571
|
if (this.initializePromise) {
|
|
527
572
|
return await this.initializePromise;
|
|
528
573
|
}
|
|
529
|
-
setLoggerEnvironmentId(this.environmentId);
|
|
530
574
|
this.logger.debug('[DynamicWaasWalletClient] Initializing Dynamic Waas Wallet SDK');
|
|
531
575
|
this.initializePromise = this._initialize();
|
|
532
576
|
const result = await this.initializePromise;
|
|
@@ -669,17 +713,13 @@ class DynamicWalletClient {
|
|
|
669
713
|
clientKeyShares
|
|
670
714
|
};
|
|
671
715
|
} catch (error) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
}
|
|
680
|
-
this.logger.error(message, {
|
|
681
|
-
error,
|
|
682
|
-
context
|
|
716
|
+
logError({
|
|
717
|
+
message: '[DynamicWaasWalletClient] Error in keyGen',
|
|
718
|
+
error: error,
|
|
719
|
+
context: {
|
|
720
|
+
chainName,
|
|
721
|
+
thresholdSignatureScheme
|
|
722
|
+
}
|
|
683
723
|
});
|
|
684
724
|
throw error;
|
|
685
725
|
}
|
|
@@ -750,17 +790,13 @@ class DynamicWalletClient {
|
|
|
750
790
|
clientKeyShares: clientKeygenResults
|
|
751
791
|
};
|
|
752
792
|
} catch (error) {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
this.logger.error(message, {
|
|
762
|
-
error,
|
|
763
|
-
context
|
|
793
|
+
logError({
|
|
794
|
+
message: '[DynamicWaasWalletClient] Error in importRawPrivateKey',
|
|
795
|
+
error: error,
|
|
796
|
+
context: {
|
|
797
|
+
chainName,
|
|
798
|
+
thresholdSignatureScheme
|
|
799
|
+
}
|
|
764
800
|
});
|
|
765
801
|
throw error;
|
|
766
802
|
}
|
|
@@ -794,12 +830,15 @@ class DynamicWalletClient {
|
|
|
794
830
|
const signature = await mpcSigner.sign(roomId, keyShare, formattedMessage, derivationPath);
|
|
795
831
|
return signature;
|
|
796
832
|
} catch (error) {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
833
|
+
logError({
|
|
834
|
+
message: '[DynamicWaasWalletClient] Error in clientSign',
|
|
835
|
+
error: error,
|
|
836
|
+
context: {
|
|
837
|
+
chainName,
|
|
838
|
+
roomId,
|
|
839
|
+
derivationPath,
|
|
840
|
+
isFormatted
|
|
841
|
+
}
|
|
803
842
|
});
|
|
804
843
|
throw error;
|
|
805
844
|
}
|
|
@@ -853,18 +892,14 @@ class DynamicWalletClient {
|
|
|
853
892
|
});
|
|
854
893
|
return signature;
|
|
855
894
|
} catch (error) {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
}
|
|
865
|
-
this.logger.error(message, {
|
|
866
|
-
error,
|
|
867
|
-
context
|
|
895
|
+
logError({
|
|
896
|
+
message: '[DynamicWaasWalletClient] Error in sign',
|
|
897
|
+
error: error,
|
|
898
|
+
context: {
|
|
899
|
+
accountAddress,
|
|
900
|
+
chainName,
|
|
901
|
+
isFormatted: isFormatted ? 'true' : 'false'
|
|
902
|
+
}
|
|
868
903
|
});
|
|
869
904
|
throw error;
|
|
870
905
|
}
|
|
@@ -907,17 +942,13 @@ class DynamicWalletClient {
|
|
|
907
942
|
signedSessionId
|
|
908
943
|
});
|
|
909
944
|
} catch (error) {
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
}
|
|
918
|
-
this.logger.error(message, {
|
|
919
|
-
error,
|
|
920
|
-
context
|
|
945
|
+
logError({
|
|
946
|
+
message: '[DynamicWaasWalletClient] Error in refreshWalletAccountShares',
|
|
947
|
+
error: error,
|
|
948
|
+
context: {
|
|
949
|
+
accountAddress,
|
|
950
|
+
chainName
|
|
951
|
+
}
|
|
921
952
|
});
|
|
922
953
|
throw error;
|
|
923
954
|
}
|
|
@@ -1042,19 +1073,16 @@ class DynamicWalletClient {
|
|
|
1042
1073
|
backupToGoogleDrive
|
|
1043
1074
|
});
|
|
1044
1075
|
} catch (error) {
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
this.logger.error(message, {
|
|
1056
|
-
error,
|
|
1057
|
-
context
|
|
1076
|
+
logError({
|
|
1077
|
+
message: '[DynamicWaasWalletClient] Error in reshare',
|
|
1078
|
+
error: error,
|
|
1079
|
+
context: {
|
|
1080
|
+
accountAddress,
|
|
1081
|
+
chainName,
|
|
1082
|
+
oldThresholdSignatureScheme,
|
|
1083
|
+
newThresholdSignatureScheme,
|
|
1084
|
+
backupToGoogleDrive
|
|
1085
|
+
}
|
|
1058
1086
|
});
|
|
1059
1087
|
throw error;
|
|
1060
1088
|
}
|
|
@@ -1113,17 +1141,13 @@ class DynamicWalletClient {
|
|
|
1113
1141
|
derivedPrivateKey
|
|
1114
1142
|
};
|
|
1115
1143
|
} catch (error) {
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
}
|
|
1124
|
-
this.logger.error(message, {
|
|
1125
|
-
error,
|
|
1126
|
-
context
|
|
1144
|
+
logError({
|
|
1145
|
+
message: '[DynamicWaasWalletClient] Error in exportKey',
|
|
1146
|
+
error: error,
|
|
1147
|
+
context: {
|
|
1148
|
+
accountAddress,
|
|
1149
|
+
chainName
|
|
1150
|
+
}
|
|
1127
1151
|
});
|
|
1128
1152
|
throw error;
|
|
1129
1153
|
}
|
|
@@ -1164,7 +1188,13 @@ class DynamicWalletClient {
|
|
|
1164
1188
|
rawPublicKey
|
|
1165
1189
|
};
|
|
1166
1190
|
} catch (error) {
|
|
1167
|
-
|
|
1191
|
+
logError({
|
|
1192
|
+
message: '[DynamicWaasWalletClient] Error in offlineExportKey',
|
|
1193
|
+
error: error,
|
|
1194
|
+
context: {
|
|
1195
|
+
chainName
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1168
1198
|
throw error;
|
|
1169
1199
|
}
|
|
1170
1200
|
}
|
|
@@ -1196,7 +1226,13 @@ class DynamicWalletClient {
|
|
|
1196
1226
|
}
|
|
1197
1227
|
return (parsedWalletObject == null ? void 0 : parsedWalletObject.clientKeyShares) || [];
|
|
1198
1228
|
} catch (error) {
|
|
1199
|
-
|
|
1229
|
+
logError({
|
|
1230
|
+
message: `[DynamicWaasWalletClient] Error parsing clientKeyShares: ${error} for accountAddress: ${accountAddress}`,
|
|
1231
|
+
error: error,
|
|
1232
|
+
context: {
|
|
1233
|
+
accountAddress
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1200
1236
|
return [];
|
|
1201
1237
|
}
|
|
1202
1238
|
}
|
|
@@ -1244,13 +1280,16 @@ class DynamicWalletClient {
|
|
|
1244
1280
|
accountAddress
|
|
1245
1281
|
});
|
|
1246
1282
|
if (!((_this_walletMap_accountAddress = this.walletMap[accountAddress]) == null ? void 0 : _this_walletMap_accountAddress.walletId)) {
|
|
1247
|
-
|
|
1283
|
+
const error = new Error(`WalletId not found for accountAddress ${accountAddress}`);
|
|
1284
|
+
logError({
|
|
1285
|
+
message: '[DynamicWaasWalletClient] Error in storeEncryptedBackupByWallet, wallet or walletId not found from the wallet map',
|
|
1286
|
+
error,
|
|
1248
1287
|
context: {
|
|
1249
1288
|
accountAddress,
|
|
1250
1289
|
walletMap: this.walletMap
|
|
1251
1290
|
}
|
|
1252
1291
|
});
|
|
1253
|
-
throw
|
|
1292
|
+
throw error;
|
|
1254
1293
|
}
|
|
1255
1294
|
// TODO(zfaizal2): throw error if signedSessionId is not provided after service deploy
|
|
1256
1295
|
let dynamicClientKeyShares = [];
|
|
@@ -1279,6 +1318,10 @@ class DynamicWalletClient {
|
|
|
1279
1318
|
passwordEncrypted: Boolean(password) && password !== this.environmentId,
|
|
1280
1319
|
signedSessionId
|
|
1281
1320
|
});
|
|
1321
|
+
await this.apiClient.markKeySharesAsBackedUp({
|
|
1322
|
+
walletId: this.walletMap[accountAddress].walletId,
|
|
1323
|
+
location: BackupLocation.DYNAMIC
|
|
1324
|
+
});
|
|
1282
1325
|
if (googleDriveKeyShares.length > 0) {
|
|
1283
1326
|
const googleDriveKeyShareIds = await this.uploadKeySharesToGoogleDrive({
|
|
1284
1327
|
accountAddress,
|
|
@@ -1302,16 +1345,12 @@ class DynamicWalletClient {
|
|
|
1302
1345
|
await this.storage.setItem(this.storageKey, JSON.stringify(this.walletMap));
|
|
1303
1346
|
return data;
|
|
1304
1347
|
} catch (error) {
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
}
|
|
1312
|
-
this.logger.error(message, {
|
|
1313
|
-
error: error instanceof Error ? error.message : 'Unknown error',
|
|
1314
|
-
context
|
|
1348
|
+
logError({
|
|
1349
|
+
message: '[DynamicWaasWalletClient] Error in storeEncryptedBackupByWallet',
|
|
1350
|
+
error: error,
|
|
1351
|
+
context: {
|
|
1352
|
+
accountAddress
|
|
1353
|
+
}
|
|
1315
1354
|
});
|
|
1316
1355
|
throw error;
|
|
1317
1356
|
}
|
|
@@ -1361,23 +1400,25 @@ class DynamicWalletClient {
|
|
|
1361
1400
|
const user = await this.apiClient.getUser();
|
|
1362
1401
|
const oauthAccountId = getGoogleOAuthAccountId(user == null ? void 0 : user.verifiedCredentials);
|
|
1363
1402
|
if (!oauthAccountId) {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1403
|
+
const error = new Error('No Google OAuth account ID found');
|
|
1404
|
+
logError({
|
|
1405
|
+
message: 'No Google OAuth account ID found',
|
|
1406
|
+
error,
|
|
1407
|
+
context: {
|
|
1408
|
+
user,
|
|
1409
|
+
accountAddress
|
|
1410
|
+
}
|
|
1367
1411
|
});
|
|
1368
|
-
throw
|
|
1412
|
+
throw error;
|
|
1369
1413
|
}
|
|
1370
1414
|
return oauthAccountId;
|
|
1371
1415
|
} catch (error) {
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1416
|
+
logError({
|
|
1417
|
+
message: '[DynamicWaasWalletClient] Error in getGoogleOauthAccountIdOrThrow',
|
|
1418
|
+
error: error,
|
|
1419
|
+
context: {
|
|
1375
1420
|
accountAddress
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
this.logger.error(message, {
|
|
1379
|
-
error,
|
|
1380
|
-
accountAddress
|
|
1421
|
+
}
|
|
1381
1422
|
});
|
|
1382
1423
|
throw error;
|
|
1383
1424
|
}
|
|
@@ -1440,21 +1481,14 @@ class DynamicWalletClient {
|
|
|
1440
1481
|
}
|
|
1441
1482
|
return decryptedKeyShares;
|
|
1442
1483
|
} catch (error) {
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
};
|
|
1452
|
-
if (error instanceof AxiosError) {
|
|
1453
|
-
handleAxiosError(error, message, context);
|
|
1454
|
-
}
|
|
1455
|
-
this.logger.error(message, {
|
|
1456
|
-
error,
|
|
1457
|
-
context
|
|
1484
|
+
logError({
|
|
1485
|
+
message: '[DynamicWaasWalletClient] Error in recoverEncryptedBackupByWallet',
|
|
1486
|
+
error: error,
|
|
1487
|
+
context: {
|
|
1488
|
+
accountAddress,
|
|
1489
|
+
walletOperation,
|
|
1490
|
+
shareCount
|
|
1491
|
+
}
|
|
1458
1492
|
});
|
|
1459
1493
|
throw error;
|
|
1460
1494
|
}
|
|
@@ -1511,13 +1545,13 @@ class DynamicWalletClient {
|
|
|
1511
1545
|
return googleDriveKeyShares.map((ks)=>ks.id);
|
|
1512
1546
|
}
|
|
1513
1547
|
} catch (error) {
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1548
|
+
logError({
|
|
1549
|
+
message: '[DynamicWaasWalletClient] Error in backupKeySharesToGoogleDrive',
|
|
1550
|
+
error: error,
|
|
1551
|
+
context: {
|
|
1518
1552
|
accountAddress
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1553
|
+
}
|
|
1554
|
+
});
|
|
1521
1555
|
throw error;
|
|
1522
1556
|
}
|
|
1523
1557
|
}
|
|
@@ -1569,16 +1603,12 @@ class DynamicWalletClient {
|
|
|
1569
1603
|
});
|
|
1570
1604
|
return data.keyShares.map((ks)=>ks.id);
|
|
1571
1605
|
} catch (error) {
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
}
|
|
1579
|
-
this.logger.error(message, {
|
|
1580
|
-
error,
|
|
1581
|
-
context
|
|
1606
|
+
logError({
|
|
1607
|
+
message: '[DynamicWaasWalletClient] Error in backupKeySharesToGoogleDrive',
|
|
1608
|
+
error: error,
|
|
1609
|
+
context: {
|
|
1610
|
+
accountAddress
|
|
1611
|
+
}
|
|
1582
1612
|
});
|
|
1583
1613
|
throw error;
|
|
1584
1614
|
}
|
|
@@ -1605,27 +1635,40 @@ class DynamicWalletClient {
|
|
|
1605
1635
|
fileName
|
|
1606
1636
|
}));
|
|
1607
1637
|
} catch (error) {
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1638
|
+
logError({
|
|
1639
|
+
message: '[DynamicWaasWalletClient] Failed to download backup from Google Drive',
|
|
1640
|
+
error: error,
|
|
1641
|
+
context: {
|
|
1642
|
+
accountAddress,
|
|
1643
|
+
fileName
|
|
1644
|
+
}
|
|
1612
1645
|
});
|
|
1613
|
-
throw
|
|
1646
|
+
throw error;
|
|
1614
1647
|
}
|
|
1615
1648
|
if (!backupData) {
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1649
|
+
const error = new Error('No backup file found');
|
|
1650
|
+
logError({
|
|
1651
|
+
message: '[DynamicWaasWalletClient] No backup file found',
|
|
1652
|
+
error: new Error('No backup file found'),
|
|
1653
|
+
context: {
|
|
1654
|
+
accountAddress,
|
|
1655
|
+
fileName
|
|
1656
|
+
}
|
|
1619
1657
|
});
|
|
1620
|
-
throw
|
|
1658
|
+
throw error;
|
|
1621
1659
|
}
|
|
1622
1660
|
// Validate the backup data structure
|
|
1623
1661
|
if (!backupData.keyShares || !backupData.metadata) {
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1662
|
+
const error = new Error('Invalid backup format: missing keyShares or metadata');
|
|
1663
|
+
logError({
|
|
1664
|
+
message: '[DynamicWaasWalletClient] Invalid backup format: missing keyShares or metadata',
|
|
1665
|
+
error,
|
|
1666
|
+
context: {
|
|
1667
|
+
accountAddress,
|
|
1668
|
+
fileName
|
|
1669
|
+
}
|
|
1627
1670
|
});
|
|
1628
|
-
throw
|
|
1671
|
+
throw error;
|
|
1629
1672
|
}
|
|
1630
1673
|
const { keyShares } = backupData;
|
|
1631
1674
|
const decryptedKeyShares = await Promise.all(keyShares.map((keyShare)=>this.decryptKeyShare({
|
|
@@ -1639,16 +1682,12 @@ class DynamicWalletClient {
|
|
|
1639
1682
|
});
|
|
1640
1683
|
return decryptedKeyShares;
|
|
1641
1684
|
} catch (error) {
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
}
|
|
1649
|
-
this.logger.error(message, {
|
|
1650
|
-
error,
|
|
1651
|
-
context
|
|
1685
|
+
logError({
|
|
1686
|
+
message: '[DynamicWaasWalletClient] Error in restoreBackupFromGoogleDrive',
|
|
1687
|
+
error: error,
|
|
1688
|
+
context: {
|
|
1689
|
+
accountAddress
|
|
1690
|
+
}
|
|
1652
1691
|
});
|
|
1653
1692
|
throw error;
|
|
1654
1693
|
}
|
|
@@ -1775,8 +1814,14 @@ class DynamicWalletClient {
|
|
|
1775
1814
|
signedSessionId
|
|
1776
1815
|
});
|
|
1777
1816
|
} catch (error) {
|
|
1778
|
-
|
|
1779
|
-
|
|
1817
|
+
logError({
|
|
1818
|
+
message: '[DynamicWaasWalletClient] Error in verifyPassword',
|
|
1819
|
+
error: error,
|
|
1820
|
+
context: {
|
|
1821
|
+
accountAddress
|
|
1822
|
+
}
|
|
1823
|
+
});
|
|
1824
|
+
throw error;
|
|
1780
1825
|
}
|
|
1781
1826
|
}
|
|
1782
1827
|
async isPasswordEncrypted({ accountAddress }) {
|
|
@@ -1835,15 +1880,12 @@ class DynamicWalletClient {
|
|
|
1835
1880
|
walletProperties: wallet == null ? void 0 : wallet.walletProperties
|
|
1836
1881
|
});
|
|
1837
1882
|
} catch (error) {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1883
|
+
logError({
|
|
1884
|
+
message: '[DynamicWaasWalletClient] Error in getWalletClientKeyShareBackupInfo',
|
|
1885
|
+
error: error,
|
|
1886
|
+
context: {
|
|
1841
1887
|
accountAddress
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
this.logger.error(message, {
|
|
1845
|
-
error,
|
|
1846
|
-
accountAddress
|
|
1888
|
+
}
|
|
1847
1889
|
});
|
|
1848
1890
|
throw error;
|
|
1849
1891
|
}
|
|
@@ -1906,17 +1948,15 @@ class DynamicWalletClient {
|
|
|
1906
1948
|
}
|
|
1907
1949
|
return this.walletMap[accountAddress];
|
|
1908
1950
|
} catch (error) {
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
handleAxiosError(error, message, context);
|
|
1919
|
-
}
|
|
1951
|
+
logError({
|
|
1952
|
+
message: '[DynamicWaasWalletClient] Error in getWallet',
|
|
1953
|
+
error: error,
|
|
1954
|
+
context: {
|
|
1955
|
+
accountAddress,
|
|
1956
|
+
walletOperation,
|
|
1957
|
+
shareCount
|
|
1958
|
+
}
|
|
1959
|
+
});
|
|
1920
1960
|
throw error;
|
|
1921
1961
|
}
|
|
1922
1962
|
}
|
|
@@ -1954,12 +1994,10 @@ class DynamicWalletClient {
|
|
|
1954
1994
|
}, {});
|
|
1955
1995
|
return wallets;
|
|
1956
1996
|
} catch (error) {
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
this.logger.error(message, {
|
|
1962
|
-
error
|
|
1997
|
+
logError({
|
|
1998
|
+
message: '[DynamicWaasWalletClient] Error in getWallets',
|
|
1999
|
+
error: error,
|
|
2000
|
+
context: {}
|
|
1963
2001
|
});
|
|
1964
2002
|
throw error;
|
|
1965
2003
|
}
|
|
@@ -1992,13 +2030,15 @@ class DynamicWalletClient {
|
|
|
1992
2030
|
this.iframeDomain = IFRAME_DOMAIN_MAP[environment];
|
|
1993
2031
|
// Generate unique instanceId when client is created
|
|
1994
2032
|
this.instanceId = crypto.randomUUID();
|
|
2033
|
+
// initialize logger context
|
|
2034
|
+
this.initLoggerContext(authToken);
|
|
1995
2035
|
// initialize the client
|
|
1996
2036
|
this.initialize();
|
|
1997
2037
|
}
|
|
1998
2038
|
}
|
|
1999
2039
|
|
|
2000
2040
|
const ERROR_KEYGEN_FAILED = '[DynamicWaasWalletClient]: Error with keygen';
|
|
2001
|
-
const ERROR_CREATE_WALLET_ACCOUNT = '[DynamicWaasWalletClient]: Error creating
|
|
2041
|
+
const ERROR_CREATE_WALLET_ACCOUNT = '[DynamicWaasWalletClient]: Error creating wallet account';
|
|
2002
2042
|
const ERROR_SIGN_MESSAGE = '[DynamicWaasWalletClient]: Error signing message';
|
|
2003
2043
|
const ERROR_ACCOUNT_ADDRESS_REQUIRED = '[DynamicWaasWalletClient]: Account address is required';
|
|
2004
2044
|
const ERROR_VERIFY_MESSAGE_SIGNATURE = '[DynamicWaasWalletClient]: Error verifying message signature';
|