@metamask-previews/seedless-onboarding-controller 1.0.0-preview-abf6aaef → 1.0.0-preview-08a4995

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.
@@ -10,16 +10,13 @@ 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_recoverKeyringEncryptionKey, _SeedlessOnboardingController_setUnlocked, _SeedlessOnboardingController_persistOprfKey, _SeedlessOnboardingController_persistAuthPubKey, _SeedlessOnboardingController_storeKeyringEncryptionKey, _SeedlessOnboardingController_loadKeyringEncryptionKey, _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;
13
+ var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_isUnlocked, _SeedlessOnboardingController_recoverPassword, _SeedlessOnboardingController_setUnlocked, _SeedlessOnboardingController_persistOprfKey, _SeedlessOnboardingController_persistAuthPubKey, _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");
17
17
  const base_controller_1 = require("@metamask/base-controller");
18
18
  const toprf_secure_backup_1 = require("@metamask/toprf-secure-backup");
19
19
  const utils_1 = require("@metamask/utils");
20
- const aes_1 = require("@noble/ciphers/aes");
21
- const utils_2 = require("@noble/ciphers/utils");
22
- const webcrypto_1 = require("@noble/ciphers/webcrypto");
23
20
  const secp256k1_1 = require("@noble/curves/secp256k1");
24
21
  const async_mutex_1 = require("async-mutex");
25
22
  const constants_1 = require("./constants.cjs");
@@ -102,10 +99,6 @@ const seedlessOnboardingMetadata = {
102
99
  persist: false,
103
100
  anonymous: true,
104
101
  },
105
- encryptedKeyringEncryptionKey: {
106
- persist: true,
107
- anonymous: true,
108
- },
109
102
  };
110
103
  class SeedlessOnboardingController extends base_controller_1.BaseController {
111
104
  /**
@@ -217,10 +210,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
217
210
  * @param password - The password used to create new wallet and seedphrase
218
211
  * @param seedPhrase - The initial seed phrase (Mnemonic) created together with the wallet.
219
212
  * @param keyringId - The keyring id of the backup seed phrase
220
- * @param keyringEncryptionKey - The encryption key to be used for encrypting the keyring vault.
221
213
  * @returns A promise that resolves to the encrypted seed phrase and the encryption key.
222
214
  */
223
- async createToprfKeyAndBackupSeedPhrase(password, seedPhrase, keyringId, keyringEncryptionKey) {
215
+ async createToprfKeyAndBackupSeedPhrase(password, seedPhrase, keyringId) {
224
216
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
225
217
  // to make sure that fail fast,
226
218
  // assert that the user is authenticated before creating the TOPRF key and backing up the seed phrase
@@ -254,8 +246,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
254
246
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
255
247
  authPubKey: authKeyPair.pk,
256
248
  });
257
- // encrypt and store the keyring encryption key
258
- await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_storeKeyringEncryptionKey).call(this, encKey, keyringEncryptionKey);
259
249
  };
260
250
  await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, performKeyCreationAndBackup, 'createToprfKeyAndBackupSeedPhrase');
261
251
  });
@@ -357,13 +347,11 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
357
347
  *
358
348
  * Changing password will also update the encryption key, metadata store and the vault with new encrypted values.
359
349
  *
360
- * @param params - The function parameters.
361
- * @param params.oldPassword - The old password to verify.
362
- * @param params.newPassword - The new password to update.
363
- * @param params.newKeyringEncryptionKey - The new keyring encryption key to store.
350
+ * @param newPassword - The new password to update.
351
+ * @param oldPassword - The old password to verify.
364
352
  * @returns A promise that resolves to the success of the operation.
365
353
  */
366
- async changePassword({ oldPassword, newPassword, newKeyringEncryptionKey, }) {
354
+ async changePassword(newPassword, oldPassword) {
367
355
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
368
356
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this);
369
357
  // verify the old password of the encrypted vault
@@ -376,11 +364,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
376
364
  });
