@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
package/src/index.ts ADDED
@@ -0,0 +1,414 @@
1
+ // Ensure globalThis.crypto exists in Node environments
2
+ import './runtime/crypto';
3
+
4
+ /**
5
+ * Omnituum PQC Shared
6
+ *
7
+ * Unified cryptographic and vault utilities for PQC applications.
8
+ * Combines X25519 (classical) + Kyber ML-KEM-768 (post-quantum) encryption.
9
+ *
10
+ * FROZEN CONTRACTS - see pqc-docs/specs/ for format specifications.
11
+ *
12
+ * ## API Stability
13
+ *
14
+ * Exports are annotated with stability markers:
15
+ * - `@stable` — Supported and semver-governed. Breaking changes only in major versions.
16
+ * - `@experimental` — May change in minor/patch releases until stabilized.
17
+ * - `@internal` — Not part of the public API surface; do not depend on these.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // Hybrid Encryption
22
+ * import { generateHybridIdentity, hybridEncrypt, hybridDecryptToString } from '@omnituum/pqc-shared';
23
+ *
24
+ * // Vault Management
25
+ * import { createEmptyVault, createIdentity, encryptVault, decryptVault } from '@omnituum/pqc-shared';
26
+ *
27
+ * // Vault Migration
28
+ * import { needsMigration, migrateEncryptedVault } from '@omnituum/pqc-shared';
29
+ * ```
30
+ */
31
+
32
+ // ═══════════════════════════════════════════════════════════════════════════
33
+ // HYBRID ENCRYPTION (@stable)
34
+ // ═══════════════════════════════════════════════════════════════════════════
35
+
36
+ /**
37
+ * @stable Hybrid X25519 + Kyber-768 encryption primitives.
38
+ * The core post-quantum encryption interface.
39
+ */
40
+ export {
41
+ generateHybridIdentity,
42
+ hybridEncrypt,
43
+ hybridDecrypt,
44
+ hybridDecryptToString,
45
+ getPublicKeys,
46
+ getSecretKeys,
47
+ } from './crypto/hybrid';
48
+
49
+ export type {
50
+ HybridIdentity,
51
+ HybridPublicKeys,
52
+ HybridSecretKeys,
53
+ HybridEnvelope,
54
+ } from './crypto/hybrid';
55
+
56
+ // ═══════════════════════════════════════════════════════════════════════════
57
+ // KYBER (ML-KEM-768) (@stable)
58
+ // ═══════════════════════════════════════════════════════════════════════════
59
+
60
+ /**
61
+ * @stable Kyber ML-KEM-768 post-quantum KEM primitives.
62
+ */
63
+ export {
64
+ isKyberAvailable,
65
+ generateKyberKeypair,
66
+ kyberEncapsulate,
67
+ kyberDecapsulate,
68
+ kyberWrapKey,
69
+ kyberUnwrapKey,
70
+ } from './crypto/kyber';
71
+
72
+ export type {
73
+ KyberKeypair,
74
+ KyberKeypairB64,
75
+ KyberEncapsulation,
76
+ } from './crypto/kyber';
77
+
78
+ // ═══════════════════════════════════════════════════════════════════════════
79
+ // X25519 (@stable)
80
+ // ═══════════════════════════════════════════════════════════════════════════
81
+
82
+ /**
83
+ * @stable X25519 ECDH key exchange and wrapping.
84
+ */
85
+ export {
86
+ generateX25519Keypair,
87
+ generateX25519KeypairFromSeed,
88
+ boxWrapWithX25519,
89
+ boxUnwrapWithX25519,
90
+ x25519SharedSecret,
91
+ deriveKeyFromShared,
92
+ } from './crypto/x25519';
93
+
94
+ export type {
95
+ X25519Keypair,
96
+ X25519KeypairHex,
97
+ ClassicalWrap,
98
+ } from './crypto/x25519';
99
+
100
+ // ═══════════════════════════════════════════════════════════════════════════
101
+ // DILITHIUM (ML-DSA-65) (@stable)
102
+ // ═══════════════════════════════════════════════════════════════════════════
103
+
104
+ /**
105
+ * @stable Dilithium ML-DSA-65 post-quantum digital signatures.
106
+ */
107
+ export {
108
+ isDilithiumAvailable,
109
+ generateDilithiumKeypair,
110
+ generateDilithiumKeypairFromSeed,
111
+ dilithiumSign,
112
+ dilithiumSignRaw,
113
+ dilithiumVerify,
114
+ dilithiumVerifyRaw,
115
+ DILITHIUM_PUBLIC_KEY_SIZE,
116
+ DILITHIUM_SECRET_KEY_SIZE,
117
+ DILITHIUM_SIGNATURE_SIZE,
118
+ DILITHIUM_ALGORITHM,
119
+ } from './crypto/dilithium';
120
+
121
+ export type {
122
+ DilithiumKeypair,
123
+ DilithiumKeypairB64,
124
+ DilithiumSignature,
125
+ } from './crypto/dilithium';
126
+
127
+ // ═══════════════════════════════════════════════════════════════════════════
128
+ // VAULT MANAGEMENT (@stable)
129
+ // ═══════════════════════════════════════════════════════════════════════════
130
+
131
+ /**
132
+ * @stable Vault creation, encryption, and decryption.
133
+ * Core vault operations for identity management.
134
+ */
135
+ export {
136
+ createEmptyVault,
137
+ createIdentity,
138
+ addIdentity,
139
+ encryptVault,
140
+ decryptVault,
141
+ } from './vault';
142
+
143
+ export type {
144
+ OmnituumVault,
145
+ EncryptedVaultFile,
146
+ HybridIdentityRecord,
147
+ } from './vault';
148
+
149
+ // ═══════════════════════════════════════════════════════════════════════════
150
+ // VAULT MIGRATION (@stable)
151
+ // ═══════════════════════════════════════════════════════════════════════════
152
+
153
+ /**
154
+ * @stable Migration from PBKDF2 (v1) to Argon2id (v2) vaults.
155
+ */
156
+ export {
157
+ needsMigration,
158
+ migrateEncryptedVault,
159
+ getVaultKdfInfo,
160
+ isV2Vault,
161
+ } from './vault';
162
+
163
+ export type {
164
+ MigrationOptions,
165
+ MigrationResult,
166
+ } from './vault';
167
+
168
+ // ═══════════════════════════════════════════════════════════════════════════
169
+ // INTEGRITY UTILITIES (@stable)
170
+ // ═══════════════════════════════════════════════════════════════════════════
171
+
172
+ /**
173
+ * @stable Integrity hashing and key fingerprinting.
174
+ */
175
+ export {
176
+ computeIntegrityHash,
177
+ computeKeyFingerprint,
178
+ } from './utils';
179
+
180
+ // ═══════════════════════════════════════════════════════════════════════════
181
+ // KEY DERIVATION (@stable)
182
+ // ═══════════════════════════════════════════════════════════════════════════
183
+
184
+ /**
185
+ * @stable Password-based key derivation (PBKDF2 and Argon2id).
186
+ */
187
+ export {
188
+ getRecommendedConfig,
189
+ benchmarkKDF,
190
+ kdfDeriveKey,
191
+ generateSalt,
192
+ KDF_CONFIG_ARGON2ID,
193
+ KDF_CONFIG_PBKDF2,
194
+ } from './kdf';
195
+
196
+ export type {
197
+ KDFConfig,
198
+ KDFAlgorithm,
199
+ } from './kdf';
200
+
201
+ // ═══════════════════════════════════════════════════════════════════════════
202
+ // SECURITY UTILITIES (@stable)
203
+ // ═══════════════════════════════════════════════════════════════════════════
204
+
205
+ /**
206
+ * @stable Memory hygiene, secure sessions, and sensitive data handling.
207
+ */
208
+ export {
209
+ SecureBuffer,
210
+ withSecureData,
211
+ zeroMemory,
212
+ zeroAll,
213
+ constantTimeEqual,
214
+ createSession,
215
+ unlockSecureSession,
216
+ lockSecureSession,
217
+ isSessionTimedOut,
218
+ } from './security';
219
+
220
+ export type {
221
+ SecureSession,
222
+ UnlockReason,
223
+ } from './security';
224
+
225
+ // ═══════════════════════════════════════════════════════════════════════════
226
+ // PRIMITIVES - BLAKE3 (@stable)
227
+ // ═══════════════════════════════════════════════════════════════════════════
228
+
229
+ /**
230
+ * @stable BLAKE3 hash function for transcripts and commitments.
231
+ */
232
+ export {
233
+ blake3,
234
+ blake3Hex,
235
+ blake3Mac,
236
+ blake3DeriveKey,
237
+ BLAKE3_OUTPUT_LENGTH,
238
+ } from './crypto/primitives/blake3';
239
+
240
+ // ═══════════════════════════════════════════════════════════════════════════
241
+ // PRIMITIVES - CHACHA20-POLY1305 (@stable)
242
+ // ═══════════════════════════════════════════════════════════════════════════
243
+
244
+ /**
245
+ * @stable AEAD encryption primitives (ChaCha20-Poly1305, XChaCha20-Poly1305).
246
+ */
247
+ export {
248
+ chaCha20Poly1305Encrypt,
249
+ chaCha20Poly1305Decrypt,
250
+ xChaCha20Poly1305Encrypt,
251
+ xChaCha20Poly1305Decrypt,
252
+ createXChaCha20Poly1305,
253
+ createChaCha20Poly1305,
254
+ CHACHA20_KEY_SIZE,
255
+ XCHACHA20_NONCE_SIZE,
256
+ POLY1305_TAG_SIZE,
257
+ } from './crypto/primitives/chacha';
258
+
259
+ // ═══════════════════════════════════════════════════════════════════════════
260
+ // PRIMITIVES - HKDF (@stable for basic, @experimental for Noise helpers)
261
+ // ═══════════════════════════════════════════════════════════════════════════
262
+
263
+ /**
264
+ * @stable HKDF key derivation (RFC 5869).
265
+ */
266
+ export {
267
+ hkdfDerive,
268
+ hkdfExtract,
269
+ hkdfExpand,
270
+ } from './crypto/primitives/hkdf';
271
+
272
+ /**
273
+ * @experimental Noise protocol HKDF helpers.
274
+ * These may change as Noise integration evolves.
275
+ */
276
+ export {
277
+ hkdfSplitForNoise,
278
+ hkdfTripleSplitForNoise,
279
+ } from './crypto/primitives/hkdf';
280
+
281
+ // ═══════════════════════════════════════════════════════════════════════════
282
+ // PRIMITIVES - ENCODING (@stable)
283
+ // ═══════════════════════════════════════════════════════════════════════════
284
+
285
+ /**
286
+ * @stable Encoding utilities (Base64, Hex).
287
+ */
288
+ export {
289
+ // Text encoding
290
+ textEncoder,
291
+ textDecoder,
292
+
293
+ // Base64
294
+ toB64,
295
+ fromB64,
296
+ b64,
297
+ ub64,
298
+
299
+ // Hex
300
+ toHex,
301
+ fromHex,
302
+
303
+ // Validation
304
+ assertLen,
305
+
306
+ // Randomness
307
+ rand32,
308
+ rand24,
309
+ rand12,
310
+ randN,
311
+
312
+ // Hashing
313
+ sha256,
314
+ sha256String,
315
+
316
+ // Key derivation
317
+ hkdfSha256,
318
+
319
+ // Utility
320
+ u8,
321
+ } from './crypto/primitives';
322
+
323
+ // ═══════════════════════════════════════════════════════════════════════════
324
+ // PRIMITIVES - NACL SECRETBOX (@stable)
325
+ // ═══════════════════════════════════════════════════════════════════════════
326
+
327
+ /**
328
+ * @stable NaCl secretbox symmetric encryption.
329
+ */
330
+ export {
331
+ secretboxEncrypt,
332
+ secretboxDecrypt,
333
+ secretboxEncryptString,
334
+ secretboxDecryptString,
335
+ secretboxRaw,
336
+ secretboxOpenRaw,
337
+ SECRETBOX_KEY_SIZE,
338
+ SECRETBOX_NONCE_SIZE,
339
+ SECRETBOX_OVERHEAD,
340
+ } from './crypto/nacl';
341
+
342
+ export type { SecretboxPayload } from './crypto/nacl';
343
+
344
+ /**
345
+ * @stable NaCl box authenticated public-key encryption.
346
+ */
347
+ export {
348
+ boxEncrypt,
349
+ boxDecrypt,
350
+ BOX_KEY_SIZE,
351
+ BOX_NONCE_SIZE,
352
+ } from './crypto/nacl';
353
+
354
+ export type { BoxPayload } from './crypto/nacl';
355
+
356
+ // ═══════════════════════════════════════════════════════════════════════════
357
+ // VERSION CONSTANTS (@stable)
358
+ // ═══════════════════════════════════════════════════════════════════════════
359
+
360
+ export {
361
+ VAULT_VERSION,
362
+ VAULT_ENCRYPTED_VERSION,
363
+ VAULT_ENCRYPTED_VERSION_V2,
364
+ ENVELOPE_VERSION,
365
+ ENVELOPE_SUITE,
366
+ ENVELOPE_AEAD,
367
+ VAULT_KDF,
368
+ VAULT_KDF_V2,
369
+ VAULT_ALGORITHM,
370
+ validateVault,
371
+ validateEnvelope,
372
+ validateEncryptedVault,
373
+ } from './version';
374
+
375
+ // ═══════════════════════════════════════════════════════════════════════════
376
+ // FILE ENCRYPTION (@stable)
377
+ // ═══════════════════════════════════════════════════════════════════════════
378
+
379
+ /**
380
+ * @stable Omnituum FS - file encryption with hybrid PQC.
381
+ */
382
+ export {
383
+ encryptFile,
384
+ decryptFile,
385
+ encryptFileWithPassword,
386
+ decryptFileWithPassword,
387
+ } from './fs';
388
+
389
+ export type {
390
+ OQEEncryptResult,
391
+ OQEDecryptResult,
392
+ EncryptOptions,
393
+ DecryptOptions,
394
+ } from './fs';
395
+
396
+ // ═══════════════════════════════════════════════════════════════════════════
397
+ // TUNNEL (@stable)
398
+ // ═══════════════════════════════════════════════════════════════════════════
399
+
400
+ /**
401
+ * @stable Post-handshake encrypted tunnel.
402
+ * Handshake-agnostic: accepts key material from any protocol.
403
+ */
404
+ export {
405
+ createTunnelSession,
406
+ TUNNEL_VERSION,
407
+ TUNNEL_KEY_SIZE,
408
+ TUNNEL_NONCE_SIZE,
409
+ } from './tunnel';
410
+
411
+ export type {
412
+ PQCTunnelSession,
413
+ TunnelKeyMaterial,
414
+ } from './tunnel';