@metamask-previews/seedless-onboarding-controller 3.0.0-preview-331bec5d → 3.0.0-preview-f3f2e8c8
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 -17
- package/dist/SeedlessOnboardingController.cjs +114 -151
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +4 -15
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +4 -15
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +116 -153
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/assertions.cjs +1 -1
- package/dist/assertions.cjs.map +1 -1
- package/dist/assertions.mjs +1 -1
- package/dist/assertions.mjs.map +1 -1
- package/dist/constants.cjs +1 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +1 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +1 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +9 -26
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +9 -26
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +1 -66
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -30
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +1 -30
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +1 -62
- package/dist/utils.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,23 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Added `renewRefreshToken` options in SeedlessOnboardingController constructor - A function to renew the refresh token and get new revoke token. ([#6275](https://github.com/MetaMask/core/pull/6275))
|
|
13
|
-
- Added `renewRefreshToken` method to renew refresh token from client ([#6275](https://github.com/MetaMask/core/pull/6275))
|
|
14
|
-
- Added `revokePendingRefreshTokens` method to revoke all pending old refresh tokens instead from client ([#6275](https://github.com/MetaMask/core/pull/6275))
|
|
15
|
-
|
|
16
|
-
### Changed
|
|
17
|
-
|
|
18
|
-
- **BREAKING:** Updated ControllerMessenger `AllowedEvents`. ([#6292](https://github.com/MetaMask/core/pull/6292))
|
|
19
|
-
- Update `setLocked()` method with `mutex` and it becomes `async` method. ([#6292](https://github.com/MetaMask/core/pull/6292))
|
|
20
|
-
- Bump `@metamask/base-controller` from `^8.1.0` to `^8.3.0` ([#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465))
|
|
21
|
-
|
|
22
|
-
### Removed
|
|
23
|
-
|
|
24
|
-
- **BREAKING:** Removed `Keyring:lock` and `Keyring:unlock` events from the controller allowed events. ([#6292](https://github.com/MetaMask/core/pull/6292))
|
|
25
|
-
- Removed `revokeRefreshToken` method ([#6275](https://github.com/MetaMask/core/pull/6275))
|
|
26
|
-
|
|
27
10
|
## [3.0.0]
|
|
28
11
|
|
|
29
12
|
### Changed
|
|
@@ -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,
|
|
13
|
+
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_decryptAndParseVaultData, _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_isTokenExpiredError, _SeedlessOnboardingController_isMaxKeyChainLengthError, _SeedlessOnboardingController_executeWithTokenRefresh;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SeedlessOnboardingController = exports.getInitialSeedlessOnboardingControllerStateWithDefaults = void 0;
|
|
16
16
|
const auth_network_utils_1 = require("@metamask/auth-network-utils");
|
|
@@ -116,10 +116,6 @@ const seedlessOnboardingMetadata = {
|
|
|
116
116
|
persist: false,
|
|
117
117
|
anonymous: false,
|
|
118
118
|
},
|
|
119
|
-
pendingToBeRevokedTokens: {
|
|
120
|
-
persist: true,
|
|
121
|
-
anonymous: false,
|
|
122
|
-
},
|
|
123
119
|
// stays in vault
|
|
124
120
|
accessToken: {
|
|
125
121
|
persist: false,
|
|
@@ -156,10 +152,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
156
152
|
* @param options.network - The network to be used for the Seedless Onboarding flow.
|
|
157
153
|
* @param options.refreshJWTToken - A function to get a new jwt token using refresh token.
|
|
158
154
|
* @param options.revokeRefreshToken - A function to revoke the refresh token.
|
|
159
|
-
* @param options.renewRefreshToken - A function to renew the refresh token and get new revoke token.
|
|
160
155
|
* @param options.passwordOutdatedCacheTTL - The TTL of the password outdated cache in milliseconds.,
|
|
161
156
|
*/
|
|
162
|
-
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = constants_1.Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken,
|
|
157
|
+
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = constants_1.Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken, passwordOutdatedCacheTTL = constants_1.PASSWORD_OUTDATED_CACHE_TTL_MS, }) {
|
|
163
158
|
super({
|
|
164
159
|
name: constants_1.controllerName,
|
|
165
160
|
metadata: seedlessOnboardingMetadata,
|
|
@@ -172,11 +167,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
172
167
|
_SeedlessOnboardingController_vaultOperationMutex.set(this, new async_mutex_1.Mutex());
|
|
173
168
|
_SeedlessOnboardingController_refreshJWTToken.set(this, void 0);
|
|
174
169
|
_SeedlessOnboardingController_revokeRefreshToken.set(this, void 0);
|
|
175
|
-
_SeedlessOnboardingController_renewRefreshToken.set(this, void 0);
|
|
176
|
-
/**
|
|
177
|
-
* The TTL of the password outdated cache in milliseconds.
|
|
178
|
-
*/
|
|
179
|
-
_SeedlessOnboardingController_passwordOutdatedCacheTTL.set(this, void 0);
|
|
180
170
|
/**
|
|
181
171
|
* Controller lock state.
|
|
182
172
|
*
|
|
@@ -184,11 +174,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
184
174
|
*/
|
|
185
175
|
_SeedlessOnboardingController_isUnlocked.set(this, false);
|
|
186
176
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* This is used to cache the decrypted vault data to avoid decrypting the vault data multiple times.
|
|
177
|
+
* The TTL of the password outdated cache in milliseconds.
|
|
190
178
|
*/
|
|
191
|
-
|
|
179
|
+
_SeedlessOnboardingController_passwordOutdatedCacheTTL.set(this, void 0);
|
|
192
180
|
(0, assertions_1.assertIsPasswordOutdatedCacheValid)(passwordOutdatedCacheTTL);
|
|
193
181
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, passwordOutdatedCacheTTL, "f");
|
|
194
182
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_vaultEncryptor, encryptor, "f");
|
|
@@ -199,7 +187,14 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
199
187
|
});
|
|
200
188
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_refreshJWTToken, refreshJWTToken, "f");
|
|
201
189
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_revokeRefreshToken, revokeRefreshToken, "f");
|
|
202
|
-
|
|
190
|
+
// setup subscriptions to the keyring lock event
|
|
191
|
+
// when the keyring is locked (wallet is locked), the controller will be cleared of its credentials
|
|
192
|
+
this.messagingSystem.subscribe('KeyringController:lock', () => {
|
|
193
|
+
this.setLocked();
|
|
194
|
+
});
|
|
195
|
+
this.messagingSystem.subscribe('KeyringController:unlock', () => {
|
|
196
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
197
|
+
});
|
|
203
198
|
}
|
|
204
199
|
async fetchMetadataAccessCreds() {
|
|
205
200
|
const { metadataAccessToken } = this.state;
|
|
@@ -511,7 +506,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
511
506
|
*/
|
|
512
507
|
async submitPassword(password) {
|
|
513
508
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
514
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
509
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
|
|
515
510
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
516
511
|
});
|
|
517
512
|
}
|
|
@@ -519,20 +514,15 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
519
514
|
* Set the controller to locked state, and deallocate the secrets (vault encryption key and salt).
|
|
520
515
|
*
|
|
521
516
|
* When the controller is locked, the user will not be able to perform any operations on the controller/vault.
|
|
522
|
-
*
|
|
523
|
-
* @returns A promise that resolves to the success of the operation.
|
|
524
517
|
*/
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
delete state.accessToken;
|
|
532
|
-
});
|
|
533
|
-
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, undefined, "f");
|
|
534
|
-
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
518
|
+
setLocked() {
|
|
519
|
+
this.update((state) => {
|
|
520
|
+
delete state.vaultEncryptionKey;
|
|
521
|
+
delete state.vaultEncryptionSalt;
|
|
522
|
+
delete state.revokeToken;
|
|
523
|
+
delete state.accessToken;
|
|
535
524
|
});
|
|
525
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
536
526
|
}
|
|
537
527
|
/**
|
|
538
528
|
* Sync the latest global password to the controller.
|
|
@@ -699,25 +689,22 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
699
689
|
}
|
|
700
690
|
}
|
|
701
691
|
/**
|
|
702
|
-
*
|
|
692
|
+
* Revoke the refresh token and get new refresh token and new revoke token
|
|
703
693
|
* and also updates the vault with the new revoke token.
|
|
704
694
|
* This method is to be called after user is authenticated.
|
|
705
695
|
*
|
|
706
696
|
* @param password - The password to encrypt the vault.
|
|
707
697
|
* @returns A Promise that resolves to void.
|
|
708
698
|
*/
|
|
709
|
-
async
|
|
699
|
+
async revokeRefreshToken(password) {
|
|
710
700
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
711
701
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
712
|
-
const {
|
|
713
|
-
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
714
|
-
password,
|
|
715
|
-
encryptionKey: vaultEncryptionKey,
|
|
716
|
-
});
|
|
702
|
+
const { vaultEncryptionKey } = this.state;
|
|
703
|
+
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password, vaultEncryptionKey);
|
|
717
704
|
if (!revokeToken) {
|
|
718
705
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
|
|
719
706
|
}
|
|
720
|
-
const { newRevokeToken, newRefreshToken } = await __classPrivateFieldGet(this,
|
|
707
|
+
const { newRevokeToken, newRefreshToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_revokeRefreshToken, "f").call(this, {
|
|
721
708
|
connection: this.state.authConnection,
|
|
722
709
|
revokeToken,
|
|
723
710
|
});
|
|
@@ -728,11 +715,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
728
715
|
// set new refresh token to persist in state
|
|
729
716
|
state.refreshToken = newRefreshToken;
|
|
730
717
|
});
|
|
731
|
-
// add the old refresh token to the list to be revoked later when possible
|
|
732
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_addRefreshTokenToRevokeList).call(this, {
|
|
733
|
-
refreshToken,
|
|
734
|
-
revokeToken,
|
|
735
|
-
});
|
|
736
718
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
737
719
|
password,
|
|
738
720
|
rawToprfEncryptionKey,
|
|
@@ -742,49 +724,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
742
724
|
}
|
|
743
725
|
});
|
|
744
726
|
}
|
|
745
|
-
/**
|
|
746
|
-
* Revoke all pending refresh tokens.
|
|
747
|
-
*
|
|
748
|
-
* This method is to be called after user is authenticated.
|
|
749
|
-
*
|
|
750
|
-
* @returns A Promise that resolves to void.
|
|
751
|
-
*/
|
|
752
|
-
async revokePendingRefreshTokens() {
|
|
753
|
-
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
754
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
755
|
-
const { pendingToBeRevokedTokens } = this.state;
|
|
756
|
-
if (!pendingToBeRevokedTokens || pendingToBeRevokedTokens.length === 0) {
|
|
757
|
-
return;
|
|
758
|
-
}
|
|
759
|
-
// revoke all pending refresh tokens in parallel
|
|
760
|
-
const promises = pendingToBeRevokedTokens.map(({ revokeToken }) => {
|
|
761
|
-
const revokePromise = async () => {
|
|
762
|
-
try {
|
|
763
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_revokeRefreshToken, "f").call(this, {
|
|
764
|
-
connection: this.state.authConnection,
|
|
765
|
-
revokeToken,
|
|
766
|
-
});
|
|
767
|
-
return revokeToken;
|
|
768
|
-
}
|
|
769
|
-
catch (error) {
|
|
770
|
-
log('Error revoking refresh token', error);
|
|
771
|
-
return null;
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
return revokePromise();
|
|
775
|
-
});
|
|
776
|
-
const result = await Promise.all(promises); // no need to do Promise.allSettled because the promise already handle try catch
|
|
777
|
-
// filter out the null values
|
|
778
|
-
const revokedTokens = result.filter((token) => token !== null);
|
|
779
|
-
if (revokedTokens.length > 0) {
|
|
780
|
-
// update the state to remove the revoked tokens once all concurrent token revoke finish
|
|
781
|
-
this.update((state) => {
|
|
782
|
-
state.pendingToBeRevokedTokens =
|
|
783
|
-
state.pendingToBeRevokedTokens?.filter((token) => !revokedTokens.includes(token.revokeToken));
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
727
|
/**
|
|
789
728
|
* Check if the current node auth token is expired.
|
|
790
729
|
*
|
|
@@ -839,7 +778,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
839
778
|
}
|
|
840
779
|
}
|
|
841
780
|
exports.SeedlessOnboardingController = SeedlessOnboardingController;
|
|
842
|
-
_SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardingController_controllerOperationMutex = new WeakMap(), _SeedlessOnboardingController_vaultOperationMutex = new WeakMap(), _SeedlessOnboardingController_refreshJWTToken = new WeakMap(), _SeedlessOnboardingController_revokeRefreshToken = new WeakMap(),
|
|
781
|
+
_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 =
|
|
843
782
|
/**
|
|
844
783
|
* @description Submit the global password to the controller, verify the
|
|
845
784
|
* password validity and unlock the controller.
|
|
@@ -865,9 +804,7 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
|
|
|
865
804
|
const { pwEncKey } = res;
|
|
866
805
|
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
867
806
|
// Unlock the controller
|
|
868
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
869
|
-
encryptionKey: vaultKey,
|
|
870
|
-
});
|
|
807
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
871
808
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
872
809
|
}
|
|
873
810
|
catch (error) {
|
|
@@ -899,10 +836,8 @@ async function _SeedlessOnboardingController_getAccessToken(password) {
|
|
|
899
836
|
if (!vault) {
|
|
900
837
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidAccessToken);
|
|
901
838
|
}
|
|
902
|
-
const {
|
|
903
|
-
|
|
904
|
-
});
|
|
905
|
-
return vaultData.accessToken;
|
|
839
|
+
const { parsedVaultData } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, password);
|
|
840
|
+
return parsedVaultData.accessToken;
|
|
906
841
|
}, _SeedlessOnboardingController_setUnlocked = function _SeedlessOnboardingController_setUnlocked() {
|
|
907
842
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, true, "f");
|
|
908
843
|
}, _SeedlessOnboardingController_persistOprfKey =
|
|
@@ -1067,7 +1002,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
1067
1002
|
toprfEncryptionKey: encKey,
|
|
1068
1003
|
toprfPwEncryptionKey: pwEncKey,
|
|
1069
1004
|
toprfAuthKeyPair: authKeyPair,
|
|
1070
|
-
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
1005
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, oldPassword));
|
|
1071
1006
|
}
|
|
1072
1007
|
const result = await this.toprfClient.changeEncKey({
|
|
1073
1008
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
@@ -1136,9 +1071,8 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1136
1071
|
* Unlocks the encrypted vault using the provided password and returns the decrypted vault data.
|
|
1137
1072
|
* This method ensures thread-safety by using a mutex lock when accessing the vault.
|
|
1138
1073
|
*
|
|
1139
|
-
* @param
|
|
1140
|
-
* @param
|
|
1141
|
-
* @param params.encryptionKey - The optional encryption key to unlock the vault.
|
|
1074
|
+
* @param password - The optional password to unlock the vault.
|
|
1075
|
+
* @param encryptionKey - The optional encryption key to unlock the vault.
|
|
1142
1076
|
* @returns A promise that resolves to an object containing:
|
|
1143
1077
|
* - toprfEncryptionKey: The decrypted TOPRF encryption key
|
|
1144
1078
|
* - toprfAuthKeyPair: The decrypted TOPRF authentication key pair
|
|
@@ -1150,43 +1084,54 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1150
1084
|
* - The password is incorrect (from encryptor.decrypt)
|
|
1151
1085
|
* - The decrypted vault data is malformed
|
|
1152
1086
|
*/
|
|
1153
|
-
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(
|
|
1087
|
+
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(password, encryptionKey) {
|
|
1154
1088
|
return __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, async () => {
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
}
|
|
1158
|
-
const { vaultData, vaultEncryptionKey, vaultEncryptionSalt } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, params);
|
|
1089
|
+
const { parsedVaultData, vaultEncryptionKey, vaultEncryptionSalt } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, password, encryptionKey);
|
|
1090
|
+
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, revokeToken, accessToken, } = parsedVaultData;
|
|
1159
1091
|
this.update((state) => {
|
|
1160
1092
|
state.vaultEncryptionKey = vaultEncryptionKey;
|
|
1161
1093
|
state.vaultEncryptionSalt = vaultEncryptionSalt;
|
|
1162
|
-
state.revokeToken =
|
|
1163
|
-
state.accessToken =
|
|
1094
|
+
state.revokeToken = revokeToken;
|
|
1095
|
+
state.accessToken = accessToken;
|
|
1164
1096
|
});
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1097
|
+
return {
|
|
1098
|
+
toprfEncryptionKey,
|
|
1099
|
+
toprfPwEncryptionKey,
|
|
1100
|
+
toprfAuthKeyPair,
|
|
1101
|
+
revokeToken,
|
|
1102
|
+
accessToken,
|
|
1103
|
+
};
|
|
1168
1104
|
});
|
|
1169
1105
|
}, _SeedlessOnboardingController_decryptAndParseVaultData =
|
|
1170
1106
|
/**
|
|
1171
1107
|
* Decrypts the vault data and parses it into a usable format.
|
|
1172
1108
|
*
|
|
1173
|
-
* @param
|
|
1174
|
-
* @param
|
|
1175
|
-
* @param params.encryptionKey - The optional encryption key to decrypt the vault.
|
|
1109
|
+
* @param password - The optional password to decrypt the vault.
|
|
1110
|
+
* @param encryptionKey - The optional encryption key to decrypt the vault.
|
|
1176
1111
|
* @returns A promise that resolves to an object containing:
|
|
1177
1112
|
*/
|
|
1178
|
-
async function _SeedlessOnboardingController_decryptAndParseVaultData(
|
|
1113
|
+
async function _SeedlessOnboardingController_decryptAndParseVaultData(password, encryptionKey) {
|
|
1179
1114
|
let { vaultEncryptionKey, vaultEncryptionSalt } = this.state;
|
|
1180
1115
|
const { vault: encryptedVault } = this.state;
|
|
1181
1116
|
if (!encryptedVault) {
|
|
1182
1117
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultError);
|
|
1183
1118
|
}
|
|
1184
|
-
if (
|
|
1185
|
-
vaultEncryptionKey =
|
|
1119
|
+
if (encryptionKey) {
|
|
1120
|
+
vaultEncryptionKey = encryptionKey;
|
|
1186
1121
|
}
|
|
1187
1122
|
let decryptedVaultData;
|
|
1188
|
-
|
|
1189
|
-
|
|
1123
|
+
if (password) {
|
|
1124
|
+
assertIsValidPassword(password);
|
|
1125
|
+
// Note that vault decryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1126
|
+
// from the password using an intentionally slow key derivation function.
|
|
1127
|
+
// We should make sure that we only call it very intentionally.
|
|
1128
|
+
const result = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithDetail(password, encryptedVault);
|
|
1129
|
+
decryptedVaultData = result.vault;
|
|
1130
|
+
vaultEncryptionKey = result.exportedKeyString;
|
|
1131
|
+
vaultEncryptionSalt = result.salt;
|
|
1132
|
+
}
|
|
1133
|
+
else {
|
|
1134
|
+
assertIsVaultEncryptionKeyDefined(vaultEncryptionKey);
|
|
1190
1135
|
const parsedEncryptedVault = JSON.parse(encryptedVault);
|
|
1191
1136
|
if (vaultEncryptionSalt &&
|
|
1192
1137
|
vaultEncryptionSalt !== parsedEncryptedVault.salt) {
|
|
@@ -1195,20 +1140,9 @@ async function _SeedlessOnboardingController_decryptAndParseVaultData(params) {
|
|
|
1195
1140
|
const key = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").importKey(vaultEncryptionKey);
|
|
1196
1141
|
decryptedVaultData = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithKey(key, parsedEncryptedVault);
|
|
1197
1142
|
}
|
|
1198
|
-
|
|
1199
|
-
// if the encryption key is not available, we will use the password to decrypt the vault
|
|
1200
|
-
assertIsValidPassword(params?.password);
|
|
1201
|
-
// Note that vault decryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1202
|
-
// from the password using an intentionally slow key derivation function.
|
|
1203
|
-
// We should make sure that we only call it very intentionally.
|
|
1204
|
-
const result = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithDetail(params.password, encryptedVault);
|
|
1205
|
-
decryptedVaultData = result.vault;
|
|
1206
|
-
vaultEncryptionKey = result.exportedKeyString;
|
|
1207
|
-
vaultEncryptionSalt = result.salt;
|
|
1208
|
-
}
|
|
1209
|
-
const vaultData = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_parseVaultData).call(this, decryptedVaultData);
|
|
1143
|
+
const parsedVaultData = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_parseVaultData).call(this, decryptedVaultData);
|
|
1210
1144
|
return {
|
|
1211
|
-
|
|
1145
|
+
parsedVaultData,
|
|
1212
1146
|
vaultEncryptionKey,
|
|
1213
1147
|
vaultEncryptionSalt,
|
|
1214
1148
|
};
|
|
@@ -1284,16 +1218,17 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
|
|
|
1284
1218
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
1285
1219
|
const { revokeToken } = this.state;
|
|
1286
1220
|
const accessToken = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_getAccessToken).call(this, password);
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
toprfEncryptionKey
|
|
1290
|
-
toprfPwEncryptionKey
|
|
1221
|
+
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair } = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_serializeKeyData).call(this, rawToprfEncryptionKey, rawToprfPwEncryptionKey, rawToprfAuthKeyPair);
|
|
1222
|
+
const serializedVaultData = JSON.stringify({
|
|
1223
|
+
toprfEncryptionKey,
|
|
1224
|
+
toprfPwEncryptionKey,
|
|
1225
|
+
toprfAuthKeyPair,
|
|
1291
1226
|
revokeToken,
|
|
1292
1227
|
accessToken,
|
|
1293
|
-
};
|
|
1228
|
+
});
|
|
1294
1229
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
1295
1230
|
password,
|
|
1296
|
-
|
|
1231
|
+
serializedVaultData,
|
|
1297
1232
|
pwEncKey: rawToprfPwEncryptionKey,
|
|
1298
1233
|
});
|
|
1299
1234
|
// update the authPubKey in the state
|
|
@@ -1307,16 +1242,13 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
|
|
|
1307
1242
|
*
|
|
1308
1243
|
* @param params - The parameters for updating the vault.
|
|
1309
1244
|
* @param params.password - The password to encrypt the vault.
|
|
1310
|
-
* @param params.
|
|
1245
|
+
* @param params.serializedVaultData - The serialized authentication data to update the vault with.
|
|
1311
1246
|
* @param params.pwEncKey - The global password encryption key.
|
|
1312
1247
|
* @returns A promise that resolves to the updated vault.
|
|
1313
1248
|
*/
|
|
1314
|
-
async function _SeedlessOnboardingController_updateVault({ password,
|
|
1249
|
+
async function _SeedlessOnboardingController_updateVault({ password, serializedVaultData, pwEncKey, }) {
|
|
1315
1250
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, async () => {
|
|
1316
1251
|
assertIsValidPassword(password);
|
|
1317
|
-
// cache the vault data to avoid decrypting the vault data multiple times
|
|
1318
|
-
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, vaultData, "f");
|
|
1319
|
-
const serializedVaultData = (0, utils_3.serializeVaultData)(vaultData);
|
|
1320
1252
|
// Note that vault encryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1321
1253
|
// from the password using an intentionally slow key derivation function.
|
|
1322
1254
|
// We should make sure that we only call it very intentionally.
|
|
@@ -1360,19 +1292,44 @@ async function _SeedlessOnboardingController_withControllerLock(callback) {
|
|
|
1360
1292
|
*/
|
|
1361
1293
|
async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
1362
1294
|
return await withLock(__classPrivateFieldGet(this, _SeedlessOnboardingController_vaultOperationMutex, "f"), callback);
|
|
1295
|
+
}, _SeedlessOnboardingController_serializeKeyData = function _SeedlessOnboardingController_serializeKeyData(encKey, pwEncKey, authKeyPair) {
|
|
1296
|
+
const b64EncodedEncKey = (0, utils_1.bytesToBase64)(encKey);
|
|
1297
|
+
const b64EncodedPwEncKey = (0, utils_1.bytesToBase64)(pwEncKey);
|
|
1298
|
+
const b64EncodedAuthKeyPair = JSON.stringify({
|
|
1299
|
+
sk: (0, utils_1.bigIntToHex)(authKeyPair.sk),
|
|
1300
|
+
pk: (0, utils_1.bytesToBase64)(authKeyPair.pk),
|
|
1301
|
+
});
|
|
1302
|
+
return {
|
|
1303
|
+
toprfEncryptionKey: b64EncodedEncKey,
|
|
1304
|
+
toprfPwEncryptionKey: b64EncodedPwEncKey,
|
|
1305
|
+
toprfAuthKeyPair: b64EncodedAuthKeyPair,
|
|
1306
|
+
};
|
|
1363
1307
|
}, _SeedlessOnboardingController_parseVaultData = function _SeedlessOnboardingController_parseVaultData(data) {
|
|
1364
1308
|
if (typeof data !== 'string') {
|
|
1365
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.
|
|
1309
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidVaultData);
|
|
1366
1310
|
}
|
|
1367
1311
|
let parsedVaultData;
|
|
1368
1312
|
try {
|
|
1369
1313
|
parsedVaultData = JSON.parse(data);
|
|
1370
1314
|
}
|
|
1371
1315
|
catch {
|
|
1372
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.
|
|
1316
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidVaultData);
|
|
1373
1317
|
}
|
|
1374
1318
|
(0, assertions_1.assertIsValidVaultData)(parsedVaultData);
|
|
1375
|
-
|
|
1319
|
+
const rawToprfEncryptionKey = (0, utils_1.base64ToBytes)(parsedVaultData.toprfEncryptionKey);
|
|
1320
|
+
const rawToprfPwEncryptionKey = (0, utils_1.base64ToBytes)(parsedVaultData.toprfPwEncryptionKey);
|
|
1321
|
+
const parsedToprfAuthKeyPair = JSON.parse(parsedVaultData.toprfAuthKeyPair);
|
|
1322
|
+
const rawToprfAuthKeyPair = {
|
|
1323
|
+
sk: BigInt(parsedToprfAuthKeyPair.sk),
|
|
1324
|
+
pk: (0, utils_1.base64ToBytes)(parsedToprfAuthKeyPair.pk),
|
|
1325
|
+
};
|
|
1326
|
+
return {
|
|
1327
|
+
toprfEncryptionKey: rawToprfEncryptionKey,
|
|
1328
|
+
toprfPwEncryptionKey: rawToprfPwEncryptionKey,
|
|
1329
|
+
toprfAuthKeyPair: rawToprfAuthKeyPair,
|
|
1330
|
+
revokeToken: parsedVaultData.revokeToken,
|
|
1331
|
+
accessToken: parsedVaultData.accessToken,
|
|
1332
|
+
};
|
|
1376
1333
|
}, _SeedlessOnboardingController_assertIsUnlocked = function _SeedlessOnboardingController_assertIsUnlocked() {
|
|
1377
1334
|
if (!__classPrivateFieldGet(this, _SeedlessOnboardingController_isUnlocked, "f")) {
|
|
1378
1335
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.ControllerLocked);
|
|
@@ -1402,8 +1359,10 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1402
1359
|
* @throws If the password is outdated.
|
|
1403
1360
|
*/
|
|
1404
1361
|
async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
1405
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
1406
1362
|
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
1363
|
+
if (!nodeAuthTokens || !authConnectionId || !userId) {
|
|
1364
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.MissingAuthUserInfo);
|
|
1365
|
+
}
|
|
1407
1366
|
const { authPubKey, keyIndex: latestKeyIndex } = await this.toprfClient
|
|
1408
1367
|
.fetchAuthPubKey({
|
|
1409
1368
|
nodeAuthTokens,
|
|
@@ -1427,13 +1386,6 @@ async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
|
1427
1386
|
this.update((state) => {
|
|
1428
1387
|
delete state.passwordOutdatedCache;
|
|
1429
1388
|
});
|
|
1430
|
-
}, _SeedlessOnboardingController_addRefreshTokenToRevokeList = function _SeedlessOnboardingController_addRefreshTokenToRevokeList({ refreshToken, revokeToken, }) {
|
|
1431
|
-
this.update((state) => {
|
|
1432
|
-
state.pendingToBeRevokedTokens = [
|
|
1433
|
-
...(state.pendingToBeRevokedTokens || []),
|
|
1434
|
-
{ refreshToken, revokeToken },
|
|
1435
|
-
];
|
|
1436
|
-
});
|
|
1437
1389
|
}, _SeedlessOnboardingController_isTokenExpiredError = function _SeedlessOnboardingController_isTokenExpiredError(error) {
|
|
1438
1390
|
if (error instanceof toprf_secure_backup_1.TOPRFError) {
|
|
1439
1391
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
@@ -1553,4 +1505,15 @@ function assertIsEncryptedSeedlessEncryptionKeySet(encryptedSeedlessEncryptionKe
|
|
|
1553
1505
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.EncryptedSeedlessEncryptionKeyNotSet);
|
|
1554
1506
|
}
|
|
1555
1507
|
}
|
|
1508
|
+
/**
|
|
1509
|
+
* Assert that the provided vault encryption key is a valid non-empty string.
|
|
1510
|
+
*
|
|
1511
|
+
* @param vaultEncryptionKey - The vault encryption key to check.
|
|
1512
|
+
* @throws If the vault encryption key is not a valid string.
|
|
1513
|
+
*/
|
|
1514
|
+
function assertIsVaultEncryptionKeyDefined(vaultEncryptionKey) {
|
|
1515
|
+
if (!vaultEncryptionKey) {
|
|
1516
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultEncryptionKeyUndefined);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1556
1519
|
//# sourceMappingURL=SeedlessOnboardingController.cjs.map
|