@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
53 lines • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listEntropySourcesHandler = void 0;
const rpc_errors_1 = require("@metamask/rpc-errors");
const getBip32Entropy_1 = require("../restricted/getBip32Entropy.cjs");
const getBip32PublicKey_1 = require("../restricted/getBip32PublicKey.cjs");
const getBip44Entropy_1 = require("../restricted/getBip44Entropy.cjs");
const getEntropy_1 = require("../restricted/getEntropy.cjs");
/**
* A list of permissions that the requesting origin must have at least one of
* in order to call this method.
*/
const REQUIRED_PERMISSIONS = [
getBip32Entropy_1.getBip32EntropyBuilder.targetName,
getBip32PublicKey_1.getBip32PublicKeyBuilder.targetName,
getBip44Entropy_1.getBip44EntropyBuilder.targetName,
getEntropy_1.getEntropyBuilder.targetName,
];
const hookNames = {
hasPermission: true,
getEntropySources: true,
getUnlockPromise: true,
};
exports.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(rpc_errors_1.providerErrors.unauthorized());
}
await getUnlockPromise(true);
response.result = getEntropySources();
return end();
}
//# sourceMappingURL=listEntropySources.cjs.map