@metamask-previews/seedless-onboarding-controller 2.4.0-preview-fed19434 → 2.4.0-preview-9b5151c
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 +0 -9
- package/dist/SeedlessOnboardingController.cjs +57 -62
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +13 -1
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +13 -1
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +57 -62
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -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_isUnlocked, _SeedlessOnboardingController_passwordOutdatedCacheTTL,
|
|
12
|
+
var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_isUnlocked, _SeedlessOnboardingController_passwordOutdatedCacheTTL, _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_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_revokeRefreshTokenAndUpdateState, _SeedlessOnboardingController_isTokenExpiredError, _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";
|
|
@@ -491,26 +491,14 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
491
491
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
492
492
|
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
|
|
493
493
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
494
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
495
|
-
password,
|
|
496
|
-
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
497
|
-
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
498
|
-
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
499
|
-
});
|
|
500
494
|
if (revokeToken) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
509
|
-
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
510
|
-
});
|
|
511
|
-
})
|
|
512
|
-
.catch((error) => {
|
|
513
|
-
log('Error revoking refresh token', error);
|
|
495
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken);
|
|
496
|
+
// re-creating vault to persist the new revoke token
|
|
497
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
498
|
+
password,
|
|
499
|
+
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
500
|
+
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
501
|
+
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
514
502
|
});
|
|
515
503
|
}
|
|
516
504
|
});
|
|
@@ -529,6 +517,33 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
529
517
|
});
|
|
530
518
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
531
519
|
}
|
|
520
|
+
/**
|
|
521
|
+
* Sync the latest global password to the controller.
|
|
522
|
+
* reset vault with latest globalPassword,
|
|
523
|
+
* persist the latest global password authPubKey
|
|
524
|
+
*
|
|
525
|
+
* @param params - The parameters for syncing the latest global password.
|
|
526
|
+
* @param params.globalPassword - The latest global password.
|
|
527
|
+
* @returns A promise that resolves to the success of the operation.
|
|
528
|
+
*/
|
|
529
|
+
async syncLatestGlobalPassword({ globalPassword, }) {
|
|
530
|
+
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
531
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this);
|
|
532
|
+
const doSyncPassword = async () => {
|
|
533
|
+
// update vault with latest globalPassword
|
|
534
|
+
const { encKey, pwEncKey, authKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
|
|
535
|
+
// update and encrypt the vault with new password
|
|
536
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
537
|
+
password: globalPassword,
|
|
538
|
+
rawToprfEncryptionKey: encKey,
|
|
539
|
+
rawToprfPwEncryptionKey: pwEncKey,
|
|
540
|
+
rawToprfAuthKeyPair: authKeyPair,
|
|
541
|
+
});
|
|
542
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
|
|
543
|
+
};
|
|
544
|
+
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, doSyncPassword, 'syncLatestGlobalPassword');
|
|
545
|
+
});
|
|
546
|
+
}
|
|
532
547
|
/**
|
|
533
548
|
* @description Unlock the controller with the latest global password.
|
|
534
549
|
*
|
|
@@ -537,16 +552,16 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
537
552
|
* @param params.globalPassword - The latest global password.
|
|
538
553
|
* @returns A promise that resolves to the success of the operation.
|
|
539
554
|
*/
|
|
540
|
-
async
|
|
555
|
+
async submitGlobalPassword({ globalPassword, maxKeyChainLength = 5, }) {
|
|
541
556
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
542
557
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, async () => {
|
|
543
558
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
544
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m",
|
|
559
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_submitGlobalPassword).call(this, {
|
|
545
560
|
targetAuthPubKey: currentDeviceAuthPubKey,
|
|
546
561
|
globalPassword,
|
|
547
562
|
maxKeyChainLength,
|
|
548
563
|
});
|
|
549
|
-
}, '
|
|
564
|
+
}, 'submitGlobalPassword');
|
|
550
565
|
});
|
|
551
566
|
}
|
|
552
567
|
/**
|
|
@@ -719,7 +734,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
719
734
|
}
|
|
720
735
|
}
|
|
721
736
|
}
|
|
722
|
-
_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_passwordOutdatedCacheTTL = new WeakMap(), _SeedlessOnboardingController_instances = new WeakSet(),
|
|
737
|
+
_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_passwordOutdatedCacheTTL = new WeakMap(), _SeedlessOnboardingController_instances = new WeakSet(), _SeedlessOnboardingController_submitGlobalPassword =
|
|
723
738
|
/**
|
|
724
739
|
* @description Submit the global password to the controller, verify the
|
|
725
740
|
* password validity and unlock the controller.
|
|
@@ -732,52 +747,32 @@ _SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardin
|
|
|
732
747
|
* @returns A promise that resolves to the keyring encryption key
|
|
733
748
|
* corresponding to the current authPubKey in state.
|
|
734
749
|
*/
|
|
735
|
-
async function
|
|
736
|
-
const { pwEncKey:
|
|
750
|
+
async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPubKey, globalPassword, maxKeyChainLength, }) {
|
|
751
|
+
const { pwEncKey: curPwEncKey, authKeyPair: curAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
|
|
737
752
|
try {
|
|
738
|
-
// Recover
|
|
739
|
-
const
|
|
753
|
+
// Recover vault encryption key.
|
|
754
|
+
const res = await this.toprfClient.recoverPwEncKey({
|
|
740
755
|
targetAuthPubKey,
|
|
741
|
-
curPwEncKey
|
|
742
|
-
curAuthKeyPair
|
|
756
|
+
curPwEncKey,
|
|
757
|
+
curAuthKeyPair,
|
|
743
758
|
maxPwChainLength: maxKeyChainLength,
|
|
744
759
|
});
|
|
745
|
-
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
]);
|
|
750
|
-
// Unlock the controller and vault
|
|
751
|
-
const { revokeToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
760
|
+
const { pwEncKey } = res;
|
|
761
|
+
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
762
|
+
// Unlock the controller
|
|
763
|
+
const { revokeToken, toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
752
764
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
753
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
754
|
-
password: globalPassword,
|
|
755
|
-
rawToprfEncryptionKey: latestEncKey,
|
|
756
|
-
rawToprfPwEncryptionKey: latestPwEncKey,
|
|
757
|
-
rawToprfAuthKeyPair: latestAuthKeyPair,
|
|
758
|
-
});
|
|
759
765
|
if (revokeToken) {
|
|
760
|
-
//
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
rawToprfEncryptionKey: latestEncKey,
|
|
769
|
-
rawToprfPwEncryptionKey: latestPwEncKey,
|
|
770
|
-
rawToprfAuthKeyPair: latestAuthKeyPair,
|
|
771
|
-
});
|
|
772
|
-
})
|
|
773
|
-
.catch((error) => {
|
|
774
|
-
log('Error revoking refresh token', error);
|
|
766
|
+
// revoke and recyle refresh token after unlock to keep refresh token fresh, avoid malicious use of leaked refresh token
|
|
767
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken);
|
|
768
|
+
// re-creating vault to persist the new revoke token
|
|
769
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
770
|
+
password: globalPassword,
|
|
771
|
+
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
772
|
+
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
773
|
+
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
775
774
|
});
|
|
776
775
|
}
|
|
777
|
-
// restore the current keyring encryption key with the new global password
|
|
778
|
-
await this.storeKeyringEncryptionKey(keyringEncryptionKey);
|
|
779
|
-
// reset the password outdated cache after successful global password submission and state sync
|
|
780
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
|
|
781
776
|
}
|
|
782
777
|
catch (error) {
|
|
783
778
|
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
|