Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/snaps-controllers/src/cronjob/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export type {
CronjobControllerActions,
CronjobControllerArgs,
CronjobControllerEvents,
CronjobControllerGetStateAction,
CronjobControllerMessenger,
CronjobControllerState,
CronjobControllerStateChangeEvent,
CronjobControllerStateManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import type {

const controllerName = 'SnapInsightsController';

export type SnapInsightsControllerAllowedActions =
type AllowedActions =
| GetPermissions
| SnapControllerGetRunnableSnapsAction
| SnapControllerHandleRequestAction
Expand All @@ -55,15 +55,15 @@ export type SnapInsightControllerStateChangeEvent = ControllerStateChangeEvent<

export type SnapInsightControllerEvents = SnapInsightControllerStateChangeEvent;

export type SnapInsightsControllerAllowedEvents =
type AllowedEvents =
| TransactionControllerUnapprovedTransactionAddedEvent
| TransactionControllerTransactionStatusUpdatedEvent
| SignatureControllerStateChangeEvent;

export type SnapInsightsControllerMessenger = Messenger<
typeof controllerName,
SnapInsightsControllerActions | SnapInsightsControllerAllowedActions,
SnapInsightControllerEvents | SnapInsightsControllerAllowedEvents
SnapInsightsControllerActions | AllowedActions,
SnapInsightControllerEvents | AllowedEvents
>;

export type SnapInsight = {
Expand Down
3 changes: 3 additions & 0 deletions packages/snaps-controllers/src/insights/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export type {
SnapInsight,
SnapInsightsControllerActions,
SnapInsightsControllerArgs,
SnapInsightControllerEvents,
SnapInsightsControllerMessenger,
SnapInsightsControllerState,
} from './SnapInsightsController';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type PhishingControllerTestOrigin = {
handler: (origin: string) => { result: boolean; type: string };
};

export type SnapInterfaceControllerAllowedActions =
type AllowedActions =
| PhishingControllerTestOrigin
| ApprovalControllerHasRequestAction
| ApprovalControllerAcceptRequestAction
Expand Down Expand Up @@ -143,14 +143,15 @@ type NotificationListUpdatedEvent = {
payload: [Notification[]];
};

type AllowedEvents = NotificationListUpdatedEvent;

export type SnapInterfaceControllerEvents =
| SnapInterfaceControllerStateChangeEvent
| NotificationListUpdatedEvent;
SnapInterfaceControllerStateChangeEvent;

export type SnapInterfaceControllerMessenger = Messenger<
typeof controllerName,
SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions,
SnapInterfaceControllerEvents
SnapInterfaceControllerActions | AllowedActions,
SnapInterfaceControllerEvents | AllowedEvents
>;

export type StoredInterface = {
Expand Down
4 changes: 3 additions & 1 deletion packages/snaps-controllers/src/interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export type {
SnapInterfaceControllerActions,
SnapInterfaceControllerAllowedActions,
SnapInterfaceControllerArgs,
SnapInterfaceControllerEvents,
SnapInterfaceControllerGetStateAction,
SnapInterfaceControllerMessenger,
SnapInterfaceControllerState,
SnapInterfaceControllerStateChangeEvent,
StoredInterface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type AccountsControllerListMultichainAccountsAction = {
export type MultichainRoutingServiceActions =
MultichainRoutingServiceMethodActions;

export type MultichainRoutingServiceAllowedActions =
type AllowedActions =
| SnapControllerGetRunnableSnapsAction
| SnapControllerHandleRequestAction
| GetPermissions
Expand All @@ -61,7 +61,7 @@ export type MultichainRoutingServiceEvents = never;

export type MultichainRoutingServiceMessenger = Messenger<
typeof name,
MultichainRoutingServiceActions | MultichainRoutingServiceAllowedActions
MultichainRoutingServiceActions | AllowedActions
>;

export type MultichainRoutingServiceArgs = {
Expand Down
5 changes: 5 additions & 0 deletions packages/snaps-controllers/src/multichain/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export type {
MultichainRoutingServiceActions,
MultichainRoutingServiceEvents,
MultichainRoutingServiceMessenger,
} from './MultichainRoutingService';
export { MultichainRoutingService } from './MultichainRoutingService';
export type {
MultichainRoutingServiceGetSupportedAccountsAction,
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-controllers/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type {
ExecutionServiceActions,
ExecutionServiceArgs,
ExecutionServiceEvents,
ExecutionServiceMessenger,
ExecutionServiceOutboundRequestEvent,
Expand Down
6 changes: 3 additions & 3 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export type SnapControllerEvents =
| SnapControllerSnapDisabledEvent
| SnapControllerStateChangeEvent;

export type AllowedActions =
type AllowedActions =
| GetEndowments
| GetPermissions
| GetSubjects
Expand Down Expand Up @@ -542,7 +542,7 @@ export type AllowedActions =
| StorageServiceRemoveItemAction
| StorageServiceClearAction;

export type AllowedEvents =
type AllowedEvents =
| ExecutionServiceEvents
| SnapControllerSnapInstalledEvent
| SnapControllerSnapUpdatedEvent
Expand Down Expand Up @@ -580,7 +580,7 @@ type DynamicFeatureFlags = {
disableSnaps?: boolean;
};

type SnapControllerArgs = {
export type SnapControllerArgs = {
/**
* A list of permissions that are allowed to be dynamic, meaning they can be revoked from the snap whenever.
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/snaps-controllers/src/snaps/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export * from './constants';
export * from './location';
export type {
SnapControllerActions,
SnapControllerArgs,
SnapControllerEvents,
SnapControllerGetStateAction,
SnapControllerMessenger,
SnapControllerSnapBlockedEvent,
SnapControllerSnapDisabledEvent,
SnapControllerSnapEnabledEvent,
Expand Down
55 changes: 31 additions & 24 deletions packages/snaps-simulation/src/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ import {
caip25CaveatBuilder,
Caip25CaveatType,
} from '@metamask/chain-agnostic-permission';
import type {
MessengerActions,
MessengerEvents,
MockAnyNamespace,
} from '@metamask/messenger';
import { Messenger } from '@metamask/messenger';
import type {
CaveatSpecificationConstraint,
PermissionControllerMessenger,
PermissionSpecificationConstraint,
PermissionControllerActions,
SubjectMetadataControllerActions,
} from '@metamask/permission-controller';
import {
PermissionController,
SubjectMetadataController,
SubjectType,
} from '@metamask/permission-controller';
import { SnapInterfaceController } from '@metamask/snaps-controllers';
import type {
ExecutionServiceActions,
SnapInterfaceControllerStateChangeEvent,
SnapInterfaceControllerActions,
SnapInterfaceControllerAllowedActions,
ExecutionServiceMessenger,
SnapControllerMessenger,
SnapInterfaceControllerMessenger,
SnapRegistryControllerMessenger,
} from '@metamask/snaps-controllers';
import { SnapInterfaceController } from '@metamask/snaps-controllers';
import {
caveatSpecifications as snapsCaveatsSpecifications,
endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications,
Expand All @@ -37,20 +41,22 @@ import type { SimulationOptions } from './options';
import type { RestrictedMiddlewareHooks } from './simulation';
import type { RunSagaFunction } from './store';

export type RootControllerAllowedActions =
| SnapInterfaceControllerActions
| SnapInterfaceControllerAllowedActions
| PermissionControllerActions
| ExecutionServiceActions
| SubjectMetadataControllerActions;

export type RootControllerAllowedEvents =
SnapInterfaceControllerStateChangeEvent;

export type RootControllerMessenger = Messenger<
any,
RootControllerAllowedActions,
RootControllerAllowedEvents
MockAnyNamespace,
MessengerActions<
| ExecutionServiceMessenger
| PermissionControllerMessenger
| SnapControllerMessenger
| SnapInterfaceControllerMessenger
| SnapRegistryControllerMessenger
>,
MessengerEvents<
| ExecutionServiceMessenger
| PermissionControllerMessenger
| SnapControllerMessenger
| SnapInterfaceControllerMessenger
| SnapRegistryControllerMessenger
>
>;

export type GetControllersOptions = {
Expand Down Expand Up @@ -85,10 +91,11 @@ export function getControllers(options: GetControllersOptions): Controllers {
subjectCacheLimit: 100,
});

const interfaceControllerMessenger = new Messenger({
namespace: 'SnapInterfaceController',
parent: controllerMessenger,
});
const interfaceControllerMessenger: SnapInterfaceControllerMessenger =
new Messenger({
namespace: 'SnapInterfaceController',
parent: controllerMessenger,
});

controllerMessenger.delegate({
messenger: interfaceControllerMessenger,
Expand Down
16 changes: 4 additions & 12 deletions packages/snaps-simulation/src/test-utils/controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { Messenger } from '@metamask/messenger';
import type { SnapInterfaceControllerAllowedActions } from '@metamask/snaps-controllers';
import type { SnapInterfaceControllerMessenger } from '@metamask/snaps-controllers';
import { MockControllerMessenger } from '@metamask/snaps-utils/test-utils';

import type { RootControllerAllowedActions } from '../controllers';
import type { RootControllerMessenger } from '../controllers';

export const getRootControllerMessenger = (mocked = true) => {
const messenger = new MockControllerMessenger<
RootControllerAllowedActions,
any
>();
const messenger: RootControllerMessenger = new MockControllerMessenger();

if (mocked) {
messenger.registerActionHandler('PhishingController:testOrigin', () => ({
Expand Down Expand Up @@ -42,12 +39,7 @@ export const getRestrictedSnapInterfaceControllerMessenger = (
typeof getRootControllerMessenger
> = getRootControllerMessenger(),
) => {
const controllerMessenger = new Messenger<
'SnapInterfaceController',
SnapInterfaceControllerAllowedActions,
never,
any
>({
const controllerMessenger: SnapInterfaceControllerMessenger = new Messenger({
namespace: 'SnapInterfaceController',
parent: messenger,
});
Expand Down
Loading