@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,55 @@
1
+ /**
2
+ * Omnituum PQC Shared - Version Constants & Guards
3
+ *
4
+ * FROZEN CONTRACTS: These version strings define the wire format.
5
+ * Breaking changes require a version bump.
6
+ *
7
+ * @see pqc-docs/specs/envelope.v1.md
8
+ * @see pqc-docs/specs/vault.v1.md
9
+ * @see pqc-docs/specs/identity.v1.md
10
+ */
11
+ /** HybridEnvelope version - hybrid encryption format */
12
+ declare const ENVELOPE_VERSION: "omnituum.hybrid.v1";
13
+ /** OmnituumVault version - decrypted vault format */
14
+ declare const VAULT_VERSION: "omnituum.vault.v1";
15
+ /** EncryptedVaultFile version - encrypted vault format (PBKDF2) */
16
+ declare const VAULT_ENCRYPTED_VERSION: "omnituum.vault.enc.v1";
17
+ /** EncryptedVaultFile v2 - encrypted vault format (Argon2id) */
18
+ declare const VAULT_ENCRYPTED_VERSION_V2: "omnituum.vault.enc.v2";
19
+ /** Algorithm suite for hybrid encryption */
20
+ declare const ENVELOPE_SUITE: "x25519+kyber768";
21
+ /** AEAD algorithm for envelope content */
22
+ declare const ENVELOPE_AEAD: "xsalsa20poly1305";
23
+ /** KDF for vault encryption (v1) */
24
+ declare const VAULT_KDF: "PBKDF2-SHA256";
25
+ /** KDF for vault encryption (v2) */
26
+ declare const VAULT_KDF_V2: "Argon2id";
27
+ /** Encryption algorithm for vault */
28
+ declare const VAULT_ALGORITHM: "AES-256-GCM";
29
+ /**
30
+ * Validate envelope structure and version.
31
+ * Returns detailed validation result.
32
+ */
33
+ declare function validateEnvelope(envelope: unknown): {
34
+ valid: boolean;
35
+ version?: string;
36
+ errors: string[];
37
+ };
38
+ /**
39
+ * Validate vault structure and version.
40
+ */
41
+ declare function validateVault(vault: unknown): {
42
+ valid: boolean;
43
+ version?: string;
44
+ errors: string[];
45
+ };
46
+ /**
47
+ * Validate encrypted vault structure and version.
48
+ */
49
+ declare function validateEncryptedVault(encVault: unknown): {
50
+ valid: boolean;
51
+ version?: string;
52
+ errors: string[];
53
+ };
54
+
55
+ export { ENVELOPE_VERSION as E, VAULT_VERSION as V, VAULT_ENCRYPTED_VERSION as a, VAULT_KDF as b, VAULT_ALGORITHM as c, VAULT_ENCRYPTED_VERSION_V2 as d, VAULT_KDF_V2 as e, ENVELOPE_SUITE as f, ENVELOPE_AEAD as g, validateEnvelope as h, validateEncryptedVault as i, validateVault as v };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Omnituum PQC Shared - Version Constants & Guards
3
+ *
4
+ * FROZEN CONTRACTS: These version strings define the wire format.
5
+ * Breaking changes require a version bump.
6
+ *
7
+ * @see pqc-docs/specs/envelope.v1.md
8
+ * @see pqc-docs/specs/vault.v1.md
9
+ * @see pqc-docs/specs/identity.v1.md
10
+ */
11
+ /** HybridEnvelope version - hybrid encryption format */
12
+ declare const ENVELOPE_VERSION: "omnituum.hybrid.v1";
13
+ /** OmnituumVault version - decrypted vault format */
14
+ declare const VAULT_VERSION: "omnituum.vault.v1";
15
+ /** EncryptedVaultFile version - encrypted vault format (PBKDF2) */
16
+ declare const VAULT_ENCRYPTED_VERSION: "omnituum.vault.enc.v1";
17
+ /** EncryptedVaultFile v2 - encrypted vault format (Argon2id) */
18
+ declare const VAULT_ENCRYPTED_VERSION_V2: "omnituum.vault.enc.v2";
19
+ /** Algorithm suite for hybrid encryption */
20
+ declare const ENVELOPE_SUITE: "x25519+kyber768";
21
+ /** AEAD algorithm for envelope content */
22
+ declare const ENVELOPE_AEAD: "xsalsa20poly1305";
23
+ /** KDF for vault encryption (v1) */
24
+ declare const VAULT_KDF: "PBKDF2-SHA256";
25
+ /** KDF for vault encryption (v2) */
26
+ declare const VAULT_KDF_V2: "Argon2id";
27
+ /** Encryption algorithm for vault */
28
+ declare const VAULT_ALGORITHM: "AES-256-GCM";
29
+ /**
30
+ * Validate envelope structure and version.
31
+ * Returns detailed validation result.
32
+ */
33
+ declare function validateEnvelope(envelope: unknown): {
34
+ valid: boolean;
35
+ version?: string;
36
+ errors: string[];
37
+ };
38
+ /**
39
+ * Validate vault structure and version.
40
+ */
41
+ declare function validateVault(vault: unknown): {
42
+ valid: boolean;
43
+ version?: string;
44
+ errors: string[];
45
+ };
46
+ /**
47
+ * Validate encrypted vault structure and version.
48
+ */
49
+ declare function validateEncryptedVault(encVault: unknown): {
50
+ valid: boolean;
51
+ version?: string;
52
+ errors: string[];
53
+ };
54
+
55
+ export { ENVELOPE_VERSION as E, VAULT_VERSION as V, VAULT_ENCRYPTED_VERSION as a, VAULT_KDF as b, VAULT_ALGORITHM as c, VAULT_ENCRYPTED_VERSION_V2 as d, VAULT_KDF_V2 as e, ENVELOPE_SUITE as f, ENVELOPE_AEAD as g, validateEnvelope as h, validateEncryptedVault as i, validateVault as v };
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@omnituum/pqc-shared",
3
+ "version": "0.2.6",
4
+ "description": "Omnituum PQC Shared Library - Crypto, Vault, File Encryption, and Utilities",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./crypto": {
16
+ "types": "./dist/crypto/index.d.ts",
17
+ "import": "./dist/crypto/index.js",
18
+ "require": "./dist/crypto/index.cjs"
19
+ },
20
+ "./vault": {
21
+ "types": "./dist/vault/index.d.ts",
22
+ "import": "./dist/vault/index.js",
23
+ "require": "./dist/vault/index.cjs"
24
+ },
25
+ "./utils": {
26
+ "types": "./dist/utils/index.d.ts",
27
+ "import": "./dist/utils/index.js",
28
+ "require": "./dist/utils/index.cjs"
29
+ },
30
+ "./fs": {
31
+ "types": "./dist/fs/index.d.ts",
32
+ "import": "./dist/fs/index.js",
33
+ "require": "./dist/fs/index.cjs"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "src"
39
+ ],
40
+ "dependencies": {
41
+ "@noble/ciphers": "^0.5.3",
42
+ "@noble/hashes": "^1.8.0",
43
+ "@noble/post-quantum": "^0.2.1",
44
+ "hash-wasm": "^4.11.0",
45
+ "kyber-crystals": "^1.0.7",
46
+ "tweetnacl": "^1.0.3"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^25.0.9",
50
+ "tsup": "^8.5.0",
51
+ "tsx": "^4.19.0",
52
+ "typescript": "^5.9.3"
53
+ },
54
+ "keywords": [
55
+ "pqc",
56
+ "post-quantum",
57
+ "cryptography",
58
+ "kyber",
59
+ "x25519",
60
+ "hybrid-encryption",
61
+ "vault",
62
+ "file-encryption",
63
+ "argon2",
64
+ "aes-gcm"
65
+ ],
66
+ "author": "Omnituum",
67
+ "license": "MIT",
68
+ "repository": {
69
+ "type": "git",
70
+ "url": "https://github.com/Omnituum/pqc-shared.git"
71
+ },
72
+ "bugs": {
73
+ "url": "https://github.com/Omnituum/pqc-shared/issues"
74
+ },
75
+ "homepage": "https://github.com/Omnituum/pqc-shared#readme",
76
+ "scripts": {
77
+ "build": "tsup",
78
+ "dev": "tsup --watch",
79
+ "clean": "rm -rf dist",
80
+ "typecheck": "tsc --noEmit",
81
+ "test:golden:generate": "pnpm -s build && tsx tests/golden/generate-vectors.ts",
82
+ "test:golden:verify": "pnpm -s build && tsx tests/golden/verify-vectors.ts",
83
+ "test:golden": "npm run test:golden:verify",
84
+ "pretest": "npm run build"
85
+ }
86
+ }
@@ -0,0 +1,233 @@
1
+ /**
2
+ * Omnituum PQC Shared - Dilithium ML-DSA-65 Signatures
3
+ *
4
+ * Post-quantum digital signatures using ML-DSA-65 (formerly CRYSTALS-Dilithium).
5
+ * NIST Level 3 security - quantum-resistant.
6
+ *
7
+ * Uses @noble/post-quantum for browser-compatible implementation.
8
+ */
9
+
10
+ import { toB64, fromB64, sha256, randN } from './primitives';
11
+
12
+ // ═══════════════════════════════════════════════════════════════════════════
13
+ // TYPES
14
+ // ═══════════════════════════════════════════════════════════════════════════
15
+
16
+ export interface DilithiumKeypair {
17
+ publicKey: Uint8Array;
18
+ secretKey: Uint8Array;
19
+ }
20
+
21
+ export interface DilithiumKeypairB64 {
22
+ publicB64: string;
23
+ secretB64: string;
24
+ }
25
+
26
+ export interface DilithiumSignature {
27
+ /** Signature (base64) */
28
+ signature: string;
29
+ /** Algorithm identifier */
30
+ algorithm: 'ML-DSA-65';
31
+ }
32
+
33
+ // ═══════════════════════════════════════════════════════════════════════════
34
+ // LIBRARY LOADING
35
+ // ═══════════════════════════════════════════════════════════════════════════
36
+
37
+ let dilithiumModule: any = null;
38
+
39
+ async function loadDilithium(): Promise<any> {
40
+ if (dilithiumModule) return dilithiumModule;
41
+
42
+ try {
43
+ // @noble/post-quantum provides ml-dsa
44
+ const { ml_dsa65 } = await import('@noble/post-quantum/ml-dsa');
45
+ dilithiumModule = ml_dsa65;
46
+ return dilithiumModule;
47
+ } catch (e) {
48
+ console.warn('[Dilithium] Failed to load @noble/post-quantum:', e);
49
+ return null;
50
+ }
51
+ }
52
+
53
+ // ═══════════════════════════════════════════════════════════════════════════
54
+ // AVAILABILITY CHECK
55
+ // ═══════════════════════════════════════════════════════════════════════════
56
+
57
+ export async function isDilithiumAvailable(): Promise<boolean> {
58
+ const mod = await loadDilithium();
59
+ return mod !== null;
60
+ }
61
+
62
+ // ═══════════════════════════════════════════════════════════════════════════
63
+ // KEY GENERATION
64
+ // ═══════════════════════════════════════════════════════════════════════════
65
+
66
+ /**
67
+ * Generate a Dilithium ML-DSA-65 keypair.
68
+ *
69
+ * @returns Keypair with base64-encoded keys, or null if unavailable
70
+ */
71
+ export async function generateDilithiumKeypair(): Promise<DilithiumKeypairB64 | null> {
72
+ try {
73
+ const mod = await loadDilithium();
74
+ if (!mod) return null;
75
+
76
+ // Generate random seed
77
+ const seed = randN(32);
78
+
79
+ // Generate keypair from seed for determinism
80
+ const kp = mod.keygen(seed);
81
+
82
+ return {
83
+ publicB64: toB64(kp.publicKey),
84
+ secretB64: toB64(kp.secretKey),
85
+ };
86
+ } catch (e) {
87
+ console.warn('[Dilithium] Key generation failed:', e);
88
+ return null;
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Generate a deterministic Dilithium keypair from a seed.
94
+ *
95
+ * @param seed - 32-byte seed
96
+ * @returns Keypair
97
+ */
98
+ export async function generateDilithiumKeypairFromSeed(
99
+ seed: Uint8Array
100
+ ): Promise<DilithiumKeypair> {
101
+ const mod = await loadDilithium();
102
+ if (!mod) {
103
+ throw new Error('Dilithium library not available');
104
+ }
105
+
106
+ if (seed.length !== 32) {
107
+ throw new Error('Dilithium seed must be 32 bytes');
108
+ }
109
+
110
+ // Hash seed for uniformity
111
+ const uniformSeed = sha256(seed);
112
+ const kp = mod.keygen(uniformSeed);
113
+
114
+ return {
115
+ publicKey: kp.publicKey,
116
+ secretKey: kp.secretKey,
117
+ };
118
+ }
119
+
120
+ // ═══════════════════════════════════════════════════════════════════════════
121
+ // SIGNING
122
+ // ═══════════════════════════════════════════════════════════════════════════
123
+
124
+ /**
125
+ * Sign a message using Dilithium ML-DSA-65.
126
+ *
127
+ * @param message - Message to sign (Uint8Array or string)
128
+ * @param secretKeyB64 - Secret key (base64)
129
+ * @returns Signature object
130
+ */
131
+ export async function dilithiumSign(
132
+ message: Uint8Array | string,
133
+ secretKeyB64: string
134
+ ): Promise<DilithiumSignature> {
135
+ const mod = await loadDilithium();
136
+ if (!mod) {
137
+ throw new Error('Dilithium library not available');
138
+ }
139
+
140
+ const sk = fromB64(secretKeyB64);
141
+ const msg = typeof message === 'string' ? new TextEncoder().encode(message) : message;
142
+
143
+ const signature = mod.sign(sk, msg);
144
+
145
+ return {
146
+ signature: toB64(signature),
147
+ algorithm: 'ML-DSA-65',
148
+ };
149
+ }
150
+
151
+ /**
152
+ * Sign raw bytes (returns raw signature).
153
+ */
154
+ export async function dilithiumSignRaw(
155
+ message: Uint8Array,
156
+ secretKey: Uint8Array
157
+ ): Promise<Uint8Array> {
158
+ const mod = await loadDilithium();
159
+ if (!mod) {
160
+ throw new Error('Dilithium library not available');
161
+ }
162
+
163
+ return mod.sign(secretKey, message);
164
+ }
165
+
166
+ // ═══════════════════════════════════════════════════════════════════════════
167
+ // VERIFICATION
168
+ // ═══════════════════════════════════════════════════════════════════════════
169
+
170
+ /**
171
+ * Verify a Dilithium signature.
172
+ *
173
+ * @param message - Original message
174
+ * @param signatureB64 - Signature (base64)
175
+ * @param publicKeyB64 - Public key (base64)
176
+ * @returns true if signature is valid
177
+ */
178
+ export async function dilithiumVerify(
179
+ message: Uint8Array | string,
180
+ signatureB64: string,
181
+ publicKeyB64: string
182
+ ): Promise<boolean> {
183
+ const mod = await loadDilithium();
184
+ if (!mod) {
185
+ throw new Error('Dilithium library not available');
186
+ }
187
+
188
+ const pk = fromB64(publicKeyB64);
189
+ const sig = fromB64(signatureB64);
190
+ const msg = typeof message === 'string' ? new TextEncoder().encode(message) : message;
191
+
192
+ try {
193
+ return mod.verify(pk, msg, sig);
194
+ } catch {
195
+ return false;
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Verify raw signature bytes.
201
+ */
202
+ export async function dilithiumVerifyRaw(
203
+ message: Uint8Array,
204
+ signature: Uint8Array,
205
+ publicKey: Uint8Array
206
+ ): Promise<boolean> {
207
+ const mod = await loadDilithium();
208
+ if (!mod) {
209
+ throw new Error('Dilithium library not available');
210
+ }
211
+
212
+ try {
213
+ return mod.verify(publicKey, message, signature);
214
+ } catch {
215
+ return false;
216
+ }
217
+ }
218
+
219
+ // ═══════════════════════════════════════════════════════════════════════════
220
+ // CONSTANTS
221
+ // ═══════════════════════════════════════════════════════════════════════════
222
+
223
+ /** ML-DSA-65 public key size */
224
+ export const DILITHIUM_PUBLIC_KEY_SIZE = 1952;
225
+
226
+ /** ML-DSA-65 secret key size */
227
+ export const DILITHIUM_SECRET_KEY_SIZE = 4032;
228
+
229
+ /** ML-DSA-65 signature size */
230
+ export const DILITHIUM_SIGNATURE_SIZE = 3309;
231
+
232
+ /** Algorithm identifier */
233
+ export const DILITHIUM_ALGORITHM = 'ML-DSA-65';