@sovereignbase/explorer 0.0.0-alpha.0 → 0.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/dist/class.cjs +760 -0
- package/dist/class.cjs.map +1 -0
- package/dist/class.d.cts +274 -0
- package/dist/class.d.cts.map +1 -0
- package/dist/class.d.ts +274 -0
- package/dist/class.d.ts.map +1 -0
- package/dist/class.js +759 -0
- package/dist/class.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class.cjs","names":["Sequenced","afterIdleFor","Sequenced","afterIdleFor","deriveDeviceEntropy","readableUserAgent","Bytes","Cryptographic","isRecord","loadObject","storeObject","deleteObject"],"sources":["../src/.errors/class.ts","../src/.errors/unkown.ts","../src/CredentialEntries/class.ts","../src/RecentEntries/class.ts","../src/class.ts"],"sourcesContent":["/** Identifies an Explorer failure independently of its human-readable message. */\nexport type ExplorerErrorCode =\n /** An unexpected failure was wrapped with its original cause. */\n | 'UNKNOWN_ERROR'\n /** A credential event is missing required identifying or usage information. */\n | 'INVALID_CREDENTIAL_EVENT'\n /** A new credential does not provide all required setup properties. */\n | 'MISSING_CREDENTIAL_SETUP_PROPERTIES'\n /** An operation requires an authenticated Explorer session. */\n | 'NOT_AUTHENTICATED'\n\n/**\n * An Explorer error with a stable, machine-readable code and an optional cause.\n *\n * The message is prefixed with the library name. Use {@link code} rather than\n * parsing the message when handling a particular failure.\n */\nexport class ExplorerError extends Error {\n /** The machine-readable category of the failure. */\n readonly code: ExplorerErrorCode\n\n /**\n * Creates an error whose name is `ExplorerError`.\n *\n * @param code The category of the failure.\n * @param message The detail to prefix with the library name; defaults to `code`.\n * @param options Error options, including the original `cause`.\n */\n constructor(\n code: ExplorerErrorCode,\n message?: string,\n options?: ErrorOptions\n ) {\n super(`{@sovereignbase/explorer} ${message ?? code}`, options)\n this.code = code\n this.name = 'ExplorerError'\n }\n}\n","import { ExplorerError } from './class.js'\n\n/**\n * Preserves an existing library error or wraps an unexpected failure once.\n * @param cause The value thrown by the failed operation.\n * @param operation The operation name to include in the error message.\n * @returns The original library error, or an `UNKNOWN_ERROR` retaining `cause`.\n */\nexport function unknownError(cause: unknown, operation: string): ExplorerError {\n return cause instanceof ExplorerError\n ? cause\n : new ExplorerError('UNKNOWN_ERROR', `${operation} failed.`, { cause })\n}\n","import {\n Sequenced,\n type SequencedArray,\n type SequencedArrayDelta,\n type SequencedArrayChange,\n type SequencedArraySnapshot,\n} from '@sovereignbase/sequenced'\n//\nimport type { CipherKey } from '@sovereignbase/cryptosuite'\nimport type { DeviceBindingStorage } from '@sovereignbase/hardware-bound'\n//\nimport {\n afterIdleFor,\n type DeepReadonly,\n type WritableArray,\n} from '@sovereignbase/utils'\n//\nimport { Explorer } from '../class.js'\nimport { ExplorerError } from '../.errors/class.js'\nimport { unknownError } from '../.errors/unkown.js'\n\n/**\n * Describes a credential registered with the database.\n */\nexport type CredentialEntry = {\n /** The identifier of the credential. */\n id: string\n\n /** The display name of the credential. */\n name: string\n\n /** The entropy associated with the credential. */\n entropy: Uint8Array\n\n /** The storage mechanism used for device binding. */\n storage: DeviceBindingStorage\n\n /** The timestamp of the most recent use of the credential. */\n lastUsed: number\n\n /** The user agents that have used the credential. */\n userAgents: Array<{\n /** The user agent string. */\n name: string\n\n /** The timestamp of the most recent use by the user agent. */\n lastSeen: number\n }>\n}\n\n/**\n * Describes the properties used to create or update a credential entry.\n *\n * The identifier, timestamp, and user agent are required to record use.\n * Creating a credential additionally requires a name, entropy, and storage.\n */\nexport type CredentialEvent = {\n /** The identifier of the credential. */\n id?: string\n\n /** The timestamp of the credential use. */\n timestamp?: number\n\n /** The user agent associated with the credential use. */\n userAgent?: string\n\n /** The display name of the credential. */\n name?: string\n\n /** The entropy associated with the credential. */\n entropy?: Uint8Array\n\n /** The storage mechanism used for device binding. */\n storage?: DeviceBindingStorage\n}\n\n/**\n * Represents a sequenced delta produced by the credential entries list.\n */\nexport type CredentialEntriesDelta = Readonly<\n ['credentialEntries', DeepReadonly<SequencedArrayDelta<CredentialEntry>>]\n>\n\n/**\n * Represents a sequenced change produced by the credential entries list.\n */\nexport type CredentialEntriesChange = DeepReadonly<\n SequencedArrayChange<CredentialEntry>\n>\n\n/**\n * Maps credential entries event names to their detail types.\n */\nexport type CredentialEntriesEventMap = {\n /** Fired when the credential entries list changes. */\n change: CredentialEntriesChange\n}\n\n/**\n * Represents an event listener for a {@link CredentialEntries} event.\n *\n * @typeParam K The event name that determines the event detail type.\n */\nexport type CredentialEntriesEventListener<\n K extends keyof CredentialEntriesEventMap,\n> =\n | ((event: CustomEvent<CredentialEntriesEventMap[K]>) => void)\n | { handleEvent(event: CustomEvent<CredentialEntriesEventMap[K]>): void }\n\n/**\n * Resolves an event name to its corresponding listener type.\n *\n * @typeParam K The event name to resolve.\n */\nexport type CredentialEntriesEventListenerFor<K extends string> =\n K extends keyof CredentialEntriesEventMap\n ? CredentialEntriesEventListener<K>\n : EventListenerOrEventListenerObject\n\n/**\n * Maintains the database's credential entries.\n *\n * Entries are identified by credential ID and synchronized through\n * a sequenced array. Changes are persisted as encrypted snapshots.\n */\nexport class CredentialEntries {\n private state: SequencedArray<CredentialEntry>\n private deltaBuffer: WritableArray<SequencedArrayDelta<CredentialEntry>> =\n new Array()\n private eventTarget?: EventTarget\n\n /**\n * Creates a credential entries list.\n *\n * @param id The identifier of the persisted entries object.\n * @param cipherKey The key used to encrypt the entries object.\n * @param sessionCredentialID The credential ID of the current session.\n * @param actorID The actor identifier used by the sequenced array.\n * @param trustedSnapshot An optional snapshot used to initialize the state.\n */\n constructor(\n private readonly id: string,\n private readonly cipherKey: CipherKey,\n public readonly sessionCredentialID: string,\n actorID: number,\n trustedSnapshot?: unknown\n ) {\n try {\n this.state = new Sequenced.Array(actorID, trustedSnapshot)\n\n const debouncedDispatch = afterIdleFor(250, () => {\n void Explorer.dispatchEvent('delta', [\n 'credentialEntries',\n this.deltaBuffer.splice(0),\n ])\n })\n\n void this.state.addEventListener('delta', ({ detail }) => {\n void this.deltaBuffer.push(...detail)\n void debouncedDispatch()\n })\n\n const debouncedSave = afterIdleFor(\n 250,\n async (snapshot: SequencedArraySnapshot<CredentialEntry>) => {\n void (await Explorer.storeObjectByID(\n this.id,\n snapshot,\n this.cipherKey\n ))\n }\n )\n\n void this.state.addEventListener('snapshot', ({ detail }) => {\n void debouncedSave(detail)\n })\n\n void this.state.addEventListener('change', ({ detail }) => {\n void this.dispatchEvent('change', detail)\n })\n\n const seen = new Set<string>()\n const duplicates: number[] = []\n\n for (let index = 0; index < this.state.length; index++) {\n const entry = this.state.at(index)\n if (!entry) continue\n\n if (seen.has(entry.id)) duplicates.push(index)\n else seen.add(entry.id)\n }\n\n for (let index = duplicates.length - 1; index >= 0; index--)\n void this.state.delete(duplicates[index])\n\n if (duplicates.length > 0 || this.deltaBuffer.length > 0)\n void this.state.snapshot()\n } catch (cause) {\n throw unknownError(cause, 'CredentialEntries.constructor()')\n }\n }\n\n /**\n * Creates or updates a credential entry.\n *\n * Updates the credential's last-used timestamp and the corresponding\n * user agent's last-seen timestamp. Existing properties are preserved\n * unless replacements are provided.\n *\n * @param credentialEvent The credential properties to apply.\n * @throws {ExplorerError} If the event is invalid or setup properties are missing.\n */\n public record(credentialEvent: CredentialEvent): void {\n try {\n if (!credentialEvent || typeof credentialEvent !== 'object')\n throw new ExplorerError(\n 'INVALID_CREDENTIAL_EVENT',\n 'A credential event must be an object.'\n )\n\n const { id, timestamp, userAgent, name, entropy, storage } =\n credentialEvent\n\n if (\n typeof id !== 'string' ||\n typeof timestamp !== 'number' ||\n !Number.isFinite(timestamp) ||\n typeof userAgent !== 'string'\n )\n throw new ExplorerError(\n 'INVALID_CREDENTIAL_EVENT',\n 'A credential event requires an ID, a finite timestamp, and a user agent.'\n )\n\n let existing: CredentialEntry | undefined\n\n for (let index = this.state.length - 1; index >= 0; index--) {\n const entry = this.state.at(index)\n if (entry?.id === id) {\n existing = entry\n break\n }\n }\n\n if (\n !existing &&\n (typeof name !== 'string' ||\n !(entropy instanceof Uint8Array) ||\n typeof storage !== 'string')\n )\n throw new ExplorerError(\n 'MISSING_CREDENTIAL_SETUP_PROPERTIES',\n 'A new credential requires a name, entropy, and binding storage.'\n )\n\n const userAgents =\n existing?.userAgents.map((agent) => ({ ...agent })) ?? []\n const agent = userAgents.find((agent) => agent.name === userAgent)\n\n if (agent) {\n agent.lastSeen = Math.max(agent.lastSeen, timestamp)\n } else {\n userAgents.push({ name: userAgent, lastSeen: timestamp })\n }\n\n const entry: CredentialEntry = {\n id,\n name: name ?? existing!.name,\n entropy: entropy ?? existing!.entropy,\n storage: storage ?? existing!.storage,\n lastUsed: Math.max(existing?.lastUsed ?? timestamp, timestamp),\n userAgents,\n }\n\n for (let index = this.state.length - 1; index >= 0; index--) {\n if (this.state.at(index)?.id === id) void this.state.delete(index)\n }\n\n void this.state.unshift(entry)\n void this.state.snapshot()\n } catch (cause) {\n throw unknownError(cause, 'CredentialEntries.record()')\n }\n }\n\n /**\n * Revokes a credential by deleting its persisted data and list entries.\n *\n * The list remains unchanged if deletion of the persisted credential fails.\n *\n * @param credentialID The identifier of the credential to revoke.\n */\n public async revoke(credentialID: string): Promise<void> {\n try {\n let exists = false\n\n for (let index = this.state.length - 1; index >= 0; index--) {\n if (this.state.at(index)?.id !== credentialID) continue\n exists = true\n break\n }\n\n if (!exists) return\n\n await Explorer.deleteObjectByID(credentialID)\n\n for (let index = this.state.length - 1; index >= 0; index--) {\n if (this.state.at(index)?.id === credentialID)\n void this.state.delete(index)\n }\n\n void this.state.snapshot()\n } catch (cause) {\n throw unknownError(cause, 'CredentialEntries.revoke()')\n }\n }\n\n /**\n * Returns the credential entries ordered by most recent use.\n *\n * Entries with equal timestamps are ordered by identifier.\n */\n public list(): DeepReadonly<Array<CredentialEntry>> {\n try {\n return this.state\n .slice()\n .sort((a, b) => b.lastUsed - a.lastUsed || a.id.localeCompare(b.id))\n } catch (cause) {\n throw unknownError(cause, 'CredentialEntries.list()')\n }\n }\n\n /**\n * Applies a sequenced delta to the credential entries list.\n *\n * @param delta The delta to apply.\n */\n public apply(delta: unknown): void {\n try {\n void this.state.apply(delta)\n void this.state.snapshot()\n } catch (cause) {\n throw unknownError(cause, 'CredentialEntries.apply()')\n }\n }\n\n /**\n * Merges a snapshot into the credential entries list.\n *\n * @param snapshot The snapshot to merge.\n */\n public merge(snapshot: unknown): void {\n try {\n void this.state.merge(snapshot)\n void this.state.snapshot()\n } catch (cause) {\n throw unknownError(cause, 'CredentialEntries.merge()')\n }\n }\n\n //* ███████╗██╗ ██╗███████╗███╗ ██╗████████╗ ████████╗ █████╗ ██████╗ ██████╗ ███████╗████████╗\n //* ██╔════╝██║ ██║██╔════╝████╗ ██║╚══██╔══╝ ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝ ██╔════╝╚══██╔══╝\n //* █████╗ ██║ ██║█████╗ ██╔██╗ ██║ ██║ ██║ ███████║██████╔╝██║ ███╗█████╗ ██║\n //* ██╔══╝ ╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║ ██║ ██╔══██║██╔══██╗██║ ██║██╔══╝ ██║\n //* ███████╗ ╚████╔╝ ███████╗██║ ╚████║ ██║ ██║ ██║ ██║██║ ██║╚██████╔╝███████╗ ██║\n //* ╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝\n\n /**\n * Registers an event listener for the specified event type.\n *\n * @param type The event type.\n * @param listener The event listener, or `null`.\n * @param options The event listener options.\n */\n public addEventListener<K extends keyof CredentialEntriesEventMap>(\n type: K,\n listener: CredentialEntriesEventListenerFor<K> | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n try {\n void (this.eventTarget ??= new EventTarget()).addEventListener(\n type,\n listener as EventListenerOrEventListenerObject | null,\n options\n )\n } catch (cause) {\n throw unknownError(cause, 'CredentialEntries.addEventListener()')\n }\n }\n\n /**\n * Removes an event listener previously registered with\n * {@link addEventListener}.\n *\n * @param type The event type.\n * @param listener The event listener to remove, or `null`.\n * @param options The event listener options.\n */\n public removeEventListener<K extends keyof CredentialEntriesEventMap>(\n type: K,\n listener: CredentialEntriesEventListenerFor<K> | null,\n options?: boolean | EventListenerOptions\n ): void {\n try {\n void this.eventTarget?.removeEventListener(\n type,\n listener as EventListenerOrEventListenerObject | null,\n options\n )\n } catch (cause) {\n throw unknownError(cause, 'CredentialEntries.removeEventListener()')\n }\n }\n\n /**\n * Dispatches an event to the registered listeners.\n *\n * @param type The event type.\n * @param detail The value exposed through `CustomEvent.detail`.\n */\n public dispatchEvent<K extends keyof CredentialEntriesEventMap>(\n type: K,\n detail: CredentialEntriesEventMap[K]\n ): void {\n try {\n void this.eventTarget?.dispatchEvent(new CustomEvent(type, { detail }))\n } catch (cause) {\n throw unknownError(cause, 'CredentialEntries.dispatchEvent()')\n }\n }\n}\n","import {\n Sequenced,\n type SequencedArray,\n type SequencedArrayDelta,\n type SequencedArrayChange,\n type SequencedArraySnapshot,\n} from '@sovereignbase/sequenced'\n//\nimport type { CipherKey } from '@sovereignbase/cryptosuite'\n//\nimport {\n afterIdleFor,\n type DeepReadonly,\n type WritableArray,\n} from '@sovereignbase/utils'\n//\nimport { Explorer } from '../class.js'\nimport { unknownError } from '../.errors/unkown.js'\n\n/**\n * Describes an entry in the recent objects list.\n */\nexport type RecentEntry = {\n /** The identifier of the referenced object. */\n id: string\n\n /** The display name of the referenced object. */\n name: string\n\n /** The cipher key used to access the referenced object. */\n cipherKey: CipherKey\n\n /** The date and time at which the object was most recently accessed. */\n dateAccessed: number\n}\n\n/**\n * Represents a sequenced delta produced by the recent entries list.\n */\nexport type RecentEntriesDelta = Readonly<\n ['recentEntries', DeepReadonly<SequencedArrayDelta<RecentEntry>>]\n>\n\n/**\n * Represents a sequenced change produced by the recent entries list.\n */\nexport type RecentEntriesChange = DeepReadonly<\n SequencedArrayChange<RecentEntry>\n>\n\n/**\n * Maps recent entries event names to their detail types.\n */\nexport type RecentEntriesEventMap = {\n /** Fired when the recent entries list changes. */\n change: RecentEntriesChange\n}\n\n/**\n * Represents an event listener for a {@link RecentEntries} event.\n *\n * @typeParam K The event name that determines the event detail type.\n */\nexport type RecentEntriesEventListener<K extends keyof RecentEntriesEventMap> =\n | ((event: CustomEvent<RecentEntriesEventMap[K]>) => void)\n | { handleEvent(event: CustomEvent<RecentEntriesEventMap[K]>): void }\n\n/**\n * Resolves an event name to its corresponding listener type.\n *\n * @typeParam K The event name to resolve.\n */\nexport type RecentEntriesEventListenerFor<K extends string> =\n K extends keyof RecentEntriesEventMap\n ? RecentEntriesEventListener<K>\n : EventListenerOrEventListenerObject\n\n/**\n * Maintains the ordered list of recently accessed objects.\n *\n * Entries are ordered from most recently accessed to least recently accessed,\n * deduplicated by identifier, and limited to 20 entries.\n */\nexport class RecentEntries {\n private state: SequencedArray<RecentEntry>\n private deltaBuffer: WritableArray<SequencedArrayDelta<RecentEntry>> =\n new Array()\n private eventTarget?: EventTarget\n\n /**\n * Creates a recent entries list.\n *\n * @param id The identifier of the persisted recent entries object.\n * @param cipherKey The key used to encrypt the entries object.\n * @param actorID The actor identifier used by the sequenced array.\n * @param trustedSnapshot An optional snapshot used to initialize the state.\n */\n constructor(\n private readonly id: string,\n private readonly cipherKey: CipherKey,\n actorID: number,\n trustedSnapshot?: unknown\n ) {\n try {\n this.state = new Sequenced.Array(actorID, trustedSnapshot)\n //\n const debouncedDispatch = afterIdleFor(250, () => {\n void Explorer.dispatchEvent('delta', [\n 'recentEntries',\n this.deltaBuffer.splice(0),\n ])\n })\n void this.state.addEventListener('delta', ({ detail }) => {\n void this.deltaBuffer.push(...detail)\n void debouncedDispatch()\n })\n //\n const debouncedSave = afterIdleFor(\n 250,\n async (snapshot: SequencedArraySnapshot<RecentEntry>) => {\n void (await Explorer.storeObjectByID(\n this.id,\n snapshot,\n this.cipherKey\n ))\n }\n )\n void this.state.addEventListener('snapshot', ({ detail }) => {\n void debouncedSave(detail)\n })\n //\n void this.state.addEventListener('change', ({ detail }) => {\n void this.dispatchEvent('change', detail)\n })\n //\n const seen = new Set<string>()\n const duplicates: number[] = []\n\n for (let index = 0; index < this.state.length; index++) {\n const entry = this.state.at(index)\n if (!entry) continue\n\n if (seen.has(entry.id) || seen.size >= 20) duplicates.push(index)\n else seen.add(entry.id)\n }\n\n for (let index = duplicates.length - 1; index >= 0; index--)\n void this.state.delete(duplicates[index])\n //\n if (duplicates.length > 0 || this.deltaBuffer.length > 0)\n void this.state.snapshot()\n //\n } catch (cause) {\n throw unknownError(cause, 'RecentEntries.constructor()')\n }\n }\n\n /**\n * Marks an entry as most recently accessed.\n *\n * Any existing entry with the same identifier is removed before the new\n * entry is inserted at the beginning of the list.\n *\n * @param accessed The entry that was accessed.\n */\n public update(accessed: RecentEntry): void {\n try {\n for (let index = this.state.length - 1; index >= 0; index--) {\n if (this.state.at(index)?.id === accessed.id)\n void this.state.delete(index)\n }\n\n void this.state.unshift(accessed)\n\n while (this.state.length > 20) {\n void this.state.pop()\n }\n void this.state.snapshot()\n } catch (cause) {\n throw unknownError(cause, 'RecentEntries.update()')\n }\n }\n\n /**\n * Removes an entry from the recent entries list.\n *\n * The referenced object is not deleted.\n *\n * @param id The identifier of the entry to remove.\n */\n public delete(id: string): void {\n try {\n let deleted = false\n for (let index = this.state.length - 1; index >= 0; index--) {\n if (this.state.at(index)?.id !== id) continue\n void this.state.delete(index)\n deleted = true\n }\n if (deleted) void this.state.snapshot()\n } catch (cause) {\n throw unknownError(cause, 'RecentEntries.delete()')\n }\n }\n\n /**\n * Returns the recent entries ordered by most recent access.\n */\n public list(): DeepReadonly<Array<RecentEntry>> {\n try {\n return this.state\n .slice()\n .sort(\n (a, b) => b.dateAccessed - a.dateAccessed || a.id.localeCompare(b.id)\n )\n } catch (cause) {\n throw unknownError(cause, 'RecentEntries.list()')\n }\n }\n //\n /**\n * Applies a sequenced delta to the recent entries list.\n *\n * @param delta The delta to apply.\n */\n public apply(delta: unknown): void {\n try {\n void this.state.apply(delta)\n void this.state.snapshot()\n } catch (cause) {\n throw unknownError(cause, 'RecentEntries.apply()')\n }\n }\n\n /**\n * Merges a snapshot into the recent entries list.\n *\n * @param snapshot The snapshot to merge.\n */\n public merge(snapshot: unknown): void {\n try {\n void this.state.merge(snapshot)\n void this.state.snapshot()\n } catch (cause) {\n throw unknownError(cause, 'RecentEntries.merge()')\n }\n }\n\n //* ███████╗██╗ ██╗███████╗███╗ ██╗████████╗ ████████╗ █████╗ ██████╗ ██████╗ ███████╗████████╗\n //* ██╔════╝██║ ██║██╔════╝████╗ ██║╚══██╔══╝ ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝ ██╔════╝╚══██╔══╝\n //* █████╗ ██║ ██║█████╗ ██╔██╗ ██║ ██║ ██║ ███████║██████╔╝██║ ███╗█████╗ ██║\n //* ██╔══╝ ╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║ ██║ ██╔══██║██╔══██╗██║ ██║██╔══╝ ██║\n //* ███████╗ ╚████╔╝ ███████╗██║ ╚████║ ██║ ██║ ██║ ██║██║ ██║╚██████╔╝███████╗ ██║\n //* ╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝\n\n /**\n * Registers an event listener for the specified event type.\n *\n * @param type The event type.\n * @param listener The event listener, or `null`.\n * @param options The event listener options.\n */\n public addEventListener<K extends keyof RecentEntriesEventMap>(\n type: K,\n listener: RecentEntriesEventListenerFor<K> | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n try {\n void (this.eventTarget ??= new EventTarget()).addEventListener(\n type,\n listener as EventListenerOrEventListenerObject | null,\n options\n )\n } catch (cause) {\n throw unknownError(cause, 'RecentEntries.addEventListener()')\n }\n }\n\n /**\n * Removes an event listener previously registered with\n * {@link addEventListener}.\n *\n * @param type The event type.\n * @param listener The event listener to remove, or `null`.\n * @param options The event listener options.\n */\n public removeEventListener<K extends keyof RecentEntriesEventMap>(\n type: K,\n listener: RecentEntriesEventListenerFor<K> | null,\n options?: boolean | EventListenerOptions\n ): void {\n try {\n void this.eventTarget?.removeEventListener(\n type,\n listener as EventListenerOrEventListenerObject | null,\n options\n )\n } catch (cause) {\n throw unknownError(cause, 'RecentEntries.removeEventListener()')\n }\n }\n\n /**\n * Dispatches an event to the registered listeners.\n *\n * @param type The event type.\n * @param detail The value exposed through `CustomEvent.detail`.\n */\n public dispatchEvent<K extends keyof RecentEntriesEventMap>(\n type: K,\n detail: RecentEntriesEventMap[K]\n ): void {\n try {\n void this.eventTarget?.dispatchEvent(new CustomEvent(type, { detail }))\n } catch (cause) {\n throw unknownError(cause, 'RecentEntries.dispatchEvent()')\n }\n }\n}\n","import {\n deleteObject,\n loadObject,\n storeObject,\n type URLString,\n} from '@sovereignbase/storage'\nimport { isRecord, type DeepReadonly } from '@sovereignbase/utils'\nimport { Bytes } from '@sovereignbase/bytecodec'\nimport { readableUserAgent } from '@sovereignbase/dom-utils'\nimport { deriveDeviceEntropy } from '@sovereignbase/hardware-bound'\nimport { Cryptographic, type CipherKey } from '@sovereignbase/cryptosuite'\n//\nimport type {\n AuthenticationResult,\n AuthenticationSetupParams,\n //\n ExplorerEventMap,\n ExplorerEventListenerFor,\n //\n ExplorerDelta,\n} from './.types/type.js'\n//\nimport { ExplorerError } from './.errors/class.js'\nimport { unknownError } from './.errors/unkown.js'\n//\nimport {\n CredentialEntries,\n type CredentialEntry,\n type CredentialEvent,\n type CredentialEntriesChange,\n} from './CredentialEntries/class.js'\n//\nimport {\n RecentEntries,\n type RecentEntry,\n type RecentEntriesChange,\n} from './RecentEntries/class.js'\n\n/**\n * Provides authentication, encrypted object storage, and access to\n * the database's synchronized entries.\n *\n * Maintains the authenticated database context and exposes static methods\n * for managing stored objects, observing entries, and applying remote deltas.\n */\nexport class Explorer {\n /** The identifier of the authenticated database. */\n public static databaseID: string\n\n /** Indicates whether the database has been authenticated. */\n public static isAuthenticated: boolean\n\n //\n private static storageURL: URLString\n private static eventTarget?: EventTarget\n private static databaseSecret: Readonly<Uint8Array>\n private static sessionCredential?: CredentialEvent = {}\n\n /**\n * Caches cipher keys by object identifier.\n *\n * Existing entries are preserved when an object is accessed with\n * a cipher key.\n */\n public static readonly cipherKeyCache: Map<string, CipherKey> = new Map()\n\n /**\n * Authenticates a database using a data PIN and device-bound entropy.\n *\n * Derives the credential and database identifiers from cryptographic\n * secrets. When setup parameters are provided, creates and stores a\n * new credential. Otherwise, loads the existing credential.\n *\n * Records the authenticated credential in the database's credential list.\n *\n * @param dataPIN The PIN used to derive the credential and database secrets.\n * @param storageURL The base URL used to access persisted database objects.\n * @param setupParams Optional parameters for creating a new credential.\n * @returns The authentication result.\n */\n public static async authenticate(\n dataPIN: string,\n storageURL: URLString,\n setupParams?: AuthenticationSetupParams\n ): Promise<AuthenticationResult> {\n try {\n this.storageURL = storageURL\n //\n const deviceEntropy = await deriveDeviceEntropy()\n if (!deviceEntropy) return 'authenticator-error'\n //\n this.sessionCredential = {\n timestamp: Date.now(),\n userAgent: readableUserAgent(),\n }\n //\n const dataPINBytes = Bytes.utf8.decode(dataPIN)\n //\n const credentialSecret = await Bytes.derive(\n deviceEntropy,\n dataPINBytes,\n 32\n )\n //\n const credentialID = await Cryptographic.identifier.derive(\n credentialSecret,\n Bytes.utf8.decode('@sovereignbase/explorer:CredentialID'),\n 32\n )\n this.sessionCredential.id = credentialID\n //\n const credentialCipherKey = await Cryptographic.cipherMessage.deriveKey(\n credentialSecret,\n Bytes.utf8.decode('@sovereignbase/explorer:CredentialCipherKey')\n )\n //\n let virtualEntropy: Uint8Array\n ////////\n // SETUP\n if (isRecord(setupParams)) {\n virtualEntropy = Bytes.generate(64)\n\n void (await this.storeObjectByID(\n credentialID,\n virtualEntropy,\n credentialCipherKey\n ))\n\n this.sessionCredential.name = setupParams.credentialName\n this.sessionCredential.entropy = deviceEntropy\n this.sessionCredential.storage = setupParams.bindingStorage\n }\n ////////\n // LOGIN\n else {\n const result = await this.loadObjectByID(\n credentialID,\n credentialCipherKey\n )\n if (!(result instanceof Uint8Array) || result.byteLength !== 64)\n return 'invalid-data-pin'\n\n virtualEntropy = result\n }\n //\n this.databaseSecret = await Bytes.derive(virtualEntropy, dataPINBytes, 64)\n\n this.databaseID = await Cryptographic.identifier.derive(\n this.databaseSecret,\n Bytes.utf8.decode('@sovereignbase/explorer:DatabaseID'),\n 32\n )\n\n this.isAuthenticated = true\n\n void (await this.loadCredentialEntries()).record(this.sessionCredential)\n delete this.sessionCredential\n\n void this.dispatchEvent('authenticated', true)\n\n return 'authenticated'\n } catch (cause) {\n throw unknownError(cause, 'Explorer.authenticate()')\n }\n }\n\n /**\n * Permanently revokes a credential and deletes its persisted data.\n *\n * Removes the credential from the database's registered credentials.\n *\n * @param credentialID The identifier of the credential to revoke.\n * @throws {ExplorerError} If the database is not authenticated.\n */\n public static async permanentlyDeleteCredential(\n credentialID: string\n ): Promise<void> {\n try {\n return void (await (\n await this.loadCredentialEntries()\n ).revoke(credentialID))\n } catch (cause) {\n throw unknownError(cause, 'Explorer.permanentlyDeleteCredential()')\n }\n }\n\n /**\n * Returns the registered credentials and optionally observes their changes.\n *\n * The returned tuple contains a cleanup function, the current credential\n * entries, and the identifier of the current session's credential.\n *\n * The cleanup function removes the registered change listener, if any.\n *\n * @param onChange An optional callback invoked when the entries change.\n * @returns The cleanup function, credential entries, and session credential ID.\n * @throws {ExplorerError} If the database is not authenticated.\n */\n public static async listCredentialEntries(\n onChange?: (splice: CredentialEntriesChange) => void\n ): Promise<\n [\n cleanup: () => void,\n entries: DeepReadonly<Array<CredentialEntry>>,\n sessionCredentialID: string,\n ]\n > {\n try {\n const credentialEntries = await this.loadCredentialEntries()\n\n const listener = onChange\n ? ({ detail }: CustomEvent<CredentialEntriesChange>) => onChange(detail)\n : undefined\n\n if (listener) credentialEntries.addEventListener('change', listener)\n\n return [\n () => {\n if (listener)\n credentialEntries.removeEventListener('change', listener)\n },\n credentialEntries.list(),\n credentialEntries.sessionCredentialID,\n ]\n } catch (cause) {\n throw unknownError(cause, 'Explorer.listCredentialEntries()')\n }\n }\n\n /**\n * Returns the recently accessed objects and optionally observes their changes.\n *\n * The returned tuple contains a cleanup function and the current recent\n * entries. The cleanup function removes the registered change listener,\n * if any.\n *\n * @param onChange An optional callback invoked when the entries change.\n * @returns The cleanup function and recent entries.\n * @throws {ExplorerError} If the database is not authenticated.\n */\n public static async listRecentEntries(\n onChange?: (splice: RecentEntriesChange) => void\n ): Promise<[cleanup: () => void, entries: DeepReadonly<Array<RecentEntry>>]> {\n try {\n const recentEntries = await this.loadRecentEntries()\n\n const listener = onChange\n ? ({ detail }: CustomEvent<RecentEntriesChange>) => onChange(detail)\n : undefined\n\n if (listener) recentEntries.addEventListener('change', listener)\n\n return [\n () => {\n if (listener) recentEntries.removeEventListener('change', listener)\n },\n recentEntries.list(),\n ]\n } catch (cause) {\n throw unknownError(cause, 'Explorer.listRecentEntries()')\n }\n }\n\n /**\n * Loads an encrypted object using its identifier and cipher key.\n *\n * Caches the cipher key if the identifier has not been encountered before.\n *\n * @typeParam T The expected type of the loaded object.\n * @param id The identifier of the object to load.\n * @param cipherKey The key used to decrypt the object.\n * @param onNetworkResponse An optional callback for network responses.\n * @returns The loaded object, or `undefined` if no object is available.\n */\n public static async loadObjectByID<T>(\n id: string,\n cipherKey: CipherKey,\n onNetworkResponse?: (data: unknown) => void | Promise<void>\n ): Promise<T | undefined> {\n try {\n if (!this.cipherKeyCache.has(id))\n void this.cipherKeyCache.set(id, cipherKey)\n //\n return (await loadObject(\n (this.storageURL + id) as URLString,\n cipherKey,\n false,\n onNetworkResponse\n )) as T\n } catch (cause) {\n throw unknownError(cause, 'Explorer.loadObjectByID()')\n }\n }\n\n /**\n * Encrypts and stores an object using its identifier and cipher key.\n *\n * Caches the cipher key if the identifier has not been encountered before.\n *\n * @typeParam T The type of the object to store.\n * @param id The identifier of the object to store.\n * @param object The object to encrypt and store.\n * @param cipherKey The key used to encrypt the object.\n */\n public static async storeObjectByID<T>(\n id: string,\n object: T,\n cipherKey: CipherKey\n ): Promise<void> {\n try {\n if (!this.cipherKeyCache.has(id))\n void this.cipherKeyCache.set(id, cipherKey)\n //\n return void (await storeObject(\n (this.storageURL + id) as URLString,\n object,\n cipherKey\n ))\n } catch (cause) {\n throw unknownError(cause, 'Explorer.storeObjectByID()')\n }\n }\n\n /**\n * Deletes a persisted object using its identifier.\n *\n * @param id The identifier of the object to delete.\n */\n public static async deleteObjectByID(id: string): Promise<void> {\n try {\n void (await deleteObject((this.storageURL + id) as URLString))\n return void (await this.loadRecentEntries()).delete(id)\n } catch (cause) {\n throw unknownError(cause, 'Explorer.deleteObjectByID()')\n }\n }\n\n /**\n * Schedules the application of a synchronized Explorer delta.\n *\n * Recognized deltas are forwarded to their corresponding entries list.\n * Invalid or unrecognized delta types are ignored.\n *\n * Processing is scheduled in a microtask and is not awaited by the caller.\n *\n * @param data The delta to apply.\n */\n public static apply(data: unknown): void {\n return void queueMicrotask(async () => {\n try {\n if (!this.isExplorerDelta(data)) return\n switch (data[0]) {\n case 'recentEntries': {\n void (await this.loadRecentEntries()).apply(data[1])\n break\n }\n case 'credentialEntries': {\n void (await this.loadCredentialEntries()).apply(data[1])\n break\n }\n }\n return\n } catch (cause) {\n throw unknownError(cause, 'Explorer.apply()')\n }\n })\n }\n\n //* ███████╗██╗ ██╗███████╗███╗ ██╗████████╗ ████████╗ █████╗ ██████╗ ██████╗ ███████╗████████╗\n //* ██╔════╝██║ ██║██╔════╝████╗ ██║╚══██╔══╝ ╚══██╔══╝██╔══██╗██╔════╝ ██╔════╝╚══██╔══╝\n //* █████╗ ██║ ██║█████╗ ██╔██╗ ██║ ██║ ██║ ███████║██████╔╝██║ ███╗█████╗ ██║\n //* ██╔══╝ ╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║ ██║ ██╔══██║██╔══██╗██║ ██║██╔══╝ ██║\n //* ███████╗ ╚████╔╝ ███████╗██║ ╚████║ ██║ ██║ ██║ ██║██║ ██║╚██████╔╝███████╗ ██║\n //* ╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝\n\n /**\n * Registers an event listener for the specified event type.\n *\n * @param type The event type.\n * @param listener The event listener, or `null`.\n * @param options The event listener options.\n */\n public static addEventListener<K extends keyof ExplorerEventMap>(\n type: K,\n listener: ExplorerEventListenerFor<K> | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n try {\n void (this.eventTarget ??= new EventTarget()).addEventListener(\n type,\n listener as EventListenerOrEventListenerObject | null,\n options\n )\n } catch (cause) {\n throw unknownError(cause, 'Explorer.addEventListener()')\n }\n }\n\n /**\n * Removes an event listener previously registered with\n * {@link addEventListener}.\n *\n * @param type The event type.\n * @param listener The event listener to remove, or `null`.\n * @param options The event listener options.\n */\n public static removeEventListener<K extends keyof ExplorerEventMap>(\n type: K,\n listener: ExplorerEventListenerFor<K> | null,\n options?: boolean | EventListenerOptions\n ): void {\n try {\n void this.eventTarget?.removeEventListener(\n type,\n listener as EventListenerOrEventListenerObject | null,\n options\n )\n } catch (cause) {\n throw unknownError(cause, 'Explorer.removeEventListener()')\n }\n }\n\n /**\n * Dispatches an event to the registered listeners.\n *\n * @param type The event type.\n * @param detail The value exposed through `CustomEvent.detail`.\n */\n public static dispatchEvent<K extends keyof ExplorerEventMap>(\n type: K,\n detail: ExplorerEventMap[K]\n ): void {\n try {\n void this.eventTarget?.dispatchEvent(new CustomEvent(type, { detail }))\n } catch (cause) {\n throw unknownError(cause, 'Explorer.dispatchEvent()')\n }\n }\n\n //* ██╗ ██╗███████╗██╗ ██████╗ ███████╗██████╗ ███████╗\n //* ██║ ██║██╔════╝██║ ██╔══██╗██╔════╝██╔══██╗██╔════╝\n //* ███████║█████╗ ██║ ██████╔╝█████╗ ██████╔╝███████╗\n //* ██╔══██║██╔══╝ ██║ ██╔═══╝ ██╔══╝ ██╔══██╗╚════██║\n //* ██║ ██║███████╗███████╗██║ ███████╗██║ ██║███████║\n //* ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝\n\n /**\n * Determines whether a value has the basic structure of an Explorer delta.\n *\n * @param data The value to inspect.\n * @returns Whether the value has a string discriminator.\n */\n private static isExplorerDelta(data: unknown): data is ExplorerDelta {\n return Array.isArray(data) && typeof data[0] === 'string'\n }\n\n private static recentEntries?: RecentEntries\n\n /**\n * Loads or returns the cached recent entries list.\n *\n * Derives the list identifier and cipher key from the database secret\n * and merges subsequent network responses into the loaded state.\n *\n * @returns The recent entries list.\n * @throws {ExplorerError} If the database is not authenticated.\n */\n private static async loadRecentEntries(): Promise<RecentEntries> {\n try {\n if (!this.isAuthenticated) throw new ExplorerError('NOT_AUTHENTICATED')\n\n if (this.recentEntries) return this.recentEntries\n\n const id = await Cryptographic.identifier.derive(\n this.databaseSecret,\n Bytes.utf8.decode('@sovereignbase/explorer:RecentEntriesID'),\n 32\n )\n const ck = await Cryptographic.cipherMessage.deriveKey(\n this.databaseSecret,\n Bytes.utf8.decode('@sovereignbase/explorer:RecentEntriesCipherKey')\n )\n\n const trustedSnapshot = await this.loadObjectByID(\n id,\n ck,\n (snapshot) => void this.recentEntries!.merge(snapshot)\n )\n\n this.recentEntries = new RecentEntries(id, ck, 0, trustedSnapshot)\n\n return this.recentEntries\n } catch (cause) {\n throw unknownError(cause, 'Explorer.loadRecentEntries()')\n }\n }\n\n private static credentialEntries?: CredentialEntries\n\n /**\n * Loads or returns the cached credential entries list.\n *\n * Derives the list identifier and cipher key from the database secret\n * and merges subsequent network responses into the loaded state.\n *\n * @returns The credential entries list.\n * @throws {ExplorerError} If the database is not authenticated.\n */\n private static async loadCredentialEntries(): Promise<CredentialEntries> {\n try {\n if (!this.isAuthenticated) throw new ExplorerError('NOT_AUTHENTICATED')\n\n if (this.credentialEntries) return this.credentialEntries\n\n const id = await Cryptographic.identifier.derive(\n this.databaseSecret,\n Bytes.utf8.decode('@sovereignbase/explorer:CredentialEntriesID'),\n 32\n )\n const ck = await Cryptographic.cipherMessage.deriveKey(\n this.databaseSecret,\n Bytes.utf8.decode('@sovereignbase/explorer:CredentialEntriesCipherKey')\n )\n\n const trustedSnapshot = await this.loadObjectByID(\n id,\n ck,\n (snapshot) => void this.credentialEntries!.merge(snapshot)\n )\n\n this.credentialEntries = new CredentialEntries(\n id,\n ck,\n this.sessionCredential!.id!,\n 0,\n trustedSnapshot\n )\n\n return this.credentialEntries\n } catch (cause) {\n throw unknownError(cause, 'Explorer.loadCredentialEntries()')\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAa,gBAAb,cAAmC,MAAM;;CAEvC;;;;;;;;CASA,YACE,MACA,SACA,SACA;EACA,MAAM,6BAA6B,WAAW,QAAQ,OAAO;EAC7D,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;;;;;;AC7BA,SAAgB,aAAa,OAAgB,WAAkC;CAC7E,OAAO,iBAAiB,gBACpB,QACA,IAAI,cAAc,iBAAiB,GAAG,UAAU,WAAW,EAAE,MAAM,CAAC;AAC1E;;;;;;;;ACiHA,IAAa,oBAAb,MAA+B;CAgBV;CACA;CACD;CAjBlB;CACA,cACE,IAAI,MAAM;CACZ;;;;;;;;;;CAWA,YACE,IACA,WACA,qBACA,SACA,iBACA;EALiB,KAAA,KAAA;EACA,KAAA,YAAA;EACD,KAAA,sBAAA;EAIhB,IAAI;GACF,KAAK,QAAQ,IAAIA,yBAAAA,UAAU,MAAM,SAAS,eAAe;GAEzD,MAAM,qBAAA,GAAoBC,qBAAAA,aAAAA,CAAa,WAAW;IAChD,SAAc,cAAc,SAAS,CACnC,qBACA,KAAK,YAAY,OAAO,CAAC,CAC3B,CAAC;GACH,CAAC;GAED,KAAU,MAAM,iBAAiB,UAAU,EAAE,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AAAA,MAAM,KAAK,OAAO,yCAAyC,GAC3D,EACF;GACA,MAAM,KAAK,MAAMC,2BAAAA,cAAc,cAAc,UAC3C,KAAK,gBACLD,yBAAAA,MAAM,KAAK,OAAO,gDAAgD,CACpE;GAEA,MAAM,kBAAkB,MAAM,KAAK,eACjC,IACA,KACC,aAAa,KAAK,KAAK,cAAe,MAAM,QAAQ,CACvD;GAEA,KAAK,gBAAgB,IAAI,cAAc,IAAI,IAAI,GAAG,eAAe;GAEjE,OAAO,KAAK;EACd,SAAS,OAAO;GACd,MAAM,aAAa,OAAO,8BAA8B;EAC1D;CACF;CAEA,OAAe;;;;;;;;;;CAWf,aAAqB,wBAAoD;EACvE,IAAI;GACF,IAAI,CAAC,KAAK,iBAAiB,MAAM,IAAI,cAAc,mBAAmB;GAEtE,IAAI,KAAK,mBAAmB,OAAO,KAAK;GAExC,MAAM,KAAK,MAAMC,2BAAAA,cAAc,WAAW,OACxC,KAAK,gBACLD,yBAAAA,MAAM,KAAK,OAAO,6CAA6C,GAC/D,EACF;GACA,MAAM,KAAK,MAAMC,2BAAAA,cAAc,cAAc,UAC3C,KAAK,gBACLD,yBAAAA,MAAM,KAAK,OAAO,oDAAoD,CACxE;GAEA,MAAM,kBAAkB,MAAM,KAAK,eACjC,IACA,KACC,aAAa,KAAK,KAAK,kBAAmB,MAAM,QAAQ,CAC3D;GAEA,KAAK,oBAAoB,IAAI,kBAC3B,IACA,IACA,KAAK,kBAAmB,IACxB,GACA,eACF;GAEA,OAAO,KAAK;EACd,SAAS,OAAO;GACd,MAAM,aAAa,OAAO,kCAAkC;EAC9D;CACF;AACF"}
|
package/dist/class.d.cts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
|
|
2
|
+
import { URLString } from "@sovereignbase/storage";
|
|
3
|
+
import { DeepReadonly } from "@sovereignbase/utils";
|
|
4
|
+
import { CipherKey } from "@sovereignbase/cryptosuite";
|
|
5
|
+
import { SequencedArrayChange, SequencedArrayDelta } from "@sovereignbase/sequenced";
|
|
6
|
+
import { DeviceBindingStorage } from "@sovereignbase/hardware-bound";
|
|
7
|
+
/**
|
|
8
|
+
* Describes an entry in the recent objects list.
|
|
9
|
+
*/
|
|
10
|
+
type RecentEntry = {
|
|
11
|
+
/** The identifier of the referenced object. */
|
|
12
|
+
id: string;
|
|
13
|
+
/** The display name of the referenced object. */
|
|
14
|
+
name: string;
|
|
15
|
+
/** The cipher key used to access the referenced object. */
|
|
16
|
+
cipherKey: CipherKey;
|
|
17
|
+
/** The date and time at which the object was most recently accessed. */
|
|
18
|
+
dateAccessed: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Represents a sequenced delta produced by the recent entries list.
|
|
22
|
+
*/
|
|
23
|
+
type RecentEntriesDelta = Readonly<['recentEntries', DeepReadonly<SequencedArrayDelta<RecentEntry>>]>;
|
|
24
|
+
/**
|
|
25
|
+
* Represents a sequenced change produced by the recent entries list.
|
|
26
|
+
*/
|
|
27
|
+
type RecentEntriesChange = DeepReadonly<SequencedArrayChange<RecentEntry>>;
|
|
28
|
+
/**
|
|
29
|
+
* Describes a credential registered with the database.
|
|
30
|
+
*/
|
|
31
|
+
type CredentialEntry = {
|
|
32
|
+
/** The identifier of the credential. */
|
|
33
|
+
id: string;
|
|
34
|
+
/** The display name of the credential. */
|
|
35
|
+
name: string;
|
|
36
|
+
/** The entropy associated with the credential. */
|
|
37
|
+
entropy: Uint8Array;
|
|
38
|
+
/** The storage mechanism used for device binding. */
|
|
39
|
+
storage: DeviceBindingStorage;
|
|
40
|
+
/** The timestamp of the most recent use of the credential. */
|
|
41
|
+
lastUsed: number;
|
|
42
|
+
/** The user agents that have used the credential. */
|
|
43
|
+
userAgents: Array<{
|
|
44
|
+
/** The user agent string. */
|
|
45
|
+
name: string;
|
|
46
|
+
/** The timestamp of the most recent use by the user agent. */
|
|
47
|
+
lastSeen: number;
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Represents a sequenced delta produced by the credential entries list.
|
|
52
|
+
*/
|
|
53
|
+
type CredentialEntriesDelta = Readonly<['credentialEntries', DeepReadonly<SequencedArrayDelta<CredentialEntry>>]>;
|
|
54
|
+
/**
|
|
55
|
+
* Represents a sequenced change produced by the credential entries list.
|
|
56
|
+
*/
|
|
57
|
+
type CredentialEntriesChange = DeepReadonly<SequencedArrayChange<CredentialEntry>>;
|
|
58
|
+
/**
|
|
59
|
+
* Represents the outcome of a database authentication attempt.
|
|
60
|
+
*/
|
|
61
|
+
type AuthenticationResult =
|
|
62
|
+
/** The database was successfully authenticated. */
|
|
63
|
+
'authenticated' |
|
|
64
|
+
/** The device authenticator could not provide the required entropy. */
|
|
65
|
+
'authenticator-error' |
|
|
66
|
+
/** The supplied data PIN could not unlock the credential. */
|
|
67
|
+
'invalid-data-pin';
|
|
68
|
+
/**
|
|
69
|
+
* Describes the parameters used to register a new database credential.
|
|
70
|
+
*/
|
|
71
|
+
type AuthenticationSetupParams = Readonly<{
|
|
72
|
+
/** The display name assigned to the credential. */
|
|
73
|
+
credentialName: string;
|
|
74
|
+
/** The storage mechanism used to bind the credential to the device. */
|
|
75
|
+
bindingStorage: DeviceBindingStorage;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Represents a synchronized delta exchanged between Explorer instances.
|
|
79
|
+
*
|
|
80
|
+
* Includes changes to recent and credential entries, as well as
|
|
81
|
+
* a reserved variant for other delta types.
|
|
82
|
+
*/
|
|
83
|
+
type ExplorerDelta = RecentEntriesDelta | CredentialEntriesDelta | ['other' | []];
|
|
84
|
+
/**
|
|
85
|
+
* Maps Explorer event names to their detail types.
|
|
86
|
+
*/
|
|
87
|
+
type ExplorerEventMap = {
|
|
88
|
+
/** Fired when the database authentication state changes. */
|
|
89
|
+
authenticated: boolean;
|
|
90
|
+
/** Fired when a synchronized delta is produced. */
|
|
91
|
+
delta: ExplorerDelta;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Represents an event listener for an {@link Explorer} event.
|
|
95
|
+
*
|
|
96
|
+
* @typeParam K The event name that determines the event detail type.
|
|
97
|
+
*/
|
|
98
|
+
type ExplorerEventListener<K extends keyof ExplorerEventMap> = ((event: CustomEvent<ExplorerEventMap[K]>) => void) | {
|
|
99
|
+
handleEvent(event: CustomEvent<ExplorerEventMap[K]>): void;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Resolves an event name to its corresponding listener type.
|
|
103
|
+
*
|
|
104
|
+
* @typeParam K The event name to resolve.
|
|
105
|
+
*/
|
|
106
|
+
type ExplorerEventListenerFor<K extends string> = K extends keyof ExplorerEventMap ? ExplorerEventListener<K> : EventListenerOrEventListenerObject;
|
|
107
|
+
/**
|
|
108
|
+
* Provides authentication, encrypted object storage, and access to
|
|
109
|
+
* the database's synchronized entries.
|
|
110
|
+
*
|
|
111
|
+
* Maintains the authenticated database context and exposes static methods
|
|
112
|
+
* for managing stored objects, observing entries, and applying remote deltas.
|
|
113
|
+
*/
|
|
114
|
+
export declare class Explorer {
|
|
115
|
+
/** The identifier of the authenticated database. */
|
|
116
|
+
static databaseID: string;
|
|
117
|
+
/** Indicates whether the database has been authenticated. */
|
|
118
|
+
static isAuthenticated: boolean;
|
|
119
|
+
private static storageURL;
|
|
120
|
+
private static eventTarget?;
|
|
121
|
+
private static databaseSecret;
|
|
122
|
+
private static sessionCredential?;
|
|
123
|
+
/**
|
|
124
|
+
* Caches cipher keys by object identifier.
|
|
125
|
+
*
|
|
126
|
+
* Existing entries are preserved when an object is accessed with
|
|
127
|
+
* a cipher key.
|
|
128
|
+
*/
|
|
129
|
+
static readonly cipherKeyCache: Map<string, CipherKey>;
|
|
130
|
+
/**
|
|
131
|
+
* Authenticates a database using a data PIN and device-bound entropy.
|
|
132
|
+
*
|
|
133
|
+
* Derives the credential and database identifiers from cryptographic
|
|
134
|
+
* secrets. When setup parameters are provided, creates and stores a
|
|
135
|
+
* new credential. Otherwise, loads the existing credential.
|
|
136
|
+
*
|
|
137
|
+
* Records the authenticated credential in the database's credential list.
|
|
138
|
+
*
|
|
139
|
+
* @param dataPIN The PIN used to derive the credential and database secrets.
|
|
140
|
+
* @param storageURL The base URL used to access persisted database objects.
|
|
141
|
+
* @param setupParams Optional parameters for creating a new credential.
|
|
142
|
+
* @returns The authentication result.
|
|
143
|
+
*/
|
|
144
|
+
static authenticate(dataPIN: string, storageURL: URLString, setupParams?: AuthenticationSetupParams): Promise<AuthenticationResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Permanently revokes a credential and deletes its persisted data.
|
|
147
|
+
*
|
|
148
|
+
* Removes the credential from the database's registered credentials.
|
|
149
|
+
*
|
|
150
|
+
* @param credentialID The identifier of the credential to revoke.
|
|
151
|
+
* @throws {ExplorerError} If the database is not authenticated.
|
|
152
|
+
*/
|
|
153
|
+
static permanentlyDeleteCredential(credentialID: string): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Returns the registered credentials and optionally observes their changes.
|
|
156
|
+
*
|
|
157
|
+
* The returned tuple contains a cleanup function, the current credential
|
|
158
|
+
* entries, and the identifier of the current session's credential.
|
|
159
|
+
*
|
|
160
|
+
* The cleanup function removes the registered change listener, if any.
|
|
161
|
+
*
|
|
162
|
+
* @param onChange An optional callback invoked when the entries change.
|
|
163
|
+
* @returns The cleanup function, credential entries, and session credential ID.
|
|
164
|
+
* @throws {ExplorerError} If the database is not authenticated.
|
|
165
|
+
*/
|
|
166
|
+
static listCredentialEntries(onChange?: (splice: CredentialEntriesChange) => void): Promise<[cleanup: () => void, entries: DeepReadonly<Array<CredentialEntry>>, sessionCredentialID: string]>;
|
|
167
|
+
/**
|
|
168
|
+
* Returns the recently accessed objects and optionally observes their changes.
|
|
169
|
+
*
|
|
170
|
+
* The returned tuple contains a cleanup function and the current recent
|
|
171
|
+
* entries. The cleanup function removes the registered change listener,
|
|
172
|
+
* if any.
|
|
173
|
+
*
|
|
174
|
+
* @param onChange An optional callback invoked when the entries change.
|
|
175
|
+
* @returns The cleanup function and recent entries.
|
|
176
|
+
* @throws {ExplorerError} If the database is not authenticated.
|
|
177
|
+
*/
|
|
178
|
+
static listRecentEntries(onChange?: (splice: RecentEntriesChange) => void): Promise<[cleanup: () => void, entries: DeepReadonly<Array<RecentEntry>>]>;
|
|
179
|
+
/**
|
|
180
|
+
* Loads an encrypted object using its identifier and cipher key.
|
|
181
|
+
*
|
|
182
|
+
* Caches the cipher key if the identifier has not been encountered before.
|
|
183
|
+
*
|
|
184
|
+
* @typeParam T The expected type of the loaded object.
|
|
185
|
+
* @param id The identifier of the object to load.
|
|
186
|
+
* @param cipherKey The key used to decrypt the object.
|
|
187
|
+
* @param onNetworkResponse An optional callback for network responses.
|
|
188
|
+
* @returns The loaded object, or `undefined` if no object is available.
|
|
189
|
+
*/
|
|
190
|
+
static loadObjectByID<T>(id: string, cipherKey: CipherKey, onNetworkResponse?: (data: unknown) => void | Promise<void>): Promise<T | undefined>;
|
|
191
|
+
/**
|
|
192
|
+
* Encrypts and stores an object using its identifier and cipher key.
|
|
193
|
+
*
|
|
194
|
+
* Caches the cipher key if the identifier has not been encountered before.
|
|
195
|
+
*
|
|
196
|
+
* @typeParam T The type of the object to store.
|
|
197
|
+
* @param id The identifier of the object to store.
|
|
198
|
+
* @param object The object to encrypt and store.
|
|
199
|
+
* @param cipherKey The key used to encrypt the object.
|
|
200
|
+
*/
|
|
201
|
+
static storeObjectByID<T>(id: string, object: T, cipherKey: CipherKey): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Deletes a persisted object using its identifier.
|
|
204
|
+
*
|
|
205
|
+
* @param id The identifier of the object to delete.
|
|
206
|
+
*/
|
|
207
|
+
static deleteObjectByID(id: string): Promise<void>;
|
|
208
|
+
/**
|
|
209
|
+
* Schedules the application of a synchronized Explorer delta.
|
|
210
|
+
*
|
|
211
|
+
* Recognized deltas are forwarded to their corresponding entries list.
|
|
212
|
+
* Invalid or unrecognized delta types are ignored.
|
|
213
|
+
*
|
|
214
|
+
* Processing is scheduled in a microtask and is not awaited by the caller.
|
|
215
|
+
*
|
|
216
|
+
* @param data The delta to apply.
|
|
217
|
+
*/
|
|
218
|
+
static apply(data: unknown): void;
|
|
219
|
+
/**
|
|
220
|
+
* Registers an event listener for the specified event type.
|
|
221
|
+
*
|
|
222
|
+
* @param type The event type.
|
|
223
|
+
* @param listener The event listener, or `null`.
|
|
224
|
+
* @param options The event listener options.
|
|
225
|
+
*/
|
|
226
|
+
static addEventListener<K extends keyof ExplorerEventMap>(type: K, listener: ExplorerEventListenerFor<K> | null, options?: boolean | AddEventListenerOptions): void;
|
|
227
|
+
/**
|
|
228
|
+
* Removes an event listener previously registered with
|
|
229
|
+
* {@link addEventListener}.
|
|
230
|
+
*
|
|
231
|
+
* @param type The event type.
|
|
232
|
+
* @param listener The event listener to remove, or `null`.
|
|
233
|
+
* @param options The event listener options.
|
|
234
|
+
*/
|
|
235
|
+
static removeEventListener<K extends keyof ExplorerEventMap>(type: K, listener: ExplorerEventListenerFor<K> | null, options?: boolean | EventListenerOptions): void;
|
|
236
|
+
/**
|
|
237
|
+
* Dispatches an event to the registered listeners.
|
|
238
|
+
*
|
|
239
|
+
* @param type The event type.
|
|
240
|
+
* @param detail The value exposed through `CustomEvent.detail`.
|
|
241
|
+
*/
|
|
242
|
+
static dispatchEvent<K extends keyof ExplorerEventMap>(type: K, detail: ExplorerEventMap[K]): void;
|
|
243
|
+
/**
|
|
244
|
+
* Determines whether a value has the basic structure of an Explorer delta.
|
|
245
|
+
*
|
|
246
|
+
* @param data The value to inspect.
|
|
247
|
+
* @returns Whether the value has a string discriminator.
|
|
248
|
+
*/
|
|
249
|
+
private static isExplorerDelta;
|
|
250
|
+
private static recentEntries?;
|
|
251
|
+
/**
|
|
252
|
+
* Loads or returns the cached recent entries list.
|
|
253
|
+
*
|
|
254
|
+
* Derives the list identifier and cipher key from the database secret
|
|
255
|
+
* and merges subsequent network responses into the loaded state.
|
|
256
|
+
*
|
|
257
|
+
* @returns The recent entries list.
|
|
258
|
+
* @throws {ExplorerError} If the database is not authenticated.
|
|
259
|
+
*/
|
|
260
|
+
private static loadRecentEntries;
|
|
261
|
+
private static credentialEntries?;
|
|
262
|
+
/**
|
|
263
|
+
* Loads or returns the cached credential entries list.
|
|
264
|
+
*
|
|
265
|
+
* Derives the list identifier and cipher key from the database secret
|
|
266
|
+
* and merges subsequent network responses into the loaded state.
|
|
267
|
+
*
|
|
268
|
+
* @returns The credential entries list.
|
|
269
|
+
* @throws {ExplorerError} If the database is not authenticated.
|
|
270
|
+
*/
|
|
271
|
+
private static loadCredentialEntries;
|
|
272
|
+
}
|
|
273
|
+
export {};
|
|
274
|
+
//# sourceMappingURL=class.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class.d.cts","names":[],"sources":["../src/RecentEntries/class.ts","../src/CredentialEntries/class.ts","../src/.types/type.ts","../src/class.ts"],"mappings":";;;;;;;;;KAsBY;;EAEV;;EAGA;;EAGA,WAAW;;EAGX;;;;;KAMU,qBAAqB,2BACb,aAAa,oBAAoB;;;;KAMzC,sBAAsB,aAChC,qBAAqB;;;;KCvBX;;EAEV;;EAGA;;EAGA,SAAS;;EAGT,SAAS;;EAGT;;EAGA,YAAY;;IAEV;;IAGA;;;;;;KAiCQ,yBAAyB,+BACb,aAAa,oBAAoB;;;;KAM7C,0BAA0B,aACpC,qBAAqB;;;;KChFX;;;;;;;;;;KAWA,4BAA4B;;EAEtC;;EAGA,gBAAgB;;;;;;;;KASN,gBACV,qBAAqB;;;;KAKX;;EAEV;;EAGA,OAAO;;;;;;;KAQG,sBAAsB,gBAAgB,sBAC5C,OAAO,YAAY,iBAAiB;EACpC,YAAY,OAAO,YAAY,iBAAiB;;;;;;;KAO1C,yBAAyB,oBACnC,gBAAgB,mBACZ,sBAAsB,KACtB;;;;;;;;qBClBO;;SAEG;;SAGA;iBAGC;iBACA;iBACA;iBACA;;;;;;;kBAQQ,gBAAgB,YAAY;;;;;;;;;;;;;;;SAgB/B,aAClB,iBACA,YAAY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