mindoodb 0.0.1

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.
Files changed (170) hide show
  1. package/README.md +263 -0
  2. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts +5 -0
  3. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts.map +1 -0
  4. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js +17 -0
  5. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js.map +1 -0
  6. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +111 -0
  7. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -0
  8. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +237 -0
  9. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -0
  10. package/dist/appendonlystores/network/HttpTransport.d.ts +78 -0
  11. package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -0
  12. package/dist/appendonlystores/network/HttpTransport.js +356 -0
  13. package/dist/appendonlystores/network/HttpTransport.js.map +1 -0
  14. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +131 -0
  15. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -0
  16. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +248 -0
  17. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -0
  18. package/dist/appendonlystores/network/index.d.ts +8 -0
  19. package/dist/appendonlystores/network/index.d.ts.map +1 -0
  20. package/dist/appendonlystores/network/index.js +21 -0
  21. package/dist/appendonlystores/network/index.js.map +1 -0
  22. package/dist/browser/crypto/BrowserCryptoAdapter.d.ts +14 -0
  23. package/dist/browser/crypto/BrowserCryptoAdapter.d.ts.map +1 -0
  24. package/dist/browser/crypto/BrowserCryptoAdapter.js +30 -0
  25. package/dist/browser/crypto/BrowserCryptoAdapter.js.map +1 -0
  26. package/dist/browser/index.d.ts +3 -0
  27. package/dist/browser/index.d.ts.map +1 -0
  28. package/dist/browser/index.js +26 -0
  29. package/dist/browser/index.js.map +1 -0
  30. package/dist/core/BaseMindooDB.d.ts +182 -0
  31. package/dist/core/BaseMindooDB.d.ts.map +1 -0
  32. package/dist/core/BaseMindooDB.js +1701 -0
  33. package/dist/core/BaseMindooDB.js.map +1 -0
  34. package/dist/core/BaseMindooTenant.d.ts +155 -0
  35. package/dist/core/BaseMindooTenant.d.ts.map +1 -0
  36. package/dist/core/BaseMindooTenant.js +673 -0
  37. package/dist/core/BaseMindooTenant.js.map +1 -0
  38. package/dist/core/BaseMindooTenantDirectory.d.ts +99 -0
  39. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -0
  40. package/dist/core/BaseMindooTenantDirectory.js +776 -0
  41. package/dist/core/BaseMindooTenantDirectory.js.map +1 -0
  42. package/dist/core/BaseMindooTenantFactory.d.ts +91 -0
  43. package/dist/core/BaseMindooTenantFactory.d.ts.map +1 -0
  44. package/dist/core/BaseMindooTenantFactory.js +297 -0
  45. package/dist/core/BaseMindooTenantFactory.js.map +1 -0
  46. package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts +111 -0
  47. package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts.map +1 -0
  48. package/dist/core/appendonlystores/InMemoryContentAddressedStore.js +293 -0
  49. package/dist/core/appendonlystores/InMemoryContentAddressedStore.js.map +1 -0
  50. package/dist/core/appendonlystores/network/AuthenticationService.d.ts +78 -0
  51. package/dist/core/appendonlystores/network/AuthenticationService.d.ts.map +1 -0
  52. package/dist/core/appendonlystores/network/AuthenticationService.js +297 -0
  53. package/dist/core/appendonlystores/network/AuthenticationService.js.map +1 -0
  54. package/dist/core/appendonlystores/network/NetworkTransport.d.ts +174 -0
  55. package/dist/core/appendonlystores/network/NetworkTransport.d.ts.map +1 -0
  56. package/dist/core/appendonlystores/network/NetworkTransport.js +3 -0
  57. package/dist/core/appendonlystores/network/NetworkTransport.js.map +1 -0
  58. package/dist/core/appendonlystores/network/types.d.ts +135 -0
  59. package/dist/core/appendonlystores/network/types.d.ts.map +1 -0
  60. package/dist/core/appendonlystores/network/types.js +35 -0
  61. package/dist/core/appendonlystores/network/types.js.map +1 -0
  62. package/dist/core/appendonlystores/types.d.ts +157 -0
  63. package/dist/core/appendonlystores/types.d.ts.map +1 -0
  64. package/dist/core/appendonlystores/types.js +3 -0
  65. package/dist/core/appendonlystores/types.js.map +1 -0
  66. package/dist/core/crypto/CryptoAdapter.d.ts +19 -0
  67. package/dist/core/crypto/CryptoAdapter.d.ts.map +1 -0
  68. package/dist/core/crypto/CryptoAdapter.js +3 -0
  69. package/dist/core/crypto/CryptoAdapter.js.map +1 -0
  70. package/dist/core/crypto/MindooDocSigner.d.ts +106 -0
  71. package/dist/core/crypto/MindooDocSigner.d.ts.map +1 -0
  72. package/dist/core/crypto/MindooDocSigner.js +192 -0
  73. package/dist/core/crypto/MindooDocSigner.js.map +1 -0
  74. package/dist/core/crypto/RSAEncryption.d.ts +62 -0
  75. package/dist/core/crypto/RSAEncryption.d.ts.map +1 -0
  76. package/dist/core/crypto/RSAEncryption.js +167 -0
  77. package/dist/core/crypto/RSAEncryption.js.map +1 -0
  78. package/dist/core/errors.d.ts +10 -0
  79. package/dist/core/errors.d.ts.map +1 -0
  80. package/dist/core/errors.js +17 -0
  81. package/dist/core/errors.js.map +1 -0
  82. package/dist/core/index.d.ts +14 -0
  83. package/dist/core/index.d.ts.map +1 -0
  84. package/dist/core/index.js +53 -0
  85. package/dist/core/index.js.map +1 -0
  86. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts +33 -0
  87. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts.map +1 -0
  88. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js +27 -0
  89. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js.map +1 -0
  90. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.d.ts +31 -0
  91. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.d.ts.map +1 -0
  92. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.js +3 -0
  93. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.js.map +1 -0
  94. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts +52 -0
  95. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts.map +1 -0
  96. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js +106 -0
  97. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js.map +1 -0
  98. package/dist/core/indexing/virtualviews/ViewEntrySortKey.d.ts +44 -0
  99. package/dist/core/indexing/virtualviews/ViewEntrySortKey.d.ts.map +1 -0
  100. package/dist/core/indexing/virtualviews/ViewEntrySortKey.js +107 -0
  101. package/dist/core/indexing/virtualviews/ViewEntrySortKey.js.map +1 -0
  102. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts +28 -0
  103. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts.map +1 -0
  104. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js +133 -0
  105. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js.map +1 -0
  106. package/dist/core/indexing/virtualviews/VirtualView.d.ts +109 -0
  107. package/dist/core/indexing/virtualviews/VirtualView.d.ts.map +1 -0
  108. package/dist/core/indexing/virtualviews/VirtualView.js +504 -0
  109. package/dist/core/indexing/virtualviews/VirtualView.js.map +1 -0
  110. package/dist/core/indexing/virtualviews/VirtualViewColumn.d.ts +59 -0
  111. package/dist/core/indexing/virtualviews/VirtualViewColumn.d.ts.map +1 -0
  112. package/dist/core/indexing/virtualviews/VirtualViewColumn.js +70 -0
  113. package/dist/core/indexing/virtualviews/VirtualViewColumn.js.map +1 -0
  114. package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts +49 -0
  115. package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts.map +1 -0
  116. package/dist/core/indexing/virtualviews/VirtualViewDataChange.js +69 -0
  117. package/dist/core/indexing/virtualviews/VirtualViewDataChange.js.map +1 -0
  118. package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts +121 -0
  119. package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts.map +1 -0
  120. package/dist/core/indexing/virtualviews/VirtualViewEntryData.js +365 -0
  121. package/dist/core/indexing/virtualviews/VirtualViewEntryData.js.map +1 -0
  122. package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts +131 -0
  123. package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts.map +1 -0
  124. package/dist/core/indexing/virtualviews/VirtualViewFactory.js +236 -0
  125. package/dist/core/indexing/virtualviews/VirtualViewFactory.js.map +1 -0
  126. package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts +330 -0
  127. package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts.map +1 -0
  128. package/dist/core/indexing/virtualviews/VirtualViewNavigator.js +1010 -0
  129. package/dist/core/indexing/virtualviews/VirtualViewNavigator.js.map +1 -0
  130. package/dist/core/indexing/virtualviews/index.d.ts +53 -0
  131. package/dist/core/indexing/virtualviews/index.d.ts.map +1 -0
  132. package/dist/core/indexing/virtualviews/index.js +89 -0
  133. package/dist/core/indexing/virtualviews/index.js.map +1 -0
  134. package/dist/core/indexing/virtualviews/types.d.ts +115 -0
  135. package/dist/core/indexing/virtualviews/types.d.ts.map +1 -0
  136. package/dist/core/indexing/virtualviews/types.js +175 -0
  137. package/dist/core/indexing/virtualviews/types.js.map +1 -0
  138. package/dist/core/keys/KeyBag.d.ts +122 -0
  139. package/dist/core/keys/KeyBag.d.ts.map +1 -0
  140. package/dist/core/keys/KeyBag.js +401 -0
  141. package/dist/core/keys/KeyBag.js.map +1 -0
  142. package/dist/core/types.d.ts +1004 -0
  143. package/dist/core/types.d.ts.map +1 -0
  144. package/dist/core/types.js +10 -0
  145. package/dist/core/types.js.map +1 -0
  146. package/dist/core/userid/index.d.ts +53 -0
  147. package/dist/core/userid/index.d.ts.map +1 -0
  148. package/dist/core/userid/index.js +3 -0
  149. package/dist/core/userid/index.js.map +1 -0
  150. package/dist/core/utils/idGeneration.d.ts +109 -0
  151. package/dist/core/utils/idGeneration.d.ts.map +1 -0
  152. package/dist/core/utils/idGeneration.js +182 -0
  153. package/dist/core/utils/idGeneration.js.map +1 -0
  154. package/dist/core/utils/index.d.ts +5 -0
  155. package/dist/core/utils/index.d.ts.map +1 -0
  156. package/dist/core/utils/index.js +19 -0
  157. package/dist/core/utils/index.js.map +1 -0
  158. package/dist/index.d.ts +7 -0
  159. package/dist/index.d.ts.map +1 -0
  160. package/dist/index.js +40 -0
  161. package/dist/index.js.map +1 -0
  162. package/dist/node/crypto/NodeCryptoAdapter.d.ts +16 -0
  163. package/dist/node/crypto/NodeCryptoAdapter.d.ts.map +1 -0
  164. package/dist/node/crypto/NodeCryptoAdapter.js +53 -0
  165. package/dist/node/crypto/NodeCryptoAdapter.js.map +1 -0
  166. package/dist/node/index.d.ts +3 -0
  167. package/dist/node/index.d.ts.map +1 -0
  168. package/dist/node/index.js +26 -0
  169. package/dist/node/index.js.map +1 -0
  170. package/package.json +58 -0
