@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
53 lines • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAssetsCaveatMapper = exports.assetsEndowmentBuilder = void 0;
const permission_controller_1 = require("@metamask/permission-controller");
const snaps_utils_1 = require("@metamask/snaps-utils");
const utils_1 = require("@metamask/utils");
const caveats_1 = require("./caveats/index.cjs");
const enum_1 = require("./enum.cjs");
const permissionName = enum_1.SnapEndowments.Assets;
/**
* `endowment:assets` returns nothing; it is intended to be used as a flag to determine whether the Snap can run asset queries.
*
* @param _builderOptions - Optional specification builder options.
* @returns The specification for the assets endowment.
*/
const specificationBuilder = (_builderOptions) => {
return {
permissionType: permission_controller_1.PermissionType.Endowment,
targetName: permissionName,
allowedCaveats: [snaps_utils_1.SnapCaveatType.ChainIds],
endowmentGetter: (_getterOptions) => null,
subjectTypes: [permission_controller_1.SubjectType.Snap],
validator: (0, caveats_1.createGenericPermissionValidator)([
{ type: snaps_utils_1.SnapCaveatType.ChainIds },
{ type: snaps_utils_1.SnapCaveatType.MaxRequestTime, optional: true },
]),
};
};
exports.assetsEndowmentBuilder = Object.freeze({
targetName: permissionName,
specificationBuilder,
});
/**
* Map a raw value from the `initialPermissions` to a caveat specification.
* Note that this function does not do any validation, that's handled by the
* PermissionsController when the permission is requested.
*
* @param value - The raw value from the `initialPermissions`.
* @returns The caveat specification.
*/
function getAssetsCaveatMapper(value) {
(0, utils_1.assert)((0, utils_1.isObject)(value) && value.scopes);
return {
caveats: [
{
type: snaps_utils_1.SnapCaveatType.ChainIds,
value: value.scopes,
},
],
};
}
exports.getAssetsCaveatMapper = getAssetsCaveatMapper;
//# sourceMappingURL=assets.cjs.map