UNPKG

@metamask/snaps-rpc-methods

Version:
39 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllSnapsHandler = void 0; const rpc_errors_1 = require("@metamask/rpc-errors"); const hookNames = { getAllSnaps: true, }; /** * `wallet_getAllSnaps` gets all installed Snaps. Currently, this can only be * called from `https://snaps.metamask.io`. */ exports.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(rpc_errors_1.rpcErrors.methodNotFound()); } response.result = await getAllSnaps(); return end(); } //# sourceMappingURL=getAllSnaps.cjs.map