@metamask-previews/seedless-onboarding-controller 2.4.0-preview-e0bc4b4b → 2.4.0-preview-9b5151c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/SeedlessOnboardingController.cjs +73 -15
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +6 -1
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +6 -1
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +74 -16
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/assertions.cjs +16 -1
- package/dist/assertions.cjs.map +1 -1
- package/dist/assertions.d.cts +7 -0
- package/dist/assertions.d.cts.map +1 -1
- package/dist/assertions.d.mts +7 -0
- package/dist/assertions.d.mts.map +1 -1
- package/dist/assertions.mjs +14 -0
- package/dist/assertions.mjs.map +1 -1
- package/dist/constants.cjs +3 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +4 -2
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +4 -2
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +3 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +6 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -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, _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;
|
|
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_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 { assertIsValidVaultData } from "./assertions.mjs";
|
|
22
|
+
import { assertIsPasswordOutdatedCacheValid, 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,8 +132,9 @@ 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.,
|
|
135
136
|
*/
|
|
136
|
-
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken, }) {
|
|
137
|
+
constructor({ messenger, state, encryptor, toprfKeyDeriver, network = Web3AuthNetwork.Mainnet, refreshJWTToken, revokeRefreshToken, passwordOutdatedCacheTTL = PASSWORD_OUTDATED_CACHE_TTL_MS, }) {
|
|
137
138
|
super({
|
|
138
139
|
name: controllerName,
|
|
139
140
|
metadata: seedlessOnboardingMetadata,
|
|
@@ -155,6 +156,12 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
155
156
|
* The controller lock is synchronized with the keyring lock.
|
|
156
157
|
*/
|
|
157
158
|
_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");
|
|
158
165
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_vaultEncryptor, encryptor, "f");
|
|
159
166
|
this.toprfClient = new ToprfSecureBackup({
|
|
160
167
|
network,
|
|
@@ -387,7 +394,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
387
394
|
await this.verifyVaultPassword(oldPassword, {
|
|
388
395
|
skipLock: true, // skip lock since we already have the lock
|
|
389
396
|
});
|
|
390
|
-
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertPasswordInSync).call(this, {
|
|
397
|
+
const { latestKeyIndex } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertPasswordInSync).call(this, {
|
|
391
398
|
skipCache: true,
|
|
392
399
|
skipLock: true, // skip lock since we already have the lock
|
|
393
400
|
});
|
|
@@ -401,6 +408,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
401
408
|
const { encKey: newEncKey, pwEncKey: newPwEncKey, authKeyPair: newAuthKeyPair, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_changeEncryptionKey).call(this, {
|
|
402
409
|
oldPassword,
|
|
403
410
|
newPassword,
|
|
411
|
+
latestKeyIndex,
|
|
404
412
|
});
|
|
405
413
|
// update and encrypt the vault with new password
|
|
406
414
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_createNewVaultWithAuthData).call(this, {
|
|
@@ -560,6 +568,8 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
560
568
|
* @description Check if the current password is outdated compare to the global password.
|
|
561
569
|
*
|
|
562
570
|
* @param options - Optional options object.
|
|
571
|
+
* @param options.globalAuthPubKey - The global auth public key to compare with the current auth public key.
|
|
572
|
+
* If not provided, the global auth public key will be fetched from the backend.
|
|
563
573
|
* @param options.skipCache - If true, bypass the cache and force a fresh check.
|
|
564
574
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
565
575
|
* @returns A promise that resolves to true if the password is outdated, false otherwise.
|
|
@@ -574,19 +584,28 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
574
584
|
const now = Date.now();
|
|
575
585
|
const isCacheValid = passwordOutdatedCache &&
|
|
576
586
|
now - passwordOutdatedCache.timestamp <
|
|
577
|
-
|
|
587
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_passwordOutdatedCacheTTL, "f");
|
|
578
588
|
if (isCacheValid) {
|
|
579
589
|
return passwordOutdatedCache.isExpiredPwd;
|
|
580
590
|
}
|
|
581
591
|
}
|
|
582
592
|
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
583
593
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
594
|
+
let globalAuthPubKey = options?.globalAuthPubKey;
|
|
595
|
+
if (!globalAuthPubKey) {
|
|
596
|
+
const { authPubKey } = await this.toprfClient
|
|
597
|
+
.fetchAuthPubKey({
|
|
598
|
+
nodeAuthTokens,
|
|
599
|
+
authConnectionId,
|
|
600
|
+
groupedAuthConnectionId,
|
|
601
|
+
userId,
|
|
602
|
+
})
|
|
603
|
+
.catch((error) => {
|
|
604
|
+
log('Error fetching auth pub key', error);
|
|
605
|
+
throw new Error(SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
606
|
+
});
|
|
607
|
+
globalAuthPubKey = authPubKey;
|
|
608
|
+
}
|
|
590
609
|
// use noble lib to deserialize and compare curve point
|
|
591
610
|
const isExpiredPwd = !secp256k1.ProjectivePoint.fromHex(currentDeviceAuthPubKey).equals(secp256k1.ProjectivePoint.fromHex(globalAuthPubKey));
|
|
592
611
|
// Cache the result in state
|
|
@@ -715,7 +734,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
715
734
|
}
|
|
716
735
|
}
|
|
717
736
|
}
|
|
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 =
|
|
737
|
+
_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 =
|
|
719
738
|
/**
|
|
720
739
|
* @description Submit the global password to the controller, verify the
|
|
721
740
|
* password validity and unlock the controller.
|
|
@@ -927,12 +946,31 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
|
|
|
927
946
|
* @param params - The function parameters.
|
|
928
947
|
* @param params.oldPassword - The old password to verify.
|
|
929
948
|
* @param params.newPassword - The new password to update.
|
|
949
|
+
* @param params.latestKeyIndex - The key index of the latest key.
|
|
930
950
|
* @returns A promise that resolves to new encryption key and authentication key pair.
|
|
931
951
|
*/
|
|
932
|
-
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, }) {
|
|
952
|
+
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, latestKeyIndex, }) {
|
|
933
953
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
934
954
|
const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
|
|
935
|
-
|
|
955
|
+
let encKey;
|
|
956
|
+
let pwEncKey;
|
|
957
|
+
let authKeyPair;
|
|
958
|
+
let globalKeyIndex = latestKeyIndex;
|
|
959
|
+
if (!globalKeyIndex) {
|
|
960
|
+
({
|
|
961
|
+
encKey,
|
|
962
|
+
pwEncKey,
|
|
963
|
+
authKeyPair,
|
|
964
|
+
keyShareIndex: globalKeyIndex,
|
|
965
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword));
|
|
966
|
+
}
|
|
967
|
+
else {
|
|
968
|
+
({
|
|
969
|
+
toprfEncryptionKey: encKey,
|
|
970
|
+
toprfPwEncryptionKey: pwEncKey,
|
|
971
|
+
toprfAuthKeyPair: authKeyPair,
|
|
972
|
+
} = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_unlockVaultAndGetVaultData).call(this, oldPassword));
|
|
973
|
+
}
|
|
936
974
|
const result = await this.toprfClient.changeEncKey({
|
|
937
975
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
938
976
|
authConnectionId,
|
|
@@ -941,7 +979,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
941
979
|
oldEncKey: encKey,
|
|
942
980
|
oldPwEncKey: pwEncKey,
|
|
943
981
|
oldAuthKeyPair: authKeyPair,
|
|
944
|
-
newKeyShareIndex,
|
|
982
|
+
newKeyShareIndex: globalKeyIndex,
|
|
945
983
|
newPassword,
|
|
946
984
|
});
|
|
947
985
|
return result;
|
|
@@ -1283,13 +1321,33 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1283
1321
|
* @param options - The options for asserting the password is in sync.
|
|
1284
1322
|
* @param options.skipCache - Whether to skip the cache check.
|
|
1285
1323
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
1324
|
+
* @returns The global auth public key and the latest key index.
|
|
1286
1325
|
* @throws If the password is outdated.
|
|
1287
1326
|
*/
|
|
1288
1327
|
async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
1289
|
-
const
|
|
1328
|
+
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
1329
|
+
if (!nodeAuthTokens || !authConnectionId || !userId) {
|
|
1330
|
+
throw new Error(SeedlessOnboardingControllerErrorMessage.MissingAuthUserInfo);
|
|
1331
|
+
}
|
|
1332
|
+
const { authPubKey, keyIndex: latestKeyIndex } = await this.toprfClient
|
|
1333
|
+
.fetchAuthPubKey({
|
|
1334
|
+
nodeAuthTokens,
|
|
1335
|
+
authConnectionId,
|
|
1336
|
+
groupedAuthConnectionId,
|
|
1337
|
+
userId,
|
|
1338
|
+
})
|
|
1339
|
+
.catch((error) => {
|
|
1340
|
+
log('Error fetching auth pub key', error);
|
|
1341
|
+
throw new Error(SeedlessOnboardingControllerErrorMessage.FailedToFetchAuthPubKey);
|
|
1342
|
+
});
|
|
1343
|
+
const isPasswordOutdated = await this.checkIsPasswordOutdated({
|
|
1344
|
+
...options,
|
|
1345
|
+
globalAuthPubKey: authPubKey,
|
|
1346
|
+
});
|
|
1290
1347
|
if (isPasswordOutdated) {
|
|
1291
1348
|
throw new Error(SeedlessOnboardingControllerErrorMessage.OutdatedPassword);
|
|
1292
1349
|
}
|
|
1350
|
+
return { authPubKey, latestKeyIndex };
|
|
1293
1351
|
}, _SeedlessOnboardingController_resetPasswordOutdatedCache = function _SeedlessOnboardingController_resetPasswordOutdatedCache() {
|
|
1294
1352
|
this.update((state) => {
|
|
1295
1353
|
delete state.passwordOutdatedCache;
|