@omnituum/pqc-shared 0.2.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.
Files changed (67) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +543 -0
  3. package/dist/crypto/index.cjs +807 -0
  4. package/dist/crypto/index.d.cts +641 -0
  5. package/dist/crypto/index.d.ts +641 -0
  6. package/dist/crypto/index.js +716 -0
  7. package/dist/decrypt-eSHlbh1j.d.cts +321 -0
  8. package/dist/decrypt-eSHlbh1j.d.ts +321 -0
  9. package/dist/fs/index.cjs +1168 -0
  10. package/dist/fs/index.d.cts +400 -0
  11. package/dist/fs/index.d.ts +400 -0
  12. package/dist/fs/index.js +1091 -0
  13. package/dist/index.cjs +2160 -0
  14. package/dist/index.d.cts +282 -0
  15. package/dist/index.d.ts +282 -0
  16. package/dist/index.js +2031 -0
  17. package/dist/integrity-CCYjrap3.d.ts +31 -0
  18. package/dist/integrity-Dx9jukMH.d.cts +31 -0
  19. package/dist/types-61c7Q9ri.d.ts +134 -0
  20. package/dist/types-Ch0y-n7K.d.cts +134 -0
  21. package/dist/utils/index.cjs +129 -0
  22. package/dist/utils/index.d.cts +49 -0
  23. package/dist/utils/index.d.ts +49 -0
  24. package/dist/utils/index.js +114 -0
  25. package/dist/vault/index.cjs +713 -0
  26. package/dist/vault/index.d.cts +237 -0
  27. package/dist/vault/index.d.ts +237 -0
  28. package/dist/vault/index.js +677 -0
  29. package/dist/version-BygzPVGs.d.cts +55 -0
  30. package/dist/version-BygzPVGs.d.ts +55 -0
  31. package/package.json +86 -0
  32. package/src/crypto/dilithium.ts +233 -0
  33. package/src/crypto/hybrid.ts +358 -0
  34. package/src/crypto/index.ts +181 -0
  35. package/src/crypto/kyber.ts +199 -0
  36. package/src/crypto/nacl.ts +204 -0
  37. package/src/crypto/primitives/blake3.ts +141 -0
  38. package/src/crypto/primitives/chacha.ts +211 -0
  39. package/src/crypto/primitives/hkdf.ts +192 -0
  40. package/src/crypto/primitives/index.ts +54 -0
  41. package/src/crypto/primitives.ts +144 -0
  42. package/src/crypto/x25519.ts +134 -0
  43. package/src/fs/aes.ts +343 -0
  44. package/src/fs/argon2.ts +184 -0
  45. package/src/fs/browser.ts +408 -0
  46. package/src/fs/decrypt.ts +320 -0
  47. package/src/fs/encrypt.ts +324 -0
  48. package/src/fs/format.ts +425 -0
  49. package/src/fs/index.ts +144 -0
  50. package/src/fs/types.ts +304 -0
  51. package/src/index.ts +414 -0
  52. package/src/kdf/index.ts +311 -0
  53. package/src/runtime/crypto.ts +16 -0
  54. package/src/security/index.ts +345 -0
  55. package/src/tunnel/index.ts +39 -0
  56. package/src/tunnel/session.ts +229 -0
  57. package/src/tunnel/types.ts +115 -0
  58. package/src/utils/entropy.ts +128 -0
  59. package/src/utils/index.ts +25 -0
  60. package/src/utils/integrity.ts +95 -0
  61. package/src/vault/decrypt.ts +167 -0
  62. package/src/vault/encrypt.ts +207 -0
  63. package/src/vault/index.ts +71 -0
  64. package/src/vault/manager.ts +327 -0
  65. package/src/vault/migrate.ts +190 -0
  66. package/src/vault/types.ts +177 -0
  67. package/src/version.ts +304 -0
