@dynamic-labs-wallet/browser 0.0.31 → 0.0.33

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 CHANGED
@@ -63,6 +63,47 @@ const isHexString = (str)=>{
63
63
  const getClientKeyShareExportFileName = ({ thresholdSignatureScheme, accountAddress })=>{
64
64
  return `${CLIENT_KEYSHARE_EXPORT_FILENAME_PREFIX}-${thresholdSignatureScheme}-${accountAddress}.json`;
65
65
  };
66
+ const getClientKeyShareBackupInfo = (params)=>{
67
+ var _params_walletProperties, _params_walletProperties_keyShares_;
68
+ const backups = {
69
+ [core.BackupLocation.DYNAMIC]: [],
70
+ [core.BackupLocation.GOOGLE_DRIVE]: [],
71
+ [core.BackupLocation.ICLOUD]: [],
72
+ [core.BackupLocation.USER]: [],
73
+ [core.BackupLocation.EXTERNAL]: []
74
+ };
75
+ if (!(params == null ? void 0 : (_params_walletProperties = params.walletProperties) == null ? void 0 : _params_walletProperties.keyShares)) {
76
+ return {
77
+ backups,
78
+ passwordEncrypted: false
79
+ };
80
+ }
81
+ params.walletProperties.keyShares.forEach((keyShare)=>{
82
+ if (backups[keyShare.backupLocation]) {
83
+ backups[keyShare.backupLocation].push(keyShare.id);
84
+ }
85
+ });
86
+ const passwordEncrypted = Boolean((_params_walletProperties_keyShares_ = params.walletProperties.keyShares[0]) == null ? void 0 : _params_walletProperties_keyShares_.passwordEncrypted);
87
+ return {
88
+ backups,
89
+ passwordEncrypted
90
+ };
91
+ };
92
+ /**
93
+ * Helper function to merge keyshares and remove duplicates based on pubkey and secretShare
94
+ * @param existingKeyShares - Array of existing keyshares
95
+ * @param newKeyShares - Array of new keyshares to merge
96
+ * @returns Array of merged unique keyshares
97
+ */ const mergeUniqueKeyShares = (existingKeyShares, newKeyShares)=>{
98
+ const uniqueKeyShares = newKeyShares.filter((newShare)=>!existingKeyShares.some((existingShare)=>{
99
+ if (!(newShare == null ? void 0 : newShare.pubkey) || !(existingShare == null ? void 0 : existingShare.pubkey)) return false;
100
+ return newShare.pubkey.toString() === existingShare.pubkey.toString() && newShare.secretShare === existingShare.secretShare;
101
+ }));
102
+ return [
103
+ ...existingKeyShares,
104
+ ...uniqueKeyShares
105
+ ];
106
+ };
66
107
 
67
108
  const PBKDF2_ALGORITHM = 'PBKDF2';
68
109
  const PBKDF2_ITERATIONS = 100000;
@@ -307,6 +348,17 @@ const localStorageWriteTest = {
307
348
  }
308
349
  });
309
350
 
351
+ var WalletOperation = /*#__PURE__*/ function(WalletOperation) {
352
+ WalletOperation["REACH_THRESHOLD"] = "REACH_THRESHOLD";
353
+ WalletOperation["REACH_ALL_PARTIES"] = "REACH_ALL_PARTIES";
354
+ WalletOperation["SIGN_MESSAGE"] = "SIGN_MESSAGE";
355
+ WalletOperation["SIGN_TRANSACTION"] = "SIGN_TRANSACTION";
356
+ WalletOperation["REFRESH"] = "REFRESH";
357
+ WalletOperation["RESHARE"] = "RESHARE";
358
+ WalletOperation["EXPORT_PRIVATE_KEY"] = "EXPORT_PRIVATE_KEY";
359
+ return WalletOperation;
360
+ }({});
361
+
310
362
  const logger = new logger$1.Logger('DynamicWaasWalletClient');
311
363
 