@@ -0,0 +1,401 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyBag = void 0;
4
+ /**
5
+ * The KeyBag is used to store encryption keys that the current user has access to
6
+ * in order to decrypt document changes stored in the AppendOnlyStore.
7
+ * Supports key rotation by storing multiple versions per keyId (newest first).
8
+ */
9
+ class KeyBag {
10
+ /**
11
+ * Creates a new KeyBag instance.
12
+ *
13
+ * @param userEncryptionKey The encrypted user encryption key
14
+ * @param userEncryptionKeyPassword The password to decrypt the user encryption key
15
+ * @param cryptoAdapter The crypto adapter to use for encryption and decryption
16
+ */
17
+ constructor(userEncryptionKey, userEncryptionKeyPassword, cryptoAdapter) {
18
+ this.keys = new Map();
19
+ this.userEncryptionKey = userEncryptionKey;
20
+ this.userEncryptionKeyPassword = userEncryptionKeyPassword;
21
+ this.cryptoAdapter = cryptoAdapter;
22
+ }
23
+ /**
24
+ * Reads a key from the key bag.
25
+ * Returns the newest key (based on createdAt) or the first key if no timestamps are available.
26
+ *
27
+ * @param keyId The ID of the key to read
28
+ * @return The exported key, or null if not found
29
+ */
30
+ async get(keyId) {
31
+ const keyEntries = this.keys.get(keyId);
32
+ if (!keyEntries || keyEntries.length === 0) {
33
+ return null;
34
+ }
35
+ // Sort by createdAt (newest first), then return the first one
36
+ const sorted = [...keyEntries].sort((a, b) => {
37
+ const aTime = a.createdAt ?? 0;
38
+ const bTime = b.createdAt ?? 0;
39
+ return bTime - aTime; // Descending order (newest first)
40
+ });
41
+ return sorted[0].key;
42
+ }
43
+ /**
44
+ * Gets all keys for a given keyId, sorted by createdAt (newest first).
45
+ * Useful for trying multiple keys during decryption (key rotation support).
46
+ *
47
+ * @param keyId The ID of the keys to read
48
+ * @return Array of keys sorted by createdAt (newest first), or empty array if not found
49
+ */
50
+ async getAllKeys(keyId) {
51
+ const keyEntries = this.keys.get(keyId);
52
+ if (!keyEntries || keyEntries.length === 0) {
53
+ return [];
54
+ }
55
+ // Sort by createdAt (newest first)
56
+ const sorted = [...keyEntries].sort((a, b) => {
57
+ const aTime = a.createdAt ?? 0;
58
+ const bTime = b.createdAt ?? 0;
59
+ return bTime - aTime; // Descending order (newest first)
60
+ });
61
+ return sorted.map(entry => entry.key);
62
+ }
63
+ /**
64
+ * Sets a key in the key bag.
65
+ * Adds the key to the array of keys for this keyId (supports key rotation).
66
+ *
67
+ * @param keyId The ID of the key
68
+ * @param key The key bytes
69
+ * @param createdAt Optional creation timestamp (milliseconds since Unix epoch)
70
+ */
71
+ async set(keyId, key, createdAt) {
72
+ const keyEntries = this.keys.get(keyId) || [];
73
+ keyEntries.push({ key, createdAt });
74
+ this.keys.set(keyId, keyEntries);
75
+ }
76
+ /**
77
+ * Decrypts an encrypted private key with the given password and imports it into the key bag.
78
+ * Adds the key to the array of keys for this keyId (supports key rotation).
79
+ *
80
+ * @param keyId The ID to store the decrypted key under
81
+ * @param key The encrypted private key to decrypt
82
+ * @param password The password to decrypt the key
83
+ * @param saltString Optional salt string for key derivation. Defaults to "default".
84
+ * Use "default" for keys created by createSymmetricEncryptedPrivateKey.
85
+ * Keys exported via encryptAndExportKey use keyId as salt, so pass keyId explicitly.
86
+ * @return A promise that resolves when the key is decrypted and stored
87
+ */
88
+ async decryptAndImportKey(keyId, key, password, saltString) {
89
+ const salt = saltString ?? "default";
90
+ const decryptedKeyBytes = await this.decryptPrivateKey(key, password, salt);
91
+ const keyEntries = this.keys.get(keyId) || [];
92
+ keyEntries.push({
93
+ key: new Uint8Array(decryptedKeyBytes),
94
+ createdAt: key.createdAt
95
+ });
96
+ this.keys.set(keyId, keyEntries);
97
+ }
98
+ /**
99
+ * Encrypts a key from the key bag with the given password and exports it as an EncryptedPrivateKey.
100
+ * Returns the newest key (based on createdAt) or the first key if no timestamps are available.
101
+ *
102
+ * @param keyId The ID of the key to encrypt and export
103
+ * @param password The password to encrypt the key with
104
+ * @return A promise that resolves to the encrypted private key, or null if the key is not found
105
+ */
106
+ async encryptAndExportKey(keyId, password) {
107
+ const key = await this.get(keyId);
108
+ if (!key) {
109
+ return null;
110
+ }
111
+ // Get the createdAt timestamp from the newest key entry
112
+ const keyEntries = this.keys.get(keyId);
113
+ if (!keyEntries || keyEntries.length === 0) {
114
+ return null;
115
+ }
116
+ // Sort by createdAt (newest first) to get the timestamp
117
+ const sorted = [...keyEntries].sort((a, b) => {
118
+ const aTime = a.createdAt ?? 0;
119
+ const bTime = b.createdAt ?? 0;
120
+ return bTime - aTime; // Descending order (newest first)
121
+ });
122
+ const createdAt = sorted[0].createdAt;
123
+ // Encrypt the key using the same pattern as decryptPrivateKey
124
+ const encryptedKey = await this.encryptPrivateKey(key, password, keyId);
125
+ // Include the createdAt timestamp if available
126
+ if (createdAt !== undefined) {
127
+ encryptedKey.createdAt = createdAt;
128
+ }
129
+ return encryptedKey;
130
+ }
131
+ /**
132
+ * Deletes all keys for a given keyId from the key bag.
133
+ *
134
+ * @param keyId The ID of the keys to delete
135
+ * @return A promise that resolves when the keys are deleted
136
+ */
137
+ async deleteKey(keyId) {
138
+ this.keys.delete(keyId);
139
+ }
140
+ /**
141
+ * Lists all key IDs in the key bag.
142
+ *
143
+ * @return A promise that resolves to an array of key IDs
144
+ */
145
+ async listKeys() {
146
+ return Array.from(this.keys.keys());
147
+ }
148
+ /**
149
+ * Save the key bag to a binary data blob, encrypted with the user encryption key.
150
+ *
151
+ * @return A promise that resolves to the encrypted binary data (Uint8Array)
152
+ */
153
+ async save() {
154
+ console.log(`[KeyBag] Saving key bag with ${this.keys.size} keys`);
155
+ // Serialize the map to JSON and convert to Uint8Array
156
+ // Convert Uint8Array values to base64 strings for JSON serialization
157
+ // Support multiple keys per keyId with createdAt timestamps
158
+ const mapArray = Array.from(this.keys.entries()).map(([keyId, keyEntries]) => [
159
+ keyId,
160
+ keyEntries.map(entry => ({
161
+ key: this.uint8ArrayToBase64(entry.key),
162
+ createdAt: entry.createdAt
163
+ }))
164
+ ]);
165
+ const jsonString = JSON.stringify(mapArray);
166
+ const plaintext = new TextEncoder().encode(jsonString);
167
+ const subtle = this.cryptoAdapter.getSubtle();
168
+ // Bind getRandomValues to maintain 'this' context
169
+ const randomValues = this.cryptoAdapter.getRandomValues.bind(this.cryptoAdapter);
170
+ // Derive an AES-GCM key using PBKDF2 with the user encryption key's salt
171
+ // Use the salt from the user encryption key as part of the key derivation
172
+ const userKeySaltBytes = this.base64ToUint8Array(this.userEncryptionKey.salt);
173
+ // Combine with a fixed string to differentiate from other key derivations
174
+ const saltStringBytes = new TextEncoder().encode("key-bag-encryption");
175
+ const combinedSalt = new Uint8Array(userKeySaltBytes.length + saltStringBytes.length);
176
+ combinedSalt.set(userKeySaltBytes);
177
+ combinedSalt.set(saltStringBytes, userKeySaltBytes.length);
178
+ // Use the user's password as input for PBKDF2
179
+ const passwordInput = new TextEncoder().encode(`${this.userEncryptionKeyPassword}:key-bag-encryption`);
180
+ const passwordKey = await subtle.importKey("raw", passwordInput, "PBKDF2", false, ["deriveKey"]);
181
+ // Derive AES-GCM key using PBKDF2
182
+ const derivedKey = await subtle.deriveKey({
183
+ name: "PBKDF2",
184
+ salt: combinedSalt,
185
+ iterations: 310000, // OWASP-recommended PBKDF2 iterations for PBKDF2-SHA256
186
+ hash: "SHA-256",
187
+ }, passwordKey, {
188
+ name: "AES-GCM",
189
+ length: 256,
190
+ }, false, ["encrypt"]);
191
+ // Generate IV for AES-GCM
192
+ const ivArray = new Uint8Array(12); // 12 bytes for AES-GCM
193
+ randomValues(ivArray);
194
+ const iv = new Uint8Array(ivArray);
195
+ // Encrypt the plaintext
196
+ const encrypted = await subtle.encrypt({
197
+ name: "AES-GCM",
198
+ iv: iv,
199
+ tagLength: 128,
200
+ }, derivedKey, plaintext.buffer);
201
+ // Extract ciphertext and tag
202
+ const encryptedArray = new Uint8Array(encrypted);
203
+ const tagLength = 16; // 128 bits = 16 bytes
204
+ const ciphertext = encryptedArray.slice(0, encryptedArray.length - tagLength);
205
+ const tag = encryptedArray.slice(encryptedArray.length - tagLength);
206
+ // Combine IV + tag + ciphertext
207
+ // Format: IV (12 bytes) + tag (16 bytes) + ciphertext (variable)
208
+ const result = new Uint8Array(12 + 16 + ciphertext.length);
209
+ result.set(iv, 0);
210
+ result.set(tag, 12);
211
+ result.set(ciphertext, 12 + 16);
212
+ console.log(`[KeyBag] Saved key bag (${plaintext.length} -> ${result.length} bytes)`);
213
+ return result;
214
+ }
215
+ /**
216
+ * Load the key bag from a binary data blob, decrypted with the user encryption key.
217
+ *
218
+ * @param encryptedData The encrypted binary data to load (Uint8Array)
219
+ * @return A promise that resolves when the keys are loaded
220
+ */
221
+ async load(encryptedData) {
222
+ console.log(`[KeyBag] Loading key bag`);
223
+ if (encryptedData.length < 28) {
224
+ throw new Error("Encrypted data too short (missing IV and tag)");
225
+ }
226
+ // Extract IV, tag, and ciphertext
227
+ const iv = encryptedData.slice(0, 12);
228
+ const tag = encryptedData.slice(12, 28);
229
+ const ciphertext = encryptedData.slice(28);
230
+ const subtle = this.cryptoAdapter.getSubtle();
231
+ // Derive the same AES-GCM key (same process as encryption)
232
+ const userKeySaltBytes = this.base64ToUint8Array(this.userEncryptionKey.salt);
233
+ // Combine with the same fixed string as encryption
234
+ const saltStringBytes = new TextEncoder().encode("key-bag-encryption");
235
+ const combinedSalt = new Uint8Array(userKeySaltBytes.length + saltStringBytes.length);
236
+ combinedSalt.set(userKeySaltBytes);
237
+ combinedSalt.set(saltStringBytes, userKeySaltBytes.length);
238
+ // Use the user's password as input for PBKDF2 (same as encryption)
239
+ const passwordInput = new TextEncoder().encode(`${this.userEncryptionKeyPassword}:key-bag-encryption`);
240
+ const passwordKey = await subtle.importKey("raw", passwordInput, "PBKDF2", false, ["deriveKey"]);
241
+ // Derive AES-GCM key using PBKDF2 (same parameters as encryption)
242
+ const derivedKey = await subtle.deriveKey({
243
+ name: "PBKDF2",
244
+ salt: combinedSalt,
245
+ iterations: 310000, // OWASP-recommended PBKDF2 iterations for PBKDF2-SHA256
246
+ hash: "SHA-256",
247
+ }, passwordKey, {
248
+ name: "AES-GCM",
249
+ length: 256,
250
+ }, false, ["decrypt"]);
251
+ // Combine ciphertext and tag
252
+ const encryptedDataWithTag = new Uint8Array(ciphertext.length + tag.length);
253
+ encryptedDataWithTag.set(ciphertext);
254
+ encryptedDataWithTag.set(tag, ciphertext.length);
255
+ // Decrypt
256
+ const decrypted = await subtle.decrypt({
257
+ name: "AES-GCM",
258
+ iv: iv,
259
+ tagLength: 128,
260
+ }, derivedKey, encryptedDataWithTag.buffer);
261
+ // Deserialize JSON to map
262
+ const decryptedArray = new Uint8Array(decrypted);
263
+ const jsonString = new TextDecoder().decode(decryptedArray);
264
+ const mapArray = JSON.parse(jsonString);
265
+ // Convert base64 strings back to Uint8Array arrays
266
+ // Support multiple keys per keyId with createdAt timestamps
267
+ this.keys = new Map(mapArray.map(([keyId, keyEntries]) => [
268
+ keyId,
269
+ keyEntries.map(entry => ({
270
+ key: this.base64ToUint8Array(entry.key),
271
+ createdAt: entry.createdAt
272
+ }))
273
+ ]));
274
+ console.log(`[KeyBag] Loaded key bag (${encryptedData.length} -> ${this.keys.size} keys)`);
275
+ }
276
+ /**
277
+ * Internal method to decrypt a private key using password-based key derivation.
278
+ *
279
+ * @param encryptedKey The encrypted private key
280
+ * @param password The password to decrypt the key
281
+ * @param saltString The salt string for key derivation (e.g., keyId)
282
+ * @returns The decrypted private key as ArrayBuffer
283
+ */
284
+ async decryptPrivateKey(encryptedKey, password, saltString) {
285
+ const subtle = this.cryptoAdapter.getSubtle();
286
+ // Decode base64 strings
287
+ const ciphertext = this.base64ToUint8Array(encryptedKey.ciphertext);
288
+ const iv = this.base64ToUint8Array(encryptedKey.iv);
289
+ const tag = this.base64ToUint8Array(encryptedKey.tag);
290
+ const saltBytes = this.base64ToUint8Array(encryptedKey.salt);
291
+ // Derive key from password using PBKDF2
292
+ // Combine the stored salt bytes with the salt string for additional security
293
+ const saltStringBytes = new TextEncoder().encode(saltString);
294
+ const combinedSalt = new Uint8Array(saltBytes.length + saltStringBytes.length);
295
+ combinedSalt.set(saltBytes);
296
+ combinedSalt.set(saltStringBytes, saltBytes.length);
297
+ const passwordKey = await subtle.importKey("raw", new TextEncoder().encode(password), "PBKDF2", false, ["deriveBits", "deriveKey"]);
298
+ const derivedKey = await subtle.deriveKey({
299
+ name: "PBKDF2",
300
+ salt: combinedSalt,
301
+ iterations: encryptedKey.iterations,
302
+ hash: "SHA-256",
303
+ }, passwordKey, {
304
+ name: "AES-GCM",
305
+ length: 256,
306
+ }, false, ["decrypt"]);
307
+ // Combine ciphertext and tag (GCM authentication tag is separate)
308
+ const encryptedData = new Uint8Array(ciphertext.length + tag.length);
309
+ encryptedData.set(ciphertext);
310
+ encryptedData.set(tag, ciphertext.length);
311
+ // Decrypt the private key
312
+ const decrypted = await subtle.decrypt({
313
+ name: "AES-GCM",
314
+ iv: iv,
315
+ tagLength: 128,
316
+ }, derivedKey, encryptedData.buffer);
317
+ return decrypted;
318
+ }
319
+ /**
320
+ * Internal method to encrypt a private key using password-based key derivation.
321
+ * This is the reverse of decryptPrivateKey().
322
+ *
323
+ * @param privateKeyBytes The private key bytes to encrypt
324
+ * @param password The password to encrypt the key with
325
+ * @param saltString The salt string for key derivation (e.g., keyId)
326
+ * @returns The encrypted private key
327
+ */
328
+ async encryptPrivateKey(privateKeyBytes, password, saltString) {
329
+ const subtle = this.cryptoAdapter.getSubtle();
330
+ // Bind getRandomValues to maintain 'this' context
331
+ const randomValues = this.cryptoAdapter.getRandomValues.bind(this.cryptoAdapter);
332
+ // Generate random salt and IV
333
+ const saltArray = new Uint8Array(16); // 16 bytes salt
334
+ randomValues(saltArray);
335
+ const salt = new Uint8Array(saltArray);
336
+ const ivArray = new Uint8Array(12); // 12 bytes for AES-GCM
337
+ randomValues(ivArray);
338
+ const iv = new Uint8Array(ivArray);
339
+ // Combine salt with saltString for key derivation (same as decryption)
340
+ const saltStringBytes = new TextEncoder().encode(saltString);
341
+ const combinedSalt = new Uint8Array(salt.length + saltStringBytes.length);
342
+ combinedSalt.set(salt);
343
+ combinedSalt.set(saltStringBytes, salt.length);
344
+ // Derive encryption key from password using PBKDF2
345
+ const passwordKey = await subtle.importKey("raw", new TextEncoder().encode(password), "PBKDF2", false, ["deriveBits", "deriveKey"]);
346
+ const iterations = 310000; // OWASP-recommended PBKDF2 iterations for PBKDF2-SHA256
347
+ const derivedKey = await subtle.deriveKey({
348
+ name: "PBKDF2",
349
+ salt: combinedSalt,
350
+ iterations: iterations,
351
+ hash: "SHA-256",
352
+ }, passwordKey, {
353
+ name: "AES-GCM",
354
+ length: 256,
355
+ }, false, ["encrypt"]);
356
+ // Encrypt the private key
357
+ const encrypted = await subtle.encrypt({
358
+ name: "AES-GCM",
359
+ iv: iv,
360
+ tagLength: 128,
361
+ }, derivedKey, privateKeyBytes.buffer);
362
+ // Extract ciphertext and tag from encrypted data
363
+ // AES-GCM appends the tag at the end
364
+ const encryptedArray = new Uint8Array(encrypted);
365
+ const tagLength = 16; // 128 bits = 16 bytes
366
+ const ciphertext = encryptedArray.slice(0, encryptedArray.length - tagLength);
367
+ const tag = encryptedArray.slice(encryptedArray.length - tagLength);
368
+ // Create encrypted key structure
369
+ const encryptedKey = {
370
+ ciphertext: this.uint8ArrayToBase64(ciphertext),
371
+ iv: this.uint8ArrayToBase64(iv),
372
+ tag: this.uint8ArrayToBase64(tag),
373
+ salt: this.uint8ArrayToBase64(salt),
374
+ iterations: iterations,
375
+ };
376
+ return encryptedKey;
377
+ }
378
+ /**
379
+ * Helper method to convert base64 string to Uint8Array
380
+ */
381
+ base64ToUint8Array(base64) {
382
+ const binary = atob(base64);
383
+ const bytes = new Uint8Array(binary.length);
384
+ for (let i = 0; i < binary.length; i++) {
385
+ bytes[i] = binary.charCodeAt(i);
386
+ }
387
+ return bytes;
388
+ }
389
+ /**
390
+ * Helper method to convert Uint8Array to base64 string
391
+ */
392
+ uint8ArrayToBase64(bytes) {
393
+ let binary = "";
394
+ for (let i = 0; i < bytes.length; i++) {
395
+ binary += String.fromCharCode(bytes[i]);
396
+ }
397
+ return btoa(binary);
398
+ }
399
+ }
400
+ exports.KeyBag = KeyBag;
401
+ //# sourceMappingURL=KeyBag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyBag.js","sourceRoot":"","sources":["../../../src/core/keys/KeyBag.ts"],"names":[],"mappings":";;;AAWA;;;;GAIG;AACH,MAAa,MAAM;IAMjB;;;;;;OAMG;IACH,YAAY,iBAAsC,EAAE,yBAAiC,EAAE,aAA4B;QAV3G,SAAI,GAA4B,IAAI,GAAG,EAAE,CAAC;QAWhD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,yBAAyB,GAAG,yBAAyB,CAAC;QAC3D,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED;;;;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