@metamask/kernel-rpc-methods
Version:
Utilities for implementing Ocap Kernel JSON-RPC methods
46 lines • 2.24 kB
text/typescript
import { Logger } from "@metamask/logger";
import type { JsonRpcNotification, JsonRpcRequest } from "@metamask/utils";
import type { MethodSpec, ExtractParams, ExtractResult, MethodSpecRecord, ExtractNotification, ExtractRequest } from "./types.mjs";
export type SendMessage = (payload: JsonRpcRequest | JsonRpcNotification) => Promise<void>;
export declare class RpcClient<Methods extends MethodSpecRecord<MethodSpec<string, any, any>>> {
#private;
constructor(methods: Methods, sendMessage: SendMessage, prefix: string, logger?: Logger);
/**
* Calls a JSON-RPC method and returns the result.
*
* @param method - The method to call.
* @param params - The parameters to pass to the method.
* @returns A promise that resolves to the result.
*/
call<Method extends ExtractRequest<Methods>>(method: Method, params: ExtractParams<Method, Methods>): Promise<ExtractResult<Method, Methods>>;
/**
* Sends a JSON-RPC notification. Recall that we do not receive responses to notifications
* for any reason.
*
* @param method - The method to notify.
* @param params - The parameters to pass to the method.
*/
notify<Method extends ExtractNotification<Methods>>(method: Method, params: ExtractParams<Method, Methods>): Promise<void>;
/**
* Calls a JSON-RPC method and returns the message id and the result.
*
* @param method - The method to call.
* @param params - The parameters to pass to the method.
* @returns A promise that resolves to a tuple of the message id and the result.
*/
callAndGetId<Method extends ExtractRequest<Methods>>(method: Method, params: ExtractParams<Method, Methods>): Promise<[string, ExtractResult<Method, Methods>]>;
/**
* Handles a JSON-RPC response to a previously made method call.
*
* @param messageId - The id of the message to handle.
* @param response - The response to handle.
*/
handleResponse(messageId: string, response: unknown): void;
/**
* Rejects all unresolved messages with an error.
*
* @param error - The error to reject the messages with.
*/
rejectAll(error: Error): void;
}
//# sourceMappingURL=RpcClient.d.mts.map