Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/keyring-snap-bridge/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `name` and `state` properties to `SnapKeyring` to allow modular initialisation in the clients ([#379](https://github.com/MetaMask/accounts/pull/379))

Comment thread
Mrtenz marked this conversation as resolved.
## [17.1.0]

### Changed
Expand Down
10 changes: 7 additions & 3 deletions packages/keyring-snap-bridge/src/SnapKeyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {
KnownCaipNamespace,
toCaipChainId,
} from '@metamask/utils';
import { EventEmitter } from 'events';
import { v4 as uuid } from 'uuid';

import { transformAccount } from './account';
Expand All @@ -74,6 +73,7 @@ import type {
SnapKeyringEvents,
SnapKeyringMessenger,
} from './SnapKeyringMessenger';
import { SNAP_KEYRING_NAME } from './SnapKeyringMessenger';
import type { SnapMessage } from './types';
import { SnapMessageStruct } from './types';
import {
Expand Down Expand Up @@ -154,11 +154,16 @@ function normalizeAccountAddress(account: KeyringAccount): string {
/**
* Keyring bridge implementation to support Snaps.
*/
export class SnapKeyring extends EventEmitter {
Comment thread
Mrtenz marked this conversation as resolved.
export class SnapKeyring {
static type: string = SNAP_KEYRING_TYPE;

type: string;

// Name and state are required for modular initialisation.
name: typeof SNAP_KEYRING_NAME = SNAP_KEYRING_NAME;

state = null;

/**
* Messenger to dispatch requests to the Snaps controller.
*/
Expand Down Expand Up @@ -225,7 +230,6 @@ export class SnapKeyring extends EventEmitter {
callbacks: SnapKeyringCallbacks;
isAnyAccountTypeAllowed?: boolean;
}) {
super();
this.type = SnapKeyring.type;
this.#messenger = messenger;
this.#snapClient = new KeyringInternalSnapClient({ messenger });
Expand Down
4 changes: 3 additions & 1 deletion packages/keyring-snap-bridge/src/SnapKeyringMessenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ export type SnapKeyringAllowedActions =
| SnapControllerGetSnap
| SnapControllerIsMinimumPlatformVersion;

export const SNAP_KEYRING_NAME = 'SnapKeyring';

export type SnapKeyringMessenger = RestrictedMessenger<
'SnapKeyring',
typeof SNAP_KEYRING_NAME,
SnapKeyringAllowedActions,
SnapKeyringEvents,
SnapKeyringAllowedActions['type'],
Expand Down
Loading