@metamask-previews/seedless-onboarding-controller 2.5.1-preview-8a39b4da → 2.5.1-preview-a6a20717
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 +7 -4
- package/dist/SeedlessOnboardingController.cjs +59 -63
- package/dist/SeedlessOnboardingController.cjs.map +1 -1
- package/dist/SeedlessOnboardingController.d.cts +5 -4
- package/dist/SeedlessOnboardingController.d.cts.map +1 -1
- package/dist/SeedlessOnboardingController.d.mts +5 -4
- package/dist/SeedlessOnboardingController.d.mts.map +1 -1
- package/dist/SeedlessOnboardingController.mjs +58 -62
- package/dist/SeedlessOnboardingController.mjs.map +1 -1
- package/dist/assertions.cjs +32 -1
- package/dist/assertions.cjs.map +1 -1
- package/dist/assertions.d.cts +8 -1
- package/dist/assertions.d.cts.map +1 -1
- package/dist/assertions.d.mts +8 -1
- package/dist/assertions.d.mts.map +1 -1
- package/dist/assertions.mjs +30 -0
- package/dist/assertions.mjs.map +1 -1
- package/dist/index.cjs +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 +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +4 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +4 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,16 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
###
|
|
11
|
-
|
|
12
|
-
- Apply controller level lock, mutex, on the `setLocked()` call. ([#6278](https://github.com/MetaMask/core/pull/6278))
|
|
10
|
+
### Added
|
|
13
11
|
|
|
12
|
+
- Added new persisted state value, `isSeedlessOnboardingUserAuthenticated`. ([#6288](https://github.com/MetaMask/core/pull/6288))
|
|
13
|
+
- This is for the UI state in the clients, to avoid querying sensistive controller state data to determine the social login authentication state.
|
|
14
14
|
|
|
15
15
|
### Changed
|
|
16
16
|
|
|
17
|
-
- Refactor `setUnlocked` method from `createNewVaultWithAuthData` method. ([#6278](https://github.com/MetaMask/core/pull/6278))
|
|
18
17
|
- Bump `@metamask/base-controller` from `^8.0.1` to `^8.1.0` ([#6284](https://github.com/MetaMask/core/pull/6284))
|
|
19
18
|
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- Set `anonymous` to `false` for sensitive fields in the controller state. ([#6283](https://github.com/MetaMask/core/pull/6283))
|
|
22
|
+
|
|
20
23
|
## [2.5.1]
|
|
21
24
|
|
|
22
25
|
### Changed
|
|
@@ -12,7 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
};
|
|
13
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_decryptAndParseVaultData, _SeedlessOnboardingController_withPersistedSecretMetadataBackupsState, _SeedlessOnboardingController_filterDupesAndUpdateSocialBackupsMetadata, _SeedlessOnboardingController_createNewVaultWithAuthData, _SeedlessOnboardingController_updateVault, _SeedlessOnboardingController_withControllerLock, _SeedlessOnboardingController_withVaultLock, _SeedlessOnboardingController_serializeKeyData, _SeedlessOnboardingController_parseVaultData, _SeedlessOnboardingController_assertIsUnlocked, _SeedlessOnboardingController_assertIsAuthenticatedUser, _SeedlessOnboardingController_assertIsSRPBackedUpUser, _SeedlessOnboardingController_assertPasswordInSync, _SeedlessOnboardingController_resetPasswordOutdatedCache, _SeedlessOnboardingController_isTokenExpiredError, _SeedlessOnboardingController_isMaxKeyChainLengthError, _SeedlessOnboardingController_executeWithTokenRefresh;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SeedlessOnboardingController = exports.
|
|
15
|
+
exports.SeedlessOnboardingController = exports.getInitialSeedlessOnboardingControllerStateWithDefaults = void 0;
|
|
16
16
|
const auth_network_utils_1 = require("@metamask/auth-network-utils");
|
|
17
17
|
const base_controller_1 = require("@metamask/base-controller");
|
|
18
18
|
const toprf_secure_backup_1 = require("@metamask/toprf-secure-backup");
|
|
@@ -30,16 +30,28 @@ const SecretMetadata_1 = require("./SecretMetadata.cjs");
|
|
|
30
30
|
const utils_3 = require("./utils.cjs");
|
|
31
31
|
const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, constants_1.controllerName);
|
|
32
32
|
/**
|
|
33
|
-
* Get the
|
|
33
|
+
* Get the initial state for the Seedless Onboarding Controller with defaults.
|
|
34
34
|
*
|
|
35
|
-
* @
|
|
35
|
+
* @param overrides - The overrides for the initial state.
|
|
36
|
+
* @returns The initial state for the Seedless Onboarding Controller.
|
|
36
37
|
*/
|
|
37
|
-
function
|
|
38
|
-
|
|
38
|
+
function getInitialSeedlessOnboardingControllerStateWithDefaults(overrides) {
|
|
39
|
+
const initialState = {
|
|
39
40
|
socialBackupsMetadata: [],
|
|
41
|
+
isSeedlessOnboardingUserAuthenticated: false,
|
|
42
|
+
...overrides,
|
|
40
43
|
};
|
|
44
|
+
// Ensure authenticated flag is set correctly.
|
|
45
|
+
try {
|
|
46
|
+
(0, assertions_1.assertIsSeedlessOnboardingUserAuthenticated)(initialState);
|
|
47
|
+
initialState.isSeedlessOnboardingUserAuthenticated = true;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
initialState.isSeedlessOnboardingUserAuthenticated = false;
|
|
51
|
+
}
|
|
52
|
+
return initialState;
|
|
41
53
|
}
|
|
42
|
-
exports.
|
|
54
|
+
exports.getInitialSeedlessOnboardingControllerStateWithDefaults = getInitialSeedlessOnboardingControllerStateWithDefaults;
|
|
43
55
|
/**
|
|
44
56
|
* Seedless Onboarding Controller State Metadata.
|
|
45
57
|
*
|
|
@@ -54,11 +66,11 @@ const seedlessOnboardingMetadata = {
|
|
|
54
66
|
},
|
|
55
67
|
socialBackupsMetadata: {
|
|
56
68
|
persist: true,
|
|
57
|
-
anonymous:
|
|
69
|
+
anonymous: false,
|
|
58
70
|
},
|
|
59
71
|
nodeAuthTokens: {
|
|
60
72
|
persist: true,
|
|
61
|
-
anonymous:
|
|
73
|
+
anonymous: false,
|
|
62
74
|
},
|
|
63
75
|
authConnection: {
|
|
64
76
|
persist: true,
|
|
@@ -74,23 +86,23 @@ const seedlessOnboardingMetadata = {
|
|
|
74
86
|
},
|
|
75
87
|
userId: {
|
|
76
88
|
persist: true,
|
|
77
|
-
anonymous:
|
|
89
|
+
anonymous: false,
|
|
78
90
|
},
|
|
79
91
|
socialLoginEmail: {
|
|
80
92
|
persist: true,
|
|
81
|
-
anonymous:
|
|
93
|
+
anonymous: false,
|
|
82
94
|
},
|
|
83
95
|
vaultEncryptionKey: {
|
|
84
96
|
persist: false,
|
|
85
|
-
anonymous:
|
|
97
|
+
anonymous: false,
|
|
86
98
|
},
|
|
87
99
|
vaultEncryptionSalt: {
|
|
88
100
|
persist: false,
|
|
89
|
-
anonymous:
|
|
101
|
+
anonymous: false,
|
|
90
102
|
},
|
|
91
103
|
authPubKey: {
|
|
92
104
|
persist: true,
|
|
93
|
-
anonymous:
|
|
105
|
+
anonymous: false,
|
|
94
106
|
},
|
|
95
107
|
passwordOutdatedCache: {
|
|
96
108
|
persist: true,
|
|
@@ -98,28 +110,32 @@ const seedlessOnboardingMetadata = {
|
|
|
98
110
|
},
|
|
99
111
|
refreshToken: {
|
|
100
112
|
persist: true,
|
|
101
|
-
anonymous:
|
|
113
|
+
anonymous: false,
|
|
102
114
|
},
|
|
103
115
|
revokeToken: {
|
|
104
116
|
persist: false,
|
|
105
|
-
anonymous:
|
|
117
|
+
anonymous: false,
|
|
106
118
|
},
|
|
107
119
|
// stays in vault
|
|
108
120
|
accessToken: {
|
|
109
121
|
persist: false,
|
|
110
|
-
anonymous:
|
|
122
|
+
anonymous: false,
|
|
111
123
|
},
|
|
112
124
|
// stays outside of vault as this token is accessed by the metadata service
|
|
113
125
|
// before the vault is created or unlocked.
|
|
114
126
|
metadataAccessToken: {
|
|
115
127
|
persist: true,
|
|
116
|
-
anonymous:
|
|
128
|
+
anonymous: false,
|
|
117
129
|
},
|
|
118
130
|
encryptedSeedlessEncryptionKey: {
|
|
119
131
|
persist: true,
|
|
120
|
-
anonymous:
|
|
132
|
+
anonymous: false,
|
|
121
133
|
},
|
|
122
134
|
encryptedKeyringEncryptionKey: {
|
|
135
|
+
persist: true,
|
|
136
|
+
anonymous: false,
|
|
137
|
+
},
|
|
138
|
+
isSeedlessOnboardingUserAuthenticated: {
|
|
123
139
|
persist: true,
|
|
124
140
|
anonymous: true,
|
|
125
141
|
},
|
|
@@ -142,10 +158,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
142
158
|
super({
|
|
143
159
|
name: constants_1.controllerName,
|
|
144
160
|
metadata: seedlessOnboardingMetadata,
|
|
145
|
-
state:
|
|
146
|
-
...getDefaultSeedlessOnboardingControllerState(),
|
|
147
|
-
...state,
|
|
148
|
-
},
|
|
161
|
+
state: getInitialSeedlessOnboardingControllerStateWithDefaults(state),
|
|
149
162
|
messenger,
|
|
150
163
|
});
|
|
151
164
|
_SeedlessOnboardingController_instances.add(this);
|
|
@@ -176,8 +189,8 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
176
189
|
__classPrivateFieldSet(this, _SeedlessOnboardingController_revokeRefreshToken, revokeRefreshToken, "f");
|
|
177
190
|
// setup subscriptions to the keyring lock event
|
|
178
191
|
// when the keyring is locked (wallet is locked), the controller will be cleared of its credentials
|
|
179
|
-
this.messagingSystem.subscribe('KeyringController:lock',
|
|
180
|
-
|
|
192
|
+
this.messagingSystem.subscribe('KeyringController:lock', () => {
|
|
193
|
+
this.setLocked();
|
|
181
194
|
});
|
|
182
195
|
this.messagingSystem.subscribe('KeyringController:unlock', () => {
|
|
183
196
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
@@ -237,6 +250,8 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
237
250
|
state.userId = userId;
|
|
238
251
|
state.authConnection = authConnection;
|
|
239
252
|
state.socialLoginEmail = socialLoginEmail;
|
|
253
|
+
state.metadataAccessToken = metadataAccessToken;
|
|
254
|
+
state.accessToken = accessToken;
|
|
240
255
|
if (refreshToken) {
|
|
241
256
|
state.refreshToken = refreshToken;
|
|
242
257
|
}
|
|
@@ -244,12 +259,10 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
244
259
|
// Temporarily store revoke token in state for later vault creation
|
|
245
260
|
state.revokeToken = revokeToken;
|
|
246
261
|
}
|
|
247
|
-
if
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
state.metadataAccessToken = metadataAccessToken;
|
|
252
|
-
}
|
|
262
|
+
// we will check if the controller state is properly set with the authenticated user info
|
|
263
|
+
// before setting the isSeedlessOnboardingUserAuthenticated to true
|
|
264
|
+
(0, assertions_1.assertIsSeedlessOnboardingUserAuthenticated)(state);
|
|
265
|
+
state.isSeedlessOnboardingUserAuthenticated = true;
|
|
253
266
|
});
|
|
254
267
|
return authenticationResult;
|
|
255
268
|
}
|
|
@@ -302,7 +315,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
302
315
|
rawToprfPwEncryptionKey: pwEncKey,
|
|
303
316
|
rawToprfAuthKeyPair: authKeyPair,
|
|
304
317
|
});
|
|
305
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
306
318
|
};
|
|
307
319
|
await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, performKeyCreationAndBackup, 'createToprfKeyAndBackupSeedPhrase');
|
|
308
320
|
});
|
|
@@ -377,7 +389,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
377
389
|
rawToprfPwEncryptionKey: pwEncKey,
|
|
378
390
|
rawToprfAuthKeyPair: authKeyPair,
|
|
379
391
|
});
|
|
380
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
381
392
|
}
|
|
382
393
|
return secrets;
|
|
383
394
|
};
|
|
@@ -504,16 +515,14 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
504
515
|
*
|
|
505
516
|
* When the controller is locked, the user will not be able to perform any operations on the controller/vault.
|
|
506
517
|
*/
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
delete state.accessToken;
|
|
514
|
-
});
|
|
515
|
-
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
518
|
+
setLocked() {
|
|
519
|
+
this.update((state) => {
|
|
520
|
+
delete state.vaultEncryptionKey;
|
|
521
|
+
delete state.vaultEncryptionSalt;
|
|
522
|
+
delete state.revokeToken;
|
|
523
|
+
delete state.accessToken;
|
|
516
524
|
});
|
|
525
|
+
__classPrivateFieldSet(this, _SeedlessOnboardingController_isUnlocked, false, "f");
|
|
517
526
|
}
|
|
518
527
|
/**
|
|
519
528
|
* Sync the latest global password to the controller.
|
|
@@ -538,7 +547,6 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
538
547
|
rawToprfAuthKeyPair: authKeyPair,
|
|
539
548
|
});
|
|
540
549
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_resetPasswordOutdatedCache).call(this);
|
|
541
|
-
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
542
550
|
};
|
|
543
551
|
return await __classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_executeWithTokenRefresh).call(this, doSyncPassword, 'syncLatestGlobalPassword');
|
|
544
552
|
});
|
|
@@ -621,7 +629,7 @@ class SeedlessOnboardingController extends base_controller_1.BaseController {
|
|
|
621
629
|
* Clears the current state of the SeedlessOnboardingController.
|
|
622
630
|
*/
|
|
623
631
|
clearState() {
|
|
624
|
-
const defaultState =
|
|
632
|
+
const defaultState = getInitialSeedlessOnboardingControllerStateWithDefaults();
|
|
625
633
|
this.update(() => {
|
|
626
634
|
return defaultState;
|
|
627
635
|
});
|
|
@@ -1227,6 +1235,7 @@ async function _SeedlessOnboardingController_createNewVaultWithAuthData({ passwo
|
|
|
1227
1235
|
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_persistAuthPubKey).call(this, {
|
|
1228
1236
|
authPubKey: rawToprfAuthKeyPair.pk,
|
|
1229
1237
|
});
|
|
1238
|
+
__classPrivateFieldGet(this, _SeedlessOnboardingController_instances, "m", _SeedlessOnboardingController_setUnlocked).call(this);
|
|
1230
1239
|
}, _SeedlessOnboardingController_updateVault =
|
|
1231
1240
|
/**
|
|
1232
1241
|
* Encrypt and update the vault with the given authentication data.
|
|
@@ -1326,27 +1335,14 @@ async function _SeedlessOnboardingController_withVaultLock(callback) {
|
|
|
1326
1335
|
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.ControllerLocked);
|
|
1327
1336
|
}
|
|
1328
1337
|
}, _SeedlessOnboardingController_assertIsAuthenticatedUser = function _SeedlessOnboardingController_assertIsAuthenticatedUser(value) {
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
!('authConnectionId' in value) ||
|
|
1332
|
-
typeof value.authConnectionId !== 'string' ||
|
|
1333
|
-
!('userId' in value) ||
|
|
1334
|
-
typeof value.userId !== 'string') {
|
|
1335
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.MissingAuthUserInfo);
|
|
1336
|
-
}
|
|
1337
|
-
if (!('nodeAuthTokens' in value) ||
|
|
1338
|
-
typeof value.nodeAuthTokens !== 'object' ||
|
|
1339
|
-
!Array.isArray(value.nodeAuthTokens) ||
|
|
1340
|
-
value.nodeAuthTokens.length < 3 // At least 3 auth tokens are required for Threshold OPRF service
|
|
1341
|
-
) {
|
|
1342
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InsufficientAuthToken);
|
|
1343
|
-
}
|
|
1344
|
-
if (!('refreshToken' in value) || typeof value.refreshToken !== 'string') {
|
|
1345
|
-
throw new Error(constants_1.SeedlessOnboardingControllerErrorMessage.InvalidRefreshToken);
|
|
1338
|
+
try {
|
|
1339
|
+
(0, assertions_1.assertIsSeedlessOnboardingUserAuthenticated)(value);
|
|
1346
1340
|
}
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1341
|
+
catch (error) {
|
|
1342
|
+
this.update((state) => {
|
|
1343
|
+
state.isSeedlessOnboardingUserAuthenticated = false;
|
|
1344
|
+
});
|
|
1345
|
+
throw error;
|
|
1350
1346
|
}
|
|
1351
1347
|
}, _SeedlessOnboardingController_assertIsSRPBackedUpUser = function _SeedlessOnboardingController_assertIsSRPBackedUpUser(value) {
|
|
1352
1348
|
if (!this.state.authPubKey) {
|