UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

48 lines (44 loc) 1.27 kB
import { Temporal } from "@js-temporal/polyfill"; import { URLPattern } from "urlpattern-polyfill"; globalThis.addEventListener = () => {}; import { CryptographicKey, Multikey } from "./vocab-dDpPQ0fF.js"; //#region federation/keycache.ts var KvKeyCache = class { kv; prefix; options; nullKeys; constructor(kv, prefix, options = {}) { this.kv = kv; this.prefix = prefix; this.nullKeys = /* @__PURE__ */ new Set(); this.options = options; } async get(keyId) { if (this.nullKeys.has(keyId.href)) return null; const serialized = await this.kv.get([...this.prefix, keyId.href]); if (serialized == null) return void 0; try { return await CryptographicKey.fromJsonLd(serialized, this.options); } catch { try { return await Multikey.fromJsonLd(serialized, this.options); } catch { await this.kv.delete([...this.prefix, keyId.href]); return void 0; } } } async set(keyId, key) { if (key == null) { this.nullKeys.add(keyId.href); await this.kv.delete([...this.prefix, keyId.href]); return; } this.nullKeys.delete(keyId.href); const serialized = await key.toJsonLd(this.options); await this.kv.set([...this.prefix, keyId.href], serialized); } }; //#endregion export { KvKeyCache };