@metamask-previews/seedless-onboarding-controller 3.0.0-preview-e821953 → 3.0.0-preview-8159614
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/dist/SeedlessOnboardingController.cjs +72 -91
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +74 -93
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/assertions.cjs +1 -1
- package/dist/assertions.cjs.map +1 -1
- package/dist/assertions.mjs +1 -1
- package/dist/assertions.mjs.map +1 -1
- package/dist/constants.cjs +0 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +0 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +0 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +0 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +9 -7
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +9 -7
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +66 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +30 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +30 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +62 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_isUnlocked,
|
|
13
|
+
var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_passwordOutdatedCacheTTL, _SeedlessOnboardingController_isUnlocked, _SeedlessOnboardingController_cachedDecryptedVaultData, _SeedlessOnboardingController_submitGlobalPassword, _SeedlessOnboardingController_getAccessToken, _SeedlessOnboardingController_setUnlocked, _SeedlessOnboardingController_persistOprfKey, _SeedlessOnboardingController_persistAuthPubKey, _SeedlessOnboardingController_storeKeyringEncryptionKey, _SeedlessOnboardingController_loadKeyringEncryptionKey, _SeedlessOnboardingController_loadSeedlessEncryptionKey, _SeedlessOnboardingController_recoverAuthPubKey, _SeedlessOnboardingController_recoverEncKey, _SeedlessOnboardingController_fetchAllSecretDataFromMetadataStore, _SeedlessOnboardingController_changeEncryptionKey, _SeedlessOnboardingController_encryptAndStoreSecretData, _SeedlessOnboardingController_unlockVaultAndGetVaultData, _SeedlessOnboardingController_decryptAndParseVaultData, _SeedlessOnboardingController_withPersistedSecretMetadataBackupsState, _SeedlessOnboardingController_filterDupesAndUpdateSocialBackupsMetadata, _SeedlessOnboardingController_createNewVaultWithAuthData, _SeedlessOnboardingController_updateVault, _SeedlessOnboardingController_withControllerLock, _SeedlessOnboardingController_withVaultLock, _SeedlessOnboardingController_parseVaultData, _SeedlessOnboardingController_assertIsUnlocked, _SeedlessOnboardingController_assertIsAuthenticatedUser, _SeedlessOnboardingController_assertIsSRPBackedUpUser, _SeedlessOnboardingController_assertPasswordInSync, _SeedlessOnboardingController_resetPasswordOutdatedCache, _SeedlessOnboardingController_isTokenExpiredError, _SeedlessOnboardingController_isMaxKeyChainLengthError, _SeedlessOnboardingController_executeWithTokenRefresh;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SeedlessOnboardingController = exports.getInitialSeedlessOnboardingControllerStateWithDefaults = void 0;
|
|
16
16
|
const auth_network_utils_1 = require("@metamask/auth-network-utils");
|
|
@@ -167,6 +167,10 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
167
167
|
_SeedlessOnboardingController_vaultOperationMutex.set(this, new async_mutex_1.Mutex());
|
|
168
168
|
_SeedlessOnboardingController_refreshJWTToken.set(this, void 0);
|
|
169
169
|
_SeedlessOnboardingController_revokeRefreshToken.set(this, void 0);
|
|
170
|
+
/**
|
|
171
|
+
* The TTL of the password outdated cache in milliseconds.
|
|
172
|
+
*/
|
|
173
|
+
_SeedlessOnboardingController_passwordOutdatedCacheTTL.set(this, void 0);
|
|
170
174
|
/**
|
|
171
175
|
* Controller lock state.
|
|
172
176
|
*
|
|
@@ -174,9 +178,11 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
174
178
|
*/
|
|
175
179
|
_SeedlessOnboardingController_isUnlocked.set(this, false);
|
|
176
180
|
/**
|
|
177
|
-
*
|
|
181
|
+
* Cached decrypted vault data.
|
|
182
|
+
*
|
|
183
|
+
* This is used to cache the decrypted vault data to avoid decrypting the vault data multiple times.
|
|
178
184
|
*/
|
|
179
|
-
|
|
185
|
+
_SeedlessOnboardingController_cachedDecryptedVaultData.set(this, void 0);
|
|
180
186
|
(0, assertions_1.assertIsPasswordOutdatedCacheValid)(passwordOutdatedCacheTTL);
|
|
181
187
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, passwordOutdatedCacheTTL, "f");
|
|
182
188
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_vaultEncryptor, encryptor, "f");
|
|
@@ -506,7 +512,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
506
512
|
*/
|
|
507
513
|
async submitPassword(password) {
|
|
508
514
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
509
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
|
|
515
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, { password });
|
|
510
516
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
511
517
|
});
|
|
512
518
|
}
|
|
@@ -522,6 +528,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
522
528
|
delete state.revokeToken;
|
|
523
529
|
delete state.accessToken;
|
|
524
530
|
});
|
|
531
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, undefined, "f");
|
|
525
532
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
526
533
|
}
|
|
527
534
|
/**
|
|
@@ -700,7 +707,10 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
700
707
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
701
708
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
702
709
|
const { vaultEncryptionKey } = this.state;
|
|
703
|
-
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
710
|
+
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, {
|
|
711
|
+
password,
|
|
712
|
+
encryptionKey: vaultEncryptionKey,
|
|
713
|
+
});
|
|
704
714
|
if (!revokeToken) {
|
|
705
715
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
|
|
706
716
|
}
|
|
@@ -778,7 +788,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
778
788
|
}
|
|
779
789
|
}
|
|
780
790
|
exports.SeedlessOnboardingController = SeedlessOnboardingController;
|
|
781
|
-
_SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardingController_controllerOperationMutex = new WeakMap(), _SeedlessOnboardingController_vaultOperationMutex = new WeakMap(), _SeedlessOnboardingController_refreshJWTToken = new WeakMap(), _SeedlessOnboardingController_revokeRefreshToken = new WeakMap(), _SeedlessOnboardingController_isUnlocked = new WeakMap(),
|
|
791
|
+
_SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardingController_controllerOperationMutex = new WeakMap(), _SeedlessOnboardingController_vaultOperationMutex = new WeakMap(), _SeedlessOnboardingController_refreshJWTToken = new WeakMap(), _SeedlessOnboardingController_revokeRefreshToken = new WeakMap(), _SeedlessOnboardingController_passwordOutdatedCacheTTL = new WeakMap(), _SeedlessOnboardingController_isUnlocked = new WeakMap(), _SeedlessOnboardingController_cachedDecryptedVaultData = new WeakMap(), _SeedlessOnboardingController_instances = new WeakSet(), _SeedlessOnboardingController_submitGlobalPassword =
|
|
782
792
|
/**
|
|
783
793
|
* @description Submit the global password to the controller, verify the
|
|
784
794
|
* password validity and unlock the controller.
|
|
@@ -804,7 +814,9 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
|
|
|
804
814
|
const { pwEncKey } = res;
|
|
805
815
|
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
806
816
|
// Unlock the controller
|
|
807
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
817
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, {
|
|
818
|
+
encryptionKey: vaultKey,
|
|
819
|
+
});
|
|
808
820
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
809
821
|
}
|
|
810
822
|
catch (error) {
|
|
@@ -836,8 +848,10 @@ async function _SeedlessOnboardingController_getAccessToken(password) {
|
|
|
836
848
|
if (!vault) {
|
|
837
849
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidAccessToken);
|
|
838
850
|
}
|
|
839
|
-
const {
|
|
840
|
-
|
|
851
|
+
const { vaultData } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, {
|
|
852
|
+
password,
|
|
853
|
+
});
|
|
854
|
+
return vaultData.accessToken;
|
|
841
855
|
}, _SeedlessOnboardingController_setUnlocked = function _SeedlessOnboardingController_setUnlocked() {
|
|
842
856
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, true, "f");
|
|
843
857
|
}, _SeedlessOnboardingController_persistOprfKey =
|
|
@@ -1002,7 +1016,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
1002
1016
|
toprfEncryptionKey: encKey,
|
|
1003
1017
|
toprfPwEncryptionKey: pwEncKey,
|
|
1004
1018
|
toprfAuthKeyPair: authKeyPair,
|
|
1005
|
-
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, oldPassword));
|
|
1019
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, { password: oldPassword }));
|
|
1006
1020
|
}
|
|
1007
1021
|
const result = await this.toprfClient.changeEncKey({
|
|
1008
1022
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
@@ -1071,8 +1085,9 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1071
1085
|
* Unlocks the encrypted vault using the provided password and returns the decrypted vault data.
|
|
1072
1086
|
* This method ensures thread-safety by using a mutex lock when accessing the vault.
|
|
1073
1087
|
*
|
|
1074
|
-
* @param
|
|
1075
|
-
* @param
|
|
1088
|
+
* @param params - The parameters for unlocking the vault.
|
|
1089
|
+
* @param params.password - The optional password to unlock the vault.
|
|
1090
|
+
* @param params.encryptionKey - The optional encryption key to unlock the vault.
|
|
1076
1091
|
* @returns A promise that resolves to an object containing:
|
|
1077
1092
|
* - toprfEncryptionKey: The decrypted TOPRF encryption key
|
|
1078
1093
|
* - toprfAuthKeyPair: The decrypted TOPRF authentication key pair
|
|
@@ -1084,54 +1099,43 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1084
1099
|
* - The password is incorrect (from encryptor.decrypt)
|
|
1085
1100
|
* - The decrypted vault data is malformed
|
|
1086
1101
|
*/
|
|
1087
|
-
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(
|
|
1102
|
+
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(params) {
|
|
1088
1103
|
return __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, async () => {
|
|
1089
|
-
|
|
1090
|
-
|
|
1104
|
+
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, "f")) {
|
|
1105
|
+
return __classPrivateFieldGet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, "f");
|
|
1106
|
+
}
|
|
1107
|
+
const { vaultData, vaultEncryptionKey, vaultEncryptionSalt } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, params);
|
|
1091
1108
|
this.update((state) => {
|
|
1092
1109
|
state.vaultEncryptionKey = vaultEncryptionKey;
|
|
1093
1110
|
state.vaultEncryptionSalt = vaultEncryptionSalt;
|
|
1094
|
-
state.revokeToken = revokeToken;
|
|
1095
|
-
state.accessToken = accessToken;
|
|
1111
|
+
state.revokeToken = vaultData.revokeToken;
|
|
1112
|
+
state.accessToken = vaultData.accessToken;
|
|
1096
1113
|
});
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
toprfAuthKeyPair,
|
|
1101
|
-
revokeToken,
|
|
1102
|
-
accessToken,
|
|
1103
|
-
};
|
|
1114
|
+
const deserializedVaultData = (0, utils_3.deserializeVaultData)(vaultData);
|
|
1115
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, deserializedVaultData, "f");
|
|
1116
|
+
return deserializedVaultData;
|
|
1104
1117
|
});
|
|
1105
1118
|
}, _SeedlessOnboardingController_decryptAndParseVaultData =
|
|
1106
1119
|
/**
|
|
1107
1120
|
* Decrypts the vault data and parses it into a usable format.
|
|
1108
1121
|
*
|
|
1109
|
-
* @param
|
|
1110
|
-
* @param
|
|
1122
|
+
* @param params - The parameters for decrypting the vault.
|
|
1123
|
+
* @param params.password - The optional password to decrypt the vault.
|
|
1124
|
+
* @param params.encryptionKey - The optional encryption key to decrypt the vault.
|
|
1111
1125
|
* @returns A promise that resolves to an object containing:
|
|
1112
1126
|
*/
|
|
1113
|
-
async function _SeedlessOnboardingController_decryptAndParseVaultData(
|
|
1127
|
+
async function _SeedlessOnboardingController_decryptAndParseVaultData(params) {
|
|
1114
1128
|
let { vaultEncryptionKey, vaultEncryptionSalt } = this.state;
|
|
1115
1129
|
const { vault: encryptedVault } = this.state;
|
|
1116
1130
|
if (!encryptedVault) {
|
|
1117
1131
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultError);
|
|
1118
1132
|
}
|
|
1119
|
-
if (encryptionKey) {
|
|
1120
|
-
vaultEncryptionKey = encryptionKey;
|
|
1133
|
+
if (params?.encryptionKey) {
|
|
1134
|
+
vaultEncryptionKey = params.encryptionKey;
|
|
1121
1135
|
}
|
|
1122
1136
|
let decryptedVaultData;
|
|
1123
|
-
if
|
|
1124
|
-
|
|
1125
|
-
// Note that vault decryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1126
|
-
// from the password using an intentionally slow key derivation function.
|
|
1127
|
-
// We should make sure that we only call it very intentionally.
|
|
1128
|
-
const result = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithDetail(password, encryptedVault);
|
|
1129
|
-
decryptedVaultData = result.vault;
|
|
1130
|
-
vaultEncryptionKey = result.exportedKeyString;
|
|
1131
|
-
vaultEncryptionSalt = result.salt;
|
|
1132
|
-
}
|
|
1133
|
-
else {
|
|
1134
|
-
assertIsVaultEncryptionKeyDefined(vaultEncryptionKey);
|
|
1137
|
+
// if the encryption key is available, we will use it to decrypt the vault
|
|
1138
|
+
if (vaultEncryptionKey) {
|
|
1135
1139
|
const parsedEncryptedVault = JSON.parse(encryptedVault);
|
|
1136
1140
|
if (vaultEncryptionSalt &&
|
|
1137
1141
|
vaultEncryptionSalt !== parsedEncryptedVault.salt) {
|
|
@@ -1140,9 +1144,20 @@ async function _SeedlessOnboardingController_decryptAndParseVaultData(password,
|
|
|
1140
1144
|
const key = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").importKey(vaultEncryptionKey);
|
|
1141
1145
|
decryptedVaultData = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithKey(key, parsedEncryptedVault);
|
|
1142
1146
|
}
|
|
1143
|
-
|
|
1147
|
+
else {
|
|
1148
|
+
// if the encryption key is not available, we will use the password to decrypt the vault
|
|
1149
|
+
assertIsValidPassword(params?.password);
|
|
1150
|
+
// Note that vault decryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1151
|
+
// from the password using an intentionally slow key derivation function.
|
|
1152
|
+
// We should make sure that we only call it very intentionally.
|
|
1153
|
+
const result = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithDetail(params.password, encryptedVault);
|
|
1154
|
+
decryptedVaultData = result.vault;
|
|
1155
|
+
vaultEncryptionKey = result.exportedKeyString;
|
|
1156
|
+
vaultEncryptionSalt = result.salt;
|
|
1157
|
+
}
|
|
1158
|
+
const vaultData = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_parseVaultData).call(this, decryptedVaultData);
|
|
1144
1159
|
return {
|
|
1145
|
-
|
|
1160
|
+
vaultData,
|
|
1146
1161
|
vaultEncryptionKey,
|
|
1147
1162
|
vaultEncryptionSalt,
|
|
1148
1163
|
};
|
|
@@ -1218,17 +1233,16 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
|
|
|
1218
1233
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
1219
1234
|
const { revokeToken } = this.state;
|
|
1220
1235
|
const accessToken = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_getAccessToken).call(this, password);
|
|
1221
|
-
const
|
|
1222
|
-
|
|
1223
|
-
toprfEncryptionKey,
|
|
1224
|
-
toprfPwEncryptionKey,
|
|
1225
|
-
toprfAuthKeyPair,
|
|
1236
|
+
const vaultData = {
|
|
1237
|
+
toprfAuthKeyPair: rawToprfAuthKeyPair,
|
|
1238
|
+
toprfEncryptionKey: rawToprfEncryptionKey,
|
|
1239
|
+
toprfPwEncryptionKey: rawToprfPwEncryptionKey,
|
|
1226
1240
|
revokeToken,
|
|
1227
1241
|
accessToken,
|
|
1228
|
-
}
|
|
1242
|
+
};
|
|
1229
1243
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
1230
1244
|
password,
|
|
1231
|
-
|
|
1245
|
+
vaultData,
|
|
1232
1246
|
pwEncKey: rawToprfPwEncryptionKey,
|
|
1233
1247
|
});
|
|
1234
1248
|
// update the authPubKey in the state
|
|
@@ -1242,13 +1256,16 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
|
|
|
1242
1256
|
*
|
|
1243
1257
|
* @param params - The parameters for updating the vault.
|
|
1244
1258
|
* @param params.password - The password to encrypt the vault.
|
|
1245
|
-
* @param params.
|
|
1259
|
+
* @param params.vaultData - The raw vault data to update the vault with.
|
|
1246
1260
|
* @param params.pwEncKey - The global password encryption key.
|
|
1247
1261
|
* @returns A promise that resolves to the updated vault.
|
|
1248
1262
|
*/
|
|
1249
|
-
async function _SeedlessOnboardingController_updateVault({ password,
|
|
1263
|
+
async function _SeedlessOnboardingController_updateVault({ password, vaultData, pwEncKey, }) {
|
|
1250
1264
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, async () => {
|
|
1251
1265
|
assertIsValidPassword(password);
|
|
1266
|
+
// cache the vault data to avoid decrypting the vault data multiple times
|
|
1267
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, vaultData, "f");
|
|
1268
|
+
const serializedVaultData = (0, utils_3.serializeVaultData)(vaultData);
|
|
1252
1269
|
// Note that vault encryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1253
1270
|
// from the password using an intentionally slow key derivation function.
|
|
1254
1271
|
// We should make sure that we only call it very intentionally.
|
|
@@ -1292,44 +1309,19 @@ async function _SeedlessOnboardingController_withControllerLock(callback) {
|
|
|
1292
1309
|
*/
|
|
1293
1310
|
async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
1294
1311
|
return await withLock(__classPrivateFieldGet(this, _SeedlessOnboardingController_vaultOperationMutex, "f"), callback);
|
|
1295
|
-
}, _SeedlessOnboardingController_serializeKeyData = function _SeedlessOnboardingController_serializeKeyData(encKey, pwEncKey, authKeyPair) {
|
|
1296
|
-
const b64EncodedEncKey = (0, utils_1.bytesToBase64)(encKey);
|
|
1297
|
-
const b64EncodedPwEncKey = (0, utils_1.bytesToBase64)(pwEncKey);
|
|
1298
|
-
const b64EncodedAuthKeyPair = JSON.stringify({
|
|
1299
|
-
sk: (0, utils_1.bigIntToHex)(authKeyPair.sk),
|
|
1300
|
-
pk: (0, utils_1.bytesToBase64)(authKeyPair.pk),
|
|
1301
|
-
});
|
|
1302
|
-
return {
|
|
1303
|
-
toprfEncryptionKey: b64EncodedEncKey,
|
|
1304
|
-
toprfPwEncryptionKey: b64EncodedPwEncKey,
|
|
1305
|
-
toprfAuthKeyPair: b64EncodedAuthKeyPair,
|
|
1306
|
-
};
|
|
1307
1312
|
}, _SeedlessOnboardingController_parseVaultData = function _SeedlessOnboardingController_parseVaultData(data) {
|
|
1308
1313
|
if (typeof data !== 'string') {
|
|
1309
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.
|
|
1314
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultDataError);
|
|
1310
1315
|
}
|
|
1311
1316
|
let parsedVaultData;
|
|
1312
1317
|
try {
|
|
1313
1318
|
parsedVaultData = JSON.parse(data);
|
|
1314
1319
|
}
|
|
1315
1320
|
catch {
|
|
1316
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.
|
|
1321
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultDataError);
|
|
1317
1322
|
}
|
|
1318
1323
|
(0, assertions_1.assertIsValidVaultData)(parsedVaultData);
|
|
1319
|
-
|
|
1320
|
-
const rawToprfPwEncryptionKey = (0, utils_1.base64ToBytes)(parsedVaultData.toprfPwEncryptionKey);
|
|
1321
|
-
const parsedToprfAuthKeyPair = JSON.parse(parsedVaultData.toprfAuthKeyPair);
|
|
1322
|
-
const rawToprfAuthKeyPair = {
|
|
1323
|
-
sk: BigInt(parsedToprfAuthKeyPair.sk),
|
|
1324
|
-
pk: (0, utils_1.base64ToBytes)(parsedToprfAuthKeyPair.pk),
|
|
1325
|
-
};
|
|
1326
|
-
return {
|
|
1327
|
-
toprfEncryptionKey: rawToprfEncryptionKey,
|
|
1328
|
-
toprfPwEncryptionKey: rawToprfPwEncryptionKey,
|
|
1329
|
-
toprfAuthKeyPair: rawToprfAuthKeyPair,
|
|
1330
|
-
revokeToken: parsedVaultData.revokeToken,
|
|
1331
|
-
accessToken: parsedVaultData.accessToken,
|
|
1332
|
-
};
|
|
1324
|
+
return parsedVaultData;
|
|
1333
1325
|
}, _SeedlessOnboardingController_assertIsUnlocked = function _SeedlessOnboardingController_assertIsUnlocked() {
|
|
1334
1326
|
if (!__classPrivateFieldGet(this, _SeedlessOnboardingController_isUnlocked, "f")) {
|
|
1335
1327
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.ControllerLocked);
|
|
@@ -1505,15 +1497,4 @@ function assertIsEncryptedSeedlessEncryptionKeySet(encryptedSeedlessEncryptionKe
|
|
|
1505
1497
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.EncryptedSeedlessEncryptionKeyNotSet);
|
|
1506
1498
|
}
|
|
1507
1499
|
}
|
|
1508
|
-
/**
|
|
1509
|
-
* Assert that the provided vault encryption key is a valid non-empty string.
|
|
1510
|
-
*
|
|
1511
|
-
* @param vaultEncryptionKey - The vault encryption key to check.
|
|
1512
|
-
* @throws If the vault encryption key is not a valid string.
|
|
1513
|
-
*/
|
|
1514
|
-
function assertIsVaultEncryptionKeyDefined(vaultEncryptionKey) {
|
|
1515
|
-
if (!vaultEncryptionKey) {
|
|
1516
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultEncryptionKeyUndefined);
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
1500
|
//# sourceMappingURL=SeedlessOnboardingController.cjs.map
|