UNPKG

@arcblock/did

Version:

Javascript lib to work with ArcBlock DID

38 lines (36 loc) 1.11 kB
//#region src/name-registry.ts const MAX_NAME_LENGTH = 1024; /** * In-memory name registry implementation. * Uses upsert semantics: re-registering a name overwrites the previous value. */ var InMemoryNameRegistry = class { constructor() { this.store = /* @__PURE__ */ new Map(); } resolve(name) { return this.store.get(name) ?? null; } register(name, did) { if (!name || typeof name !== "string") throw new Error("Name must be a non-empty string"); if (name.length > MAX_NAME_LENGTH) throw new Error("Name exceeds maximum length"); if (name.startsWith(".") || name.endsWith(".")) throw new Error("Name cannot start or end with a dot"); if (!did || typeof did !== "string") throw new Error("DID must be a non-empty string"); if (!did.startsWith("did:")) throw new Error("DID must have a valid did: prefix"); this.store.set(name, did); } unregister(name) { this.store.delete(name); } has(name) { return this.store.has(name); } list() { return [...this.store.keys()]; } clear() { this.store.clear(); } }; //#endregion exports.InMemoryNameRegistry = InMemoryNameRegistry;