@metamask-previews/seedless-onboarding-controller 2.4.0-preview-4bc9f9d → 2.4.0-preview-a0e6b482
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 +13 -0
- package/dist/SeedlessOnboardingController.cjs +100 -62
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +7 -14
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +7 -14
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +101 -63
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/assertions.cjs +16 -1
- package/dist/assertions.cjs.map +1 -1
- package/dist/assertions.d.cts +7 -0
- package/dist/assertions.d.cts.map +1 -1
- package/dist/assertions.d.mts +7 -0
- package/dist/assertions.d.mts.map +1 -1
- package/dist/assertions.mjs +14 -0
- package/dist/assertions.mjs.map +1 -1
- package/dist/constants.cjs +3 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +4 -2
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +4 -2
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +3 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +6 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Added an optional parameter, `passwordOutdatedCacheTTL` to the constructor params and exported `SecretMetadata` class from the controller.([#6169](https://github.com/MetaMask/core/pull/6169))
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Renamed public method `submitGlobalPassword` to `submitGlobalPasswordAndSync`. ([#6180](https://github.com/MetaMask/core/pull/6180))
|
|
17
|
+
|
|
18
|
+
### Removed
|
|
19
|
+
|
|
20
|
+
- Removed `syncLatestGlobalPassword` from the Controller. ([#6180](https://github.com/MetaMask/core/pull/6180))
|
|
21
|
+
- Moved the vault syncing to the `submitGlobalPassword` method
|
|
22
|
+
|
|
10
23
|
## [2.4.0]
|
|
11
24
|
|
|
12
25
|
### Fixed
|
|
@@ -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_isUnlocked, _SeedlessOnboardingController_passwordOutdatedCacheTTL, _SeedlessOnboardingController_submitGlobalPasswordAndSync, _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_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_revokeRefreshTokenAndUpdateState, _SeedlessOnboardingController_isTokenExpiredError, _SeedlessOnboardingController_isMaxKeyChainLengthError, _SeedlessOnboardingController_executeWithTokenRefresh;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SeedlessOnboardingController = exports.getDefaultSeedlessOnboardingControllerState = void 0;
|
|
16
16
|
const auth_network_utils_1 = require("@metamask/auth-network-utils");
|
|
@@ -136,8 +136,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
136
136
|
* @param options.network - The network to be used for the Seedless Onboarding flow.
|
|
137
137
|
* @param options.refreshJWTToken - A function to get a new jwt token using refresh token.
|
|
138
138
|
* @param options.revokeRefreshToken - A function to revoke the refresh token.
|
|
139
|
+
* @param options.passwordOutdatedCacheTTL - The TTL of the password outdated cache in milliseconds.,
|
|
139
140
|
*/
|
|
140
|
-
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = constants_1.Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken, }) {
|
|
141
|
+
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = constants_1.Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken, passwordOutdatedCacheTTL = constants_1.PASSWORD_OUTDATED_CACHE_TTL_MS, }) {
|
|
141
142
|
super({
|
|
142
143
|
name: constants_1.controllerName,
|
|
143
144
|
metadata: seedlessOnboardingMetadata,
|
|
@@ -159,6 +160,12 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
159
160
|
* The controller lock is synchronized with the keyring lock.
|
|
160
161
|
*/
|
|
161
162
|
_SeedlessOnboardingController_isUnlocked.set(this, false);
|
|
163
|
+
/**
|
|
164
|
+
* The TTL of the password outdated cache in milliseconds.
|
|
165
|
+
*/
|
|
166
|
+
_SeedlessOnboardingController_passwordOutdatedCacheTTL.set(this, void 0);
|
|
167
|
+
(0, assertions_1.assertIsPasswordOutdatedCacheValid)(passwordOutdatedCacheTTL);
|
|
168
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, passwordOutdatedCacheTTL, "f");
|
|
162
169
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_vaultEncryptor, encryptor, "f");
|
|
163
170
|
this.toprfClient = new toprf_secure_backup_1.ToprfSecureBackup({
|
|
164
171
|
network,
|
|
@@ -391,7 +398,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
391
398
|
await this.verifyVaultPassword(oldPassword, {
|
|
392
399
|
skipLock: true, // skip lock since we already have the lock
|
|
393
400
|
});
|
|
394
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertPasswordInSync).call(this, {
|
|
401
|
+
const { latestKeyIndex } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertPasswordInSync).call(this, {
|
|
395
402
|
skipCache: true,
|
|
396
403
|
skipLock: true, // skip lock since we already have the lock
|
|
397
404
|
});
|
|
@@ -405,6 +412,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
405
412
|
const { encKey: newEncKey, pwEncKey: newPwEncKey, authKeyPair: newAuthKeyPair, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_changeEncryptionKey).call(this, {
|
|
406
413
|
oldPassword,
|
|
407
414
|
newPassword,
|
|
415
|
+
latestKeyIndex,
|
|
408
416
|
});
|
|
409
417
|
// update and encrypt the vault with new password
|
|
410
418
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
@@ -513,33 +521,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
513
521
|
});
|
|
514
522
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
515
523
|
}
|
|
516
|
-
/**
|
|
517
|
-
* Sync the latest global password to the controller.
|
|
518
|
-
* reset vault with latest globalPassword,
|
|
519
|
-
* persist the latest global password authPubKey
|
|
520
|
-
*
|
|
521
|
-
* @param params - The parameters for syncing the latest global password.
|
|
522
|
-
* @param params.globalPassword - The latest global password.
|
|
523
|
-
* @returns A promise that resolves to the success of the operation.
|
|
524
|
-
*/
|
|
525
|
-
async syncLatestGlobalPassword({ globalPassword, }) {
|
|
526
|
-
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
527
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this);
|
|
528
|
-
const doSyncPassword = async () => {
|
|
529
|
-
// update vault with latest globalPassword
|
|
530
|
-
const { encKey, pwEncKey, authKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
|
|
531
|
-
// update and encrypt the vault with new password
|
|
532
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
533
|
-
password: globalPassword,
|
|
534
|
-
rawToprfEncryptionKey: encKey,
|
|
535
|
-
rawToprfPwEncryptionKey: pwEncKey,
|
|
536
|
-
rawToprfAuthKeyPair: authKeyPair,
|
|
537
|
-
});
|
|
538
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
|
|
539
|
-
};
|
|
540
|
-
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, doSyncPassword, 'syncLatestGlobalPassword');
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
524
|
/**
|
|
544
525
|
* @description Unlock the controller with the latest global password.
|
|
545
526
|
*
|
|
@@ -548,22 +529,24 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
548
529
|
* @param params.globalPassword - The latest global password.
|
|
549
530
|
* @returns A promise that resolves to the success of the operation.
|
|
550
531
|
*/
|
|
551
|
-
async
|
|
532
|
+
async submitGlobalPasswordAndSync({ globalPassword, maxKeyChainLength = 5, }) {
|
|
552
533
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
553
534
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, async () => {
|
|
554
535
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
555
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m",
|
|
536
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_submitGlobalPasswordAndSync).call(this, {
|
|
556
537
|
targetAuthPubKey: currentDeviceAuthPubKey,
|
|
557
538
|
globalPassword,
|
|
558
539
|
maxKeyChainLength,
|
|
559
540
|
});
|
|
560
|
-
}, '
|
|
541
|
+
}, 'submitGlobalPasswordAndSync');
|
|
561
542
|
});
|
|
562
543
|
}
|
|
563
544
|
/**
|
|
564
545
|
* @description Check if the current password is outdated compare to the global password.
|
|
565
546
|
*
|
|
566
547
|
* @param options - Optional options object.
|
|
548
|
+
* @param options.globalAuthPubKey - The global auth public key to compare with the current auth public key.
|
|
549
|
+
* If not provided, the global auth public key will be fetched from the backend.
|
|
567
550
|
* @param options.skipCache - If true, bypass the cache and force a fresh check.
|
|
568
551
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
569
552
|
* @returns A promise that resolves to true if the password is outdated, false otherwise.
|
|
@@ -578,19 +561,28 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
578
561
|
const now = Date.now();
|
|
579
562
|
const isCacheValid = passwordOutdatedCache &&
|
|
580
563
|
now - passwordOutdatedCache.timestamp <
|
|
581
|
-
|
|
564
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, "f");
|
|
582
565
|
if (isCacheValid) {
|
|
583
566
|
return passwordOutdatedCache.isExpiredPwd;
|
|
584
567
|
}
|
|
585
568
|
}
|
|
586
569
|
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
587
570
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
571
|
+
let globalAuthPubKey = options?.globalAuthPubKey;
|
|
572
|
+
if (!globalAuthPubKey) {
|
|
573
|
+
const { authPubKey } = await this.toprfClient
|
|
574
|
+
.fetchAuthPubKey({
|
|
575
|
+
nodeAuthTokens,
|
|
576
|
+
authConnectionId,
|
|
577
|
+
groupedAuthConnectionId,
|
|
578
|
+
userId,
|
|
579
|
+
})
|
|
580
|
+
.catch((error) => {
|
|
581
|
+
log('Error fetching auth pub key', error);
|
|
582
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
583
|
+
});
|
|
584
|
+
globalAuthPubKey = authPubKey;
|
|
585
|
+
}
|
|
594
586
|
// use noble lib to deserialize and compare curve point
|
|
595
587
|
const isExpiredPwd = !secp256k1_1.secp256k1.ProjectivePoint.fromHex(currentDeviceAuthPubKey).equals(secp256k1_1.secp256k1.ProjectivePoint.fromHex(globalAuthPubKey));
|
|
596
588
|
// Cache the result in state
|
|
@@ -720,7 +712,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
720
712
|
}
|
|
721
713
|
}
|
|
722
714
|
exports.SeedlessOnboardingController = SeedlessOnboardingController;
|
|
723
|
-
_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_instances = new WeakSet(),
|
|
715
|
+
_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_submitGlobalPasswordAndSync =
|
|
724
716
|
/**
|
|
725
717
|
* @description Submit the global password to the controller, verify the
|
|
726
718
|
* password validity and unlock the controller.
|
|
@@ -733,32 +725,39 @@ _SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardin
|
|
|
733
725
|
* @returns A promise that resolves to the keyring encryption key
|
|
734
726
|
* corresponding to the current authPubKey in state.
|
|
735
727
|
*/
|
|
736
|
-
async function
|
|
737
|
-
const { pwEncKey:
|
|
728
|
+
async function _SeedlessOnboardingController_submitGlobalPasswordAndSync({ targetAuthPubKey, globalPassword, maxKeyChainLength, }) {
|
|
729
|
+
const { pwEncKey: latestPwEncKey, authKeyPair: latestAuthKeyPair, encKey: latestEncKey, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
|
|
738
730
|
try {
|
|
739
|
-
// Recover vault encryption key
|
|
740
|
-
const
|
|
731
|
+
// Recover current device's vault encryption key with the latest global password
|
|
732
|
+
const { pwEncKey: currentDevicePwEncKey } = await this.toprfClient.recoverPwEncKey({
|
|
741
733
|
targetAuthPubKey,
|
|
742
|
-
curPwEncKey,
|
|
743
|
-
curAuthKeyPair,
|
|
734
|
+
curPwEncKey: latestPwEncKey,
|
|
735
|
+
curAuthKeyPair: latestAuthKeyPair,
|
|
744
736
|
maxPwChainLength: maxKeyChainLength,
|
|
745
737
|
});
|
|
746
|
-
|
|
747
|
-
const vaultKey = await
|
|
748
|
-
|
|
749
|
-
|
|
738
|
+
// recover the vault encryption key and keyring encryption key with the current device's pwEncKey
|
|
739
|
+
const [vaultKey, keyringEncryptionKey] = await Promise.all([
|
|
740
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, currentDevicePwEncKey),
|
|
741
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadKeyringEncryptionKey).call(this, currentDevicePwEncKey),
|
|
742
|
+
]);
|
|
743
|
+
// Unlock the controller and vault
|
|
744
|
+
const { revokeToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
750
745
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
751
746
|
if (revokeToken) {
|
|
752
747
|
// revoke and recyle refresh token after unlock to keep refresh token fresh, avoid malicious use of leaked refresh token
|
|
753
748
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken);
|
|
754
|
-
// re-creating vault to persist the new revoke token
|
|
755
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
756
|
-
password: globalPassword,
|
|
757
|
-
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
758
|
-
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
759
|
-
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
760
|
-
});
|
|
761
749
|
}
|
|
750
|
+
// re-creating vault to persist the new revoke token
|
|
751
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
752
|
+
password: globalPassword,
|
|
753
|
+
rawToprfEncryptionKey: latestEncKey,
|
|
754
|
+
rawToprfPwEncryptionKey: latestPwEncKey,
|
|
755
|
+
rawToprfAuthKeyPair: latestAuthKeyPair,
|
|
756
|
+
});
|
|
757
|
+
// restore the current keyring encryption key with the new global password
|
|
758
|
+
await this.storeKeyringEncryptionKey(keyringEncryptionKey);
|
|
759
|
+
// reset the password outdated cache after successful global password submission and state sync
|
|
760
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
|
|
762
761
|
}
|
|
763
762
|
catch (error) {
|
|
764
763
|
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
|
|
@@ -932,12 +931,31 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
|
|
|
932
931
|
* @param params - The function parameters.
|
|
933
932
|
* @param params.oldPassword - The old password to verify.
|
|
934
933
|
* @param params.newPassword - The new password to update.
|
|
934
|
+
* @param params.latestKeyIndex - The key index of the latest key.
|
|
935
935
|
* @returns A promise that resolves to new encryption key and authentication key pair.
|
|
936
936
|
*/
|
|
937
|
-
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, }) {
|
|
937
|
+
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, latestKeyIndex, }) {
|
|
938
938
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
939
939
|
const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
|
|
940
|
-
|
|
940
|
+
let encKey;
|
|
941
|
+
let pwEncKey;
|
|
942
|
+
let authKeyPair;
|
|
943
|
+
let globalKeyIndex = latestKeyIndex;
|
|
944
|
+
if (!globalKeyIndex) {
|
|
945
|
+
({
|
|
946
|
+
encKey,
|
|
947
|
+
pwEncKey,
|
|
948
|
+
authKeyPair,
|
|
949
|
+
keyShareIndex: globalKeyIndex,
|
|
950
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword));
|
|
951
|
+
}
|
|
952
|
+
else {
|
|
953
|
+
({
|
|
954
|
+
toprfEncryptionKey: encKey,
|
|
955
|
+
toprfPwEncryptionKey: pwEncKey,
|
|
956
|
+
toprfAuthKeyPair: authKeyPair,
|
|
957
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, oldPassword));
|
|
958
|
+
}
|
|
941
959
|
const result = await this.toprfClient.changeEncKey({
|
|
942
960
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
943
961
|
authConnectionId,
|
|
@@ -946,7 +964,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
946
964
|
oldEncKey: encKey,
|
|
947
965
|
oldPwEncKey: pwEncKey,
|
|
948
966
|
oldAuthKeyPair: authKeyPair,
|
|
949
|
-
newKeyShareIndex,
|
|
967
|
+
newKeyShareIndex: globalKeyIndex,
|
|
950
968
|
newPassword,
|
|
951
969
|
});
|
|
952
970
|
return result;
|
|
@@ -1288,13 +1306,33 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1288
1306
|
* @param options - The options for asserting the password is in sync.
|
|
1289
1307
|
* @param options.skipCache - Whether to skip the cache check.
|
|
1290
1308
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
1309
|
+
* @returns The global auth public key and the latest key index.
|
|
1291
1310
|
* @throws If the password is outdated.
|
|
1292
1311
|
*/
|
|
1293
1312
|
async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
1294
|
-
const
|
|
1313
|
+
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
1314
|
+
if (!nodeAuthTokens || !authConnectionId || !userId) {
|
|
1315
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.MissingAuthUserInfo);
|
|
1316
|
+
}
|
|
1317
|
+
const { authPubKey, keyIndex: latestKeyIndex } = await this.toprfClient
|
|
1318
|
+
.fetchAuthPubKey({
|
|
1319
|
+
nodeAuthTokens,
|
|
1320
|
+
authConnectionId,
|
|
1321
|
+
groupedAuthConnectionId,
|
|
1322
|
+
userId,
|
|
1323
|
+
})
|
|
1324
|
+
.catch((error) => {
|
|
1325
|
+
log('Error fetching auth pub key', error);
|
|
1326
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
1327
|
+
});
|
|
1328
|
+
const isPasswordOutdated = await this.checkIsPasswordOutdated({
|
|
1329
|
+
...options,
|
|
1330
|
+
globalAuthPubKey: authPubKey,
|
|
1331
|
+
});
|
|
1295
1332
|
if (isPasswordOutdated) {
|
|
1296
1333
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.OutdatedPassword);
|
|
1297
1334
|
}
|
|
1335
|
+
return { authPubKey, latestKeyIndex };
|
|
1298
1336
|
}, _SeedlessOnboardingController_resetPasswordOutdatedCache = function _SeedlessOnboardingController_resetPasswordOutdatedCache() {
|
|
1299
1337
|
this.update((state) => {
|
|
1300
1338
|
delete state.passwordOutdatedCache;
|