diff --git a/packages/snaps-rpc-methods/src/permitted/cancelBackgroundEvent.ts b/packages/snaps-rpc-methods/src/permitted/cancelBackgroundEvent.ts index 1059ea373c..c47883aa2c 100644 --- a/packages/snaps-rpc-methods/src/permitted/cancelBackgroundEvent.ts +++ b/packages/snaps-rpc-methods/src/permitted/cancelBackgroundEvent.ts @@ -25,6 +25,26 @@ export type CancelBackgroundEventMethodHooks = { hasPermission: (permissionName: string) => boolean; }; +/** + * Cancel a background event created by + * [`snap_scheduleBackgroundEvent`](https://docs.metamask.io/snaps/reference/snaps-api/snap_schedulebackgroundevent). + * + * @example + * ```ts + * const id = snap.request({ + * method: 'snap_scheduleBackgroundEvent', + * params: { + * // ... + * }, + * }); + * + * // Later, when you want to cancel the background event: + * snap.request({ + * method: 'snap_cancelBackgroundEvent', + * params: { id }, + * }); + * ``` + */ export const cancelBackgroundEventHandler = { methodNames: [methodName] as const, implementation: getCancelBackgroundEventImplementation, diff --git a/packages/snaps-rpc-methods/src/permitted/clearState.ts b/packages/snaps-rpc-methods/src/permitted/clearState.ts index 021e36eaf9..0cf12d74bb 100644 --- a/packages/snaps-rpc-methods/src/permitted/clearState.ts +++ b/packages/snaps-rpc-methods/src/permitted/clearState.ts @@ -23,7 +23,17 @@ const hookNames: MethodHooksObject = { }; /** - * `snap_clearState` clears the state of the Snap. + * Clear the entire state of the Snap. + * + * @example + * ```ts + * await snap.request({ + * method: 'snap_clearState', + * params: { + * encrypted: true, // Optional, defaults to true + * }, + * }); + * ``` */ export const clearStateHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/closeWebSocket.ts b/packages/snaps-rpc-methods/src/permitted/closeWebSocket.ts index c4eac35a5e..4f58ea3f13 100644 --- a/packages/snaps-rpc-methods/src/permitted/closeWebSocket.ts +++ b/packages/snaps-rpc-methods/src/permitted/closeWebSocket.ts @@ -35,7 +35,8 @@ export type CloseWebSocketParameters = InferMatching< >; /** - * Handler for the `snap_closeWebSocket` method. + * Closes a WebSocket connection that was previously opened with + * [`snap_openWebSocket`](https://docs.metamask.io/snaps/reference/snaps-api/snap_openwebsocket). */ export const closeWebSocketHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/createInterface.ts b/packages/snaps-rpc-methods/src/permitted/createInterface.ts index 1bafbe8dec..1bf1dbf6b4 100644 --- a/packages/snaps-rpc-methods/src/permitted/createInterface.ts +++ b/packages/snaps-rpc-methods/src/permitted/createInterface.ts @@ -47,6 +47,27 @@ export type CreateInterfaceMethodHooks = { ) => string; }; +/** + * Create an interactive interface for use in + * [interactive UI](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/). + * + * @example + * ```tsx + * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx'; + * + * const interfaceId = snap.request({ + * method: 'snap_createInterface', + * params: { + * ui: ( + * + * Example Interface + * This is an example interface created by "snap_createInterface". + * + * ), + * }, + * }); + * ``` + */ export const createInterfaceHandler = { methodNames: [methodName] as const, implementation: getCreateInterfaceImplementation, diff --git a/packages/snaps-rpc-methods/src/permitted/endTrace.ts b/packages/snaps-rpc-methods/src/permitted/endTrace.ts index abb13e51d8..f49aa55576 100644 --- a/packages/snaps-rpc-methods/src/permitted/endTrace.ts +++ b/packages/snaps-rpc-methods/src/permitted/endTrace.ts @@ -56,7 +56,8 @@ export type EndTraceParameters = InferMatching< >; /** - * Handler for the `snap_endTrace` method. + * End a performance trace in Sentry. This method is only available to + * preinstalled Snaps. * * @internal */ diff --git a/packages/snaps-rpc-methods/src/permitted/getBackgroundEvents.ts b/packages/snaps-rpc-methods/src/permitted/getBackgroundEvents.ts index 0bb9a8a36c..3836157894 100644 --- a/packages/snaps-rpc-methods/src/permitted/getBackgroundEvents.ts +++ b/packages/snaps-rpc-methods/src/permitted/getBackgroundEvents.ts @@ -24,6 +24,30 @@ export type GetBackgroundEventsMethodHooks = { hasPermission: (permissionName: string) => boolean; }; +/** + * Get the scheduled background events for the Snap. + * + * @example + * ```ts + * const events = await snap.request({ + * method: 'snap_getBackgroundEvents', + * }); + * console.log(events); + * // [ + * // { + * // id: 'event-1', + * // scheduledAt: 1672531200000, + * // snapId: 'npm:example-snap', + * // date: 1672531200000, + * // request: { + * // method: 'example_method', + * // params: { example: 'data' }, + * // }, + * // }, + * // ..., + * // ] + * ``` + */ export const getBackgroundEventsHandler = { methodNames: [methodName] as const, implementation: getGetBackgroundEventsImplementation, diff --git a/packages/snaps-rpc-methods/src/permitted/getClientStatus.ts b/packages/snaps-rpc-methods/src/permitted/getClientStatus.ts index e0b40a4f74..ee18a89944 100644 --- a/packages/snaps-rpc-methods/src/permitted/getClientStatus.ts +++ b/packages/snaps-rpc-methods/src/permitted/getClientStatus.ts @@ -19,7 +19,31 @@ const hookNames: MethodHooksObject = { }; /** - * `snap_getClientStatus` returns useful information about the client running the snap. + * Get the status of the client running the Snap. + * + * @example + * ```ts + * import type { OnCronjobHandler } from '@metamask/snaps-sdk' + * import { MethodNotFoundError } from '@metamask/snaps-sdk' + * + * export const onCronjob: OnCronjobHandler = async ({ request }) => { + * switch (request.method) { + * case 'execute': + * // Find out if MetaMask is locked. + * const { locked } = await snap.request({ + * method: 'snap_getClientStatus', + * }) + * + * if (!locked) { + * // Do something that requires MetaMask to be unlocked, such as + * // accessing the encrypted state. + * } + * + * default: + * throw new MethodNotFoundError() + * } + * } + * ``` */ export const getClientStatusHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/getFile.ts b/packages/snaps-rpc-methods/src/permitted/getFile.ts index 018238f368..3bee7487cc 100644 --- a/packages/snaps-rpc-methods/src/permitted/getFile.ts +++ b/packages/snaps-rpc-methods/src/permitted/getFile.ts @@ -32,6 +32,32 @@ const hookNames: MethodHooksObject = { getSnapFile: true, }; +/** + * Gets a static file's content in UTF-8, Base64, or hexadecimal. + * + * The file must be specified in [the Snap's manifest file](https://docs.metamask.io/snaps/features/static-files/). + * + * @example + * ```json name="Manifest" + * { + * "source": { + * "files": ["./files/my-file.bin"] + * } + * } + * ``` + * ```ts name="Usage" + * const contents = await snap.request({ + * method: 'snap_getFile', + * params: { + * path: './files/myfile.bin', + * encoding: 'hex', + * }, + * }) + * + * // '0x...' + * console.log(contents) + * ``` + */ export const getFileHandler = { methodNames: [methodName] as const, implementation, diff --git a/packages/snaps-rpc-methods/src/permitted/getInterfaceContext.ts b/packages/snaps-rpc-methods/src/permitted/getInterfaceContext.ts index 84989c56c9..ed08dbf917 100644 --- a/packages/snaps-rpc-methods/src/permitted/getInterfaceContext.ts +++ b/packages/snaps-rpc-methods/src/permitted/getInterfaceContext.ts @@ -35,6 +35,42 @@ export type GetInterfaceContextMethodHooks = { getInterfaceContext: (id: string) => InterfaceContext | null; }; +/** + * Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/) + * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface). + * + * @example + * ```ts + * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx'; + * + * const interfaceId = await snap.request({ + * method: 'snap_createInterface', + * params: { + * ui: ( + * + * Hello, world! + * Welcome to my Snap homepage! + * + * ), + * context: { + * key: 'value' + * } + * }, + * }) + * + * const context = await snap.request({ + * method: 'snap_getInterfaceContext', + * params: { + * id: interfaceId, + * }, + * }) + * + * console.log(context) + * // { + * // key: 'value' + * // } + * ``` + */ export const getInterfaceContextHandler = { methodNames: [methodName] as const, implementation: getInterfaceContextImplementation, diff --git a/packages/snaps-rpc-methods/src/permitted/getInterfaceState.ts b/packages/snaps-rpc-methods/src/permitted/getInterfaceState.ts index 5c9c6c282e..4863dbda92 100644 --- a/packages/snaps-rpc-methods/src/permitted/getInterfaceState.ts +++ b/packages/snaps-rpc-methods/src/permitted/getInterfaceState.ts @@ -35,6 +35,20 @@ export type GetInterfaceStateMethodHooks = { getInterfaceState: (id: string) => InterfaceState; }; +/** + * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/) + * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface). + * + * @example + * ```ts + * const state = await snap.request({ + * method: 'snap_getInterfaceState', + * params: { + * id: interfaceId, + * }, + * }); + * ``` + */ export const getInterfaceStateHandler = { methodNames: [methodName] as const, implementation: getGetInterfaceStateImplementation, diff --git a/packages/snaps-rpc-methods/src/permitted/getSnaps.ts b/packages/snaps-rpc-methods/src/permitted/getSnaps.ts index 0509802d30..a42a750d37 100644 --- a/packages/snaps-rpc-methods/src/permitted/getSnaps.ts +++ b/packages/snaps-rpc-methods/src/permitted/getSnaps.ts @@ -12,7 +12,25 @@ const hookNames: MethodHooksObject = { }; /** - * `wallet_getSnaps` gets the requester's permitted and installed Snaps. + * Get permitted and installed Snaps for the requesting origin. + * + * @example + * ```ts + * const snaps = await snap.request({ + * method: 'wallet_getSnaps', + * }); + * console.log(snaps); + * // { + * // 'npm:example-snap': { + * // id: 'npm:example-snap', + * // version: '1.0.0', + * // initialPermissions: { ... }, + * // blocked: false, + * // enabled: true, + * // }, + * // ..., + * // } + * ``` */ export const getSnapsHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/getState.ts b/packages/snaps-rpc-methods/src/permitted/getState.ts index 12bf97f30d..c42c8e5b4e 100644 --- a/packages/snaps-rpc-methods/src/permitted/getState.ts +++ b/packages/snaps-rpc-methods/src/permitted/getState.ts @@ -30,7 +30,28 @@ const hookNames: MethodHooksObject = { }; /** - * `snap_getState` gets the state of the Snap. + * Get the state of the Snap, or a specific value within the state. By default, + * the data is automatically encrypted using a Snap-specific key and + * automatically decrypted when retrieved. You can set `encrypted` to `false` to + * use unencrypted storage (available when the client is locked). + * + * @example + * ```json name="Manifest" + * { + * "initialPermissions": { + * "snap_manageState": {} + * } + * } + * ``` + * ```ts name="Usage" + * const state = await snap.request({ + * method: 'snap_getState', + * params: { + * key: 'some.nested.value', // Optional, defaults to entire state + * encrypted: true, // Optional, defaults to `true` + * }, + * }); + * ``` */ export const getStateHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/getWebSockets.ts b/packages/snaps-rpc-methods/src/permitted/getWebSockets.ts index 56ebe9b92e..57a6c08abf 100644 --- a/packages/snaps-rpc-methods/src/permitted/getWebSockets.ts +++ b/packages/snaps-rpc-methods/src/permitted/getWebSockets.ts @@ -24,7 +24,7 @@ export type GetWebSocketsMethodHooks = { }; /** - * Handler for the `snap_getWebSockets` method. + * Get the connected WebSockets for the Snap. */ export const getWebSocketsHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/invokeKeyring.ts b/packages/snaps-rpc-methods/src/permitted/invokeKeyring.ts index dd924c2f91..d5144bee7e 100644 --- a/packages/snaps-rpc-methods/src/permitted/invokeKeyring.ts +++ b/packages/snaps-rpc-methods/src/permitted/invokeKeyring.ts @@ -28,7 +28,12 @@ const hookNames: MethodHooksObject = { }; /** - * `wallet_invokeKeyring` gets the requester's permitted and installed Snaps. + * Invoke a keyring method of a Snap. This calls the `onKeyringRequest` handler + * of the 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`](https://docs.metamask.io/snaps/reference/snaps-api/wallet_requestsnaps). */ export const invokeKeyringHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/invokeSnapSugar.ts b/packages/snaps-rpc-methods/src/permitted/invokeSnapSugar.ts index 44fd861ccd..eeab21b1ef 100644 --- a/packages/snaps-rpc-methods/src/permitted/invokeSnapSugar.ts +++ b/packages/snaps-rpc-methods/src/permitted/invokeSnapSugar.ts @@ -8,11 +8,33 @@ import type { InvokeSnapParams, InvokeSnapResult } from '@metamask/snaps-sdk'; import type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils'; import { isObject } from '@metamask/utils'; -/** - * `wallet_invokeSnap` attempts to invoke an RPC method of the specified Snap. - */ const methodName = 'wallet_invokeSnap'; +/** + * Invoke a method of a Snap, designated by the `snapId` parameter, with a + * JSON-RPC request specified in the `request` parameter. This is effectively a + * wrapper around [`wallet_snap`](https://docs.metamask.io/snaps/reference/snaps-api/wallet_snap) + * that allows for more convenient invocation of Snap methods without needing to + * specify the full `wallet_snap` parameters. + * + * 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`](https://docs.metamask.io/snaps/reference/snaps-api/wallet_requestsnaps). + * + * @example + * ```ts + * const result = await snap.request({ + * method: 'wallet_invokeSnap', + * params: { + * snapId: 'npm:@metamask/example-snap', + * request: { + * method: 'someMethod', + * params: { some: 'params' }, + * }, + * }, + * }); + * ``` + */ export const invokeSnapSugarHandler = { methodNames: [methodName] as const, implementation: invokeSnapSugar, diff --git a/packages/snaps-rpc-methods/src/permitted/listEntropySources.ts b/packages/snaps-rpc-methods/src/permitted/listEntropySources.ts index 16a54e4dba..b7a0c91940 100644 --- a/packages/snaps-rpc-methods/src/permitted/listEntropySources.ts +++ b/packages/snaps-rpc-methods/src/permitted/listEntropySources.ts @@ -58,6 +58,16 @@ export type ListEntropySourcesHooks = { getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise; }; +/** + * Get a list of entropy sources available to the Snap. The requesting origin + * must have at least one of the following permissions to access entropy source + * metadata: + * + * - `snap_getBip32Entropy` + * - `snap_getBip32PublicKey` + * - `snap_getBip44Entropy` + * - `snap_getEntropy` + */ export const listEntropySourcesHandler = { methodNames: [methodName] as const, implementation: listEntropySourcesImplementation, diff --git a/packages/snaps-rpc-methods/src/permitted/openWebSocket.ts b/packages/snaps-rpc-methods/src/permitted/openWebSocket.ts index 137fbb1e81..40edf2e89c 100644 --- a/packages/snaps-rpc-methods/src/permitted/openWebSocket.ts +++ b/packages/snaps-rpc-methods/src/permitted/openWebSocket.ts @@ -45,7 +45,50 @@ export type OpenWebSocketParameters = InferMatching< >; /** - * Handler for the `snap_openWebSocket` method. + * Open a WebSocket connection to the specified URL with optional protocols. + * + * Note: This method is only available to snaps that have the + * [`endowment:network-access`](https://docs.metamask.io/snaps/features/network-access/) + * permission. + * + * @example + * ```json name="Manifest" + * { + * "initialPermissions": { + * "endowment:network-access": {} + * } + * } + * ``` + * ```ts name="Usage" + * // Open a connection to a WebSocket server, e.g., in the JSON-RPC handler of + * // the Snap: + * snap.request({ + * method: 'snap_openWebSocket', + * params: { + * url: 'wss://example.com/socket', + * protocols: ['protocol1', 'protocol2'], // Optional + * }, + * }); + * + * // Listen for events from the WebSocket connection in the `onWebSocketEvent` + * // handler of the Snap: + * export const onWebSocketEvent: OnWebSocketEventHandler = async ({ event }) => { + * switch (event.type) { + * case 'open': + * console.log(`WebSocket connection opened with origin ${event.origin}`); + * break; + * case 'message': + * console.log(`WebSocket message received from origin ${event.origin}:`, event.data); + * break; + * case 'close': + * console.log(`WebSocket connection closed with origin ${event.origin}`); + * break; + * case 'error': + * console.error(`WebSocket error from origin ${event.origin}:`, event.error); + * break; + * } + * }; + * ``` */ export const openWebSocketHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/requestSnaps.ts b/packages/snaps-rpc-methods/src/permitted/requestSnaps.ts index 19c70e0c94..a9bf5d91bf 100644 --- a/packages/snaps-rpc-methods/src/permitted/requestSnaps.ts +++ b/packages/snaps-rpc-methods/src/permitted/requestSnaps.ts @@ -35,7 +35,18 @@ const hookNames: MethodHooksObject = { }; /** - * `wallet_requestSnaps` installs the requested Snaps and requests permission to use them if necessary. + * Request permission for a dapp to communicate with the specified Snaps and + * attempt to install them if they're not already installed. + * + * If the Snap version range is specified, MetaMask attempts to install a + * version of the Snap that satisfies the range. If a compatible version of the + * Snap is already installed, the request succeeds. If an incompatible version + * is installed, MetaMask attempts to update the Snap to the latest version that + * satisfies the range. The request succeeds if the Snap is successfully + * installed. + * + * If the installation of any Snap fails, or the user rejects the installation + * or permission request, this method returns the error that caused the failure. */ export const requestSnapsHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/resolveInterface.ts b/packages/snaps-rpc-methods/src/permitted/resolveInterface.ts index d641c7477e..e4d5c10df4 100644 --- a/packages/snaps-rpc-methods/src/permitted/resolveInterface.ts +++ b/packages/snaps-rpc-methods/src/permitted/resolveInterface.ts @@ -35,6 +35,10 @@ export type ResolveInterfaceMethodHooks = { resolveInterface: (id: string, value: Json) => Promise; }; +/** + * Resolve an interactive interface. For use in + * [custom dialogs](https://docs.metamask.io/snaps/features/custom-ui/dialogs/#display-a-custom-dialog). + */ export const resolveInterfaceHandler = { methodNames: [methodName] as const, implementation: getResolveInterfaceImplementation, diff --git a/packages/snaps-rpc-methods/src/permitted/scheduleBackgroundEvent.ts b/packages/snaps-rpc-methods/src/permitted/scheduleBackgroundEvent.ts index 8d606dc71e..e849e9f127 100644 --- a/packages/snaps-rpc-methods/src/permitted/scheduleBackgroundEvent.ts +++ b/packages/snaps-rpc-methods/src/permitted/scheduleBackgroundEvent.ts @@ -39,6 +39,32 @@ export type ScheduleBackgroundEventMethodHooks = { hasPermission: (permissionName: string) => boolean; }; +/** + * Schedule a background event for a Snap. The background event will trigger a + * JSON-RPC request to the Snap at the scheduled time, handled by the + * `onCronjob` entry point in the Snap. + * + * The schedule can be defined using either an ISO 8601 date or duration string. + * For example: + * + * - Using a date: `2026-12-31T23:59:59Z` + * - Using a duration: `P1DT2H` (which represents a duration of 1 day and 2 + * hours) + * + * @example + * ```ts + * const id = await wallet.request({ + * method: 'snap_scheduleBackgroundEvent', + * params: { + * date: '2026-12-31T23:59:59Z', + * request: { + * method: 'mySnapMethod', + * params: { foo: 'bar' }, + * }, + * }, + * }); + * ``` + */ export const scheduleBackgroundEventHandler = { methodNames: [methodName] as const, implementation: getScheduleBackgroundEventImplementation, diff --git a/packages/snaps-rpc-methods/src/permitted/sendWebSocketMessage.ts b/packages/snaps-rpc-methods/src/permitted/sendWebSocketMessage.ts index d6bef54dd7..a2728d17c3 100644 --- a/packages/snaps-rpc-methods/src/permitted/sendWebSocketMessage.ts +++ b/packages/snaps-rpc-methods/src/permitted/sendWebSocketMessage.ts @@ -44,7 +44,21 @@ export type SendWebSocketMessageParameters = InferMatching< >; /** - * Handler for the `snap_sendWebSocketMessage` method. + * Send a message to an open WebSocket connection. The message will be sent to + * the WebSocket connection with the specified ID, which must have been + * previously opened by the snap using the [`snap_openWebSocket`](https://docs.metamask.io/snaps/reference/snaps-api/snap_openwebsocket/) + * method. + * + * @example + * ```ts + * await wallet.request({ + * method: 'snap_sendWebSocketMessage', + * params: { + * id: 'websocket-connection-id', + * message: 'Hello, WebSocket!', // or message: [1, 2, 3] for binary data + * }, + * }); + * ``` */ export const sendWebSocketMessageHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/setState.ts b/packages/snaps-rpc-methods/src/permitted/setState.ts index 5410e972a7..c041eaa8cd 100644 --- a/packages/snaps-rpc-methods/src/permitted/setState.ts +++ b/packages/snaps-rpc-methods/src/permitted/setState.ts @@ -45,7 +45,52 @@ const hookNames: MethodHooksObject = { }; /** - * `snap_setState` sets the state of the Snap. + * Allow the Snap to persist up to 64 MB of data to disk and retrieve it at + * will. By default, the data is automatically encrypted using a Snap-specific + * key and automatically decrypted when retrieved. You can set `encrypted` to + * `false` to use unencrypted storage (available when the client is locked). + * + * If the key is `undefined`, the value is expected to be an object. In this + * case, the value is set as the new root state. + * + * If the key is not `undefined`, the value is set in the state at the key. If + * the key does not exist, it is created (and any missing intermediate keys are + * created as well). + * + * @example + * ```json name="Manifest" + * { + * "initialPermissions": { + * "snap_manageState": {} + * } + * } + * ``` + * ```ts name="Usage" + * // Set the entire state: + * await snap.request({ + * method: 'snap_setState', + * params: { + * value: { + * some: { + * nested: { + * value: 'Hello, world!', + * }, + * }, + * }, + * encrypted: true, // Optional, defaults to `true` + * }, + * }); + * + * // Set a specific value within the state: + * await snap.request({ + * method: 'snap_setState', + * params: { + * key: 'some.nested.value', + * value: 'Hello, world!', + * encrypted: true, // Optional, defaults to `true` + * }, + * }); + * ``` */ export const setStateHandler = { methodNames: [methodName] as const, diff --git a/packages/snaps-rpc-methods/src/permitted/updateInterface.ts b/packages/snaps-rpc-methods/src/permitted/updateInterface.ts index 8d4cfaa624..3561e6e5f4 100644 --- a/packages/snaps-rpc-methods/src/permitted/updateInterface.ts +++ b/packages/snaps-rpc-methods/src/permitted/updateInterface.ts @@ -51,6 +51,10 @@ export type UpdateInterfaceMethodHooks = { ) => void; }; +/** + * Update an interactive interface. For use in + * [interactive UI](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/). + */ export const updateInterfaceHandler = { methodNames: [methodName] as const, implementation: getUpdateInterfaceImplementation, diff --git a/packages/snaps-rpc-methods/src/restricted/dialog.ts b/packages/snaps-rpc-methods/src/restricted/dialog.ts index a6bb1a1bcb..aa6269f172 100644 --- a/packages/snaps-rpc-methods/src/restricted/dialog.ts +++ b/packages/snaps-rpc-methods/src/restricted/dialog.ts @@ -20,6 +20,7 @@ import type { ComponentOrElement, InterfaceContext, ContentType, + DialogResult, } from '@metamask/snaps-sdk'; import type { InferMatching } from '@metamask/snaps-utils'; import type { Infer } from '@metamask/superstruct'; @@ -145,6 +146,32 @@ const methodHooks: MethodHooksObject = { getInterface: true, }; +/** + * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/) + * in the MetaMask UI. + * + * @example + * ```ts + * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx'; + * + * const walletAddress = await snap.request({ + * method: 'snap_dialog', + * params: { + * type: 'prompt', + * content: ( + * + * What is the wallet address? + * Please enter the wallet address to be monitored. + * + * ), + * placeholder: '0x123...', + * }, + * }); + * + * // `walletAddress` will be a string containing the address entered by the + * // user. + * ``` + */ export const dialogBuilder = Object.freeze({ targetName: methodName, specificationBuilder, @@ -245,8 +272,6 @@ export type DialogParameters = InferMatching< DialogParams >; -type DialogResult = Json; - /** * Builds the method implementation for `snap_dialog`. * diff --git a/packages/snaps-rpc-methods/src/restricted/getBip32Entropy.ts b/packages/snaps-rpc-methods/src/restricted/getBip32Entropy.ts index ecb67f6727..ae16964e7b 100644 --- a/packages/snaps-rpc-methods/src/restricted/getBip32Entropy.ts +++ b/packages/snaps-rpc-methods/src/restricted/getBip32Entropy.ts @@ -114,6 +114,61 @@ const methodHooks: MethodHooksObject = { getClientCryptography: true, }; +/** + * Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/) + * by deriving the [SLIP-10](https://github.com/satoshilabs/slips/blob/master/slip-0010.md) + * keys specified by the `path` and `curve` parameters. The keys are derived + * using the entropy from the user's Secret Recovery Phrase. + * + * If the keys you want to derive conform to the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) + * structure, use [snap_getBip44Entropy](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip44entropy) + * instead. Otherwise, use this method. + * + * This method is designed to be used with the [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree) + * module. `@metamask/key-tree` can help you get the [extended private keys](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys) + * for user addresses, but it's your responsibility to know how to use those + * keys to, for example, derive an address for the relevant protocol or sign a + * transaction for the user. + * + * @example + * ```json name="Manifest" + * { + * "initialPermissions": { + * "snap_getBip32Entropy": [ + * { + * "path": ["m", "44'", "3'"], + * "curve": "secp256k1" // Or "ed25519", "ed25519Bip32" + * } + * ] + * } + * } + * ``` + * ```ts name="Usage" + * import { SLIP10Node } from '@metamask/key-tree' + * + * // This example uses Dogecoin, which has a derivation path starting with + * // m/44'/3'. + * const dogecoinNode = await snap.request({ + * method: 'snap_getBip32Entropy', + * params: { + * // The path and curve must be specified in the initial permissions. + * path: ['m', "44'", "3'"], + * curve: 'secp256k1', + * }, + * }) + * + * // Next, create an instance of a SLIP-10 node for the Dogecoin node. + * const dogecoinSlip10Node = await SLIP10Node.fromJSON(dogecoinNode) + * + * // m/44'/3'/0' + * const accountKey0 = await dogecoinSlip10Node.derive(["bip32:0'"]) + * + * // m/44'/3'/1' + * const accountKey1 = await dogecoinSlip10Node.derive(["bip32:1'"]) + * + * // Now, you can ask the user to sign transactions, etc. + * ``` + */ export const getBip32EntropyBuilder = Object.freeze({ targetName, specificationBuilder, diff --git a/packages/snaps-rpc-methods/src/restricted/getBip32PublicKey.ts b/packages/snaps-rpc-methods/src/restricted/getBip32PublicKey.ts index 5340ec7f6f..45ab805657 100644 --- a/packages/snaps-rpc-methods/src/restricted/getBip32PublicKey.ts +++ b/packages/snaps-rpc-methods/src/restricted/getBip32PublicKey.ts @@ -129,6 +129,42 @@ const methodHooks: MethodHooksObject = { getClientCryptography: true, }; +/** + * Gets the [BIP-32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) + * public key for the derivation path specified by the `path` parameter. Note + * that this returns the public key, not the extended public key (`xpub`), or + * Ethereum address. + * + * @example + * ```json name="Manifest" + * { + * "initialPermissions": { + * "snap_getBip32PublicKey": [ + * { + * "path": ["m", "44'", "3'", "0'", "0", "0"], + * "curve": "secp256k1" + * } + * ] + * } + * } + * ``` + * ```ts name="Usage" + * // This example uses Dogecoin, which has a derivation path starting with + * // "m / 44' / 3'". + * const dogecoinPublicKey = await snap.request({ + * method: 'snap_getBip32PublicKey', + * params: { + * // The path and curve must be specified in the initial permissions. + * path: ['m', "44'", "3'", "0'", "0", "0"], + * curve: 'secp256k1', + * compressed: false, + * }, + * }) + * + * // '0x...' + * console.log(dogecoinPublicKey) + * ``` + */ export const getBip32PublicKeyBuilder = Object.freeze({ targetName, specificationBuilder, diff --git a/packages/snaps-rpc-methods/src/restricted/getBip44Entropy.ts b/packages/snaps-rpc-methods/src/restricted/getBip44Entropy.ts index 990a8e4b49..f7ec1beb43 100644 --- a/packages/snaps-rpc-methods/src/restricted/getBip44Entropy.ts +++ b/packages/snaps-rpc-methods/src/restricted/getBip44Entropy.ts @@ -100,6 +100,59 @@ const methodHooks: MethodHooksObject = { getClientCryptography: true, }; +/** + * Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/) + * by deriving the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) + * keys specified by the `coinType` parameter. The keys are derived using the + * entropy from the user's Secret Recovery Phrase. + * + * If the keys you want to derive don't conform to the BIP-44 structure, use + * [`snap_getBip32Entropy`](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip32entropy) + * instead. + * + * This method is designed to be used with the [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree) + * module. `@metamask/key-tree` can help you get the [extended private keys](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys) + * for user addresses, but it's your responsibility to know how to use those + * keys to, for example, derive an address for the relevant protocol or sign a + * transaction for the user. + * + * @example + * ```json name="Manifest" + * { + * "initialPermissions": { + * "snap_getBip44Entropy": [ + * { + * "coinType": 3 + * } + * ] + * } + * } + * ``` + * ```ts name="Usage" + * import { getBIP44AddressKeyDeriver } from '@metamask/key-tree' + * + * // This example uses Dogecoin, which has coin_type 3. + * const dogecoinNode = await snap.request({ + * method: 'snap_getBip44Entropy', + * params: { + * coinType: 3, + * }, + * }) + * + * // Next, create an address key deriver function for the Dogecoin coin_type + * // node. In this case, its path is: m/44'/3'/0'/0/address_index + * const deriveDogecoinAddress = await getBIP44AddressKeyDeriver(dogecoinNode) + * + * // These are BIP-44 nodes containing the extended private keys for the + * // respective derivation paths. + * + * // m/44'/3'/0'/0/0 + * const addressKey0 = await deriveDogecoinAddress(0) + * + * // m/44'/3'/0'/0/1 + * const addressKey1 = await deriveDogecoinAddress(1) + * ``` + */ export const getBip44EntropyBuilder = Object.freeze({ targetName, specificationBuilder, diff --git a/packages/snaps-rpc-methods/src/restricted/getEntropy.ts b/packages/snaps-rpc-methods/src/restricted/getEntropy.ts index 5146dcd6b0..b493452548 100644 --- a/packages/snaps-rpc-methods/src/restricted/getEntropy.ts +++ b/packages/snaps-rpc-methods/src/restricted/getEntropy.ts @@ -67,6 +67,41 @@ const methodHooks: MethodHooksObject = { getClientCryptography: true, }; +/** + * Get a deterministic 256-bit entropy value, specific to the Snap and the + * user's account. You can use this entropy to generate a private key, or any + * other value that requires a high level of randomness. Other Snaps can't + * access this entropy, and it changes if the user's secret recovery phrase + * changes. + * + * You can optionally specify a salt to generate different entropy for different + * purposes. Using a salt results in entropy unrelated to the entropy generated + * without a salt. + * + * This value is deterministic: it's always the same for the same Snap, user + * account, and salt. + * + * @example + * ```json name="Manifest" + * { + * "initialPermissions": { + * "snap_getEntropy": {} + * } + * } + * ``` + * ```ts name="Usage" + * const entropy = await snap.request({ + * method: 'snap_getEntropy', + * params: { + * version: 1, + * salt: 'foo', // Optional. + * }, + * }) + * + * // '0x...' + * console.log(entropy) + * ``` + */ export const getEntropyBuilder = Object.freeze({ targetName, specificationBuilder, diff --git a/packages/snaps-rpc-methods/src/restricted/getLocale.ts b/packages/snaps-rpc-methods/src/restricted/getLocale.ts index 4d3aa3a944..51b2416c88 100644 --- a/packages/snaps-rpc-methods/src/restricted/getLocale.ts +++ b/packages/snaps-rpc-methods/src/restricted/getLocale.ts @@ -59,6 +59,15 @@ const methodHooks: MethodHooksObject = { getPreferences: true, }; +/** + * Get the user's locale setting. You can use this method to localize text in + * your Snap. + * + * Note that this method is deprecated. We recommend using + * [`snap_getPreferences`](https://docs.metamask.io/snaps/reference/snaps-api/snap_getpreferences) + * instead, which provides access to the user's locale as well as other + * preferences. + */ export const getLocaleBuilder = Object.freeze({ targetName: methodName, specificationBuilder, diff --git a/packages/snaps-rpc-methods/src/restricted/getPreferences.ts b/packages/snaps-rpc-methods/src/restricted/getPreferences.ts index 64dac9db94..66ab117886 100644 --- a/packages/snaps-rpc-methods/src/restricted/getPreferences.ts +++ b/packages/snaps-rpc-methods/src/restricted/getPreferences.ts @@ -55,6 +55,9 @@ const methodHooks: MethodHooksObject = { getPreferences: true, }; +/** + * Gets the user's preferences. + */ export const getPreferencesBuilder = Object.freeze({ targetName: methodName, specificationBuilder, diff --git a/packages/snaps-rpc-methods/src/restricted/invokeSnap.ts b/packages/snaps-rpc-methods/src/restricted/invokeSnap.ts index e69eb1926d..4d177e1152 100644 --- a/packages/snaps-rpc-methods/src/restricted/invokeSnap.ts +++ b/packages/snaps-rpc-methods/src/restricted/invokeSnap.ts @@ -141,6 +141,13 @@ const methodHooks: MethodHooksObject = { handleSnapRpcRequest: true, }; +/** + * 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). + */ export const invokeSnapBuilder = Object.freeze({ targetName: WALLET_SNAP_PERMISSION_KEY, specificationBuilder, diff --git a/packages/snaps-rpc-methods/src/restricted/manageAccounts.ts b/packages/snaps-rpc-methods/src/restricted/manageAccounts.ts index 9afe4525de..52eadc9340 100644 --- a/packages/snaps-rpc-methods/src/restricted/manageAccounts.ts +++ b/packages/snaps-rpc-methods/src/restricted/manageAccounts.ts @@ -122,6 +122,16 @@ export function manageAccountsImplementation({ }; } +/** + * Manage account management Snap accounts. This method is organized into + * multiple sub-methods which each take their own parameters: + * + * - `createAccount` + * - `updateAccount` + * - `deleteAccount` + * - `listAccounts` + * - `submitResponse` + */ export const manageAccountsBuilder = Object.freeze({ targetName: methodName, specificationBuilder, diff --git a/packages/snaps-rpc-methods/src/restricted/manageState.ts b/packages/snaps-rpc-methods/src/restricted/manageState.ts index 4f85a6433a..bb0372c4ec 100644 --- a/packages/snaps-rpc-methods/src/restricted/manageState.ts +++ b/packages/snaps-rpc-methods/src/restricted/manageState.ts @@ -113,6 +113,48 @@ const methodHooks: MethodHooksObject = { getSnap: true, }; +/** + * Allow the Snap to persist up to 64 MB of data to disk and retrieve it at + * will. By default, the data is automatically encrypted using a Snap-specific + * key and automatically decrypted when retrieved. You can set `encrypted` to + * `false` to use unencrypted storage (available when the client is locked). + * + * @example + * ```json name="Manifest" + * { + * "initialPermissions": { + * "snap_manageState": {} + * } + * } + * ``` + * ```ts name="Usage" + * // Persist some data. + * await snap.request({ + * method: 'snap_manageState', + * params: { + * operation: 'update', + * newState: { hello: 'world' }, + * }, + * }) + * + * // At a later time, get the stored data. + * const persistedData = await snap.request({ + * method: 'snap_manageState', + * params: { operation: 'get' }, + * }) + * + * console.log(persistedData) + * // { hello: 'world' } + * + * // If there's no need to store data anymore, clear it out. + * await snap.request({ + * method: 'snap_manageState', + * params: { + * operation: 'clear', + * }, + * }) + * ``` + */ export const manageStateBuilder = Object.freeze({ targetName: methodName, specificationBuilder, diff --git a/packages/snaps-rpc-methods/src/restricted/notify.ts b/packages/snaps-rpc-methods/src/restricted/notify.ts index 4b5c184f27..ee07043791 100644 --- a/packages/snaps-rpc-methods/src/restricted/notify.ts +++ b/packages/snaps-rpc-methods/src/restricted/notify.ts @@ -143,6 +143,16 @@ const methodHooks: MethodHooksObject = { getSnap: true, }; +/** + * Display a + * [notification](https://docs.metamask.io/snaps/features/notifications/) in + * MetaMask or natively in the OS. Snaps can trigger a short (up to 80 + * characters) notification message for actionable or time sensitive + * information. `inApp` notifications can also include an optional + * [expanded view](https://docs.metamask.io/snaps/features/notifications/#expanded-view). + * The expanded view has a title, content, and optional footer link shown when + * a user clicks on the notification. + */ export const notifyBuilder = Object.freeze({ targetName: methodName, specificationBuilder, diff --git a/packages/snaps-sdk/src/types/methods/close-web-socket.ts b/packages/snaps-sdk/src/types/methods/close-web-socket.ts index 100ef64669..96c028d743 100644 --- a/packages/snaps-sdk/src/types/methods/close-web-socket.ts +++ b/packages/snaps-sdk/src/types/methods/close-web-socket.ts @@ -1,7 +1,7 @@ /** * The request parameters for the `snap_closeWebSocket` method. * - * @property id - The id of the WebSocket connection to close. + * @property id - The ID of the WebSocket connection to close. */ export type CloseWebSocketParams = { id: string; diff --git a/packages/snaps-sdk/src/types/methods/create-interface.ts b/packages/snaps-sdk/src/types/methods/create-interface.ts index 79b0b6a4c7..44558dd03a 100644 --- a/packages/snaps-sdk/src/types/methods/create-interface.ts +++ b/packages/snaps-sdk/src/types/methods/create-interface.ts @@ -2,15 +2,26 @@ import type { ComponentOrElement, InterfaceContext } from '..'; /** * The request parameters for the `snap_createInterface` method. - * - * @property ui - The components to display in the interface. */ export type CreateInterfaceParams = { + /** + * The [custom UI](https://docs.metamask.io/snaps/features/custom-ui/) to + * create. + */ ui: ComponentOrElement; + + /** + * Optional context for the interface, which can be used to provide additional + * information about the interface to the Snap, without being part of the UI + * itself. + */ context?: InterfaceContext; }; /** - * The result returned by the `snap_createInterface` method, which is the id of the created interface. + * The interface's ID to be used in subsequent calls to custom UI methods such + * as [`snap_updateInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_updateinterface), + * or to display the interface using one of the interface display methods such + * as [`snap_dialog`](https://docs.metamask.io/snaps/reference/snaps-api/snap_dialog). */ export type CreateInterfaceResult = string; diff --git a/packages/snaps-sdk/src/types/methods/dialog.ts b/packages/snaps-sdk/src/types/methods/dialog.ts index 187730c8c7..3c345adedb 100644 --- a/packages/snaps-sdk/src/types/methods/dialog.ts +++ b/packages/snaps-sdk/src/types/methods/dialog.ts @@ -78,8 +78,24 @@ export type PromptDialog = placeholder?: string; }; +/* eslint-disable jsdoc/check-indentation */ /** - * The request parameters for the `snap_dialog` method. + * An object containing the contents of the dialog. + * + * - `type` - The type of dialog. Not providing a type will create a fully + * [custom dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/#display-a-custom-dialog). + * Possible values are: + * - `alert` - An alert that can only be acknowledged. + * - `confirmation` - A confirmation that can be accepted or rejected. + * - `prompt` - A prompt where the user can enter a text response. + * + * - One of: + * - `content` - The content of the alert, as a + * [custom UI](https://docs.metamask.io/snaps/features/custom-ui/) component. + * - `id` - The ID of an + * [interactive interface](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface). + * - `placeholder` - An optional placeholder text to display in the dialog. Only + * applicable for the `prompt` dialog. * * @property type - The type of dialog to display. * @property content - The content to display in the dialog. @@ -92,10 +108,9 @@ export type DialogParams = | ConfirmationDialog | PromptDialog | DefaultDialog; +/* eslint-enable jsdoc/check-indentation */ /** - * The result returned by the `snap_dialog` method. - * * - If the dialog is an `alert`, the result is `null`. * - If the dialog is a `confirmation`, the result is a boolean indicating * whether the user confirmed the dialog. diff --git a/packages/snaps-sdk/src/types/methods/get-bip32-public-key.ts b/packages/snaps-sdk/src/types/methods/get-bip32-public-key.ts index 53ed243d53..bff6c3d1dc 100644 --- a/packages/snaps-sdk/src/types/methods/get-bip32-public-key.ts +++ b/packages/snaps-sdk/src/types/methods/get-bip32-public-key.ts @@ -18,9 +18,7 @@ export type GetBip32PublicKeyParams = Bip32Entropy & { }; /** - * The result returned by the `snap_getBip32PublicKey` method. - * - * It is the public key in hexadecimal format, in either compressed or - * uncompressed format, depending on the `compressed` parameter. + * The public key as hexadecimal string. May be compressed or uncompressed + * depending on the `compressed` parameter provided in the request parameters. */ export type GetBip32PublicKeyResult = string; diff --git a/packages/snaps-sdk/src/types/methods/get-entropy.ts b/packages/snaps-sdk/src/types/methods/get-entropy.ts index 44b14bcb73..520c2b0f05 100644 --- a/packages/snaps-sdk/src/types/methods/get-entropy.ts +++ b/packages/snaps-sdk/src/types/methods/get-entropy.ts @@ -5,13 +5,14 @@ import type { Hex } from '@metamask/utils'; */ export type GetEntropyParams = { /** - * The version of the entropy to retrieve. This is used for backwards - * compatibility. As of now, only version 1 is supported. + * The version of the entropy to retrieve. This is reserved for future use, + * and as of now, only version 1 is supported. */ version: 1; /** - * The optional salt to use when deriving the entropy. + * An arbitrary string to be used as a salt for the entropy. This can be used + * to generate different entropy for different purposes. */ salt?: string | undefined; @@ -24,6 +25,6 @@ export type GetEntropyParams = { }; /** - * The result returned by the `snap_getEntropy` method. + * The entropy as a hexadecimal string. */ export type GetEntropyResult = Hex; diff --git a/packages/snaps-sdk/src/types/methods/get-file.ts b/packages/snaps-sdk/src/types/methods/get-file.ts index 608bac9e44..766fd7d62d 100644 --- a/packages/snaps-sdk/src/types/methods/get-file.ts +++ b/packages/snaps-sdk/src/types/methods/get-file.ts @@ -11,16 +11,21 @@ export enum AuxiliaryFileEncoding { /** * The request parameters for the `snap_getFile` method. - * - * @property path - The path to the file to retrieve. - * @property encoding - The encoding to use when retrieving the file. */ export type GetFileParams = { + /** + * The path to the file, relative to the Snap's package directory + * (that is, one level above `src`). + */ path: string; + + /** + * The encoding to use when retrieving the file. Defaults to `base64`. + */ encoding?: EnumToUnion; }; /** - * The result returned by the `snap_getFile` method. + * The file content as a string in the requested encoding. */ export type GetFileResult = string; diff --git a/packages/snaps-sdk/src/types/methods/get-interface-context.ts b/packages/snaps-sdk/src/types/methods/get-interface-context.ts index 587f738fc8..a11d51170d 100644 --- a/packages/snaps-sdk/src/types/methods/get-interface-context.ts +++ b/packages/snaps-sdk/src/types/methods/get-interface-context.ts @@ -3,13 +3,13 @@ import type { InterfaceContext } from '../interface'; /** * The request parameters for the `snap_getInterfaceContext` method. * - * @property id - The interface id. + * @property id - The interface ID. */ export type GetInterfaceContextParams = { id: string; }; /** - * The result returned by the `snap_getInterfaceContext` method, which is the context for a given interface. + * The context for the given interface. */ export type GetInterfaceContextResult = InterfaceContext | null; diff --git a/packages/snaps-sdk/src/types/methods/get-interface-state.ts b/packages/snaps-sdk/src/types/methods/get-interface-state.ts index 7c2253de06..970b990e51 100644 --- a/packages/snaps-sdk/src/types/methods/get-interface-state.ts +++ b/packages/snaps-sdk/src/types/methods/get-interface-state.ts @@ -3,13 +3,20 @@ import type { InterfaceState } from '../interface'; /** * The request parameters for the `snap_getInterfaceState` method. * - * @property id - The interface id. + * @property id - The interface ID. */ export type GetInterfaceStateParams = { id: string; }; /** - * The result returned by the `snap_getInterfaceState` method, which is the state of the interface. + * The state of the given interface. This is a `Record` of the form state, where + * the keys are the `name` properties of the form fields, and the values are the + * current values of those fields, depending on the type of the field. + * + * For example, for a text field, the value would be a `string`, for a checkbox + * field, the value would be a `boolean`, and for a file upload field, the value + * would be a `File` object. The exact structure of the state depends on the + * form fields that were defined when the interface was created. */ export type GetInterfaceStateResult = InterfaceState; diff --git a/packages/snaps-sdk/src/types/methods/get-locale.ts b/packages/snaps-sdk/src/types/methods/get-locale.ts index 689d46f0ac..f1cb9c68e1 100644 --- a/packages/snaps-sdk/src/types/methods/get-locale.ts +++ b/packages/snaps-sdk/src/types/methods/get-locale.ts @@ -6,8 +6,6 @@ export type GetLocaleParams = never; /** - * The result returned by the `snap_getLocale` method. - * - * It is the locale of the user's MetaMask extension. + * The user's locale setting as a [language code](https://github.com/MetaMask/metamask-extension/blob/develop/app/_locales/index.json). */ export type GetLocaleResult = string; diff --git a/packages/snaps-sdk/src/types/methods/get-preferences.ts b/packages/snaps-sdk/src/types/methods/get-preferences.ts index 3ad6d2c990..6e5eb4877d 100644 --- a/packages/snaps-sdk/src/types/methods/get-preferences.ts +++ b/packages/snaps-sdk/src/types/methods/get-preferences.ts @@ -6,20 +6,22 @@ export type GetPreferencesParams = never; /** - * The result returned by the `snap_getPreferences` method. + * An object containing the user's preferences. * - * It is the user selected preferences from the MetaMask client. - * - * @property locale - The user's selected locale. - * @property currency - The user's selected currency. + * @property locale - The user's locale setting as a language code. + * @property currency - The user's preferred fiat currency code. * @property hideBalances - Whether the user has chosen to hide balances. - * @property useSecurityAlerts - Whether to run transactions and signatures through security providers. - * @property simulateOnChainActions - Whether to simulate transactions and signatures. + * @property useSecurityAlerts - Whether to run transactions and signatures + * through security providers. + * @property simulateOnChainActions - Whether to simulate transactions and + * signatures. * @property useTokenDetection - Whether to auto-detect tokens. - * @property batchCheckBalances - Whether to fetch balances in an aggregated manner. + * @property batchCheckBalances - Whether to fetch balances in an aggregated + * manner. * @property displayNftMedia - Whether to display NFT media. * @property useNftDetection - Whether to auto-detect NFTs. - * @property useExternalPricingData - Whether to get token price data from an external source. + * @property useExternalPricingData - Whether to get token price data from an + * external source. * @property showTestnets - Whether to show testnets. */ export type GetPreferencesResult = { diff --git a/packages/snaps-sdk/src/types/methods/get-snaps.ts b/packages/snaps-sdk/src/types/methods/get-snaps.ts index 9359419744..db08e69297 100644 --- a/packages/snaps-sdk/src/types/methods/get-snaps.ts +++ b/packages/snaps-sdk/src/types/methods/get-snaps.ts @@ -10,8 +10,6 @@ import type { Snap, SnapId } from '../snap'; export type GetSnapsParams = never; /** - * The result returned by the `wallet_getSnaps` method. - * - * It consists of a map of Snap IDs to either the Snap object or an error. + * A map of Snap IDs to either the Snap metadata or an error. */ export type GetSnapsResult = Record; diff --git a/packages/snaps-sdk/src/types/methods/get-state.ts b/packages/snaps-sdk/src/types/methods/get-state.ts index e3931bca6a..55ec9af0bb 100644 --- a/packages/snaps-sdk/src/types/methods/get-state.ts +++ b/packages/snaps-sdk/src/types/methods/get-state.ts @@ -17,6 +17,7 @@ export type GetStateParams = { }; /** - * The result returned by the `snap_getState` method. + * The state of the Snap. If a key was provided in the request parameters, this + * is the value of that key in the state. Otherwise, this is the entire state. */ export type GetStateResult = Json; diff --git a/packages/snaps-sdk/src/types/methods/get-web-sockets.ts b/packages/snaps-sdk/src/types/methods/get-web-sockets.ts index 5be0cde50b..ebecc72c3a 100644 --- a/packages/snaps-sdk/src/types/methods/get-web-sockets.ts +++ b/packages/snaps-sdk/src/types/methods/get-web-sockets.ts @@ -6,7 +6,13 @@ export type GetWebSocketsParams = never; /** - * The result returned by the `snap_getWebSockets` method. + * An array of connected WebSockets for the Snap. Each WebSocket is represented + * by an object containing the following properties: + * + * - `id` - The unique identifier of the WebSocket connection. + * - `url` - The URL of the WebSocket connection. + * - `protocols` - An array of subprotocols used in the WebSocket connection (if + * any). */ export type GetWebSocketsResult = { id: string; diff --git a/packages/snaps-sdk/src/types/methods/invoke-keyring.ts b/packages/snaps-sdk/src/types/methods/invoke-keyring.ts index b2045acd35..68130a18dc 100644 --- a/packages/snaps-sdk/src/types/methods/invoke-keyring.ts +++ b/packages/snaps-sdk/src/types/methods/invoke-keyring.ts @@ -11,7 +11,6 @@ import type { InvokeSnapParams } from './invoke-snap'; export type InvokeKeyringParams = InvokeSnapParams; /** - * The result returned by the `wallet_invokeKeyring` method, which is the result - * returned by the Snap. + * The result returned by the Snap. */ export type InvokeKeyringResult = Json; diff --git a/packages/snaps-sdk/src/types/methods/invoke-snap.ts b/packages/snaps-sdk/src/types/methods/invoke-snap.ts index 654b26d920..f81c9d7ea7 100644 --- a/packages/snaps-sdk/src/types/methods/invoke-snap.ts +++ b/packages/snaps-sdk/src/types/methods/invoke-snap.ts @@ -2,17 +2,20 @@ import type { Json } from '@metamask/utils'; /** * The request parameters for the `wallet_invokeSnap` method. - * - * @property snapId - The ID of the Snap to invoke. - * @property request - The JSON-RPC request to send to the Snap. */ export type InvokeSnapParams = { + /** + * The ID of the Snap to invoke. + */ snapId: string; + + /** + * The JSON-RPC request to send to the Snap. + */ request: Record; }; /** - * The result returned by the `wallet_invokeSnap` method, which is the result - * returned by the Snap. + * The result of the Snap method call. */ export type InvokeSnapResult = Json; diff --git a/packages/snaps-sdk/src/types/methods/list-entropy-sources.ts b/packages/snaps-sdk/src/types/methods/list-entropy-sources.ts index 854dccf08d..a45ea911ce 100644 --- a/packages/snaps-sdk/src/types/methods/list-entropy-sources.ts +++ b/packages/snaps-sdk/src/types/methods/list-entropy-sources.ts @@ -30,6 +30,13 @@ export type EntropySource = { export type ListEntropySourcesParams = never; /** - * The result returned by the `snap_listEntropySources` method. + * An array of entropy sources available to the Snap. Each entropy source + * consists of: + * + * - `name` - The name of the entropy source. + * - `id` - The ID of the entropy source. + * - `type` - The type of the entropy source. Currently, only `mnemonic` is + * supported. + * - `primary` - Whether the entropy source is the primary source. */ export type ListEntropySourcesResult = EntropySource[]; diff --git a/packages/snaps-sdk/src/types/methods/manage-state.ts b/packages/snaps-sdk/src/types/methods/manage-state.ts index d3d2aa6fd6..1603f122ed 100644 --- a/packages/snaps-sdk/src/types/methods/manage-state.ts +++ b/packages/snaps-sdk/src/types/methods/manage-state.ts @@ -71,8 +71,6 @@ export type ManageStateParams = | UpdateStateOperation; /** - * The result returned by the `snap_manageState` method. - * * If the operation is `get`, the result is the state. Otherwise, the result is * `null`. */ diff --git a/packages/snaps-sdk/src/types/methods/notify.ts b/packages/snaps-sdk/src/types/methods/notify.ts index baf48da8d1..11e29f4e52 100644 --- a/packages/snaps-sdk/src/types/methods/notify.ts +++ b/packages/snaps-sdk/src/types/methods/notify.ts @@ -15,7 +15,8 @@ export enum NotificationType { /** * The request parameters for the `snap_notify` method. * - * @property type - The type of notification to display. + * @property type - The notification type (`inApp` or `native`). We recommend + * using `inApp` because native notifications may be rate-limited by the OS. * @property message - The message to display in the notification. */ export type NotifyParams = diff --git a/packages/snaps-sdk/src/types/methods/open-web-socket.ts b/packages/snaps-sdk/src/types/methods/open-web-socket.ts index 38606e9c29..8ff7cc10f1 100644 --- a/packages/snaps-sdk/src/types/methods/open-web-socket.ts +++ b/packages/snaps-sdk/src/types/methods/open-web-socket.ts @@ -1,8 +1,9 @@ /** * The request parameters for the `snap_openWebSocket` method. * - * @property url - The URL of the WebSocket connection to open. - * @property protocols - The protocols to use for the WebSocket connection. + * @property url - The `wss://` URL of the WebSocket connection to open. + * @property protocols - The optional protocols to use for the WebSocket + * connection. */ export type OpenWebSocketParams = { url: string; @@ -10,6 +11,8 @@ export type OpenWebSocketParams = { }; /** - * The result returned by the `snap_openWebSocket` method. + * The ID of the opened WebSocket connection, which can be used to reference the + * connection in subsequent calls to [`snap_sendWebSocketMessage`](https://docs.metamask.io/snaps/reference/snaps-api/snap_sendwebsocketmessage) + * and [`snap_closeWebSocket`](https://docs.metamask.io/snaps/reference/snaps-api/snap_closewebsocket). */ export type OpenWebSocketResult = string; diff --git a/packages/snaps-sdk/src/types/methods/request-snaps.ts b/packages/snaps-sdk/src/types/methods/request-snaps.ts index 3d28244786..9827550d72 100644 --- a/packages/snaps-sdk/src/types/methods/request-snaps.ts +++ b/packages/snaps-sdk/src/types/methods/request-snaps.ts @@ -3,15 +3,14 @@ import type { JsonRpcError } from '@metamask/utils'; import type { Snap } from '../snap'; /** - * The request parameters for the `wallet_requestSnaps` method. - * - * It consists of a map of Snap IDs to optional version strings to request. + * An object mapping the IDs of the requested Snaps to optional SemVer version + * ranges. The SemVer version ranges use the same semantics as NPM + * `package.json` ranges. */ export type RequestSnapsParams = Record; /** - * The result returned by the `wallet_requestSnaps` method. - * - * It consists of a map of Snap IDs to either the Snap object or an error. + * An object mapping the IDs of the requested Snaps to either the installed Snap + * or an error if the Snap failed to install or was not permitted. */ export type RequestSnapsResult = Record; diff --git a/packages/snaps-sdk/src/types/methods/resolve-interface.ts b/packages/snaps-sdk/src/types/methods/resolve-interface.ts index f5e3a6381f..1df55ff819 100644 --- a/packages/snaps-sdk/src/types/methods/resolve-interface.ts +++ b/packages/snaps-sdk/src/types/methods/resolve-interface.ts @@ -3,7 +3,7 @@ import type { Json } from '@metamask/utils'; /** * The request parameters for the `snap_resolveInterface` method. * - * @property id - The interface id. + * @property id - The interface ID. * @property value - The value to resolve the interface with. */ export type ResolveInterfaceParams = { diff --git a/packages/snaps-sdk/src/types/methods/schedule-background-event.ts b/packages/snaps-sdk/src/types/methods/schedule-background-event.ts index 19f121f933..0ca7e64d4b 100644 --- a/packages/snaps-sdk/src/types/methods/schedule-background-event.ts +++ b/packages/snaps-sdk/src/types/methods/schedule-background-event.ts @@ -17,6 +17,6 @@ export type ScheduleBackgroundEventParams = | { duration: string; request: Cronjob['request'] }; /** - * The result returned by the `snap_scheduleBackgroundEvent` method, which is the ID of the scheduled event. + * The ID of the scheduled background event. */ export type ScheduleBackgroundEventResult = string; diff --git a/packages/snaps-sdk/src/types/methods/send-web-socket-message.ts b/packages/snaps-sdk/src/types/methods/send-web-socket-message.ts index 01a64e3cf2..563a2b04db 100644 --- a/packages/snaps-sdk/src/types/methods/send-web-socket-message.ts +++ b/packages/snaps-sdk/src/types/methods/send-web-socket-message.ts @@ -1,7 +1,7 @@ /** * The request parameters for the `snap_sendWebSocketMessage` method. * - * @property id - The id of the WebSocket connection to send a message to. + * @property id - The ID of the WebSocket connection to send a message to. * @property message - The message to send. */ export type SendWebSocketMessageParams = { diff --git a/packages/snaps-sdk/src/types/permissions.ts b/packages/snaps-sdk/src/types/permissions.ts index 1427b6bce3..f8dff9838e 100644 --- a/packages/snaps-sdk/src/types/permissions.ts +++ b/packages/snaps-sdk/src/types/permissions.ts @@ -30,11 +30,25 @@ export type NameLookupMatchers = }; export type Bip32Entropy = { + /** + * The curve to use for the derived key. This must be a curve supported by + * [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree). + */ curve: SupportedCurve; + + /** + * The derivation path to use for the derived key, represented as an array of + * path segments. For example, the path `m/44'/1'/0'/0/0` would be represented + * as `['m', "44'", "1'", "0'", '0', '0']`. + */ path: string[]; }; export type Bip44Entropy = { + /** + * The coin type to use for the derived key, as specified in the + * [SLIP-44 registry](https://github.com/satoshilabs/slips/blob/master/slip-0044.md). + */ coinType: number; };