@metamask-previews/seedless-onboarding-controller 6.0.0-preview-d0277a7f → 6.0.0-preview-fe9b7e4c

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
@@ -9,12 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
- - Revert `revokeToken` value as optional in `authenticate` method. ([#7012](https://github.com/MetaMask/core/pull/7012))
13
- - Renamed `checkIsSeedlessOnboardingUserAuthenticated` to `getIsUserAuthenticated`. ([#7012](https://github.com/MetaMask/core/pull/7012))
14
-
15
- ### Fixed
16
-
17
- - Fixed `InvalidRevokeToken` issue in `refreshAuthTokens` method. ([#7012](https://github.com/MetaMask/core/pull/7012))
12
+ - `SeedlessOnboardingController` now accepts an optional `SupportedKeyDerivationOptions` type parameter ([#5963](https://github.com/MetaMask/core/pull/5963))
13
+ - The type parameter can be used to specify which key derivation algorithms are supported by the controller instance.
18
14
 
19
15
  ## [6.0.0]
20
16
 
@@ -117,7 +113,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
117
113
  ### Added
118
114
 
119
115
  - Added an optional parameter, `passwordOutdatedCacheTTL` to the constructor params and exported `SecretMetadata` class from the controller.([#6169](https://github.com/MetaMask/core/pull/6169))
120
-
121
116
  - Added `revokeRefreshToken` function to revoke refresh token and update vault with the new revoke token.([#6187](https://github.com/MetaMask/core/pull/6187))
122
117
 
123
118
  ## [2.4.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_renewRefreshToken, _SeedlessOnboardingController_passwordOutdatedCacheTTL, _SeedlessOnboardingController_isUnlocked, _SeedlessOnboardingController_cachedDecryptedVaultData, _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_unlockVaultAndGetVaultData, _SeedlessOnboardingController_decryptAndParseVaultData, _SeedlessOnboardingController_withPersistedSecretMetadataBackupsState, _SeedlessOnboardingController_filterDupesAndUpdateSocialBackupsMetadata, _SeedlessOnboardingController_createNewVaultWithAuthData, _SeedlessOnboardingController_updateVault, _SeedlessOnboardingController_getAccessTokenAndRevokeToken, _SeedlessOnboardingController_withControllerLock, _SeedlessOnboardingController_withVaultLock, _SeedlessOnboardingController_parseVaultData, _SeedlessOnboardingController_assertIsUnlocked, _SeedlessOnboardingController_assertIsAuthenticatedUser, _SeedlessOnboardingController_assertPasswordInSync, _SeedlessOnboardingController_resetPasswordOutdatedCache, _SeedlessOnboardingController_addRefreshTokenToRevokeList, _SeedlessOnboardingController_isAuthTokenError, _SeedlessOnboardingController_isMaxKeyChainLengthError, _SeedlessOnboardingController_executeWithTokenRefresh;
13
+ var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_renewRefreshToken, _SeedlessOnboardingController_passwordOutdatedCacheTTL, _SeedlessOnboardingController_isUnlocked, _SeedlessOnboardingController_cachedDecryptedVaultData, _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_unlockVaultAndGetVaultData, _SeedlessOnboardingController_decryptAndParseVaultData, _SeedlessOnboardingController_withPersistedSecretMetadataBackupsState, _SeedlessOnboardingController_filterDupesAndUpdateSocialBackupsMetadata, _SeedlessOnboardingController_createNewVaultWithAuthData, _SeedlessOnboardingController_updateVault, _SeedlessOnboardingController_withControllerLock, _SeedlessOnboardingController_withVaultLock, _SeedlessOnboardingController_parseVaultData, _SeedlessOnboardingController_assertIsUnlocked, _SeedlessOnboardingController_assertIsAuthenticatedUser, _SeedlessOnboardingController_assertIsSRPBackedUpUser, _SeedlessOnboardingController_assertPasswordInSync, _SeedlessOnboardingController_resetPasswordOutdatedCache, _SeedlessOnboardingController_addRefreshTokenToRevokeList, _SeedlessOnboardingController_isAuthTokenError, _SeedlessOnboardingController_isMaxKeyChainLengthError, _SeedlessOnboardingController_executeWithTokenRefresh;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SeedlessOnboardingController = exports.getInitialSeedlessOnboardingControllerStateWithDefaults = void 0;
16
16
  const auth_network_utils_1 = require("@metamask/auth-network-utils");
@@ -298,10 +298,8 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
298
298
  state.socialLoginEmail = socialLoginEmail;
299
299
  state.metadataAccessToken = metadataAccessToken;
300
300
  state.refreshToken = refreshToken;
301
- if (revokeToken) {
302
- // Temporarily store revoke token & access token in state for later vault creation
303
- state.revokeToken = revokeToken;
304
- }
301
+ // Temporarily store revoke token & access token in state for later vault creation
302
+ state.revokeToken = revokeToken;
305
303
  state.accessToken = accessToken;
306
304
  // we will check if the controller state is properly set with the authenticated user info
307
305
  // before setting the isSeedlessOnboardingUserAuthenticated to true
@@ -643,7 +641,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
643
641
  return passwordOutdatedCache.isExpiredPwd;
644
642
  }
645
643
  }
646
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
644
+ (0, assertions_1.assertIsAuthUserInfoValid)(this.state);
647
645
  const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
648
646
  const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
649
647
  let globalAuthPubKey = options?.globalAuthPubKey;
@@ -676,22 +674,21 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
676
674
  /**
677
675
  * Check if the user is authenticated with the seedless onboarding flow by checking the token values in the state.
678
676
  *
679
- * This method will check the `accessToken` and `revokeToken` in the state, besides the social login authentication details.
680
- * If both are present, the user is authenticated.
681
- * If either is missing, the user is not authenticated.
682
- *
683
- * This method is useful when we want to check if the state has valid authenticated user details to perform vault creations.
684
- *
685
677
  * @returns True if the user is authenticated, false otherwise.
686
678
  */
687
- async getIsUserAuthenticated() {
679
+ async checkIsSeedlessOnboardingUserAuthenticated() {
680
+ let isAuthenticated = false;
688
681
  try {
689
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
690
- return Boolean(this.state.accessToken) && Boolean(this.state.revokeToken);
682
+ (0, assertions_1.assertIsSeedlessOnboardingUserAuthenticated)(this.state);
683
+ isAuthenticated = true;
691
684
  }
692
685
  catch {
693
- return false;
686
+ isAuthenticated = false;
694
687
  }
688
+ this.update((state) => {
689
+ state.isSeedlessOnboardingUserAuthenticated = isAuthenticated;
690
+ });
691
+ return isAuthenticated;
695
692
  }
696
693
  /**
697
694
  * Clears the current state of the SeedlessOnboardingController.
@@ -732,7 +729,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
732
729
  */
733
730
  async refreshAuthTokens() {
734
731
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
735
- const { refreshToken } = this.state;
732
+ const { refreshToken, revokeToken } = this.state;
736
733
  const res = await __classPrivateFieldGet(this, _SeedlessOnboardingController_refreshJWTToken, "f").call(this, {
737
734
  connection: this.state.authConnection,
738
735
  refreshToken,
@@ -743,7 +740,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
743
740
  try {
744
741
  const { idTokens, accessToken, metadataAccessToken } = res;
745
742
  // re-authenticate with the new id tokens to set new node auth tokens
746
- // NOTE: here we can't provide the `revokeToken` value to the `authenticate` method because `refreshAuthTokens` method can be called when the wallet (vault) is locked
747
743
  await this.authenticate({
748
744
  idTokens,
749
745
  accessToken,
@@ -753,6 +749,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
753
749
  groupedAuthConnectionId: this.state.groupedAuthConnectionId,
754
750
  userId: this.state.userId,
755
751
  refreshToken,
752
+ revokeToken,
756
753
  skipLock: true,
757
754
  });
758
755
  }
@@ -777,6 +774,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
777
774
  password,
778
775
  encryptionKey: vaultEncryptionKey,
779
776
  });
777
+ if (!revokeToken) {
778
+ throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
779
+ }
780
780
  const { newRevokeToken, newRefreshToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_renewRefreshToken, "f").call(this, {
781
781
  connection: this.state.authConnection,
782
782
  revokeToken,
@@ -887,9 +887,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
887
887
  try {
888
888
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
889
889
  const { accessToken } = this.state;
890
- if (!accessToken) {
891
- return true; // Consider missing token as expired
892
- }
893
890
  const decodedToken = (0, utils_3.decodeJWTToken)(accessToken);
894
891
  return decodedToken.exp < Math.floor(Date.now() / 1000);
895
892
  }
@@ -1015,10 +1012,8 @@ async function _SeedlessOnboardingController_loadSeedlessEncryptionKey(encKey) {
1015
1012
  const seedlessEncryptionKey = aes.decrypt(encryptedKeyBytes);
1016
1013
  return (0, utils_2.bytesToUtf8)(seedlessEncryptionKey);
1017
1014
  }, _SeedlessOnboardingController_recoverAuthPubKey = function _SeedlessOnboardingController_recoverAuthPubKey() {
1015
+ __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsSRPBackedUpUser).call(this, this.state);
1018
1016
  const { authPubKey } = this.state;
1019
- if (!authPubKey) {
1020
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.SRPNotBackedUpError);
1021
- }
1022
1017
  return (0, utils_1.base64ToBytes)(authPubKey);
1023
1018
  }, _SeedlessOnboardingController_recoverEncKey =
1024
1019
  /**
@@ -1029,7 +1024,7 @@ async function _SeedlessOnboardingController_loadSeedlessEncryptionKey(encKey) {
1029
1024
  * @throws RecoveryError - If failed to recover the encryption key.
1030
1025
  */
1031
1026
  async function _SeedlessOnboardingController_recoverEncKey(password) {
1032
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
1027
+ (0, assertions_1.assertIsAuthUserInfoValid)(this.state);
1033
1028
  const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
1034
1029
  try {
1035
1030
  const recoverEncKeyResult = await this.toprfClient.recoverEncKey({
@@ -1320,7 +1315,7 @@ async function _SeedlessOnboardingController_withPersistedSecretMetadataBackupsS
1320
1315
  */
1321
1316
  async function _SeedlessOnboardingController_createNewVaultWithAuthData({ password, rawToprfEncryptionKey, rawToprfPwEncryptionKey, rawToprfAuthKeyPair, }) {
1322
1317
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
1323
- const { accessToken, revokeToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_getAccessTokenAndRevokeToken).call(this, password);
1318
+ const { revokeToken, accessToken } = this.state;
1324
1319
  const vaultData = {
1325
1320
  toprfAuthKeyPair: rawToprfAuthKeyPair,
1326
1321
  toprfEncryptionKey: rawToprfEncryptionKey,
@@ -1368,36 +1363,6 @@ async function _SeedlessOnboardingController_updateVault({ password, vaultData,
1368
1363
  state.encryptedSeedlessEncryptionKey = (0, utils_1.bytesToBase64)(encryptedKey);
1369
1364
  });
1370
1365
  });
1371
- }, _SeedlessOnboardingController_getAccessTokenAndRevokeToken =
1372
- /**
1373
- * Get the access token and revoke token from the state or the vault.
1374
- *
1375
- * @param password - The password to decrypt the vault.
1376
- * @returns The access token and revoke token.
1377
- */
1378
- async function _SeedlessOnboardingController_getAccessTokenAndRevokeToken(password) {
1379
- let { accessToken, revokeToken } = this.state;
1380
- // `accessToken` and `revokeToken` are both available in the state, `ONLY` when the wallet (vault) is unlocked
1381
- // or during the period between the social authentication and the vault creation during the onboarding flow.
1382
- if (accessToken && revokeToken) {
1383
- return { accessToken, revokeToken };
1384
- }
1385
- // if `password` is provided to decrypt the vault, decrypt the vault and get the access token and revoke token from the vault
1386
- if (this.state.vault) {
1387
- // if the access token or revoke token is not available in the state, decrypt the vault and get the access token and revoke token from the vault
1388
- const { vaultData } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, { password });
1389
- accessToken = accessToken || vaultData.accessToken;
1390
- revokeToken = revokeToken || vaultData.revokeToken;
1391
- }
1392
- // we should always throw an error if the access token or revoke token is not available
1393
- // to prevent the caller from using the controller in an invalid state
1394
- if (!accessToken) {
1395
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidAccessToken);
1396
- }
1397
- if (!revokeToken) {
1398
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
1399
- }
1400
- return { accessToken, revokeToken };
1401
1366
  }, _SeedlessOnboardingController_withControllerLock =
1402
1367
  /**
1403
1368
  * Lock the controller mutex before executing the given function,
@@ -1454,6 +1419,10 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
1454
1419
  });
1455
1420
  throw error;
1456
1421
  }
1422
+ }, _SeedlessOnboardingController_assertIsSRPBackedUpUser = function _SeedlessOnboardingController_assertIsSRPBackedUpUser(value) {
1423
+ if (!this.state.authPubKey) {
1424
+ throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.SRPNotBackedUpError);
1425
+ }
1457
1426
  }, _SeedlessOnboardingController_assertPasswordInSync =
1458
1427
  /**
1459
1428
  * Assert that the password is in sync with the global password.