UNPKG

@metamask/ocap-kernel

Version:
60 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRevocationMethods = void 0; const base_ts_1 = require("./base.cjs"); const promise_ref_ts_1 = require("../utils/promise-ref.cjs"); /** * 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 const getRevocationMethods = (ctx) => { const { getRevokedKey } = (0, base_ts_1.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 ((0, promise_ref_ts_1.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, }; }; exports.getRevocationMethods = getRevocationMethods; //# sourceMappingURL=revocation.cjs.map