@metamask-previews/seedless-onboarding-controller 3.0.0-preview-0b2bfc8a → 3.0.0-preview-e821953d
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 +91 -72
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +93 -74
- 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 +7 -9
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +7 -9
- 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 +1 -1
|
@@ -9,11 +9,11 @@ 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,
|
|
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_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;
|
|
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";
|
|
16
|
-
import { base64ToBytes, bytesToBase64 } from "@metamask/utils";
|
|
16
|
+
import { base64ToBytes, bytesToBase64, bigIntToHex } from "@metamask/utils";
|
|
17
17
|
import { gcm } from "@noble/ciphers/aes";
|
|
18
18
|
import { bytesToUtf8, utf8ToBytes } from "@noble/ciphers/utils";
|
|
19
19
|
import { managedNonce } from "@noble/ciphers/webcrypto";
|
|
@@ -24,7 +24,7 @@ import { controllerName, PASSWORD_OUTDATED_CACHE_TTL_MS, SecretType, SeedlessOnb
|
|
|
24
24
|
import { PasswordSyncError, RecoveryError } from "./errors.mjs";
|
|
25
25
|
import { projectLogger, createModuleLogger } from "./logger.mjs";
|
|
26
26
|
import { SecretMetadata } from "./SecretMetadata.mjs";
|
|
27
|
-
import { decodeJWTToken, decodeNodeAuthToken
|
|
27
|
+
import { decodeJWTToken, decodeNodeAuthToken } from "./utils.mjs";
|
|
28
28
|
const log = createModuleLogger(projectLogger, controllerName);
|
|
29
29
|
/**
|
|
30
30
|
* Get the initial state for the Seedless Onboarding Controller with defaults.
|
|
@@ -163,10 +163,6 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
163
163
|
_SeedlessOnboardingController_vaultOperationMutex.set(this, new Mutex());
|
|
164
164
|
_SeedlessOnboardingController_refreshJWTToken.set(this, void 0);
|
|
165
165
|
_SeedlessOnboardingController_revokeRefreshToken.set(this, void 0);
|
|
166
|
-
/**
|
|
167
|
-
* The TTL of the password outdated cache in milliseconds.
|
|
168
|
-
*/
|
|
169
|
-
_SeedlessOnboardingController_passwordOutdatedCacheTTL.set(this, void 0);
|
|
170
166
|
/**
|
|
171
167
|
* Controller lock state.
|
|
172
168
|
*
|
|
@@ -174,11 +170,9 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
174
170
|
*/
|
|
175
171
|
_SeedlessOnboardingController_isUnlocked.set(this, false);
|
|
176
172
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* This is used to cache the decrypted vault data to avoid decrypting the vault data multiple times.
|
|
173
|
+
* The TTL of the password outdated cache in milliseconds.
|
|
180
174
|
*/
|
|
181
|
-
|
|
175
|
+
_SeedlessOnboardingController_passwordOutdatedCacheTTL.set(this, void 0);
|
|
182
176
|
assertIsPasswordOutdatedCacheValid(passwordOutdatedCacheTTL);
|
|
183
177
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, passwordOutdatedCacheTTL, "f");
|
|
184
178
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_vaultEncryptor, encryptor, "f");
|
|
@@ -508,7 +502,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
508
502
|
*/
|
|
509
503
|
async submitPassword(password) {
|
|
510
504
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
511
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
505
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
|
|
512
506
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
513
507
|
});
|
|
514
508
|
}
|
|
@@ -524,7 +518,6 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
524
518
|
delete state.revokeToken;
|
|
525
519
|
delete state.accessToken;
|
|
526
520
|
});
|
|
527
|
-
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, undefined, "f");
|
|
528
521
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
529
522
|
}
|
|
530
523
|
/**
|
|
@@ -703,10 +696,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
703
696
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
704
697
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
705
698
|
const { vaultEncryptionKey } = this.state;
|
|
706
|
-
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
707
|
-
password,
|
|
708
|
-
encryptionKey: vaultEncryptionKey,
|
|
709
|
-
});
|
|
699
|
+
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password, vaultEncryptionKey);
|
|
710
700
|
if (!revokeToken) {
|
|
711
701
|
throw new Error(SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
|
|
712
702
|
}
|
|
@@ -783,7 +773,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
783
773
|
}
|
|
784
774
|
}
|
|
785
775
|
}
|
|
786
|
-
_SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardingController_controllerOperationMutex = new WeakMap(), _SeedlessOnboardingController_vaultOperationMutex = new WeakMap(), _SeedlessOnboardingController_refreshJWTToken = new WeakMap(), _SeedlessOnboardingController_revokeRefreshToken = new WeakMap(),
|
|
776
|
+
_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 =
|
|
787
777
|
/**
|
|
788
778
|
* @description Submit the global password to the controller, verify the
|
|
789
779
|
* password validity and unlock the controller.
|
|
@@ -809,9 +799,7 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
|
|
|
809
799
|
const { pwEncKey } = res;
|
|
810
800
|
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
811
801
|
// Unlock the controller
|
|
812
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
813
|
-
encryptionKey: vaultKey,
|
|
814
|
-
});
|
|
802
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
815
803
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
816
804
|
}
|
|
817
805
|
catch (error) {
|
|
@@ -843,10 +831,8 @@ async function _SeedlessOnboardingController_getAccessToken(password) {
|
|
|
843
831
|
if (!vault) {
|
|
844
832
|
throw new Error(SeedlessOnboardingControllerErrorMessage.InvalidAccessToken);
|
|
845
833
|
}
|
|
846
|
-
const {
|
|
847
|
-
|
|
848
|
-
});
|
|
849
|
-
return vaultData.accessToken;
|
|
834
|
+
const { parsedVaultData } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, password);
|
|
835
|
+
return parsedVaultData.accessToken;
|
|
850
836
|
}, _SeedlessOnboardingController_setUnlocked = function _SeedlessOnboardingController_setUnlocked() {
|
|
851
837
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, true, "f");
|
|
852
838
|
}, _SeedlessOnboardingController_persistOprfKey =
|
|
@@ -1011,7 +997,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
1011
997
|
toprfEncryptionKey: encKey,
|
|
1012
998
|
toprfPwEncryptionKey: pwEncKey,
|
|
1013
999
|
toprfAuthKeyPair: authKeyPair,
|
|
1014
|
-
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
1000
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, oldPassword));
|
|
1015
1001
|
}
|
|
1016
1002
|
const result = await this.toprfClient.changeEncKey({
|
|
1017
1003
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
@@ -1080,9 +1066,8 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1080
1066
|
* Unlocks the encrypted vault using the provided password and returns the decrypted vault data.
|
|
1081
1067
|
* This method ensures thread-safety by using a mutex lock when accessing the vault.
|
|
1082
1068
|
*
|
|
1083
|
-
* @param
|
|
1084
|
-
* @param
|
|
1085
|
-
* @param params.encryptionKey - The optional encryption key to unlock the vault.
|
|
1069
|
+
* @param password - The optional password to unlock the vault.
|
|
1070
|
+
* @param encryptionKey - The optional encryption key to unlock the vault.
|
|
1086
1071
|
* @returns A promise that resolves to an object containing:
|
|
1087
1072
|
* - toprfEncryptionKey: The decrypted TOPRF encryption key
|
|
1088
1073
|
* - toprfAuthKeyPair: The decrypted TOPRF authentication key pair
|
|
@@ -1094,43 +1079,54 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1094
1079
|
* - The password is incorrect (from encryptor.decrypt)
|
|
1095
1080
|
* - The decrypted vault data is malformed
|
|
1096
1081
|
*/
|
|
1097
|
-
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(
|
|
1082
|
+
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(password, encryptionKey) {
|
|
1098
1083
|
return __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, async () => {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
}
|
|
1102
|
-
const { vaultData, vaultEncryptionKey, vaultEncryptionSalt } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, params);
|
|
1084
|
+
const { parsedVaultData, vaultEncryptionKey, vaultEncryptionSalt } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_decryptAndParseVaultData).call(this, password, encryptionKey);
|
|
1085
|
+
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, revokeToken, accessToken, } = parsedVaultData;
|
|
1103
1086
|
this.update((state) => {
|
|
1104
1087
|
state.vaultEncryptionKey = vaultEncryptionKey;
|
|
1105
1088
|
state.vaultEncryptionSalt = vaultEncryptionSalt;
|
|
1106
|
-
state.revokeToken =
|
|
1107
|
-
state.accessToken =
|
|
1089
|
+
state.revokeToken = revokeToken;
|
|
1090
|
+
state.accessToken = accessToken;
|
|
1108
1091
|
});
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1092
|
+
return {
|
|
1093
|
+
toprfEncryptionKey,
|
|
1094
|
+
toprfPwEncryptionKey,
|
|
1095
|
+
toprfAuthKeyPair,
|
|
1096
|
+
revokeToken,
|
|
1097
|
+
accessToken,
|
|
1098
|
+
};
|
|
1112
1099
|
});
|
|
1113
1100
|
}, _SeedlessOnboardingController_decryptAndParseVaultData =
|
|
1114
1101
|
/**
|
|
1115
1102
|
* Decrypts the vault data and parses it into a usable format.
|
|
1116
1103
|
*
|
|
1117
|
-
* @param
|
|
1118
|
-
* @param
|
|
1119
|
-
* @param params.encryptionKey - The optional encryption key to decrypt the vault.
|
|
1104
|
+
* @param password - The optional password to decrypt the vault.
|
|
1105
|
+
* @param encryptionKey - The optional encryption key to decrypt the vault.
|
|
1120
1106
|
* @returns A promise that resolves to an object containing:
|
|
1121
1107
|
*/
|
|
1122
|
-
async function _SeedlessOnboardingController_decryptAndParseVaultData(
|
|
1108
|
+
async function _SeedlessOnboardingController_decryptAndParseVaultData(password, encryptionKey) {
|
|
1123
1109
|
let { vaultEncryptionKey, vaultEncryptionSalt } = this.state;
|
|
1124
1110
|
const { vault: encryptedVault } = this.state;
|
|
1125
1111
|
if (!encryptedVault) {
|
|
1126
1112
|
throw new Error(SeedlessOnboardingControllerErrorMessage.VaultError);
|
|
1127
1113
|
}
|
|
1128
|
-
if (
|
|
1129
|
-
vaultEncryptionKey =
|
|
1114
|
+
if (encryptionKey) {
|
|
1115
|
+
vaultEncryptionKey = encryptionKey;
|
|
1130
1116
|
}
|
|
1131
1117
|
let decryptedVaultData;
|
|
1132
|
-
|
|
1133
|
-
|
|
1118
|
+
if (password) {
|
|
1119
|
+
assertIsValidPassword(password);
|
|
1120
|
+
// Note that vault decryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1121
|
+
// from the password using an intentionally slow key derivation function.
|
|
1122
|
+
// We should make sure that we only call it very intentionally.
|
|
1123
|
+
const result = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithDetail(password, encryptedVault);
|
|
1124
|
+
decryptedVaultData = result.vault;
|
|
1125
|
+
vaultEncryptionKey = result.exportedKeyString;
|
|
1126
|
+
vaultEncryptionSalt = result.salt;
|
|
1127
|
+
}
|
|
1128
|
+
else {
|
|
1129
|
+
assertIsVaultEncryptionKeyDefined(vaultEncryptionKey);
|
|
1134
1130
|
const parsedEncryptedVault = JSON.parse(encryptedVault);
|
|
1135
1131
|
if (vaultEncryptionSalt &&
|
|
1136
1132
|
vaultEncryptionSalt !== parsedEncryptedVault.salt) {
|
|
@@ -1139,20 +1135,9 @@ async function _SeedlessOnboardingController_decryptAndParseVaultData(params) {
|
|
|
1139
1135
|
const key = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").importKey(vaultEncryptionKey);
|
|
1140
1136
|
decryptedVaultData = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithKey(key, parsedEncryptedVault);
|
|
1141
1137
|
}
|
|
1142
|
-
|
|
1143
|
-
// if the encryption key is not available, we will use the password to decrypt the vault
|
|
1144
|
-
assertIsValidPassword(params?.password);
|
|
1145
|
-
// Note that vault decryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1146
|
-
// from the password using an intentionally slow key derivation function.
|
|
1147
|
-
// We should make sure that we only call it very intentionally.
|
|
1148
|
-
const result = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithDetail(params.password, encryptedVault);
|
|
1149
|
-
decryptedVaultData = result.vault;
|
|
1150
|
-
vaultEncryptionKey = result.exportedKeyString;
|
|
1151
|
-
vaultEncryptionSalt = result.salt;
|
|
1152
|
-
}
|
|
1153
|
-
const vaultData = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_parseVaultData).call(this, decryptedVaultData);
|
|
1138
|
+
const parsedVaultData = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_parseVaultData).call(this, decryptedVaultData);
|
|
1154
1139
|
return {
|
|
1155
|
-
|
|
1140
|
+
parsedVaultData,
|
|
1156
1141
|
vaultEncryptionKey,
|
|
1157
1142
|
vaultEncryptionSalt,
|
|
1158
1143
|
};
|
|
@@ -1228,16 +1213,17 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
|
|
|
1228
1213
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
1229
1214
|
const { revokeToken } = this.state;
|
|
1230
1215
|
const accessToken = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_getAccessToken).call(this, password);
|
|
1231
|
-
const
|
|
1232
|
-
|
|
1233
|
-
toprfEncryptionKey
|
|
1234
|
-
toprfPwEncryptionKey
|
|
1216
|
+
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair } = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_serializeKeyData).call(this, rawToprfEncryptionKey, rawToprfPwEncryptionKey, rawToprfAuthKeyPair);
|
|
1217
|
+
const serializedVaultData = JSON.stringify({
|
|
1218
|
+
toprfEncryptionKey,
|
|
1219
|
+
toprfPwEncryptionKey,
|
|
1220
|
+
toprfAuthKeyPair,
|
|
1235
1221
|
revokeToken,
|
|
1236
1222
|
accessToken,
|
|
1237
|
-
};
|
|
1223
|
+
});
|
|
1238
1224
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
1239
1225
|
password,
|
|
1240
|
-
|
|
1226
|
+
serializedVaultData,
|
|
1241
1227
|
pwEncKey: rawToprfPwEncryptionKey,
|
|
1242
1228
|
});
|
|
1243
1229
|
// update the authPubKey in the state
|
|
@@ -1251,16 +1237,13 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
|
|
|
1251
1237
|
*
|
|
1252
1238
|
* @param params - The parameters for updating the vault.
|
|
1253
1239
|
* @param params.password - The password to encrypt the vault.
|
|
1254
|
-
* @param params.
|
|
1240
|
+
* @param params.serializedVaultData - The serialized authentication data to update the vault with.
|
|
1255
1241
|
* @param params.pwEncKey - The global password encryption key.
|
|
1256
1242
|
* @returns A promise that resolves to the updated vault.
|
|
1257
1243
|
*/
|
|
1258
|
-
async function _SeedlessOnboardingController_updateVault({ password,
|
|
1244
|
+
async function _SeedlessOnboardingController_updateVault({ password, serializedVaultData, pwEncKey, }) {
|
|
1259
1245
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, async () => {
|
|
1260
1246
|
assertIsValidPassword(password);
|
|
1261
|
-
// cache the vault data to avoid decrypting the vault data multiple times
|
|
1262
|
-
__classPrivateFieldSet(this, _SeedlessOnboardingController_cachedDecryptedVaultData, vaultData, "f");
|
|
1263
|
-
const serializedVaultData = serializeVaultData(vaultData);
|
|
1264
1247
|
// Note that vault encryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1265
1248
|
// from the password using an intentionally slow key derivation function.
|
|
1266
1249
|
// We should make sure that we only call it very intentionally.
|
|
@@ -1304,19 +1287,44 @@ async function _SeedlessOnboardingController_withControllerLock(callback) {
|
|
|
1304
1287
|
*/
|
|
1305
1288
|
async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
1306
1289
|
return await withLock(__classPrivateFieldGet(this, _SeedlessOnboardingController_vaultOperationMutex, "f"), callback);
|
|
1290
|
+
}, _SeedlessOnboardingController_serializeKeyData = function _SeedlessOnboardingController_serializeKeyData(encKey, pwEncKey, authKeyPair) {
|
|
1291
|
+
const b64EncodedEncKey = bytesToBase64(encKey);
|
|
1292
|
+
const b64EncodedPwEncKey = bytesToBase64(pwEncKey);
|
|
1293
|
+
const b64EncodedAuthKeyPair = JSON.stringify({
|
|
1294
|
+
sk: bigIntToHex(authKeyPair.sk),
|
|
1295
|
+
pk: bytesToBase64(authKeyPair.pk),
|
|
1296
|
+
});
|
|
1297
|
+
return {
|
|
1298
|
+
toprfEncryptionKey: b64EncodedEncKey,
|
|
1299
|
+
toprfPwEncryptionKey: b64EncodedPwEncKey,
|
|
1300
|
+
toprfAuthKeyPair: b64EncodedAuthKeyPair,
|
|
1301
|
+
};
|
|
1307
1302
|
}, _SeedlessOnboardingController_parseVaultData = function _SeedlessOnboardingController_parseVaultData(data) {
|
|
1308
1303
|
if (typeof data !== 'string') {
|
|
1309
|
-
throw new Error(SeedlessOnboardingControllerErrorMessage.
|
|
1304
|
+
throw new Error(SeedlessOnboardingControllerErrorMessage.InvalidVaultData);
|
|
1310
1305
|
}
|
|
1311
1306
|
let parsedVaultData;
|
|
1312
1307
|
try {
|
|
1313
1308
|
parsedVaultData = JSON.parse(data);
|
|
1314
1309
|
}
|
|
1315
1310
|
catch {
|
|
1316
|
-
throw new Error(SeedlessOnboardingControllerErrorMessage.
|
|
1311
|
+
throw new Error(SeedlessOnboardingControllerErrorMessage.InvalidVaultData);
|
|
1317
1312
|
}
|
|
1318
1313
|
assertIsValidVaultData(parsedVaultData);
|
|
1319
|
-
|
|
1314
|
+
const rawToprfEncryptionKey = base64ToBytes(parsedVaultData.toprfEncryptionKey);
|
|
1315
|
+
const rawToprfPwEncryptionKey = base64ToBytes(parsedVaultData.toprfPwEncryptionKey);
|
|
1316
|
+
const parsedToprfAuthKeyPair = JSON.parse(parsedVaultData.toprfAuthKeyPair);
|
|
1317
|
+
const rawToprfAuthKeyPair = {
|
|
1318
|
+
sk: BigInt(parsedToprfAuthKeyPair.sk),
|
|
1319
|
+
pk: base64ToBytes(parsedToprfAuthKeyPair.pk),
|
|
1320
|
+
};
|
|
1321
|
+
return {
|
|
1322
|
+
toprfEncryptionKey: rawToprfEncryptionKey,
|
|
1323
|
+
toprfPwEncryptionKey: rawToprfPwEncryptionKey,
|
|
1324
|
+
toprfAuthKeyPair: rawToprfAuthKeyPair,
|
|
1325
|
+
revokeToken: parsedVaultData.revokeToken,
|
|
1326
|
+
accessToken: parsedVaultData.accessToken,
|
|
1327
|
+
};
|
|
1320
1328
|
}, _SeedlessOnboardingController_assertIsUnlocked = function _SeedlessOnboardingController_assertIsUnlocked() {
|
|
1321
1329
|
if (!__classPrivateFieldGet(this, _SeedlessOnboardingController_isUnlocked, "f")) {
|
|
1322
1330
|
throw new Error(SeedlessOnboardingControllerErrorMessage.ControllerLocked);
|
|
@@ -1492,4 +1500,15 @@ function assertIsEncryptedSeedlessEncryptionKeySet(encryptedSeedlessEncryptionKe
|
|
|
1492
1500
|
throw new Error(SeedlessOnboardingControllerErrorMessage.EncryptedSeedlessEncryptionKeyNotSet);
|
|
1493
1501
|
}
|
|
1494
1502
|
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Assert that the provided vault encryption key is a valid non-empty string.
|
|
1505
|
+
*
|
|
1506
|
+
* @param vaultEncryptionKey - The vault encryption key to check.
|
|
1507
|
+
* @throws If the vault encryption key is not a valid string.
|
|
1508
|
+
*/
|
|
1509
|
+
function assertIsVaultEncryptionKeyDefined(vaultEncryptionKey) {
|
|
1510
|
+
if (!vaultEncryptionKey) {
|
|
1511
|
+
throw new Error(SeedlessOnboardingControllerErrorMessage.VaultEncryptionKeyUndefined);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1495
1514
|
//# sourceMappingURL=SeedlessOnboardingController.mjs.map
|