@metamask-previews/seedless-onboarding-controller 2.1.0-preview-c2d112dc → 2.1.0-preview-95269c6d

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
@@ -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
+ ### Added
11
+
12
+ - Added a optional param `maxKeyChainLength` in `submitGlobalPassword` function.([#6134](https://github.com/MetaMask/core/pull/6134))
13
+
14
+ ### Fixed
15
+
16
+ - remove `access_token` validation when the wallet is locked. ([#6133](https://github.com/MetaMask/core/pull/6133))
17
+
10
18
  ## [2.1.0]
11
19
 
12
20
  ### Added
@@ -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_setUnlocked, _SeedlessOnboardingController_persistOprfKey, _SeedlessOnboardingController_persistAuthPubKey, _SeedlessOnboardingController_storeKeyringEncryptionKey, _SeedlessOnboardingController_loadKeyringEncryptionKey, _SeedlessOnboardingController_loadSeedlessEncryptionKey, _SeedlessOnboardingController_recoverAuthPubKey, _SeedlessOnboardingController_recoverEncKey, _SeedlessOnboardingController_fetchAllSecretDataFromMetadataStore, _SeedlessOnboardingController_changeEncryptionKey, _SeedlessOnboardingController_encryptAndStoreSecretData, _SeedlessOnboardingController_unlockVaultAndGetBackupEncKey, _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_assertIsValidVaultData, _SeedlessOnboardingController_isTokenExpiredError, _SeedlessOnboardingController_executeWithTokenRefresh;
13
+ var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_isUnlocked, _SeedlessOnboardingController_submitGlobalPassword, _SeedlessOnboardingController_setUnlocked, _SeedlessOnboardingController_persistOprfKey, _SeedlessOnboardingController_persistAuthPubKey, _SeedlessOnboardingController_storeKeyringEncryptionKey, _SeedlessOnboardingController_loadKeyringEncryptionKey, _SeedlessOnboardingController_loadSeedlessEncryptionKey, _SeedlessOnboardingController_recoverAuthPubKey, _SeedlessOnboardingController_recoverEncKey, _SeedlessOnboardingController_fetchAllSecretDataFromMetadataStore, _SeedlessOnboardingController_changeEncryptionKey, _SeedlessOnboardingController_encryptAndStoreSecretData, _SeedlessOnboardingController_unlockVaultAndGetBackupEncKey, _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_assertIsValidVaultData, _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");
@@ -535,16 +535,18 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
535
535
  * @description Unlock the controller with the latest global password.
536
536
  *
537
537
  * @param params - The parameters for unlocking the controller.
538
+ * @param params.maxKeyChainLength - The maximum chain length of the pwd encryption keys.
538
539
  * @param params.globalPassword - The latest global password.
539
540
  * @returns A promise that resolves to the success of the operation.
540
541
  */
541
- async submitGlobalPassword({ globalPassword, }) {
542
+ async submitGlobalPassword({ globalPassword, maxKeyChainLength = 5, }) {
542
543
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
543
544
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, async () => {
544
545
  const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
545
546
  await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_submitGlobalPassword).call(this, {
546
547
  targetAuthPubKey: currentDeviceAuthPubKey,
547
548
  globalPassword,
549
+ maxKeyChainLength,
548
550
  });
549
551
  }, 'submitGlobalPassword');
550
552
  });
@@ -698,6 +700,11 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
698
700
  // check if the token is expired
699
701
  return decodedToken.exp < Date.now() / 1000;
700
702
  }
703
+ /**
704
+ * Check if the current metadata access token is expired.
705
+ *
706
+ * @returns True if the metadata access token is expired, false otherwise.
707
+ */
701
708
  checkMetadataAccessTokenExpired() {
702
709
  try {
703
710
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
@@ -710,6 +717,12 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
710
717
  return true; // Consider unauthenticated user as having expired tokens
711
718
  }
712
719
  }
720
+ /**
721
+ * Check if the current access token is expired.
722
+ * When the vault is locked, the access token is not accessible, so we return false.
723
+ *
724
+ * @returns True if the access token is expired, false otherwise.
725
+ */
713
726
  checkAccessTokenExpired() {
714
727
  try {
715
728
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
@@ -732,13 +745,14 @@ _SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardin
732
745
  * password validity and unlock the controller.
733
746
  *
734
747
  * @param params - The parameters for submitting the global password.
748
+ * @param params.maxKeyChainLength - The maximum chain length of the pwd encryption keys.
735
749
  * @param params.targetAuthPubKey - The target public key of the keyring
736
750
  * encryption key to recover.
737
751
  * @param params.globalPassword - The latest global password.
738
752
  * @returns A promise that resolves to the keyring encryption key
739
753
  * corresponding to the current authPubKey in state.
740
754
  */
741
- async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPubKey, globalPassword, }) {
755
+ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPubKey, globalPassword, maxKeyChainLength = 5, }) {
742
756
  const { pwEncKey: curPwEncKey, authKeyPair: curAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
743
757
  try {
744
758
  // Recover vault encryption key.
@@ -746,6 +760,7 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
746
760
  targetAuthPubKey,
747
761
  curPwEncKey,
748
762
  curAuthKeyPair,
763
+ maxPwChainLength: maxKeyChainLength,
749
764
  });
750
765
  const { pwEncKey } = res;
751
766
  const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
@@ -759,6 +774,9 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
759
774
  if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
760
775
  throw error;
761
776
  }
