@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
46 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSnapsHandler = void 0;
/**
* 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,
* // },
* // ...,
* // }
* ```
*/
exports.getSnapsHandler = {
implementation: getSnapsImplementation,
actionNames: ['SnapController:getPermittedSnaps'],
};
/**
* The `wallet_getSnaps` method implementation.
* Fetches available snaps for the requesting origin and adds them to the JSON-RPC response.
*
* @param req - The JSON-RPC request object.
* @param res - 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. Not used by this function.
* @param messenger - The messenger used to call controller actions.
* @returns Nothing.
*/
async function getSnapsImplementation(req, res, _next, end, _hooks, messenger) {
res.result = messenger.call('SnapController:getPermittedSnaps', req.origin);
return end();
}
//# sourceMappingURL=getSnaps.cjs.map