312
364
  class DynamicWalletClient {
@@ -495,7 +547,8 @@ class DynamicWalletClient {
495
547
  }
496
548
  async refreshWalletAccountShares({ accountAddress, chainName }) {
497
549
  const wallet = await this.getWallet({
498
- accountAddress
550
+ accountAddress,
551
+ walletOperation: WalletOperation.REFRESH
499
552
  });
500
553
  const mpcSigner = getMPCSigner({
501
554
  chainName,
@@ -566,8 +619,14 @@ class DynamicWalletClient {
566
619
  };
567
620
  }
568
621
  async reshare({ chainName, accountAddress, oldThresholdSignatureScheme, newThresholdSignatureScheme }) {
622
+ const { existingClientShareCount } = core.getReshareConfig({
623
+ oldThresholdSignatureScheme,
624
+ newThresholdSignatureScheme
625
+ });
569
626
  const wallet = await this.getWallet({
570
- accountAddress
627
+ accountAddress,
628
+ walletOperation: WalletOperation.RESHARE,
629
+ shareCount: existingClientShareCount
571
630
  });
572
631
  console.log(`Resharing from ${oldThresholdSignatureScheme} to ${newThresholdSignatureScheme}`);
573
632
  const { newClientInitKeygenResults, newClientKeygenIds, existingClientKeygenIds, existingClientKeyShares } = await this.reshareStrategy({
@@ -714,28 +773,51 @@ class DynamicWalletClient {
714
773
  const deserializedKeyShare = JSON.parse(decryptedKeyShare);
715
774
  return deserializedKeyShare;
716
775
  }
717
- async recoverEncryptedBackupByWallet({ accountAddress, password }) {
776
+ /**
777
+ * Helper function to determine keyshare recovery strategy for dynamic shares.
778
+ * For REFRESH operations, retrieves enough shares to meet the client threshold.
779
+ * For all other operations, retrieves just 1 share.
780
+ *
781
+ * @param clientKeyShareBackupInfo - Information about backed up key shares
782
+ * @param thresholdSignatureScheme - The signature scheme being used (2-of-2, 2-of-3, etc)
783
+ * @param walletOperation - The operation being performed (REFRESH, SIGN_MESSAGE, etc)
784
+ * @param shareCount - The number of shares to recover if specified for reshare operations
785
+ * @returns Object mapping backup locations to arrays of share IDs to recover
786
+ */ async recoverStrategy({ clientKeyShareBackupInfo, thresholdSignatureScheme, walletOperation, shareCount = undefined }) {
787
+ const { backups } = clientKeyShareBackupInfo;
788
+ const { clientThreshold } = core.MPC_CONFIG[thresholdSignatureScheme];
789
+ let requiredBackupCount = walletOperation === WalletOperation.REFRESH || walletOperation === WalletOperation.REACH_ALL_PARTIES || walletOperation === WalletOperation.RESHARE ? clientThreshold : 1;
790
+ // Override requiredBackupCount if shareCount is provided
791
+ if (shareCount !== undefined) {
792
+ requiredBackupCount = shareCount;
793
+ }
794
+ const dynamicShares = backups[core.BackupLocation.DYNAMIC].slice(0, requiredBackupCount);
795
+ return {
796
+ [core.BackupLocation.DYNAMIC]: dynamicShares
797
+ };
798
+ }
799
+ async recoverEncryptedBackupByWallet({ accountAddress, password, walletOperation, shareCount = undefined }) {
718
800
  const wallet = this.walletMap[accountAddress];
719
- this.logger.debug('recoverEncryptedBackupByWallet wallet', wallet);
801
+ this.logger.debug(`recoverEncryptedBackupByWallet wallet: ${walletOperation}`, wallet);
802
+ const { dynamic: dynamicKeyShareIds } = await this.recoverStrategy({
803
+ clientKeyShareBackupInfo: wallet.clientKeySharesBackupInfo,
804
+ thresholdSignatureScheme: wallet.thresholdSignatureScheme,
805
+ walletOperation,
806
+ shareCount
807
+ });
720
808
  const data = await this.apiClient.recoverEncryptedBackupByWallet({
721
- walletId: wallet.walletId
809
+ walletId: wallet.walletId,
810
+ keyShareIds: dynamicKeyShareIds
722
811
  });
723
- // TODO: allow handling backup from other sources
724
- const dynamicKeyShares = data.keyShares.filter((keyShare)=>keyShare.encryptedAccountCredential !== null && keyShare.backupLocation === 'dynamic');
812
+ const dynamicKeyShares = data.keyShares.filter((keyShare)=>keyShare.encryptedAccountCredential !== null && keyShare.backupLocation === core.BackupLocation.DYNAMIC);
725
813
  const decryptedKeyShares = await Promise.all(dynamicKeyShares.map((keyShare)=>this.decryptKeyShare({
726
814
  keyShare: keyShare.encryptedAccountCredential,
727
815
  password: password != null ? password : this.environmentId
728
816
  })));
729
- decryptedKeyShares.forEach((keyShare)=>{
730
- this.restoreBackupShare({
731
- walletId: wallet.walletId,
732
- accountAddress,
733
- chainName: data.chainName,
734
- keyShare,
735
- thresholdSignatureScheme: wallet.thresholdSignatureScheme,
736
- derivationPath: wallet.derivationPath
737
- });
817
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress], {
818
+ clientKeyShares: mergeUniqueKeyShares(this.walletMap[accountAddress].clientKeyShares || [], decryptedKeyShares)
738
819
  });
820
+ await this.storage.setItem(this.storageKey, JSON.stringify(this.walletMap));
739
821
  return decryptedKeyShares;
740
822
  }
741
823
  async restoreWallets() {
@@ -746,24 +828,10 @@ class DynamicWalletClient {
746
828
  }
747
829
  this.walletMap = JSON.parse(wallets);
748
830
  }
749
- async restoreBackupShare({ walletId, accountAddress, chainName, keyShare, thresholdSignatureScheme, derivationPath }) {
750
- var _this_walletMap_accountAddress;
751
- this.walletMap[accountAddress] = {
752
- walletId,
753
- chainName,
754
- accountAddress,
755
- clientKeyShares: [
756
- ...((_this_walletMap_accountAddress = this.walletMap[accountAddress]) == null ? void 0 : _this_walletMap_accountAddress.clientKeyShares) || [],
757
- keyShare
758
- ],
759
- thresholdSignatureScheme,
760
- derivationPath
761
- };
762
- await this.storage.setItem(this.storageKey, JSON.stringify(this.walletMap));
763
- }
764
831
  async backupKeySharesToGoogleDrive({ accountAddress, fileName, oauthAccountId, password }) {
765
832
  await this.getWallet({
766
- accountAddress
833
+ accountAddress,
834
+ walletOperation: WalletOperation.REACH_ALL_PARTIES
767
835
  });
768
836
  const clientKeyShares = this.walletMap[accountAddress].clientKeyShares;
769
837
  if (clientKeyShares.length === 0) {
@@ -848,16 +916,8 @@ class DynamicWalletClient {
848
916
  keyShare,
849
917
  password
850
918
  })));
851
- const existingKeyShares = this.walletMap[accountAddress].clientKeyShares || [];
852
- const uniqueKeyShares = decryptedKeyShares.filter((newShare)=>!existingKeyShares.some((existingShare)=>{
853
- if (!(newShare == null ? void 0 : newShare.pubkey) || !(existingShare == null ? void 0 : existingShare.pubkey)) return false;
854
- return newShare.pubkey.toString() === existingShare.pubkey.toString() && newShare.secretShare === existingShare.secretShare;
855
- }));
856
919
  this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress], {
857
- clientKeyShares: [
858
- ...existingKeyShares,
859
- ...uniqueKeyShares
860
- ]
920
+ clientKeyShares: mergeUniqueKeyShares(this.walletMap[accountAddress].clientKeyShares || [], decryptedKeyShares)
861
921
  });
862
922
  return decryptedKeyShares;
863
923
  }
@@ -906,6 +966,10 @@ class DynamicWalletClient {
906
966
  };
907
967
  }
908
968
  async exportClientKeyshares({ accountAddress }) {
969
+ await this.getWallet({
970
+ accountAddress,
971
+ walletOperation: WalletOperation.REACH_ALL_PARTIES
972
+ });
909
973
  const clientKeyShares = await this.getClientKeyShares({
910
974
  accountAddress
911
975
  });
@@ -934,69 +998,112 @@ class DynamicWalletClient {
934
998
  });
935
999
  return wallet.clientKeyShares;
936
1000
  }
937
- async getWallet({ accountAddress }) {
938
- if (accountAddress) {
939
- if (this.walletMap[accountAddress] && this.walletMap[accountAddress].clientKeyShares.length > 0 && this.walletMap[accountAddress].thresholdSignatureScheme && this.walletMap[accountAddress].derivationPath) {
940
- this.logger.debug('Wallet already exists', this.walletMap[accountAddress]);
941
- return this.walletMap[accountAddress];
942
- } else {
943
- var _user_verifiedCredentials;
944
- this.logger.debug('Wallet needs to be restored', this.walletMap[accountAddress]);
945
- const user = await this.apiClient.getUser();
946
- const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.find((vc)=>vc.address.toLowerCase() === accountAddress.toLowerCase());
947
- this.logger.debug('Restoring wallet', wallet);
948
- const clientShares = wallet.walletProperties.keyShares.filter((ks)=>ks.backupLocation === 'dynamic');
949
- this.logger.debug('clientShares', clientShares);
950
- const walletProperties = wallet.walletProperties;
951
- this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress], {
952
- walletId: wallet.id,
953
- chainName: wallet.chainName,
954
- accountAddress,
955
- thresholdSignatureScheme: walletProperties.thresholdSignatureScheme,
956
- derivationPath: walletProperties.derivationPath
957
- });
958
- // restore backup
959
- const decryptedKeyShares = await this.recoverEncryptedBackupByWallet({
960
- accountAddress,
961
- password: this.environmentId
962
- });
963
- //todo: check to see if their are other backups ie google drive, etc
964
- this.logger.debug('Recovered backup', decryptedKeyShares);
1001
+ /**
1002
+ * Helper function to check if the required wallet fields are present and valid
1003
+ * @param accountAddress - The account address of the wallet to check
1004
+ * @param walletOperation - The wallet operation that determines required fields
1005
+ * @returns boolean indicating if wallet needs to be re-fetched and restored from server
1006
+ */ async checkWalletFields({ accountAddress, walletOperation = WalletOperation.REACH_THRESHOLD, shareCount }) {
1007
+ let keyshareCheck = false;
1008
+ let walletCheck = false;
1009
+ let thresholdSignatureSchemeCheck = false;
1010
+ // check if wallet exists
1011
+ const existingWallet = this.walletMap[accountAddress];
1012
+ if (existingWallet) {
1013
+ walletCheck = true;
1014
+ }
1015
+ // check if threshold signature scheme exists
1016
+ if (existingWallet == null ? void 0 : existingWallet.thresholdSignatureScheme) {
1017
+ thresholdSignatureSchemeCheck = true;
1018
+ }
1019
+ // check if wallet already exists with sufficient keyshares
1020
+ if (existingWallet) {
1021
+ var _existingWallet_clientKeyShares;
1022
+ const { dynamic: requiredDynamicKeyShareIds = [] } = await this.recoverStrategy({
1023
+ clientKeyShareBackupInfo: existingWallet.clientKeySharesBackupInfo || {
1024
+ backups: getClientKeyShareBackupInfo()
1025
+ },
1026
+ thresholdSignatureScheme: existingWallet.thresholdSignatureScheme,
1027
+ walletOperation,
1028
+ shareCount
1029
+ });
1030
+ if (requiredDynamicKeyShareIds.length <= (((_existingWallet_clientKeyShares = existingWallet.clientKeyShares) == null ? void 0 : _existingWallet_clientKeyShares.length) || 0)) {
1031
+ keyshareCheck = true;
965
1032
  }
966
1033
  }
1034
+ return walletCheck && thresholdSignatureSchemeCheck && keyshareCheck;
1035
+ }
1036
+ async getWallet({ accountAddress, walletOperation = WalletOperation.REACH_THRESHOLD, shareCount = undefined }) {
1037
+ var _user_verifiedCredentials;
1038
+ const existingWalletCheck = await this.checkWalletFields({
1039
+ accountAddress,
1040
+ walletOperation,
1041
+ shareCount
1042
+ });
1043
+ if (existingWalletCheck) {
1044
+ this.logger.debug(`Wallet ${accountAddress} already exists`);
1045
+ return this.walletMap[accountAddress];
1046
+ }
1047
+ // Fetch and restore wallet from server
1048
+ const user = await this.apiClient.getUser();
1049
+ const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.find((vc)=>vc.address.toLowerCase() === accountAddress.toLowerCase());
1050
+ this.logger.debug('Restoring wallet', wallet);
1051
+ const walletProperties = wallet.walletProperties;
1052
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress], {
1053
+ walletId: wallet.id,
1054
+ chainName: wallet.chainName,
1055
+ accountAddress,
1056
+ thresholdSignatureScheme: walletProperties.thresholdSignatureScheme,
1057
+ derivationPath: walletProperties.derivationPath,
1058
+ clientKeySharesBackupInfo: getClientKeyShareBackupInfo({
1059
+ walletProperties
1060
+ })
1061
+ });
1062
+ // Restore backup to reach threshold
1063
+ const decryptedKeyShares = await this.recoverEncryptedBackupByWallet({
1064
+ accountAddress,
1065
+ password: this.environmentId,
1066
+ walletOperation: walletOperation,
1067
+ shareCount
1068
+ });
1069
+ this.logger.debug('Recovered backup', decryptedKeyShares);
967
1070
  const walletCount = Object.keys(this.walletMap).length;
968
- // if there are no wallets, throw an error
969
1071
  if (walletCount === 0) {
970
1072
  throw new Error('No wallets found');
971
1073
  }
972
- // if there is only one wallet, return it by default
1074
+ // Return the only wallet if there's just one
973
1075
  if (walletCount === 1) {
974
1076
  return Object.values(this.walletMap)[0];
975
1077
  }
976
- if (!accountAddress) {
977
- throw new Error('Must provide an account address');
978
- }
979
1078
  return this.walletMap[accountAddress];
980
1079
  }
