@metamask-previews/seedless-onboarding-controller 2.4.0-preview-e0bc4b4b → 2.4.0-preview-b8fffa99
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 +4 -0
- package/dist/SeedlessOnboardingController.cjs +114 -30
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +6 -1
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +6 -1
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +115 -31
- 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
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_isUnlocked, _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_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;
|
|
12
|
+
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_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;
|
|
13
13
|
import { keccak256AndHexify } from "@metamask/auth-network-utils";
|
|
14
14
|
import { BaseController } from "@metamask/base-controller";
|
|
15
15
|
import { ToprfSecureBackup, TOPRFErrorCode, TOPRFError } from "@metamask/toprf-secure-backup";
|
|
@@ -19,7 +19,7 @@ import { bytesToUtf8, utf8ToBytes } from "@noble/ciphers/utils";
|
|
|
19
19
|
import { managedNonce } from "@noble/ciphers/webcrypto";
|
|
20
20
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
21
21
|
import { Mutex } from "async-mutex";
|
|
22
|
-
import { assertIsValidVaultData } from "./assertions.mjs";
|
|
22
|
+
import { assertIsPasswordOutdatedCacheValid, assertIsValidVaultData } from "./assertions.mjs";
|
|
23
23
|
import { controllerName, PASSWORD_OUTDATED_CACHE_TTL_MS, SecretType, SeedlessOnboardingControllerErrorMessage, Web3AuthNetwork } from "./constants.mjs";
|
|
24
24
|
import { PasswordSyncError, RecoveryError } from "./errors.mjs";
|
|
25
25
|
import { projectLogger, createModuleLogger } from "./logger.mjs";
|
|
@@ -132,8 +132,9 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
132
132
|
* @param options.network - The network to be used for the Seedless Onboarding flow.
|
|
133
133
|
* @param options.refreshJWTToken - A function to get a new jwt token using refresh token.
|
|
134
134
|
* @param options.revokeRefreshToken - A function to revoke the refresh token.
|
|
135
|
+
* @param options.passwordOutdatedCacheTTL - The TTL of the password outdated cache in milliseconds.,
|
|
135
136
|
*/
|
|
136
|
-
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken, }) {
|
|
137
|
+
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken, passwordOutdatedCacheTTL = PASSWORD_OUTDATED_CACHE_TTL_MS, }) {
|
|
137
138
|
super({
|
|
138
139
|
name: controllerName,
|
|
139
140
|
metadata: seedlessOnboardingMetadata,
|
|
@@ -155,6 +156,12 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
155
156
|
* The controller lock is synchronized with the keyring lock.
|
|
156
157
|
*/
|
|
157
158
|
_SeedlessOnboardingController_isUnlocked.set(this, false);
|
|
159
|
+
/**
|
|
160
|
+
* The TTL of the password outdated cache in milliseconds.
|
|
161
|
+
*/
|
|
162
|
+
_SeedlessOnboardingController_passwordOutdatedCacheTTL.set(this, void 0);
|
|
163
|
+
assertIsPasswordOutdatedCacheValid(passwordOutdatedCacheTTL);
|
|
164
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, passwordOutdatedCacheTTL, "f");
|
|
158
165
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_vaultEncryptor, encryptor, "f");
|
|
159
166
|
this.toprfClient = new ToprfSecureBackup({
|
|
160
167
|
network,
|
|
@@ -387,7 +394,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
387
394
|
await this.verifyVaultPassword(oldPassword, {
|
|
388
395
|
skipLock: true, // skip lock since we already have the lock
|
|
389
396
|
});
|
|
390
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertPasswordInSync).call(this, {
|
|
397
|
+
const { latestKeyIndex } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertPasswordInSync).call(this, {
|
|
391
398
|
skipCache: true,
|
|
392
399
|
skipLock: true, // skip lock since we already have the lock
|
|
393
400
|
});
|
|
@@ -401,6 +408,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
401
408
|
const { encKey: newEncKey, pwEncKey: newPwEncKey, authKeyPair: newAuthKeyPair, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_changeEncryptionKey).call(this, {
|
|
402
409
|
oldPassword,
|
|
403
410
|
newPassword,
|
|
411
|
+
latestKeyIndex,
|
|
404
412
|
});
|
|
405
413
|
// update and encrypt the vault with new password
|
|
406
414
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
@@ -483,14 +491,27 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
483
491
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
484
492
|
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
|
|
485
493
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
494
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
495
|
+
password,
|
|
496
|
+
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
497
|
+
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
498
|
+
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
499
|
+
});
|
|
486
500
|
if (revokeToken) {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
501
|
+
// this call is not critical for unlocking, so we can do it in the background without await.
|
|
502
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken)
|
|
503
|
+
.then(() => {
|
|
504
|
+
// re-creating vault to persist the new revoke token
|
|
505
|
+
// TODO: Optimize this function such that updates to vault wont require re-creating the vault.
|
|
506
|
+
return __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
507
|
+
password,
|
|
508
|
+
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
509
|
+
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
510
|
+
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
511
|
+
});
|
|
512
|
+
})
|
|
513
|
+
.catch((error) => {
|
|
514
|
+
log('Error revoking refresh token', error);
|
|
494
515
|
});
|
|
495
516
|
}
|
|
496
517
|
});
|
|
@@ -560,6 +581,8 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
560
581
|
* @description Check if the current password is outdated compare to the global password.
|
|
561
582
|
*
|
|
562
583
|
* @param options - Optional options object.
|
|
584
|
+
* @param options.globalAuthPubKey - The global auth public key to compare with the current auth public key.
|
|
585
|
+
* If not provided, the global auth public key will be fetched from the backend.
|
|
563
586
|
* @param options.skipCache - If true, bypass the cache and force a fresh check.
|
|
564
587
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
565
588
|
* @returns A promise that resolves to true if the password is outdated, false otherwise.
|
|
@@ -574,19 +597,28 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
574
597
|
const now = Date.now();
|
|
575
598
|
const isCacheValid = passwordOutdatedCache &&
|
|
576
599
|
now - passwordOutdatedCache.timestamp <
|
|
577
|
-
|
|
600
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, "f");
|
|
578
601
|
if (isCacheValid) {
|
|
579
602
|
return passwordOutdatedCache.isExpiredPwd;
|
|
580
603
|
}
|
|
581
604
|
}
|
|
582
605
|
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
583
606
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
607
|
+
let globalAuthPubKey = options?.globalAuthPubKey;
|
|
608
|
+
if (!globalAuthPubKey) {
|
|
609
|
+
const { authPubKey } = await this.toprfClient
|
|
610
|
+
.fetchAuthPubKey({
|
|
611
|
+
nodeAuthTokens,
|
|
612
|
+
authConnectionId,
|
|
613
|
+
groupedAuthConnectionId,
|
|
614
|
+
userId,
|
|
615
|
+
})
|
|
616
|
+
.catch((error) => {
|
|
617
|
+
log('Error fetching auth pub key', error);
|
|
618
|
+
throw new Error(SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
619
|
+
});
|
|
620
|
+
globalAuthPubKey = authPubKey;
|
|
621
|
+
}
|
|
590
622
|
// use noble lib to deserialize and compare curve point
|
|
591
623
|
const isExpiredPwd = !secp256k1.ProjectivePoint.fromHex(currentDeviceAuthPubKey).equals(secp256k1.ProjectivePoint.fromHex(globalAuthPubKey));
|
|
592
624
|
// Cache the result in state
|
|
@@ -715,7 +747,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
715
747
|
}
|
|
716
748
|
}
|
|
717
749
|
}
|
|
718
|
-
_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(), _SeedlessOnboardingController_submitGlobalPassword =
|
|
750
|
+
_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 =
|
|
719
751
|
/**
|
|
720
752
|
* @description Submit the global password to the controller, verify the
|
|
721
753
|
* password validity and unlock the controller.
|
|
@@ -741,17 +773,30 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
|
|
|
741
773
|
const { pwEncKey } = res;
|
|
742
774
|
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
743
775
|
// Unlock the controller
|
|
744
|
-
const { revokeToken, toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
776
|
+
const { revokeToken, toprfEncryptionKey: latestEncKey, toprfPwEncryptionKey: latestPwEncKey, toprfAuthKeyPair: latestAuthKeyPair, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
745
777
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
778
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
779
|
+
password: globalPassword,
|
|
780
|
+
rawToprfEncryptionKey: latestEncKey,
|
|
781
|
+
rawToprfPwEncryptionKey: latestPwEncKey,
|
|
782
|
+
rawToprfAuthKeyPair: latestAuthKeyPair,
|
|
783
|
+
});
|
|
746
784
|
if (revokeToken) {
|
|
747
785
|
// revoke and recyle refresh token after unlock to keep refresh token fresh, avoid malicious use of leaked refresh token
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
786
|
+
// this call is not critical for unlocking, so we can do it in the background without await.
|
|
787
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken)
|
|
788
|
+
.then(() => {
|
|
789
|
+
// re-creating vault to persist the new revoke token.
|
|
790
|
+
// TODO: Optimize this function such that updates to vault wont require re-creating the vault.
|
|
791
|
+
return __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
792
|
+
password: globalPassword,
|
|
793
|
+
rawToprfEncryptionKey: latestEncKey,
|
|
794
|
+
rawToprfPwEncryptionKey: latestPwEncKey,
|
|
795
|
+
rawToprfAuthKeyPair: latestAuthKeyPair,
|
|
796
|
+
});
|
|
797
|
+
})
|
|
798
|
+
.catch((error) => {
|
|
799
|
+
log('Error revoking refresh token', error);
|
|
755
800
|
});
|
|
756
801
|
}
|
|
757
802
|
}
|
|
@@ -927,12 +972,31 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
|
|
|
927
972
|
* @param params - The function parameters.
|
|
928
973
|
* @param params.oldPassword - The old password to verify.
|
|
929
974
|
* @param params.newPassword - The new password to update.
|
|
975
|
+
* @param params.latestKeyIndex - The key index of the latest key.
|
|
930
976
|
* @returns A promise that resolves to new encryption key and authentication key pair.
|
|
931
977
|
*/
|
|
932
|
-
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, }) {
|
|
978
|
+
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, latestKeyIndex, }) {
|
|
933
979
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
934
980
|
const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
|
|
935
|
-
|
|
981
|
+
let encKey;
|
|
982
|
+
let pwEncKey;
|
|
983
|
+
let authKeyPair;
|
|
984
|
+
let globalKeyIndex = latestKeyIndex;
|
|
985
|
+
if (!globalKeyIndex) {
|
|
986
|
+
({
|
|
987
|
+
encKey,
|
|
988
|
+
pwEncKey,
|
|
989
|
+
authKeyPair,
|
|
990
|
+
keyShareIndex: globalKeyIndex,
|
|
991
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword));
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
({
|
|
995
|
+
toprfEncryptionKey: encKey,
|
|
996
|
+
toprfPwEncryptionKey: pwEncKey,
|
|
997
|
+
toprfAuthKeyPair: authKeyPair,
|
|
998
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, oldPassword));
|
|
999
|
+
}
|
|
936
1000
|
const result = await this.toprfClient.changeEncKey({
|
|
937
1001
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
938
1002
|
authConnectionId,
|
|
@@ -941,7 +1005,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
941
1005
|
oldEncKey: encKey,
|
|
942
1006
|
oldPwEncKey: pwEncKey,
|
|
943
1007
|
oldAuthKeyPair: authKeyPair,
|
|
944
|
-
newKeyShareIndex,
|
|
1008
|
+
newKeyShareIndex: globalKeyIndex,
|
|
945
1009
|
newPassword,
|
|
946
1010
|
});
|
|
947
1011
|
return result;
|
|
@@ -1283,13 +1347,33 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1283
1347
|
* @param options - The options for asserting the password is in sync.
|
|
1284
1348
|
* @param options.skipCache - Whether to skip the cache check.
|
|
1285
1349
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
1350
|
+
* @returns The global auth public key and the latest key index.
|
|
1286
1351
|
* @throws If the password is outdated.
|
|
1287
1352
|
*/
|
|
1288
1353
|
async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
1289
|
-
const
|
|
1354
|
+
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
1355
|
+
if (!nodeAuthTokens || !authConnectionId || !userId) {
|
|
1356
|
+
throw new Error(SeedlessOnboardingControllerErrorMessage.MissingAuthUserInfo);
|
|
1357
|
+
}
|
|
1358
|
+
const { authPubKey, keyIndex: latestKeyIndex } = await this.toprfClient
|
|
1359
|
+
.fetchAuthPubKey({
|
|
1360
|
+
nodeAuthTokens,
|
|
1361
|
+
authConnectionId,
|
|
1362
|
+
groupedAuthConnectionId,
|
|
1363
|
+
userId,
|
|
1364
|
+
})
|
|
1365
|
+
.catch((error) => {
|
|
1366
|
+
log('Error fetching auth pub key', error);
|
|
1367
|
+
throw new Error(SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
1368
|
+
});
|
|
1369
|
+
const isPasswordOutdated = await this.checkIsPasswordOutdated({
|
|
1370
|
+
...options,
|
|
1371
|
+
globalAuthPubKey: authPubKey,
|
|
1372
|
+
});
|
|
1290
1373
|
if (isPasswordOutdated) {
|
|
1291
1374
|
throw new Error(SeedlessOnboardingControllerErrorMessage.OutdatedPassword);
|
|
1292
1375
|
}
|
|
1376
|
+
return { authPubKey, latestKeyIndex };
|
|
1293
1377
|
}, _SeedlessOnboardingController_resetPasswordOutdatedCache = function _SeedlessOnboardingController_resetPasswordOutdatedCache() {
|
|
1294
1378
|
this.update((state) => {
|
|
1295
1379
|
delete state.passwordOutdatedCache;
|