@metamask-previews/seedless-onboarding-controller 2.4.0-preview-ed2a2e6 → 2.4.0-preview-b3ea3f86
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 -4
- package/dist/SeedlessOnboardingController.cjs +15 -73
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +1 -6
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +1 -6
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +16 -74
- 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
|
@@ -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, {
|
|
@@ -568,8 +560,6 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
568
560
|
* @description Check if the current password is outdated compare to the global password.
|
|
569
561
|
*
|
|
570
562
|
* @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.
|
|
573
563
|
* @param options.skipCache - If true, bypass the cache and force a fresh check.
|
|
574
564
|
* @param options.skipLock - Whether to skip the lock acquisition. (to prevent deadlock in case the caller already acquired the lock)
|
|
575
565
|
* @returns A promise that resolves to true if the password is outdated, false otherwise.
|
|
@@ -584,28 +574,19 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
584
574
|
const now = Date.now();
|
|
585
575
|
const isCacheValid = passwordOutdatedCache &&
|
|
586
576
|
now - passwordOutdatedCache.timestamp <
|
|
587
|
-
|
|
577
|
+
PASSWORD_OUTDATED_CACHE_TTL_MS;
|
|
588
578
|
if (isCacheValid) {
|
|
589
579
|
return passwordOutdatedCache.isExpiredPwd;
|
|
590
580
|
}
|
|
591
581
|
}
|
|
592
582
|
const { nodeAuthTokens, authConnectionId, groupedAuthConnectionId, userId, } = this.state;
|
|
593
583
|
const currentDeviceAuthPubKey = __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverAuthPubKey).call(this);
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
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
|
-
}
|
|
584
|
+
const { authPubKey: globalAuthPubKey } = await this.toprfClient.fetchAuthPubKey({
|
|
585
|
+
nodeAuthTokens,
|
|
586
|
+
authConnectionId,
|
|
587
|
+
groupedAuthConnectionId,
|
|
588
|
+
userId,
|
|
589
|
+
});
|
|
609
590
|
// use noble lib to deserialize and compare curve point
|
|
610
591
|
const isExpiredPwd = !secp256k1.ProjectivePoint.fromHex(currentDeviceAuthPubKey).equals(secp256k1.ProjectivePoint.fromHex(globalAuthPubKey));
|
|
611
592
|
// Cache the result in state
|
|
@@ -734,7 +715,7 @@ export class SeedlessOnboardingController extends BaseController {
|
|
|
734
715
|
}
|
|
735
716
|
}
|
|
736
717
|
}
|
|
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(),
|
|
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 =
|
|
738
719
|
/**
|
|
739
720
|
* @description Submit the global password to the controller, verify the
|
|
740
721
|
* password validity and unlock the controller.
|
|
@@ -946,31 +927,12 @@ async function _SeedlessOnboardingController_recoverEncKey(password) {
|
|
|
946
927
|
* @param params - The function parameters.
|
|
947
928
|
* @param params.oldPassword - The old password to verify.
|
|
948
929
|
* @param params.newPassword - The new password to update.
|
|
949
|
-
* @param params.latestKeyIndex - The key index of the latest key.
|
|
950
930
|
* @returns A promise that resolves to new encryption key and authentication key pair.
|
|
951
931
|
*/
|
|
952
|
-
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword,
|
|
932
|
+
async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword, newPassword, }) {
|
|
953
933
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_assertIsAuthenticatedUser).call(this, this.state);
|
|
954
934
|
const { authConnectionId, groupedAuthConnectionId, userId } = this.state;
|
|
955
|
-
|
|
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
|
-
}
|
|
935
|
+
const { encKey, pwEncKey, authKeyPair, keyShareIndex: newKeyShareIndex, } = await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_recoverEncKey).call(this, oldPassword);
|
|
974
936
|
const result = await this.toprfClient.changeEncKey({
|
|
975
937
|
nodeAuthTokens: this.state.nodeAuthTokens,
|
|
976
938
|
authConnectionId,
|
|
@@ -979,7 +941,7 @@ async function _SeedlessOnboardingController_changeEncryptionKey({ oldPassword,
|
|
|
979
941
|
oldEncKey: encKey,
|
|
980
942
|
oldPwEncKey: pwEncKey,
|
|
981
943
|
oldAuthKeyPair: authKeyPair,
|
|
982
|
-
newKeyShareIndex
|
|
944
|
+
newKeyShareIndex,
|
|
983
945
|
newPassword,
|
|
984
946
|
});
|
|
985
947
|
return result;
|
|
@@ -1321,33 +1283,13 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1321
1283
|
* @param options - The options for asserting the password is in sync.
|
|
1322
1284
|
* @param options.skipCache - Whether to skip the cache check.
|
|
1323
1285
|
* @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.
|
|
1325
1286
|
* @throws If the password is outdated.
|
|
1326
1287
|
*/
|
|
1327
1288
|
async function _SeedlessOnboardingController_assertPasswordInSync(options) {
|
|
1328
|
-
const
|
|
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
|
-
});
|
|
1289
|
+
const isPasswordOutdated = await this.checkIsPasswordOutdated(options);
|
|
1347
1290
|
if (isPasswordOutdated) {
|
|
1348
1291
|
throw new Error(SeedlessOnboardingControllerErrorMessage.OutdatedPassword);
|
|
1349
1292
|
}
|
|
1350
|
-
return { authPubKey, latestKeyIndex };
|
|
1351
1293
|
}, _SeedlessOnboardingController_resetPasswordOutdatedCache = function _SeedlessOnboardingController_resetPasswordOutdatedCache() {
|
|
1352
1294
|
this.update((state) => {
|
|
1353
1295
|
delete state.passwordOutdatedCache;
|