981
1080
  async getWallets() {
982
1081
  var _user_verifiedCredentials;
983
1082
  const user = await this.apiClient.getUser();
984
1083
  const waasWallets = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.filter((vc)=>vc.walletName === 'dynamicwaas');
985
- const wallets = waasWallets.map((vc)=>({
1084
+ const wallets = waasWallets.map((vc)=>{
1085
+ var _vc_walletProperties;
1086
+ return {
986
1087
  walletId: vc.id,
987
1088
  chainName: vc.chain,
988
- accountAddress: vc.address
989
- }));
1089
+ accountAddress: vc.address,
1090
+ clientKeySharesBackupInfo: getClientKeyShareBackupInfo({
1091
+ walletProperties: vc.walletProperties || {}
1092
+ }),
1093
+ thresholdSignatureScheme: (_vc_walletProperties = vc.walletProperties) == null ? void 0 : _vc_walletProperties.thresholdSignatureScheme
1094
+ };
1095
+ });
990
1096
  this.walletMap = wallets.reduce((acc, wallet)=>{
991
- var _acc_accountAddress, _acc_accountAddress1, _acc_accountAddress2;
1097
+ var _acc_wallet_accountAddress, _acc_accountAddress;
992
1098
  const accountAddress = wallet.accountAddress;
993
1099
  acc[wallet.accountAddress] = {
994
1100
  walletId: wallet.walletId,
995
1101
  chainName: wallet.chainName,
996
- accountAddress: accountAddress,
997
- clientKeyShares: ((_acc_accountAddress = acc[accountAddress]) == null ? void 0 : _acc_accountAddress.clientKeyShares) || [],
998
- thresholdSignatureScheme: ((_acc_accountAddress1 = acc[accountAddress]) == null ? void 0 : _acc_accountAddress1.thresholdSignatureScheme) || undefined,
999
- derivationPath: ((_acc_accountAddress2 = acc[accountAddress]) == null ? void 0 : _acc_accountAddress2.derivationPath) || undefined
1102
+ accountAddress: wallet.accountAddress,
1103
+ clientKeyShares: ((_acc_wallet_accountAddress = acc[wallet.accountAddress]) == null ? void 0 : _acc_wallet_accountAddress.clientKeyShares) || [],
1104
+ clientKeySharesBackupInfo: wallet.clientKeySharesBackupInfo,
1105
+ derivationPath: ((_acc_accountAddress = acc[accountAddress]) == null ? void 0 : _acc_accountAddress.derivationPath) || undefined,
1106
+ thresholdSignatureScheme: wallet.thresholdSignatureScheme
1000
1107
  };
1001
1108
  return acc;
1002
1109
  }, {});
@@ -1079,8 +1186,18 @@ Object.defineProperty(exports, "MessageHash", {
1079
1186
  get: function () { return web.MessageHash; }
1080
1187
  });
1081
1188
  exports.DynamicWalletClient = DynamicWalletClient;
1189
+ exports.WalletOperation = WalletOperation;
1190
+ exports.base64ToBytes = base64ToBytes;
1191
+ exports.bytesToBase64 = bytesToBase64;
1192
+ exports.ensureBase64Padding = ensureBase64Padding;
1193
+ exports.getClientKeyShareBackupInfo = getClientKeyShareBackupInfo;
1194
+ exports.getClientKeyShareExportFileName = getClientKeyShareExportFileName;
1082
1195
  exports.getMPCSignatureScheme = getMPCSignatureScheme;
1083
1196
  exports.getMPCSigner = getMPCSigner;
1197
+ exports.isBrowser = isBrowser;
1198
+ exports.isHexString = isHexString;
1199
+ exports.mergeUniqueKeyShares = mergeUniqueKeyShares;
1200
+ exports.stringToBytes = stringToBytes;
1084
1201
  Object.keys(core).forEach(function (k) {
1085
1202
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1086
1203
  enumerable: true,
package/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { SigningAlgorithm, MPC_RELAY_PROD_API_URL, getMPCChainConfig, getClientThreshold, MPC_CONFIG, getReshareConfig, getTSSConfig, DynamicApiClient } from '@dynamic-labs-wallet/core';
1
+ import { SigningAlgorithm, MPC_RELAY_PROD_API_URL, getMPCChainConfig, BackupLocation, getClientThreshold, MPC_CONFIG, getReshareConfig, getTSSConfig, DynamicApiClient } from '@dynamic-labs-wallet/core';
2
2
  export * from '@dynamic-labs-wallet/core';
3
3
  import { BIP340, Ed25519, Ecdsa, MessageHash, EcdsaKeygenResult, Ed25519KeygenResult, BIP340KeygenResult } from './internal/web';
4
4
  export { BIP340, BIP340InitKeygenResult, BIP340KeygenResult, Ecdsa, EcdsaInitKeygenResult, EcdsaKeygenResult, EcdsaPublicKey, EcdsaSignature, Ed25519, Ed25519InitKeygenResult, Ed25519KeygenResult, MessageHash } from './internal/web';
@@ -63,6 +63,47 @@ const isHexString = (str)=>{
63
63
  const getClientKeyShareExportFileName = ({ thresholdSignatureScheme, accountAddress })=>{
64
64
  return `${CLIENT_KEYSHARE_EXPORT_FILENAME_PREFIX}-${thresholdSignatureScheme}-${accountAddress}.json`;
65
65
  };
66
+ const getClientKeyShareBackupInfo = (params)=>{
67
+ var _params_walletProperties, _params_walletProperties_keyShares_;
68
+ const backups = {
69
+ [BackupLocation.DYNAMIC]: [],
70
+ [BackupLocation.GOOGLE_DRIVE]: [],
71
+ [BackupLocation.ICLOUD]: [],
72
+ [BackupLocation.USER]: [],
73
+ [BackupLocation.EXTERNAL]: []
74
+ };
75
+ if (!(params == null ? void 0 : (_params_walletProperties = params.walletProperties) == null ? void 0 : _params_walletProperties.keyShares)) {
76
+ return {
77
+ backups,
78
+ passwordEncrypted: false
79
+ };
80
+ }
81
+ params.walletProperties.keyShares.forEach((keyShare)=>{
82
+ if (backups[keyShare.backupLocation]) {
83
+ backups[keyShare.backupLocation].push(keyShare.id);
84
+ }
85
+ });
86
+ const passwordEncrypted = Boolean((_params_walletProperties_keyShares_ = params.walletProperties.keyShares[0]) == null ? void 0 : _params_walletProperties_keyShares_.passwordEncrypted);
87
+ return {
88
+ backups,
89
+ passwordEncrypted
90
+ };
91
+ };
92
+ /**
93
+ * Helper function to merge keyshares and remove duplicates based on pubkey and secretShare
94
+ * @param existingKeyShares - Array of existing keyshares
95
+ * @param newKeyShares - Array of new keyshares to merge
96
+ * @returns Array of merged unique keyshares
97
+ */ const mergeUniqueKeyShares = (existingKeyShares, newKeyShares)=>{
98
+ const uniqueKeyShares = newKeyShares.filter((newShare)=>!existingKeyShares.some((existingShare)=>{
99
+ if (!(newShare == null ? void 0 : newShare.pubkey) || !(existingShare == null ? void 0 : existingShare.pubkey)) return false;
100
+ return newShare.pubkey.toString() === existingShare.pubkey.toString() && newShare.secretShare === existingShare.secretShare;
101
+ }));
102
+ return [
103
+ ...existingKeyShares,
104
+ ...uniqueKeyShares
105
+ ];
106
+ };
66
107
 
67
108
  const PBKDF2_ALGORITHM = 'PBKDF2';
68
109
  const PBKDF2_ITERATIONS = 100000;
@@ -307,6 +348,17 @@ const localStorageWriteTest = {
307
348
  }
308
349
  });
309
350
 
351
+ var WalletOperation = /*#__PURE__*/ function(WalletOperation) {
352
+ WalletOperation["REACH_THRESHOLD"] = "REACH_THRESHOLD";
353
+ WalletOperation["REACH_ALL_PARTIES"] = "REACH_ALL_PARTIES";
354
+ WalletOperation["SIGN_MESSAGE"] = "SIGN_MESSAGE";
355
+ WalletOperation["SIGN_TRANSACTION"] = "SIGN_TRANSACTION";
356
+ WalletOperation["REFRESH"] = "REFRESH";
357
+ WalletOperation["RESHARE"] = "RESHARE";
358
+ WalletOperation["EXPORT_PRIVATE_KEY"] = "EXPORT_PRIVATE_KEY";
359
+ return WalletOperation;
360
+ }({});
361
+
310
362
  const logger = new Logger('DynamicWaasWalletClient');
311
363
 
312
364
  class DynamicWalletClient {
@@ -495,7 +547,8 @@ class DynamicWalletClient {
495
547
  }
496
548
  async refreshWalletAccountShares({ accountAddress, chainName }) {
497
549
  const wallet = await this.getWallet({
498
- accountAddress
550
+ accountAddress,
551
+ walletOperation: WalletOperation.REFRESH
499
552
  });
500
553
  const mpcSigner = getMPCSigner({
501
554
  chainName,
@@ -566,8 +619,14 @@ class DynamicWalletClient {
566
619
  };
567
620
  }
568
621
  async reshare({ chainName, accountAddress, oldThresholdSignatureScheme, newThresholdSignatureScheme }) {
622
+ const { existingClientShareCount } = getReshareConfig({
623
+ oldThresholdSignatureScheme,
624
+ newThresholdSignatureScheme
625
+ });
569
626
  const wallet = await this.getWallet({
570
- accountAddress
627
+ accountAddress,
628
+ walletOperation: WalletOperation.RESHARE,
629
+ shareCount: existingClientShareCount
571
630
  });
572
631
  console.log(`Resharing from ${oldThresholdSignatureScheme} to ${newThresholdSignatureScheme}`);
573
632
  const { newClientInitKeygenResults, newClientKeygenIds, existingClientKeygenIds, existingClientKeyShares } = await this.reshareStrategy({
@@ -714,28 +773,51 @@ class DynamicWalletClient {
714
773
  const deserializedKeyShare = JSON.parse(decryptedKeyShare);
715
774
  return deserializedKeyShare;
716
775
  }
717
- async recoverEncryptedBackupByWallet({ accountAddress, password }) {
776
+ /**
777
+ * Helper function to determine keyshare recovery strategy for dynamic shares.
778
+ * For REFRESH operations, retrieves enough shares to meet the client threshold.
779
+ * For all other operations, retrieves just 1 share.
780
+ *
781
+ * @param clientKeyShareBackupInfo - Information about backed up key shares
782
+ * @param thresholdSignatureScheme - The signature scheme being used (2-of-2, 2-of-3, etc)
783
+ * @param walletOperation - The operation being performed (REFRESH, SIGN_MESSAGE, etc)
784
+ * @param shareCount - The number of shares to recover if specified for reshare operations
785
+ * @returns Object mapping backup locations to arrays of share IDs to recover
786
+ */ async recoverStrategy({ clientKeyShareBackupInfo, thresholdSignatureScheme, walletOperation, shareCount = undefined }) {
787
+ const { backups } = clientKeyShareBackupInfo;
788
+ const { clientThreshold } = MPC_CONFIG[thresholdSignatureScheme];
789
+ let requiredBackupCount = walletOperation === WalletOperation.REFRESH || walletOperation === WalletOperation.REACH_ALL_PARTIES || walletOperation === WalletOperation.RESHARE ? clientThreshold : 1;
790
+ // Override requiredBackupCount if shareCount is provided
791
+ if (shareCount !== undefined) {
792
+ requiredBackupCount = shareCount;
793
+ }
794
+ const dynamicShares = backups[BackupLocation.DYNAMIC].slice(0, requiredBackupCount);
795
+ return {
796
+ [BackupLocation.DYNAMIC]: dynamicShares
797
+ };
798
+ }
799
+ async recoverEncryptedBackupByWallet({ accountAddress, password, walletOperation, shareCount = undefined }) {
718
800
  const wallet = this.walletMap[accountAddress];
719
- this.logger.debug('recoverEncryptedBackupByWallet wallet', wallet);
801
+ this.logger.debug(`recoverEncryptedBackupByWallet wallet: ${walletOperation}`, wallet);
802
+ const { dynamic: dynamicKeyShareIds } = await this.recoverStrategy({
803
+ clientKeyShareBackupInfo: wallet.clientKeySharesBackupInfo,
804
+ thresholdSignatureScheme: wallet.thresholdSignatureScheme,
805
+ walletOperation,
806
+ shareCount
807
+ });
720
808
  const data = await this.apiClient.recoverEncryptedBackupByWallet({
721
- walletId: wallet.walletId
809
+ walletId: wallet.walletId,
810
+ keyShareIds: dynamicKeyShareIds
722
811
  });
723
- // TODO: allow handling backup from other sources
724
- const dynamicKeyShares = data.keyShares.filter((keyShare)=>keyShare.encryptedAccountCredential !== null && keyShare.backupLocation === 'dynamic');
812
+ const dynamicKeyShares = data.keyShares.filter((keyShare)=>keyShare.encryptedAccountCredential !== null && keyShare.backupLocation === BackupLocation.DYNAMIC);
725
813
  const decryptedKeyShares = await Promise.all(dynamicKeyShares.map((keyShare)=>this.decryptKeyShare({
726
814
  keyShare: keyShare.encryptedAccountCredential,
727
815
  password: password != null ? password : this.environmentId
728
816
  })));
729
- decryptedKeyShares.forEach((keyShare)=>{
730
- this.restoreBackupShare({
731
- walletId: wallet.walletId,
732
- accountAddress,
733
- chainName: data.chainName,
734
- keyShare,
735
- thresholdSignatureScheme: wallet.thresholdSignatureScheme,
736
- derivationPath: wallet.derivationPath
737
- });
817
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress], {
818
+ clientKeyShares: mergeUniqueKeyShares(this.walletMap[accountAddress].clientKeyShares || [], decryptedKeyShares)
738
819
  });
820
+ await this.storage.setItem(this.storageKey, JSON.stringify(this.walletMap));
739
821
  return decryptedKeyShares;
740
822
  }
741
823
  async restoreWallets() {
@@ -746,24 +828,10 @@ class DynamicWalletClient {
746
828
  }
747
829
  this.walletMap = JSON.parse(wallets);
748
830
  }
749
- async restoreBackupShare({ walletId, accountAddress, chainName, keyShare, thresholdSignatureScheme, derivationPath }) {
750
- var _this_walletMap_accountAddress;
751
- this.walletMap[accountAddress] = {
752
- walletId,
753
- chainName,
754
- accountAddress,
755
- clientKeyShares: [
756
- ...((_this_walletMap_accountAddress = this.walletMap[accountAddress]) == null ? void 0 : _this_walletMap_accountAddress.clientKeyShares) || [],
757
- keyShare
758
- ],
759
- thresholdSignatureScheme,
760
- derivationPath
761
- };
762
- await this.storage.setItem(this.storageKey, JSON.stringify(this.walletMap));
763
- }
764
831
  async backupKeySharesToGoogleDrive({ accountAddress, fileName, oauthAccountId, password }) {
765
832
  await this.getWallet({
766
- accountAddress
833
+ accountAddress,
834
+ walletOperation: WalletOperation.REACH_ALL_PARTIES
767
835
  });
768
836
  const clientKeyShares = this.walletMap[accountAddress].clientKeyShares;
769
837
  if (clientKeyShares.length === 0) {
@@ -848,16 +916,8 @@ class DynamicWalletClient {
848
916
  keyShare,
849
917
  password
850
918
  })));
851
- const existingKeyShares = this.walletMap[accountAddress].clientKeyShares || [];
852
- const uniqueKeyShares = decryptedKeyShares.filter((newShare)=>!existingKeyShares.some((existingShare)=>{
853
- if (!(newShare == null ? void 0 : newShare.pubkey) || !(existingShare == null ? void 0 : existingShare.pubkey)) return false;
854
- return newShare.pubkey.toString() === existingShare.pubkey.toString() && newShare.secretShare === existingShare.secretShare;
855
- }));
856
919
  this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress], {
857
- clientKeyShares: [
858
- ...existingKeyShares,
859
- ...uniqueKeyShares
860
- ]
920
+ clientKeyShares: mergeUniqueKeyShares(this.walletMap[accountAddress].clientKeyShares || [], decryptedKeyShares)
861
921
  });
862
922
  return decryptedKeyShares;
863
923
  }
@@ -906,6 +966,10 @@ class DynamicWalletClient {
906
966
  };
907
967
  }
908
968
  async exportClientKeyshares({ accountAddress }) {
969
+ await this.getWallet({
970
+ accountAddress,
971
+ walletOperation: WalletOperation.REACH_ALL_PARTIES
972
+ });
909
973
  const clientKeyShares = await this.getClientKeyShares({
910
974
  accountAddress
911
975
  });
@@ -934,69 +998,112 @@ class DynamicWalletClient {
934
998
  });
935
999
  return wallet.clientKeyShares;
936
1000
  }
937
- async getWallet({ accountAddress }) {
938
- if (accountAddress) {
939
- if (this.walletMap[accountAddress] && this.walletMap[accountAddress].clientKeyShares.length > 0 && this.walletMap[accountAddress].thresholdSignatureScheme && this.walletMap[accountAddress].derivationPath) {
940
- this.logger.debug('Wallet already exists', this.walletMap[accountAddress]);
941
- return this.walletMap[accountAddress];
942
- } else {
943
- var _user_verifiedCredentials;
944
- this.logger.debug('Wallet needs to be restored', this.walletMap[accountAddress]);
945
- const user = await this.apiClient.getUser();
946
- const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.find((vc)=>vc.address.toLowerCase() === accountAddress.toLowerCase());
947
- this.logger.debug('Restoring wallet', wallet);
948
- const clientShares = wallet.walletProperties.keyShares.filter((ks)=>ks.backupLocation === 'dynamic');
949
- this.logger.debug('clientShares', clientShares);
950
- const walletProperties = wallet.walletProperties;
951
- this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress], {
952
- walletId: wallet.id,
953
- chainName: wallet.chainName,
954
- accountAddress,
955
- thresholdSignatureScheme: walletProperties.thresholdSignatureScheme,
956
- derivationPath: walletProperties.derivationPath
957
- });
958
- // restore backup
959
- const decryptedKeyShares = await this.recoverEncryptedBackupByWallet({
960
- accountAddress,
961
- password: this.environmentId
962
- });
963
- //todo: check to see if their are other backups ie google drive, etc
964
- this.logger.debug('Recovered backup', decryptedKeyShares);
1001
+ /**
1002
+ * Helper function to check if the required wallet fields are present and valid
1003
+ * @param accountAddress - The account address of the wallet to check
1004
+ * @param walletOperation - The wallet operation that determines required fields
1005
+ * @returns boolean indicating if wallet needs to be re-fetched and restored from server
1006
+ */ async checkWalletFields({ accountAddress, walletOperation = WalletOperation.REACH_THRESHOLD, shareCount }) {
1007
+ let keyshareCheck = false;
1008
+ let walletCheck = false;
1009
+ let thresholdSignatureSchemeCheck = false;
1010
+ // check if wallet exists
1011
+ const existingWallet = this.walletMap[accountAddress];
1012
+ if (existingWallet) {
1013
+ walletCheck = true;
1014
+ }
1015
+ // check if threshold signature scheme exists
1016
+ if (existingWallet == null ? void 0 : existingWallet.thresholdSignatureScheme) {
1017
+ thresholdSignatureSchemeCheck = true;
1018
+ }
1019
+ // check if wallet already exists with sufficient keyshares
1020
+ if (existingWallet) {
1021
+ var _existingWallet_clientKeyShares;
1022
+ const { dynamic: requiredDynamicKeyShareIds = [] } = await this.recoverStrategy({
1023
+ clientKeyShareBackupInfo: existingWallet.clientKeySharesBackupInfo || {
1024
+ backups: getClientKeyShareBackupInfo()
1025
+ },
1026
+ thresholdSignatureScheme: existingWallet.thresholdSignatureScheme,
1027
+ walletOperation,
1028
+ shareCount
1029
+ });
1030
+ if (requiredDynamicKeyShareIds.length <= (((_existingWallet_clientKeyShares = existingWallet.clientKeyShares) == null ? void 0 : _existingWallet_clientKeyShares.length) || 0)) {
1031
+ keyshareCheck = true;
965
1032
  }
966
1033
  }
1034
+ return walletCheck && thresholdSignatureSchemeCheck && keyshareCheck;
1035
+ }
1036
+ async getWallet({ accountAddress, walletOperation = WalletOperation.REACH_THRESHOLD, shareCount = undefined }) {
1037
+ var _user_verifiedCredentials;
1038
+ const existingWalletCheck = await this.checkWalletFields({
1039
+ accountAddress,
1040
+ walletOperation,
1041
+ shareCount
1042
+ });
1043
+ if (existingWalletCheck) {
1044
+ this.logger.debug(`Wallet ${accountAddress} already exists`);
1045
+ return this.walletMap[accountAddress];
1046
+ }
1047
+ // Fetch and restore wallet from server
1048
+ const user = await this.apiClient.getUser();
1049
+ const wallet = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.find((vc)=>vc.address.toLowerCase() === accountAddress.toLowerCase());
1050
+ this.logger.debug('Restoring wallet', wallet);
1051
+ const walletProperties = wallet.walletProperties;
1052
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress], {
1053
+ walletId: wallet.id,
1054
+ chainName: wallet.chainName,
1055
+ accountAddress,
1056
+ thresholdSignatureScheme: walletProperties.thresholdSignatureScheme,
1057
+ derivationPath: walletProperties.derivationPath,
1058
+ clientKeySharesBackupInfo: getClientKeyShareBackupInfo({
1059
+ walletProperties
1060
+ })
1061
+ });
1062
+ // Restore backup to reach threshold
1063
+ const decryptedKeyShares = await this.recoverEncryptedBackupByWallet({
1064
+ accountAddress,
1065
+ password: this.environmentId,
1066
+ walletOperation: walletOperation,
1067
+ shareCount
1068
+ });
1069
+ this.logger.debug('Recovered backup', decryptedKeyShares);
967
1070
  const walletCount = Object.keys(this.walletMap).length;
968
- // if there are no wallets, throw an error
969
1071
  if (walletCount === 0) {
970
1072
  throw new Error('No wallets found');
971
1073
  }
972
- // if there is only one wallet, return it by default
1074
+ // Return the only wallet if there's just one
973
1075
  if (walletCount === 1) {
974
1076
  return Object.values(this.walletMap)[0];
975
1077
  }
976
- if (!accountAddress) {
977
- throw new Error('Must provide an account address');
978
- }
979
1078
  return this.walletMap[accountAddress];
980
1079
  }
981
1080
  async getWallets() {
982
1081
  var _user_verifiedCredentials;
983
1082
  const user = await this.apiClient.getUser();
984
1083
  const waasWallets = (_user_verifiedCredentials = user.verifiedCredentials) == null ? void 0 : _user_verifiedCredentials.filter((vc)=>vc.walletName === 'dynamicwaas');
985
- const wallets = waasWallets.map((vc)=>({
1084
+ const wallets = waasWallets.map((vc)=>{
1085
+ var _vc_walletProperties;
1086
+ return {
986
1087
  walletId: vc.id,
987
1088
  chainName: vc.chain,
988
- accountAddress: vc.address
989
- }));
1089
+ accountAddress: vc.address,
1090
+ clientKeySharesBackupInfo: getClientKeyShareBackupInfo({
1091
+ walletProperties: vc.walletProperties || {}
1092
+ }),
1093
+ thresholdSignatureScheme: (_vc_walletProperties = vc.walletProperties) == null ? void 0 : _vc_walletProperties.thresholdSignatureScheme
1094
+ };
1095
+ });
990
1096
  this.walletMap = wallets.reduce((acc, wallet)=>{
991
- var _acc_accountAddress, _acc_accountAddress1, _acc_accountAddress2;
1097
+ var _acc_wallet_accountAddress, _acc_accountAddress;
992
1098
  const accountAddress = wallet.accountAddress;
993
1099
  acc[wallet.accountAddress] = {
994
1100
  walletId: wallet.walletId,
995
1101
  chainName: wallet.chainName,
996
- accountAddress: accountAddress,
997
- clientKeyShares: ((_acc_accountAddress = acc[accountAddress]) == null ? void 0 : _acc_accountAddress.clientKeyShares) || [],
998
- thresholdSignatureScheme: ((_acc_accountAddress1 = acc[accountAddress]) == null ? void 0 : _acc_accountAddress1.thresholdSignatureScheme) || undefined,
999
- derivationPath: ((_acc_accountAddress2 = acc[accountAddress]) == null ? void 0 : _acc_accountAddress2.derivationPath) || undefined
1102
+ accountAddress: wallet.accountAddress,
1103
+ clientKeyShares: ((_acc_wallet_accountAddress = acc[wallet.accountAddress]) == null ? void 0 : _acc_wallet_accountAddress.clientKeyShares) || [],
1104
+ clientKeySharesBackupInfo: wallet.clientKeySharesBackupInfo,
1105
+ derivationPath: ((_acc_accountAddress = acc[accountAddress]) == null ? void 0 : _acc_accountAddress.derivationPath) || undefined,
1106
+ thresholdSignatureScheme: wallet.thresholdSignatureScheme
1000
1107
  };
1001
1108
  return acc;
1002
1109
  }, {});
@@ -1030,4 +1137,4 @@ class DynamicWalletClient {
1030
1137
  }
1031
1138
  }
1032
1139
 
1033
- export { DynamicWalletClient, getMPCSignatureScheme, getMPCSigner };
1140
+ export { DynamicWalletClient, WalletOperation, base64ToBytes, bytesToBase64, ensureBase64Padding, getClientKeyShareBackupInfo, getClientKeyShareExportFileName, getMPCSignatureScheme, getMPCSigner, isBrowser, isHexString, mergeUniqueKeyShares, stringToBytes };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/browser",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "dependencies": {
5
- "@dynamic-labs-wallet/core": "0.0.31",
5
+ "@dynamic-labs-wallet/core": "0.0.33",
6
6
  "@dynamic-labs/logger": "^4.5.1"
7
7
  },
8
8
  "files": [
package/src/client.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ThresholdSignatureScheme, DynamicApiClient } from '@dynamic-labs-wallet/core';
1
+ import { ThresholdSignatureScheme, DynamicApiClient, BackupLocation } from '@dynamic-labs-wallet/core';
2
2
  import { EcdsaPublicKey, EcdsaKeygenResult, Ed25519KeygenResult, BIP340KeygenResult, EcdsaSignature } from '../../internal/web';
3
3
  import { ClientInitKeygenResult, ClientKeyShare } from './mpc/types';
4
4
  import { SupportedStorage } from './services/localStorage';
5
- import { DynamicWalletClientProps, InitializeResult, WalletProperties } from './types';
5
+ import { DynamicWalletClientProps, InitializeResult, KeyShareBackupInfo, WalletProperties, WalletOperation } from './types';
6
6
  export declare class DynamicWalletClient {
7
7
  environmentId: string;
8
8
  storageKey: string;
@@ -65,7 +65,7 @@ export declare class DynamicWalletClient {
65
65
  derivationPath: Uint32Array | undefined;
66
66
  }): Promise<Uint8Array | EcdsaSignature>;
67
67
  sign({ accountAddress, message, chainName, }: {
68
- accountAddress?: string;
68
+ accountAddress: string;
69
69
  message: string | Uint8Array;
70
70
  chainName: string;
71
71
  }): Promise<Uint8Array | EcdsaSignature>;
@@ -133,19 +133,30 @@ export declare class DynamicWalletClient {
133
133
  keyShare: string;
134
134
  password?: string;
135
135
  }): Promise<ClientKeyShare>;
