@sovereignbase/explorer 0.0.0-alpha.4 → 0.0.0-alpha.6

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.
@@ -1 +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,aAAa;IACxD,KAAU,YAAY,KAAK,GAAG,MAAM;IACpC,kBAAuB;GACzB,CAAC;GAED,MAAM,iBAAA,GAAgBA,qBAAAA,aAAAA,CACpB,KACA,OAAO,aAAsD;IAC3D,MAAY,SAAS,gBACnB,KAAK,IACL,UACA,KAAK,SACP;GACF,CACF;GAEA,KAAU,MAAM,iB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AAe,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"}
1
+ {"version":3,"file":"class.cjs","names":["Sequenced","afterIdleFor","invalidateDeviceBinding","Sequenced","afterIdleFor","accessDeviceBinding","readableUserAgent","Bytes","Cryptographic","isRecord","createDeviceBinding","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 {\n invalidateDeviceBinding,\n type DeviceBindingStorage,\n} 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 display name of the credential. */\n name: string\n\n /** The entropy associated with the credential. */\n entropy: Uint8Array\n\n /** The storage characteristics of the device binding. */\n storage: DeviceBindingStorage\n\n /** The identifier of the object storing virtual entropy protected by the credential. */\n objectID: string\n\n /** The WebAuthn credential identifier. */\n credentialID: string\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 object identifier, timestamp, and user agent are required to record use.\n * Creating an entry additionally requires the credential identifier,\n * display name, entropy, and storage characteristics.\n */\nexport type CredentialEvent = {\n /** The identifier of the object storing the credential's virtual entropy. */\n objectID?: string\n\n /** The WebAuthn credential identifier. */\n credentialID?: 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 characteristics of the 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 registered credentials.\n *\n * Entries are identified by their object and credential identifiers.\n * Changes are synchronized through a sequenced array and persisted\n * 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 WebAuthn 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 seenObjects = new Set<string>()\n const seenCredentials = 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 (\n seenObjects.has(entry.objectID) ||\n seenCredentials.has(entry.credentialID)\n ) {\n duplicates.push(index)\n } else {\n seenObjects.add(entry.objectID)\n seenCredentials.add(entry.credentialID)\n }\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 {\n objectID,\n credentialID,\n timestamp,\n userAgent,\n name,\n entropy,\n storage,\n } = credentialEvent\n\n if (\n typeof objectID !== '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 object 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\n if (\n entry?.objectID === objectID ||\n (credentialID !== undefined && entry?.credentialID === credentialID)\n ) {\n existing = entry\n break\n }\n }\n\n if (\n !existing &&\n (typeof credentialID !== 'string' ||\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 credential ID, name, entropy, and binding storage.'\n )\n\n const userAgents =\n existing?.userAgents.map((agent) => ({ ...agent })) ?? []\n\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 objectID,\n credentialID: credentialID ?? existing!.credentialID,\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 const current = this.state.at(index)\n\n if (\n current?.objectID === entry.objectID ||\n current?.credentialID === entry.credentialID\n )\n 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 and removes its registered entries.\n *\n * Deletes the credential's persisted objects before removing its entries.\n * The entries remain unchanged if deletion fails. Credential invalidation\n * is requested on a best-effort basis after successful removal.\n *\n * @param credentialID The WebAuthn credential identifier to revoke.\n */\n public async revoke(credentialID: string): Promise<void> {\n try {\n const objectIDs = new Set<string>()\n\n for (let index = this.state.length - 1; index >= 0; index--) {\n const entry = this.state.at(index)\n\n if (entry?.credentialID === credentialID) objectIDs.add(entry.objectID)\n }\n\n if (objectIDs.size === 0) return\n\n for (const objectID of objectIDs)\n await Explorer.deleteObjectByID(objectID)\n\n let removed = false\n\n for (let index = this.state.length - 1; index >= 0; index--) {\n if (this.state.at(index)?.credentialID === credentialID) {\n void this.state.delete(index)\n removed = true\n }\n }\n\n if (removed) void this.state.snapshot()\n\n try {\n await invalidateDeviceBinding(credentialID)\n } catch {\n // Credential invalidation is best-effort.\n }\n\n // Log out.\n if (credentialID === this.sessionCredentialID)\n void window.location.reload()\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 credential identifier.\n */\n public list(): DeepReadonly<Array<CredentialEntry>> {\n try {\n return this.state\n .slice()\n .sort(\n (a, b) =>\n b.lastUsed - a.lastUsed ||\n a.credentialID.localeCompare(b.credentialID)\n )\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 * 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 {\n accessDeviceBinding,\n createDeviceBinding,\n} from '@sovereignbase/hardware-bound'\nimport {\n Cryptographic,\n type DecapsulateKey,\n type EncapsulateKey,\n type KeyOffer,\n type CipherKey,\n type CipherMessage,\n} 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 access to an authenticated Sovereignbase database.\n *\n * Manages database authentication, encrypted object storage, credential\n * registration, database linking, and synchronized entries.\n */\nexport class Explorer {\n /** The identifier of the authenticated database. */\n public static databaseID: string\n\n /** Indicates whether a database has been authenticated. */\n public static isAuthenticated: boolean\n\n /** The base URL used to access database objects. */\n private static storageURL: URLString\n\n /** The event target used for Explorer events. */\n private static eventTarget?: EventTarget\n\n /** The data PIN associated with the current session. */\n private static dataPIN: string\n\n /** The virtual entropy associated with the authenticated database. */\n private static virtualEntropy: Readonly<Uint8Array>\n\n /** The secret used to access the authenticated database. */\n private static databaseSecret: Readonly<Uint8Array>\n\n /** The credential information associated with the current authentication. */\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 an existing device binding.\n *\n * Establishes the authenticated database context and records the credential\n * used for authentication.\n *\n * When setup parameters are provided, registers a credential using the\n * supplied virtual entropy or generates new virtual entropy.\n *\n * @param dataPIN The PIN associated with the database.\n * @param storageURL The base URL used to access database objects.\n * @param setupParams Optional parameters for registering a credential.\n *\n * @param credentialId An optional credential identifier used to restrict credential selection.\n * @returns The authentication result.\n */\n public static async authenticate(\n dataPIN: string,\n storageURL: URLString,\n setupParams?: AuthenticationSetupParams,\n credentialId?: string\n ): Promise<AuthenticationResult> {\n try {\n this.dataPIN = dataPIN\n this.storageURL = storageURL\n //\n const deviceBinding = await accessDeviceBinding(credentialId)\n if (!Array.isArray(deviceBinding)) return 'authenticator-error'\n const [credentialID, deviceEntropy] = deviceBinding\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 credentialObjectID = await Cryptographic.identifier.derive(\n credentialSecret,\n Bytes.utf8.decode('@sovereignbase/explorer:CredentialObjectID'),\n 32\n )\n this.sessionCredential.objectID = credentialObjectID\n this.sessionCredential.credentialID = credentialID\n //\n const credentialCipherKey = await Cryptographic.cipherMessage.deriveKey(\n credentialSecret,\n Bytes.utf8.decode('@sovereignbase/explorer:CredentialCipherKey')\n )\n //\n ////////\n // SETUP\n if (isRecord(setupParams)) {\n this.virtualEntropy =\n setupParams.virtualEntropy instanceof Uint8Array\n ? setupParams.virtualEntropy\n : Bytes.generate(64)\n\n void (await this.storeObjectByID(\n credentialObjectID,\n this.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 credentialObjectID,\n credentialCipherKey\n )\n if (!(result instanceof Uint8Array) || result.byteLength !== 64)\n return 'invalid-data-pin'\n\n this.virtualEntropy = result\n }\n //\n this.databaseSecret = await Bytes.derive(\n this.virtualEntropy,\n dataPINBytes,\n 64\n )\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 /** The number of consecutive failed database linking PIN attempts. */\n private static failCounter: number = 0\n\n /**\n * Prepares an authenticated database for linking to another device.\n *\n * Verifies the current data PIN and prepares an encrypted transfer\n * containing the information required to access the same database.\n *\n * Repeated PIN failures cause the current page to reload.\n *\n * @param dataPIN The PIN associated with the authenticated database.\n * @param encapsulateKey The key used to establish encryption for the transfer.\n * @returns The key offer and encrypted transfer message, or `false`\n * if the supplied PIN is incorrect.\n */\n public static async prepareDatabaseLink(\n dataPIN: string,\n encapsulateKey: EncapsulateKey\n ): Promise<[keyOffer: KeyOffer, cipherMessage: CipherMessage] | false> {\n try {\n if (!this.isAuthenticated) throw new ExplorerError('NOT_AUTHENTICATED')\n\n if (dataPIN !== this.dataPIN) {\n if (this.failCounter >= 2) void window.location.reload() // log out\n this.failCounter++\n return false\n }\n\n this.failCounter = 0\n\n const { keyOffer, cipherKey } =\n await Cryptographic.keyAgreement.encapsulate(encapsulateKey)\n\n const cipherMessage = await Cryptographic.cipherMessage.encrypt(\n cipherKey,\n Bytes.concat([this.virtualEntropy, Bytes.utf8.decode(dataPIN)])\n )\n\n return [keyOffer, cipherMessage]\n } catch (cause) {\n throw unknownError(cause, 'Explorer.prepareDatabaseLink()')\n }\n }\n\n /**\n * Links the current device to an existing database.\n *\n * Accesses the transferred database information, creates a device binding,\n * and registers a credential for the existing database.\n *\n * @param keyOffer The key offer associated with the database link.\n * @param cipherMessage The encrypted database linking message.\n * @param decapsulateKey The key used to establish decryption for the transfer.\n * @param credentialName The display name assigned to the new credential.\n * @param storageURL The base URL used to access database objects.\n * @returns `true` if the database was linked and authenticated;\n * otherwise, `false`.\n */\n public static async linkToDatabase(\n keyOffer: KeyOffer,\n cipherMessage: CipherMessage,\n decapsulateKey: DecapsulateKey,\n credentialName: string,\n storageURL: URLString\n ): Promise<boolean> {\n try {\n const { cipherKey } = await Cryptographic.keyAgreement.decapsulate(\n keyOffer,\n decapsulateKey\n )\n const raw = await Cryptographic.cipherMessage.decrypt(\n cipherKey,\n cipherMessage\n )\n\n const setupResult = await createDeviceBinding(credentialName)\n if (!Array.isArray(setupResult)) return false\n const [credentialId, bindingStorage] = setupResult\n\n const result = await this.authenticate(\n Bytes.utf8.encode(raw.slice(64)),\n storageURL,\n {\n credentialName,\n virtualEntropy: raw.slice(0, 64),\n bindingStorage,\n },\n credentialId\n )\n\n return result === 'authenticated' ? true : false\n } catch (cause) {\n throw unknownError(cause, 'Explorer.linkToDatabase()')\n }\n }\n\n /**\n * Permanently revokes a registered database credential.\n *\n * Removes the credential's persisted data and registration from\n * the authenticated database.\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 database credentials.\n *\n * Optionally registers a listener for changes to the credential entries.\n * The returned cleanup function removes the registered listener.\n *\n * @param onChange An optional callback invoked when the entries change.\n * @returns The cleanup function, credential entries, and identifier\n * of the current session's credential.\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 database objects.\n *\n * Optionally registers a listener for changes to the recent entries.\n * The returned cleanup function removes the registered listener.\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 database object by its identifier.\n *\n * Caches the supplied cipher key if no key has been cached for the object.\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 a database object by its identifier.\n *\n * Caches the supplied cipher key if no key has been cached for the object.\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 database object by its identifier.\n *\n * Removes the persisted object and its corresponding recent entry.\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 Explorer event.\n *\n * @typeParam K The event name that determines the event detail type.\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 * @typeParam K The event name that determines the listener type.\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 Explorer event to registered listeners.\n *\n * @typeParam K The event name that determines the event detail type.\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 /** The cached recent entries list. */\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 /** The cached credential entries list. */\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!.credentialID!,\n 0,\n trustedSnapshot\n )\n\n return this.credentialEntries\n } catch (cause) {\n throw unknownError(cause, 'Explorer.loadCredentialEntries()')\n }\n }\n}\n\nexport { ExplorerError, type ExplorerErrorCode } from './.errors/class.js'\n\nexport * from './.types/type.js'\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;;;;;;;;;AC4HA,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,IA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;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,cACxB,GACA,eACF;GAEA,OAAO,KAAK;EACd,SAAS,OAAO;GACd,MAAM,aAAa,OAAO,kCAAkC;EAC9D;CACF;AACF"}
package/dist/class.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { URLString } from "@sovereignbase/storage";
3
3
  import { DeepReadonly } from "@sovereignbase/utils";
4
- import { CipherKey } from "@sovereignbase/cryptosuite";
4
+ import { CipherKey, CipherMessage, DecapsulateKey, EncapsulateKey, KeyOffer } from "@sovereignbase/cryptosuite";
5
5
  import { SequencedArrayChange, SequencedArrayDelta } from "@sovereignbase/sequenced";
6
6
  import { DeviceBindingStorage } from "@sovereignbase/hardware-bound";
7
7
  /**
@@ -29,14 +29,16 @@ type RecentEntriesChange = DeepReadonly<SequencedArrayChange<RecentEntry>>;
29
29
  * Describes a credential registered with the database.
30
30
  */
31
31
  type CredentialEntry = {
32
- /** The identifier of the credential. */
33
- id: string;
34
32
  /** The display name of the credential. */
35
33
  name: string;
36
34
  /** The entropy associated with the credential. */
37
35
  entropy: Uint8Array;
38
- /** The storage mechanism used for device binding. */
36
+ /** The storage characteristics of the device binding. */
39
37
  storage: DeviceBindingStorage;
38
+ /** The identifier of the object storing virtual entropy protected by the credential. */
39
+ objectID: string;
40
+ /** The WebAuthn credential identifier. */
41
+ credentialID: string;
40
42
  /** The timestamp of the most recent use of the credential. */
41
43
  lastUsed: number;
42
44
  /** The user agents that have used the credential. */
@@ -58,7 +60,7 @@ type CredentialEntriesChange = DeepReadonly<SequencedArrayChange<CredentialEntry
58
60
  /**
59
61
  * Represents the outcome of a database authentication attempt.
60
62
  */
61
- type AuthenticationResult =
63
+ export type AuthenticationResult =
62
64
  /** The database was successfully authenticated. */
63
65
  'authenticated' |
64
66
  /** The device authenticator could not provide the required entropy. */
@@ -68,9 +70,11 @@ type AuthenticationResult =
68
70
  /**
69
71
  * Describes the parameters used to register a new database credential.
70
72
  */
71
- type AuthenticationSetupParams = Readonly<{
73
+ export type AuthenticationSetupParams = Readonly<{
72
74
  /** The display name assigned to the credential. */
73
75
  credentialName: string;
76
+ /** Optional virtual entropy used to establish an existing database. */
77
+ virtualEntropy?: Uint8Array;
74
78
  /** The storage mechanism used to bind the credential to the device. */
75
79
  bindingStorage: DeviceBindingStorage;
76
80
  }>;
@@ -80,11 +84,11 @@ type AuthenticationSetupParams = Readonly<{
80
84
  * Includes changes to recent and credential entries, as well as
81
85
  * a reserved variant for other delta types.
82
86
  */
83
- type ExplorerDelta = RecentEntriesDelta | CredentialEntriesDelta | ['other' | []];
87
+ export type ExplorerDelta = RecentEntriesDelta | CredentialEntriesDelta | ['other' | []];
84
88
  /**
85
89
  * Maps Explorer event names to their detail types.
86
90
  */
87
- type ExplorerEventMap = {
91
+ export type ExplorerEventMap = {
88
92
  /** Fired when the database authentication state changes. */
89
93
  authenticated: boolean;
90
94
  /** Fired when a synchronized delta is produced. */
@@ -95,7 +99,7 @@ type ExplorerEventMap = {
95
99
  *
96
100
  * @typeParam K The event name that determines the event detail type.
97
101
  */
98
- type ExplorerEventListener<K extends keyof ExplorerEventMap> = ((event: CustomEvent<ExplorerEventMap[K]>) => void) | {
102
+ export type ExplorerEventListener<K extends keyof ExplorerEventMap> = ((event: CustomEvent<ExplorerEventMap[K]>) => void) | {
99
103
  handleEvent(event: CustomEvent<ExplorerEventMap[K]>): void;
100
104
  };
101
105
  /**
@@ -103,22 +107,57 @@ type ExplorerEventListener<K extends keyof ExplorerEventMap> = ((event: CustomEv
103
107
  *
104
108
  * @typeParam K The event name to resolve.
105
109
  */
106
- type ExplorerEventListenerFor<K extends string> = K extends keyof ExplorerEventMap ? ExplorerEventListener<K> : EventListenerOrEventListenerObject;
110
+ export type ExplorerEventListenerFor<K extends string> = K extends keyof ExplorerEventMap ? ExplorerEventListener<K> : EventListenerOrEventListenerObject;
111
+ /** Identifies an Explorer failure independently of its human-readable message. */
112
+ type ExplorerErrorCode =
113
+ /** An unexpected failure was wrapped with its original cause. */
114
+ 'UNKNOWN_ERROR' |
115
+ /** A credential event is missing required identifying or usage information. */
116
+ 'INVALID_CREDENTIAL_EVENT' |
117
+ /** A new credential does not provide all required setup properties. */
118
+ 'MISSING_CREDENTIAL_SETUP_PROPERTIES' |
119
+ /** An operation requires an authenticated Explorer session. */
120
+ 'NOT_AUTHENTICATED';
121
+ /**
122
+ * An Explorer error with a stable, machine-readable code and an optional cause.
123
+ *
124
+ * The message is prefixed with the library name. Use {@link code} rather than
125
+ * parsing the message when handling a particular failure.
126
+ */
127
+ export declare class ExplorerError extends Error {
128
+ /** The machine-readable category of the failure. */
129
+ readonly code: ExplorerErrorCode;
130
+ /**
131
+ * Creates an error whose name is `ExplorerError`.
132
+ *
133
+ * @param code The category of the failure.
134
+ * @param message The detail to prefix with the library name; defaults to `code`.
135
+ * @param options Error options, including the original `cause`.
136
+ */
137
+ constructor(code: ExplorerErrorCode, message?: string, options?: ErrorOptions);
138
+ }
107
139
  /**
108
- * Provides authentication, encrypted object storage, and access to
109
- * the database's synchronized entries.
140
+ * Provides access to an authenticated Sovereignbase database.
110
141
  *
111
- * Maintains the authenticated database context and exposes static methods
112
- * for managing stored objects, observing entries, and applying remote deltas.
142
+ * Manages database authentication, encrypted object storage, credential
143
+ * registration, database linking, and synchronized entries.
113
144
  */
114
145
  export declare class Explorer {
115
146
  /** The identifier of the authenticated database. */
116
147
  static databaseID: string;
117
- /** Indicates whether the database has been authenticated. */
148
+ /** Indicates whether a database has been authenticated. */
118
149
  static isAuthenticated: boolean;
150
+ /** The base URL used to access database objects. */
119
151
  private static storageURL;
152
+ /** The event target used for Explorer events. */
120
153
  private static eventTarget?;
154
+ /** The data PIN associated with the current session. */
155
+ private static dataPIN;
156
+ /** The virtual entropy associated with the authenticated database. */
157
+ private static virtualEntropy;
158
+ /** The secret used to access the authenticated database. */
121
159
  private static databaseSecret;
160
+ /** The credential information associated with the current authentication. */
122
161
  private static sessionCredential?;
123
162
  /**
124
163
  * Caches cipher keys by object identifier.
@@ -128,48 +167,80 @@ export declare class Explorer {
128
167
  */
129
168
  static readonly cipherKeyCache: Map<string, CipherKey>;
130
169
  /**
131
- * Authenticates a database using a data PIN and device-bound entropy.
170
+ * Authenticates a database using a data PIN and an existing device binding.
132
171
  *
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.
172
+ * Establishes the authenticated database context and records the credential
173
+ * used for authentication.
136
174
  *
137
- * Records the authenticated credential in the database's credential list.
175
+ * When setup parameters are provided, registers a credential using the
176
+ * supplied virtual entropy or generates new virtual entropy.
138
177
  *
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.
178
+ * @param dataPIN The PIN associated with the database.
179
+ * @param storageURL The base URL used to access database objects.
180
+ * @param setupParams Optional parameters for registering a credential.
181
+ *
182
+ * @param credentialId An optional credential identifier used to restrict credential selection.
142
183
  * @returns The authentication result.
143
184
  */
144
- static authenticate(dataPIN: string, storageURL: URLString, setupParams?: AuthenticationSetupParams): Promise<AuthenticationResult>;
185
+ static authenticate(dataPIN: string, storageURL: URLString, setupParams?: AuthenticationSetupParams, credentialId?: string): Promise<AuthenticationResult>;
186
+ /** The number of consecutive failed database linking PIN attempts. */
187
+ private static failCounter;
188
+ /**
189
+ * Prepares an authenticated database for linking to another device.
190
+ *
191
+ * Verifies the current data PIN and prepares an encrypted transfer
192
+ * containing the information required to access the same database.
193
+ *
194
+ * Repeated PIN failures cause the current page to reload.
195
+ *
196
+ * @param dataPIN The PIN associated with the authenticated database.
197
+ * @param encapsulateKey The key used to establish encryption for the transfer.
198
+ * @returns The key offer and encrypted transfer message, or `false`
199
+ * if the supplied PIN is incorrect.
200
+ */
201
+ static prepareDatabaseLink(dataPIN: string, encapsulateKey: EncapsulateKey): Promise<[keyOffer: KeyOffer, cipherMessage: CipherMessage] | false>;
202
+ /**
203
+ * Links the current device to an existing database.
204
+ *
205
+ * Accesses the transferred database information, creates a device binding,
206
+ * and registers a credential for the existing database.
207
+ *
208
+ * @param keyOffer The key offer associated with the database link.
209
+ * @param cipherMessage The encrypted database linking message.
210
+ * @param decapsulateKey The key used to establish decryption for the transfer.
211
+ * @param credentialName The display name assigned to the new credential.
212
+ * @param storageURL The base URL used to access database objects.
213
+ * @returns `true` if the database was linked and authenticated;
214
+ * otherwise, `false`.
215
+ */
216
+ static linkToDatabase(keyOffer: KeyOffer, cipherMessage: CipherMessage, decapsulateKey: DecapsulateKey, credentialName: string, storageURL: URLString): Promise<boolean>;
145
217
  /**
146
- * Permanently revokes a credential and deletes its persisted data.
218
+ * Permanently revokes a registered database credential.
147
219
  *
148
- * Removes the credential from the database's registered credentials.
220
+ * Removes the credential's persisted data and registration from
221
+ * the authenticated database.
149
222
  *
150
223
  * @param credentialID The identifier of the credential to revoke.
151
224
  * @throws {ExplorerError} If the database is not authenticated.
152
225
  */
153
226
  static permanentlyDeleteCredential(credentialID: string): Promise<void>;
154
227
  /**
155
- * Returns the registered credentials and optionally observes their changes.
228
+ * Returns the registered database credentials.
156
229
  *
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.
230
+ * Optionally registers a listener for changes to the credential entries.
231
+ * The returned cleanup function removes the registered listener.
161
232
  *
162
233
  * @param onChange An optional callback invoked when the entries change.
163
- * @returns The cleanup function, credential entries, and session credential ID.
234
+ * @returns The cleanup function, credential entries, and identifier
235
+ * of the current session's credential.
164
236
  * @throws {ExplorerError} If the database is not authenticated.
165
237
  */
166
238
  static listCredentialEntries(onChange?: (splice: CredentialEntriesChange) => void): Promise<[cleanup: () => void, entries: DeepReadonly<Array<CredentialEntry>>, sessionCredentialID: string]>;
167
239
  /**
168
- * Returns the recently accessed objects and optionally observes their changes.
240
+ * Returns the recently accessed database objects.
169
241
  *
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.
242
+ * Optionally registers a listener for changes to the recent entries.
243
+ * The returned cleanup function removes the registered listener.
173
244
  *
174
245
  * @param onChange An optional callback invoked when the entries change.
175
246
  * @returns The cleanup function and recent entries.
@@ -177,9 +248,9 @@ export declare class Explorer {
177
248
  */
178
249
  static listRecentEntries(onChange?: (splice: RecentEntriesChange) => void): Promise<[cleanup: () => void, entries: DeepReadonly<Array<RecentEntry>>]>;
179
250
  /**
180
- * Loads an encrypted object using its identifier and cipher key.
251
+ * Loads an encrypted database object by its identifier.
181
252
  *
182
- * Caches the cipher key if the identifier has not been encountered before.
253
+ * Caches the supplied cipher key if no key has been cached for the object.
183
254
  *
184
255
  * @typeParam T The expected type of the loaded object.
185
256
  * @param id The identifier of the object to load.
@@ -189,9 +260,9 @@ export declare class Explorer {
189
260
  */
190
261
  static loadObjectByID<T>(id: string, cipherKey: CipherKey, onNetworkResponse?: (data: unknown) => void | Promise<void>): Promise<T | undefined>;
191
262
  /**
192
- * Encrypts and stores an object using its identifier and cipher key.
263
+ * Encrypts and stores a database object by its identifier.
193
264
  *
194
- * Caches the cipher key if the identifier has not been encountered before.
265
+ * Caches the supplied cipher key if no key has been cached for the object.
195
266
  *
196
267
  * @typeParam T The type of the object to store.
197
268
  * @param id The identifier of the object to store.
@@ -200,7 +271,9 @@ export declare class Explorer {
200
271
  */
201
272
  static storeObjectByID<T>(id: string, object: T, cipherKey: CipherKey): Promise<void>;
202
273
  /**
203
- * Deletes a persisted object using its identifier.
274
+ * Deletes a database object by its identifier.
275
+ *
276
+ * Removes the persisted object and its corresponding recent entry.
204
277
  *
205
278
  * @param id The identifier of the object to delete.
206
279
  */
@@ -217,8 +290,9 @@ export declare class Explorer {
217
290
  */
218
291
  static apply(data: unknown): void;
219
292
  /**
220
- * Registers an event listener for the specified event type.
293
+ * Registers an event listener for the specified Explorer event.
221
294
  *
295
+ * @typeParam K The event name that determines the event detail type.
222
296
  * @param type The event type.
223
297
  * @param listener The event listener, or `null`.
224
298
  * @param options The event listener options.
@@ -228,14 +302,16 @@ export declare class Explorer {
228
302
  * Removes an event listener previously registered with
229
303
  * {@link addEventListener}.
230
304
  *
305
+ * @typeParam K The event name that determines the listener type.
231
306
  * @param type The event type.
232
307
  * @param listener The event listener to remove, or `null`.
233
308
  * @param options The event listener options.
234
309
  */
235
310
  static removeEventListener<K extends keyof ExplorerEventMap>(type: K, listener: ExplorerEventListenerFor<K> | null, options?: boolean | EventListenerOptions): void;
236
311
  /**
237
- * Dispatches an event to the registered listeners.
312
+ * Dispatches an Explorer event to registered listeners.
238
313
  *
314
+ * @typeParam K The event name that determines the event detail type.
239
315
  * @param type The event type.
240
316
  * @param detail The value exposed through `CustomEvent.detail`.
241
317
  */
@@ -247,6 +323,7 @@ export declare class Explorer {
247
323
  * @returns Whether the value has a string discriminator.
248
324
  */
249
325
  private static isExplorerDelta;
326
+ /** The cached recent entries list. */
250
327
  private static recentEntries?;
251
328
  /**
252
329
  * Loads or returns the cached recent entries list.
@@ -258,6 +335,7 @@ export declare class Explorer {
258
335
  * @throws {ExplorerError} If the database is not authenticated.
259
336
  */
260
337
  private static loadRecentEntries;
338
+ /** The cached credential entries list. */
261
339
  private static credentialEntries?;
262
340
  /**
263
341
  * Loads or returns the cached credential entries list.
@@ -270,5 +348,5 @@ export declare class Explorer {
270
348
  */
271
349
  private static loadCredentialEntries;
272
350
  }
273
- export {};
351
+ export type { ExplorerErrorCode };
274
352
  //# sourceMappingURL=class.d.cts.map