@metamask-previews/seedless-onboarding-controller 2.4.0-preview-bd86fa14 → 2.5.0-preview-3f5f144a
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 +14 -5
- package/dist/SeedlessOnboardingController.cjs +109 -57
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +15 -1
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +15 -1
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +110 -58
- 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,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.5.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Added an optional parameter, `passwordOutdatedCacheTTL` to the constructor params and exported `SecretMetadata` class from the controller.([#6169](https://github.com/MetaMask/core/pull/6169))
|
|
15
|
+
|
|
16
|
+
- Added `revokeRefreshToken` function to revoke refresh token and update vault with the new revoke token.([#6187](https://github.com/MetaMask/core/pull/6187))
|
|
17
|
+
|
|
10
18
|
## [2.4.0]
|
|
11
19
|
|
|
12
20
|
### Fixed
|
|
@@ -15,10 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
15
23
|
|
|
16
24
|
## [2.3.0]
|
|
17
25
|
|
|
18
|
-
### Uncategorized
|
|
19
|
-
|
|
20
|
-
- Seedless onboarding controller: Remove usage of `Buffer` ([#6140](https://github.com/MetaMask/core/pull/6140))
|
|
21
|
-
|
|
22
26
|
### Added
|
|
23
27
|
|
|
24
28
|
- Added a optional param `maxKeyChainLength` in `submitGlobalPassword` function.([#6134](https://github.com/MetaMask/core/pull/6134))
|
|
@@ -28,6 +32,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
28
32
|
|
|
29
33
|
- `revokeRefreshToken` is removed and a private function named `revokeRefreshTokenAndUpdateState` is added as a replacement.([#6136](https://github.com/MetaMask/core/pull/6136))
|
|
30
34
|
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- Seedless onboarding controller: Remove usage of `Buffer` ([#6140](https://github.com/MetaMask/core/pull/6140))
|
|
38
|
+
|
|
31
39
|
## [2.2.0]
|
|
32
40
|
|
|
33
41
|
### Fixed
|
|
@@ -114,7 +122,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
114
122
|
- `checkIsPasswordOutdated`: Check if the password is current device is outdated, i.e. user changed password in another device.
|
|
115
123
|
- `clearState`: Reset the state of the controller to the defaults.
|
|
116
124
|
|
|
117
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/seedless-onboarding-controller@2.
|
|
125
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/seedless-onboarding-controller@2.5.0...HEAD
|
|
126
|
+
[2.5.0]: https://github.com/MetaMask/core/compare/@metamask/seedless-onboarding-controller@2.4.0...@metamask/seedless-onboarding-controller@2.5.0
|
|
118
127
|
[2.4.0]: https://github.com/MetaMask/core/compare/@metamask/seedless-onboarding-controller@2.3.0...@metamask/seedless-onboarding-controller@2.4.0
|
|
119
128
|
[2.3.0]: https://github.com/MetaMask/core/compare/@metamask/seedless-onboarding-controller@2.2.0...@metamask/seedless-onboarding-controller@2.3.0
|
|
120
129
|
[2.2.0]: https://github.com/MetaMask/core/compare/@metamask/seedless-onboarding-controller@2.1.0...@metamask/seedless-onboarding-controller@2.2.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, _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,
|
|
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_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.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, {
|
|
@@ -485,18 +493,8 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
485
493
|
*/
|
|
486
494
|
async submitPassword(password) {
|
|
487
495
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
488
|
-
|
|
496
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
|
|
489
497
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
490
|
-
if (revokeToken) {
|
|
491
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken);
|
|
492
|
-
// re-creating vault to persist the new revoke token
|
|
493
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
494
|
-
password,
|
|
495
|
-
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
496
|
-
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
497
|
-
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
498
|
});
|
|
501
499
|
}
|
|
502
500
|
/**
|
|
@@ -564,6 +562,8 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
564
562
|
* @description Check if the current password is outdated compare to the global password.
|
|
565
563
|
*
|
|
566
564
|
* @param options - Optional options object.
|
|
565
|
+
* @param options.globalAuthPubKey - The global auth public key to compare with the current auth public key.
|
|
566
|
+
* If not provided, the global auth public key will be fetched from the backend.
|
|
567
567
|
* @param options.skipCache - If true, bypass the cache and force a fresh check.
|
|
568
568
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
569
569
|
* @returns A promise that resolves to true if the password is outdated, false otherwise.
|
|
@@ -578,19 +578,28 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
578
578
|
const now = Date.now();
|
|
579
579
|
const isCacheValid = passwordOutdatedCache &&
|
|
580
580
|
now - passwordOutdatedCache.timestamp <
|
|
581
|
-
|
|
581
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, "f");
|
|
582
582
|
if (isCacheValid) {
|
|
583
583
|
return passwordOutdatedCache.isExpiredPwd;
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
586
|
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
587
587
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
588
|
+
let globalAuthPubKey = options?.globalAuthPubKey;
|
|
589
|
+
if (!globalAuthPubKey) {
|
|
590
|
+
const { authPubKey } = await this.toprfClient
|
|
591
|
+
.fetchAuthPubKey({
|
|
592
|
+
nodeAuthTokens,
|
|
593
|
+
authConnectionId,
|
|
594
|
+
groupedAuthConnectionId,
|
|
595
|
+
userId,
|
|
596
|
+
})
|
|
597
|
+
.catch((error) => {
|
|
598
|
+
log('Error fetching auth pub key', error);
|
|
599
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
600
|
+
});
|
|
601
|
+
globalAuthPubKey = authPubKey;
|
|
602
|
+
}
|
|
594
603
|
// use noble lib to deserialize and compare curve point
|
|
595
604
|
const isExpiredPwd = !secp256k1_1.secp256k1.ProjectivePoint.fromHex(currentDeviceAuthPubKey).equals(secp256k1_1.secp256k1.ProjectivePoint.fromHex(globalAuthPubKey));
|
|
596
605
|
// Cache the result in state
|
|
@@ -666,6 +675,40 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
666
675
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.AuthenticationError);
|
|
667
676
|
}
|
|
668
677
|
}
|
|
678
|
+
/**
|
|
679
|
+
* Revoke the refresh token and get new refresh token and new revoke token
|
|
680
|
+
* and also updates the vault with the new revoke token.
|
|
681
|
+
* This method is to be called after user is authenticated.
|
|
682
|
+
*
|
|
683
|
+
* @param password - The password to encrypt the vault.
|
|
684
|
+
* @returns A Promise that resolves to void.
|
|
685
|
+
*/
|
|
686
|
+
async revokeRefreshToken(password) {
|
|
687
|
+
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
688
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
689
|
+
const { vaultEncryptionKey } = this.state;
|
|
690
|
+
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password, vaultEncryptionKey);
|
|
691
|
+
if (!revokeToken) {
|
|
692
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
|
|
693
|
+
}
|
|
694
|
+
const { newRevokeToken, newRefreshToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_revokeRefreshToken, "f").call(this, {
|
|
695
|
+
connection: this.state.authConnection,
|
|
696
|
+
revokeToken,
|
|
697
|
+
});
|
|
698
|
+
this.update((state) => {
|
|
699
|
+
// set new revoke token in state temporarily for persisting in vault
|
|
700
|
+
state.revokeToken = newRevokeToken;
|
|
701
|
+
// set new refresh token to persist in state
|
|
702
|
+
state.refreshToken = newRefreshToken;
|
|
703
|
+
});
|
|
704
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
705
|
+
password,
|
|
706
|
+
rawToprfEncryptionKey,
|
|
707
|
+
rawToprfPwEncryptionKey,
|
|
708
|
+
rawToprfAuthKeyPair,
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
}
|
|
669
712
|
/**
|
|
670
713
|
* Check if the current node auth token is expired.
|
|
671
714
|
*
|
|
@@ -720,7 +763,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
720
763
|
}
|
|
721
764
|
}
|
|
722
765
|
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(), _SeedlessOnboardingController_submitGlobalPassword =
|
|
766
|
+
_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 =
|
|
724
767
|
/**
|
|
725
768
|
* @description Submit the global password to the controller, verify the
|
|
726
769
|
* password validity and unlock the controller.
|
|
@@ -746,19 +789,8 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
|
|
|
746
789
|
const { pwEncKey } = res;
|
|
747
790
|
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
748
791
|
// Unlock the controller
|
|
749
|
-
|
|
792
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
750
793
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
751
|
-
if (revokeToken) {
|
|
752
|
-
// revoke and recyle refresh token after unlock to keep refresh token fresh, avoid malicious use of leaked refresh token
|
|
753
|
-
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
|
-
}
|
|
762
794
|
}
|
|
763
795
|
catch (error) {
|
|
764
796
|
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
|
|
@@ -932,12 +964,31 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
|
|
|
932
964
|
* @param params - The function parameters.
|
|
933
965
|
* @param params.oldPassword - The old password to verify.
|
|
934
966
|
* @param params.newPassword - The new password to update.
|
|
967
|
+
* @param params.latestKeyIndex - The key index of the latest key.
|
|
935
968
|
* @returns A promise that resolves to new encryption key and authentication key pair.
|
|
936
969
|
*/
|
|
937
|
-
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, }) {
|
|
970
|
+
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, latestKeyIndex, }) {
|
|
938
971
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
939
972
|
const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
|
|
940
|
-
|
|
973
|
+
let encKey;
|
|
974
|
+
let pwEncKey;
|
|
975
|
+
let authKeyPair;
|
|
976
|
+
let globalKeyIndex = latestKeyIndex;
|
|
977
|
+
if (!globalKeyIndex) {
|
|
978
|
+
({
|
|
979
|
+
encKey,
|
|
980
|
+
pwEncKey,
|
|
981
|
+
authKeyPair,
|
|
982
|
+
keyShareIndex: globalKeyIndex,
|
|
983
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword));
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
({
|
|
987
|
+
toprfEncryptionKey: encKey,
|
|
988
|
+
toprfPwEncryptionKey: pwEncKey,
|
|
989
|
+
toprfAuthKeyPair: authKeyPair,
|
|
990
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, oldPassword));
|
|
991
|
+
}
|
|
941
992
|
const result = await this.toprfClient.changeEncKey({
|
|
942
993
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
943
994
|
authConnectionId,
|
|
@@ -946,7 +997,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
946
997
|
oldEncKey: encKey,
|
|
947
998
|
oldPwEncKey: pwEncKey,
|
|
948
999
|
oldAuthKeyPair: authKeyPair,
|
|
949
|
-
newKeyShareIndex,
|
|
1000
|
+
newKeyShareIndex: globalKeyIndex,
|
|
950
1001
|
newPassword,
|
|
951
1002
|
});
|
|
952
1003
|
return result;
|
|
@@ -1288,36 +1339,37 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1288
1339
|
* @param options - The options for asserting the password is in sync.
|
|
1289
1340
|
* @param options.skipCache - Whether to skip the cache check.
|
|
1290
1341
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
1342
|
+
* @returns The global auth public key and the latest key index.
|
|
1291
1343
|
* @throws If the password is outdated.
|
|
1292
1344
|
*/
|
|
1293
1345
|
async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
1294
|
-
const
|
|
1346
|
+
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
1347
|
+
if (!nodeAuthTokens || !authConnectionId || !userId) {
|
|
1348
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.MissingAuthUserInfo);
|
|
1349
|
+
}
|
|
1350
|
+
const { authPubKey, keyIndex: latestKeyIndex } = await this.toprfClient
|
|
1351
|
+
.fetchAuthPubKey({
|
|
1352
|
+
nodeAuthTokens,
|
|
1353
|
+
authConnectionId,
|
|
1354
|
+
groupedAuthConnectionId,
|
|
1355
|
+
userId,
|
|
1356
|
+
})
|
|
1357
|
+
.catch((error) => {
|
|
1358
|
+
log('Error fetching auth pub key', error);
|
|
1359
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
1360
|
+
});
|
|
1361
|
+
const isPasswordOutdated = await this.checkIsPasswordOutdated({
|
|
1362
|
+
...options,
|
|
1363
|
+
globalAuthPubKey: authPubKey,
|
|
1364
|
+
});
|
|
1295
1365
|
if (isPasswordOutdated) {
|
|
1296
1366
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.OutdatedPassword);
|
|
1297
1367
|
}
|
|
1368
|
+
return { authPubKey, latestKeyIndex };
|
|
1298
1369
|
}, _SeedlessOnboardingController_resetPasswordOutdatedCache = function _SeedlessOnboardingController_resetPasswordOutdatedCache() {
|
|
1299
1370
|
this.update((state) => {
|
|
1300
1371
|
delete state.passwordOutdatedCache;
|
|
1301
1372
|
});
|
|
1302
|
-
}, _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState =
|
|
1303
|
-
/**
|
|
1304
|
-
* Revoke the refresh token and get new refresh token and new revoke token.
|
|
1305
|
-
* This method is to be called after user is authenticated.
|
|
1306
|
-
*
|
|
1307
|
-
* @param revokeToken - The revoke token to use for revoking the refresh token.
|
|
1308
|
-
*/
|
|
1309
|
-
async function _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState(revokeToken) {
|
|
1310
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
1311
|
-
const { newRevokeToken, newRefreshToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_revokeRefreshToken, "f").call(this, {
|
|
1312
|
-
connection: this.state.authConnection,
|
|
1313
|
-
revokeToken,
|
|
1314
|
-
});
|
|
1315
|
-
this.update((state) => {
|
|
1316
|
-
// set new revoke token in state temporarily for persisting in vault
|
|
1317
|
-
state.revokeToken = newRevokeToken;
|
|
1318
|
-
// set new refresh token to persist in state
|
|
1319
|
-
state.refreshToken = newRefreshToken;
|
|
1320
|
-
});
|
|
1321
1373
|
}, _SeedlessOnboardingController_isTokenExpiredError = function _SeedlessOnboardingController_isTokenExpiredError(error) {
|
|
1322
1374
|
if (error instanceof toprf_secure_backup_1.TOPRFError) {
|
|
1323
1375
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|