777
+ if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isMaxKeyChainLengthError).call(this, error)) {
778
+ throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.MaxKeyChainLengthExceeded);
779
+ }
762
780
  throw errors_1.PasswordSyncError.getInstance(error);
763
781
  }
764
782
  }, _SeedlessOnboardingController_setUnlocked = function _SeedlessOnboardingController_setUnlocked() {
@@ -1295,6 +1313,13 @@ async function _SeedlessOnboardingController_assertPasswordInSync(options) {
1295
1313
  return error.code === toprf_secure_backup_1.TOPRFErrorCode.AuthTokenExpired;
1296
1314
  }
1297
1315
  return false;
1316
+ }, _SeedlessOnboardingController_isMaxKeyChainLengthError = function _SeedlessOnboardingController_isMaxKeyChainLengthError(error) {
1317
+ if (error instanceof toprf_secure_backup_1.TOPRFError) {
1318
+ // todo: update this when the error message to error code once toprf sdk is updated.
1319
+ return (error.message ===
1320
+ 'Could not fetch password. Exceeded maximum password chain length');
1321
+ }
1322
+ return false;
1298
1323
  }, _SeedlessOnboardingController_executeWithTokenRefresh =
1299
1324
  /**
1300
1325
  * Executes an operation with automatic token refresh on expiration.
@@ -1313,7 +1338,12 @@ async function _SeedlessOnboardingController_executeWithTokenRefresh(operation,
1313
1338
  // proactively check for expired tokens and refresh them if needed
1314
1339
  const isNodeAuthTokenExpired = this.checkNodeAuthTokenExpired();
1315
1340
  const isMetadataAccessTokenExpired = this.checkMetadataAccessTokenExpired();
1316
- const isAccessTokenExpired = this.checkAccessTokenExpired();
1341
+ // access token is only accessible when the vault is unlocked
1342
+ // so skip the check if the vault is locked
1343
+ let isAccessTokenExpired = false;
1344
+ if (__classPrivateFieldGet(this, _SeedlessOnboardingController_isUnlocked, "f")) {
1345
+ isAccessTokenExpired = this.checkAccessTokenExpired();
1346
+ }
1317
1347
  if (isNodeAuthTokenExpired ||
1318
1348
  isMetadataAccessTokenExpired ||
1319
1349
  isAccessTokenExpired) {