Skip to content

Commit ca85082

Browse files
mikespositoGuillaumeRx
authored andcommitted
add metadata properties to SeedlessOnboardingController
1 parent 36dbd3d commit ca85082

File tree

3 files changed

+270
-2
lines changed

3 files changed

+270
-2
lines changed

packages/seedless-onboarding-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6504](https://github.com/MetaMask/core/pull/6504))
13+
1014
## [4.0.0]
1115

1216
### Added

packages/seedless-onboarding-controller/src/SeedlessOnboardingController.test.ts

Lines changed: 221 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { keccak256AndHexify } from '@metamask/auth-network-utils';
2-
import type { Messenger } from '@metamask/base-controller';
2+
import {
3+
deriveStateFromMetadata,
4+
type Messenger,
5+
} from '@metamask/base-controller';
36
import type { EncryptionKey } from '@metamask/browser-passworder';
47
import {
58
encrypt,
@@ -5432,4 +5435,221 @@ describe('SeedlessOnboardingController', () => {
54325435
);
54335436
});
54345437
});
5438+
5439+
describe('metadata', () => {
5440+
it('includes expected state in debug snapshots', async () => {
5441+
await withController(
5442+
{
5443+
state: {
5444+
accessToken: 'accessToken',
5445+
authPubKey: 'authPubKey',
5446+
authConnection: AuthConnection.Google,
5447+
authConnectionId: 'authConnectionId',
5448+
encryptedKeyringEncryptionKey: 'encryptedKeyringEncryptionKey',
5449+
encryptedSeedlessEncryptionKey: 'encryptedSeedlessEncryptionKey',
5450+
groupedAuthConnectionId: 'groupedAuthConnectionId',
5451+
isSeedlessOnboardingUserAuthenticated: true,
5452+
metadataAccessToken: 'metadataAccessToken',
5453+
nodeAuthTokens: [],
5454+
passwordOutdatedCache: {
5455+
isExpiredPwd: false,
5456+
timestamp: 1234567890,
5457+
},
5458+
refreshToken: 'refreshToken',
5459+
revokeToken: 'revokeToken',
5460+
socialBackupsMetadata: [],
5461+
socialLoginEmail: 'socialLoginEmail',
5462+
userId: 'userId',
5463+
vault: 'vault',
5464+
vaultEncryptionKey: 'vaultEncryptionKey',
5465+
vaultEncryptionSalt: 'vaultEncryptionSalt',
5466+
},
5467+
},
5468+
({ controller }) => {
5469+
expect(
5470+
deriveStateFromMetadata(
5471+
controller.state,
5472+
controller.metadata,
5473+
'anonymous',
5474+
),
5475+
).toMatchInlineSnapshot(`
5476+
Object {
5477+
"authConnection": "google",
5478+
"authConnectionId": "authConnectionId",
5479+
"groupedAuthConnectionId": "groupedAuthConnectionId",
5480+
"isSeedlessOnboardingUserAuthenticated": false,
5481+
"passwordOutdatedCache": Object {
5482+
"isExpiredPwd": false,
5483+
"timestamp": 1234567890,
5484+
},
5485+
}
5486+
`);
5487+
},
5488+
);
5489+
});
5490+
5491+
it('includes expected state in state logs', async () => {
5492+
await withController(
5493+
{
5494+
state: {
5495+
accessToken: 'accessToken',
5496+
authPubKey: 'authPubKey',
5497+
authConnection: AuthConnection.Google,
5498+
authConnectionId: 'authConnectionId',
5499+
encryptedKeyringEncryptionKey: 'encryptedKeyringEncryptionKey',
5500+
encryptedSeedlessEncryptionKey: 'encryptedSeedlessEncryptionKey',
5501+
groupedAuthConnectionId: 'groupedAuthConnectionId',
5502+
isSeedlessOnboardingUserAuthenticated: true,
5503+
metadataAccessToken: 'metadataAccessToken',
5504+
nodeAuthTokens: [],
5505+
passwordOutdatedCache: {
5506+
isExpiredPwd: false,
5507+
timestamp: 1234567890,
5508+
},
5509+
refreshToken: 'refreshToken',
5510+
revokeToken: 'revokeToken',
5511+
socialBackupsMetadata: [],
5512+
socialLoginEmail: 'socialLoginEmail',
5513+
userId: 'userId',
5514+
vault: 'vault',
5515+
vaultEncryptionKey: 'vaultEncryptionKey',
5516+
vaultEncryptionSalt: 'vaultEncryptionSalt',
5517+
},
5518+
},
5519+
({ controller }) => {
5520+
expect(
5521+
deriveStateFromMetadata(
5522+
controller.state,
5523+
controller.metadata,
5524+
'includeInStateLogs',
5525+
),
5526+
).toMatchInlineSnapshot(`
5527+
Object {
5528+
"accessToken": true,
5529+
"authConnection": "google",
5530+
"authConnectionId": "authConnectionId",
5531+
"authPubKey": "authPubKey",
5532+
"groupedAuthConnectionId": "groupedAuthConnectionId",
5533+
"isSeedlessOnboardingUserAuthenticated": false,
5534+
"metadataAccessToken": true,
5535+
"nodeAuthTokens": true,
5536+
"passwordOutdatedCache": Object {
5537+
"isExpiredPwd": false,
5538+
"timestamp": 1234567890,
5539+
},
5540+
"refreshToken": true,
5541+
"revokeToken": true,
5542+
"userId": "userId",
5543+
}
5544+
`);
5545+
},
5546+
);
5547+
});
5548+
5549+
it('persists expected state', async () => {
5550+
await withController(
5551+
{
5552+
state: {
5553+
accessToken: 'accessToken',
5554+
authPubKey: 'authPubKey',
5555+
authConnection: AuthConnection.Google,
5556+
authConnectionId: 'authConnectionId',
5557+
encryptedKeyringEncryptionKey: 'encryptedKeyringEncryptionKey',
5558+
encryptedSeedlessEncryptionKey: 'encryptedSeedlessEncryptionKey',
5559+
groupedAuthConnectionId: 'groupedAuthConnectionId',
5560+
isSeedlessOnboardingUserAuthenticated: true,
5561+
metadataAccessToken: 'metadataAccessToken',
5562+
nodeAuthTokens: [],
5563+
passwordOutdatedCache: {
5564+
isExpiredPwd: false,
5565+
timestamp: 1234567890,
5566+
},
5567+
refreshToken: 'refreshToken',
5568+
revokeToken: 'revokeToken',
5569+
socialBackupsMetadata: [],
5570+
socialLoginEmail: 'socialLoginEmail',
5571+
userId: 'userId',
5572+
vault: 'vault',
5573+
vaultEncryptionKey: 'vaultEncryptionKey',
5574+
vaultEncryptionSalt: 'vaultEncryptionSalt',
5575+
},
5576+
},
5577+
({ controller }) => {
5578+
expect(
5579+
deriveStateFromMetadata(
5580+
controller.state,
5581+
controller.metadata,
5582+
'persist',
5583+
),
5584+
).toMatchInlineSnapshot(`
5585+
Object {
5586+
"authConnection": "google",
5587+
"authConnectionId": "authConnectionId",
5588+
"authPubKey": "authPubKey",
5589+
"encryptedKeyringEncryptionKey": "encryptedKeyringEncryptionKey",
5590+
"encryptedSeedlessEncryptionKey": "encryptedSeedlessEncryptionKey",
5591+
"groupedAuthConnectionId": "groupedAuthConnectionId",
5592+
"isSeedlessOnboardingUserAuthenticated": false,
5593+
"metadataAccessToken": "metadataAccessToken",
5594+
"nodeAuthTokens": Array [],
5595+
"passwordOutdatedCache": Object {
5596+
"isExpiredPwd": false,
5597+
"timestamp": 1234567890,
5598+
},
5599+
"refreshToken": "refreshToken",
5600+
"socialBackupsMetadata": Array [],
5601+
"socialLoginEmail": "socialLoginEmail",
5602+
"userId": "userId",
5603+
"vault": "vault",
5604+
}
5605+
`);
5606+
},
5607+
);
5608+
});
5609+
5610+
it('exposes expected state to UI', async () => {
5611+
await withController(
5612+
{
5613+
state: {
5614+
accessToken: 'accessToken',
5615+
authPubKey: 'authPubKey',
5616+
authConnection: AuthConnection.Google,
5617+
authConnectionId: 'authConnectionId',
5618+
encryptedKeyringEncryptionKey: 'encryptedKeyringEncryptionKey',
5619+
encryptedSeedlessEncryptionKey: 'encryptedSeedlessEncryptionKey',
5620+
groupedAuthConnectionId: 'groupedAuthConnectionId',
5621+
isSeedlessOnboardingUserAuthenticated: true,
5622+
metadataAccessToken: 'metadataAccessToken',
5623+
nodeAuthTokens: [],
5624+
passwordOutdatedCache: {
5625+
isExpiredPwd: false,
5626+
timestamp: 1234567890,
5627+
},
5628+
refreshToken: 'refreshToken',
5629+
revokeToken: 'revokeToken',
5630+
socialBackupsMetadata: [],
5631+
socialLoginEmail: 'socialLoginEmail',
5632+
userId: 'userId',
5633+
vault: 'vault',
5634+
vaultEncryptionKey: 'vaultEncryptionKey',
5635+
vaultEncryptionSalt: 'vaultEncryptionSalt',
5636+
},
5637+
},
5638+
({ controller }) => {
5639+
expect(
5640+
deriveStateFromMetadata(
5641+
controller.state,
5642+
controller.metadata,
5643+
'usedInUi',
5644+
),
5645+
).toMatchInlineSnapshot(`
5646+
Object {
5647+
"authConnection": "google",
5648+
"socialLoginEmail": "socialLoginEmail",
5649+
}
5650+
`);
5651+
},
5652+
);
5653+
});
5654+
});
54355655
});