136
- recoverEncryptedBackupByWallet({ accountAddress, password, }: {
136
+ /**
137
+ * Helper function to determine keyshare recovery strategy for dynamic shares.
138
+ * For REFRESH operations, retrieves enough shares to meet the client threshold.
139
+ * For all other operations, retrieves just 1 share.
140
+ *
141
+ * @param clientKeyShareBackupInfo - Information about backed up key shares
142
+ * @param thresholdSignatureScheme - The signature scheme being used (2-of-2, 2-of-3, etc)
143
+ * @param walletOperation - The operation being performed (REFRESH, SIGN_MESSAGE, etc)
144
+ * @param shareCount - The number of shares to recover if specified for reshare operations
145
+ * @returns Object mapping backup locations to arrays of share IDs to recover
146
+ */
147
+ recoverStrategy({ clientKeyShareBackupInfo, thresholdSignatureScheme, walletOperation, shareCount, }: {
148
+ clientKeyShareBackupInfo: KeyShareBackupInfo;
149
+ thresholdSignatureScheme: ThresholdSignatureScheme;
150
+ walletOperation: WalletOperation;
151
+ shareCount?: number;
152
+ }): Promise<Partial<Record<BackupLocation, string[]>>>;
153
+ recoverEncryptedBackupByWallet({ accountAddress, password, walletOperation, shareCount, }: {
137
154
  accountAddress: string;
138
155
  password?: string;
156
+ walletOperation: WalletOperation;
157
+ shareCount?: number;
139
158
  }): Promise<any[]>;
140
159
  restoreWallets(): Promise<void>;
141
- restoreBackupShare({ walletId, accountAddress, chainName, keyShare, thresholdSignatureScheme, derivationPath, }: {
142
- walletId: string;
143
- accountAddress: string;
144
- chainName: string;
145
- keyShare: ClientKeyShare;
146
- thresholdSignatureScheme: ThresholdSignatureScheme;
147
- derivationPath?: string;
148
- }): Promise<void>;
149
160
  backupKeySharesToGoogleDrive({ accountAddress, fileName, oauthAccountId, password, }: {
150
161
  accountAddress: string;
151
162
  fileName?: string;
@@ -170,13 +181,22 @@ export declare class DynamicWalletClient {
170
181
  clientKeyShares: ClientKeyShare[];
171
182
  }>;
172
183
  exportClientKeyshares({ accountAddress }: {
173
- accountAddress?: string;
184
+ accountAddress: string;
174
185
  }): Promise<void>;
175
186
  getClientKeyShares({ accountAddress }: {
176
- accountAddress?: string;
187
+ accountAddress: string;
177
188
  }): Promise<ClientKeyShare[]>;
178
- getWallet({ accountAddress }: {
179
- accountAddress?: string;
189
+ /**
190
+ * Helper function to check if the required wallet fields are present and valid
191
+ * @param accountAddress - The account address of the wallet to check
192
+ * @param walletOperation - The wallet operation that determines required fields
193
+ * @returns boolean indicating if wallet needs to be re-fetched and restored from server
194
+ */
195
+ private checkWalletFields;
196
+ getWallet({ accountAddress, walletOperation, shareCount, }: {
197
+ accountAddress: string;
198
+ walletOperation?: WalletOperation;
199
+ shareCount?: number;
180
200
  }): Promise<WalletProperties>;
181
201
  getWallets(): Promise<any>;
182
202
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../packages/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wBAAwB,EACxB,gBAAgB,EAIjB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAIL,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAElB,cAAc,EACf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAoBrE,OAAO,EAGL,gBAAgB,EAEjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,wBAAwB,EACxB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAIjB,qBAAa,mBAAmB;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IAEtB,SAAS,CAAC,iBAAiB,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAQ;IACrE,SAAS,CAAC,MAAM,wCAAU;IAC1B,SAAS,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACtC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,gB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,SAAS,EAAE,MAAM,CAAC;QAClB,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;IAkEI,qBAAqB,CAAC,EAAE,cAAc,EAAE,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE;IAyBpE,kBAAkB,CAAC,EAAE,cAAc,EAAE,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE;IAKvE;;;;;OAKG;YACW,iBAAiB;IA2CzB,SAAS,CAAC,EACd,cAAc,EACd,eAAiD,EACjD,UAAsB,GACvB,EAAE;QACD,cAAc,EAAE,MAAM,CAAC;QACvB,eAAe,CAAC,EAAE,eAAe,CAAC;QAClC,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;IAqDK,UAAU;CAiCjB"}
package/src/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from '@dynamic-labs-wallet/core';
2
2
  export * from './client';
3
3
  export * from './types';
4
4
  export * from './mpc/index';
5
+ export * from './utils';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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"}
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;AAC5B,cAAc,SAAS,CAAC"}
package/src/types.d.ts CHANGED
@@ -1,16 +1,40 @@
1
- import { ThresholdSignatureScheme } from '.';
1
+ import { BackupLocation, ThresholdSignatureScheme } from '.';
2
2
  import { ClientKeyShare } from './mpc/types';
3
3
  export type InitializeResult = {
4
4
  error: unknown | null;
5
5
  };
6
+ export declare enum WalletOperation {
7
+ REACH_THRESHOLD = "REACH_THRESHOLD",
8
+ REACH_ALL_PARTIES = "REACH_ALL_PARTIES",
9
+ SIGN_MESSAGE = "SIGN_MESSAGE",
10
+ SIGN_TRANSACTION = "SIGN_TRANSACTION",
11
+ REFRESH = "REFRESH",
12
+ RESHARE = "RESHARE",
13
+ EXPORT_PRIVATE_KEY = "EXPORT_PRIVATE_KEY"
14
+ }
6
15
  export interface WalletProperties {
7
16
  chainName: string;
8
17
  walletId: string;
9
18
  accountAddress: string;
10
19
  clientKeyShares: ClientKeyShare[];
20
+ clientKeySharesBackupInfo: KeyShareBackupInfo;
11
21
  thresholdSignatureScheme: ThresholdSignatureScheme;
12
22
  derivationPath?: string;
13
23
  }
24
+ export interface KeyShareBackupInfo {
25
+ passwordEncrypted: boolean;
26
+ backups: Record<BackupLocation, string[]>;
27
+ }
28
+ export interface WaasWalletProperties {
29
+ derivationPath: string;
30
+ keyShares: KeyShareInfo[];
31
+ thresholdSignatureScheme: ThresholdSignatureScheme;
32
+ }
33
+ export interface KeyShareInfo {
34
+ id: string;
35
+ backupLocation: BackupLocation;
36
+ passwordEncrypted: boolean;
37
+ }
14
38
  export interface DynamicWalletClientProps {
15
39
  environmentId: string;
16
40
  authToken: string;
@@ -1 +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,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AM,CAAC;YAClB,aAAa,EAAE,MAAM,CAAC;YACtB,UAAU,EAAE,MAAM,CAAC;YACnB,aAAa,EAAE,MAAM,CAAC;SACvB,CAAC;QACF,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC"}
package/src/utils.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { ThresholdSignatureScheme } from "@dynamic-labs-wallet/core";
2
+ import { KeyShareBackupInfo, WaasWalletProperties } from "./types";
3
+ import { ClientKeyShare } from "./mpc/types";
2
4
  export declare const bytesToBase64: (arr: Uint8Array) => string;
3
5
  export declare const stringToBytes: (str: string) => Uint8Array;
4
6
  export declare const base64ToBytes: (base64: string) => Uint8Array;
@@ -9,4 +11,14 @@ export declare const getClientKeyShareExportFileName: ({ thresholdSignatureSchem
9
11
  thresholdSignatureScheme: ThresholdSignatureScheme;
10
12
  accountAddress: string;
11
13
  }) => string;
14
+ export declare const getClientKeyShareBackupInfo: (params?: {
15
+ walletProperties: WaasWalletProperties;
16
+ }) => KeyShareBackupInfo;
17
+ /**
18
+ * Helper function to merge keyshares and remove duplicates based on pubkey and secretShare
19
+ * @param existingKeyShares - Array of existing keyshares
20
+ * @param newKeyShares - Array of new keyshares to merge
21
+ * @returns Array of merged unique keyshares
22
+ */
23
+ export declare const mergeUniqueKeyShares: (existingKeyShares: ClientKeyShare[], newKeyShares: ClientKeyShare[]) => ClientKeyShare[];
12
24
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAGrE,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,KA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