@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
50 lines • 1.99 kB
JavaScript
import { providerErrors } from "@metamask/rpc-errors";
import { getBip32EntropyBuilder } from "../restricted/getBip32Entropy.mjs";
import { getBip32PublicKeyBuilder } from "../restricted/getBip32PublicKey.mjs";
import { getBip44EntropyBuilder } from "../restricted/getBip44Entropy.mjs";
import { getEntropyBuilder } from "../restricted/getEntropy.mjs";
/**
* A list of permissions that the requesting origin must have at least one of
* in order to call this method.
*/
const REQUIRED_PERMISSIONS = [
getBip32EntropyBuilder.targetName,
getBip32PublicKeyBuilder.targetName,
getBip44EntropyBuilder.targetName,
getEntropyBuilder.targetName,
];
const hookNames = {
hasPermission: true,
getEntropySources: true,
getUnlockPromise: true,
};
export const listEntropySourcesHandler = {
methodNames: ['snap_listEntropySources'],
implementation: listEntropySourcesImplementation,
hookNames,
};
/**
* The `snap_listEntropySources` method implementation.
*
* @param _request - The JSON-RPC request object. Not used by this function.
* @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.hasPermission - The function to check if the origin has a
* permission.
* @param hooks.getEntropySources - The function to get the entropy sources.
* @param hooks.getUnlockPromise - The function to get the unlock promise.
* @returns Noting.
*/
async function listEntropySourcesImplementation(_request, response, _next, end, { hasPermission, getEntropySources, getUnlockPromise, }) {
const isPermitted = REQUIRED_PERMISSIONS.some(hasPermission);
if (!isPermitted) {
return end(providerErrors.unauthorized());
}
await getUnlockPromise(true);
response.result = getEntropySources();
return end();
}
//# sourceMappingURL=listEntropySources.mjs.map