@metamask-previews/seedless-onboarding-controller 6.0.0-preview-950f30f7 → 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` and added an optional parameter to skip the vault creation check. ([#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,19 +674,13 @@ 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
- * @param skipVaultCreationCheck - An optional flag to skip the vault creation check.
680
- * If false, the method will check all the required state values which are necessary for vault creation.
681
- * If true, the method will only check the persisted authentication state values which are accessible regardless of the vault lock status.
682
677
  * @returns True if the user is authenticated, false otherwise.
683
678
  */
684
- async getIsUserAuthenticated(skipVaultCreationCheck = false) {
679
+ async checkIsSeedlessOnboardingUserAuthenticated() {
685
680
  let isAuthenticated = false;
686
681
  try {
687
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
688
- console.log('skipVaultCreationCheck', skipVaultCreationCheck);
689
- isAuthenticated =
690
- skipVaultCreationCheck || // if the `vaultCreationCheck` is skipped, we won't check the `accessToken` and `revokeToken`
691
- (Boolean(this.state.accessToken) && Boolean(this.state.revokeToken));
682
+ (0, assertions_1.assertIsSeedlessOnboardingUserAuthenticated)(this.state);
683
+ isAuthenticated = true;
692
684
  }
693
685
  catch {
694
686
  isAuthenticated = false;
@@ -737,7 +729,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
737
729
  */
738
730
  async refreshAuthTokens() {
739
731
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
740
- const { refreshToken } = this.state;
732
+ const { refreshToken, revokeToken } = this.state;
741
733
  const res = await __classPrivateFieldGet(this, _SeedlessOnboardingController_refreshJWTToken, "f").call(this, {
742
734
  connection: this.state.authConnection,
743
735
  refreshToken,
@@ -748,7 +740,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
748
740
  try {
749
741
  const { idTokens, accessToken, metadataAccessToken } = res;
750
742
  // re-authenticate with the new id tokens to set new node auth tokens
751
- // 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
752
743
  await this.authenticate({
753
744
  idTokens,
754
745
  accessToken,
@@ -758,6 +749,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
758
749
  groupedAuthConnectionId: this.state.groupedAuthConnectionId,
759
750
  userId: this.state.userId,
760
751
  refreshToken,
752
+ revokeToken,
761
753
  skipLock: true,
762
754
  });
763
755
  }
@@ -782,6 +774,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
782
774
  password,
783
775
  encryptionKey: vaultEncryptionKey,
784
776
  });
777
+ if (!revokeToken) {
778
+ throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
779
+ }
785
780
  const { newRevokeToken, newRefreshToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_renewRefreshToken, "f").call(this, {
786
781
  connection: this.state.authConnection,
787
782
  revokeToken,
@@ -892,9 +887,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
892
887
  try {
893
888
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
894
889
  const { accessToken } = this.state;
895
- if (!accessToken) {
896
- return true; // Consider missing token as expired
897
- }
898
890
  const decodedToken = (0, utils_3.decodeJWTToken)(accessToken);
899
891
  return decodedToken.exp < Math.floor(Date.now() / 1000);
900
892
  }
@@ -1020,10 +1012,8 @@ async function _SeedlessOnboardingController_loadSeedlessEncryptionKey(encKey) {
1020
1012
  const seedlessEncryptionKey = aes.decrypt(encryptedKeyBytes);
1021
1013
  return (0, utils_2.bytesToUtf8)(seedlessEncryptionKey);
1022
1014
  }, _SeedlessOnboardingController_recoverAuthPubKey = function _SeedlessOnboardingController_recoverAuthPubKey() {
1015
+ __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsSRPBackedUpUser).call(this, this.state);
1023
1016
  const { authPubKey } = this.state;
1024
- if (!authPubKey) {
1025
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.SRPNotBackedUpError);
1026
- }
1027
1017
  return (0, utils_1.base64ToBytes)(authPubKey);
1028
1018
  }, _SeedlessOnboardingController_recoverEncKey =
1029
1019
  /**
@@ -1034,7 +1024,7 @@ async function _SeedlessOnboardingController_loadSeedlessEncryptionKey(encKey) {
1034
1024
  * @throws RecoveryError - If failed to recover the encryption key.
1035
1025
  */
1036
1026
  async function _SeedlessOnboardingController_recoverEncKey(password) {
1037
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
1027
+ (0, assertions_1.assertIsAuthUserInfoValid)(this.state);
1038
1028
  const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
1039
1029
  try {
1040
1030
  const recoverEncKeyResult = await this.toprfClient.recoverEncKey({
@@ -1325,7 +1315,7 @@ async function _SeedlessOnboardingController_withPersistedSecretMetadataBackupsS
1325
1315
  */
1326
1316
  async function _SeedlessOnboardingController_createNewVaultWithAuthData({ password, rawToprfEncryptionKey, rawToprfPwEncryptionKey, rawToprfAuthKeyPair, }) {
1327
1317
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
1328
- const { accessToken, revokeToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_getAccessTokenAndRevokeToken).call(this, password);
1318
+ const { revokeToken, accessToken } = this.state;
1329
1319
  const vaultData = {
1330
1320
  toprfAuthKeyPair: rawToprfAuthKeyPair,
1331
1321
  toprfEncryptionKey: rawToprfEncryptionKey,
@@ -1373,36 +1363,6 @@ async function _SeedlessOnboardingController_updateVault({ password, vaultData,
1373
1363
  state.encryptedSeedlessEncryptionKey = (0, utils_1.bytesToBase64)(encryptedKey);
1374
1364
  });
1375
1365
  });
1376
- }, _SeedlessOnboardingController_getAccessTokenAndRevokeToken =
1377
- /**
1378
- * Get the access token and revoke token from the state or the vault.
1379
- *
1380
- * @param password - The password to decrypt the vault.
1381
- * @returns The access token and revoke token.
1382
- */
1383
- async function _SeedlessOnboardingController_getAccessTokenAndRevokeToken(password) {
1384
- let { accessToken, revokeToken } = this.state;
1385
- // `accessToken` and `revokeToken` are both available in the state, `ONLY` when the wallet (vault) is unlocked
1386
- // or during the period between the social authentication and the vault creation during the onboarding flow.
1387
- if (accessToken && revokeToken) {
1388
- return { accessToken, revokeToken };
1389
- }
1390
- // if `password` is provided to decrypt the vault, decrypt the vault and get the access token and revoke token from the vault
1391
- if (this.state.vault) {
1392
- // 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
1393
- const { vaultData } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, { password });
1394
- accessToken = accessToken || vaultData.accessToken;
1395
- revokeToken = revokeToken || vaultData.revokeToken;
1396
- }
1397
- // we should always throw an error if the access token or revoke token is not available
1398
- // to prevent the caller from using the controller in an invalid state
1399
- if (!accessToken) {
1400
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidAccessToken);
1401
- }
1402
- if (!revokeToken) {
1403
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
1404
- }
1405
- return { accessToken, revokeToken };
1406
1366
  }, _SeedlessOnboardingController_withControllerLock =
1407
1367
  /**
1408
1368
  * Lock the controller mutex before executing the given function,
@@ -1459,6 +1419,10 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
1459
1419
  });
1460
1420
  throw error;
1461
1421
  }
1422
+ }, _SeedlessOnboardingController_assertIsSRPBackedUpUser = function _SeedlessOnboardingController_assertIsSRPBackedUpUser(value) {
1423
+ if (!this.state.authPubKey) {
1424
+ throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.SRPNotBackedUpError);
1425
+ }
1462
1426
  }, _SeedlessOnboardingController_assertPasswordInSync =
1463
1427
  /**
1464
1428
  * Assert that the password is in sync with the global password.