--- name: caretaker description: >- Caretaker: revocable access as a forwarder plus a separate revoker. Use when access must end later: when a contract, session, share, conversation, or trial ends; when someone asks for "revoke", "expire", "cancel access", or "undo sharing". --- # Caretaker: revoke by cutting the forwarder **Bad:** a flag on the object you hand out; the holder can read and flip it. ```js const share = { file, revoked: false, read() { if (!this.revoked) return this.file.read(); } }; ``` **Good:** the holder gets the forwarder; only the owner gets the revoker. ```js const makeCaretaker = target => { let t = target; const forwarder = Object.freeze({ read: () => { if (!t) throw Error('revoked'); return t.read(); } }); const revoker = Object.freeze({ revoke: () => { t = null; } }); return { forwarder, revoker }; }; ``` Rules: the forwarder exposes no way to reach the target, the revoker, or the revoked state; every method checks; revocation can't be undone by the holder. ## Sources - [E in a Walnut: Capability Patterns](https://www.skyhunter.com/marcs/ewalnut.html#SEC45): the caretaker as revocable forwarder.