@metamask-previews/seedless-onboarding-controller 3.0.0-preview-e821953d → 3.0.0-preview-e43ca14
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/CHANGELOG.md +1 -0
- package/dist/SeedlessOnboardingController.cjs +84 -109
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +3 -1
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +3 -1
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +86 -111
- 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 +10 -8
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +10 -8
- 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
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- **BREAKING:** Removed `Keyring:lock` and `Keyring:unlock` events from the controller allowed events. ([#6295](https://github.com/MetaMask/core/pull/6292))
|
|
12
13
|
- Bump `@metamask/base-controller` from `^8.1.0` to `^8.2.0` ([#6355](https://github.com/MetaMask/core/pull/6355))
|
|
13
14
|
|
|
14
15
|
## [3.0.0]
|
|
@@ -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");
|
|
@@ -187,14 +193,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
187
193
|
});
|
|
188
194
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_refreshJWTToken, refreshJWTToken, "f");
|
|
189
195
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_revokeRefreshToken, revokeRefreshToken, "f");
|
|
190
|
-
// setup subscriptions to the keyring lock event
|
|
191
|
-
// when the keyring is locked (wallet is locked), the controller will be cleared of its credentials
|
|
192
|
-
this.messagingSystem.subscribe('KeyringController:lock', () => {
|
|
193
|
-
this.setLocked();
|
|
194
|
-
});
|
|
195
|
-
this.messagingSystem.subscribe('KeyringController:unlock', () => {
|
|
196
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
197
|
-
});
|
|
198
196
|
}
|
|
199
197
|
async fetchMetadataAccessCreds() {
|
|
200
198
|
const { metadataAccessToken } = this.state;
|
|
@@ -506,7 +504,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
506
504
|
*/
|
|
507
505
|
async submitPassword(password) {
|
|
508
506
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
509
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
|
|
507
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, { password });
|
|
510
508
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
511
509
|
});
|
|
512
510
|
}
|
|
@@ -514,15 +512,20 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
514
512
|
* Set the controller to locked state, and deallocate the secrets (vault encryption key and salt).
|
|
515
513
|
*
|
|
516
514
|
* When the controller is locked, the user will not be able to perform any operations on the controller/vault.
|
|
515
|
+
*
|
|
516
|
+
* @returns A promise that resolves to the success of the operation.
|
|
517
517
|
*/
|
|
518
|
-
setLocked() {
|
|
519
|
-
this.
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
518
|
+
async setLocked() {
|
|
519
|
+
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
520
|
+
this.update((state) => {
|
|
521
|
+
delete state.vaultEncryptionKey;
|
|
522
|
+
delete state.vaultEncryptionSalt;
|
|
523
|
+
delete state.revokeToken;
|
|
524
|
+
delete state.accessToken;
|
|
525
|
+
});
|
|
526
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, undefined, "f");
|
|
527
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
524
528
|
});
|
|
525
|
-
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
526
529
|
}
|
|
527
530
|
/**
|
|
528
531
|
* Sync the latest global password to the controller.
|
|
@@ -700,7 +703,10 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
700
703
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
701
704
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
702
705
|
const { vaultEncryptionKey } = this.state;
|
|
703
|
-
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
706
|
+
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, {
|
|
707
|
+
password,
|
|
708
|
+
encryptionKey: vaultEncryptionKey,
|
|
709
|
+
});
|
|
704
710
|
if (!revokeToken) {
|
|
705
711
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
|
|
706
712
|
}
|
|
@@ -778,7 +784,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
778
784
|
}
|
|
779
785
|
}
|
|
780
786
|
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(),
|
|
787
|
+
_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
788
|
/**
|
|
783
789
|
* @description Submit the global password to the controller, verify the
|
|
784
790
|
* password validity and unlock the controller.
|
|
@@ -804,7 +810,9 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
|
|
|
804
810
|
const { pwEncKey } = res;
|
|
805
811
|
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
806
812
|
// Unlock the controller
|
|
807
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
813
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, {
|
|
814
|
+
encryptionKey: vaultKey,
|
|
815
|
+
});
|
|
808
816
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
809
817
|
}
|
|
810
818
|
catch (error) {
|
|
@@ -836,8 +844,10 @@ async function _SeedlessOnboardingController_getAccessToken(password) {
|
|
|
836
844
|
if (!vault) {
|
|
837
845
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidAccessToken);
|
|
838
846
|
}
|
|
839
|
-
const {
|
|
840
|
-
|
|
847
|
+
const { vaultData } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, {
|
|
848
|
+
password,
|
|
849
|
+
});
|
|
850
|
+
return vaultData.accessToken;
|
|
841
851
|
}, _SeedlessOnboardingController_setUnlocked = function _SeedlessOnboardingController_setUnlocked() {
|
|
842
852
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, true, "f");
|
|
843
853
|
}, _SeedlessOnboardingController_persistOprfKey =
|
|
@@ -1002,7 +1012,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
1002
1012
|
toprfEncryptionKey: encKey,
|
|
1003
1013
|
toprfPwEncryptionKey: pwEncKey,
|
|
1004
1014
|
toprfAuthKeyPair: authKeyPair,
|
|
1005
|
-
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, oldPassword));
|
|
1015
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, { password: oldPassword }));
|
|
1006
1016
|
}
|
|
1007
1017
|
const result = await this.toprfClient.changeEncKey({
|
|
1008
1018
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
@@ -1071,8 +1081,9 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1071
1081
|
* Unlocks the encrypted vault using the provided password and returns the decrypted vault data.
|
|
1072
1082
|
* This method ensures thread-safety by using a mutex lock when accessing the vault.
|
|
1073
1083
|
*
|
|
1074
|
-
* @param
|
|
1075
|
-
* @param
|
|
1084
|
+
* @param params - The parameters for unlocking the vault.
|
|
1085
|
+
* @param params.password - The optional password to unlock the vault.
|
|
1086
|
+
* @param params.encryptionKey - The optional encryption key to unlock the vault.
|
|
1076
1087
|
* @returns A promise that resolves to an object containing:
|
|
1077
1088
|
* - toprfEncryptionKey: The decrypted TOPRF encryption key
|
|
1078
1089
|
* - toprfAuthKeyPair: The decrypted TOPRF authentication key pair
|
|
@@ -1084,54 +1095,43 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1084
1095
|
* - The password is incorrect (from encryptor.decrypt)
|
|
1085
1096
|
* - The decrypted vault data is malformed
|
|
1086
1097
|
*/
|
|
1087
|
-
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(
|
|
1098
|
+
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(params) {
|
|
1088
1099
|
return __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, async () => {
|
|
1089
|
-
|
|
1090
|
-
|
|
1100
|
+
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, "f")) {
|
|
1101
|
+
return __classPrivateFieldGet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, "f");
|
|
1102
|
+
}
|
|
1103
|
+
const { vaultData, vaultEncryptionKey, vaultEncryptionSalt } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, params);
|
|
1091
1104
|
this.update((state) => {
|
|
1092
1105
|
state.vaultEncryptionKey = vaultEncryptionKey;
|
|
1093
1106
|
state.vaultEncryptionSalt = vaultEncryptionSalt;
|
|
1094
|
-
state.revokeToken = revokeToken;
|
|
1095
|
-
state.accessToken = accessToken;
|
|
1107
|
+
state.revokeToken = vaultData.revokeToken;
|
|
1108
|
+
state.accessToken = vaultData.accessToken;
|
|
1096
1109
|
});
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
toprfAuthKeyPair,
|
|
1101
|
-
revokeToken,
|
|
1102
|
-
accessToken,
|
|
1103
|
-
};
|
|
1110
|
+
const deserializedVaultData = (0, utils_3.deserializeVaultData)(vaultData);
|
|
1111
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, deserializedVaultData, "f");
|
|
1112
|
+
return deserializedVaultData;
|
|
1104
1113
|
});
|
|
1105
1114
|
}, _SeedlessOnboardingController_decryptAndParseVaultData =
|
|
1106
1115
|
/**
|
|
1107
1116
|
* Decrypts the vault data and parses it into a usable format.
|
|
1108
1117
|
*
|
|
1109
|
-
* @param
|
|
1110
|
-
* @param
|
|
1118
|
+
* @param params - The parameters for decrypting the vault.
|
|
1119
|
+
* @param params.password - The optional password to decrypt the vault.
|
|
1120
|
+
* @param params.encryptionKey - The optional encryption key to decrypt the vault.
|
|
1111
1121
|
* @returns A promise that resolves to an object containing:
|
|
1112
1122
|
*/
|
|
1113
|
-
async function _SeedlessOnboardingController_decryptAndParseVaultData(
|
|
1123
|
+
async function _SeedlessOnboardingController_decryptAndParseVaultData(params) {
|
|
1114
1124
|
let { vaultEncryptionKey, vaultEncryptionSalt } = this.state;
|
|
1115
1125
|
const { vault: encryptedVault } = this.state;
|
|
1116
1126
|
if (!encryptedVault) {
|
|
1117
1127
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultError);
|
|
1118
1128
|
}
|
|
1119
|
-
if (encryptionKey) {
|
|
1120
|
-
vaultEncryptionKey = encryptionKey;
|
|
1129
|
+
if (params?.encryptionKey) {
|
|
1130
|
+
vaultEncryptionKey = params.encryptionKey;
|
|
1121
1131
|
}
|
|
1122
1132
|
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);
|
|
1133
|
+
// if the encryption key is available, we will use it to decrypt the vault
|
|
1134
|
+
if (vaultEncryptionKey) {
|
|
1135
1135
|
const parsedEncryptedVault = JSON.parse(encryptedVault);
|
|
1136
1136
|
if (vaultEncryptionSalt &&
|
|
1137
1137
|
vaultEncryptionSalt !== parsedEncryptedVault.salt) {
|
|
@@ -1140,9 +1140,20 @@ async function _SeedlessOnboardingController_decryptAndParseVaultData(password,
|
|
|
1140
1140
|
const key = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").importKey(vaultEncryptionKey);
|
|
1141
1141
|
decryptedVaultData = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithKey(key, parsedEncryptedVault);
|
|
1142
1142
|
}
|
|
1143
|
-
|
|
1143
|
+
else {
|
|
1144
|
+
// if the encryption key is not available, we will use the password to decrypt the vault
|
|
1145
|
+
assertIsValidPassword(params?.password);
|
|
1146
|
+
// Note that vault decryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1147
|
+
// from the password using an intentionally slow key derivation function.
|
|
1148
|
+
// We should make sure that we only call it very intentionally.
|
|
1149
|
+
const result = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithDetail(params.password, encryptedVault);
|
|
1150
|
+
decryptedVaultData = result.vault;
|
|
1151
|
+
vaultEncryptionKey = result.exportedKeyString;
|
|
1152
|
+
vaultEncryptionSalt = result.salt;
|
|
1153
|
+
}
|
|
1154
|
+
const vaultData = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_parseVaultData).call(this, decryptedVaultData);
|
|
1144
1155
|
return {
|
|
1145
|
-
|
|
1156
|
+
vaultData,
|
|
1146
1157
|
vaultEncryptionKey,
|
|
1147
1158
|
vaultEncryptionSalt,
|
|
1148
1159
|
};
|
|
@@ -1218,17 +1229,16 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
|
|
|
1218
1229
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
1219
1230
|
const { revokeToken } = this.state;
|
|
1220
1231
|
const accessToken = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_getAccessToken).call(this, password);
|
|
1221
|
-
const
|
|
1222
|
-
|
|
1223
|
-
toprfEncryptionKey,
|
|
1224
|
-
toprfPwEncryptionKey,
|
|
1225
|
-
toprfAuthKeyPair,
|
|
1232
|
+
const vaultData = {
|
|
1233
|
+
toprfAuthKeyPair: rawToprfAuthKeyPair,
|
|
1234
|
+
toprfEncryptionKey: rawToprfEncryptionKey,
|
|
1235
|
+
toprfPwEncryptionKey: rawToprfPwEncryptionKey,
|
|
1226
1236
|
revokeToken,
|
|
1227
1237
|
accessToken,
|
|
1228
|
-
}
|
|
1238
|
+
};
|
|
1229
1239
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
1230
1240
|
password,
|
|
1231
|
-
|
|
1241
|
+
vaultData,
|
|
1232
1242
|
pwEncKey: rawToprfPwEncryptionKey,
|
|
1233
1243
|
});
|
|
1234
1244
|
// update the authPubKey in the state
|
|
@@ -1242,13 +1252,16 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
|
|
|
1242
1252
|
*
|
|
1243
1253
|
* @param params - The parameters for updating the vault.
|
|
1244
1254
|
* @param params.password - The password to encrypt the vault.
|
|
1245
|
-
* @param params.
|
|
1255
|
+
* @param params.vaultData - The raw vault data to update the vault with.
|
|
1246
1256
|
* @param params.pwEncKey - The global password encryption key.
|
|
1247
1257
|
* @returns A promise that resolves to the updated vault.
|
|
1248
1258
|
*/
|
|
1249
|
-
async function _SeedlessOnboardingController_updateVault({ password,
|
|
1259
|
+
async function _SeedlessOnboardingController_updateVault({ password, vaultData, pwEncKey, }) {
|
|
1250
1260
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, async () => {
|
|
1251
1261
|
assertIsValidPassword(password);
|
|
1262
|
+
// cache the vault data to avoid decrypting the vault data multiple times
|
|
1263
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, vaultData, "f");
|
|
1264
|
+
const serializedVaultData = (0, utils_3.serializeVaultData)(vaultData);
|
|
1252
1265
|
// Note that vault encryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1253
1266
|
// from the password using an intentionally slow key derivation function.
|
|
1254
1267
|
// We should make sure that we only call it very intentionally.
|
|
@@ -1292,44 +1305,19 @@ async function _SeedlessOnboardingController_withControllerLock(callback) {
|
|
|
1292
1305
|
*/
|
|
1293
1306
|
async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
1294
1307
|
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
1308
|
}, _SeedlessOnboardingController_parseVaultData = function _SeedlessOnboardingController_parseVaultData(data) {
|
|
1308
1309
|
if (typeof data !== 'string') {
|
|
1309
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.
|
|
1310
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultDataError);
|
|
1310
1311
|
}
|
|
1311
1312
|
let parsedVaultData;
|
|
1312
1313
|
try {
|
|
1313
1314
|
parsedVaultData = JSON.parse(data);
|
|
1314
1315
|
}
|
|
1315
1316
|
catch {
|
|
1316
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.
|
|
1317
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultDataError);
|
|
1317
1318
|
}
|
|
1318
1319
|
(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
|
-
};
|
|
1320
|
+
return parsedVaultData;
|
|
1333
1321
|
}, _SeedlessOnboardingController_assertIsUnlocked = function _SeedlessOnboardingController_assertIsUnlocked() {
|
|
1334
1322
|
if (!__classPrivateFieldGet(this, _SeedlessOnboardingController_isUnlocked, "f")) {
|
|
1335
1323
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.ControllerLocked);
|
|
@@ -1359,10 +1347,8 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1359
1347
|
* @throws If the password is outdated.
|
|
1360
1348
|
*/
|
|
1361
1349
|
async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
1350
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
1362
1351
|
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
1363
|
-
if (!nodeAuthTokens || !authConnectionId || !userId) {
|
|
1364
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.MissingAuthUserInfo);
|
|
1365
|
-
}
|
|
1366
1352
|
const { authPubKey, keyIndex: latestKeyIndex } = await this.toprfClient
|
|
1367
1353
|
.fetchAuthPubKey({
|
|
1368
1354
|
nodeAuthTokens,
|
|
@@ -1505,15 +1491,4 @@ function assertIsEncryptedSeedlessEncryptionKeySet(encryptedSeedlessEncryptionKe
|
|
|
1505
1491
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.EncryptedSeedlessEncryptionKeyNotSet);
|
|
1506
1492
|
}
|
|
1507
1493
|
}
|
|
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
1494
|
//# sourceMappingURL=SeedlessOnboardingController.cjs.map
|