@noy-db/hub 0.1.0-pre.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +197 -0
- package/dist/aggregate/index.cjs +476 -0
- package/dist/aggregate/index.cjs.map +1 -0
- package/dist/aggregate/index.d.cts +38 -0
- package/dist/aggregate/index.d.ts +38 -0
- package/dist/aggregate/index.js +53 -0
- package/dist/aggregate/index.js.map +1 -0
- package/dist/blobs/index.cjs +1480 -0
- package/dist/blobs/index.cjs.map +1 -0
- package/dist/blobs/index.d.cts +45 -0
- package/dist/blobs/index.d.ts +45 -0
- package/dist/blobs/index.js +48 -0
- package/dist/blobs/index.js.map +1 -0
- package/dist/bundle/index.cjs +436 -0
- package/dist/bundle/index.cjs.map +1 -0
- package/dist/bundle/index.d.cts +7 -0
- package/dist/bundle/index.d.ts +7 -0
- package/dist/bundle/index.js +40 -0
- package/dist/bundle/index.js.map +1 -0
- package/dist/chunk-2QR2PQTT.js +217 -0
- package/dist/chunk-2QR2PQTT.js.map +1 -0
- package/dist/chunk-4OWFYIDQ.js +79 -0
- package/dist/chunk-4OWFYIDQ.js.map +1 -0
- package/dist/chunk-5AATM2M2.js +90 -0
- package/dist/chunk-5AATM2M2.js.map +1 -0
- package/dist/chunk-ACLDOTNQ.js +543 -0
- package/dist/chunk-ACLDOTNQ.js.map +1 -0
- package/dist/chunk-BTDCBVJW.js +160 -0
- package/dist/chunk-BTDCBVJW.js.map +1 -0
- package/dist/chunk-CIMZBAZB.js +72 -0
- package/dist/chunk-CIMZBAZB.js.map +1 -0
- package/dist/chunk-E445ICYI.js +365 -0
- package/dist/chunk-E445ICYI.js.map +1 -0
- package/dist/chunk-EXQRC2L4.js +722 -0
- package/dist/chunk-EXQRC2L4.js.map +1 -0
- package/dist/chunk-FZU343FL.js +32 -0
- package/dist/chunk-FZU343FL.js.map +1 -0
- package/dist/chunk-GJILMRPO.js +354 -0
- package/dist/chunk-GJILMRPO.js.map +1 -0
- package/dist/chunk-GOUT6DND.js +1285 -0
- package/dist/chunk-GOUT6DND.js.map +1 -0
- package/dist/chunk-J66GRPNH.js +111 -0
- package/dist/chunk-J66GRPNH.js.map +1 -0
- package/dist/chunk-M2F2JAWB.js +464 -0
- package/dist/chunk-M2F2JAWB.js.map +1 -0
- package/dist/chunk-M5INGEFC.js +84 -0
- package/dist/chunk-M5INGEFC.js.map +1 -0
- package/dist/chunk-M62XNWRA.js +72 -0
- package/dist/chunk-M62XNWRA.js.map +1 -0
- package/dist/chunk-MR4424N3.js +275 -0
- package/dist/chunk-MR4424N3.js.map +1 -0
- package/dist/chunk-NPC4LFV5.js +132 -0
- package/dist/chunk-NPC4LFV5.js.map +1 -0
- package/dist/chunk-NXFEYLVG.js +311 -0
- package/dist/chunk-NXFEYLVG.js.map +1 -0
- package/dist/chunk-R36SIKES.js +79 -0
- package/dist/chunk-R36SIKES.js.map +1 -0
- package/dist/chunk-TDR6T5CJ.js +381 -0
- package/dist/chunk-TDR6T5CJ.js.map +1 -0
- package/dist/chunk-UF3BUNQZ.js +1 -0
- package/dist/chunk-UF3BUNQZ.js.map +1 -0
- package/dist/chunk-UQFSPSWG.js +1109 -0
- package/dist/chunk-UQFSPSWG.js.map +1 -0
- package/dist/chunk-USKYUS74.js +793 -0
- package/dist/chunk-USKYUS74.js.map +1 -0
- package/dist/chunk-XCL3WP6J.js +121 -0
- package/dist/chunk-XCL3WP6J.js.map +1 -0
- package/dist/chunk-XHFOENR2.js +680 -0
- package/dist/chunk-XHFOENR2.js.map +1 -0
- package/dist/chunk-ZFKD4QMV.js +430 -0
- package/dist/chunk-ZFKD4QMV.js.map +1 -0
- package/dist/chunk-ZLMV3TUA.js +490 -0
- package/dist/chunk-ZLMV3TUA.js.map +1 -0
- package/dist/chunk-ZRG4V3F5.js +17 -0
- package/dist/chunk-ZRG4V3F5.js.map +1 -0
- package/dist/consent/index.cjs +204 -0
- package/dist/consent/index.cjs.map +1 -0
- package/dist/consent/index.d.cts +24 -0
- package/dist/consent/index.d.ts +24 -0
- package/dist/consent/index.js +23 -0
- package/dist/consent/index.js.map +1 -0
- package/dist/crdt/index.cjs +152 -0
- package/dist/crdt/index.cjs.map +1 -0
- package/dist/crdt/index.d.cts +30 -0
- package/dist/crdt/index.d.ts +30 -0
- package/dist/crdt/index.js +24 -0
- package/dist/crdt/index.js.map +1 -0
- package/dist/crypto-IVKU7YTT.js +44 -0
- package/dist/crypto-IVKU7YTT.js.map +1 -0
- package/dist/delegation-XDJCBTI2.js +16 -0
- package/dist/delegation-XDJCBTI2.js.map +1 -0
- package/dist/dev-unlock-CeXic1xC.d.cts +263 -0
- package/dist/dev-unlock-KrKkcqD3.d.ts +263 -0
- package/dist/hash-9KO1BGxh.d.cts +63 -0
- package/dist/hash-ChfJjRjQ.d.ts +63 -0
- package/dist/history/index.cjs +1215 -0
- package/dist/history/index.cjs.map +1 -0
- package/dist/history/index.d.cts +62 -0
- package/dist/history/index.d.ts +62 -0
- package/dist/history/index.js +79 -0
- package/dist/history/index.js.map +1 -0
- package/dist/i18n/index.cjs +746 -0
- package/dist/i18n/index.cjs.map +1 -0
- package/dist/i18n/index.d.cts +38 -0
- package/dist/i18n/index.d.ts +38 -0
- package/dist/i18n/index.js +55 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/index-BRHBCmLt.d.ts +1940 -0
- package/dist/index-C8kQtmOk.d.ts +380 -0
- package/dist/index-DN-J-5wT.d.cts +1940 -0
- package/dist/index-DhjMjz7L.d.cts +380 -0
- package/dist/index.cjs +14756 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +269 -0
- package/dist/index.d.ts +269 -0
- package/dist/index.js +6085 -0
- package/dist/index.js.map +1 -0
- package/dist/indexing/index.cjs +736 -0
- package/dist/indexing/index.cjs.map +1 -0
- package/dist/indexing/index.d.cts +36 -0
- package/dist/indexing/index.d.ts +36 -0
- package/dist/indexing/index.js +77 -0
- package/dist/indexing/index.js.map +1 -0
- package/dist/lazy-builder-BwEoBQZ9.d.ts +304 -0
- package/dist/lazy-builder-CZVLKh0Z.d.cts +304 -0
- package/dist/ledger-2NX4L7PN.js +33 -0
- package/dist/ledger-2NX4L7PN.js.map +1 -0
- package/dist/mime-magic-CBBSOkjm.d.cts +50 -0
- package/dist/mime-magic-CBBSOkjm.d.ts +50 -0
- package/dist/periods/index.cjs +1035 -0
- package/dist/periods/index.cjs.map +1 -0
- package/dist/periods/index.d.cts +21 -0
- package/dist/periods/index.d.ts +21 -0
- package/dist/periods/index.js +25 -0
- package/dist/periods/index.js.map +1 -0
- package/dist/predicate-SBHmi6D0.d.cts +161 -0
- package/dist/predicate-SBHmi6D0.d.ts +161 -0
- package/dist/query/index.cjs +1957 -0
- package/dist/query/index.cjs.map +1 -0
- package/dist/query/index.d.cts +3 -0
- package/dist/query/index.d.ts +3 -0
- package/dist/query/index.js +62 -0
- package/dist/query/index.js.map +1 -0
- package/dist/session/index.cjs +487 -0
- package/dist/session/index.cjs.map +1 -0
- package/dist/session/index.d.cts +45 -0
- package/dist/session/index.d.ts +45 -0
- package/dist/session/index.js +44 -0
- package/dist/session/index.js.map +1 -0
- package/dist/shadow/index.cjs +133 -0
- package/dist/shadow/index.cjs.map +1 -0
- package/dist/shadow/index.d.cts +16 -0
- package/dist/shadow/index.d.ts +16 -0
- package/dist/shadow/index.js +20 -0
- package/dist/shadow/index.js.map +1 -0
- package/dist/store/index.cjs +1069 -0
- package/dist/store/index.cjs.map +1 -0
- package/dist/store/index.d.cts +491 -0
- package/dist/store/index.d.ts +491 -0
- package/dist/store/index.js +34 -0
- package/dist/store/index.js.map +1 -0
- package/dist/strategy-BSxFXGzb.d.cts +110 -0
- package/dist/strategy-BSxFXGzb.d.ts +110 -0
- package/dist/strategy-D-SrOLCl.d.cts +548 -0
- package/dist/strategy-D-SrOLCl.d.ts +548 -0
- package/dist/sync/index.cjs +1062 -0
- package/dist/sync/index.cjs.map +1 -0
- package/dist/sync/index.d.cts +42 -0
- package/dist/sync/index.d.ts +42 -0
- package/dist/sync/index.js +28 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/team/index.cjs +1233 -0
- package/dist/team/index.cjs.map +1 -0
- package/dist/team/index.d.cts +117 -0
- package/dist/team/index.d.ts +117 -0
- package/dist/team/index.js +39 -0
- package/dist/team/index.js.map +1 -0
- package/dist/tx/index.cjs +212 -0
- package/dist/tx/index.cjs.map +1 -0
- package/dist/tx/index.d.cts +20 -0
- package/dist/tx/index.d.ts +20 -0
- package/dist/tx/index.js +20 -0
- package/dist/tx/index.js.map +1 -0
- package/dist/types-BZpCZB8N.d.ts +7526 -0
- package/dist/types-Bfs0qr5F.d.cts +7526 -0
- package/dist/ulid-COREQ2RQ.js +9 -0
- package/dist/ulid-COREQ2RQ.js.map +1 -0
- package/dist/util/index.cjs +230 -0
- package/dist/util/index.cjs.map +1 -0
- package/dist/util/index.d.cts +77 -0
- package/dist/util/index.d.ts +77 -0
- package/dist/util/index.js +190 -0
- package/dist/util/index.js.map +1 -0
- package/package.json +244 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { aq as Role, ar as UnlockedKeyring } from './types-BZpCZB8N.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Session tokens —
|
|
5
|
+
*
|
|
6
|
+
* After a vault is unlocked (via passphrase, WebAuthn, OIDC, or magic-
|
|
7
|
+
* link), the caller can call `createSession()` to get a session token that
|
|
8
|
+
* allows re-establishing the KEK for the session lifetime without re-running
|
|
9
|
+
* PBKDF2 or any interactive auth challenge.
|
|
10
|
+
*
|
|
11
|
+
* Security model
|
|
12
|
+
* ──────────────
|
|
13
|
+
* A session consists of two pieces that must both be present to recover the
|
|
14
|
+
* KEK:
|
|
15
|
+
*
|
|
16
|
+
* 1. The **session key** — a non-extractable AES-256-GCM CryptoKey that
|
|
17
|
+
* exists only in memory. "Non-extractable" is enforced by the WebCrypto
|
|
18
|
+
* API: the key object cannot be serialized, exported, or sent over
|
|
19
|
+
* postMessage. When the JS context is GC'd (tab close, navigation away,
|
|
20
|
+
* worker termination) the key becomes unrecoverable.
|
|
21
|
+
*
|
|
22
|
+
* 2. The **session token** — a JSON object that carries the KEK wrapped
|
|
23
|
+
* with the session key (AES-256-GCM, fresh IV per session), plus
|
|
24
|
+
* unencrypted session metadata (sessionId, userId, vault, role,
|
|
25
|
+
* expiresAt). The token can be serialized to JSON and stored in
|
|
26
|
+
* sessionStorage or passed across callsites within the same tab, but
|
|
27
|
+
* it is useless without the session key.
|
|
28
|
+
*
|
|
29
|
+
* The session key is kept in a module-level Map indexed by sessionId. Callers
|
|
30
|
+
* that need to re-use a session must hold on to the sessionId returned from
|
|
31
|
+
* `createSession()`; the key is looked up automatically by `resolveSession()`.
|
|
32
|
+
*
|
|
33
|
+
* Revocation: `revokeSession()` removes the entry from the Map. Because the
|
|
34
|
+
* key is non-extractable, removal is sufficient — no one holds a serializable
|
|
35
|
+
* copy of the key.
|
|
36
|
+
*
|
|
37
|
+
* Tab-scoped lifetime: the module-level Map lives only as long as the JS
|
|
38
|
+
* module. Tab close → module unloaded → Map GC'd → all session keys gone.
|
|
39
|
+
* This is the zero-effort logout: closing the tab is always a secure logout.
|
|
40
|
+
*
|
|
41
|
+
* Expiry: `createSession()` accepts a `ttlMs` option. `resolveSession()`
|
|
42
|
+
* checks `expiresAt` and throws `SessionExpiredError` if the token is stale,
|
|
43
|
+
* even if the session key is still in the Map.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/** The serializable part of a session token. Safe to store in sessionStorage. */
|
|
47
|
+
interface SessionToken {
|
|
48
|
+
readonly _noydb_session: 1;
|
|
49
|
+
/** Unique session identifier (ULID). Use this as the handle for resolve/revoke. */
|
|
50
|
+
readonly sessionId: string;
|
|
51
|
+
readonly userId: string;
|
|
52
|
+
readonly vault: string;
|
|
53
|
+
readonly role: Role;
|
|
54
|
+
/** ISO timestamp — resolveSession() rejects this token after this time. */
|
|
55
|
+
readonly expiresAt: string;
|
|
56
|
+
/** KEK wrapped with the session key (AES-256-GCM). Base64. */
|
|
57
|
+
readonly wrappedKek: string;
|
|
58
|
+
/** IV used for the wrapping operation. Base64. */
|
|
59
|
+
readonly kekIv: string;
|
|
60
|
+
}
|
|
61
|
+
/** Result returned from `createSession()`. */
|
|
62
|
+
interface CreateSessionResult {
|
|
63
|
+
/** Serializable token — store in sessionStorage or pass to `resolveSession()`. */
|
|
64
|
+
token: SessionToken;
|
|
65
|
+
/** The sessionId — use this handle for `resolveSession()` and `revokeSession()`. */
|
|
66
|
+
sessionId: string;
|
|
67
|
+
}
|
|
68
|
+
/** Options for `createSession()`. */
|
|
69
|
+
interface CreateSessionOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Session lifetime in milliseconds. Defaults to 60 minutes.
|
|
72
|
+
* After this duration, `resolveSession()` throws `SessionExpiredError`.
|
|
73
|
+
*/
|
|
74
|
+
ttlMs?: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a session for an already-unlocked keyring.
|
|
78
|
+
*
|
|
79
|
+
* Call this after any successful unlock (passphrase, WebAuthn, OIDC,
|
|
80
|
+
* magic-link). The returned `sessionId` is the handle for later
|
|
81
|
+
* `resolveSession()` and `revokeSession()` calls.
|
|
82
|
+
*
|
|
83
|
+
* The session key is generated fresh (non-extractable) and stored in the
|
|
84
|
+
* module-level Map. The KEK from `keyring.kek` is exported (it must be
|
|
85
|
+
* extractable — it was derived by `deriveKey()` which sets extractable: false,
|
|
86
|
+
* but it's unwrapped from the keyring which sets extractable: true) and then
|
|
87
|
+
* re-wrapped with the session key.
|
|
88
|
+
*
|
|
89
|
+
* @param keyring - An already-unlocked keyring whose `kek` is available.
|
|
90
|
+
* @param vault - The vault name this session is scoped to.
|
|
91
|
+
* @param options - Optional session configuration.
|
|
92
|
+
*/
|
|
93
|
+
declare function createSession(keyring: UnlockedKeyring, vault: string, options?: CreateSessionOptions): Promise<CreateSessionResult>;
|
|
94
|
+
/**
|
|
95
|
+
* Resolve a session token back into an UnlockedKeyring.
|
|
96
|
+
*
|
|
97
|
+
* Looks up the session key by `sessionId`, checks the token is not expired,
|
|
98
|
+
* then decrypts the payload to reconstruct the keyring's DEK set.
|
|
99
|
+
*
|
|
100
|
+
* Throws `SessionExpiredError` if the token's `expiresAt` is in the past.
|
|
101
|
+
* Throws `SessionNotFoundError` if the session key is not in the store
|
|
102
|
+
* (tab was reloaded, session was revoked, or the sessionId is wrong).
|
|
103
|
+
*
|
|
104
|
+
* @param token - The SessionToken from `createSession()`.
|
|
105
|
+
*/
|
|
106
|
+
declare function resolveSession(token: SessionToken): Promise<UnlockedKeyring>;
|
|
107
|
+
/**
|
|
108
|
+
* Revoke a session by removing its key from the store.
|
|
109
|
+
*
|
|
110
|
+
* After revocation, `resolveSession()` will throw `SessionNotFoundError`
|
|
111
|
+
* for this sessionId. The session token (if held by the caller) becomes
|
|
112
|
+
* permanently useless. This is the explicit logout path.
|
|
113
|
+
*
|
|
114
|
+
* No-op if the session was already expired or does not exist.
|
|
115
|
+
*/
|
|
116
|
+
declare function revokeSession(sessionId: string): void;
|
|
117
|
+
/**
|
|
118
|
+
* Check if a session is still alive (key in store + not expired).
|
|
119
|
+
* Does not decrypt anything — purely a metadata check.
|
|
120
|
+
*/
|
|
121
|
+
declare function isSessionAlive(token: SessionToken): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Revoke all active sessions. Used by `Noydb.close()` to ensure that
|
|
124
|
+
* closing the instance destroys all session state, not just the keyring
|
|
125
|
+
* cache.
|
|
126
|
+
*/
|
|
127
|
+
declare function revokeAllSessions(): void;
|
|
128
|
+
/**
|
|
129
|
+
* Return the number of active sessions currently in the store.
|
|
130
|
+
* Useful for diagnostics and tests.
|
|
131
|
+
*/
|
|
132
|
+
declare function activeSessionCount(): number;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Dev-mode persistent unlock —
|
|
136
|
+
*
|
|
137
|
+
* Solves the developer inner-loop friction: hot-reload destroys the session
|
|
138
|
+
* (page navigation semantics), forcing a passphrase re-entry every refresh.
|
|
139
|
+
*
|
|
140
|
+
* This module provides an opt-in, deliberately-named escape hatch that lets
|
|
141
|
+
* developers store the keyring payload in sessionStorage or localStorage so
|
|
142
|
+
* the vault auto-unlocks on every page load — without a passphrase,
|
|
143
|
+
* without a biometric prompt, without any OIDC flow.
|
|
144
|
+
*
|
|
145
|
+
* ⚠️ WARNING — this is a loaded footgun ⚠️
|
|
146
|
+
* ─────────────────────────────────────────
|
|
147
|
+
* The keyring payload stored by this module contains the DEKs. Whoever has
|
|
148
|
+
* access to sessionStorage/localStorage has access to the DEKs. On a shared
|
|
149
|
+
* development machine, a compromised browser extension, or a mis-configured
|
|
150
|
+
* origin, this is a complete key exposure.
|
|
151
|
+
*
|
|
152
|
+
* This module is ONLY safe for local development. It must NEVER be active
|
|
153
|
+
* in production builds.
|
|
154
|
+
*
|
|
155
|
+
* Guardrails (all enforced by the module, not by the caller)
|
|
156
|
+
* ──────────────────────────────────────────────────────────
|
|
157
|
+
* 1. **Production guard:** `enableDevUnlock()` throws immediately if
|
|
158
|
+
* `process.env.NODE_ENV === 'production'` or if `import.meta.env?.PROD === true`
|
|
159
|
+
* (Vite convention). Also throws if the hostname is NOT localhost or 127.0.0.1.
|
|
160
|
+
*
|
|
161
|
+
* 2. **Explicit acknowledgement string:** the caller must pass
|
|
162
|
+
* `acknowledge: 'I-UNDERSTAND-THIS-DISABLES-UNLOCK-SECURITY'` or the call
|
|
163
|
+
* throws. This string appears in every grep for `devUnlock` in the codebase,
|
|
164
|
+
* making it impossible to enable this feature accidentally.
|
|
165
|
+
*
|
|
166
|
+
* 3. **Scope is vault + userId:** the storage key includes both the
|
|
167
|
+
* vault name and the userId, so dev-unlock for vault-A does
|
|
168
|
+
* NOT auto-unlock vault-B.
|
|
169
|
+
*
|
|
170
|
+
* 4. **Storage scope:** default is `sessionStorage` (cleared on tab close).
|
|
171
|
+
* `localStorage` is opt-in and requires an additional
|
|
172
|
+
* `persistAcrossTabs: true` flag in the options.
|
|
173
|
+
*
|
|
174
|
+
* 5. **Clear method:** `clearDevUnlock()` removes the stored payload. Wire
|
|
175
|
+
* this to a dev toolbar button or `Ctrl+Shift+L` so clearing is one action.
|
|
176
|
+
*
|
|
177
|
+
* 6. **Console banner:** on first enable, a highly visible console warning
|
|
178
|
+
* fires. Cannot be suppressed.
|
|
179
|
+
*
|
|
180
|
+
* Usage
|
|
181
|
+
* ─────
|
|
182
|
+
* ```ts
|
|
183
|
+
* // In your dev entry point only (guarded by import.meta.env.DEV):
|
|
184
|
+
* if (import.meta.env.DEV) {
|
|
185
|
+
* const { enableDevUnlock, loadDevUnlock } = await import('@noy-db/hub')
|
|
186
|
+
* enableDevUnlock('my-compartment', 'alice', keyring, {
|
|
187
|
+
* acknowledge: 'I-UNDERSTAND-THIS-DISABLES-UNLOCK-SECURITY',
|
|
188
|
+
* })
|
|
189
|
+
* }
|
|
190
|
+
*
|
|
191
|
+
* // On page load:
|
|
192
|
+
* if (import.meta.env.DEV) {
|
|
193
|
+
* const keyring = await loadDevUnlock('my-compartment', 'alice')
|
|
194
|
+
* if (keyring) {
|
|
195
|
+
* // Skip unlock prompt, use keyring directly
|
|
196
|
+
* }
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
interface DevUnlockOptions {
|
|
202
|
+
/**
|
|
203
|
+
* Required: the exact string 'I-UNDERSTAND-THIS-DISABLES-UNLOCK-SECURITY'.
|
|
204
|
+
* Any other value causes `enableDevUnlock()` to throw.
|
|
205
|
+
*/
|
|
206
|
+
acknowledge: string;
|
|
207
|
+
/**
|
|
208
|
+
* If `true`, stores in localStorage (persists across tabs and browser restarts).
|
|
209
|
+
* If `false` (default), stores in sessionStorage (cleared on tab close).
|
|
210
|
+
*/
|
|
211
|
+
persistAcrossTabs?: boolean;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Serialize and store a keyring to browser storage for dev-mode auto-unlock.
|
|
215
|
+
*
|
|
216
|
+
* Throws immediately if:
|
|
217
|
+
* - The acknowledge string is wrong.
|
|
218
|
+
* - Running in a production environment (NODE_ENV=production).
|
|
219
|
+
* - Running on a non-localhost hostname.
|
|
220
|
+
*
|
|
221
|
+
* Emits a highly visible console warning that cannot be suppressed.
|
|
222
|
+
*
|
|
223
|
+
* @param vault - The vault name.
|
|
224
|
+
* @param userId - The user ID.
|
|
225
|
+
* @param keyring - The unlocked keyring to persist.
|
|
226
|
+
* @param options - Options including the required acknowledge string.
|
|
227
|
+
*/
|
|
228
|
+
declare function enableDevUnlock(vault: string, userId: string, keyring: UnlockedKeyring, options: DevUnlockOptions): Promise<void>;
|
|
229
|
+
/**
|
|
230
|
+
* Load a dev-mode keyring from browser storage.
|
|
231
|
+
*
|
|
232
|
+
* Returns `null` if no dev-unlock state is stored for this vault + user,
|
|
233
|
+
* or if the stored payload is malformed.
|
|
234
|
+
*
|
|
235
|
+
* Does NOT perform the production environment check — it's safe to CALL
|
|
236
|
+
* `loadDevUnlock` in production (it will simply return `null` because no
|
|
237
|
+
* dev-unlock state was ever written). The guard only fires on `enableDevUnlock`.
|
|
238
|
+
*
|
|
239
|
+
* @param vault - The vault name.
|
|
240
|
+
* @param userId - The user ID.
|
|
241
|
+
* @param options - Optional storage override.
|
|
242
|
+
*/
|
|
243
|
+
declare function loadDevUnlock(vault: string, userId: string, options?: {
|
|
244
|
+
persistAcrossTabs?: boolean;
|
|
245
|
+
}): Promise<UnlockedKeyring | null>;
|
|
246
|
+
/**
|
|
247
|
+
* Remove dev-unlock state from browser storage.
|
|
248
|
+
*
|
|
249
|
+
* Safe to call in production (no-op if no dev state exists).
|
|
250
|
+
*/
|
|
251
|
+
declare function clearDevUnlock(vault: string, userId: string, options?: {
|
|
252
|
+
persistAcrossTabs?: boolean;
|
|
253
|
+
}): void;
|
|
254
|
+
/**
|
|
255
|
+
* Check if dev-unlock state exists for this vault + user.
|
|
256
|
+
*
|
|
257
|
+
* Safe to call in production (returns false if nothing is stored).
|
|
258
|
+
*/
|
|
259
|
+
declare function isDevUnlockActive(vault: string, userId: string, options?: {
|
|
260
|
+
persistAcrossTabs?: boolean;
|
|
261
|
+
}): boolean;
|
|
262
|
+
|
|
263
|
+
export { type CreateSessionOptions as C, type DevUnlockOptions as D, type SessionToken as S, type CreateSessionResult as a, activeSessionCount as b, clearDevUnlock as c, createSession as d, enableDevUnlock as e, isSessionAlive as f, revokeAllSessions as g, revokeSession as h, isDevUnlockActive as i, loadDevUnlock as l, resolveSession as r };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { av as EncryptedEnvelope } from './types-Bfs0qr5F.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ledger storage constants — pinned in their own leaf module so
|
|
5
|
+
* always-on core code (vault.ts, dictionary.ts) can import them
|
|
6
|
+
* without dragging the `LedgerStore` class into the bundle.
|
|
7
|
+
*
|
|
8
|
+
* `splitting: true` in tsup is not enough on its own: when a
|
|
9
|
+
* source file exports both pure constants and a heavyweight class,
|
|
10
|
+
* the bundler keeps the entire chunk reachable from any importer.
|
|
11
|
+
* Extracting the constants lets the floor scenario import them
|
|
12
|
+
* without paying for the class.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
/** The internal collection name used for ledger entry storage. */
|
|
17
|
+
declare const LEDGER_COLLECTION = "_ledger";
|
|
18
|
+
/**
|
|
19
|
+
* The internal collection name used for delta payload storage.
|
|
20
|
+
*
|
|
21
|
+
* Deltas live in a sibling collection (not inside `_ledger`) for two
|
|
22
|
+
* reasons:
|
|
23
|
+
*
|
|
24
|
+
* 1. **Listing efficiency.** `ledger.loadAllEntries()` calls
|
|
25
|
+
* `adapter.list(_ledger)` which would otherwise return every
|
|
26
|
+
* delta key alongside every entry key. Splitting them keeps the
|
|
27
|
+
* list small (one key per ledger entry) and the delta reads
|
|
28
|
+
* keyed by the entry's index.
|
|
29
|
+
*
|
|
30
|
+
* 2. **Prune-friendliness.** A future `pruneHistory()` will delete
|
|
31
|
+
* old deltas while keeping the ledger chain intact (folding old
|
|
32
|
+
* deltas into a base snapshot). Separating the storage makes
|
|
33
|
+
* that deletion a targeted operation on one collection instead
|
|
34
|
+
* of a filter across a mixed list.
|
|
35
|
+
*
|
|
36
|
+
* Both collections share the same ledger DEK — one DEK, two
|
|
37
|
+
* internal collections, same zero-knowledge guarantees.
|
|
38
|
+
*/
|
|
39
|
+
declare const LEDGER_DELTAS_COLLECTION = "_ledger_deltas";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Envelope payload hash — pinned in its own leaf module so consumers
|
|
43
|
+
* (DictionaryHandle, the active history strategy) can import it
|
|
44
|
+
* without dragging in the `LedgerStore` class.
|
|
45
|
+
*
|
|
46
|
+
* see `constants.ts` for the broader rationale.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Compute the `payloadHash` value for an encrypted envelope. Used by
|
|
53
|
+
* `LedgerStore.append` for both put (hash the new envelope) and
|
|
54
|
+
* delete (hash the previous envelope) paths, and by
|
|
55
|
+
* `DictionaryHandle` so its ledger entries match the same contract.
|
|
56
|
+
*
|
|
57
|
+
* Returns the empty string when there is no envelope (delete of a
|
|
58
|
+
* never-existed record). The empty string tolerated by the ledger
|
|
59
|
+
* entry's `payloadHash` field as the canonical "nothing here" value.
|
|
60
|
+
*/
|
|
61
|
+
declare function envelopePayloadHash(envelope: EncryptedEnvelope | null): Promise<string>;
|
|
62
|
+
|
|
63
|
+
export { LEDGER_COLLECTION as L, LEDGER_DELTAS_COLLECTION as a, envelopePayloadHash as e };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { av as EncryptedEnvelope } from './types-BZpCZB8N.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ledger storage constants — pinned in their own leaf module so
|
|
5
|
+
* always-on core code (vault.ts, dictionary.ts) can import them
|
|
6
|
+
* without dragging the `LedgerStore` class into the bundle.
|
|
7
|
+
*
|
|
8
|
+
* `splitting: true` in tsup is not enough on its own: when a
|
|
9
|
+
* source file exports both pure constants and a heavyweight class,
|
|
10
|
+
* the bundler keeps the entire chunk reachable from any importer.
|
|
11
|
+
* Extracting the constants lets the floor scenario import them
|
|
12
|
+
* without paying for the class.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
/** The internal collection name used for ledger entry storage. */
|
|
17
|
+
declare const LEDGER_COLLECTION = "_ledger";
|
|
18
|
+
/**
|
|
19
|
+
* The internal collection name used for delta payload storage.
|
|
20
|
+
*
|
|
21
|
+
* Deltas live in a sibling collection (not inside `_ledger`) for two
|
|
22
|
+
* reasons:
|
|
23
|
+
*
|
|
24
|
+
* 1. **Listing efficiency.** `ledger.loadAllEntries()` calls
|
|
25
|
+
* `adapter.list(_ledger)` which would otherwise return every
|
|
26
|
+
* delta key alongside every entry key. Splitting them keeps the
|
|
27
|
+
* list small (one key per ledger entry) and the delta reads
|
|
28
|
+
* keyed by the entry's index.
|
|
29
|
+
*
|
|
30
|
+
* 2. **Prune-friendliness.** A future `pruneHistory()` will delete
|
|
31
|
+
* old deltas while keeping the ledger chain intact (folding old
|
|
32
|
+
* deltas into a base snapshot). Separating the storage makes
|
|
33
|
+
* that deletion a targeted operation on one collection instead
|
|
34
|
+
* of a filter across a mixed list.
|
|
35
|
+
*
|
|
36
|
+
* Both collections share the same ledger DEK — one DEK, two
|
|
37
|
+
* internal collections, same zero-knowledge guarantees.
|
|
38
|
+
*/
|
|
39
|
+
declare const LEDGER_DELTAS_COLLECTION = "_ledger_deltas";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Envelope payload hash — pinned in its own leaf module so consumers
|
|
43
|
+
* (DictionaryHandle, the active history strategy) can import it
|
|
44
|
+
* without dragging in the `LedgerStore` class.
|
|
45
|
+
*
|
|
46
|
+
* see `constants.ts` for the broader rationale.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Compute the `payloadHash` value for an encrypted envelope. Used by
|
|
53
|
+
* `LedgerStore.append` for both put (hash the new envelope) and
|
|
54
|
+
* delete (hash the previous envelope) paths, and by
|
|
55
|
+
* `DictionaryHandle` so its ledger entries match the same contract.
|
|
56
|
+
*
|
|
57
|
+
* Returns the empty string when there is no envelope (delete of a
|
|
58
|
+
* never-existed record). The empty string tolerated by the ledger
|
|
59
|
+
* entry's `payloadHash` field as the canonical "nothing here" value.
|
|
60
|
+
*/
|
|
61
|
+
declare function envelopePayloadHash(envelope: EncryptedEnvelope | null): Promise<string>;
|
|
62
|
+
|
|
63
|
+
export { LEDGER_COLLECTION as L, LEDGER_DELTAS_COLLECTION as a, envelopePayloadHash as e };
|