packages/seedless-onboarding-controller/src/SeedlessOnboardingController.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
TOPRFErrorCode,
1212
TOPRFError,
1313
} from '@metamask/toprf-secure-backup';
14-
import { base64ToBytes, bytesToBase64 } from '@metamask/utils';
14+
import {
15+
base64ToBytes,
16+
bytesToBase64,
17+
isNullOrUndefined,
18+
} from '@metamask/utils';
1519
import { gcm } from '@noble/ciphers/aes';
1620
import { bytesToUtf8, utf8ToBytes } from '@noble/ciphers/utils';
1721
import { managedNonce } from '@noble/ciphers/webcrypto';
@@ -93,87 +97,127 @@ export function getInitialSeedlessOnboardingControllerStateWithDefaults(
9397
const seedlessOnboardingMetadata: StateMetadata<SeedlessOnboardingControllerState> =
9498
{
9599
vault: {
100+
includeInStateLogs: false,
96101
persist: true,
97102
anonymous: false,
103+
usedInUi: false,
98104
},
99105
socialBackupsMetadata: {
106+
includeInStateLogs: false,
100107
persist: true,
101108
anonymous: false,
109+
usedInUi: false,
102110
},
103111
nodeAuthTokens: {
112+
includeInStateLogs: (nodeAuthTokens) =>
113+
!isNullOrUndefined(nodeAuthTokens),
104114
persist: true,
105115
anonymous: false,
116+
usedInUi: false,
106117
},
107118
authConnection: {
119+
includeInStateLogs: true,
108120
persist: true,
109121
anonymous: true,
122+
usedInUi: true,
110123
},
111124
authConnectionId: {
125+
includeInStateLogs: true,
112126
persist: true,
113127
anonymous: true,
128+
usedInUi: false,
114129
},
115130
groupedAuthConnectionId: {
131+
includeInStateLogs: true,
116132
persist: true,
117133
anonymous: true,
134+
usedInUi: false,
118135
},
119136
userId: {
137+
includeInStateLogs: true,
120138
persist: true,
121139
anonymous: false,
140+
usedInUi: false,
122141
},
123142
socialLoginEmail: {
143+
includeInStateLogs: false,
124144
persist: true,
125145
anonymous: false,
146+
usedInUi: true,
126147
},
127148
vaultEncryptionKey: {
149+
includeInStateLogs: false,
128150
persist: false,
129151
anonymous: false,
152+
usedInUi: false,
130153
},
131154
vaultEncryptionSalt: {
155+
includeInStateLogs: false,
132156
persist: false,
133157
anonymous: false,
158+
usedInUi: false,
134159
},
135160
authPubKey: {
161+
includeInStateLogs: true,
136162
persist: true,
137163
anonymous: false,
164+
usedInUi: false,
138165
},
139166
passwordOutdatedCache: {
167+
includeInStateLogs: true,
140168
persist: true,
141169
anonymous: true,
170+
usedInUi: false,
142171
},
143172
refreshToken: {
173+
includeInStateLogs: (refreshToken) => !isNullOrUndefined(refreshToken),
144174
persist: true,
145175
anonymous: false,
176+
usedInUi: false,
146177
},
147178
revokeToken: {
179+
includeInStateLogs: (revokeToken) => !isNullOrUndefined(revokeToken),
148180
persist: false,
149181
anonymous: false,
182+
usedInUi: false,
150183
},
151184
pendingToBeRevokedTokens: {
152185
persist: true,
153186
anonymous: false,
154187
},
155188
// stays in vault
156189
accessToken: {
190+
includeInStateLogs: (accessToken) => !isNullOrUndefined(accessToken),
157191
persist: false,
158192
anonymous: false,
193+
usedInUi: false,
159194
},
160195
// stays outside of vault as this token is accessed by the metadata service
161196
// before the vault is created or unlocked.
162197
metadataAccessToken: {
198+
includeInStateLogs: (metadataAccessToken) =>
199+
!isNullOrUndefined(metadataAccessToken),
163200
persist: true,
164201
anonymous: false,
202+
usedInUi: false,
165203
},
166204
encryptedSeedlessEncryptionKey: {
205+
includeInStateLogs: false,
167206
persist: true,
168207
anonymous: false,
208+
usedInUi: false,
169209
},
170210
encryptedKeyringEncryptionKey: {
211+
includeInStateLogs: false,
171212
persist: true,
172213
anonymous: false,
214+
usedInUi: false,
173215
},
174216
isSeedlessOnboardingUserAuthenticated: {
217+
includeInStateLogs: true,
175218
persist: true,
176219
anonymous: true,
220+
usedInUi: false,
177221
},
178222
};
179223

0 commit comments

Comments
 (0)