Skip to content

Commit cb75a90

Browse files
feat: Add new metadata properties to Web3Auth controllers (#6504)
## Explanation The new metadata properties `includeInStateLogs` and `usedInUi` have been added to all controllers maintained by the Web3Auth team. ## References * Fixes #6521 * Related to #6443 ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes --------- Co-authored-by: Michele Esposito <michele@esposito.codes>
1 parent dda083d commit cb75a90

File tree

9 files changed

+432
-3
lines changed

9 files changed

+432
-3
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: 240 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,240 @@ 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+
pendingToBeRevokedTokens: [
5459+
{ refreshToken: 'refreshToken', revokeToken: 'revokeToken' },
5460+
],
5461+
refreshToken: 'refreshToken',
5462+
revokeToken: 'revokeToken',
5463+
socialBackupsMetadata: [],
5464+
socialLoginEmail: 'socialLoginEmail',
5465+
userId: 'userId',
5466+
vault: 'vault',
5467+
vaultEncryptionKey: 'vaultEncryptionKey',
5468+
vaultEncryptionSalt: 'vaultEncryptionSalt',
5469+
},
5470+
},
5471+
({ controller }) => {
5472+
expect(
5473+
deriveStateFromMetadata(
5474+
controller.state,
5475+
controller.metadata,
5476+
'anonymous',
5477+
),
5478+
).toMatchInlineSnapshot(`
5479+
Object {
5480+
"authConnection": "google",
5481+
"authConnectionId": "authConnectionId",
5482+
"groupedAuthConnectionId": "groupedAuthConnectionId",
5483+
"isSeedlessOnboardingUserAuthenticated": false,
5484+
"passwordOutdatedCache": Object {
5485+
"isExpiredPwd": false,
5486+
"timestamp": 1234567890,
5487+
},
5488+
}
5489+
`);
5490+
},
5491+
);
5492+
});
5493+
5494+
it('includes expected state in state logs', async () => {
5495+
await withController(
5496+
{
5497+
state: {
5498+
accessToken: 'accessToken',
5499+
authPubKey: 'authPubKey',
5500+
authConnection: AuthConnection.Google,
5501+
authConnectionId: 'authConnectionId',
5502+
encryptedKeyringEncryptionKey: 'encryptedKeyringEncryptionKey',
5503+
encryptedSeedlessEncryptionKey: 'encryptedSeedlessEncryptionKey',
5504+
groupedAuthConnectionId: 'groupedAuthConnectionId',
5505+
isSeedlessOnboardingUserAuthenticated: true,
5506+
metadataAccessToken: 'metadataAccessToken',
5507+
nodeAuthTokens: [],
5508+
passwordOutdatedCache: {
5509+
isExpiredPwd: false,
5510+
timestamp: 1234567890,
5511+
},
5512+
pendingToBeRevokedTokens: [
5513+
{ refreshToken: 'refreshToken', revokeToken: 'revokeToken' },
5514+
],
5515+
refreshToken: 'refreshToken',
5516+
revokeToken: 'revokeToken',
5517+
socialBackupsMetadata: [],
5518+
socialLoginEmail: 'socialLoginEmail',
5519+
userId: 'userId',
5520+
vault: 'vault',
5521+
vaultEncryptionKey: 'vaultEncryptionKey',
5522+
vaultEncryptionSalt: 'vaultEncryptionSalt',
5523+
},
5524+
},
5525+
({ controller }) => {
5526+
expect(
5527+
deriveStateFromMetadata(
5528+
controller.state,
5529+
controller.metadata,
5530+
'includeInStateLogs',
5531+
),
5532+
).toMatchInlineSnapshot(`
5533+
Object {
5534+
"accessToken": true,
5535+
"authConnection": "google",
5536+
"authConnectionId": "authConnectionId",
5537+
"authPubKey": "authPubKey",
5538+
"groupedAuthConnectionId": "groupedAuthConnectionId",
5539+
"isSeedlessOnboardingUserAuthenticated": false,
5540+
"metadataAccessToken": true,
5541+
"nodeAuthTokens": true,
5542+
"passwordOutdatedCache": Object {
5543+
"isExpiredPwd": false,
5544+
"timestamp": 1234567890,
5545+
},
5546+
"pendingToBeRevokedTokens": true,
5547+
"refreshToken": true,
5548+
"revokeToken": true,
5549+
"userId": "userId",
5550+
}
5551+
`);
5552+
},
5553+
);
5554+
});
5555+
5556+
it('persists expected state', async () => {
5557+
await withController(
5558+
{
5559+
state: {
5560+
accessToken: 'accessToken',
5561+
authPubKey: 'authPubKey',
5562+
authConnection: AuthConnection.Google,
5563+
authConnectionId: 'authConnectionId',
5564+
encryptedKeyringEncryptionKey: 'encryptedKeyringEncryptionKey',
5565+
encryptedSeedlessEncryptionKey: 'encryptedSeedlessEncryptionKey',
5566+
groupedAuthConnectionId: 'groupedAuthConnectionId',
5567+
isSeedlessOnboardingUserAuthenticated: true,
5568+
metadataAccessToken: 'metadataAccessToken',
5569+
nodeAuthTokens: [],
5570+
passwordOutdatedCache: {
5571+
isExpiredPwd: false,
5572+
timestamp: 1234567890,
5573+
},
5574+
pendingToBeRevokedTokens: [
5575+
{ refreshToken: 'refreshToken', revokeToken: 'revokeToken' },
5576+
],
5577+
refreshToken: 'refreshToken',
5578+
revokeToken: 'revokeToken',
5579+
socialBackupsMetadata: [],
5580+
socialLoginEmail: 'socialLoginEmail',
5581+
userId: 'userId',
5582+
vault: 'vault',
5583+
vaultEncryptionKey: 'vaultEncryptionKey',
5584+
vaultEncryptionSalt: 'vaultEncryptionSalt',
5585+
},
5586+
},
5587+
({ controller }) => {
5588+
expect(
5589+
deriveStateFromMetadata(
5590+
controller.state,
5591+
controller.metadata,
5592+
'persist',
5593+
),
5594+
).toMatchInlineSnapshot(`
5595+
Object {
5596+
"authConnection": "google",
5597+
"authConnectionId": "authConnectionId",
5598+
"authPubKey": "authPubKey",
5599+
"encryptedKeyringEncryptionKey": "encryptedKeyringEncryptionKey",
5600+
"encryptedSeedlessEncryptionKey": "encryptedSeedlessEncryptionKey",
5601+
"groupedAuthConnectionId": "groupedAuthConnectionId",
5602+
"isSeedlessOnboardingUserAuthenticated": false,
5603+
"metadataAccessToken": "metadataAccessToken",
5604+
"nodeAuthTokens": Array [],
5605+
"passwordOutdatedCache": Object {
5606+
"isExpiredPwd": false,
5607+
"timestamp": 1234567890,
5608+
},
5609+
"pendingToBeRevokedTokens": Array [
5610+
Object {
5611+
"refreshToken": "refreshToken",
5612+
"revokeToken": "revokeToken",
5613+
},
5614+
],
5615+
"refreshToken": "refreshToken",
5616+
"socialBackupsMetadata": Array [],
5617+
"socialLoginEmail": "socialLoginEmail",
5618+
"userId": "userId",
5619+
"vault": "vault",
5620+
}
5621+
`);
5622+
},
5623+
);
5624+
});
5625+
5626+
it('exposes expected state to UI', async () => {
5627+
await withController(
5628+
{
5629+
state: {
5630+
accessToken: 'accessToken',
5631+
authPubKey: 'authPubKey',
5632+
authConnection: AuthConnection.Google,
5633+
authConnectionId: 'authConnectionId',
5634+
encryptedKeyringEncryptionKey: 'encryptedKeyringEncryptionKey',
5635+
encryptedSeedlessEncryptionKey: 'encryptedSeedlessEncryptionKey',
5636+
groupedAuthConnectionId: 'groupedAuthConnectionId',
5637+
isSeedlessOnboardingUserAuthenticated: true,
5638+
metadataAccessToken: 'metadataAccessToken',
5639+
nodeAuthTokens: [],
5640+
passwordOutdatedCache: {
5641+
isExpiredPwd: false,
5642+
timestamp: 1234567890,
5643+
},
5644+
pendingToBeRevokedTokens: [
5645+
{ refreshToken: 'refreshToken', revokeToken: 'revokeToken' },
5646+
],
5647+
refreshToken: 'refreshToken',
5648+
revokeToken: 'revokeToken',
5649+
socialBackupsMetadata: [],
5650+
socialLoginEmail: 'socialLoginEmail',
5651+
userId: 'userId',
5652+
vault: 'vault',
5653+
vaultEncryptionKey: 'vaultEncryptionKey',
5654+
vaultEncryptionSalt: 'vaultEncryptionSalt',
5655+
},
5656+
},
5657+
({ controller }) => {
5658+
expect(
5659+
deriveStateFromMetadata(
5660+
controller.state,
5661+
controller.metadata,
5662+
'usedInUi',
5663+
),
5664+
).toMatchInlineSnapshot(`
5665+
Object {
5666+
"authConnection": "google",
5667+
"socialLoginEmail": "socialLoginEmail",
5668+
}
5669+
`);
5670+
},
5671+
);
5672+
});
5673+
});
54355674
});

0 commit comments

Comments
 (0)