@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,321 @@
1
+ /**
2
+ * Omnituum FS - File Encryption Types
3
+ *
4
+ * Type definitions for the .oqe (Omnituum Quantum Encrypted) file format.
5
+ * Supports two encryption modes:
6
+ * - Mode A: Hybrid (X25519 + Kyber768) - for identity-based encryption
7
+ * - Mode B: Password (Argon2id) - for standalone file protection
8
+ */
9
+ /** Magic bytes: "OQEF" (Omnituum Quantum Encrypted File) */
10
+ declare const OQE_MAGIC: Uint8Array<ArrayBuffer>;
11
+ /** Current format version */
12
+ declare const OQE_FORMAT_VERSION = 1;
13
+ /** Supported encryption modes */
14
+ type OQEMode = 'hybrid' | 'password';
15
+ /** Algorithm suite identifiers */
16
+ declare const ALGORITHM_SUITES: {
17
+ /** Hybrid: X25519 ECDH + Kyber768 KEM + AES-256-GCM */
18
+ readonly HYBRID_X25519_KYBER768_AES256GCM: 1;
19
+ /** Password: Argon2id + AES-256-GCM */
20
+ readonly PASSWORD_ARGON2ID_AES256GCM: 2;
21
+ };
22
+ type AlgorithmSuiteId = typeof ALGORITHM_SUITES[keyof typeof ALGORITHM_SUITES];
23
+ interface Argon2idParams {
24
+ /** Memory cost in KiB (default: 65536 = 64MB) */
25
+ memoryCost: number;
26
+ /** Time cost / iterations (default: 3) */
27
+ timeCost: number;
28
+ /** Parallelism (default: 4) */
29
+ parallelism: number;
30
+ /** Output key length in bytes (default: 32 for AES-256) */
31
+ hashLength: number;
32
+ /** Salt length in bytes (default: 32) */
33
+ saltLength: number;
34
+ }
35
+ /** Default Argon2id parameters - OWASP 2024 recommended */
36
+ declare const DEFAULT_ARGON2ID_PARAMS: Argon2idParams;
37
+ /** Minimum Argon2id parameters for low-memory environments */
38
+ declare const MIN_ARGON2ID_PARAMS: Argon2idParams;
39
+ interface OQEMetadata {
40
+ /** Original filename (encrypted in file) */
41
+ filename: string;
42
+ /** Original file size in bytes */
43
+ originalSize: number;
44
+ /** Original MIME type (optional) */
45
+ mimeType?: string;
46
+ /** Encryption timestamp (ISO 8601) */
47
+ encryptedAt: string;
48
+ /** Encryptor identity hash (hybrid mode only) */
49
+ encryptorIdHash?: string;
50
+ /** Recipient identity hash (hybrid mode only) */
51
+ recipientIdHash?: string;
52
+ /** Custom metadata (optional) */
53
+ custom?: Record<string, string>;
54
+ }
55
+ /**
56
+ * OQE Binary Header Layout:
57
+ *
58
+ * Offset | Size | Description
59
+ * -------|------|------------
60
+ * 0 | 4 | Magic bytes "OQEF"
61
+ * 4 | 1 | Format version (1)
62
+ * 5 | 1 | Algorithm suite ID
63
+ * 6 | 4 | Flags (reserved)
64
+ * 10 | 4 | Metadata length (encrypted JSON)
65
+ * 14 | 4 | Key material length
66
+ * 18 | 12 | AES-GCM IV
67
+ * 30 | var | Key material (mode-specific)
68
+ * --- | var | Encrypted metadata (JSON + auth tag)
69
+ * --- | var | Encrypted file content (with auth tag)
70
+ */
71
+ interface OQEHeader {
72
+ /** Format version */
73
+ version: number;
74
+ /** Algorithm suite ID */
75
+ algorithmSuite: AlgorithmSuiteId;
76
+ /** Header flags (reserved for future use) */
77
+ flags: number;
78
+ /** Length of encrypted metadata */
79
+ metadataLength: number;
80
+ /** Length of key material section */
81
+ keyMaterialLength: number;
82
+ /** AES-GCM initialization vector */
83
+ iv: Uint8Array;
84
+ }
85
+ /** Fixed header size in bytes (before variable-length sections) */
86
+ declare const OQE_HEADER_SIZE = 30;
87
+ /**
88
+ * Hybrid Mode Key Material:
89
+ * - X25519 ephemeral public key (32 bytes)
90
+ * - X25519 wrapped content key (32 + 16 bytes auth tag = 48 bytes)
91
+ * - X25519 wrap nonce (24 bytes for XSalsa20-Poly1305)
92
+ * - Kyber KEM ciphertext (~1088 bytes for Kyber768)
93
+ * - Kyber wrapped content key (48 bytes)
94
+ * - Kyber wrap nonce (24 bytes)
95
+ */
96
+ interface HybridKeyMaterial {
97
+ /** X25519 ephemeral public key */
98
+ x25519EphemeralPk: Uint8Array;
99
+ /** X25519 wrapped content key (NaCl secretbox) */
100
+ x25519WrappedKey: Uint8Array;
101
+ /** X25519 wrap nonce */
102
+ x25519Nonce: Uint8Array;
103
+ /** Kyber KEM ciphertext */
104
+ kyberCiphertext: Uint8Array;
105
+ /** Kyber wrapped content key (NaCl secretbox) */
106
+ kyberWrappedKey: Uint8Array;
107
+ /** Kyber wrap nonce */
108
+ kyberNonce: Uint8Array;
109
+ }
110
+ /**
111
+ * Password Mode Key Material:
112
+ * - Argon2id salt (32 bytes)
113
+ * - Argon2id parameters (encoded as 4 bytes each: mem, time, parallelism)
114
+ */
115
+ interface PasswordKeyMaterial {
116
+ /** Argon2id salt */
117
+ salt: Uint8Array;
118
+ /** Argon2id memory cost in KiB */
119
+ memoryCost: number;
120
+ /** Argon2id time cost (iterations) */
121
+ timeCost: number;
122
+ /** Argon2id parallelism */
123
+ parallelism: number;
124
+ }
125
+ /** Options for hybrid mode encryption */
126
+ interface HybridEncryptOptions {
127
+ mode: 'hybrid';
128
+ /** Recipient's public keys */
129
+ recipientPublicKeys: {
130
+ x25519PubHex: string;
131
+ kyberPubB64: string;
132
+ };
133
+ /** Sender identity (optional, for metadata) */
134
+ sender?: {
135
+ id: string;
136
+ name?: string;
137
+ };
138
+ }
139
+ /** Options for password mode encryption */
140
+ interface PasswordEncryptOptions {
141
+ mode: 'password';
142
+ /** User password */
143
+ password: string;
144
+ /** Argon2id parameters (uses defaults if not specified) */
145
+ argon2Params?: Partial<Argon2idParams>;
146
+ }
147
+ type EncryptOptions = HybridEncryptOptions | PasswordEncryptOptions;
148
+ /** Options for hybrid mode decryption */
149
+ interface HybridDecryptOptions {
150
+ mode: 'hybrid';
151
+ /** Recipient's secret keys */
152
+ recipientSecretKeys: {
153
+ x25519SecHex: string;
154
+ kyberSecB64: string;
155
+ };
156
+ }
157
+ /** Options for password mode decryption */
158
+ interface PasswordDecryptOptions {
159
+ mode: 'password';
160
+ /** User password */
161
+ password: string;
162
+ }
163
+ type DecryptOptions = HybridDecryptOptions | PasswordDecryptOptions;
164
+ interface OQEEncryptResult {
165
+ /** Complete .oqe file as bytes */
166
+ data: Uint8Array;
167
+ /** Suggested filename with .oqe extension */
168
+ filename: string;
169
+ /** File metadata (for UI display) */
170
+ metadata: OQEMetadata;
171
+ /** Encryption mode used */
172
+ mode: OQEMode;
173
+ }
174
+ interface OQEDecryptResult {
175
+ /** Decrypted file content */
176
+ data: Uint8Array;
177
+ /** Original filename */
178
+ filename: string;
179
+ /** Original MIME type */
180
+ mimeType?: string;
181
+ /** Original file size */
182
+ originalSize: number;
183
+ /** File metadata */
184
+ metadata: OQEMetadata;
185
+ /** Decryption mode used */
186
+ mode: OQEMode;
187
+ }
188
+ type OQEErrorCode = 'INVALID_MAGIC' | 'UNSUPPORTED_VERSION' | 'UNSUPPORTED_ALGORITHM' | 'INVALID_HEADER' | 'DECRYPTION_FAILED' | 'PASSWORD_WRONG' | 'KEY_UNWRAP_FAILED' | 'INTEGRITY_CHECK_FAILED' | 'KYBER_UNAVAILABLE' | 'ARGON2_UNAVAILABLE' | 'FILE_TOO_LARGE' | 'ENCRYPTION_FAILED';
189
+ declare class OQEError extends Error {
190
+ code: OQEErrorCode;
191
+ constructor(code: OQEErrorCode, message: string);
192
+ }
193
+ /** Progress callback for large file operations */
194
+ type ProgressCallback = (progress: {
195
+ phase: 'reading' | 'encrypting' | 'decrypting' | 'writing';
196
+ bytesProcessed: number;
197
+ totalBytes: number;
198
+ percent: number;
199
+ }) => void;
200
+ /** File input types supported */
201
+ type FileInput = File | Blob | Uint8Array | ArrayBuffer;
202
+ /** Convert any file input to Uint8Array */
203
+ declare function toUint8Array(input: FileInput): Promise<Uint8Array>;
204
+
205
+ /**
206
+ * Omnituum FS - File Encryption
207
+ *
208
+ * Encrypt files using hybrid post-quantum cryptography or password-based encryption.
209
+ * Outputs .oqe (Omnituum Quantum Encrypted) files.
210
+ */
211
+
212
+ interface EncryptFileInput {
213
+ /** File data */
214
+ data: FileInput;
215
+ /** Original filename */
216
+ filename: string;
217
+ /** Optional MIME type */
218
+ mimeType?: string;
219
+ }
220
+ /**
221
+ * Encrypt a file using hybrid PQC or password-based encryption.
222
+ *
223
+ * @param input - File data and metadata
224
+ * @param options - Encryption options (hybrid or password mode)
225
+ * @returns Encrypted .oqe file result
226
+ *
227
+ * @example
228
+ * // Hybrid mode (with identity)
229
+ * const result = await encryptFile(
230
+ * { data: fileBytes, filename: 'secret.pdf' },
231
+ * {
232
+ * mode: 'hybrid',
233
+ * recipientPublicKeys: identity.getPublicKeys(),
234
+ * }
235
+ * );
236
+ *
237
+ * @example
238
+ * // Password mode
239
+ * const result = await encryptFile(
240
+ * { data: fileBytes, filename: 'secret.pdf' },
241
+ * {
242
+ * mode: 'password',
243
+ * password: 'my-secure-password',
244
+ * }
245
+ * );
246
+ */
247
+ declare function encryptFile(input: EncryptFileInput, options: EncryptOptions): Promise<OQEEncryptResult>;
248
+ /**
249
+ * Encrypt a file for self (encrypt and decrypt with same identity).
250
+ * Convenience method for personal file encryption.
251
+ */
252
+ declare function encryptFileForSelf(input: EncryptFileInput, identity: {
253
+ id: string;
254
+ name?: string;
255
+ x25519PubHex: string;
256
+ kyberPubB64: string;
257
+ }): Promise<OQEEncryptResult>;
258
+ /**
259
+ * Quick encrypt with password (simple API).
260
+ */
261
+ declare function encryptFileWithPassword(input: EncryptFileInput, password: string): Promise<OQEEncryptResult>;
262
+
263
+ /**
264
+ * Omnituum FS - File Decryption
265
+ *
266
+ * Decrypt .oqe (Omnituum Quantum Encrypted) files using hybrid PQC or password.
267
+ */
268
+
269
+ /**
270
+ * Decrypt an OQE file.
271
+ *
272
+ * @param encryptedData - Encrypted .oqe file data
273
+ * @param options - Decryption options (hybrid or password mode)
274
+ * @returns Decrypted file result
275
+ *
276
+ * @example
277
+ * // Hybrid mode (with identity)
278
+ * const result = await decryptFile(oqeData, {
279
+ * mode: 'hybrid',
280
+ * recipientSecretKeys: identity.getSecretKeys(),
281
+ * });
282
+ *
283
+ * @example
284
+ * // Password mode
285
+ * const result = await decryptFile(oqeData, {
286
+ * mode: 'password',
287
+ * password: 'my-secure-password',
288
+ * });
289
+ */
290
+ declare function decryptFile(encryptedData: FileInput, options: DecryptOptions): Promise<OQEDecryptResult>;
291
+ /**
292
+ * Decrypt a file encrypted for self.
293
+ * Convenience method for personal file decryption.
294
+ */
295
+ declare function decryptFileForSelf(encryptedData: FileInput, identity: {
296
+ x25519SecHex: string;
297
+ kyberSecB64: string;
298
+ }): Promise<OQEDecryptResult>;
299
+ /**
300
+ * Quick decrypt with password (simple API).
301
+ */
302
+ declare function decryptFileWithPassword(encryptedData: FileInput, password: string): Promise<OQEDecryptResult>;
303
+ interface OQEFileInfo {
304
+ /** Format version */
305
+ version: number;
306
+ /** Encryption mode */
307
+ mode: 'hybrid' | 'password';
308
+ /** Algorithm name */
309
+ algorithm: string;
310
+ /** Can decrypt with Kyber (for hybrid mode) */
311
+ supportsKyber: boolean;
312
+ /** File size */
313
+ fileSize: number;
314
+ }
315
+ /**
316
+ * Inspect an OQE file without decrypting it.
317
+ * Useful for determining what credentials are needed.
318
+ */
319
+ declare function inspectOQEFile(data: FileInput): Promise<OQEFileInfo>;
320
+
321
+ export { type Argon2idParams as A, type DecryptOptions as D, type EncryptOptions as E, type FileInput as F, type HybridKeyMaterial as H, MIN_ARGON2ID_PARAMS as M, type OQEEncryptResult as O, type PasswordKeyMaterial as P, encryptFileWithPassword as a, decryptFileWithPassword as b, type OQEDecryptResult as c, decryptFile as d, encryptFile as e, type OQEHeader as f, type OQEMetadata as g, type AlgorithmSuiteId as h, DEFAULT_ARGON2ID_PARAMS as i, encryptFileForSelf as j, decryptFileForSelf as k, inspectOQEFile as l, type OQEMode as m, type HybridEncryptOptions as n, type PasswordEncryptOptions as o, type HybridDecryptOptions as p, type PasswordDecryptOptions as q, type OQEErrorCode as r, type ProgressCallback as s, OQEError as t, OQE_MAGIC as u, OQE_FORMAT_VERSION as v, ALGORITHM_SUITES as w, OQE_HEADER_SIZE as x, toUint8Array as y };
@@ -0,0 +1,321 @@
1
+ /**
2
+ * Omnituum FS - File Encryption Types
3
+ *
4
+ * Type definitions for the .oqe (Omnituum Quantum Encrypted) file format.
5
+ * Supports two encryption modes:
6
+ * - Mode A: Hybrid (X25519 + Kyber768) - for identity-based encryption
7
+ * - Mode B: Password (Argon2id) - for standalone file protection
8
+ */
9
+ /** Magic bytes: "OQEF" (Omnituum Quantum Encrypted File) */
10
+ declare const OQE_MAGIC: Uint8Array<ArrayBuffer>;
11
+ /** Current format version */
12
+ declare const OQE_FORMAT_VERSION = 1;
13
+ /** Supported encryption modes */
14
+ type OQEMode = 'hybrid' | 'password';
15
+ /** Algorithm suite identifiers */
16
+ declare const ALGORITHM_SUITES: {
17
+ /** Hybrid: X25519 ECDH + Kyber768 KEM + AES-256-GCM */
18
+ readonly HYBRID_X25519_KYBER768_AES256GCM: 1;
19
+ /** Password: Argon2id + AES-256-GCM */
20
+ readonly PASSWORD_ARGON2ID_AES256GCM: 2;
21
+ };
22
+ type AlgorithmSuiteId = typeof ALGORITHM_SUITES[keyof typeof ALGORITHM_SUITES];
23
+ interface Argon2idParams {
24
+ /** Memory cost in KiB (default: 65536 = 64MB) */
25
+ memoryCost: number;
26
+ /** Time cost / iterations (default: 3) */
27
+ timeCost: number;
28
+ /** Parallelism (default: 4) */
29
+ parallelism: number;
30
+ /** Output key length in bytes (default: 32 for AES-256) */
31
+ hashLength: number;
32
+ /** Salt length in bytes (default: 32) */
33
+ saltLength: number;
34
+ }
35
+ /** Default Argon2id parameters - OWASP 2024 recommended */
36
+ declare const DEFAULT_ARGON2ID_PARAMS: Argon2idParams;
37
+ /** Minimum Argon2id parameters for low-memory environments */
38
+ declare const MIN_ARGON2ID_PARAMS: Argon2idParams;
39
+ interface OQEMetadata {
40
+ /** Original filename (encrypted in file) */
41
+ filename: string;
42
+ /** Original file size in bytes */
43
+ originalSize: number;
44
+ /** Original MIME type (optional) */
45
+ mimeType?: string;
46
+ /** Encryption timestamp (ISO 8601) */
47
+ encryptedAt: string;
48
+ /** Encryptor identity hash (hybrid mode only) */
49
+ encryptorIdHash?: string;
50
+ /** Recipient identity hash (hybrid mode only) */
51
+ recipientIdHash?: string;
52
+ /** Custom metadata (optional) */
53
+ custom?: Record<string, string>;
54
+ }
55
+ /**
56
+ * OQE Binary Header Layout:
57
+ *
58
+ * Offset | Size | Description
59
+ * -------|------|------------
60
+ * 0 | 4 | Magic bytes "OQEF"
61
+ * 4 | 1 | Format version (1)
62
+ * 5 | 1 | Algorithm suite ID
63
+ * 6 | 4 | Flags (reserved)
64
+ * 10 | 4 | Metadata length (encrypted JSON)
65
+ * 14 | 4 | Key material length
66
+ * 18 | 12 | AES-GCM IV
67
+ * 30 | var | Key material (mode-specific)
68
+ * --- | var | Encrypted metadata (JSON + auth tag)
69
+ * --- | var | Encrypted file content (with auth tag)
70
+ */
71
+ interface OQEHeader {
72
+ /** Format version */
73
+ version: number;
74
+ /** Algorithm suite ID */
75
+ algorithmSuite: AlgorithmSuiteId;
76
+ /** Header flags (reserved for future use) */
77
+ flags: number;
78
+ /** Length of encrypted metadata */
79
+ metadataLength: number;
80
+ /** Length of key material section */
81
+ keyMaterialLength: number;
82
+ /** AES-GCM initialization vector */
83
+ iv: Uint8Array;
84
+ }
85
+ /** Fixed header size in bytes (before variable-length sections) */
86
+ declare const OQE_HEADER_SIZE = 30;
87
+ /**
88
+ * Hybrid Mode Key Material:
89
+ * - X25519 ephemeral public key (32 bytes)
90
+ * - X25519 wrapped content key (32 + 16 bytes auth tag = 48 bytes)
91
+ * - X25519 wrap nonce (24 bytes for XSalsa20-Poly1305)
92
+ * - Kyber KEM ciphertext (~1088 bytes for Kyber768)
93
+ * - Kyber wrapped content key (48 bytes)
94
+ * - Kyber wrap nonce (24 bytes)
95
+ */
96
+ interface HybridKeyMaterial {
97
+ /** X25519 ephemeral public key */
98
+ x25519EphemeralPk: Uint8Array;
99
+ /** X25519 wrapped content key (NaCl secretbox) */
100
+ x25519WrappedKey: Uint8Array;
101
+ /** X25519 wrap nonce */
102
+ x25519Nonce: Uint8Array;
103
+ /** Kyber KEM ciphertext */
104
+ kyberCiphertext: Uint8Array;
105
+ /** Kyber wrapped content key (NaCl secretbox) */
106
+ kyberWrappedKey: Uint8Array;
107
+ /** Kyber wrap nonce */
108
+ kyberNonce: Uint8Array;
109
+ }
110
+ /**
111
+ * Password Mode Key Material:
112
+ * - Argon2id salt (32 bytes)
113
+ * - Argon2id parameters (encoded as 4 bytes each: mem, time, parallelism)
114
+ */
115
+ interface PasswordKeyMaterial {
116
+ /** Argon2id salt */
117
+ salt: Uint8Array;
118
+ /** Argon2id memory cost in KiB */
119
+ memoryCost: number;
120
+ /** Argon2id time cost (iterations) */
121
+ timeCost: number;
122
+ /** Argon2id parallelism */
123
+ parallelism: number;
124
+ }
125
+ /** Options for hybrid mode encryption */
126
+ interface HybridEncryptOptions {
127
+ mode: 'hybrid';
128
+ /** Recipient's public keys */
129
+ recipientPublicKeys: {
130
+ x25519PubHex: string;
131
+ kyberPubB64: string;
132
+ };
133
+ /** Sender identity (optional, for metadata) */
134
+ sender?: {
135
+ id: string;
136
+ name?: string;
137
+ };
138
+ }
139
+ /** Options for password mode encryption */
140
+ interface PasswordEncryptOptions {
141
+ mode: 'password';
142
+ /** User password */
143
+ password: string;
144
+ /** Argon2id parameters (uses defaults if not specified) */
145
+ argon2Params?: Partial<Argon2idParams>;
146
+ }
147
+ type EncryptOptions = HybridEncryptOptions | PasswordEncryptOptions;
148
+ /** Options for hybrid mode decryption */
149
+ interface HybridDecryptOptions {
150
+ mode: 'hybrid';
151
+ /** Recipient's secret keys */
152
+ recipientSecretKeys: {
153
+ x25519SecHex: string;
154
+ kyberSecB64: string;
155
+ };
156
+ }
157
+ /** Options for password mode decryption */
158
+ interface PasswordDecryptOptions {
159
+ mode: 'password';
160
+ /** User password */
161
+ password: string;
162
+ }
163
+ type DecryptOptions = HybridDecryptOptions | PasswordDecryptOptions;
164
+ interface OQEEncryptResult {
165
+ /** Complete .oqe file as bytes */
166
+ data: Uint8Array;
167
+ /** Suggested filename with .oqe extension */
168
+ filename: string;
169
+ /** File metadata (for UI display) */
170
+ metadata: OQEMetadata;
171
+ /** Encryption mode used */
172
+ mode: OQEMode;
173
+ }
174
+ interface OQEDecryptResult {
175
+ /** Decrypted file content */
176
+ data: Uint8Array;
177
+ /** Original filename */
178
+ filename: string;
179
+ /** Original MIME type */
180
+ mimeType?: string;
181
+ /** Original file size */
182
+ originalSize: number;
183
+ /** File metadata */
184
+ metadata: OQEMetadata;
185
+ /** Decryption mode used */
186
+ mode: OQEMode;
187
+ }
188
+ type OQEErrorCode = 'INVALID_MAGIC' | 'UNSUPPORTED_VERSION' | 'UNSUPPORTED_ALGORITHM' | 'INVALID_HEADER' | 'DECRYPTION_FAILED' | 'PASSWORD_WRONG' | 'KEY_UNWRAP_FAILED' | 'INTEGRITY_CHECK_FAILED' | 'KYBER_UNAVAILABLE' | 'ARGON2_UNAVAILABLE' | 'FILE_TOO_LARGE' | 'ENCRYPTION_FAILED';
189
+ declare class OQEError extends Error {
190
+ code: OQEErrorCode;
191
+ constructor(code: OQEErrorCode, message: string);
192
+ }
193
+ /** Progress callback for large file operations */
194
+ type ProgressCallback = (progress: {
195
+ phase: 'reading' | 'encrypting' | 'decrypting' | 'writing';
196
+ bytesProcessed: number;
197
+ totalBytes: number;
198
+ percent: number;
199
+ }) => void;
200
+ /** File input types supported */
201
+ type FileInput = File | Blob | Uint8Array | ArrayBuffer;
202
+ /** Convert any file input to Uint8Array */
203
+ declare function toUint8Array(input: FileInput): Promise<Uint8Array>;
204
+
205
+ /**
206
+ * Omnituum FS - File Encryption
207
+ *
208
+ * Encrypt files using hybrid post-quantum cryptography or password-based encryption.
209
+ * Outputs .oqe (Omnituum Quantum Encrypted) files.
210
+ */
211
+
212
+ interface EncryptFileInput {
213
+ /** File data */
214
+ data: FileInput;
215
+ /** Original filename */
216
+ filename: string;
217
+ /** Optional MIME type */
218
+ mimeType?: string;
219
+ }
220
+ /**
221
+ * Encrypt a file using hybrid PQC or password-based encryption.
222
+ *
223
+ * @param input - File data and metadata
224
+ * @param options - Encryption options (hybrid or password mode)
225
+ * @returns Encrypted .oqe file result
226
+ *
227
+ * @example
228
+ * // Hybrid mode (with identity)
229
+ * const result = await encryptFile(
230
+ * { data: fileBytes, filename: 'secret.pdf' },
231
+ * {
232
+ * mode: 'hybrid',
233
+ * recipientPublicKeys: identity.getPublicKeys(),
234
+ * }
235
+ * );
236
+ *
237
+ * @example
238
+ * // Password mode
239
+ * const result = await encryptFile(
240
+ * { data: fileBytes, filename: 'secret.pdf' },
241
+ * {
242
+ * mode: 'password',
243
+ * password: 'my-secure-password',
244
+ * }
245
+ * );
246
+ */
247
+ declare function encryptFile(input: EncryptFileInput, options: EncryptOptions): Promise<OQEEncryptResult>;
248
+ /**
249
+ * Encrypt a file for self (encrypt and decrypt with same identity).
250
+ * Convenience method for personal file encryption.
251
+ */
252
+ declare function encryptFileForSelf(input: EncryptFileInput, identity: {
253
+ id: string;
254
+ name?: string;
255
+ x25519PubHex: string;
256
+ kyberPubB64: string;
257
+ }): Promise<OQEEncryptResult>;
258
+ /**
259
+ * Quick encrypt with password (simple API).
260
+ */
261
+ declare function encryptFileWithPassword(input: EncryptFileInput, password: string): Promise<OQEEncryptResult>;
262
+
263
+ /**
264
+ * Omnituum FS - File Decryption
265
+ *
266
+ * Decrypt .oqe (Omnituum Quantum Encrypted) files using hybrid PQC or password.
267
+ */
268
+
269
+ /**
270
+ * Decrypt an OQE file.
271
+ *
272
+ * @param encryptedData - Encrypted .oqe file data
273
+ * @param options - Decryption options (hybrid or password mode)
274
+ * @returns Decrypted file result
275
+ *
276
+ * @example
277
+ * // Hybrid mode (with identity)
278
+ * const result = await decryptFile(oqeData, {
279
+ * mode: 'hybrid',
280
+ * recipientSecretKeys: identity.getSecretKeys(),
281
+ * });
282
+ *
283
+ * @example
284
+ * // Password mode
285
+ * const result = await decryptFile(oqeData, {
286
+ * mode: 'password',
287
+ * password: 'my-secure-password',
288
+ * });
289
+ */
290
+ declare function decryptFile(encryptedData: FileInput, options: DecryptOptions): Promise<OQEDecryptResult>;
291
+ /**
292
+ * Decrypt a file encrypted for self.
293
+ * Convenience method for personal file decryption.
294
+ */
295
+ declare function decryptFileForSelf(encryptedData: FileInput, identity: {
296
+ x25519SecHex: string;
297
+ kyberSecB64: string;
298
+ }): Promise<OQEDecryptResult>;
299
+ /**
300
+ * Quick decrypt with password (simple API).
301
+ */
302
+ declare function decryptFileWithPassword(encryptedData: FileInput, password: string): Promise<OQEDecryptResult>;
303
+ interface OQEFileInfo {
304
+ /** Format version */
305
+ version: number;
306
+ /** Encryption mode */
307
+ mode: 'hybrid' | 'password';
308
+ /** Algorithm name */
309
+ algorithm: string;
310
+ /** Can decrypt with Kyber (for hybrid mode) */
311
+ supportsKyber: boolean;
312
+ /** File size */
313
+ fileSize: number;
314
+ }
315
+ /**
316
+ * Inspect an OQE file without decrypting it.
317
+ * Useful for determining what credentials are needed.
318
+ */
319
+ declare function inspectOQEFile(data: FileInput): Promise<OQEFileInfo>;
320
+
321
+ export { type Argon2idParams as A, type DecryptOptions as D, type EncryptOptions as E, type FileInput as F, type HybridKeyMaterial as H, MIN_ARGON2ID_PARAMS as M, type OQEEncryptResult as O, type PasswordKeyMaterial as P, encryptFileWithPassword as a, decryptFileWithPassword as b, type OQEDecryptResult as c, decryptFile as d, encryptFile as e, type OQEHeader as f, type OQEMetadata as g, type AlgorithmSuiteId as h, DEFAULT_ARGON2ID_PARAMS as i, encryptFileForSelf as j, decryptFileForSelf as k, inspectOQEFile as l, type OQEMode as m, type HybridEncryptOptions as n, type PasswordEncryptOptions as o, type HybridDecryptOptions as p, type PasswordDecryptOptions as q, type OQEErrorCode as r, type ProgressCallback as s, OQEError as t, OQE_MAGIC as u, OQE_FORMAT_VERSION as v, ALGORITHM_SUITES as w, OQE_HEADER_SIZE as x, toUint8Array as y };