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