mindoodb 0.0.19 → 0.0.21
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 +200 -0
- package/README-server.md +14 -14
- package/README.md +12 -10
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts +6 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts.map +1 -1
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js +519 -373
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js.map +1 -1
- package/dist/browser/cache/IndexedDBLocalCacheStore.d.ts +12 -0
- package/dist/browser/cache/IndexedDBLocalCacheStore.d.ts.map +1 -1
- package/dist/browser/cache/IndexedDBLocalCacheStore.js +152 -65
- package/dist/browser/cache/IndexedDBLocalCacheStore.js.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +2 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +14 -0
- package/dist/core/BaseMindooDB.d.ts +594 -6
- package/dist/core/BaseMindooDB.d.ts.map +1 -1
- package/dist/core/BaseMindooDB.js +2478 -191
- package/dist/core/BaseMindooDB.js.map +1 -1
- package/dist/core/BaseMindooTenant.d.ts +65 -1
- package/dist/core/BaseMindooTenant.d.ts.map +1 -1
- package/dist/core/BaseMindooTenant.js +250 -35
- package/dist/core/BaseMindooTenant.js.map +1 -1
- package/dist/core/BaseMindooTenantFactory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantFactory.js +47 -18
- package/dist/core/BaseMindooTenantFactory.js.map +1 -1
- package/dist/core/DocumentConflictAnalysis.d.ts +22 -0
- package/dist/core/DocumentConflictAnalysis.d.ts.map +1 -0
- package/dist/core/DocumentConflictAnalysis.js +101 -0
- package/dist/core/DocumentConflictAnalysis.js.map +1 -0
- package/dist/core/MindooDBServerAdmin.d.ts +26 -1
- package/dist/core/MindooDBServerAdmin.d.ts.map +1 -1
- package/dist/core/MindooDBServerAdmin.js +19 -3
- package/dist/core/MindooDBServerAdmin.js.map +1 -1
- package/dist/core/appendonlystores/types.d.ts +9 -0
- package/dist/core/appendonlystores/types.d.ts.map +1 -1
- package/dist/core/automerge-adapter.d.ts.map +1 -1
- package/dist/core/automerge-adapter.js +26 -14
- package/dist/core/automerge-adapter.js.map +1 -1
- package/dist/core/cache/EncryptedLocalCacheStore.d.ts +51 -1
- package/dist/core/cache/EncryptedLocalCacheStore.d.ts.map +1 -1
- package/dist/core/cache/EncryptedLocalCacheStore.js +48 -9
- package/dist/core/cache/EncryptedLocalCacheStore.js.map +1 -1
- package/dist/core/cache/LocalCacheStore.d.ts +34 -0
- package/dist/core/cache/LocalCacheStore.d.ts.map +1 -1
- package/dist/core/cache/LocalCacheStore.js +16 -0
- package/dist/core/cache/LocalCacheStore.js.map +1 -1
- package/dist/core/databaseIdValidation.d.ts +13 -0
- package/dist/core/databaseIdValidation.d.ts.map +1 -0
- package/dist/core/databaseIdValidation.js +38 -0
- package/dist/core/databaseIdValidation.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts.map +1 -1
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js +5 -1
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualView.d.ts +14 -0
- package/dist/core/indexing/virtualviews/VirtualView.d.ts.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualView.js +38 -6
- package/dist/core/indexing/virtualviews/VirtualView.js.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts +9 -2
- package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualViewDataChange.js +10 -3
- package/dist/core/indexing/virtualviews/VirtualViewDataChange.js.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts +23 -1
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.js +17 -1
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.js.map +1 -1
- package/dist/core/indexing/virtualviews/types.d.ts +8 -0
- package/dist/core/indexing/virtualviews/types.d.ts.map +1 -1
- package/dist/core/indexing/virtualviews/types.js.map +1 -1
- package/dist/core/keys/KeyBag.d.ts +244 -7
- package/dist/core/keys/KeyBag.d.ts.map +1 -1
- package/dist/core/keys/KeyBag.js +299 -82
- package/dist/core/keys/KeyBag.js.map +1 -1
- package/dist/core/tenantIdValidation.d.ts +19 -0
- package/dist/core/tenantIdValidation.d.ts.map +1 -0
- package/dist/core/tenantIdValidation.js +43 -0
- package/dist/core/tenantIdValidation.js.map +1 -0
- package/dist/core/types.d.ts +703 -12
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/node/cache/FileSystemLocalCacheStore.d.ts +2 -1
- package/dist/node/cache/FileSystemLocalCacheStore.d.ts.map +1 -1
- package/dist/node/cache/FileSystemLocalCacheStore.js +4 -0
- package/dist/node/cache/FileSystemLocalCacheStore.js.map +1 -1
- package/dist/node/server/ServerSync.d.ts.map +1 -1
- package/dist/node/server/ServerSync.js +3 -1
- package/dist/node/server/ServerSync.js.map +1 -1
- package/dist/node/server/TenantManager.d.ts +1 -0
- package/dist/node/server/TenantManager.d.ts.map +1 -1
- package/dist/node/server/TenantManager.js +11 -3
- package/dist/node/server/TenantManager.js.map +1 -1
- package/dist/node/server/validation.d.ts +2 -6
- package/dist/node/server/validation.d.ts.map +1 -1
- package/dist/node/server/validation.js +14 -24
- package/dist/node/server/validation.js.map +1 -1
- package/dist/reactnative/cache/MMKVLocalCacheStore.d.ts +1 -0
- package/dist/reactnative/cache/MMKVLocalCacheStore.d.ts.map +1 -1
- package/dist/reactnative/cache/MMKVLocalCacheStore.js +14 -0
- package/dist/reactnative/cache/MMKVLocalCacheStore.js.map +1 -1
- package/package.json +25 -23
|
@@ -2,32 +2,222 @@ import { EncryptedPrivateKey } from "../types";
|
|
|
2
2
|
import { type KeyType } from "./KeyContext";
|
|
3
3
|
import { CryptoAdapter } from "../crypto/CryptoAdapter";
|
|
4
4
|
import { Logger } from "../logging";
|
|
5
|
+
/**
|
|
6
|
+
* Opaque cursor into the {@link KeyBag} local changes feed.
|
|
7
|
+
*
|
|
8
|
+
* `changeSeq` is a monotonic in-memory sequence number assigned to each
|
|
9
|
+
* doc-key mutation by {@link KeyBag.recordKeyChange}. The sequence is
|
|
10
|
+
* local to a single `KeyBag` instance and resets when the bag is
|
|
11
|
+
* recreated; cursors must therefore not be persisted across process
|
|
12
|
+
* restarts.
|
|
13
|
+
*/
|
|
14
|
+
export interface KeyBagChangeCursor {
|
|
15
|
+
changeSeq: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* High-level intent of a doc-key mutation event emitted by the {@link KeyBag}
|
|
19
|
+
* local changes feed. The action describes what the caller did to the bag,
|
|
20
|
+
* not whether a key remains afterwards (see {@link KeyBagChangeEvent.hasKey}).
|
|
21
|
+
*/
|
|
22
|
+
export type KeyBagChangeAction = "add" | "remove";
|
|
23
|
+
/**
|
|
24
|
+
* One event in the local {@link KeyBag} changes feed.
|
|
25
|
+
*
|
|
26
|
+
* Events are emitted by {@link KeyBag.set}, {@link KeyBag.createDocKey},
|
|
27
|
+
* {@link KeyBag.createTenantKey}, {@link KeyBag.decryptAndImportKey},
|
|
28
|
+
* {@link KeyBag.deleteKey}, and {@link KeyBag.deleteKeyVersion} whenever the
|
|
29
|
+
* set of available doc-key versions for a scoped key id actually changes.
|
|
30
|
+
*
|
|
31
|
+
* Events intentionally never carry raw key bytes: they are designed to be
|
|
32
|
+
* safe to pass through telemetry, listeners, and tests without expanding the
|
|
33
|
+
* exposure surface of secret material.
|
|
34
|
+
*/
|
|
35
|
+
export interface KeyBagChangeEvent {
|
|
36
|
+
/** Monotonic local sequence number assigned at emit time. */
|
|
37
|
+
changeSeq: number;
|
|
38
|
+
/** Scoped key type (currently always `"doc"`). */
|
|
39
|
+
type: KeyType;
|
|
40
|
+
/** Tenant the affected key belongs to. */
|
|
41
|
+
tenantId: string;
|
|
42
|
+
/** Key identifier within the tenant (e.g. `"default"`, `"$publicinfos"`, or a named key id). */
|
|
43
|
+
keyId: string;
|
|
44
|
+
/** Whether the caller added a key version or removed one. */
|
|
45
|
+
action: KeyBagChangeAction;
|
|
46
|
+
/** Number of remaining stored versions for this scoped key id after the mutation. */
|
|
47
|
+
versionsRemaining: number;
|
|
48
|
+
/** Convenience flag equal to `versionsRemaining > 0`. */
|
|
49
|
+
hasKey: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Listener callback registered through {@link KeyBag.onChanges}.
|
|
53
|
+
*
|
|
54
|
+
* Listener invocations happen synchronously from the mutating call site
|
|
55
|
+
* after the underlying key store has been updated. Listeners must be
|
|
56
|
+
* short-lived; long-running work should be deferred (`void`-prefixed
|
|
57
|
+
* promises or microtask scheduling are recommended).
|
|
58
|
+
*/
|
|
59
|
+
export type KeyBagChangeListener = (event: KeyBagChangeEvent) => void;
|
|
5
60
|
export interface KeyDetail {
|
|
6
61
|
scopedKeyId: string;
|
|
7
62
|
createdAt?: number;
|
|
8
63
|
keyLengthBits: number;
|
|
9
64
|
versionIndex: number;
|
|
10
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Options accepted by {@link KeyBag.constructor} when constructing a KeyBag from
|
|
68
|
+
* an already-derived AES-GCM wrapping {@link CryptoKey}.
|
|
69
|
+
*
|
|
70
|
+
* Prefer this form over the legacy password-taking constructor: the wrapping
|
|
71
|
+
* key can be derived once during user login (via {@link KeyBag.deriveWrappingKey})
|
|
72
|
+
* and held as a non-extractable {@link CryptoKey} for the lifetime of the
|
|
73
|
+
* session, so {@link KeyBag.save} and {@link KeyBag.load} no longer need to
|
|
74
|
+
* re-run PBKDF2 or hold the plaintext password in memory.
|
|
75
|
+
*/
|
|
76
|
+
export interface KeyBagWrappingKeyOptions {
|
|
77
|
+
/**
|
|
78
|
+
* The AES-GCM {@link CryptoKey} used to encrypt/decrypt the persisted KeyBag
|
|
79
|
+
* blob. Must have `usages` including `["encrypt", "decrypt"]`. Typically
|
|
80
|
+
* imported with `extractable: false` to avoid the raw bytes leaking into
|
|
81
|
+
* the JS heap.
|
|
82
|
+
*/
|
|
83
|
+
wrappingKey: CryptoKey;
|
|
84
|
+
/** Crypto adapter to use for encryption and decryption. */
|
|
85
|
+
cryptoAdapter: CryptoAdapter;
|
|
86
|
+
/** Optional logger instance. */
|
|
87
|
+
logger?: Logger;
|
|
88
|
+
}
|
|
11
89
|
/**
|
|
12
90
|
* The KeyBag is used to store encryption keys that the current user has access to
|
|
13
91
|
* in order to decrypt document changes stored in the AppendOnlyStore.
|
|
14
92
|
* Supports key rotation by storing multiple versions per keyId (newest first).
|
|
93
|
+
*
|
|
94
|
+
* Two construction modes are supported:
|
|
95
|
+
* - Legacy: pass `(userEncryptionKey, password, cryptoAdapter, ...)`. Each
|
|
96
|
+
* {@link save} / {@link load} call re-derives the AES-GCM wrapping key from
|
|
97
|
+
* `password` via PBKDF2. Required `password` is held by the instance for
|
|
98
|
+
* its lifetime.
|
|
99
|
+
* - Preferred: pass `({ wrappingKey, cryptoAdapter, ... })`. The caller has
|
|
100
|
+
* already derived the wrapping key (e.g. via {@link deriveWrappingKey})
|
|
101
|
+
* and the bag never sees the password. PBKDF2 runs zero times in this
|
|
102
|
+
* mode, and the bag is safe to persist/restore from storage repeatedly
|
|
103
|
+
* without password-handling overhead.
|
|
15
104
|
*/
|
|
16
105
|
export declare class KeyBag {
|
|
17
106
|
private userEncryptionKey;
|
|
18
107
|
private userEncryptionKeyPassword;
|
|
108
|
+
private wrappingKey;
|
|
19
109
|
private keys;
|
|
110
|
+
/**
|
|
111
|
+
* In-memory append-only log of doc-key mutations applied to this bag.
|
|
112
|
+
*
|
|
113
|
+
* Used by {@link iterateChangesSince} and {@link getLatestChangeCursor}
|
|
114
|
+
* so consumers (notably {@link BaseMindooTenant}) can reconcile state
|
|
115
|
+
* from a cursor even if they missed live listener notifications.
|
|
116
|
+
*
|
|
117
|
+
* Bound by the number of doc-key mutations per session, which in
|
|
118
|
+
* practice is small (one entry per add/remove/version change).
|
|
119
|
+
*/
|
|
120
|
+
private keyChanges;
|
|
121
|
+
private nextKeyChangeSeq;
|
|
122
|
+
private changeListeners;
|
|
20
123
|
private cryptoAdapter;
|
|
21
124
|
private logger;
|
|
22
125
|
/**
|
|
23
|
-
* Creates a
|
|
126
|
+
* Creates a KeyBag from a user encryption key + password (legacy form).
|
|
24
127
|
*
|
|
25
|
-
* @
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
128
|
+
* @deprecated Prefer the wrapping-key constructor overload. The password
|
|
129
|
+
* form holds the plaintext password for the lifetime of the bag and
|
|
130
|
+
* re-runs PBKDF2 on every {@link save}/{@link load} call.
|
|
131
|
+
*
|
|
132
|
+
* @param userEncryptionKey The encrypted user encryption key (provides
|
|
133
|
+
* the salt used for KeyBag wrapping-key derivation).
|
|
134
|
+
* @param userEncryptionKeyPassword The password to derive the KeyBag
|
|
135
|
+
* wrapping key.
|
|
136
|
+
* @param cryptoAdapter The crypto adapter to use for encryption and
|
|
137
|
+
* decryption.
|
|
138
|
+
* @param logger Optional logger instance.
|
|
29
139
|
*/
|
|
30
140
|
constructor(userEncryptionKey: EncryptedPrivateKey, userEncryptionKeyPassword: string, cryptoAdapter: CryptoAdapter, logger?: Logger);
|
|
141
|
+
/**
|
|
142
|
+
* Creates a KeyBag from a pre-derived AES-GCM wrapping {@link CryptoKey}.
|
|
143
|
+
*
|
|
144
|
+
* Recommended for production use: derive `wrappingKey` once at login via
|
|
145
|
+
* {@link KeyBag.deriveWrappingKey} and reuse it across {@link save}/{@link load}.
|
|
146
|
+
* No plaintext password is retained by the bag in this mode.
|
|
147
|
+
*/
|
|
148
|
+
constructor(options: KeyBagWrappingKeyOptions);
|
|
149
|
+
/**
|
|
150
|
+
* Derives the AES-GCM wrapping {@link CryptoKey} that {@link KeyBag.save}
|
|
151
|
+
* and {@link KeyBag.load} use to encrypt/decrypt the persisted bag blob.
|
|
152
|
+
*
|
|
153
|
+
* This runs PBKDF2 once with the same parameters the legacy constructor
|
|
154
|
+
* uses internally (combined salt = `userEncryptionKey.salt` +
|
|
155
|
+
* `"key-bag-encryption"`, iterations from
|
|
156
|
+
* {@link resolvePbkdf2Iterations}), so a key derived here is fully
|
|
157
|
+
* interchangeable with the password-derived key for both new and existing
|
|
158
|
+
* persisted bags.
|
|
159
|
+
*
|
|
160
|
+
* Callers that want to eliminate plaintext-password retention should
|
|
161
|
+
* derive the wrapping key once at login and pass it to the
|
|
162
|
+
* {@link KeyBagWrappingKeyOptions} constructor overload.
|
|
163
|
+
*
|
|
164
|
+
* @param userEncryptionKey The user's encrypted encryption key (provides
|
|
165
|
+
* the salt). Only `userEncryptionKey.salt` is read; the encrypted
|
|
166
|
+
* bytes are not touched.
|
|
167
|
+
* @param password The user's password.
|
|
168
|
+
* @param cryptoAdapter Crypto adapter to use for the derivation.
|
|
169
|
+
* @param options.extractable Whether the returned key should be
|
|
170
|
+
* extractable. Defaults to `false` so the raw bytes never appear in
|
|
171
|
+
* the JS heap.
|
|
172
|
+
*/
|
|
173
|
+
static deriveWrappingKey(userEncryptionKey: EncryptedPrivateKey, password: string, cryptoAdapter: CryptoAdapter, options?: {
|
|
174
|
+
extractable?: boolean;
|
|
175
|
+
}): Promise<CryptoKey>;
|
|
176
|
+
private static isWrappingKeyOptions;
|
|
177
|
+
private static staticBase64ToUint8Array;
|
|
178
|
+
/**
|
|
179
|
+
* Subscribe to live doc-key mutation events.
|
|
180
|
+
*
|
|
181
|
+
* Listeners receive a shallow copy of the same {@link KeyBagChangeEvent}
|
|
182
|
+
* record that gets appended to the internal feed, so reads via
|
|
183
|
+
* {@link iterateChangesSince} stay consistent with what listeners see.
|
|
184
|
+
* Listener exceptions are caught and logged so they cannot break the
|
|
185
|
+
* mutating call site.
|
|
186
|
+
*
|
|
187
|
+
* Live notifications are a convenience: callers that need to be robust
|
|
188
|
+
* against missed events should also persist a cursor and replay through
|
|
189
|
+
* {@link iterateChangesSince}.
|
|
190
|
+
*
|
|
191
|
+
* @returns A disposer that removes the listener.
|
|
192
|
+
*/
|
|
193
|
+
onChanges(listener: KeyBagChangeListener): () => void;
|
|
194
|
+
/**
|
|
195
|
+
* Snapshot the current head of the local changes feed.
|
|
196
|
+
*
|
|
197
|
+
* Returns `null` when no doc-key mutations have ever been observed by
|
|
198
|
+
* this bag instance. Useful as a starting cursor when a consumer wants
|
|
199
|
+
* to react only to *future* changes.
|
|
200
|
+
*/
|
|
201
|
+
getLatestChangeCursor(): KeyBagChangeCursor | null;
|
|
202
|
+
/**
|
|
203
|
+
* Iterate doc-key mutation events strictly after the given cursor.
|
|
204
|
+
*
|
|
205
|
+
* Pass `null` to consume all events since the bag was created. Yielded
|
|
206
|
+
* events are independent copies, so consumers may mutate them freely
|
|
207
|
+
* without affecting other listeners. Events are emitted in the order
|
|
208
|
+
* the underlying mutations occurred, which is also the order of their
|
|
209
|
+
* `changeSeq` values.
|
|
210
|
+
*/
|
|
211
|
+
iterateChangesSince(cursor: KeyBagChangeCursor | null): AsyncGenerator<KeyBagChangeEvent, void, unknown>;
|
|
212
|
+
/**
|
|
213
|
+
* Append a doc-key mutation event to the local feed and notify
|
|
214
|
+
* subscribed listeners.
|
|
215
|
+
*
|
|
216
|
+
* Called from every mutation site after the underlying `keys` map has
|
|
217
|
+
* been updated. Never includes raw key bytes in the recorded event so
|
|
218
|
+
* the feed is safe to expose to telemetry or external consumers.
|
|
219
|
+
*/
|
|
220
|
+
private recordKeyChange;
|
|
31
221
|
/**
|
|
32
222
|
* Reads a key from the key bag.
|
|
33
223
|
* Returns the newest key (based on createdAt) or the first key if no timestamps are available.
|
|
@@ -110,6 +300,29 @@ export declare class KeyBag {
|
|
|
110
300
|
* @return A promise that resolves to an array of key IDs
|
|
111
301
|
*/
|
|
112
302
|
listKeys(): Promise<string[]>;
|
|
303
|
+
/**
|
|
304
|
+
* Build a stable fingerprint of the doc-type keys available for a given
|
|
305
|
+
* tenant.
|
|
306
|
+
*
|
|
307
|
+
* The fingerprint changes whenever the *set* of scoped key ids the bag
|
|
308
|
+
* holds for `doc:tenantId:*` gains or loses an entry, but does not
|
|
309
|
+
* depend on key version counts or key material. It is used by
|
|
310
|
+
* {@link BaseMindooDB} to short-circuit visibility reconciliation on
|
|
311
|
+
* warm starts when the bag composition has not changed since the last
|
|
312
|
+
* cache flush, avoiding an otherwise unconditional full metadata scan
|
|
313
|
+
* against the underlying store (potentially several REST round-trips
|
|
314
|
+
* against a remote store).
|
|
315
|
+
*
|
|
316
|
+
* Implementation notes:
|
|
317
|
+
* - Scoped key ids are not secret (only key bytes are), so we use the
|
|
318
|
+
* sorted ids directly rather than hashing them. This keeps the
|
|
319
|
+
* fingerprint debuggable and avoids dragging crypto into a hot
|
|
320
|
+
* startup path.
|
|
321
|
+
* - The leading `v1:` tag is a format version so future iterations can
|
|
322
|
+
* extend the fingerprint without colliding with old persisted
|
|
323
|
+
* values.
|
|
324
|
+
*/
|
|
325
|
+
getDocKeyFingerprint(tenantId: string): Promise<string>;
|
|
113
326
|
/**
|
|
114
327
|
* Lists all stored key versions with metadata, newest first within each scoped key.
|
|
115
328
|
*/
|
|
@@ -117,21 +330,45 @@ export declare class KeyBag {
|
|
|
117
330
|
/**
|
|
118
331
|
* Creates an in-memory clone of this KeyBag.
|
|
119
332
|
* The clone contains deep-copied key material and independent key maps.
|
|
333
|
+
*
|
|
334
|
+
* The clone follows the same construction mode as this instance:
|
|
335
|
+
* - bags built with the wrapping-key constructor are cloned with the
|
|
336
|
+
* same {@link CryptoKey} reference (the underlying key handle is safe
|
|
337
|
+
* to share across instances - it is treated as immutable),
|
|
338
|
+
* - bags built with the legacy password constructor are cloned with the
|
|
339
|
+
* same encrypted user key + plaintext password.
|
|
120
340
|
*/
|
|
121
341
|
clone(): KeyBag;
|
|
122
342
|
/**
|
|
123
|
-
* Save the key bag to a binary data blob, encrypted with the
|
|
343
|
+
* Save the key bag to a binary data blob, encrypted with the wrapping key
|
|
344
|
+
* (either the {@link CryptoKey} provided to the constructor or one derived
|
|
345
|
+
* on demand from the legacy password).
|
|
124
346
|
*
|
|
125
347
|
* @return A promise that resolves to the encrypted binary data (Uint8Array)
|
|
126
348
|
*/
|
|
127
349
|
save(): Promise<Uint8Array>;
|
|
128
350
|
/**
|
|
129
|
-
* Load the key bag from a binary data blob, decrypted with the
|
|
351
|
+
* Load the key bag from a binary data blob, decrypted with the wrapping key
|
|
352
|
+
* (either the {@link CryptoKey} provided to the constructor or one derived
|
|
353
|
+
* on demand from the legacy password).
|
|
130
354
|
*
|
|
131
355
|
* @param encryptedData The encrypted binary data to load (Uint8Array)
|
|
132
356
|
* @return A promise that resolves when the keys are loaded
|
|
133
357
|
*/
|
|
134
358
|
load(encryptedData: Uint8Array): Promise<void>;
|
|
359
|
+
/**
|
|
360
|
+
* Returns the AES-GCM wrapping key used for {@link save}/{@link load}.
|
|
361
|
+
*
|
|
362
|
+
* - If this bag was constructed with a pre-derived `wrappingKey`, returns
|
|
363
|
+
* that key directly. The caller-supplied key already supports both
|
|
364
|
+
* `encrypt` and `decrypt`, so no per-usage derivation is needed.
|
|
365
|
+
* - Otherwise (legacy password constructor), derives a wrapping key from
|
|
366
|
+
* the stored password + user encryption salt via PBKDF2 with the
|
|
367
|
+
* requested usage. The derived key is intentionally not cached on the
|
|
368
|
+
* instance: the password constructor is the slow path and exists for
|
|
369
|
+
* backward compatibility only.
|
|
370
|
+
*/
|
|
371
|
+
private resolveWrappingKey;
|
|
135
372
|
/**
|
|
136
373
|
* Internal method to decrypt a private key using password-based key derivation.
|
|
137
374
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyBag.d.ts","sourceRoot":"","sources":["../../../src/core/keys/KeyBag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,KAAK,OAAO,EAA4C,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAoC,MAAM,YAAY,CAAC;AAUtE,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED
|
|
1
|
+
{"version":3,"file":"KeyBag.d.ts","sourceRoot":"","sources":["../../../src/core/keys/KeyBag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,KAAK,OAAO,EAA4C,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAoC,MAAM,YAAY,CAAC;AAUtE;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB;IAChC,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,IAAI,EAAE,OAAO,CAAC;IACd,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,gGAAgG;IAChG,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,MAAM,EAAE,kBAAkB,CAAC;IAC3B,qFAAqF;IACrF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,yD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