@metamask-previews/seedless-onboarding-controller 2.5.0-preview-3f5f144a → 2.5.0-preview-b8352c78
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 +116 -111
- 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 +118 -113
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +1 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +30 -36
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +30 -36
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +28 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +15 -0
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +15 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +26 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_isUnlocked, _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,
|
|
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_withPersistedSecretMetadataBackupsState, _SeedlessOnboardingController_filterDupesAndUpdateSocialBackupsMetadata, _SeedlessOnboardingController_updateVault, _SeedlessOnboardingController_withControllerLock, _SeedlessOnboardingController_withVaultLock, _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.getDefaultSeedlessOnboardingControllerState = void 0;
|
|
16
16
|
const auth_network_utils_1 = require("@metamask/auth-network-utils");
|
|
@@ -84,10 +84,6 @@ const seedlessOnboardingMetadata = {
|
|
|
84
84
|
persist: false,
|
|
85
85
|
anonymous: true,
|
|
86
86
|
},
|
|
87
|
-
vaultEncryptionSalt: {
|
|
88
|
-
persist: false,
|
|
89
|
-
anonymous: true,
|
|
90
|
-
},
|
|
91
87
|
authPubKey: {
|
|
92
88
|
persist: true,
|
|
93
89
|
anonymous: true,
|
|
@@ -123,6 +119,18 @@ const seedlessOnboardingMetadata = {
|
|
|
123
119
|
persist: true,
|
|
124
120
|
anonymous: true,
|
|
125
121
|
},
|
|
122
|
+
toprfEncryptionKey: {
|
|
123
|
+
persist: false,
|
|
124
|
+
anonymous: true,
|
|
125
|
+
},
|
|
126
|
+
toprfPwEncryptionKey: {
|
|
127
|
+
persist: false,
|
|
128
|
+
anonymous: true,
|
|
129
|
+
},
|
|
130
|
+
toprfAuthKeyPair: {
|
|
131
|
+
persist: false,
|
|
132
|
+
anonymous: true,
|
|
133
|
+
},
|
|
126
134
|
};
|
|
127
135
|
class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
128
136
|
/**
|
|
@@ -296,7 +304,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
296
304
|
// to have an account but with no associated data.
|
|
297
305
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistOprfKey).call(this, oprfKey, authKeyPair.pk);
|
|
298
306
|
// create a new vault with the resulting authentication data
|
|
299
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m",
|
|
307
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
300
308
|
password,
|
|
301
309
|
rawToprfEncryptionKey: encKey,
|
|
302
310
|
rawToprfPwEncryptionKey: pwEncKey,
|
|
@@ -317,20 +325,22 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
317
325
|
*/
|
|
318
326
|
async addNewSecretData(data, type, options) {
|
|
319
327
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
320
|
-
|
|
328
|
+
// assert that the controller is unlocked before adding new secret data
|
|
329
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this, this.state);
|
|
330
|
+
// get the TOPRF encryption key and authentication key pair from the state
|
|
331
|
+
const { toprfEncryptionKey, toprfAuthKeyPair } = this.state;
|
|
332
|
+
// assert that the password is in sync with the encryption key
|
|
321
333
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertPasswordInSync).call(this, {
|
|
322
334
|
skipCache: true,
|
|
323
335
|
skipLock: true, // skip lock since we already have the lock
|
|
324
336
|
});
|
|
325
337
|
const performBackup = async () => {
|
|
326
|
-
// verify the password and unlock the vault
|
|
327
|
-
const { toprfEncryptionKey, toprfAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this);
|
|
328
338
|
// encrypt and store the secret data
|
|
329
339
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_encryptAndStoreSecretData).call(this, {
|
|
330
340
|
data,
|
|
331
341
|
type,
|
|
332
|
-
encKey: toprfEncryptionKey,
|
|
333
|
-
authKeyPair: toprfAuthKeyPair,
|
|
342
|
+
encKey: (0, utils_1.base64ToBytes)(toprfEncryptionKey),
|
|
343
|
+
authKeyPair: (0, utils_3.deserializAuthKeyPair)(toprfAuthKeyPair),
|
|
334
344
|
options,
|
|
335
345
|
});
|
|
336
346
|
};
|
|
@@ -359,18 +369,17 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
359
369
|
authKeyPair = recoverEncKeyResult.authKeyPair;
|
|
360
370
|
}
|
|
361
371
|
else {
|
|
362
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this);
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
authKeyPair = keysFromVault.toprfAuthKeyPair;
|
|
372
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this, this.state);
|
|
373
|
+
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair } = this.state;
|
|
374
|
+
encKey = (0, utils_1.base64ToBytes)(toprfEncryptionKey);
|
|
375
|
+
pwEncKey = (0, utils_1.base64ToBytes)(toprfPwEncryptionKey);
|
|
376
|
+
authKeyPair = (0, utils_3.deserializAuthKeyPair)(toprfAuthKeyPair);
|
|
368
377
|
}
|
|
369
378
|
const performFetch = async () => {
|
|
370
379
|
const secrets = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_fetchAllSecretDataFromMetadataStore).call(this, encKey, authKeyPair);
|
|
371
380
|
if (password) {
|
|
372
381
|
// if password is provided, we need to create a new vault with the auth data. (supposedly the user is trying to rehydrate the wallet)
|
|
373
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m",
|
|
382
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
374
383
|
password,
|
|
375
384
|
rawToprfEncryptionKey: encKey,
|
|
376
385
|
rawToprfPwEncryptionKey: pwEncKey,
|
|
@@ -393,7 +402,8 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
393
402
|
*/
|
|
394
403
|
async changePassword(newPassword, oldPassword) {
|
|
395
404
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
396
|
-
|
|
405
|
+
// assert that the controller is unlocked before changing the password
|
|
406
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this, this.state);
|
|
397
407
|
// verify the old password of the encrypted vault
|
|
398
408
|
await this.verifyVaultPassword(oldPassword, {
|
|
399
409
|
skipLock: true, // skip lock since we already have the lock
|
|
@@ -415,7 +425,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
415
425
|
latestKeyIndex,
|
|
416
426
|
});
|
|
417
427
|
// update and encrypt the vault with new password
|
|
418
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m",
|
|
428
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
419
429
|
password: newPassword,
|
|
420
430
|
rawToprfEncryptionKey: newEncKey,
|
|
421
431
|
rawToprfPwEncryptionKey: newPwEncKey,
|
|
@@ -444,7 +454,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
444
454
|
* @param secretData.data - The secret data to update the backup metadata state.
|
|
445
455
|
*/
|
|
446
456
|
updateBackupMetadataState(secretData) {
|
|
447
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this);
|
|
457
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this, this.state);
|
|
448
458
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_filterDupesAndUpdateSocialBackupsMetadata).call(this, secretData);
|
|
449
459
|
}
|
|
450
460
|
/**
|
|
@@ -493,7 +503,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
493
503
|
*/
|
|
494
504
|
async submitPassword(password) {
|
|
495
505
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
496
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
|
|
506
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, { password });
|
|
497
507
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
498
508
|
});
|
|
499
509
|
}
|
|
@@ -505,7 +515,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
505
515
|
setLocked() {
|
|
506
516
|
this.update((state) => {
|
|
507
517
|
delete state.vaultEncryptionKey;
|
|
508
|
-
delete state.
|
|
518
|
+
delete state.toprfEncryptionKey;
|
|
519
|
+
delete state.toprfPwEncryptionKey;
|
|
520
|
+
delete state.toprfAuthKeyPair;
|
|
509
521
|
delete state.revokeToken;
|
|
510
522
|
delete state.accessToken;
|
|
511
523
|
});
|
|
@@ -522,12 +534,12 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
522
534
|
*/
|
|
523
535
|
async syncLatestGlobalPassword({ globalPassword, }) {
|
|
524
536
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
525
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this);
|
|
537
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this, this.state);
|
|
526
538
|
const doSyncPassword = async () => {
|
|
527
539
|
// update vault with latest globalPassword
|
|
528
540
|
const { encKey, pwEncKey, authKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
|
|
529
541
|
// update and encrypt the vault with new password
|
|
530
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m",
|
|
542
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
531
543
|
password: globalPassword,
|
|
532
544
|
rawToprfEncryptionKey: encKey,
|
|
533
545
|
rawToprfPwEncryptionKey: pwEncKey,
|
|
@@ -628,7 +640,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
628
640
|
* @param keyringEncryptionKey - The keyring encryption key.
|
|
629
641
|
*/
|
|
630
642
|
async storeKeyringEncryptionKey(keyringEncryptionKey) {
|
|
631
|
-
|
|
643
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this, this.state);
|
|
644
|
+
const { toprfPwEncryptionKey } = this.state;
|
|
645
|
+
const encKey = (0, utils_1.base64ToBytes)(toprfPwEncryptionKey);
|
|
632
646
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_storeKeyringEncryptionKey).call(this, encKey, keyringEncryptionKey);
|
|
633
647
|
}
|
|
634
648
|
/**
|
|
@@ -638,7 +652,9 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
638
652
|
* @returns The keyring encryption key.
|
|
639
653
|
*/
|
|
640
654
|
async loadKeyringEncryptionKey() {
|
|
641
|
-
|
|
655
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this, this.state);
|
|
656
|
+
const { toprfPwEncryptionKey } = this.state;
|
|
657
|
+
const encKey = (0, utils_1.base64ToBytes)(toprfPwEncryptionKey);
|
|
642
658
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadKeyringEncryptionKey).call(this, encKey);
|
|
643
659
|
}
|
|
644
660
|
/**
|
|
@@ -687,7 +703,10 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
687
703
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
688
704
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
689
705
|
const { vaultEncryptionKey } = this.state;
|
|
690
|
-
const { toprfEncryptionKey: rawToprfEncryptionKey, toprfPwEncryptionKey: rawToprfPwEncryptionKey, toprfAuthKeyPair: rawToprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
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
|
+
});
|
|
691
710
|
if (!revokeToken) {
|
|
692
711
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRevokeToken);
|
|
693
712
|
}
|
|
@@ -701,7 +720,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
701
720
|
// set new refresh token to persist in state
|
|
702
721
|
state.refreshToken = newRefreshToken;
|
|
703
722
|
});
|
|
704
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m",
|
|
723
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
705
724
|
password,
|
|
706
725
|
rawToprfEncryptionKey,
|
|
707
726
|
rawToprfPwEncryptionKey,
|
|
@@ -789,7 +808,9 @@ async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPu
|
|
|
789
808
|
const { pwEncKey } = res;
|
|
790
809
|
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
791
810
|
// Unlock the controller
|
|
792
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
811
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, {
|
|
812
|
+
encryptionKey: vaultKey,
|
|
813
|
+
});
|
|
793
814
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
794
815
|
}
|
|
795
816
|
catch (error) {
|
|
@@ -821,7 +842,10 @@ async function _SeedlessOnboardingController_getAccessToken(password) {
|
|
|
821
842
|
if (!vault) {
|
|
822
843
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidAccessToken);
|
|
823
844
|
}
|
|
824
|
-
const { accessToken: accessTokenFromVault } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this,
|
|
845
|
+
const { accessToken: accessTokenFromVault } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, {
|
|
846
|
+
password,
|
|
847
|
+
skipVaultMutexLock: true,
|
|
848
|
+
});
|
|
825
849
|
return accessTokenFromVault;
|
|
826
850
|
}, _SeedlessOnboardingController_setUnlocked = function _SeedlessOnboardingController_setUnlocked() {
|
|
827
851
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, true, "f");
|
|
@@ -940,7 +964,6 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
|
|
|
940
964
|
});
|
|
941
965
|
}
|
|
942
966
|
catch (error) {
|
|
943
|
-
log('Error fetching secret data', error);
|
|
944
967
|
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
|
|
945
968
|
throw error;
|
|
946
969
|
}
|
|
@@ -983,11 +1006,12 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
983
1006
|
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword));
|
|
984
1007
|
}
|
|
985
1008
|
else {
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1009
|
+
// get the TOPRF encryption key and authentication key pair from the state
|
|
1010
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this, this.state);
|
|
1011
|
+
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair } = this.state;
|
|
1012
|
+
encKey = (0, utils_1.base64ToBytes)(toprfEncryptionKey);
|
|
1013
|
+
pwEncKey = (0, utils_1.base64ToBytes)(toprfPwEncryptionKey);
|
|
1014
|
+
authKeyPair = (0, utils_3.deserializAuthKeyPair)(toprfAuthKeyPair);
|
|
991
1015
|
}
|
|
992
1016
|
const result = await this.toprfClient.changeEncKey({
|
|
993
1017
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
@@ -1056,8 +1080,10 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1056
1080
|
* Unlocks the encrypted vault using the provided password and returns the decrypted vault data.
|
|
1057
1081
|
* This method ensures thread-safety by using a mutex lock when accessing the vault.
|
|
1058
1082
|
*
|
|
1059
|
-
* @param
|
|
1060
|
-
* @param
|
|
1083
|
+
* @param params - The parameters for unlocking the vault.
|
|
1084
|
+
* @param params.password - The optional password to unlock the vault.
|
|
1085
|
+
* @param params.encryptionKey - The optional encryption key to unlock the vault.
|
|
1086
|
+
* @param params.skipVaultMutexLock - Whether to skip the vault mutex lock.
|
|
1061
1087
|
* @returns A promise that resolves to an object containing:
|
|
1062
1088
|
* - toprfEncryptionKey: The decrypted TOPRF encryption key
|
|
1063
1089
|
* - toprfAuthKeyPair: The decrypted TOPRF authentication key pair
|
|
@@ -1069,44 +1095,40 @@ async function _SeedlessOnboardingController_encryptAndStoreSecretData(params) {
|
|
|
1069
1095
|
* - The password is incorrect (from encryptor.decrypt)
|
|
1070
1096
|
* - The decrypted vault data is malformed
|
|
1071
1097
|
*/
|
|
1072
|
-
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(
|
|
1073
|
-
|
|
1098
|
+
async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(params) {
|
|
1099
|
+
const doUnlockVaultAndGetVaultData = async () => {
|
|
1074
1100
|
let { vaultEncryptionKey } = this.state;
|
|
1075
|
-
const { vault: encryptedVault
|
|
1101
|
+
const { vault: encryptedVault } = this.state;
|
|
1076
1102
|
if (!encryptedVault) {
|
|
1077
1103
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultError);
|
|
1078
1104
|
}
|
|
1079
|
-
if (encryptionKey) {
|
|
1080
|
-
vaultEncryptionKey = encryptionKey;
|
|
1105
|
+
if (params?.encryptionKey) {
|
|
1106
|
+
vaultEncryptionKey = params.encryptionKey;
|
|
1081
1107
|
}
|
|
1082
1108
|
let decryptedVaultData;
|
|
1083
1109
|
const updatedState = {};
|
|
1084
|
-
if (password) {
|
|
1085
|
-
assertIsValidPassword(password);
|
|
1110
|
+
if (params?.password) {
|
|
1111
|
+
assertIsValidPassword(params.password);
|
|
1086
1112
|
// Note that vault decryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1087
1113
|
// from the password using an intentionally slow key derivation function.
|
|
1088
1114
|
// We should make sure that we only call it very intentionally.
|
|
1089
|
-
const result = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithDetail(password, encryptedVault);
|
|
1115
|
+
const result = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithDetail(params.password, encryptedVault);
|
|
1090
1116
|
decryptedVaultData = result.vault;
|
|
1091
1117
|
updatedState.vaultEncryptionKey = result.exportedKeyString;
|
|
1092
|
-
updatedState.vaultEncryptionSalt = result.salt;
|
|
1093
1118
|
}
|
|
1094
1119
|
else {
|
|
1095
1120
|
assertIsVaultEncryptionKeyDefined(vaultEncryptionKey);
|
|
1096
1121
|
const parsedEncryptedVault = JSON.parse(encryptedVault);
|
|
1097
|
-
if (vaultEncryptionSalt &&
|
|
1098
|
-
vaultEncryptionSalt !== parsedEncryptedVault.salt) {
|
|
1099
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.ExpiredCredentials);
|
|
1100
|
-
}
|
|
1101
1122
|
const key = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").importKey(vaultEncryptionKey);
|
|
1102
1123
|
decryptedVaultData = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").decryptWithKey(key, parsedEncryptedVault);
|
|
1103
1124
|
updatedState.vaultEncryptionKey = vaultEncryptionKey;
|
|
1104
|
-
updatedState.vaultEncryptionSalt = vaultEncryptionSalt;
|
|
1105
1125
|
}
|
|
1106
1126
|
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, revokeToken, accessToken, } = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_parseVaultData).call(this, decryptedVaultData);
|
|
1107
1127
|
this.update((state) => {
|
|
1108
1128
|
state.vaultEncryptionKey = updatedState.vaultEncryptionKey;
|
|
1109
|
-
state.
|
|
1129
|
+
state.toprfEncryptionKey = (0, utils_1.bytesToBase64)(toprfEncryptionKey);
|
|
1130
|
+
state.toprfPwEncryptionKey = (0, utils_1.bytesToBase64)(toprfPwEncryptionKey);
|
|
1131
|
+
state.toprfAuthKeyPair = (0, utils_3.serializeAuthKeyPair)(toprfAuthKeyPair);
|
|
1110
1132
|
state.revokeToken = revokeToken;
|
|
1111
1133
|
state.accessToken = accessToken;
|
|
1112
1134
|
});
|
|
@@ -1117,7 +1139,10 @@ async function _SeedlessOnboardingController_unlockVaultAndGetVaultData(password
|
|
|
1117
1139
|
revokeToken,
|
|
1118
1140
|
accessToken,
|
|
1119
1141
|
};
|
|
1120
|
-
}
|
|
1142
|
+
};
|
|
1143
|
+
return params?.skipVaultMutexLock
|
|
1144
|
+
? doUnlockVaultAndGetVaultData()
|
|
1145
|
+
: __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, doUnlockVaultAndGetVaultData);
|
|
1121
1146
|
}, _SeedlessOnboardingController_withPersistedSecretMetadataBackupsState =
|
|
1122
1147
|
/**
|
|
1123
1148
|
* Executes a callback function that creates or restores secret data and persists their hashes in the controller state.
|
|
@@ -1174,65 +1199,54 @@ async function _SeedlessOnboardingController_withPersistedSecretMetadataBackupsS
|
|
|
1174
1199
|
];
|
|
1175
1200
|
});
|
|
1176
1201
|
}
|
|
1177
|
-
}, _SeedlessOnboardingController_createNewVaultWithAuthData =
|
|
1178
|
-
/**
|
|
1179
|
-
* Create a new vault with the given authentication data.
|
|
1180
|
-
*
|
|
1181
|
-
* Serialize the authentication and key data which will be stored in the vault.
|
|
1182
|
-
*
|
|
1183
|
-
* @param params - The parameters for creating a new vault.
|
|
1184
|
-
* @param params.password - The password to encrypt the vault.
|
|
1185
|
-
* @param params.rawToprfEncryptionKey - The encryption key to encrypt the vault.
|
|
1186
|
-
* @param params.rawToprfPwEncryptionKey - The encryption key to encrypt the password.
|
|
1187
|
-
* @param params.rawToprfAuthKeyPair - The authentication key pair to encrypt the vault.
|
|
1188
|
-
*/
|
|
1189
|
-
async function _SeedlessOnboardingController_createNewVaultWithAuthData({ password, rawToprfEncryptionKey, rawToprfPwEncryptionKey, rawToprfAuthKeyPair, }) {
|
|
1190
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
1191
|
-
const accessToken = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_getAccessToken).call(this, password);
|
|
1192
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
1193
|
-
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair } = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_serializeKeyData).call(this, rawToprfEncryptionKey, rawToprfPwEncryptionKey, rawToprfAuthKeyPair);
|
|
1194
|
-
const serializedVaultData = JSON.stringify({
|
|
1195
|
-
toprfEncryptionKey,
|
|
1196
|
-
toprfPwEncryptionKey,
|
|
1197
|
-
toprfAuthKeyPair,
|
|
1198
|
-
revokeToken: this.state.revokeToken,
|
|
1199
|
-
accessToken,
|
|
1200
|
-
});
|
|
1201
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_updateVault).call(this, {
|
|
1202
|
-
password,
|
|
1203
|
-
serializedVaultData,
|
|
1204
|
-
pwEncKey: rawToprfPwEncryptionKey,
|
|
1205
|
-
});
|
|
1206
|
-
// update the authPubKey in the state
|
|
1207
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
|
|
1208
|
-
authPubKey: rawToprfAuthKeyPair.pk,
|
|
1209
|
-
});
|
|
1210
1202
|
}, _SeedlessOnboardingController_updateVault =
|
|
1211
1203
|
/**
|
|
1212
1204
|
* Encrypt and update the vault with the given authentication data.
|
|
1213
1205
|
*
|
|
1214
1206
|
* @param params - The parameters for updating the vault.
|
|
1215
1207
|
* @param params.password - The password to encrypt the vault.
|
|
1216
|
-
* @param params.
|
|
1217
|
-
* @param params.
|
|
1208
|
+
* @param params.rawToprfEncryptionKey - The TOPRF encryption key.
|
|
1209
|
+
* @param params.rawToprfPwEncryptionKey - The TOPRF password encryption key.
|
|
1210
|
+
* @param params.rawToprfAuthKeyPair - The TOPRF authentication key pair.
|
|
1218
1211
|
* @returns A promise that resolves to the updated vault.
|
|
1219
1212
|
*/
|
|
1220
|
-
async function _SeedlessOnboardingController_updateVault({ password,
|
|
1213
|
+
async function _SeedlessOnboardingController_updateVault({ password, rawToprfEncryptionKey, rawToprfPwEncryptionKey, rawToprfAuthKeyPair, }) {
|
|
1221
1214
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withVaultLock).call(this, async () => {
|
|
1215
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
1222
1216
|
assertIsValidPassword(password);
|
|
1217
|
+
const accessToken = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_getAccessToken).call(this, password);
|
|
1218
|
+
const toprfEncryptionKey = (0, utils_1.bytesToBase64)(rawToprfEncryptionKey);
|
|
1219
|
+
const toprfPwEncryptionKey = (0, utils_1.bytesToBase64)(rawToprfPwEncryptionKey);
|
|
1220
|
+
const toprfAuthKeyPair = (0, utils_3.serializeAuthKeyPair)(rawToprfAuthKeyPair);
|
|
1221
|
+
const serializedVaultData = JSON.stringify({
|
|
1222
|
+
toprfEncryptionKey,
|
|
1223
|
+
toprfPwEncryptionKey,
|
|
1224
|
+
toprfAuthKeyPair,
|
|
1225
|
+
revokeToken: this.state.revokeToken,
|
|
1226
|
+
accessToken,
|
|
1227
|
+
});
|
|
1223
1228
|
// Note that vault encryption using the password is a very costly operation as it involves deriving the encryption key
|
|
1224
1229
|
// from the password using an intentionally slow key derivation function.
|
|
1225
1230
|
// We should make sure that we only call it very intentionally.
|
|
1226
1231
|
const { vault, exportedKeyString } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_vaultEncryptor, "f").encryptWithDetail(password, serializedVaultData);
|
|
1227
1232
|
// Encrypt vault key.
|
|
1228
|
-
const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(
|
|
1233
|
+
const aes = (0, webcrypto_1.managedNonce)(aes_1.gcm)(rawToprfPwEncryptionKey);
|
|
1229
1234
|
const encryptedKey = aes.encrypt((0, utils_2.utf8ToBytes)(exportedKeyString));
|
|
1235
|
+
// update the controller state after updating the vault
|
|
1230
1236
|
this.update((state) => {
|
|
1231
1237
|
state.vault = vault;
|
|
1232
1238
|
state.vaultEncryptionKey = exportedKeyString;
|
|
1233
|
-
state.vaultEncryptionSalt = JSON.parse(vault).salt;
|
|
1234
1239
|
state.encryptedSeedlessEncryptionKey = (0, utils_1.bytesToBase64)(encryptedKey);
|
|
1240
|
+
state.toprfEncryptionKey = toprfEncryptionKey;
|
|
1241
|
+
state.toprfPwEncryptionKey = toprfPwEncryptionKey;
|
|
1242
|
+
state.toprfAuthKeyPair = toprfAuthKeyPair;
|
|
1243
|
+
});
|
|
1244
|
+
// update the authPubKey in the state
|
|
1245
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
|
|
1246
|
+
authPubKey: rawToprfAuthKeyPair.pk,
|
|
1235
1247
|
});
|
|
1248
|
+
// unlock the controller
|
|
1249
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
1236
1250
|
});
|
|
1237
1251
|
}, _SeedlessOnboardingController_withControllerLock =
|
|
1238
1252
|
/**
|
|
@@ -1263,18 +1277,6 @@ async function _SeedlessOnboardingController_withControllerLock(callback) {
|
|
|
1263
1277
|
*/
|
|
1264
1278
|
async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
1265
1279
|
return await withLock(__classPrivateFieldGet(this, _SeedlessOnboardingController_vaultOperationMutex, "f"), callback);
|
|
1266
|
-
}, _SeedlessOnboardingController_serializeKeyData = function _SeedlessOnboardingController_serializeKeyData(encKey, pwEncKey, authKeyPair) {
|
|
1267
|
-
const b64EncodedEncKey = (0, utils_1.bytesToBase64)(encKey);
|
|
1268
|
-
const b64EncodedPwEncKey = (0, utils_1.bytesToBase64)(pwEncKey);
|
|
1269
|
-
const b64EncodedAuthKeyPair = JSON.stringify({
|
|
1270
|
-
sk: (0, utils_1.bigIntToHex)(authKeyPair.sk),
|
|
1271
|
-
pk: (0, utils_1.bytesToBase64)(authKeyPair.pk),
|
|
1272
|
-
});
|
|
1273
|
-
return {
|
|
1274
|
-
toprfEncryptionKey: b64EncodedEncKey,
|
|
1275
|
-
toprfPwEncryptionKey: b64EncodedPwEncKey,
|
|
1276
|
-
toprfAuthKeyPair: b64EncodedAuthKeyPair,
|
|
1277
|
-
};
|
|
1278
1280
|
}, _SeedlessOnboardingController_parseVaultData = function _SeedlessOnboardingController_parseVaultData(data) {
|
|
1279
1281
|
if (typeof data !== 'string') {
|
|
1280
1282
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidVaultData);
|
|
@@ -1289,11 +1291,7 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1289
1291
|
(0, assertions_1.assertIsValidVaultData)(parsedVaultData);
|
|
1290
1292
|
const rawToprfEncryptionKey = (0, utils_1.base64ToBytes)(parsedVaultData.toprfEncryptionKey);
|
|
1291
1293
|
const rawToprfPwEncryptionKey = (0, utils_1.base64ToBytes)(parsedVaultData.toprfPwEncryptionKey);
|
|
1292
|
-
const
|
|
1293
|
-
const rawToprfAuthKeyPair = {
|
|
1294
|
-
sk: BigInt(parsedToprfAuthKeyPair.sk),
|
|
1295
|
-
pk: (0, utils_1.base64ToBytes)(parsedToprfAuthKeyPair.pk),
|
|
1296
|
-
};
|
|
1294
|
+
const rawToprfAuthKeyPair = (0, utils_3.deserializAuthKeyPair)(parsedVaultData.toprfAuthKeyPair);
|
|
1297
1295
|
return {
|
|
1298
1296
|
toprfEncryptionKey: rawToprfEncryptionKey,
|
|
1299
1297
|
toprfPwEncryptionKey: rawToprfPwEncryptionKey,
|
|
@@ -1301,10 +1299,17 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1301
1299
|
revokeToken: parsedVaultData.revokeToken,
|
|
1302
1300
|
accessToken: parsedVaultData.accessToken,
|
|
1303
1301
|
};
|
|
1304
|
-
}, _SeedlessOnboardingController_assertIsUnlocked = function _SeedlessOnboardingController_assertIsUnlocked() {
|
|
1302
|
+
}, _SeedlessOnboardingController_assertIsUnlocked = function _SeedlessOnboardingController_assertIsUnlocked(value) {
|
|
1305
1303
|
if (!__classPrivateFieldGet(this, _SeedlessOnboardingController_isUnlocked, "f")) {
|
|
1306
1304
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.ControllerLocked);
|
|
1307
1305
|
}
|
|
1306
|
+
if (!value ||
|
|
1307
|
+
typeof value !== 'object' ||
|
|
1308
|
+
!('toprfEncryptionKey' in value) ||
|
|
1309
|
+
!('toprfPwEncryptionKey' in value) ||
|
|
1310
|
+
!('toprfAuthKeyPair' in value)) {
|
|
1311
|
+
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.VaultLocked);
|
|
1312
|
+
}
|
|
1308
1313
|
}, _SeedlessOnboardingController_assertIsAuthenticatedUser = function _SeedlessOnboardingController_assertIsAuthenticatedUser(value) {
|
|
1309
1314
|
if (!value ||
|
|
1310
1315
|
typeof value !== 'object' ||
|