UNPKG

@metamask/snaps-rpc-methods

Version:
49 lines 1.83 kB
import { PermissionType, SubjectType } from "@metamask/permission-controller"; import { SnapCaveatType } from "@metamask/snaps-utils"; import { assert, isObject } from "@metamask/utils"; import { createGenericPermissionValidator } from "./caveats/index.mjs"; import { SnapEndowments } from "./enum.mjs"; const permissionName = 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: PermissionType.Endowment, targetName: permissionName, allowedCaveats: [SnapCaveatType.ChainIds], endowmentGetter: (_getterOptions) => null, subjectTypes: [SubjectType.Snap], validator: createGenericPermissionValidator([ { type: SnapCaveatType.ChainIds }, { type: SnapCaveatType.MaxRequestTime, optional: true }, ]), }; }; export const 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. */ export function getAssetsCaveatMapper(value) { assert(isObject(value) && value.scopes); return { caveats: [ { type: SnapCaveatType.ChainIds, value: value.scopes, }, ], }; } //# sourceMappingURL=assets.mjs.map