@metamask-previews/seedless-onboarding-controller 1.0.0-preview-d327019 → 1.0.0-preview-e149187d
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/dist/SeedlessOnboardingController.cjs +71 -47
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +13 -6
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +13 -6
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +71 -47
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/constants.cjs +2 -2
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -2
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +2 -2
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +2 -2
- package/dist/constants.mjs.map +1 -1
- package/dist/errors.cjs +3 -3
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.mjs +3 -3
- package/dist/errors.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -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,
|
|
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;
|
|
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");
|
|
@@ -102,7 +102,7 @@ const seedlessOnboardingMetadata = {
|
|
|
102
102
|
persist: false,
|
|
103
103
|
anonymous: true,
|
|
104
104
|
},
|
|
105
|
-
|
|
105
|
+
encryptedKeyringEncryptionKey: {
|
|
106
106
|
persist: true,
|
|
107
107
|
anonymous: true,
|
|
108
108
|
},
|
|
@@ -217,9 +217,10 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
217
217
|
* @param password - The password used to create new wallet and seedphrase
|
|
218
218
|
* @param seedPhrase - The initial seed phrase (Mnemonic) created together with the wallet.
|
|
219
219
|
* @param keyringId - The keyring id of the backup seed phrase
|
|
220
|
+
* @param keyringEncryptionKey - The encryption key to be used for encrypting the keyring vault.
|
|
220
221
|
* @returns A promise that resolves to the encrypted seed phrase and the encryption key.
|
|
221
222
|
*/
|
|
222
|
-
async createToprfKeyAndBackupSeedPhrase(password, seedPhrase, keyringId) {
|
|
223
|
+
async createToprfKeyAndBackupSeedPhrase(password, seedPhrase, keyringId, keyringEncryptionKey) {
|
|
223
224
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
224
225
|
// to make sure that fail fast,
|
|
225
226
|
// assert that the user is authenticated before creating the TOPRF key and backing up the seed phrase
|
|
@@ -253,7 +254,8 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
253
254
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
|
|
254
255
|
authPubKey: authKeyPair.pk,
|
|
255
256
|
});
|
|
256
|
-
|
|
257
|
+
// encrypt and store the keyring encryption key
|
|
258
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_storeKeyringEncryptionKey).call(this, encKey, keyringEncryptionKey);
|
|
257
259
|
};
|
|
258
260
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, performKeyCreationAndBackup, 'createToprfKeyAndBackupSeedPhrase');
|
|
259
261
|
});
|
|
@@ -355,11 +357,13 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
355
357
|
*
|
|
356
358
|
* Changing password will also update the encryption key, metadata store and the vault with new encrypted values.
|
|
357
359
|
*
|
|
358
|
-
* @param
|
|
359
|
-
* @param oldPassword - The old password to verify.
|
|
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.
|
|
360
364
|
* @returns A promise that resolves to the success of the operation.
|
|
361
365
|
*/
|
|
362
|
-
async changePassword(newPassword,
|
|
366
|
+
async changePassword({ oldPassword, newPassword, newKeyringEncryptionKey, }) {
|
|
363
367
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
364
368
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this);
|
|
365
369
|
// verify the old password of the encrypted vault
|
|
@@ -372,7 +376,11 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
372
376
|
});
|
|
373
377
|
const attemptChangePassword = async () => {
|
|
374
378
|
// update the encryption key with new password and update the Metadata Store
|
|
375
|
-
const { encKey: newEncKey, authKeyPair: newAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_changeEncryptionKey).call(this,
|
|
379
|
+
const { encKey: newEncKey, authKeyPair: newAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_changeEncryptionKey).call(this, {
|
|
380
|
+
oldPassword,
|
|
381
|
+
newPassword,
|
|
382
|
+
newKeyringEncryptionKey,
|
|
383
|
+
});
|
|
376
384
|
// update and encrypt the vault with new password
|
|
377
385
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
378
386
|
password: newPassword,
|
|
@@ -511,18 +519,18 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
511
519
|
* @param params.globalPassword - The latest global password.
|
|
512
520
|
* @returns A promise that resolves to the password corresponding to the current authPubKey in state.
|
|
513
521
|
*/
|
|
514
|
-
async
|
|
522
|
+
async recoverKeyringEncryptionKey({ globalPassword, }) {
|
|
515
523
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
516
524
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, async () => {
|
|
517
525
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
518
|
-
const {
|
|
519
|
-
|
|
526
|
+
const { keyringEncryptionKey } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverKeyringEncryptionKey).call(this, {
|
|
527
|
+
targetAuthPubKey: currentDeviceAuthPubKey,
|
|
520
528
|
globalPassword,
|
|
521
529
|
});
|
|
522
530
|
return {
|
|
523
|
-
|
|
531
|
+
keyringEncryptionKey,
|
|
524
532
|
};
|
|
525
|
-
}, '
|
|
533
|
+
}, 'recoverKeyringEncryptionKey');
|
|
526
534
|
});
|
|
527
535
|
}
|
|
528
536
|
/**
|
|
@@ -662,27 +670,27 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
662
670
|
}
|
|
663
671
|
}
|
|
664
672
|
exports.SeedlessOnboardingController = SeedlessOnboardingController;
|
|
665
|
-
_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(),
|
|
673
|
+
_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 =
|
|
666
674
|
/**
|
|
667
|
-
* @description Fetch the
|
|
675
|
+
* @description Fetch the keyring encryption key corresponding to the targetAuthPubKey.
|
|
668
676
|
*
|
|
669
|
-
* @param params - The parameters for fetching the
|
|
670
|
-
* @param params.
|
|
677
|
+
* @param params - The parameters for fetching the keyring encryption key.
|
|
678
|
+
* @param params.targetAuthPubKey - The target public key of the keyring encryption key to recover.
|
|
671
679
|
* @param params.globalPassword - The latest global password.
|
|
672
|
-
* @returns A promise that resolves to the
|
|
680
|
+
* @returns A promise that resolves to the keyring encryption key corresponding to the current authPubKey in state.
|
|
673
681
|
*/
|
|
674
|
-
async function
|
|
682
|
+
async function _SeedlessOnboardingController_recoverKeyringEncryptionKey({ targetAuthPubKey, globalPassword, }) {
|
|
675
683
|
const { encKey: latestPwEncKey, authKeyPair: latestPwAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
|
|
676
684
|
try {
|
|
677
685
|
const res = await this.toprfClient.recoverPassword({
|
|
678
|
-
targetPwPubKey,
|
|
686
|
+
targetPwPubKey: targetAuthPubKey,
|
|
679
687
|
curEncKey: latestPwEncKey,
|
|
680
688
|
curAuthKeyPair: latestPwAuthKeyPair,
|
|
681
689
|
});
|
|
682
690
|
const { password: recoveredEncryptionKeyBase64 } = res;
|
|
683
691
|
const recoveredEncryptionKey = (0, utils_1.base64ToBytes)(recoveredEncryptionKeyBase64);
|
|
684
|
-
const
|
|
685
|
-
return {
|
|
692
|
+
const keyringEncryptionKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadKeyringEncryptionKey).call(this, recoveredEncryptionKey);
|
|
693
|
+
return { keyringEncryptionKey };
|
|
686
694
|
}
|
|
687
695
|
catch (error) {
|
|
688
696
|
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
|
|
@@ -724,6 +732,33 @@ async function _SeedlessOnboardingController_persistOprfKey(oprfKey, authPubKey)
|
|
|
724
732
|
this.update((state) => {
|
|
725
733
|
state.authPubKey = (0, utils_1.bytesToBase64)(params.authPubKey);
|
|
726
734
|
});
|
|
735
|
+
}, _SeedlessOnboardingController_storeKeyringEncryptionKey =
|
|
736
|
+
/**
|
|
737
|
+
* Encrypt the keyring encryption key and store it in state.
|
|
738
|
+
*
|
|
739
|
+
* @param encKey - The encryption key.
|
|
740
|
+
* @param keyringEncryptionKey - The keyring encryption key.
|
|
741
|
+
*/
|
|
742
|
+
async function _SeedlessOnboardingController_storeKeyringEncryptionKey(encKey, keyringEncryptionKey) {
|
|
743
|
+
const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(encKey);
|
|
744
|
+
const encryptedKeyringEncryptionKey = aes.encrypt((0, utils_2.utf8ToBytes)(keyringEncryptionKey));
|
|
745
|
+
this.update((state) => {
|
|
746
|
+
state.encryptedKeyringEncryptionKey = (0, utils_1.bytesToBase64)(encryptedKeyringEncryptionKey);
|
|
747
|
+
});
|
|
748
|
+
}, _SeedlessOnboardingController_loadKeyringEncryptionKey =
|
|
749
|
+
/**
|
|
750
|
+
* Decrypt the keyring encryption key from state.
|
|
751
|
+
*
|
|
752
|
+
* @param encKey - The encryption key.
|
|
753
|
+
* @returns The keyring encryption key.
|
|
754
|
+
*/
|
|
755
|
+
async function _SeedlessOnboardingController_loadKeyringEncryptionKey(encKey) {
|
|
756
|
+
const { encryptedKeyringEncryptionKey: encryptedKey } = this.state;
|
|
757
|
+
assertIsEncryptedKeyringEncryptionKeySet(encryptedKey);
|
|
758
|
+
const encryptedPasswordBytes = (0, utils_1.base64ToBytes)(encryptedKey);
|
|
759
|
+
const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(encKey);
|
|
760
|
+
const password = aes.decrypt(encryptedPasswordBytes);
|
|
761
|
+
return (0, utils_2.bytesToUtf8)(password);
|
|
727
762
|
}, _SeedlessOnboardingController_recoverAuthPubKey = function _SeedlessOnboardingController_recoverAuthPubKey() {
|
|
728
763
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsSRPBackedUpUser).call(this, this.state);
|
|
729
764
|
const { authPubKey } = this.state;
|
|
@@ -762,15 +797,17 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
|
|
|
762
797
|
/**
|
|
763
798
|
* Update the encryption key with new password and update the Metadata Store with new encryption key.
|
|
764
799
|
*
|
|
765
|
-
* @param
|
|
766
|
-
* @param oldPassword - The old password to verify.
|
|
800
|
+
* @param params - The function parameters.
|
|
801
|
+
* @param params.oldPassword - The old password to verify.
|
|
802
|
+
* @param params.newPassword - The new password to update.
|
|
803
|
+
* @param params.newKeyringEncryptionKey - The new keyring encryption key to store.
|
|
767
804
|
* @returns A promise that resolves to new encryption key and authentication key pair.
|
|
768
805
|
*/
|
|
769
|
-
async function _SeedlessOnboardingController_changeEncryptionKey(newPassword,
|
|
806
|
+
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, newKeyringEncryptionKey, }) {
|
|
770
807
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
771
808
|
const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
|
|
772
809
|
const { encKey, authKeyPair, keyShareIndex: newKeyShareIndex, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword);
|
|
773
|
-
const
|
|
810
|
+
const result = await this.toprfClient.changeEncKey({
|
|
774
811
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
775
812
|
authConnectionId,
|
|
776
813
|
groupedAuthConnectionId,
|
|
@@ -781,21 +818,8 @@ async function _SeedlessOnboardingController_changeEncryptionKey(newPassword, ol
|
|
|
781
818
|
oldPassword: (0, utils_1.bytesToBase64)(encKey),
|
|
782
819
|
newPassword,
|
|
783
820
|
});
|
|
784
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m",
|
|
785
|
-
return
|
|
786
|
-
}, _SeedlessOnboardingController_storeEncryptedPassword = async function _SeedlessOnboardingController_storeEncryptedPassword(encKey, password) {
|
|
787
|
-
const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(encKey);
|
|
788
|
-
const encryptedPassword = aes.encrypt((0, utils_2.utf8ToBytes)(password));
|
|
789
|
-
this.update((state) => {
|
|
790
|
-
state.encryptedPassword = (0, utils_1.bytesToBase64)(encryptedPassword);
|
|
791
|
-
});
|
|
792
|
-
}, _SeedlessOnboardingController_loadEncryptedPassword = async function _SeedlessOnboardingController_loadEncryptedPassword(encKey) {
|
|
793
|
-
const { encryptedPassword } = this.state;
|
|
794
|
-
assertIsEncryptedPasswordSet(encryptedPassword);
|
|
795
|
-
const encryptedPasswordBytes = (0, utils_1.base64ToBytes)(encryptedPassword);
|
|
796
|
-
const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(encKey);
|
|
797
|
-
const password = aes.decrypt(encryptedPasswordBytes);
|
|
798
|
-
return (0, utils_2.bytesToUtf8)(password);
|
|
821
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_storeKeyringEncryptionKey).call(this, result.encKey, newKeyringEncryptionKey);
|
|
822
|
+
return result;
|
|
799
823
|
}, _SeedlessOnboardingController_encryptAndStoreSecretData =
|
|
800
824
|
/**
|
|
801
825
|
* Encrypt and store the secret data backup in the metadata store.
|
|
@@ -1223,14 +1247,14 @@ async function withLock(mutex, callback) {
|
|
|
1223
1247
|
}
|
|
1224
1248
|
}
|
|
1225
1249
|
/**
|
|
1226
|
-
* Assert that the provided encrypted
|
|
1250
|
+
* Assert that the provided encrypted keyring encryption key is a valid non-empty string.
|
|
1227
1251
|
*
|
|
1228
|
-
* @param
|
|
1229
|
-
* @throws If the encrypted
|
|
1252
|
+
* @param encryptedKeyringEncryptionKey - The encrypted keyring encryption key to check.
|
|
1253
|
+
* @throws If the encrypted keyring encryption key is not a valid string.
|
|
1230
1254
|
*/
|
|
1231
|
-
function
|
|
1232
|
-
if (!
|
|
1233
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.
|
|
1255
|
+
function assertIsEncryptedKeyringEncryptionKeySet(encryptedKeyringEncryptionKey) {
|
|
1256
|
+
if (!encryptedKeyringEncryptionKey) {
|
|
1257
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.EncryptedKeyringEncryptionKeyNotSet);
|
|
1234
1258
|
}
|
|
1235
1259
|
}
|
|
1236
1260
|
//# sourceMappingURL=SeedlessOnboardingController.cjs.map
|