@@ -0,0 +1,400 @@
1
+ import { A as Argon2idParams, f as OQEHeader, H as HybridKeyMaterial, P as PasswordKeyMaterial, g as OQEMetadata, h as AlgorithmSuiteId, O as OQEEncryptResult, c as OQEDecryptResult } from '../decrypt-eSHlbh1j.js';
2
+ export { w as ALGORITHM_SUITES, i as DEFAULT_ARGON2ID_PARAMS, D as DecryptOptions, E as EncryptOptions, F as FileInput, p as HybridDecryptOptions, n as HybridEncryptOptions, M as MIN_ARGON2ID_PARAMS, t as OQEError, r as OQEErrorCode, m as OQEMode, v as OQE_FORMAT_VERSION, x as OQE_HEADER_SIZE, u as OQE_MAGIC, q as PasswordDecryptOptions, o as PasswordEncryptOptions, s as ProgressCallback, d as decryptFile, k as decryptFileForSelf, b as decryptFileWithPassword, e as encryptFile, j as encryptFileForSelf, a as encryptFileWithPassword, l as inspectOQEFile, y as toUint8Array } from '../decrypt-eSHlbh1j.js';
3
+
4
+ /**
5
+ * Omnituum FS - Argon2id Key Derivation
6
+ *
7
+ * Memory-hard password hashing using Argon2id (winner of PHC).
8
+ * Uses hash-wasm for browser-compatible WASM implementation.
9
+ *
10
+ * Security: OWASP 2024 recommended parameters.
11
+ */
12
+
13
+ /**
14
+ * Derive an encryption key from a password using Argon2id.
15
+ *
16
+ * @param password - User password
17
+ * @param salt - 32-byte random salt (generate with generateArgon2Salt())
18
+ * @param params - Argon2id parameters (uses OWASP defaults if not specified)
19
+ * @returns 32-byte derived key suitable for AES-256
20
+ */
21
+ declare function deriveKeyFromPassword(password: string, salt: Uint8Array, params?: Argon2idParams): Promise<Uint8Array>;
22
+ /**
23
+ * Generate a random salt for Argon2id.
24
+ *
25
+ * @param length - Salt length in bytes (default: 32)
26
+ * @returns Random salt
27
+ */
28
+ declare function generateArgon2Salt(length?: number): Uint8Array;
29
+ /**
30
+ * Verify a password against a stored hash.
31
+ * Useful for vault unlocking or file password verification.
32
+ *
33
+ * @param password - Password to verify
34
+ * @param salt - Original salt used
35
+ * @param expectedKey - Expected derived key
36
+ * @param params - Argon2id parameters
37
+ * @returns true if password is correct
38
+ */
39
+ declare function verifyPassword(password: string, salt: Uint8Array, expectedKey: Uint8Array, params?: Argon2idParams): Promise<boolean>;
40
+ /**
41
+ * Estimate Argon2id parameters based on available memory and target time.
42
+ * Useful for adapting to low-memory environments.
43
+ *
44
+ * @param targetTimeMs - Target key derivation time in milliseconds
45
+ * @param availableMemoryMB - Available memory in megabytes
46
+ * @returns Estimated Argon2id parameters
47
+ */
48
+ declare function estimateArgon2Params(targetTimeMs?: number, availableMemoryMB?: number): Argon2idParams;
49
+ /**
50
+ * Benchmark Argon2id on current device.
51
+ * Returns the time in milliseconds for one derivation.
52
+ *
53
+ * @param params - Parameters to benchmark
54
+ * @returns Time in milliseconds
55
+ */
56
+ declare function benchmarkArgon2(params?: Argon2idParams): Promise<number>;
57
+ /**
58
+ * Check if Argon2id is available in current environment.
59
+ * Caches result after first check.
60
+ */
61
+ declare function isArgon2Available(): Promise<boolean>;
62
+
63
+ /**
64
+ * Omnituum FS - AES-256-GCM Encryption
65
+ *
66
+ * File encryption using AES-256-GCM via Web Crypto API.
67
+ * Provides authenticated encryption with associated data (AEAD).
68
+ */
69
+ /** AES-256 key size in bytes */
70
+ declare const AES_KEY_SIZE = 32;
71
+ /** AES-GCM IV size in bytes (96 bits recommended by NIST) */
72
+ declare const AES_GCM_IV_SIZE = 12;
73
+ /** AES-GCM auth tag size in bytes (128 bits) */
74
+ declare const AES_GCM_TAG_SIZE = 16;
75
+ /**
76
+ * Import a raw 256-bit key for AES-GCM operations.
77
+ *
78
+ * @param keyBytes - 32-byte raw key material
79
+ * @returns CryptoKey suitable for AES-GCM encryption/decryption
80
+ */
81
+ declare function importAesKey(keyBytes: Uint8Array): Promise<CryptoKey>;
82
+ /**
83
+ * Generate a random 256-bit AES key.
84
+ *
85
+ * @returns CryptoKey for AES-GCM
86
+ */
87
+ declare function generateAesKey(): Promise<CryptoKey>;
88
+ /**
89
+ * Export a CryptoKey to raw bytes.
90
+ *
91
+ * @param key - CryptoKey to export
92
+ * @returns 32-byte raw key
93
+ */
94
+ declare function exportAesKey(key: CryptoKey): Promise<Uint8Array>;
95
+ /**
96
+ * Encrypt data using AES-256-GCM.
97
+ *
98
+ * @param plaintext - Data to encrypt
99
+ * @param key - AES-256 key (CryptoKey or 32-byte Uint8Array)
100
+ * @param iv - Optional 12-byte IV (generated if not provided)
101
+ * @param additionalData - Optional additional authenticated data (AAD)
102
+ * @returns Object containing IV and ciphertext (with auth tag appended)
103
+ */
104
+ declare function aesEncrypt(plaintext: Uint8Array, key: CryptoKey | Uint8Array, iv?: Uint8Array, additionalData?: Uint8Array): Promise<{
105
+ iv: Uint8Array;
106
+ ciphertext: Uint8Array;
107
+ }>;
108
+ /**
109
+ * Encrypt data and return combined IV + ciphertext.
110
+ * Convenience method for simple encryption.
111
+ *
112
+ * @param plaintext - Data to encrypt
113
+ * @param key - AES-256 key
114
+ * @param additionalData - Optional AAD
115
+ * @returns Combined bytes: [IV (12 bytes)] [ciphertext + tag]
116
+ */
117
+ declare function aesEncryptCombined(plaintext: Uint8Array, key: CryptoKey | Uint8Array, additionalData?: Uint8Array): Promise<Uint8Array>;
118
+ /**
119
+ * Decrypt data using AES-256-GCM.
120
+ *
121
+ * @param ciphertext - Encrypted data (with auth tag appended)
122
+ * @param key - AES-256 key (CryptoKey or 32-byte Uint8Array)
123
+ * @param iv - 12-byte IV used for encryption
124
+ * @param additionalData - Optional additional authenticated data (must match encryption)
125
+ * @returns Decrypted plaintext
126
+ * @throws Error if authentication fails (wrong key or tampered data)
127
+ */
128
+ declare function aesDecrypt(ciphertext: Uint8Array, key: CryptoKey | Uint8Array, iv: Uint8Array, additionalData?: Uint8Array): Promise<Uint8Array>;
129
+ /**
130
+ * Decrypt combined IV + ciphertext.
131
+ * Convenience method for simple decryption.
132
+ *
133
+ * @param combined - Combined bytes: [IV (12 bytes)] [ciphertext + tag]
134
+ * @param key - AES-256 key
135
+ * @param additionalData - Optional AAD
136
+ * @returns Decrypted plaintext
137
+ */
138
+ declare function aesDecryptCombined(combined: Uint8Array, key: CryptoKey | Uint8Array, additionalData?: Uint8Array): Promise<Uint8Array>;
139
+ /** Chunk size for streaming operations (1 MB) */
140
+ declare const STREAM_CHUNK_SIZE: number;
141
+ /**
142
+ * Encrypt large data in chunks.
143
+ * Each chunk is encrypted with a unique IV derived from base IV + counter.
144
+ *
145
+ * Note: For files < 100MB, use regular aesEncrypt for simplicity.
146
+ * This is primarily for very large files where memory is a concern.
147
+ *
148
+ * @param plaintext - Data to encrypt
149
+ * @param key - AES-256 key
150
+ * @param onProgress - Optional progress callback
151
+ * @returns Encrypted data with format: [chunk count (4 bytes)] [IV] [chunks...]
152
+ */
153
+ declare function aesEncryptStreaming(plaintext: Uint8Array, key: CryptoKey | Uint8Array, onProgress?: (percent: number) => void): Promise<Uint8Array>;
154
+ /**
155
+ * Decrypt large data encrypted with aesEncryptStreaming.
156
+ *
157
+ * @param encrypted - Encrypted data from aesEncryptStreaming
158
+ * @param key - AES-256 key
159
+ * @param onProgress - Optional progress callback
160
+ * @returns Decrypted plaintext
161
+ */
162
+ declare function aesDecryptStreaming(encrypted: Uint8Array, key: CryptoKey | Uint8Array, onProgress?: (percent: number) => void): Promise<Uint8Array>;
163
+
164
+ /**
165
+ * Omnituum FS - OQE Binary Format
166
+ *
167
+ * Reader/writer for the .oqe (Omnituum Quantum Encrypted) file format.
168
+ * Implements a documented, stable binary format for encrypted files.
169
+ */
170
+
171
+ /**
172
+ * Write an OQE file header.
173
+ *
174
+ * @param header - Header data
175
+ * @returns 30-byte header buffer
176
+ */
177
+ declare function writeOQEHeader(header: OQEHeader): Uint8Array;
178
+ /**
179
+ * Parse an OQE file header.
180
+ *
181
+ * @param data - File data (at least 30 bytes)
182
+ * @returns Parsed header
183
+ * @throws OQEError if header is invalid
184
+ */
185
+ declare function parseOQEHeader(data: Uint8Array): OQEHeader;
186
+ /**
187
+ * Serialize hybrid mode key material.
188
+ *
189
+ * Format:
190
+ * - X25519 ephemeral PK (32 bytes)
191
+ * - X25519 nonce (24 bytes)
192
+ * - X25519 wrapped key length (2 bytes)
193
+ * - X25519 wrapped key (variable)
194
+ * - Kyber ciphertext length (2 bytes)
195
+ * - Kyber ciphertext (variable, ~1088 bytes)
196
+ * - Kyber nonce (24 bytes)
197
+ * - Kyber wrapped key length (2 bytes)
198
+ * - Kyber wrapped key (variable)
199
+ */
200
+ declare function serializeHybridKeyMaterial(km: HybridKeyMaterial): Uint8Array;
201
+ /**
202
+ * Parse hybrid mode key material.
203
+ */
204
+ declare function parseHybridKeyMaterial(data: Uint8Array): HybridKeyMaterial;
205
+ /**
206
+ * Serialize password mode key material.
207
+ *
208
+ * Format:
209
+ * - Salt (32 bytes)
210
+ * - Memory cost (4 bytes, KiB)
211
+ * - Time cost (4 bytes)
212
+ * - Parallelism (4 bytes)
213
+ */
214
+ declare function serializePasswordKeyMaterial(km: PasswordKeyMaterial): Uint8Array;
215
+ /**
216
+ * Parse password mode key material.
217
+ */
218
+ declare function parsePasswordKeyMaterial(data: Uint8Array): PasswordKeyMaterial;
219
+ /**
220
+ * Serialize metadata to JSON bytes.
221
+ */
222
+ declare function serializeMetadata(metadata: OQEMetadata): Uint8Array;
223
+ /**
224
+ * Parse metadata from JSON bytes.
225
+ */
226
+ declare function parseMetadata(data: Uint8Array): OQEMetadata;
227
+ interface OQEFileComponents {
228
+ header: OQEHeader;
229
+ keyMaterial: Uint8Array;
230
+ encryptedMetadata: Uint8Array;
231
+ encryptedContent: Uint8Array;
232
+ }
233
+ /**
234
+ * Assemble a complete OQE file from components.
235
+ */
236
+ declare function assembleOQEFile(components: OQEFileComponents): Uint8Array;
237
+ /**
238
+ * Parse a complete OQE file into components.
239
+ */
240
+ declare function parseOQEFile(data: Uint8Array): OQEFileComponents;
241
+ /** OQE file extension */
242
+ declare const OQE_EXTENSION = ".oqe";
243
+ /**
244
+ * Add .oqe extension to a filename.
245
+ */
246
+ declare function addOQEExtension(filename: string): string;
247
+ /**
248
+ * Remove .oqe extension from a filename.
249
+ */
250
+ declare function removeOQEExtension(filename: string): string;
251
+ /**
252
+ * Check if a file is an OQE file (by extension or magic bytes).
253
+ */
254
+ declare function isOQEFile(filenameOrData: string | Uint8Array): boolean;
255
+ /** OQE MIME type */
256
+ declare const OQE_MIME_TYPE = "application/x-omnituum-encrypted";
257
+ /**
258
+ * Get a display-friendly algorithm name from suite ID.
259
+ */
260
+ declare function getAlgorithmName(suiteId: AlgorithmSuiteId): string;
261
+
262
+ /**
263
+ * Omnituum FS - Browser File Utilities
264
+ *
265
+ * Utilities for handling files in the browser environment:
266
+ * - Drag and drop support
267
+ * - File download/upload
268
+ * - Blob/URL handling
269
+ */
270
+
271
+ /**
272
+ * Download encrypted file to user's device.
273
+ *
274
+ * @param result - Encryption result from encryptFile()
275
+ */
276
+ declare function downloadEncryptedFile(result: OQEEncryptResult): void;
277
+ /**
278
+ * Download decrypted file to user's device.
279
+ *
280
+ * @param result - Decryption result from decryptFile()
281
+ */
282
+ declare function downloadDecryptedFile(result: OQEDecryptResult): void;
283
+ /**
284
+ * Download a Blob as a file.
285
+ */
286
+ declare function downloadBlob(blob: Blob, filename: string): void;
287
+ /**
288
+ * Download bytes as a file.
289
+ */
290
+ declare function downloadBytes(data: Uint8Array, filename: string, mimeType?: string): void;
291
+ /**
292
+ * Read a File object as Uint8Array.
293
+ */
294
+ declare function readFile(file: File): Promise<Uint8Array>;
295
+ /**
296
+ * Read a File object as text.
297
+ */
298
+ declare function readFileAsText(file: File): Promise<string>;
299
+ /**
300
+ * Read a File object as Data URL.
301
+ */
302
+ declare function readFileAsDataURL(file: File): Promise<string>;
303
+ interface DropZoneOptions {
304
+ /** Element to attach drop zone to */
305
+ element: HTMLElement;
306
+ /** Called when valid files are dropped */
307
+ onDrop: (files: File[]) => void;
308
+ /** Called when drag enters */
309
+ onDragEnter?: () => void;
310
+ /** Called when drag leaves */
311
+ onDragLeave?: () => void;
312
+ /** Filter for accepted file types (e.g., ['image/*', '.pdf']) */
313
+ accept?: string[];
314
+ /** Allow multiple files */
315
+ multiple?: boolean;
316
+ }
317
+ /**
318
+ * Create a drop zone for file drag and drop.
319
+ * Returns a cleanup function to remove listeners.
320
+ */
321
+ declare function createDropZone(options: DropZoneOptions): () => void;
322
+ interface FileInputOptions {
323
+ /** Filter for accepted file types */
324
+ accept?: string[];
325
+ /** Allow multiple files */
326
+ multiple?: boolean;
327
+ }
328
+ /**
329
+ * Open file picker dialog and return selected files.
330
+ */
331
+ declare function openFilePicker(options?: FileInputOptions): Promise<File[]>;
332
+ /**
333
+ * Open file picker for OQE files specifically.
334
+ */
335
+ declare function openOQEFilePicker(multiple?: boolean): Promise<File[]>;
336
+ /**
337
+ * Open file picker for any file to encrypt.
338
+ */
339
+ declare function openFileToEncrypt(multiple?: boolean): Promise<File[]>;
340
+ /**
341
+ * Create a Blob from encryption result.
342
+ */
343
+ declare function encryptResultToBlob(result: OQEEncryptResult): Blob;
344
+ /**
345
+ * Create a Blob from decryption result.
346
+ */
347
+ declare function decryptResultToBlob(result: OQEDecryptResult): Blob;
348
+ /**
349
+ * Create an object URL for a Blob.
350
+ * Remember to call URL.revokeObjectURL() when done.
351
+ */
352
+ declare function createObjectURL(blob: Blob): string;
353
+ /**
354
+ * Create a Data URL from bytes.
355
+ */
356
+ declare function bytesToDataURL(data: Uint8Array, mimeType: string): Promise<string>;
357
+ interface FileInfo {
358
+ /** Filename */
359
+ name: string;
360
+ /** File size in bytes */
361
+ size: number;
362
+ /** MIME type */
363
+ type: string;
364
+ /** Last modified timestamp */
365
+ lastModified: number;
366
+ /** Is this an OQE file? */
367
+ isOQE: boolean;
368
+ /** Human-readable size */
369
+ sizeFormatted: string;
370
+ }
371
+ /**
372
+ * Get information about a file.
373
+ */
374
+ declare function getFileInfo(file: File): FileInfo;
375
+ /**
376
+ * Format file size for display.
377
+ */
378
+ declare function formatFileSize(bytes: number): string;
379
+ /**
380
+ * Copy text to clipboard.
381
+ */
382
+ declare function copyToClipboard(text: string): Promise<boolean>;
383
+ /**
384
+ * Check if running in a browser environment.
385
+ */
386
+ declare function isBrowser(): boolean;
387
+ /**
388
+ * Check if Web Crypto API is available.
389
+ */
390
+ declare function isWebCryptoAvailable(): boolean;
391
+ /**
392
+ * Check if File API is available.
393
+ */
394
+ declare function isFileAPIAvailable(): boolean;
395
+ /**
396
+ * Check if drag and drop is supported.
397
+ */
398
+ declare function isDragDropSupported(): boolean;
399
+
400
+ export { AES_GCM_IV_SIZE, AES_GCM_TAG_SIZE, AES_KEY_SIZE, AlgorithmSuiteId, Argon2idParams, HybridKeyMaterial, OQEDecryptResult, OQEEncryptResult, OQEHeader, OQEMetadata, OQE_EXTENSION, OQE_MIME_TYPE, PasswordKeyMaterial, STREAM_CHUNK_SIZE, addOQEExtension, aesDecrypt, aesDecryptCombined, aesDecryptStreaming, aesEncrypt, aesEncryptCombined, aesEncryptStreaming, assembleOQEFile, benchmarkArgon2, bytesToDataURL, copyToClipboard, createDropZone, createObjectURL, decryptResultToBlob, deriveKeyFromPassword, downloadBlob, downloadBytes, downloadDecryptedFile, downloadEncryptedFile, encryptResultToBlob, estimateArgon2Params, exportAesKey, formatFileSize, generateAesKey, generateArgon2Salt, getAlgorithmName, getFileInfo, importAesKey, isArgon2Available, isBrowser, isDragDropSupported, isFileAPIAvailable, isOQEFile, isWebCryptoAvailable, openFilePicker, openFileToEncrypt, openOQEFilePicker, parseHybridKeyMaterial, parseMetadata, parseOQEFile, parseOQEHeader, parsePasswordKeyMaterial, readFile, readFileAsDataURL, readFileAsText, removeOQEExtension, serializeHybridKeyMaterial, serializeMetadata, serializePasswordKeyMaterial, verifyPassword, writeOQEHeader };