UNPKG

@metamask/ocap-kernel

Version:
56 lines 1.83 kB
import { getBaseMethods } from "./base.mjs"; import { isPromiseRef } from "../utils/promise-ref.mjs"; /** * Get the methods that provide functionality for managing object revocation. * * @param ctx - The store context. * @returns The revocation methods. */ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export const getRevocationMethods = (ctx) => { const { getRevokedKey } = getBaseMethods(ctx.kv); /** * Set the revoked flag for a kernel object. * * @param koId - The KRef of the kernel object to set the revoked flag for. * @param revoked - The value of the revoked flag. */ function setRevoked(koId, revoked) { if (revoked) { ctx.kv.set(getRevokedKey(koId), 'true'); } else { ctx.kv.delete(getRevokedKey(koId)); } } /** * Revoke a kernel object. Idempotent. Revoking promises is not supported. * * @param koId - The KRef of the kernel object to revoke. * @throws If the object is a promise or the koId is unknown. */ function revoke(koId) { if (isPromiseRef(koId)) { // Revoking a promise is not supported. throw Error(`cannot revoke promise ${koId}`); } // Set the revoked flag to true. setRevoked(koId, true); } /** * Check if a kernel object has been revoked. * * @param koId - The KRef of the kernel object of interest. * @returns True if the object is revoked, false otherwise. * @throws If the object is unknown and `throwIfUnknown` is true. */ function isRevoked(koId) { return Boolean(ctx.kv.get(getRevokedKey(koId))); } return { setRevoked, revoke, isRevoked, }; }; //# sourceMappingURL=revocation.mjs.map