@metamask-previews/seedless-onboarding-controller 1.0.0-preview-4e3fd4c0 → 1.0.0-preview-c6e5eb7

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
  /**
@@ -370,16 +363,8 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
370
363
  skipLock: true, // skip lock since we already have the lock
371
364
  });
372
365
  const attemptChangePassword = async () => {
373
- // load keyring encryption key if it exists
374
- let keyringEncryptionKey;
375
- if (this.state.encryptedKeyringEncryptionKey) {
376
- keyringEncryptionKey = await this.loadKeyringEncryptionKey();
377
- }
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
- });
367
+ const { encKey: newEncKey, authKeyPair: newAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_changeEncryptionKey).call(this, newPassword, oldPassword);
383
368
  // update and encrypt the vault with new password
384
369
  await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
385
370
  password: newPassword,
@@ -390,10 +375,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
390
375
  authPubKey: newAuthKeyPair.pk,
391
376
  });
392
377
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
393
- // store the keyring encryption key if it exists
394
- if (keyringEncryptionKey) {
395
- await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_storeKeyringEncryptionKey).call(this, newEncKey, keyringEncryptionKey);
396
- }
397
378
  };
398
379
  try {
399
380
  await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, attemptChangePassword, 'changePassword');
@@ -486,12 +467,17 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
486
467
  * persist the latest global password authPubKey
487
468
  *
488
469
  * @param params - The parameters for syncing the latest global password.
470
+ * @param params.oldPassword - The old password to verify.
489
471
  * @param params.globalPassword - The latest global password.
490
472
  * @returns A promise that resolves to the success of the operation.
491
473
  */
492
- async syncLatestGlobalPassword({ globalPassword, }) {
474
+ async syncLatestGlobalPassword({ oldPassword, globalPassword, }) {
493
475
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
494
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
+ });
495
481
  // update vault with latest globalPassword
496
482
  const { encKey, authKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
497
483
  // update and encrypt the vault with new password
@@ -517,18 +503,18 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
517
503
  * @param params.globalPassword - The latest global password.
518
504
  * @returns A promise that resolves to the password corresponding to the current authPubKey in state.
519
505
  */
520
- async recoverKeyringEncryptionKey({ globalPassword, }) {
506
+ async recoverCurrentDevicePassword({ globalPassword, }) {
521
507
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
522
508
  return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, async () => {
523
509
  const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
524
- const { keyringEncryptionKey } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverKeyringEncryptionKey).call(this, {
525
- targetAuthPubKey: currentDeviceAuthPubKey,
510
+ const { password: currentDevicePassword } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverPassword).call(this, {
511
+ targetPwPubKey: currentDeviceAuthPubKey,
526
512
  globalPassword,
527
513
  });
528
514
  return {
529
- keyringEncryptionKey,
515
+ password: currentDevicePassword,
530
516
  };
531
- }, 'recoverKeyringEncryptionKey');
517
+ }, 'recoverCurrentDevicePassword');
532
518
  });
533
519
  }
534
520
  /**
@@ -583,26 +569,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
583
569
  return defaultState;
584
570
  });
585
571
  }
586
- /**
587
- * Store the keyring encryption key in state, encrypted under the current
588
- * encryption key.
589
- *
590
- * @param keyringEncryptionKey - The keyring encryption key.
591
- */
592
- async storeKeyringEncryptionKey(keyringEncryptionKey) {
593
- const { toprfEncryptionKey: encKey } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetBackupEncKey).call(this);
594
- await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_storeKeyringEncryptionKey).call(this, encKey, keyringEncryptionKey);
595
- }
596
- /**
597
- * Load the keyring encryption key from state, decrypted under the current
598
- * encryption key.
599
- *
600
- * @returns The keyring encryption key.
601
- */
602
- async loadKeyringEncryptionKey() {
603
- const { toprfEncryptionKey: encKey } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetBackupEncKey).call(this);
604
- return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadKeyringEncryptionKey).call(this, encKey);
605
- }
606
572
  /**
607
573
  * Refresh expired nodeAuthTokens using the stored refresh token.
608
574
  *
@@ -688,27 +654,24 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
688
654
  }
689
655
  }
690
656
  exports.SeedlessOnboardingController = SeedlessOnboardingController;
691
- _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 =
692
658
  /**
693
- * @description Fetch the keyring encryption key corresponding to the targetAuthPubKey.
659
+ * @description Fetch the password corresponding to the targetPwPubKey.
694
660
  *
695
- * @param params - The parameters for fetching the keyring encryption key.
696
- * @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.
697
663
  * @param params.globalPassword - The latest global password.
698
- * @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.
699
665
  */
