@metamask-previews/seedless-onboarding-controller 2.1.0-preview-c2d112dc → 2.1.0-preview-7b1ac259
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 +4 -0
- package/dist/SeedlessOnboardingController.cjs +35 -4
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +14 -1
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +14 -1
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +35 -4
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/constants.cjs +1 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +2 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -0
- package/dist/constants.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- remove `access_token` validation when the wallet is locked. ([#6133](https://github.com/MetaMask/core/pull/6133))
|
|
13
|
+
|
|
10
14
|
## [2.1.0]
|
|
11
15
|
|
|
12
16
|
### Added
|
|
@@ -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_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_isMaxKeyChainLengthError, _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");
|
|
@@ -212,6 +212,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
212
212
|
* @returns A promise that resolves to the authentication result.
|
|
213
213
|
*/
|
|
214
214
|
async authenticate(params) {
|
|
215
|
+
console.log('authenticate::params', params);
|
|
215
216
|
const doAuthenticateWithNodes = async () => {
|
|
216
217
|
try {
|
|
217
218
|
const { idTokens, authConnectionId, groupedAuthConnectionId, userId, authConnection, socialLoginEmail, refreshToken, revokeToken, accessToken, metadataAccessToken, } = params;
|
|
@@ -535,16 +536,18 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
535
536
|
* @description Unlock the controller with the latest global password.
|
|
536
537
|
*
|
|
537
538
|
* @param params - The parameters for unlocking the controller.
|
|
539
|
+
* @param params.maxKeyChainLength - The maximum chain length of the pwd encryption keys.
|
|
538
540
|
* @param params.globalPassword - The latest global password.
|
|
539
541
|
* @returns A promise that resolves to the success of the operation.
|
|
540
542
|
*/
|
|
541
|
-
async submitGlobalPassword({ globalPassword, }) {
|
|
543
|
+
async submitGlobalPassword({ globalPassword, maxKeyChainLength = 5, }) {
|
|
542
544
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
543
545
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, async () => {
|
|
544
546
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
545
547
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_submitGlobalPassword).call(this, {
|
|
546
548
|
targetAuthPubKey: currentDeviceAuthPubKey,
|
|
547
549
|
globalPassword,
|
|
550
|
+
maxKeyChainLength,
|
|
548
551
|
});
|
|
549
552
|
}, 'submitGlobalPassword');
|
|
550
553
|
});
|
|
@@ -698,6 +701,11 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
698
701
|
// check if the token is expired
|
|
699
702
|
return decodedToken.exp < Date.now() / 1000;
|
|
700
703
|
}
|
|
704
|
+
/**
|
|
705
|
+
* Check if the current metadata access token is expired.
|
|
706
|
+
*
|
|
707
|
+
* @returns True if the metadata access token is expired, false otherwise.
|
|
708
|
+
*/
|
|
701
709
|
checkMetadataAccessTokenExpired() {
|
|
702
710
|
try {
|
|
703
711
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
@@ -710,10 +718,17 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
710
718
|
return true; // Consider unauthenticated user as having expired tokens
|
|
711
719
|
}
|
|
712
720
|
}
|
|
721
|
+
/**
|
|
722
|
+
* Check if the current access token is expired.
|
|
723
|
+
* When the vault is locked, the access token is not accessible, so we return false.
|
|
724
|
+
*
|
|
725
|
+
* @returns True if the access token is expired, false otherwise.
|
|
726
|
+
*/
|
|
713
727
|
checkAccessTokenExpired() {
|
|
714
728
|
try {
|
|
715
729
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
716
730
|
const { accessToken } = this.state;
|
|
731
|
+
console.log('checkAccessTokenExpired::accessToken', accessToken);
|
|
717
732
|
if (!accessToken) {
|
|
718
733
|
return true; // Consider missing token as expired
|
|
719
734
|
}
|
|
@@ -732,13 +747,14 @@ _SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardin
|
|
|
732
747
|
* password validity and unlock the controller.
|
|
733
748
|
*
|
|
734
749
|
* @param params - The parameters for submitting the global password.
|
|
750
|
+
* @param params.maxKeyChainLength - The maximum chain length of the pwd encryption keys.
|
|
735
751
|
* @param params.targetAuthPubKey - The target public key of the keyring
|
|
736
752
|
* encryption key to recover.
|
|
737
753
|
* @param params.globalPassword - The latest global password.
|
|
738
754
|
* @returns A promise that resolves to the keyring encryption key
|
|
739
755
|
* corresponding to the current authPubKey in state.
|
|
740
756
|
*/
|
|
741
|
-
async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPubKey, globalPassword, }) {
|
|
757
|
+
async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPubKey, globalPassword, maxKeyChainLength = 5, }) {
|
|
742
758
|
const { pwEncKey: curPwEncKey, authKeyPair: curAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
|
|
743
759
|
try {
|
|
744
760
|
// Recover vault encryption key.
|
|
@@ -746,6 +762,7 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
|
|
|
746
762
|
targetAuthPubKey,
|
|
747
763
|
curPwEncKey,
|
|
748
764
|
curAuthKeyPair,
|
|
765
|
+
maxPwChainLength: maxKeyChainLength,
|
|
749
766
|
});
|
|
750
767
|
const { pwEncKey } = res;
|
|
751
768
|
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
@@ -759,6 +776,9 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
|
|
|
759
776
|
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
|
|
760
777
|
throw error;
|
|
761
778
|
}
|
|
779
|
+
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isMaxKeyChainLengthError).call(this, error)) {
|
|
780
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.MaxKeyChainLengthExceeded);
|
|
781
|
+
}
|
|
762
782
|
throw errors_1.PasswordSyncError.getInstance(error);
|
|
763
783
|
}
|
|
764
784
|
}, _SeedlessOnboardingController_setUnlocked = function _SeedlessOnboardingController_setUnlocked() {
|
|
@@ -1295,6 +1315,12 @@ async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
|
1295
1315
|
return error.code === toprf_secure_backup_1.TOPRFErrorCode.AuthTokenExpired;
|
|
1296
1316
|
}
|
|
1297
1317
|
return false;
|
|
1318
|
+
}, _SeedlessOnboardingController_isMaxKeyChainLengthError = function _SeedlessOnboardingController_isMaxKeyChainLengthError(error) {
|
|
1319
|
+
if (error instanceof toprf_secure_backup_1.TOPRFError) {
|
|
1320
|
+
// todo: update this when the error message to error code once toprf sdk is updated.
|
|
1321
|
+
return error.message === 'Exceeded maximum password chain length';
|
|
1322
|
+
}
|
|
1323
|
+
return false;
|
|
1298
1324
|
}, _SeedlessOnboardingController_executeWithTokenRefresh =
|
|
1299
1325
|
/**
|
|
1300
1326
|
* Executes an operation with automatic token refresh on expiration.
|
|
@@ -1313,7 +1339,12 @@ async function _SeedlessOnboardingController_executeWithTokenRefresh(operation,
|
|
|
1313
1339
|
// proactively check for expired tokens and refresh them if needed
|
|
1314
1340
|
const isNodeAuthTokenExpired = this.checkNodeAuthTokenExpired();
|
|
1315
1341
|
const isMetadataAccessTokenExpired = this.checkMetadataAccessTokenExpired();
|
|
1316
|
-
|
|
1342
|
+
// access token is only accessible when the vault is unlocked
|
|
1343
|
+
// so skip the check if the vault is locked
|
|
1344
|
+
let isAccessTokenExpired = false;
|
|
1345
|
+
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_isUnlocked, "f")) {
|
|
1346
|
+
isAccessTokenExpired = this.checkAccessTokenExpired();
|
|
1347
|
+
}
|
|
1317
1348
|
if (isNodeAuthTokenExpired ||
|
|
1318
1349
|
isMetadataAccessTokenExpired ||
|
|
1319
1350
|
isAccessTokenExpired) {
|