@metamask-previews/seedless-onboarding-controller 5.0.0-preview-e98a6769 → 5.0.0-preview-7bc334fb

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.
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  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");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_renewRefreshToken, _SeedlessOnboardingController_passwordOutdatedCacheTTL, _SeedlessOnboardingController_isUnlocked, _SeedlessOnboardingController_cachedDecryptedVaultData, _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_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;
12
+ 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;
13
13
  import { keccak256AndHexify } from "@metamask/auth-network-utils";
14
14
  import { BaseController } from "@metamask/base-controller";
15
15
  import { ToprfSecureBackup, TOPRFErrorCode, TOPRFError } from "@metamask/toprf-secure-backup";
@@ -19,7 +19,7 @@ import { bytesToUtf8, utf8ToBytes } from "@noble/ciphers/utils";
19
19
  import { managedNonce } from "@noble/ciphers/webcrypto";
20
20
  import { secp256k1 } from "@noble/curves/secp256k1";
21
21
  import { Mutex } from "async-mutex";
22
- import { assertIsPasswordOutdatedCacheValid, assertIsSeedlessOnboardingUserAuthenticated, assertIsValidVaultData } from "./assertions.mjs";
22
+ import { assertIsAuthUserInfoValid, assertIsPasswordOutdatedCacheValid, assertIsSeedlessOnboardingUserAuthenticated, assertIsValidVaultData } from "./assertions.mjs";
23
23
  import { controllerName, PASSWORD_OUTDATED_CACHE_TTL_MS, SecretType, SeedlessOnboardingControllerErrorMessage, Web3AuthNetwork } from "./constants.mjs";
24
24
  import { PasswordSyncError, RecoveryError } from "./errors.mjs";
25
25
  import { projectLogger, createModuleLogger } from "./logger.mjs";
@@ -625,7 +625,6 @@ export class SeedlessOnboardingController extends BaseController {
625
625
  */
626
626
  async checkIsPasswordOutdated(options) {
627
627
  const doCheckIsPasswordExpired = async () => {
628
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
629
628
  // cache result to reduce load on infra
630
629
  // Check cache first unless skipCache is true
631
630
  if (!options?.skipCache) {
@@ -638,6 +637,7 @@ export class SeedlessOnboardingController extends BaseController {
638
637
  return passwordOutdatedCache.isExpiredPwd;
639
638
  }
640
639
  }
640
+ assertIsAuthUserInfoValid(this.state);
641
641
  const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
642
642
  const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
643
643
  let globalAuthPubKey = options?.globalAuthPubKey;
@@ -879,9 +879,6 @@ export class SeedlessOnboardingController extends BaseController {
879
879
  try {
880
880
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
881
881
  const { accessToken } = this.state;
882
- if (!accessToken) {
883
- return true; // Consider missing token as expired
884
- }
885
882
  const decodedToken = decodeJWTToken(accessToken);
886
883
  return decodedToken.exp < Math.floor(Date.now() / 1000);
887
884
  }
@@ -930,30 +927,6 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
930
927
  }
931
928
  throw PasswordSyncError.getInstance(error);
932
929
  }
933
- }, _SeedlessOnboardingController_getAccessToken =
934
- /**
935
- * Get the access token from the state or the vault.
936
- * If the access token is not in the state, it will be retrieved from the vault by decrypting it with the password.
937
- *
938
- * If both the access token and the vault are not available, an error will be thrown.
939
- *
940
- * @param password - The optional password to unlock the vault. If not provided, the access token will be retrieved from the vault.
941
- * @returns The access token.
942
- */
943
- async function _SeedlessOnboardingController_getAccessToken(password) {
944
- const { accessToken, vault } = this.state;
945
- if (accessToken) {
946
- // if the access token is in the state, return it
947
- return accessToken;
948
- }
949
- // otherwise, check the vault availability and decrypt the access token from the vault
950
- if (!vault) {
951
- throw new Error(SeedlessOnboardingControllerErrorMessage.InvalidAccessToken);
952
- }
953
- const { vaultData } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, {
954
- password,
955
- });
956
- return vaultData.accessToken;
957
930
  }, _SeedlessOnboardingController_setUnlocked = function _SeedlessOnboardingController_setUnlocked() {
958
931
  __classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, true, "f");
959
932
  }, _SeedlessOnboardingController_persistOprfKey =
@@ -1042,11 +1015,11 @@ async function _SeedlessOnboardingController_loadSeedlessEncryptionKey(encKey) {
1042
1015
  * @throws RecoveryError - If failed to recover the encryption key.
1043
1016
  */
1044
1017
  async function _SeedlessOnboardingController_recoverEncKey(password) {
1045
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
1046
- const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
1018
+ assertIsAuthUserInfoValid(this.state);
1019
+ const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
1047
1020
  try {
1048
1021
  const recoverEncKeyResult = await this.toprfClient.recoverEncKey({
1049
- nodeAuthTokens: this.state.nodeAuthTokens,
1022
+ nodeAuthTokens,
1050
1023
  password,
1051
1024
  authConnectionId,
1052
1025
  groupedAuthConnectionId,
@@ -1333,8 +1306,7 @@ async function _SeedlessOnboardingController_withPersistedSecretMetadataBackupsS
1333
1306
  */
1334
1307
  async function _SeedlessOnboardingController_createNewVaultWithAuthData({ password, rawToprfEncryptionKey, rawToprfPwEncryptionKey, rawToprfAuthKeyPair, }) {
1335
1308
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
1336
- const { revokeToken } = this.state;
1337
- const accessToken = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_getAccessToken).call(this, password);
1309
+ const { revokeToken, accessToken } = this.state;
1338
1310
  const vaultData = {
1339
1311
  toprfAuthKeyPair: rawToprfAuthKeyPair,
1340
1312
  toprfEncryptionKey: rawToprfEncryptionKey,