UNPKG

@metamask/snaps-rpc-methods

Version:
1 lines 6.2 kB
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuxiliaryFileEncoding,\n BackgroundEvent,\n ComponentOrElement,\n GetSnapsResult,\n GetWebSocketsResult,\n InterfaceContext,\n InterfaceState,\n RequestSnapsResult,\n ContentType,\n RequestSnapsParams,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n Snap,\n SnapRpcHookArgs,\n TruncatedSnap,\n} from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nexport type JsonRpcRequestWithOrigin<\n Params extends JsonRpcParams = JsonRpcParams,\n> = JsonRpcRequest<Params> & { origin: string };\n\nexport type HdKeyring = {\n type: 'hd';\n seed?: Uint8Array;\n mnemonic?: Uint8Array;\n};\n\nexport type KeyringControllerWithKeyringV2UnsafeAction = {\n type: 'KeyringController:withKeyringV2Unsafe';\n handler: (\n selector:\n | {\n type: string;\n index?: number;\n }\n | { id: string },\n operation: (args: { keyring: HdKeyring }) => Promise<unknown>,\n ) => Promise<unknown>;\n};\n\nexport type KeyringControllerGetStateAction = {\n type: `KeyringController:getState`;\n handler: () => {\n isUnlocked: boolean;\n keyrings: {\n type: string;\n metadata: { id: string; name: string };\n }[];\n };\n};\n\nexport type ApprovalControllerAddRequestAction = {\n type: 'ApprovalController:addRequest';\n handler: (\n opts: {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, unknown>;\n requestState?: Record<string, Json>;\n },\n shouldShowRequest: boolean,\n ) => Promise<Json>;\n};\n\nexport type SnapInterfaceControllerCreateInterfaceAction = {\n type: 'SnapInterfaceController:createInterface';\n handler: (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => string;\n};\n\nexport type SnapInterfaceControllerGetInterfaceAction = {\n type: 'SnapInterfaceController:getInterface';\n handler: (\n snapId: string,\n id: string,\n ) => {\n content: ComponentOrElement;\n snapId: SnapId;\n state: InterfaceState;\n context: InterfaceContext | null;\n };\n};\n\nexport type SnapInterfaceControllerSetInterfaceDisplayedAction = {\n type: 'SnapInterfaceController:setInterfaceDisplayed';\n handler: (snapId: string, id: string) => void;\n};\n\nexport type SnapInterfaceControllerGetInterfaceStateAction = {\n type: `SnapInterfaceController:getInterfaceState`;\n handler: (snapId: string, id: string) => InterfaceState;\n};\n\nexport type SnapInterfaceControllerUpdateInterfaceAction = {\n type: `SnapInterfaceController:updateInterface`;\n handler: (\n snapId: string,\n id: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) => void;\n};\n\nexport type SnapInterfaceControllerResolveInterfaceAction = {\n type: `SnapInterfaceController:resolveInterface`;\n handler: (snapId: string, id: string, value: Json) => Promise<void>;\n};\n\nexport type SnapControllerHandleRequestAction = {\n type: 'SnapController:handleRequest';\n handler: (args: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\nexport type SnapControllerGetSnapAction = {\n type: 'SnapController:getSnap';\n handler: (snapId: string) => Snap | null;\n};\n\nexport type SnapControllerClearSnapStateAction = {\n type: 'SnapController:clearSnapState';\n handler: (snapId: string, encrypted: boolean) => void;\n};\n\nexport type SnapControllerGetSnapStateAction = {\n type: 'SnapController:getSnapState';\n handler: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json> | null>;\n};\n\nexport type SnapControllerUpdateSnapStateAction = {\n type: 'SnapController:updateSnapState';\n handler: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\nexport type SnapControllerGetAllSnapsAction = {\n type: `SnapController:getAllSnaps`;\n handler: () => TruncatedSnap[];\n};\n\nexport type SnapControllerGetPermittedSnapsAction = {\n type: `SnapController:getPermittedSnaps`;\n handler: (origin: string) => GetSnapsResult;\n};\n\nexport type SnapControllerInstallSnapsAction = {\n type: `SnapController:installSnaps`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type SnapControllerGetSnapFileAction = {\n type: `SnapController:getSnapFile`;\n handler: (\n snapId: string,\n path: string,\n encoding?: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n};\n\nexport type RateLimitControllerCallAction = {\n type: 'RateLimitController:call';\n handler: (\n origin: string,\n type: string,\n ...args: unknown[]\n ) => Promise<unknown>;\n};\n\nexport type CronjobControllerCancelAction = {\n type: `CronjobController:cancel`;\n handler: (origin: string, id: string) => void;\n};\n\nexport type CronjobControllerScheduleAction = {\n type: `CronjobController:schedule`;\n handler: (event: {\n snapId: string;\n request: {\n method: string;\n jsonrpc?: '2.0';\n id?: string | number | null;\n params?: Json[] | Record<string, Json>;\n };\n schedule: string;\n id?: string;\n }) => string;\n};\n\nexport type CronjobControllerGetAction = {\n type: `CronjobController:get`;\n handler: (snapId: string) => BackgroundEvent[];\n};\n\nexport type WebSocketServiceOpenAction = {\n type: `WebSocketService:open`;\n handler: (\n snapId: string,\n url: string,\n protocols?: string[],\n ) => Promise<string>;\n};\n\nexport type WebSocketServiceCloseAction = {\n type: `WebSocketService:close`;\n handler: (snapId: string, id: string) => void;\n};\n\nexport type WebSocketServiceSendMessageAction = {\n type: `WebSocketService:sendMessage`;\n handler: (\n snapId: string,\n id: string,\n data: string | number[],\n ) => Promise<void>;\n};\n\nexport type WebSocketServiceGetAllAction = {\n type: `WebSocketService:getAll`;\n handler: (snapId: string) => GetWebSocketsResult;\n};\n"]}