@metamask/keyring-internal-snap-client
Version:
MetaMask Keyring Snap internal clients
81 lines • 3.45 kB
text/typescript
import type { KeyringRequestWithoutOrigin, KeyringResponseWithoutOrigin } from "@metamask/keyring-internal-api";
import type { Sender } from "@metamask/keyring-snap-client";
import { KeyringClient } from "@metamask/keyring-snap-client";
import type { Messenger } from "@metamask/messenger";
import type { SnapControllerHandleRequestAction } from "@metamask/snaps-controllers";
import type { JsonRpcRequest, SnapId } from "@metamask/snaps-sdk";
import type { HandlerType } from "@metamask/snaps-utils";
import type { Json } from "@metamask/utils";
type AllowedActions = SnapControllerHandleRequestAction;
/**
* A restricted-`Messenger` used by `KeyringInternalSnapClient` to dispatch
* internal Snap requests.
*/
export type KeyringInternalSnapClientMessenger = Messenger<'KeyringInternalSnapClient', AllowedActions>;
/**
* Implementation of the `Sender` interface that can be used to send requests
* to a Snap through a `Messenger`.
*/
export declare class SnapControllerMessengerSender implements Sender {
#private;
/**
* Create a new instance of `SnapControllerSender`.
*
* @param messenger - The `Messenger` instance used when dispatching controllers actions.
* @param snapId - The ID of the Snap to use.
* @param origin - The sender's origin.
* @param handler - The handler type.
*/
constructor(messenger: KeyringInternalSnapClientMessenger, snapId: SnapId, origin: string, handler: HandlerType);
/**
* Send a request to the Snap and return the response.
*
* @param request - JSON-RPC request to send to the Snap.
* @returns A promise that resolves to the response of the request.
*/
send(request: JsonRpcRequest): Promise<Json>;
}
/**
* A `KeyringClient` that allows the communication with a Snap through a
* `Messenger`.
*/
export declare class KeyringInternalSnapClient extends KeyringClient {
#private;
/**
* Create a new instance of `KeyringInternalSnapClient`.
*
* The `handlerType` argument has a hard-coded default `string` value instead
* of a `HandlerType` value to prevent the `@metamask/snaps-utils` module
* from being required at runtime.
*
* @param args - Constructor arguments.
* @param args.messenger - The `KeyringInternalSnapClientMessenger` instance to use.
* @param args.snapId - The ID of the Snap to use (default: `'undefined'`).
* @param args.origin - The sender's origin (default: `'metamask'`).
* @param args.handler - The handler type (default: `'onKeyringRequest'`).
*/
constructor({ messenger, snapId, origin, handler, }: {
messenger: KeyringInternalSnapClientMessenger;
snapId?: SnapId;
origin?: string;
handler?: HandlerType;
});
/**
* Create a new instance of `KeyringInternalSnapClient` with the specified
* `snapId`.
*
* @param snapId - The ID of the Snap to use in the new instance.
* @returns A new instance of `KeyringInternalSnapClient` with the
* specified Snap ID.
*/
withSnapId(snapId: SnapId): KeyringInternalSnapClient;
/**
* Submit a keyring request v1 (with no `origin`).
*
* @param request - Keyring request.
* @returns Keyring request's response.
*/
submitRequestWithoutOrigin(request: KeyringRequestWithoutOrigin): Promise<KeyringResponseWithoutOrigin>;
}
export {};
//# sourceMappingURL=KeyringInternalSnapClient.d.mts.map