@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
77 lines • 3.63 kB
text/typescript
import type { Messenger } from "@metamask/messenger";
import type { PermissionSpecificationBuilder, RestrictedMethodOptions, PermissionValidatorConstraint, PermissionSideEffect } from "@metamask/permission-controller";
import { PermissionType } from "@metamask/permission-controller";
import type { InvokeSnapParams, InvokeSnapResult, RequestSnapsParams, RequestSnapsResult } from "@metamask/snaps-sdk";
import type { NonEmptyArray } from "@metamask/utils";
import type { SnapControllerHandleRequestAction } from "../types.cjs";
export declare const WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
export type SnapControllerInstallSnapsAction = {
type: `SnapController:installSnaps`;
handler: (origin: string, requestedSnaps: RequestSnapsParams) => Promise<RequestSnapsResult>;
};
export type SnapControllerGetPermittedSnapsAction = {
type: `SnapController:getPermittedSnaps`;
handler: (origin: string) => RequestSnapsResult;
};
type AllowedActions = SnapControllerInstallSnapsAction | SnapControllerGetPermittedSnapsAction;
export type InvokeSnapMessengerActions = SnapControllerHandleRequestAction;
type InvokeSnapSpecificationBuilderOptions = {
allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
messenger: Messenger<string, InvokeSnapMessengerActions>;
};
/**
* The side-effect method to handle the snap install.
*
* @param params - The side-effect params.
* @param params.requestData - The request data associated to the requested permission.
* @param params.messenger - The messenger to call an action.
* @returns The result of the Snap installation.
*/
export declare const handleSnapInstall: PermissionSideEffect<AllowedActions, never>['onPermitted'];
/**
* Calls the specified JSON-RPC API method of the specified Snap. The Snap
* must be installed and the dapp must have permission to communicate with the
* Snap, or the request is rejected. The dapp can install the Snap and request
* permission to communicate with it using
* [`wallet_requestSnaps`](http://docs.metamask.io/snaps/reference/snaps-api/wallet_requestsnaps).
*
* @example
* ```ts
* const result = await ethereum.request({
* method: 'wallet_snap',
* params: {
* snapId: 'npm:my-snap',
* request: {
* method: 'hello',
* params: { name: 'world' },
* },
* },
* });
* console.log(result); // "Hello, world!"
* ```
*/
export declare const invokeSnapBuilder: Readonly<{
readonly targetName: "wallet_snap";
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, InvokeSnapSpecificationBuilderOptions, {
permissionType: PermissionType.RestrictedMethod;
targetName: typeof WALLET_SNAP_PERMISSION_KEY;
methodImplementation: ReturnType<typeof getInvokeSnapImplementation>;
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
validator: PermissionValidatorConstraint;
sideEffect: {
onPermitted: PermissionSideEffect<AllowedActions, never>['onPermitted'];
};
}>;
readonly actionNames: readonly ["SnapController:handleRequest"];
}>;
/**
* Builds the method implementation for `wallet_snap_*`.
*
* @param options - The options.
* @param options.messenger - The messenger.
* @returns The method implementation which returns the result of `SnapController:handleRequest`.
* @throws If the params are invalid.
*/
export declare function getInvokeSnapImplementation({ messenger, }: InvokeSnapSpecificationBuilderOptions): (options: RestrictedMethodOptions<InvokeSnapParams>) => Promise<InvokeSnapResult>;
export {};
//# sourceMappingURL=invokeSnap.d.cts.map