377
365
  const attemptChangePassword = async () => {
378
366
  // update the encryption key with new password and update the Metadata Store
379
- const { encKey: newEncKey, authKeyPair: newAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_changeEncryptionKey).call(this, {
380
- oldPassword,
381
- newPassword,
382
- newKeyringEncryptionKey,
383
- });
367
+ const { encKey: newEncKey, authKeyPair: newAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_changeEncryptionKey).call(this, newPassword, oldPassword);
384
368
  // update and encrypt the vault with new password
385
369
  await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
386
370
  password: newPassword,
@@ -483,12 +467,17 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
483
467
  * persist the latest global password authPubKey
484
468
  *
485
469
  * @param params - The parameters for syncing the latest global password.
470
+ * @param params.oldPassword - The old password to verify.
486
471
  * @param params.globalPassword - The latest global password.
487
472
  * @returns A promise that resolves to the success of the operation.
488
473
  */
489
- async syncLatestGlobalPassword({ globalPassword, }) {
474
+ async syncLatestGlobalPassword({ oldPassword, globalPassword, }) {
490
475
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
491
476
  const doSyncPassword = async () => {
477
+ // verify correct old password
478
+ await this.verifyVaultPassword(oldPassword, {
479
+ skipLock: true, // skip lock since we already have the lock
480
+ });
492
481
  // update vault with latest globalPassword
493
482
  const { encKey, authKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
494
483
  // update and encrypt the vault with new password
@@ -514,18 +503,18 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
514
503
  * @param params.globalPassword - The latest global password.
515
504
  * @returns A promise that resolves to the password corresponding to the current authPubKey in state.
516
505
  */
517
- async recoverKeyringEncryptionKey({ globalPassword, }) {
506
+ async recoverCurrentDevicePassword({ globalPassword, }) {
518
507
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
519
508
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, async () => {
520
509
  const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
521
- const { keyringEncryptionKey } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverKeyringEncryptionKey).call(this, {
522
- targetAuthPubKey: currentDeviceAuthPubKey,
510
+ const { password: currentDevicePassword } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverPassword).call(this, {
511
+ targetPwPubKey: currentDeviceAuthPubKey,
523
512
  globalPassword,
524
513
  });
525
514
  return {
526
- keyringEncryptionKey,
515
+ password: currentDevicePassword,
527
516
  };
528
- }, 'recoverKeyringEncryptionKey');
517
+ }, 'recoverCurrentDevicePassword');
529
518
  });
530
519
  }
531
520
  /**
@@ -665,27 +654,24 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
665
654
  }
666
655
  }
667
656
  exports.SeedlessOnboardingController = SeedlessOnboardingController;
668
- _SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardingController_controllerOperationMutex = new WeakMap(), _SeedlessOnboardingController_vaultOperationMutex = new WeakMap(), _SeedlessOnboardingController_refreshJWTToken = new WeakMap(), _SeedlessOnboardingController_revokeRefreshToken = new WeakMap(), _SeedlessOnboardingController_isUnlocked = new WeakMap(), _SeedlessOnboardingController_instances = new WeakSet(), _SeedlessOnboardingController_recoverKeyringEncryptionKey =
657
+ _SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardingController_controllerOperationMutex = new WeakMap(), _SeedlessOnboardingController_vaultOperationMutex = new WeakMap(), _SeedlessOnboardingController_refreshJWTToken = new WeakMap(), _SeedlessOnboardingController_revokeRefreshToken = new WeakMap(), _SeedlessOnboardingController_isUnlocked = new WeakMap(), _SeedlessOnboardingController_instances = new WeakSet(), _SeedlessOnboardingController_recoverPassword =
669
658
  /**
670
- * @description Fetch the keyring encryption key corresponding to the targetAuthPubKey.
659
+ * @description Fetch the password corresponding to the targetPwPubKey.
671
660
  *
672
- * @param params - The parameters for fetching the keyring encryption key.
673
- * @param params.targetAuthPubKey - The target public key of the keyring encryption key to recover.
661
+ * @param params - The parameters for fetching the password.
662
+ * @param params.targetPwPubKey - The target public key of the password to recover.
674
663
  * @param params.globalPassword - The latest global password.
675
- * @returns A promise that resolves to the keyring encryption key corresponding to the current authPubKey in state.
664
+ * @returns A promise that resolves to the password corresponding to the current authPubKey in state.
676
665
  */
677
- async function _SeedlessOnboardingController_recoverKeyringEncryptionKey({ targetAuthPubKey, globalPassword, }) {
666
+ async function _SeedlessOnboardingController_recoverPassword({ targetPwPubKey, globalPassword, }) {
678
667
  const { encKey: latestPwEncKey, authKeyPair: latestPwAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
679
668
  try {
680
669
  const res = await this.toprfClient.recoverPassword({
681
- targetPwPubKey: targetAuthPubKey,
670
+ targetPwPubKey,
682
671
  curEncKey: latestPwEncKey,
683
672
  curAuthKeyPair: latestPwAuthKeyPair,
684
673
  });
685
- const { password: recoveredEncryptionKeyBase64 } = res;
686
- const recoveredEncryptionKey = (0, utils_1.base64ToBytes)(recoveredEncryptionKeyBase64);
687
- const keyringEncryptionKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadKeyringEncryptionKey).call(this, recoveredEncryptionKey);
688
- return { keyringEncryptionKey };
674
+ return res;
689
675
  }
690
676
  catch (error) {
691
677
  if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
@@ -727,33 +713,6 @@ async function _SeedlessOnboardingController_persistOprfKey(oprfKey, authPubKey)
727
713
  this.update((state) => {
728
714
  state.authPubKey = (0, utils_1.bytesToBase64)(params.authPubKey);
729
715
  });
730
- }, _SeedlessOnboardingController_storeKeyringEncryptionKey =
731
- /**
732
- * Encrypt the keyring encryption key and store it in state.
733
- *
734
- * @param encKey - The encryption key.
735
- * @param keyringEncryptionKey - The keyring encryption key.
736
- */
737
- async function _SeedlessOnboardingController_storeKeyringEncryptionKey(encKey, keyringEncryptionKey) {
738
- const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(encKey);
739
- const encryptedKeyringEncryptionKey = aes.encrypt((0, utils_2.utf8ToBytes)(keyringEncryptionKey));
740
- this.update((state) => {
741
- state.encryptedKeyringEncryptionKey = (0, utils_1.bytesToBase64)(encryptedKeyringEncryptionKey);
742
- });
743
- }, _SeedlessOnboardingController_loadKeyringEncryptionKey =
744
- /**
745
- * Decrypt the keyring encryption key from state.
746
- *
747
- * @param encKey - The encryption key.
748
- * @returns The keyring encryption key.
749
- */
750
- async function _SeedlessOnboardingController_loadKeyringEncryptionKey(encKey) {
751
- const { encryptedKeyringEncryptionKey: encryptedKey } = this.state;
752
- assertIsEncryptedKeyringEncryptionKeySet(encryptedKey);
753
- const encryptedPasswordBytes = (0, utils_1.base64ToBytes)(encryptedKey);
754
- const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(encKey);
755
- const password = aes.decrypt(encryptedPasswordBytes);
756
- return (0, utils_2.bytesToUtf8)(password);
757
716
  }, _SeedlessOnboardingController_recoverAuthPubKey = function _SeedlessOnboardingController_recoverAuthPubKey() {
758
717
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsSRPBackedUpUser).call(this, this.state);
759
718
  const { authPubKey } = this.state;
@@ -792,17 +751,15 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
792
751
  /**
793
752
  * Update the encryption key with new password and update the Metadata Store with new encryption key.
794
753
  *
795
- * @param params - The function parameters.
796
- * @param params.oldPassword - The old password to verify.
797
- * @param params.newPassword - The new password to update.
798
- * @param params.newKeyringEncryptionKey - The new keyring encryption key to store.
754
+ * @param newPassword - The new password to update.
755
+ * @param oldPassword - The old password to verify.
799
756
  * @returns A promise that resolves to new encryption key and authentication key pair.
800
757
  */
801
- async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, newKeyringEncryptionKey, }) {
758
+ async function _SeedlessOnboardingController_changeEncryptionKey(newPassword, oldPassword) {
802
759
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
803
760
  const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
804
761
  const { encKey, authKeyPair, keyShareIndex: newKeyShareIndex, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword);
805
- const result = await this.toprfClient.changeEncKey({
762
+ return await this.toprfClient.changeEncKey({
806
763
  nodeAuthTokens: this.state.nodeAuthTokens,
807
764
  authConnectionId,
808
765
  groupedAuthConnectionId,
@@ -810,11 +767,9 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
810
767
  oldEncKey: encKey,
811
768
  oldAuthKeyPair: authKeyPair,
812
769
  newKeyShareIndex,
813
- oldPassword: (0, utils_1.bytesToBase64)(encKey),
770
+ oldPassword,
814
771
  newPassword,
815
772
  });
816
- await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_storeKeyringEncryptionKey).call(this, result.encKey, newKeyringEncryptionKey);
817
- return result;
818
773
  }, _SeedlessOnboardingController_encryptAndStoreSecretData =
819
774
  /**
820
775
  * Encrypt and store the secret data backup in the metadata store.
@@ -1241,15 +1196,4 @@ async function withLock(mutex, callback) {
1241
1196
  releaseLock();
1242
1197
  }
1243
1198
  }
1244
- /**
1245
- * Assert that the provided encrypted keyring encryption key is a valid non-empty string.
1246
- *
1247
- * @param encryptedKeyringEncryptionKey - The encrypted keyring encryption key to check.
1248
- * @throws If the encrypted keyring encryption key is not a valid string.
1249
- */
1250
- function assertIsEncryptedKeyringEncryptionKeySet(encryptedKeyringEncryptionKey) {
1251
- if (!encryptedKeyringEncryptionKey) {
1252
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.EncryptedKeyringEncryptionKeyNotSet);
1253
- }
1254
- }
1255
1199
  //# sourceMappingURL=SeedlessOnboardingController.cjs.map