@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
36 lines • 1.27 kB
JavaScript
import { rpcErrors } from "@metamask/rpc-errors";
const hookNames = {
getAllSnaps: true,
};
/**
* `wallet_getAllSnaps` gets all installed Snaps. Currently, this can only be
* called from `https://snaps.metamask.io`.
*/
export const getAllSnapsHandler = {
methodNames: ['wallet_getAllSnaps'],
implementation: getAllSnapsImplementation,
hookNames,
};
/**
* The `wallet_getAllSnaps` method implementation.
* Fetches all installed snaps and adds them to the JSON-RPC response.
*
* @param request - The JSON-RPC request object.
* @param response - The JSON-RPC response object.
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
* function.
* @param end - The `json-rpc-engine` "end" callback.
* @param hooks - The RPC method hooks.
* @param hooks.getAllSnaps - A function that returns all installed snaps.
* @returns Nothing.
*/
async function getAllSnapsImplementation(request, response, _next, end, { getAllSnaps }) {
// The origin is added by the MetaMask middleware stack.
const { origin } = request;
if (origin !== 'https://snaps.metamask.io') {
return end(rpcErrors.methodNotFound());
}
response.result = await getAllSnaps();
return end();
}
//# sourceMappingURL=getAllSnaps.mjs.map