-
-
Notifications
You must be signed in to change notification settings - Fork 290
feat(wallet): Add SeedlessOnboardingController and PasskeyController #9533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lwin-kyaw
wants to merge
11
commits into
main
Choose a base branch
from
feat/passkey-seedless-init-instance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0781e51
feat: add PasskeyController to wallet initialization instances
lwin-kyaw d795cf6
feat: add SeedlessOnboardingController to wallet init
lwin-kyaw 3cbc158
fix: fixed build and lint
lwin-kyaw abc2e4c
chore: updated CHANGELOG
lwin-kyaw b867f45
chore: updaed CODE_OWNERS
lwin-kyaw 901744a
chore: reuse constructor options for PasskeyControllerInstanceOptions
lwin-kyaw c94fc01
fix: fixed lint
lwin-kyaw ded1aa1
feat: updated passkey-controller-init
lwin-kyaw 6b754f5
Merge remote-tracking branch 'origin/main' into feat/passkey-seedless…
lwin-kyaw 70079ce
fix: fixed tests
lwin-kyaw c60b979
fix: fixed tests
lwin-kyaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
packages/wallet/src/initialization/instances/passkey-controller/passkey-controller.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import { Messenger } from '@metamask/messenger'; | ||
| import { | ||
| PasskeyController, | ||
| getDefaultPasskeyControllerState, | ||
| } from '@metamask/passkey-controller'; | ||
| import type { PasskeyRecord } from '@metamask/passkey-controller'; | ||
|
|
||
| import { defaultConfigurations } from '../../defaults'; | ||
| import type { | ||
| DefaultActions, | ||
| DefaultEvents, | ||
| RootMessenger, | ||
| } from '../../defaults'; | ||
| import { passkeyController } from './passkey-controller'; | ||
|
|
||
| const { PasskeyController: ActualPasskeyController } = jest.requireActual( | ||
| '@metamask/passkey-controller', | ||
| ); | ||
|
|
||
| jest.mock('@metamask/passkey-controller', () => ({ | ||
| ...jest.requireActual('@metamask/passkey-controller'), | ||
| PasskeyController: jest.fn(), | ||
| })); | ||
|
|
||
| const REQUIRED_OPTIONS = { | ||
| expectedRPID: 'extension-id', | ||
| expectedOrigin: 'https://extension.origin', | ||
| rpName: 'MetaMask', | ||
| }; | ||
|
|
||
| /** | ||
| * Creates a root messenger for use in tests. | ||
| * | ||
| * @returns A root messenger. | ||
| */ | ||
| function getRootMessenger(): RootMessenger<DefaultActions, DefaultEvents> { | ||
| return new Messenger({ namespace: 'Root' }); | ||
| } | ||
|
|
||
| describe('passkeyController', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| (PasskeyController as jest.Mock).mockImplementation( | ||
| (...args: unknown[]) => new ActualPasskeyController(...args), | ||
| ); | ||
| }); | ||
|
|
||
| it('is registered as a default initialization configuration', () => { | ||
| expect(Object.values(defaultConfigurations)).toContain(passkeyController); | ||
| }); | ||
|
|
||
| it('initializes a PasskeyController with default state', () => { | ||
| const messenger = passkeyController.getMessenger(getRootMessenger()); | ||
|
|
||
| const instance = passkeyController.init({ | ||
| state: undefined, | ||
| messenger, | ||
| options: REQUIRED_OPTIONS, | ||
| }); | ||
|
|
||
| expect(instance).toBeInstanceOf(ActualPasskeyController); | ||
| expect(instance.state).toStrictEqual(getDefaultPasskeyControllerState()); | ||
| }); | ||
|
|
||
| it('forwards the provided state to the controller', () => { | ||
| const messenger = passkeyController.getMessenger(getRootMessenger()); | ||
|
|
||
| const passkeyRecord: PasskeyRecord = { | ||
| credential: { | ||
| id: 'credential-id', | ||
| publicKey: 'public-key', | ||
| counter: 0, | ||
| transports: ['internal'], | ||
| aaguid: '00000000-0000-0000-0000-000000000000', | ||
| }, | ||
| encryptedVaultKey: { | ||
| ciphertext: 'YQ==', | ||
| iv: 'YWFhYWFhYWFhYQ==', | ||
| }, | ||
| keyDerivation: { method: 'userHandle' }, | ||
| }; | ||
|
|
||
| const instance = passkeyController.init({ | ||
| state: { passkeyRecord }, | ||
| messenger, | ||
| options: REQUIRED_OPTIONS, | ||
| }); | ||
|
|
||
| expect(instance.state.passkeyRecord).toStrictEqual(passkeyRecord); | ||
| }); | ||
|
|
||
| it('forwards custom passkey configuration options', () => { | ||
| const messenger = passkeyController.getMessenger(getRootMessenger()); | ||
|
|
||
| passkeyController.init({ | ||
| state: undefined, | ||
| messenger, | ||
| options: { | ||
| expectedRPID: ['extension-id', 'other-id'], | ||
| expectedOrigin: ['https://a.example', 'https://b.example'], | ||
| rpId: 'rp-id', | ||
| rpName: 'Custom RP', | ||
| userName: 'custom-user', | ||
| userDisplayName: 'Custom Display Name', | ||
| }, | ||
| }); | ||
|
|
||
| expect(PasskeyController).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| rpId: 'rp-id', | ||
| rpName: 'Custom RP', | ||
| userName: 'custom-user', | ||
| userDisplayName: 'Custom Display Name', | ||
| expectedRPID: ['extension-id', 'other-id'], | ||
| expectedOrigin: ['https://a.example', 'https://b.example'], | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('exposes its state through the root messenger', () => { | ||
| const rootMessenger = getRootMessenger(); | ||
| const messenger = passkeyController.getMessenger(rootMessenger); | ||
|
|
||
| passkeyController.init({ | ||
| state: undefined, | ||
| messenger, | ||
| options: REQUIRED_OPTIONS, | ||
| }); | ||
|
|
||
| expect(rootMessenger.call('PasskeyController:getState')).toStrictEqual( | ||
| getDefaultPasskeyControllerState(), | ||
| ); | ||
| }); | ||
| }); |
25 changes: 25 additions & 0 deletions
25
packages/wallet/src/initialization/instances/passkey-controller/passkey-controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Messenger } from '@metamask/messenger'; | ||
| import { | ||
| PasskeyController, | ||
| PasskeyControllerMessenger, | ||
| } from '@metamask/passkey-controller'; | ||
|
|
||
| import { InitializationConfiguration } from '../../types'; | ||
|
|
||
| export const passkeyController: InitializationConfiguration< | ||
| PasskeyController, | ||
| PasskeyControllerMessenger | ||
| > = { | ||
| name: 'PasskeyController', | ||
| init: ({ state, messenger, options }) => | ||
| new PasskeyController({ | ||
| ...options, | ||
| messenger, | ||
| state, | ||
| }), | ||
| getMessenger: (parent) => | ||
| new Messenger({ | ||
| namespace: 'PasskeyController', | ||
| parent, | ||
| }), | ||
| }; | ||
6 changes: 6 additions & 0 deletions
6
packages/wallet/src/initialization/instances/passkey-controller/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { PasskeyController } from '@metamask/passkey-controller'; | ||
|
|
||
| export type PasskeyControllerInstanceOptions = Omit< | ||
| ConstructorParameters<typeof PasskeyController>[0], | ||
| 'messenger' | 'state' | ||
| >; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.