@metamask-previews/seedless-onboarding-controller 2.4.0-preview-fed19434 → 2.4.0-preview-e0bc4b4b
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 -13
- package/dist/SeedlessOnboardingController.cjs +70 -133
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +14 -7
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +14 -7
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +71 -134
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/assertions.cjs +1 -16
- package/dist/assertions.cjs.map +1 -1
- package/dist/assertions.d.cts +0 -7
- package/dist/assertions.d.cts.map +1 -1
- package/dist/assertions.d.mts +0 -7
- package/dist/assertions.d.mts.map +1 -1
- package/dist/assertions.mjs +0 -14
- package/dist/assertions.mjs.map +1 -1
- package/dist/constants.cjs +1 -3
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -4
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +2 -4
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -3
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +0 -6
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +0 -6
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseController } from "@metamask/base-controller";
|
|
2
|
-
import type { SEC1EncodedPublicKey } from "@metamask/toprf-secure-backup";
|
|
3
2
|
import { ToprfSecureBackup } from "@metamask/toprf-secure-backup";
|
|
4
3
|
import type { AuthConnection } from "./constants.mjs";
|
|
5
4
|
import { controllerName, SecretType } from "./constants.mjs";
|
|
@@ -25,9 +24,8 @@ export declare class SeedlessOnboardingController<EncryptionKey> extends BaseCon
|
|
|
25
24
|
* @param options.network - The network to be used for the Seedless Onboarding flow.
|
|
26
25
|
* @param options.refreshJWTToken - A function to get a new jwt token using refresh token.
|
|
27
26
|
* @param options.revokeRefreshToken - A function to revoke the refresh token.
|
|
28
|
-
* @param options.passwordOutdatedCacheTTL - The TTL of the password outdated cache in milliseconds.,
|
|
29
27
|
*/
|
|
30
|
-
constructor({ messenger, state, encryptor, toprfKeyDeriver, network, refreshJWTToken, revokeRefreshToken,
|
|
28
|
+
constructor({ messenger, state, encryptor, toprfKeyDeriver, network, refreshJWTToken, revokeRefreshToken, }: SeedlessOnboardingControllerOptions<EncryptionKey>);
|
|
31
29
|
fetchMetadataAccessCreds(): Promise<{
|
|
32
30
|
metadataAccessToken: string;
|
|
33
31
|
}>;
|
|
@@ -154,6 +152,18 @@ export declare class SeedlessOnboardingController<EncryptionKey> extends BaseCon
|
|
|
154
152
|
* When the controller is locked, the user will not be able to perform any operations on the controller/vault.
|
|
155
153
|
*/
|
|
156
154
|
setLocked(): void;
|
|
155
|
+
/**
|
|
156
|
+
* Sync the latest global password to the controller.
|
|
157
|
+
* reset vault with latest globalPassword,
|
|
158
|
+
* persist the latest global password authPubKey
|
|
159
|
+
*
|
|
160
|
+
* @param params - The parameters for syncing the latest global password.
|
|
161
|
+
* @param params.globalPassword - The latest global password.
|
|
162
|
+
* @returns A promise that resolves to the success of the operation.
|
|
163
|
+
*/
|
|
164
|
+
syncLatestGlobalPassword({ globalPassword, }: {
|
|
165
|
+
globalPassword: string;
|
|
166
|
+
}): Promise<void>;
|
|
157
167
|
/**
|
|
158
168
|
* @description Unlock the controller with the latest global password.
|
|
159
169
|
*
|
|
@@ -162,7 +172,7 @@ export declare class SeedlessOnboardingController<EncryptionKey> extends BaseCon
|
|
|
162
172
|
* @param params.globalPassword - The latest global password.
|
|
163
173
|
* @returns A promise that resolves to the success of the operation.
|
|
164
174
|
*/
|
|
165
|
-
|
|
175
|
+
submitGlobalPassword({ globalPassword, maxKeyChainLength, }: {
|
|
166
176
|
globalPassword: string;
|
|
167
177
|
maxKeyChainLength?: number;
|
|
168
178
|
}): Promise<void>;
|
|
@@ -170,8 +180,6 @@ export declare class SeedlessOnboardingController<EncryptionKey> extends BaseCon
|
|
|
170
180
|
* @description Check if the current password is outdated compare to the global password.
|
|
171
181
|
*
|
|
172
182
|
* @param options - Optional options object.
|
|
173
|
-
* @param options.globalAuthPubKey - The global auth public key to compare with the current auth public key.
|
|
174
|
-
* If not provided, the global auth public key will be fetched from the backend.
|
|
175
183
|
* @param options.skipCache - If true, bypass the cache and force a fresh check.
|
|
176
184
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
177
185
|
* @returns A promise that resolves to true if the password is outdated, false otherwise.
|
|
@@ -179,7 +187,6 @@ export declare class SeedlessOnboardingController<EncryptionKey> extends BaseCon
|
|
|
179
187
|
checkIsPasswordOutdated(options?: {
|
|
180
188
|
skipCache?: boolean;
|
|
181
189
|
skipLock?: boolean;
|
|
182
|
-
globalAuthPubKey?: SEC1EncodedPublicKey;
|
|
183
190
|
}): Promise<boolean>;
|
|
184
191
|
/**
|
|
185
192
|
* Clears the current state of the SeedlessOnboardingController.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SeedlessOnboardingController.d.mts","sourceRoot":"","sources":["../src/SeedlessOnboardingController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,kCAAkC;
|
|
1
|
+
{"version":3,"file":"SeedlessOnboardingController.d.mts","sourceRoot":"","sources":["../src/SeedlessOnboardingController.ts"],"names":[],"mappings":"AAEA,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AAC,EACzB,cAAc,EACd,iBAAqB,GACtB,EAAE;QACD,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B,GAAG,OAAO,CAAC,IAAI,CAAC;IAiFjB;;;;;;;OAOG;IACG,uBAAuB,CAAC,OAAO,CAAC,EAAE;QACtC,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,GAAG,OAAO,CAAC,OAAO,CAAC;IAwFpB;;OAEG;IACH,UAAU;IAmDV;;;;;OAKG;IACG,yBAAyB,CAAC,oBAAoB,EAAE,MAAM;IAM5D;;;;;OAKG;IACG,wBAAwB;IAivB9B;;;;;;;OAOG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAwJxC;;;;OAIG;IACI,yBAAyB,IAAI,OAAO;IAY3C;;;;OAIG;IACI,+BAA+B,IAAI,OAAO;IAYjD;;;;;OAKG;IACI,uBAAuB,IAAI,OAAO;CAa1C"}
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_isUnlocked,
|
|
12
|
+
var _SeedlessOnboardingController_instances, _SeedlessOnboardingController_vaultEncryptor, _SeedlessOnboardingController_controllerOperationMutex, _SeedlessOnboardingController_vaultOperationMutex, _SeedlessOnboardingController_refreshJWTToken, _SeedlessOnboardingController_revokeRefreshToken, _SeedlessOnboardingController_isUnlocked, _SeedlessOnboardingController_submitGlobalPassword, _SeedlessOnboardingController_getAccessToken, _SeedlessOnboardingController_setUnlocked, _SeedlessOnboardingController_persistOprfKey, _SeedlessOnboardingController_persistAuthPubKey, _SeedlessOnboardingController_storeKeyringEncryptionKey, _SeedlessOnboardingController_loadKeyringEncryptionKey, _SeedlessOnboardingController_loadSeedlessEncryptionKey, _SeedlessOnboardingController_recoverAuthPubKey, _SeedlessOnboardingController_recoverEncKey, _SeedlessOnboardingController_fetchAllSecretDataFromMetadataStore, _SeedlessOnboardingController_changeEncryptionKey, _SeedlessOnboardingController_encryptAndStoreSecretData, _SeedlessOnboardingController_unlockVaultAndGetVaultData, _SeedlessOnboardingController_withPersistedSecretMetadataBackupsState, _SeedlessOnboardingController_filterDupesAndUpdateSocialBackupsMetadata, _SeedlessOnboardingController_createNewVaultWithAuthData, _SeedlessOnboardingController_updateVault, _SeedlessOnboardingController_withControllerLock, _SeedlessOnboardingController_withVaultLock, _SeedlessOnboardingController_serializeKeyData, _SeedlessOnboardingController_parseVaultData, _SeedlessOnboardingController_assertIsUnlocked, _SeedlessOnboardingController_assertIsAuthenticatedUser, _SeedlessOnboardingController_assertIsSRPBackedUpUser, _SeedlessOnboardingController_assertPasswordInSync, _SeedlessOnboardingController_resetPasswordOutdatedCache, _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState, _SeedlessOnboardingController_isTokenExpiredError, _SeedlessOnboardingController_isMaxKeyChainLengthError, _SeedlessOnboardingController_executeWithTokenRefresh;
|
|
13
13
|
import { keccak256AndHexify } from "@metamask/auth-network-utils";
|
|
14
14
|
import { BaseController } from "@metamask/base-controller";
|
|
15
15
|
import { ToprfSecureBackup, TOPRFErrorCode, TOPRFError } from "@metamask/toprf-secure-backup";
|
|
@@ -19,7 +19,7 @@ import { bytesToUtf8, utf8ToBytes } from "@noble/ciphers/utils";
|
|
|
19
19
|
import { managedNonce } from "@noble/ciphers/webcrypto";
|
|
20
20
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
21
21
|
import { Mutex } from "async-mutex";
|
|
22
|
-
import {
|
|
22
|
+
import { assertIsValidVaultData } from "./assertions.mjs";
|
|
23
23
|
import { controllerName, PASSWORD_OUTDATED_CACHE_TTL_MS, SecretType, SeedlessOnboardingControllerErrorMessage, Web3AuthNetwork } from "./constants.mjs";
|
|
24
24
|
import { PasswordSyncError, RecoveryError } from "./errors.mjs";
|
|
25
25
|
import { projectLogger, createModuleLogger } from "./logger.mjs";
|
|
@@ -132,9 +132,8 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
132
132
|
* @param options.network - The network to be used for the Seedless Onboarding flow.
|
|
133
133
|
* @param options.refreshJWTToken - A function to get a new jwt token using refresh token.
|
|
134
134
|
* @param options.revokeRefreshToken - A function to revoke the refresh token.
|
|
135
|
-
* @param options.passwordOutdatedCacheTTL - The TTL of the password outdated cache in milliseconds.,
|
|
136
135
|
*/
|
|
137
|
-
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken,
|
|
136
|
+
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken, }) {
|
|
138
137
|
super({
|
|
139
138
|
name: controllerName,
|
|
140
139
|
metadata: seedlessOnboardingMetadata,
|
|
@@ -156,12 +155,6 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
156
155
|
* The controller lock is synchronized with the keyring lock.
|
|
157
156
|
*/
|
|
158
157
|
_SeedlessOnboardingController_isUnlocked.set(this, false);
|
|
159
|
-
/**
|
|
160
|
-
* The TTL of the password outdated cache in milliseconds.
|
|
161
|
-
*/
|
|
162
|
-
_SeedlessOnboardingController_passwordOutdatedCacheTTL.set(this, void 0);
|
|
163
|
-
assertIsPasswordOutdatedCacheValid(passwordOutdatedCacheTTL);
|
|
164
|
-
__classPrivateFieldSet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, passwordOutdatedCacheTTL, "f");
|
|
165
158
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_vaultEncryptor, encryptor, "f");
|
|
166
159
|
this.toprfClient = new ToprfSecureBackup({
|
|
167
160
|
network,
|
|
@@ -394,7 +387,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
394
387
|
await this.verifyVaultPassword(oldPassword, {
|
|
395
388
|
skipLock: true, // skip lock since we already have the lock
|
|
396
389
|
});
|
|
397
|
-
|
|
390
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertPasswordInSync).call(this, {
|
|
398
391
|
skipCache: true,
|
|
399
392
|
skipLock: true, // skip lock since we already have the lock
|
|
400
393
|
});
|
|
@@ -408,7 +401,6 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
408
401
|
const { encKey: newEncKey, pwEncKey: newPwEncKey, authKeyPair: newAuthKeyPair, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_changeEncryptionKey).call(this, {
|
|
409
402
|
oldPassword,
|
|
410
403
|
newPassword,
|
|
411
|
-
latestKeyIndex,
|
|
412
404
|
});
|
|
413
405
|
// update and encrypt the vault with new password
|
|
414
406
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
@@ -491,26 +483,14 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
491
483
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
492
484
|
const { toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, revokeToken, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, password);
|
|
493
485
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
494
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
495
|
-
password,
|
|
496
|
-
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
497
|
-
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
498
|
-
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
499
|
-
});
|
|
500
486
|
if (revokeToken) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
509
|
-
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
510
|
-
});
|
|
511
|
-
})
|
|
512
|
-
.catch((error) => {
|
|
513
|
-
log('Error revoking refresh token', error);
|
|
487
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken);
|
|
488
|
+
// re-creating vault to persist the new revoke token
|
|
489
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
490
|
+
password,
|
|
491
|
+
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
492
|
+
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
493
|
+
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
514
494
|
});
|
|
515
495
|
}
|
|
516
496
|
});
|
|
@@ -529,6 +509,33 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
529
509
|
});
|
|
530
510
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
531
511
|
}
|
|
512
|
+
/**
|
|
513
|
+
* Sync the latest global password to the controller.
|
|
514
|
+
* reset vault with latest globalPassword,
|
|
515
|
+
* persist the latest global password authPubKey
|
|
516
|
+
*
|
|
517
|
+
* @param params - The parameters for syncing the latest global password.
|
|
518
|
+
* @param params.globalPassword - The latest global password.
|
|
519
|
+
* @returns A promise that resolves to the success of the operation.
|
|
520
|
+
*/
|
|
521
|
+
async syncLatestGlobalPassword({ globalPassword, }) {
|
|
522
|
+
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
523
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsUnlocked).call(this);
|
|
524
|
+
const doSyncPassword = async () => {
|
|
525
|
+
// update vault with latest globalPassword
|
|
526
|
+
const { encKey, pwEncKey, authKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
|
|
527
|
+
// update and encrypt the vault with new password
|
|
528
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
529
|
+
password: globalPassword,
|
|
530
|
+
rawToprfEncryptionKey: encKey,
|
|
531
|
+
rawToprfPwEncryptionKey: pwEncKey,
|
|
532
|
+
rawToprfAuthKeyPair: authKeyPair,
|
|
533
|
+
});
|
|
534
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
|
|
535
|
+
};
|
|
536
|
+
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, doSyncPassword, 'syncLatestGlobalPassword');
|
|
537
|
+
});
|
|
538
|
+
}
|
|
532
539
|
/**
|
|
533
540
|
* @description Unlock the controller with the latest global password.
|
|
534
541
|
*
|
|
@@ -537,24 +544,22 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
537
544
|
* @param params.globalPassword - The latest global password.
|
|
538
545
|
* @returns A promise that resolves to the success of the operation.
|
|
539
546
|
*/
|
|
540
|
-
async
|
|
547
|
+
async submitGlobalPassword({ globalPassword, maxKeyChainLength = 5, }) {
|
|
541
548
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_withControllerLock).call(this, async () => {
|
|
542
549
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, async () => {
|
|
543
550
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
544
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m",
|
|
551
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_submitGlobalPassword).call(this, {
|
|
545
552
|
targetAuthPubKey: currentDeviceAuthPubKey,
|
|
546
553
|
globalPassword,
|
|
547
554
|
maxKeyChainLength,
|
|
548
555
|
});
|
|
549
|
-
}, '
|
|
556
|
+
}, 'submitGlobalPassword');
|
|
550
557
|
});
|
|
551
558
|
}
|
|
552
559
|
/**
|
|
553
560
|
* @description Check if the current password is outdated compare to the global password.
|
|
554
561
|
*
|
|
555
562
|
* @param options - Optional options object.
|
|
556
|
-
* @param options.globalAuthPubKey - The global auth public key to compare with the current auth public key.
|
|
557
|
-
* If not provided, the global auth public key will be fetched from the backend.
|
|
558
563
|
* @param options.skipCache - If true, bypass the cache and force a fresh check.
|
|
559
564
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
560
565
|
* @returns A promise that resolves to true if the password is outdated, false otherwise.
|
|
@@ -569,28 +574,19 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
569
574
|
const now = Date.now();
|
|
570
575
|
const isCacheValid = passwordOutdatedCache &&
|
|
571
576
|
now - passwordOutdatedCache.timestamp <
|
|
572
|
-
|
|
577
|
+
PASSWORD_OUTDATED_CACHE_TTL_MS;
|
|
573
578
|
if (isCacheValid) {
|
|
574
579
|
return passwordOutdatedCache.isExpiredPwd;
|
|
575
580
|
}
|
|
576
581
|
}
|
|
577
582
|
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
578
583
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
groupedAuthConnectionId,
|
|
586
|
-
userId,
|
|
587
|
-
})
|
|
588
|
-
.catch((error) => {
|
|
589
|
-
log('Error fetching auth pub key', error);
|
|
590
|
-
throw new Error(SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
591
|
-
});
|
|
592
|
-
globalAuthPubKey = authPubKey;
|
|
593
|
-
}
|
|
584
|
+
const { authPubKey: globalAuthPubKey } = await this.toprfClient.fetchAuthPubKey({
|
|
585
|
+
nodeAuthTokens,
|
|
586
|
+
authConnectionId,
|
|
587
|
+
groupedAuthConnectionId,
|
|
588
|
+
userId,
|
|
589
|
+
});
|
|
594
590
|
// use noble lib to deserialize and compare curve point
|
|
595
591
|
const isExpiredPwd = !secp256k1.ProjectivePoint.fromHex(currentDeviceAuthPubKey).equals(secp256k1.ProjectivePoint.fromHex(globalAuthPubKey));
|
|
596
592
|
// Cache the result in state
|
|
@@ -719,7 +715,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
719
715
|
}
|
|
720
716
|
}
|
|
721
717
|
}
|
|
722
|
-
_SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardingController_controllerOperationMutex = new WeakMap(), _SeedlessOnboardingController_vaultOperationMutex = new WeakMap(), _SeedlessOnboardingController_refreshJWTToken = new WeakMap(), _SeedlessOnboardingController_revokeRefreshToken = new WeakMap(), _SeedlessOnboardingController_isUnlocked = new WeakMap(),
|
|
718
|
+
_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_instances = new WeakSet(), _SeedlessOnboardingController_submitGlobalPassword =
|
|
723
719
|
/**
|
|
724
720
|
* @description Submit the global password to the controller, verify the
|
|
725
721
|
* password validity and unlock the controller.
|
|
@@ -732,52 +728,32 @@ _SeedlessOnboardingController_vaultEncryptor = new WeakMap(), _SeedlessOnboardin
|
|
|
732
728
|
* @returns A promise that resolves to the keyring encryption key
|
|
733
729
|
* corresponding to the current authPubKey in state.
|
|
734
730
|
*/
|
|
735
|
-
async function
|
|
736
|
-
const { pwEncKey:
|
|
731
|
+
async function _SeedlessOnboardingController_submitGlobalPassword({ targetAuthPubKey, globalPassword, maxKeyChainLength, }) {
|
|
732
|
+
const { pwEncKey: curPwEncKey, authKeyPair: curAuthKeyPair } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, globalPassword);
|
|
737
733
|
try {
|
|
738
|
-
// Recover
|
|
739
|
-
const
|
|
734
|
+
// Recover vault encryption key.
|
|
735
|
+
const res = await this.toprfClient.recoverPwEncKey({
|
|
740
736
|
targetAuthPubKey,
|
|
741
|
-
curPwEncKey
|
|
742
|
-
curAuthKeyPair
|
|
737
|
+
curPwEncKey,
|
|
738
|
+
curAuthKeyPair,
|
|
743
739
|
maxPwChainLength: maxKeyChainLength,
|
|
744
740
|
});
|
|
745
|
-
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
]);
|
|
750
|
-
// Unlock the controller and vault
|
|
751
|
-
const { revokeToken } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
741
|
+
const { pwEncKey } = res;
|
|
742
|
+
const vaultKey = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_loadSeedlessEncryptionKey).call(this, pwEncKey);
|
|
743
|
+
// Unlock the controller
|
|
744
|
+
const { revokeToken, toprfEncryptionKey, toprfPwEncryptionKey, toprfAuthKeyPair, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, undefined, vaultKey);
|
|
752
745
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
753
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
754
|
-
password: globalPassword,
|
|
755
|
-
rawToprfEncryptionKey: latestEncKey,
|
|
756
|
-
rawToprfPwEncryptionKey: latestPwEncKey,
|
|
757
|
-
rawToprfAuthKeyPair: latestAuthKeyPair,
|
|
758
|
-
});
|
|
759
746
|
if (revokeToken) {
|
|
760
|
-
//
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
rawToprfEncryptionKey: latestEncKey,
|
|
769
|
-
rawToprfPwEncryptionKey: latestPwEncKey,
|
|
770
|
-
rawToprfAuthKeyPair: latestAuthKeyPair,
|
|
771
|
-
});
|
|
772
|
-
})
|
|
773
|
-
.catch((error) => {
|
|
774
|
-
log('Error revoking refresh token', error);
|
|
747
|
+
// revoke and recyle refresh token after unlock to keep refresh token fresh, avoid malicious use of leaked refresh token
|
|
748
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_revokeRefreshTokenAndUpdateState).call(this, revokeToken);
|
|
749
|
+
// re-creating vault to persist the new revoke token
|
|
750
|
+
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
751
|
+
password: globalPassword,
|
|
752
|
+
rawToprfEncryptionKey: toprfEncryptionKey,
|
|
753
|
+
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
|
|
754
|
+
rawToprfAuthKeyPair: toprfAuthKeyPair,
|
|
775
755
|
});
|
|
776
756
|
}
|
|
777
|
-
// restore the current keyring encryption key with the new global password
|
|
778
|
-
await this.storeKeyringEncryptionKey(keyringEncryptionKey);
|
|
779
|
-
// reset the password outdated cache after successful global password submission and state sync
|
|
780
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
|
|
781
757
|
}
|
|
782
758
|
catch (error) {
|
|
783
759
|
if (__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_isTokenExpiredError).call(this, error)) {
|
|
@@ -951,31 +927,12 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
|
|
|
951
927
|
* @param params - The function parameters.
|
|
952
928
|
* @param params.oldPassword - The old password to verify.
|
|
953
929
|
* @param params.newPassword - The new password to update.
|
|
954
|
-
* @param params.latestKeyIndex - The key index of the latest key.
|
|
955
930
|
* @returns A promise that resolves to new encryption key and authentication key pair.
|
|
956
931
|
*/
|
|
957
|
-
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword,
|
|
932
|
+
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, }) {
|
|
958
933
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
959
934
|
const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
|
|
960
|
-
|
|
961
|
-
let pwEncKey;
|
|
962
|
-
let authKeyPair;
|
|
963
|
-
let globalKeyIndex = latestKeyIndex;
|
|
964
|
-
if (!globalKeyIndex) {
|
|
965
|
-
({
|
|
966
|
-
encKey,
|
|
967
|
-
pwEncKey,
|
|
968
|
-
authKeyPair,
|
|
969
|
-
keyShareIndex: globalKeyIndex,
|
|
970
|
-
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword));
|
|
971
|
-
}
|
|
972
|
-
else {
|
|
973
|
-
({
|
|
974
|
-
toprfEncryptionKey: encKey,
|
|
975
|
-
toprfPwEncryptionKey: pwEncKey,
|
|
976
|
-
toprfAuthKeyPair: authKeyPair,
|
|
977
|
-
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, oldPassword));
|
|
978
|
-
}
|
|
935
|
+
const { encKey, pwEncKey, authKeyPair, keyShareIndex: newKeyShareIndex, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword);
|
|
979
936
|
const result = await this.toprfClient.changeEncKey({
|
|
980
937
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
981
938
|
authConnectionId,
|
|
@@ -984,7 +941,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
984
941
|
oldEncKey: encKey,
|
|
985
942
|
oldPwEncKey: pwEncKey,
|
|
986
943
|
oldAuthKeyPair: authKeyPair,
|
|
987
|
-
newKeyShareIndex
|
|
944
|
+
newKeyShareIndex,
|
|
988
945
|
newPassword,
|
|
989
946
|
});
|
|
990
947
|
return result;
|
|
@@ -1326,33 +1283,13 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1326
1283
|
* @param options - The options for asserting the password is in sync.
|
|
1327
1284
|
* @param options.skipCache - Whether to skip the cache check.
|
|
1328
1285
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
1329
|
-
* @returns The global auth public key and the latest key index.
|
|
1330
1286
|
* @throws If the password is outdated.
|
|
1331
1287
|
*/
|
|
1332
1288
|
async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
1333
|
-
const
|
|
1334
|
-
if (!nodeAuthTokens || !authConnectionId || !userId) {
|
|
1335
|
-
throw new Error(SeedlessOnboardingControllerErrorMessage.MissingAuthUserInfo);
|
|
1336
|
-
}
|
|
1337
|
-
const { authPubKey, keyIndex: latestKeyIndex } = await this.toprfClient
|
|
1338
|
-
.fetchAuthPubKey({
|
|
1339
|
-
nodeAuthTokens,
|
|
1340
|
-
authConnectionId,
|
|
1341
|
-
groupedAuthConnectionId,
|
|
1342
|
-
userId,
|
|
1343
|
-
})
|
|
1344
|
-
.catch((error) => {
|
|
1345
|
-
log('Error fetching auth pub key', error);
|
|
1346
|
-
throw new Error(SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
1347
|
-
});
|
|
1348
|
-
const isPasswordOutdated = await this.checkIsPasswordOutdated({
|
|
1349
|
-
...options,
|
|
1350
|
-
globalAuthPubKey: authPubKey,
|
|
1351
|
-
});
|
|
1289
|
+
const isPasswordOutdated = await this.checkIsPasswordOutdated(options);
|
|
1352
1290
|
if (isPasswordOutdated) {
|
|
1353
1291
|
throw new Error(SeedlessOnboardingControllerErrorMessage.OutdatedPassword);
|
|
1354
1292
|
}
|
|
1355
|
-
return { authPubKey, latestKeyIndex };
|
|
1356
1293
|
}, _SeedlessOnboardingController_resetPasswordOutdatedCache = function _SeedlessOnboardingController_resetPasswordOutdatedCache() {
|
|
1357
1294
|
this.update((state) => {
|
|
1358
1295
|
delete state.passwordOutdatedCache;
|