700
- async function _SeedlessOnboardingController_recoverKeyringEncryptionKey({ targetAuthPubKey, globalPassword, }) {
666
+ async function _SeedlessOnboardingController_recoverPassword({ targetPwPubKey, globalPassword, }) {
701
667
  const { encKey: latestPwEncKey, authKeyPair: latestPwAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
702
668
  try {
703
669
  const res = await this.toprfClient.recoverPassword({
704
- targetPwPubKey: targetAuthPubKey,
670
+ targetPwPubKey,
705
671
  curEncKey: latestPwEncKey,
706
672
  curAuthKeyPair: latestPwAuthKeyPair,
707
673
  });
708
- const { password: recoveredEncryptionKeyBase64 } = res;
709
- const recoveredEncryptionKey = (0, utils_1.base64ToBytes)(recoveredEncryptionKeyBase64);
710
- const keyringEncryptionKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadKeyringEncryptionKey).call(this, recoveredEncryptionKey);
711
- return { keyringEncryptionKey };
674
+ return res;
712
675
  }
713
676
  catch (error) {
714
677
  if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
@@ -750,33 +713,6 @@ async function _SeedlessOnboardingController_persistOprfKey(oprfKey, authPubKey)
750
713
  this.update((state) => {
751
714
  state.authPubKey = (0, utils_1.bytesToBase64)(params.authPubKey);
752
715
  });
753
- }, _SeedlessOnboardingController_storeKeyringEncryptionKey =
754
- /**
755
- * Encrypt the keyring encryption key and store it in state.
756
- *
757
- * @param encKey - The encryption key.
758
- * @param keyringEncryptionKey - The keyring encryption key.
759
- */
760
- async function _SeedlessOnboardingController_storeKeyringEncryptionKey(encKey, keyringEncryptionKey) {
761
- const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(encKey);
762
- const encryptedKeyringEncryptionKey = aes.encrypt((0, utils_2.utf8ToBytes)(keyringEncryptionKey));
763
- this.update((state) => {
764
- state.encryptedKeyringEncryptionKey = (0, utils_1.bytesToBase64)(encryptedKeyringEncryptionKey);
765
- });
766
- }, _SeedlessOnboardingController_loadKeyringEncryptionKey =
767
- /**
768
- * Decrypt the keyring encryption key from state.
769
- *
770
- * @param encKey - The encryption key.
771
- * @returns The keyring encryption key.
772
- */
773
- async function _SeedlessOnboardingController_loadKeyringEncryptionKey(encKey) {
774
- const { encryptedKeyringEncryptionKey: encryptedKey } = this.state;
775
- assertIsEncryptedKeyringEncryptionKeySet(encryptedKey);
776
- const encryptedPasswordBytes = (0, utils_1.base64ToBytes)(encryptedKey);
777
- const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(encKey);
778
- const password = aes.decrypt(encryptedPasswordBytes);
779
- return (0, utils_2.bytesToUtf8)(password);
780
716
  }, _SeedlessOnboardingController_recoverAuthPubKey = function _SeedlessOnboardingController_recoverAuthPubKey() {
781
717
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsSRPBackedUpUser).call(this, this.state);
782
718
  const { authPubKey } = this.state;
@@ -815,16 +751,15 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
815
751
  /**
816
752
  * Update the encryption key with new password and update the Metadata Store with new encryption key.
817
753
  *
818
- * @param params - The function parameters.
819
- * @param params.oldPassword - The old password to verify.
820
- * @param params.newPassword - The new password to update.
754
+ * @param newPassword - The new password to update.
755
+ * @param oldPassword - The old password to verify.
821
756
  * @returns A promise that resolves to new encryption key and authentication key pair.
822
757
  */
823
- async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, }) {
758
+ async function _SeedlessOnboardingController_changeEncryptionKey(newPassword, oldPassword) {
824
759
  __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
825
760
  const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
826
761
  const { encKey, authKeyPair, keyShareIndex: newKeyShareIndex, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword);
827
- const result = await this.toprfClient.changeEncKey({
762
+ return await this.toprfClient.changeEncKey({
828
763
  nodeAuthTokens: this.state.nodeAuthTokens,
829
764
  authConnectionId,
830
765
  groupedAuthConnectionId,
@@ -832,10 +767,9 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
832
767
  oldEncKey: encKey,
833
768
  oldAuthKeyPair: authKeyPair,
834
769
  newKeyShareIndex,
835
- oldPassword: (0, utils_1.bytesToBase64)(encKey),
770
+ oldPassword,
836
771
  newPassword,
837
772
  });
838
- return result;
839
773
  }, _SeedlessOnboardingController_encryptAndStoreSecretData =
840
774
  /**
841
775
  * Encrypt and store the secret data backup in the metadata store.
@@ -1262,15 +1196,4 @@ async function withLock(mutex, callback) {
1262
1196
  releaseLock();
1263
1197
  }
1264
1198
  }
1265
- /**
1266
- * Assert that the provided encrypted keyring encryption key is a valid non-empty string.
1267
- *
1268
- * @param encryptedKeyringEncryptionKey - The encrypted keyring encryption key to check.
1269
- * @throws If the encrypted keyring encryption key is not a valid string.
1270
- */
1271
- function assertIsEncryptedKeyringEncryptionKeySet(encryptedKeyringEncryptionKey) {
1272
- if (!encryptedKeyringEncryptionKey) {
1273
- throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.EncryptedKeyringEncryptionKeyNotSet);
1274
- }
1275
- }
1276
1199
  //# sourceMappingURL=SeedlessOnboardingController.cjs.map