@metamask-previews/seedless-onboarding-controller 2.4.0-preview-fed19434 → 2.4.0-preview-9b5151c

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 CHANGED
@@ -11,15 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
 
12
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
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
-
23
14
  ## [2.4.0]
24
15
 
25
16
  ### 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, _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;
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_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");
@@ -495,26 +495,14 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
495
495
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
496
496
  const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
497
497
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
498
- await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
499
- password,
500
- rawToprfEncryptionKey: toprfEncryptionKey,
501
- rawToprfPwEncryptionKey: toprfPwEncryptionKey,
502
- rawToprfAuthKeyPair: toprfAuthKeyPair,
503
- });
504
498
  if (revokeToken) {
505
- // this call is not critical for unlocking, so we can do it in the background without await.
506
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken)
507
- .then(() => {
508
- // re-creating vault to persist the new revoke token
509
- return __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
510
- password,
511
- rawToprfEncryptionKey: toprfEncryptionKey,
512
- rawToprfPwEncryptionKey: toprfPwEncryptionKey,
513
- rawToprfAuthKeyPair: toprfAuthKeyPair,
514
- });
515
- })
516
- .catch((error) => {
517
- log('Error revoking refresh token', error);
499
+ await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken);
500
+ // re-creating vault to persist the new revoke token
501
+ await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
502
+ password,
503
+ rawToprfEncryptionKey: toprfEncryptionKey,
504
+ rawToprfPwEncryptionKey: toprfPwEncryptionKey,
505
+ rawToprfAuthKeyPair: toprfAuthKeyPair,
518
506
  });
519
507
  }
520
508
  });
@@ -533,6 +521,33 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
533
521
  });
534
522
  __classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
535
523
  }
524
+ /**
525
+ * Sync the latest global password to the controller.
526
+ * reset vault with latest globalPassword,
527
+ * persist the latest global password authPubKey
528
+ *
529
+ * @param params - The parameters for syncing the latest global password.
530
+ * @param params.globalPassword - The latest global password.
531
+ * @returns A promise that resolves to the success of the operation.
532
+ */
533
+ async syncLatestGlobalPassword({ globalPassword, }) {
534
+ return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
535
+ __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this);
536
+ const doSyncPassword = async () => {
537
+ // update vault with latest globalPassword
538
+ const { encKey, pwEncKey, authKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
539
+ // update and encrypt the vault with new password
540
+ await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
541
+ password: globalPassword,
542
+ rawToprfEncryptionKey: encKey,
543
+ rawToprfPwEncryptionKey: pwEncKey,
544
+ rawToprfAuthKeyPair: authKeyPair,
545
+ });
546
+ __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
547
+ };
548
+ return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, doSyncPassword, 'syncLatestGlobalPassword');
549
+ });
550
+ }
536
551
  /**
537
552
  * @description Unlock the controller with the latest global password.
538
553
  *
@@ -541,16 +556,16 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
541
556
  * @param params.globalPassword - The latest global password.
542
557
  * @returns A promise that resolves to the success of the operation.
543
558
  */
544
- async submitGlobalPasswordAndSync({ globalPassword, maxKeyChainLength = 5, }) {
559
+ async submitGlobalPassword({ globalPassword, maxKeyChainLength = 5, }) {
545
560
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
546
561
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, async () => {
547
562
  const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
548
- await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_submitGlobalPasswordAndSync).call(this, {
563
+ await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_submitGlobalPassword).call(this, {
549
564
  targetAuthPubKey: currentDeviceAuthPubKey,
550
565
  globalPassword,
551
566
  maxKeyChainLength,
552
567
  });
553
- }, 'submitGlobalPasswordAndSync');
568
+ }, 'submitGlobalPassword');
554
569
  });
555
570
  }
556
571
  /**
@@ -724,7 +739,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
724
739
  }
725
740
  }
726
741
  exports.SeedlessOnboardingController = SeedlessOnboardingController;
727
- _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 =
742
+ _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 =
728
743
  /**
729
744
  * @description Submit the global password to the controller, verify the
730
745
  * password validity and unlock the controller.
@@ -737,52 +752,32 @@ _SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardin
737
752
  * @returns A promise that resolves to the keyring encryption key
738
753
  * corresponding to the current authPubKey in state.
739
754
  */
740
- async function _SeedlessOnboardingController_submitGlobalPasswordAndSync({ targetAuthPubKey, globalPassword, maxKeyChainLength, }) {
741
- const { pwEncKey: latestPwEncKey, authKeyPair: latestAuthKeyPair, encKey: latestEncKey, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
755
+ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPubKey, globalPassword, maxKeyChainLength, }) {
756
+ const { pwEncKey: curPwEncKey, authKeyPair: curAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
742
757
  try {
743
- // Recover current device's vault encryption key with the latest global password
744
- const { pwEncKey: currentDevicePwEncKey } = await this.toprfClient.recoverPwEncKey({
758
+ // Recover vault encryption key.
759
+ const res = await this.toprfClient.recoverPwEncKey({
745
760
  targetAuthPubKey,
746
- curPwEncKey: latestPwEncKey,
747
- curAuthKeyPair: latestAuthKeyPair,
761
+ curPwEncKey,
762
+ curAuthKeyPair,
748
763
  maxPwChainLength: maxKeyChainLength,
749
764
  });
750
- // recover the vault encryption key and keyring encryption key with the current device's pwEncKey
751
- const [vaultKey, keyringEncryptionKey] = await Promise.all([
752
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, currentDevicePwEncKey),
753
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadKeyringEncryptionKey).call(this, currentDevicePwEncKey),
754
- ]);
755
- // Unlock the controller and vault
756
- const { revokeToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
765
+ const { pwEncKey } = res;
766
+ const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
767
+ // Unlock the controller
768
+ const { revokeToken, toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
757
769
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
758
- await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
759
- password: globalPassword,
760
- rawToprfEncryptionKey: latestEncKey,
761
- rawToprfPwEncryptionKey: latestPwEncKey,
762
- rawToprfAuthKeyPair: latestAuthKeyPair,
763
- });
764
770
  if (revokeToken) {
765
- // // revoke and recyle refresh token after unlock to keep refresh token fresh, avoid malicious use of leaked refresh token
766
- // // this call is not critical for unlocking, so we can do it in the background without await.
767
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken)
768
- .then(() => {
769
- // re-creating vault to persist the new revoke token.
770
- // TODO: Optimize this function such that updates to vault wont require re-creating the vault.
771
- return __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
772
- password: globalPassword,
773
- rawToprfEncryptionKey: latestEncKey,
774
- rawToprfPwEncryptionKey: latestPwEncKey,
775
- rawToprfAuthKeyPair: latestAuthKeyPair,
776
- });
777
- })
778
- .catch((error) => {
779
- log('Error revoking refresh token', error);
771
+ // revoke and recyle refresh token after unlock to keep refresh token fresh, avoid malicious use of leaked refresh token
772
+ await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken);
773
+ // re-creating vault to persist the new revoke token
774
+ await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
775
+ password: globalPassword,
776
+ rawToprfEncryptionKey: toprfEncryptionKey,
777
+ rawToprfPwEncryptionKey: toprfPwEncryptionKey,
778
+ rawToprfAuthKeyPair: toprfAuthKeyPair,
780
779
  });
781
780
  }
782
- // restore the current keyring encryption key with the new global password
783
- await this.storeKeyringEncryptionKey(keyringEncryptionKey);
784
- // reset the password outdated cache after successful global password submission and state sync
785
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
786
781
  }
787
782
  catch (error) {
788
783
  if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {