@metamask-previews/seedless-onboarding-controller 1.0.0-preview-52f43d2 → 1.0.0-preview-7b670bb5

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
@@ -20,10 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20
20
  - updated `updateBackupMetadataState` method param with `{ keyringId?: string; data: Uint8Array; type: SecretType }`. Previously , `{ keyringId: string; seedPhrase: Uint8Array }`.
21
21
  - Added `submitGlobalPassword`. ([#5995](https://github.com/MetaMask/core/pull/5995))
22
22
  - Added `storeKeyringEncryptionKey` and `loadKeyringEncryptionKey`. ([#5995](https://github.com/MetaMask/core/pull/5995))
23
- - Added validations in `fetchAllSecretData`. ([#6047](https://github.com/MetaMask/core/pull/6047))
24
- - Throwing `NoSecretDataFound` error when the client receives the empty secret data from the metadata store.
25
- - Throwing `InvalidPrimarySecretDataType` error when the first secret data backup is not a `Mnemonic`. First backup must always be a `Mnemonic`
26
- since generating a new mnemonic (SRP) is the only way to create a new wallet for a Social Login user.
27
23
 
28
24
  ### Changed
29
25
 
@@ -37,8 +33,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
37
33
  - removed parameter `oldPassword`
38
34
  - no longer verifying old password
39
35
  - explicitly requring unlocked controller
40
- - **BREAKING** Changed data structure of return values from `fetchAllSecretData`. ([#6047](https://github.com/MetaMask/core/pull/6047))
41
- - Now returns `SecretMetadata[]` object instead of `Record<SecretType, Uint8Array[]>`
42
36
 
43
37
  ### Removed
44
38
 
@@ -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_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;
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");
@@ -255,6 +255,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
255
255
  rawToprfPwEncryptionKey: pwEncKey,
256
256
  rawToprfAuthKeyPair: authKeyPair,
257
257
  });
258
+ __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
259
+ authPubKey: authKeyPair.pk,
260
+ });
258
261
  };
259
262
  await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, performKeyCreationAndBackup, 'createToprfKeyAndBackupSeedPhrase');
260
263
  });
@@ -319,20 +322,40 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
319
322
  pwEncKey = keysFromVault.toprfPwEncryptionKey;
320
323
  authKeyPair = keysFromVault.toprfAuthKeyPair;
321
324
  }
322
- const performFetch = async () => {
323
- const secrets = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_fetchAllSecretDataFromMetadataStore).call(this, encKey, authKeyPair);
324
- if (password) {
325
- // if password is provided, we need to create a new vault with the auth data. (supposedly the user is trying to rehydrate the wallet)
326
- await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
327
- password,
328
- rawToprfEncryptionKey: encKey,
329
- rawToprfPwEncryptionKey: pwEncKey,
330
- rawToprfAuthKeyPair: authKeyPair,
325
+ try {
326
+ const performFetch = async () => {
327
+ const secretData = await this.toprfClient.fetchAllSecretDataItems({
328
+ decKey: encKey,
329
+ authKeyPair,
331
330
  });
332
- }
333
- return secrets;
334
- };
335
- return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, performFetch, 'fetchAllSecretData');
331
+ if (secretData?.length > 0 && password) {
332
+ // if password is provided, we need to create a new vault with the auth data. (supposedly the user is trying to rehydrate the wallet)
333
+ await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
334
+ password,
335
+ rawToprfEncryptionKey: encKey,
336
+ rawToprfPwEncryptionKey: pwEncKey,
337
+ rawToprfAuthKeyPair: authKeyPair,
338
+ });
339
+ __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
340
+ authPubKey: authKeyPair.pk,
341
+ });
342
+ }
343
+ const result = {
344
+ mnemonic: [],
345
+ privateKey: [],
346
+ };
347
+ const secrets = SecretMetadata_1.SecretMetadata.parseSecretsFromMetadataStore(secretData);
348
+ secrets.forEach((secret) => {
349
+ result[secret.type].push(secret.data);
350
+ });
351
+ return result;
352
+ };
353
+ return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, performFetch, 'fetchAllSecretData');
354
+ }
355
+ catch (error) {
356
+ log('Error fetching secret data', error);
357
+ throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.FailedToFetchSecretMetadata);
358
+ }
336
359
  });
337
360
  }
338
361
  /**
@@ -373,6 +396,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
373
396
  rawToprfPwEncryptionKey: newPwEncKey,
374
397
  rawToprfAuthKeyPair: newAuthKeyPair,
375
398
  });
399
+ __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
400
+ authPubKey: newAuthKeyPair.pk,
401
+ });
376
402
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
377
403
  // store the keyring encryption key if it exists
378
404
  if (keyringEncryptionKey) {
@@ -486,6 +512,10 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
486
512
  rawToprfPwEncryptionKey: pwEncKey,
487
513
  rawToprfAuthKeyPair: authKeyPair,
488
514
  });
515
+ // persist the latest global password authPubKey
516
+ __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
517
+ authPubKey: authKeyPair.pk,
518
+ });
489
519
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
490
520
  };
491
521
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, doSyncPassword, 'syncLatestGlobalPassword');
@@ -790,9 +820,9 @@ async function _SeedlessOnboardingController_loadSeedlessEncryptionKey(encKey) {
790
820
  * @throws RecoveryError - If failed to recover the encryption key.
791
821
  */
792
822
  async function _SeedlessOnboardingController_recoverEncKey(password) {
793
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
794
- const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
795
823
  try {
824
+ __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
825
+ const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
796
826
  const recoverEncKeyResult = await this.toprfClient.recoverEncKey({
797
827
  nodeAuthTokens: this.state.nodeAuthTokens,
798
828
  password,
@@ -803,39 +833,14 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
803
833
  return recoverEncKeyResult;
804
834
  }
805
835
  catch (error) {
836
+ console.log('error', error);
837
+ console.log('isTokenExpiredError', __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error));
806
838
  // throw token expired error for token refresh handler
807
839
  if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
808
840
  throw error;
809
841
  }
810
842
  throw errors_1.RecoveryError.getInstance(error);
811
843
  }
812
- }, _SeedlessOnboardingController_fetchAllSecretDataFromMetadataStore = async function _SeedlessOnboardingController_fetchAllSecretDataFromMetadataStore(encKey, authKeyPair) {
813
- let secretData = [];
814
- try {
815
- // fetch and decrypt the secret data from the metadata store
816
- secretData = await this.toprfClient.fetchAllSecretDataItems({
817
- decKey: encKey,
818
- authKeyPair,
819
- });
820
- }
821
- catch (error) {
822
- log('Error fetching secret data', error);
823
- if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
824
- throw error;
825
- }
826
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.FailedToFetchSecretMetadata);
827
- }
828
- // user must have at least one secret data
829
- if (secretData?.length > 0) {
830
- const secrets = SecretMetadata_1.SecretMetadata.parseSecretsFromMetadataStore(secretData);
831
- // validate the primary secret data is a mnemonic (SRP)
832
- const primarySecret = secrets[0];
833
- if (primarySecret.type !== constants_1.SecretType.Mnemonic) {
834
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidPrimarySecretDataType);
835
- }
836
- return secrets;
837
- }
838
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.NoSecretDataFound);
839
844
  }, _SeedlessOnboardingController_changeEncryptionKey =
840
845
  /**
841
846
  * Update the encryption key with new password and update the Metadata Store with new encryption key.
@@ -1065,10 +1070,6 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
1065
1070
  serializedVaultData,
1066
1071
  pwEncKey: rawToprfPwEncryptionKey,
1067
1072
  });
1068
- // update the authPubKey in the state
1069
- __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
1070
- authPubKey: rawToprfAuthKeyPair.pk,
1071
- });
1072
1073
  }, _SeedlessOnboardingController_updateVault =
1073
1074
  /**
1074
1075
  * Encrypt and update the vault with the given authentication data.