@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.
- package/LICENSE +22 -0
- package/README.md +543 -0
- package/dist/crypto/index.cjs +807 -0
- package/dist/crypto/index.d.cts +641 -0
- package/dist/crypto/index.d.ts +641 -0
- package/dist/crypto/index.js +716 -0
- package/dist/decrypt-eSHlbh1j.d.cts +321 -0
- package/dist/decrypt-eSHlbh1j.d.ts +321 -0
- package/dist/fs/index.cjs +1168 -0
- package/dist/fs/index.d.cts +400 -0
- package/dist/fs/index.d.ts +400 -0
- package/dist/fs/index.js +1091 -0
- package/dist/index.cjs +2160 -0
- package/dist/index.d.cts +282 -0
- package/dist/index.d.ts +282 -0
- package/dist/index.js +2031 -0
- package/dist/integrity-CCYjrap3.d.ts +31 -0
- package/dist/integrity-Dx9jukMH.d.cts +31 -0
- package/dist/types-61c7Q9ri.d.ts +134 -0
- package/dist/types-Ch0y-n7K.d.cts +134 -0
- package/dist/utils/index.cjs +129 -0
- package/dist/utils/index.d.cts +49 -0
- package/dist/utils/index.d.ts +49 -0
- package/dist/utils/index.js +114 -0
- package/dist/vault/index.cjs +713 -0
- package/dist/vault/index.d.cts +237 -0
- package/dist/vault/index.d.ts +237 -0
- package/dist/vault/index.js +677 -0
- package/dist/version-BygzPVGs.d.cts +55 -0
- package/dist/version-BygzPVGs.d.ts +55 -0
- package/package.json +86 -0
- package/src/crypto/dilithium.ts +233 -0
- package/src/crypto/hybrid.ts +358 -0
- package/src/crypto/index.ts +181 -0
- package/src/crypto/kyber.ts +199 -0
- package/src/crypto/nacl.ts +204 -0
- package/src/crypto/primitives/blake3.ts +141 -0
- package/src/crypto/primitives/chacha.ts +211 -0
- package/src/crypto/primitives/hkdf.ts +192 -0
- package/src/crypto/primitives/index.ts +54 -0
- package/src/crypto/primitives.ts +144 -0
- package/src/crypto/x25519.ts +134 -0
- package/src/fs/aes.ts +343 -0
- package/src/fs/argon2.ts +184 -0
- package/src/fs/browser.ts +408 -0
- package/src/fs/decrypt.ts +320 -0
- package/src/fs/encrypt.ts +324 -0
- package/src/fs/format.ts +425 -0
- package/src/fs/index.ts +144 -0
- package/src/fs/types.ts +304 -0
- package/src/index.ts +414 -0
- package/src/kdf/index.ts +311 -0
- package/src/runtime/crypto.ts +16 -0
- package/src/security/index.ts +345 -0
- package/src/tunnel/index.ts +39 -0
- package/src/tunnel/session.ts +229 -0
- package/src/tunnel/types.ts +115 -0
- package/src/utils/entropy.ts +128 -0
- package/src/utils/index.ts +25 -0
- package/src/utils/integrity.ts +95 -0
- package/src/vault/decrypt.ts +167 -0
- package/src/vault/encrypt.ts +207 -0
- package/src/vault/index.ts +71 -0
- package/src/vault/manager.ts +327 -0
- package/src/vault/migrate.ts +190 -0
- package/src/vault/types.ts +177 -0
- package/src/version.ts +304 -0
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import { E as ENVELOPE_VERSION, f as ENVELOPE_SUITE, g as ENVELOPE_AEAD } from '../version-BygzPVGs.js';
|
|
2
|
+
import * as _noble_ciphers_utils from '@noble/ciphers/utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Omnituum PQC Shared - Kyber ML-KEM-768
|
|
6
|
+
*
|
|
7
|
+
* Browser-compatible Kyber operations using kyber-crystals.
|
|
8
|
+
* NIST Level 3 security - quantum-resistant.
|
|
9
|
+
*/
|
|
10
|
+
interface KyberKeypair {
|
|
11
|
+
publicKey: Uint8Array;
|
|
12
|
+
secretKey: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
interface KyberKeypairB64 {
|
|
15
|
+
publicB64: string;
|
|
16
|
+
secretB64: string;
|
|
17
|
+
}
|
|
18
|
+
interface KyberEncapsulation {
|
|
19
|
+
ciphertext: Uint8Array;
|
|
20
|
+
sharedSecret: Uint8Array;
|
|
21
|
+
}
|
|
22
|
+
declare function isKyberAvailable(): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Generate a Kyber ML-KEM-768 keypair.
|
|
25
|
+
*/
|
|
26
|
+
declare function generateKyberKeypair(): Promise<KyberKeypairB64 | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Encapsulate a shared secret using Kyber ML-KEM-768.
|
|
29
|
+
*/
|
|
30
|
+
declare function kyberEncapsulate(pubKeyB64: string): Promise<KyberEncapsulation>;
|
|
31
|
+
/**
|
|
32
|
+
* Decapsulate a shared secret using Kyber ML-KEM-768.
|
|
33
|
+
*/
|
|
34
|
+
declare function kyberDecapsulate(kemCiphertextB64: string, secretKeyB64: string): Promise<Uint8Array>;
|
|
35
|
+
/**
|
|
36
|
+
* Wrap a message key using Kyber shared secret.
|
|
37
|
+
*/
|
|
38
|
+
declare function kyberWrapKey(sharedSecret: Uint8Array, msgKey32: Uint8Array): {
|
|
39
|
+
nonce: string;
|
|
40
|
+
wrapped: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Unwrap a message key using Kyber shared secret.
|
|
44
|
+
*/
|
|
45
|
+
declare function kyberUnwrapKey(sharedSecret: Uint8Array, nonceB64: string, wrappedB64: string): Uint8Array | null;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Omnituum PQC Shared - Hybrid Encryption
|
|
49
|
+
*
|
|
50
|
+
* Post-quantum secure hybrid encryption combining:
|
|
51
|
+
* - X25519 ECDH (classical, proven security)
|
|
52
|
+
* - Kyber ML-KEM-768 (post-quantum, NIST Level 3)
|
|
53
|
+
*
|
|
54
|
+
* Both key exchanges must succeed for decryption, providing
|
|
55
|
+
* security against both classical and quantum attacks.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
interface HybridIdentity {
|
|
59
|
+
/** Unique identifier */
|
|
60
|
+
id: string;
|
|
61
|
+
/** Display name */
|
|
62
|
+
name: string;
|
|
63
|
+
/** X25519 public key (hex) */
|
|
64
|
+
x25519PubHex: string;
|
|
65
|
+
/** X25519 secret key (hex) - keep private! */
|
|
66
|
+
x25519SecHex: string;
|
|
67
|
+
/** Kyber public key (base64) */
|
|
68
|
+
kyberPubB64: string;
|
|
69
|
+
/** Kyber secret key (base64) - keep private! */
|
|
70
|
+
kyberSecB64: string;
|
|
71
|
+
/** Creation timestamp */
|
|
72
|
+
createdAt: string;
|
|
73
|
+
/** Last rotation timestamp */
|
|
74
|
+
lastRotatedAt?: string;
|
|
75
|
+
/** Key rotation count */
|
|
76
|
+
rotationCount: number;
|
|
77
|
+
}
|
|
78
|
+
interface HybridPublicKeys {
|
|
79
|
+
/** X25519 public key (hex) */
|
|
80
|
+
x25519PubHex: string;
|
|
81
|
+
/** Kyber public key (base64) */
|
|
82
|
+
kyberPubB64: string;
|
|
83
|
+
}
|
|
84
|
+
interface HybridSecretKeys {
|
|
85
|
+
/** X25519 secret key (hex) */
|
|
86
|
+
x25519SecHex: string;
|
|
87
|
+
/** Kyber secret key (base64) */
|
|
88
|
+
kyberSecB64: string;
|
|
89
|
+
}
|
|
90
|
+
interface HybridEnvelope {
|
|
91
|
+
/** Version identifier (FROZEN - see pqc-docs/specs/envelope.v1.md) */
|
|
92
|
+
v: typeof ENVELOPE_VERSION;
|
|
93
|
+
/** Algorithm suite */
|
|
94
|
+
suite: typeof ENVELOPE_SUITE;
|
|
95
|
+
/** AEAD algorithm */
|
|
96
|
+
aead: typeof ENVELOPE_AEAD;
|
|
97
|
+
/** X25519 ephemeral public key (hex) */
|
|
98
|
+
x25519Epk: string;
|
|
99
|
+
/** X25519 wrapped content key */
|
|
100
|
+
x25519Wrap: {
|
|
101
|
+
nonce: string;
|
|
102
|
+
wrapped: string;
|
|
103
|
+
};
|
|
104
|
+
/** Kyber KEM ciphertext (base64) */
|
|
105
|
+
kyberKemCt: string;
|
|
106
|
+
/** Kyber wrapped content key */
|
|
107
|
+
kyberWrap: {
|
|
108
|
+
nonce: string;
|
|
109
|
+
wrapped: string;
|
|
110
|
+
};
|
|
111
|
+
/** Content encryption nonce (base64) */
|
|
112
|
+
contentNonce: string;
|
|
113
|
+
/** Encrypted content (base64) */
|
|
114
|
+
ciphertext: string;
|
|
115
|
+
/** Metadata */
|
|
116
|
+
meta: {
|
|
117
|
+
createdAt: string;
|
|
118
|
+
senderName?: string;
|
|
119
|
+
senderId?: string;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Generate a new hybrid identity with both X25519 and Kyber keys.
|
|
124
|
+
*/
|
|
125
|
+
declare function generateHybridIdentity(name: string): Promise<HybridIdentity | null>;
|
|
126
|
+
/**
|
|
127
|
+
* Rotate keys for an existing identity.
|
|
128
|
+
*/
|
|
129
|
+
declare function rotateHybridIdentity(identity: HybridIdentity): Promise<HybridIdentity | null>;
|
|
130
|
+
/**
|
|
131
|
+
* Extract public keys from identity.
|
|
132
|
+
*/
|
|
133
|
+
declare function getPublicKeys(identity: HybridIdentity): HybridPublicKeys;
|
|
134
|
+
/**
|
|
135
|
+
* Extract secret keys from identity.
|
|
136
|
+
*/
|
|
137
|
+
declare function getSecretKeys(identity: HybridIdentity): HybridSecretKeys;
|
|
138
|
+
/**
|
|
139
|
+
* Encrypt a message using hybrid X25519 + Kyber encryption.
|
|
140
|
+
*
|
|
141
|
+
* @param plaintext - Message to encrypt (string or bytes)
|
|
142
|
+
* @param recipientPublicKeys - Recipient's public keys
|
|
143
|
+
* @param sender - Optional sender identity for metadata
|
|
144
|
+
*/
|
|
145
|
+
declare function hybridEncrypt(plaintext: string | Uint8Array, recipientPublicKeys: HybridPublicKeys, sender?: {
|
|
146
|
+
name?: string;
|
|
147
|
+
id?: string;
|
|
148
|
+
}): Promise<HybridEnvelope>;
|
|
149
|
+
/**
|
|
150
|
+
* Decrypt a hybrid envelope.
|
|
151
|
+
*
|
|
152
|
+
* Tries Kyber first (post-quantum), falls back to X25519 (classical).
|
|
153
|
+
* Both must be valid for the envelope to be considered secure.
|
|
154
|
+
*
|
|
155
|
+
* @param envelope - Encrypted envelope
|
|
156
|
+
* @param secretKeys - Recipient's secret keys
|
|
157
|
+
* @returns Decrypted plaintext as bytes
|
|
158
|
+
*/
|
|
159
|
+
declare function hybridDecrypt(envelope: HybridEnvelope, secretKeys: HybridSecretKeys): Promise<Uint8Array>;
|
|
160
|
+
/**
|
|
161
|
+
* Decrypt and decode as UTF-8 string.
|
|
162
|
+
*/
|
|
163
|
+
declare function hybridDecryptToString(envelope: HybridEnvelope, secretKeys: HybridSecretKeys): Promise<string>;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Omnituum PQC Shared - X25519 Key Exchange
|
|
167
|
+
*
|
|
168
|
+
* Browser-compatible X25519 operations using tweetnacl.
|
|
169
|
+
* Provides key generation, ECDH, and NaCl box operations.
|
|
170
|
+
*/
|
|
171
|
+
interface X25519Keypair {
|
|
172
|
+
publicKey: Uint8Array;
|
|
173
|
+
secretKey: Uint8Array;
|
|
174
|
+
}
|
|
175
|
+
interface X25519KeypairHex {
|
|
176
|
+
publicHex: string;
|
|
177
|
+
secretHex: string;
|
|
178
|
+
publicBytes: Uint8Array;
|
|
179
|
+
secretBytes: Uint8Array;
|
|
180
|
+
}
|
|
181
|
+
interface ClassicalWrap {
|
|
182
|
+
ephPubKey: string;
|
|
183
|
+
nonce: string;
|
|
184
|
+
boxed: string;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Generate a new random X25519 keypair.
|
|
188
|
+
*/
|
|
189
|
+
declare function generateX25519Keypair(): X25519KeypairHex;
|
|
190
|
+
/**
|
|
191
|
+
* Generate a deterministic X25519 keypair from a 32-byte seed.
|
|
192
|
+
*/
|
|
193
|
+
declare function generateX25519KeypairFromSeed(seed: Uint8Array): X25519Keypair;
|
|
194
|
+
/**
|
|
195
|
+
* Wrap a symmetric key for a recipient using X25519 ECDH.
|
|
196
|
+
* Creates an ephemeral keypair and encrypts the key using NaCl box.
|
|
197
|
+
*/
|
|
198
|
+
declare function boxWrapWithX25519(symKey32: Uint8Array, recipientPubKeyHex: string): ClassicalWrap;
|
|
199
|
+
/**
|
|
200
|
+
* Unwrap a symmetric key using X25519 ECDH.
|
|
201
|
+
*/
|
|
202
|
+
declare function boxUnwrapWithX25519(wrap: ClassicalWrap, recipientSecretKey32: Uint8Array): Uint8Array | null;
|
|
203
|
+
/**
|
|
204
|
+
* Perform raw X25519 ECDH to derive a shared secret.
|
|
205
|
+
*/
|
|
206
|
+
declare function x25519SharedSecret(ourSecretKey: Uint8Array, theirPublicKey: Uint8Array): Uint8Array;
|
|
207
|
+
declare function deriveKeyFromShared(shared: Uint8Array, salt: string, info: string): Uint8Array;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Omnituum PQC Shared - Dilithium ML-DSA-65 Signatures
|
|
211
|
+
*
|
|
212
|
+
* Post-quantum digital signatures using ML-DSA-65 (formerly CRYSTALS-Dilithium).
|
|
213
|
+
* NIST Level 3 security - quantum-resistant.
|
|
214
|
+
*
|
|
215
|
+
* Uses @noble/post-quantum for browser-compatible implementation.
|
|
216
|
+
*/
|
|
217
|
+
interface DilithiumKeypair {
|
|
218
|
+
publicKey: Uint8Array;
|
|
219
|
+
secretKey: Uint8Array;
|
|
220
|
+
}
|
|
221
|
+
interface DilithiumKeypairB64 {
|
|
222
|
+
publicB64: string;
|
|
223
|
+
secretB64: string;
|
|
224
|
+
}
|
|
225
|
+
interface DilithiumSignature {
|
|
226
|
+
/** Signature (base64) */
|
|
227
|
+
signature: string;
|
|
228
|
+
/** Algorithm identifier */
|
|
229
|
+
algorithm: 'ML-DSA-65';
|
|
230
|
+
}
|
|
231
|
+
declare function isDilithiumAvailable(): Promise<boolean>;
|
|
232
|
+
/**
|
|
233
|
+
* Generate a Dilithium ML-DSA-65 keypair.
|
|
234
|
+
*
|
|
235
|
+
* @returns Keypair with base64-encoded keys, or null if unavailable
|
|
236
|
+
*/
|
|
237
|
+
declare function generateDilithiumKeypair(): Promise<DilithiumKeypairB64 | null>;
|
|
238
|
+
/**
|
|
239
|
+
* Generate a deterministic Dilithium keypair from a seed.
|
|
240
|
+
*
|
|
241
|
+
* @param seed - 32-byte seed
|
|
242
|
+
* @returns Keypair
|
|
243
|
+
*/
|
|
244
|
+
declare function generateDilithiumKeypairFromSeed(seed: Uint8Array): Promise<DilithiumKeypair>;
|
|
245
|
+
/**
|
|
246
|
+
* Sign a message using Dilithium ML-DSA-65.
|
|
247
|
+
*
|
|
248
|
+
* @param message - Message to sign (Uint8Array or string)
|
|
249
|
+
* @param secretKeyB64 - Secret key (base64)
|
|
250
|
+
* @returns Signature object
|
|
251
|
+
*/
|
|
252
|
+
declare function dilithiumSign(message: Uint8Array | string, secretKeyB64: string): Promise<DilithiumSignature>;
|
|
253
|
+
/**
|
|
254
|
+
* Sign raw bytes (returns raw signature).
|
|
255
|
+
*/
|
|
256
|
+
declare function dilithiumSignRaw(message: Uint8Array, secretKey: Uint8Array): Promise<Uint8Array>;
|
|
257
|
+
/**
|
|
258
|
+
* Verify a Dilithium signature.
|
|
259
|
+
*
|
|
260
|
+
* @param message - Original message
|
|
261
|
+
* @param signatureB64 - Signature (base64)
|
|
262
|
+
* @param publicKeyB64 - Public key (base64)
|
|
263
|
+
* @returns true if signature is valid
|
|
264
|
+
*/
|
|
265
|
+
declare function dilithiumVerify(message: Uint8Array | string, signatureB64: string, publicKeyB64: string): Promise<boolean>;
|
|
266
|
+
/**
|
|
267
|
+
* Verify raw signature bytes.
|
|
268
|
+
*/
|
|
269
|
+
declare function dilithiumVerifyRaw(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): Promise<boolean>;
|
|
270
|
+
/** ML-DSA-65 public key size */
|
|
271
|
+
declare const DILITHIUM_PUBLIC_KEY_SIZE = 1952;
|
|
272
|
+
/** ML-DSA-65 secret key size */
|
|
273
|
+
declare const DILITHIUM_SECRET_KEY_SIZE = 4032;
|
|
274
|
+
/** ML-DSA-65 signature size */
|
|
275
|
+
declare const DILITHIUM_SIGNATURE_SIZE = 3309;
|
|
276
|
+
/** Algorithm identifier */
|
|
277
|
+
declare const DILITHIUM_ALGORITHM = "ML-DSA-65";
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Omnituum PQC Shared - BLAKE3 Hash Primitive
|
|
281
|
+
*
|
|
282
|
+
* BLAKE3 is a cryptographic hash function that provides:
|
|
283
|
+
* - Fast performance (faster than SHA-256, SHA-3)
|
|
284
|
+
* - 256-bit security (collision resistance)
|
|
285
|
+
* - Variable output length (default 32 bytes)
|
|
286
|
+
*
|
|
287
|
+
* Used in Noise protocols for transcript hashing.
|
|
288
|
+
*/
|
|
289
|
+
interface Blake3Options {
|
|
290
|
+
/** Output length in bytes (default: 32) */
|
|
291
|
+
outputLength?: number;
|
|
292
|
+
/** Optional key for keyed hashing (32 bytes) */
|
|
293
|
+
key?: Uint8Array;
|
|
294
|
+
/** Optional context string for domain separation */
|
|
295
|
+
context?: string;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Compute BLAKE3 hash of input data.
|
|
299
|
+
*
|
|
300
|
+
* @param data - Data to hash (Uint8Array or string)
|
|
301
|
+
* @param options - Optional configuration
|
|
302
|
+
* @returns BLAKE3 hash (default 32 bytes)
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts
|
|
306
|
+
* // Simple hash
|
|
307
|
+
* const hash = blake3(new Uint8Array([1, 2, 3]));
|
|
308
|
+
*
|
|
309
|
+
* // Hash with context (domain separation)
|
|
310
|
+
* const hash = blake3(data, { context: 'MyApp v1.0 signing' });
|
|
311
|
+
*
|
|
312
|
+
* // Keyed hash (requires 32-byte key)
|
|
313
|
+
* const hash = blake3(data, { key: keyBytes });
|
|
314
|
+
*
|
|
315
|
+
* // Variable output length
|
|
316
|
+
* const hash = blake3(data, { outputLength: 64 });
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
declare function blake3(data: Uint8Array | string, options?: Blake3Options): Uint8Array;
|
|
320
|
+
/**
|
|
321
|
+
* Compute BLAKE3 hash and return as hex string.
|
|
322
|
+
*/
|
|
323
|
+
declare function blake3Hex(data: Uint8Array | string, options?: Blake3Options): string;
|
|
324
|
+
/**
|
|
325
|
+
* Create a keyed BLAKE3 hash (MAC).
|
|
326
|
+
*
|
|
327
|
+
* @param key - 32-byte key
|
|
328
|
+
* @param data - Data to hash
|
|
329
|
+
* @returns BLAKE3-MAC (32 bytes by default)
|
|
330
|
+
*/
|
|
331
|
+
declare function blake3Mac(key: Uint8Array, data: Uint8Array, outputLength?: number): Uint8Array;
|
|
332
|
+
/**
|
|
333
|
+
* Derive a key from a context and key material using BLAKE3.
|
|
334
|
+
* This uses BLAKE3's built-in KDF mode.
|
|
335
|
+
*
|
|
336
|
+
* @param context - Domain separation string
|
|
337
|
+
* @param keyMaterial - Input key material
|
|
338
|
+
* @param outputLength - Desired output length (default 32)
|
|
339
|
+
* @returns Derived key
|
|
340
|
+
*/
|
|
341
|
+
declare function blake3DeriveKey(context: string, keyMaterial: Uint8Array, outputLength?: number): Uint8Array;
|
|
342
|
+
/** Default BLAKE3 output length (32 bytes = 256 bits) */
|
|
343
|
+
declare const BLAKE3_OUTPUT_LENGTH = 32;
|
|
344
|
+
/** BLAKE3 key length for keyed mode (32 bytes) */
|
|
345
|
+
declare const BLAKE3_KEY_LENGTH = 32;
|
|
346
|
+
/** BLAKE3 block size (64 bytes) */
|
|
347
|
+
declare const BLAKE3_BLOCK_SIZE = 64;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Omnituum PQC Shared - ChaCha20-Poly1305 Primitives
|
|
351
|
+
*
|
|
352
|
+
* AEAD ciphers for authenticated encryption:
|
|
353
|
+
* - ChaCha20-Poly1305: Standard AEAD (12-byte nonce)
|
|
354
|
+
* - XChaCha20-Poly1305: Extended nonce variant (24-byte nonce)
|
|
355
|
+
*
|
|
356
|
+
* Used in Noise protocols and general-purpose encryption.
|
|
357
|
+
*/
|
|
358
|
+
interface ChaChaPayload {
|
|
359
|
+
/** Nonce (12 bytes for standard, 24 bytes for xchacha) */
|
|
360
|
+
nonce: Uint8Array;
|
|
361
|
+
/** Ciphertext with Poly1305 tag (16 bytes appended) */
|
|
362
|
+
ciphertext: Uint8Array;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Encrypt using ChaCha20-Poly1305.
|
|
366
|
+
*
|
|
367
|
+
* @param key - 32-byte encryption key
|
|
368
|
+
* @param nonce - 12-byte nonce (must be unique per key)
|
|
369
|
+
* @param plaintext - Data to encrypt
|
|
370
|
+
* @param aad - Optional additional authenticated data
|
|
371
|
+
* @returns Ciphertext with Poly1305 tag appended
|
|
372
|
+
*/
|
|
373
|
+
declare function chaCha20Poly1305Encrypt(key: Uint8Array, nonce: Uint8Array, plaintext: Uint8Array, aad?: Uint8Array): Uint8Array;
|
|
374
|
+
/**
|
|
375
|
+
* Decrypt using ChaCha20-Poly1305.
|
|
376
|
+
*
|
|
377
|
+
* @param key - 32-byte encryption key
|
|
378
|
+
* @param nonce - 12-byte nonce
|
|
379
|
+
* @param ciphertext - Ciphertext with Poly1305 tag
|
|
380
|
+
* @param aad - Optional additional authenticated data
|
|
381
|
+
* @returns Plaintext, or null if authentication fails
|
|
382
|
+
*/
|
|
383
|
+
declare function chaCha20Poly1305Decrypt(key: Uint8Array, nonce: Uint8Array, ciphertext: Uint8Array, aad?: Uint8Array): Uint8Array | null;
|
|
384
|
+
/**
|
|
385
|
+
* Encrypt using XChaCha20-Poly1305 (extended 24-byte nonce).
|
|
386
|
+
*
|
|
387
|
+
* XChaCha20-Poly1305 is preferred for most applications because:
|
|
388
|
+
* - 24-byte nonce can be safely generated randomly
|
|
389
|
+
* - No nonce collision risk with ~2^80 messages per key
|
|
390
|
+
*
|
|
391
|
+
* @param key - 32-byte encryption key
|
|
392
|
+
* @param nonce - 24-byte nonce (can be random)
|
|
393
|
+
* @param plaintext - Data to encrypt
|
|
394
|
+
* @param aad - Optional additional authenticated data
|
|
395
|
+
* @returns Ciphertext with Poly1305 tag appended
|
|
396
|
+
*/
|
|
397
|
+
declare function xChaCha20Poly1305Encrypt(key: Uint8Array, nonce: Uint8Array, plaintext: Uint8Array, aad?: Uint8Array): Uint8Array;
|
|
398
|
+
/**
|
|
399
|
+
* Decrypt using XChaCha20-Poly1305.
|
|
400
|
+
*
|
|
401
|
+
* @param key - 32-byte encryption key
|
|
402
|
+
* @param nonce - 24-byte nonce
|
|
403
|
+
* @param ciphertext - Ciphertext with Poly1305 tag
|
|
404
|
+
* @param aad - Optional additional authenticated data
|
|
405
|
+
* @returns Plaintext, or null if authentication fails
|
|
406
|
+
*/
|
|
407
|
+
declare function xChaCha20Poly1305Decrypt(key: Uint8Array, nonce: Uint8Array, ciphertext: Uint8Array, aad?: Uint8Array): Uint8Array | null;
|
|
408
|
+
/**
|
|
409
|
+
* Create an XChaCha20-Poly1305 cipher instance.
|
|
410
|
+
* Compatible with @noble/ciphers API used in noise-kyber.
|
|
411
|
+
*
|
|
412
|
+
* @param key - 32-byte encryption key
|
|
413
|
+
* @param nonce - 24-byte nonce
|
|
414
|
+
* @param aad - Optional additional authenticated data
|
|
415
|
+
* @returns Cipher with encrypt/decrypt methods
|
|
416
|
+
*/
|
|
417
|
+
declare function createXChaCha20Poly1305(key: Uint8Array, nonce: Uint8Array, aad?: Uint8Array): _noble_ciphers_utils.CipherWithOutput;
|
|
418
|
+
/**
|
|
419
|
+
* Create a ChaCha20-Poly1305 cipher instance.
|
|
420
|
+
*
|
|
421
|
+
* @param key - 32-byte encryption key
|
|
422
|
+
* @param nonce - 12-byte nonce
|
|
423
|
+
* @param aad - Optional additional authenticated data
|
|
424
|
+
* @returns Cipher with encrypt/decrypt methods
|
|
425
|
+
*/
|
|
426
|
+
declare function createChaCha20Poly1305(key: Uint8Array, nonce: Uint8Array, aad?: Uint8Array): _noble_ciphers_utils.CipherWithOutput;
|
|
427
|
+
/** ChaCha20-Poly1305 key size (32 bytes) */
|
|
428
|
+
declare const CHACHA20_KEY_SIZE = 32;
|
|
429
|
+
/** ChaCha20-Poly1305 nonce size (12 bytes) */
|
|
430
|
+
declare const CHACHA20_NONCE_SIZE = 12;
|
|
431
|
+
/** XChaCha20-Poly1305 nonce size (24 bytes) */
|
|
432
|
+
declare const XCHACHA20_NONCE_SIZE = 24;
|
|
433
|
+
/** Poly1305 tag size (16 bytes) */
|
|
434
|
+
declare const POLY1305_TAG_SIZE = 16;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Omnituum PQC Shared - HKDF (HMAC-based Key Derivation Function)
|
|
438
|
+
*
|
|
439
|
+
* HKDF is a NIST-approved key derivation function (RFC 5869).
|
|
440
|
+
* Supports SHA-256 (default) and SHA-512 hash functions.
|
|
441
|
+
*
|
|
442
|
+
* Two-step process:
|
|
443
|
+
* 1. Extract: Derive a pseudorandom key from input keying material
|
|
444
|
+
* 2. Expand: Generate output keying material from the PRK
|
|
445
|
+
*
|
|
446
|
+
* Used in Noise protocols for key derivation.
|
|
447
|
+
*/
|
|
448
|
+
type HkdfHash = 'sha256' | 'sha512';
|
|
449
|
+
interface HkdfOptions {
|
|
450
|
+
/** Hash function to use (default: 'sha256') */
|
|
451
|
+
hash?: HkdfHash;
|
|
452
|
+
/** Context info for domain separation */
|
|
453
|
+
info?: Uint8Array | string;
|
|
454
|
+
/** Salt (defaults to zeroes if not provided) */
|
|
455
|
+
salt?: Uint8Array;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Derive keys using HKDF (Extract + Expand).
|
|
459
|
+
*
|
|
460
|
+
* @param ikm - Input keying material
|
|
461
|
+
* @param outputLength - Desired output length in bytes
|
|
462
|
+
* @param options - Optional salt, info, and hash selection
|
|
463
|
+
* @returns Derived key material
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```ts
|
|
467
|
+
* // Basic key derivation
|
|
468
|
+
* const key = hkdfDerive(sharedSecret, 32);
|
|
469
|
+
*
|
|
470
|
+
* // With domain separation
|
|
471
|
+
* const key = hkdfDerive(sharedSecret, 32, {
|
|
472
|
+
* info: 'MyApp v1.0 encryption key'
|
|
473
|
+
* });
|
|
474
|
+
*
|
|
475
|
+
* // With salt
|
|
476
|
+
* const key = hkdfDerive(sharedSecret, 32, {
|
|
477
|
+
* salt: randomSalt,
|
|
478
|
+
* info: 'session key'
|
|
479
|
+
* });
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
declare function hkdfDerive(ikm: Uint8Array, outputLength: number, options?: HkdfOptions): Uint8Array;
|
|
483
|
+
/**
|
|
484
|
+
* HKDF-Extract: Derive a pseudorandom key from input keying material.
|
|
485
|
+
*
|
|
486
|
+
* @param ikm - Input keying material
|
|
487
|
+
* @param salt - Optional salt (defaults to zeroes)
|
|
488
|
+
* @param hash - Hash function ('sha256' or 'sha512')
|
|
489
|
+
* @returns Pseudorandom key (32 bytes for SHA-256, 64 for SHA-512)
|
|
490
|
+
*/
|
|
491
|
+
declare function hkdfExtract(ikm: Uint8Array, salt?: Uint8Array, hash?: HkdfHash): Uint8Array;
|
|
492
|
+
/**
|
|
493
|
+
* HKDF-Expand: Expand a pseudorandom key into output keying material.
|
|
494
|
+
*
|
|
495
|
+
* @param prk - Pseudorandom key (from hkdfExtract)
|
|
496
|
+
* @param info - Context info for domain separation
|
|
497
|
+
* @param outputLength - Desired output length in bytes
|
|
498
|
+
* @param hash - Hash function ('sha256' or 'sha512')
|
|
499
|
+
* @returns Output keying material
|
|
500
|
+
*/
|
|
501
|
+
declare function hkdfExpand(prk: Uint8Array, info: Uint8Array | string | undefined, outputLength: number, hash?: HkdfHash): Uint8Array;
|
|
502
|
+
/**
|
|
503
|
+
* HKDF for Noise protocol key derivation.
|
|
504
|
+
* Splits output into chaining key and output key.
|
|
505
|
+
*
|
|
506
|
+
* @param chainingKey - Current chaining key (salt)
|
|
507
|
+
* @param inputKeyMaterial - New key material to mix in
|
|
508
|
+
* @returns [newChainingKey, outputKey] - both 32 bytes
|
|
509
|
+
*/
|
|
510
|
+
declare function hkdfSplitForNoise(chainingKey: Uint8Array, inputKeyMaterial: Uint8Array): [Uint8Array, Uint8Array];
|
|
511
|
+
/**
|
|
512
|
+
* HKDF for Noise protocol with three outputs.
|
|
513
|
+
* Used when deriving transport keys at the end of handshake.
|
|
514
|
+
*
|
|
515
|
+
* @param chainingKey - Current chaining key
|
|
516
|
+
* @param inputKeyMaterial - Key material to mix
|
|
517
|
+
* @returns [ck, k1, k2] - chaining key and two output keys
|
|
518
|
+
*/
|
|
519
|
+
declare function hkdfTripleSplitForNoise(chainingKey: Uint8Array, inputKeyMaterial: Uint8Array): [Uint8Array, Uint8Array, Uint8Array];
|
|
520
|
+
/** HKDF-SHA256 output size (32 bytes) */
|
|
521
|
+
declare const HKDF_SHA256_OUTPUT_SIZE = 32;
|
|
522
|
+
/** HKDF-SHA512 output size (64 bytes) */
|
|
523
|
+
declare const HKDF_SHA512_OUTPUT_SIZE = 64;
|
|
524
|
+
/** Maximum HKDF output length for SHA-256 (255 * 32 = 8160 bytes) */
|
|
525
|
+
declare const HKDF_SHA256_MAX_OUTPUT: number;
|
|
526
|
+
/** Maximum HKDF output length for SHA-512 (255 * 64 = 16320 bytes) */
|
|
527
|
+
declare const HKDF_SHA512_MAX_OUTPUT: number;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Omnituum PQC Shared - Cryptographic Primitives
|
|
531
|
+
*
|
|
532
|
+
* Pure browser implementation - no Node.js dependencies.
|
|
533
|
+
* Uses Web Crypto API and @noble/hashes for all operations.
|
|
534
|
+
*/
|
|
535
|
+
declare const textEncoder: TextEncoder;
|
|
536
|
+
declare const textDecoder: TextDecoder;
|
|
537
|
+
declare function toB64(bytes: Uint8Array): string;
|
|
538
|
+
declare function fromB64(str: string): Uint8Array;
|
|
539
|
+
declare function toHex(bytes: Uint8Array): string;
|
|
540
|
+
declare function fromHex(hex: string): Uint8Array;
|
|
541
|
+
declare function assertLen(label: string, arr: Uint8Array, n: number): void;
|
|
542
|
+
declare function rand32(): Uint8Array;
|
|
543
|
+
declare function rand24(): Uint8Array;
|
|
544
|
+
declare function rand12(): Uint8Array;
|
|
545
|
+
declare function randN(n: number): Uint8Array;
|
|
546
|
+
declare function sha256(bytes: Uint8Array): Uint8Array;
|
|
547
|
+
declare function sha256String(str: string): Uint8Array;
|
|
548
|
+
declare function hkdfSha256(ikm: Uint8Array, opts?: {
|
|
549
|
+
salt?: Uint8Array;
|
|
550
|
+
info?: Uint8Array;
|
|
551
|
+
length?: number;
|
|
552
|
+
}): Uint8Array;
|
|
553
|
+
declare const b64: typeof toB64;
|
|
554
|
+
declare const ub64: typeof fromB64;
|
|
555
|
+
declare const u8: (s: string | Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Omnituum PQC Shared - NaCl Secretbox Operations
|
|
559
|
+
*
|
|
560
|
+
* Symmetric encryption using XSalsa20-Poly1305 (NaCl secretbox).
|
|
561
|
+
* 32-byte key, 24-byte nonce, authenticated encryption.
|
|
562
|
+
*/
|
|
563
|
+
interface SecretboxPayload {
|
|
564
|
+
/** Scheme identifier for format detection */
|
|
565
|
+
scheme: 'nacl.secretbox';
|
|
566
|
+
/** Nonce (base64, 24 bytes) */
|
|
567
|
+
nonce: string;
|
|
568
|
+
/** Ciphertext (base64, includes auth tag) */
|
|
569
|
+
ciphertext: string;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Encrypt data using NaCl secretbox (XSalsa20-Poly1305).
|
|
573
|
+
*
|
|
574
|
+
* @param key - 32-byte symmetric key
|
|
575
|
+
* @param plaintext - Data to encrypt
|
|
576
|
+
* @param nonce - Optional 24-byte nonce (generated if not provided)
|
|
577
|
+
* @returns Encrypted payload with nonce and ciphertext
|
|
578
|
+
*/
|
|
579
|
+
declare function secretboxEncrypt(key: Uint8Array, plaintext: Uint8Array, nonce?: Uint8Array): SecretboxPayload;
|
|
580
|
+
/**
|
|
581
|
+
* Encrypt a string using NaCl secretbox.
|
|
582
|
+
*/
|
|
583
|
+
declare function secretboxEncryptString(key: Uint8Array, plaintext: string, nonce?: Uint8Array): SecretboxPayload;
|
|
584
|
+
/**
|
|
585
|
+
* Decrypt data using NaCl secretbox.
|
|
586
|
+
*
|
|
587
|
+
* @param key - 32-byte symmetric key
|
|
588
|
+
* @param payload - Encrypted payload from secretboxEncrypt
|
|
589
|
+
* @returns Decrypted data, or null if authentication fails
|
|
590
|
+
*/
|
|
591
|
+
declare function secretboxDecrypt(key: Uint8Array, payload: SecretboxPayload): Uint8Array | null;
|
|
592
|
+
/**
|
|
593
|
+
* Decrypt to a string using NaCl secretbox.
|
|
594
|
+
*/
|
|
595
|
+
declare function secretboxDecryptString(key: Uint8Array, payload: SecretboxPayload): string | null;
|
|
596
|
+
/**
|
|
597
|
+
* Raw secretbox encryption (returns raw bytes).
|
|
598
|
+
*/
|
|
599
|
+
declare function secretboxRaw(key: Uint8Array, plaintext: Uint8Array, nonce: Uint8Array): Uint8Array;
|
|
600
|
+
/**
|
|
601
|
+
* Raw secretbox decryption (returns raw bytes).
|
|
602
|
+
*/
|
|
603
|
+
declare function secretboxOpenRaw(key: Uint8Array, ciphertext: Uint8Array, nonce: Uint8Array): Uint8Array | null;
|
|
604
|
+
interface BoxPayload {
|
|
605
|
+
/** Nonce (base64, 24 bytes) */
|
|
606
|
+
nonce: string;
|
|
607
|
+
/** Ciphertext (base64) */
|
|
608
|
+
ciphertext: string;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Encrypt data using NaCl box (X25519 + XSalsa20-Poly1305).
|
|
612
|
+
*
|
|
613
|
+
* @param plaintext - Data to encrypt
|
|
614
|
+
* @param nonce - 24-byte nonce
|
|
615
|
+
* @param recipientPubKey - Recipient's X25519 public key (32 bytes)
|
|
616
|
+
* @param senderSecKey - Sender's X25519 secret key (32 bytes)
|
|
617
|
+
* @returns Encrypted ciphertext
|
|
618
|
+
*/
|
|
619
|
+
declare function boxEncrypt(plaintext: Uint8Array, nonce: Uint8Array, recipientPubKey: Uint8Array, senderSecKey: Uint8Array): Uint8Array;
|
|
620
|
+
/**
|
|
621
|
+
* Decrypt data using NaCl box.
|
|
622
|
+
*
|
|
623
|
+
* @param ciphertext - Encrypted data
|
|
624
|
+
* @param nonce - 24-byte nonce
|
|
625
|
+
* @param senderPubKey - Sender's X25519 public key (32 bytes)
|
|
626
|
+
* @param recipientSecKey - Recipient's X25519 secret key (32 bytes)
|
|
627
|
+
* @returns Decrypted data, or null if authentication fails
|
|
628
|
+
*/
|
|
629
|
+
declare function boxDecrypt(ciphertext: Uint8Array, nonce: Uint8Array, senderPubKey: Uint8Array, recipientSecKey: Uint8Array): Uint8Array | null;
|
|
630
|
+
/** NaCl secretbox key size (32 bytes) */
|
|
631
|
+
declare const SECRETBOX_KEY_SIZE: number;
|
|
632
|
+
/** NaCl secretbox nonce size (24 bytes) */
|
|
633
|
+
declare const SECRETBOX_NONCE_SIZE: number;
|
|
634
|
+
/** NaCl secretbox overhead (16 bytes auth tag) */
|
|
635
|
+
declare const SECRETBOX_OVERHEAD: number;
|
|
636
|
+
/** NaCl box key size (32 bytes) */
|
|
637
|
+
declare const BOX_KEY_SIZE: number;
|
|
638
|
+
/** NaCl box nonce size (24 bytes) */
|
|
639
|
+
declare const BOX_NONCE_SIZE: number;
|
|
640
|
+
|
|
641
|
+
export { BLAKE3_BLOCK_SIZE, BLAKE3_KEY_LENGTH, BLAKE3_OUTPUT_LENGTH, BOX_KEY_SIZE, BOX_NONCE_SIZE, type Blake3Options, type BoxPayload, CHACHA20_KEY_SIZE, CHACHA20_NONCE_SIZE, type ChaChaPayload, type ClassicalWrap, DILITHIUM_ALGORITHM, DILITHIUM_PUBLIC_KEY_SIZE, DILITHIUM_SECRET_KEY_SIZE, DILITHIUM_SIGNATURE_SIZE, type DilithiumKeypair, type DilithiumKeypairB64, type DilithiumSignature, HKDF_SHA256_MAX_OUTPUT, HKDF_SHA256_OUTPUT_SIZE, HKDF_SHA512_MAX_OUTPUT, HKDF_SHA512_OUTPUT_SIZE, type HkdfHash, type HkdfOptions, type HybridEnvelope, type HybridIdentity, type HybridPublicKeys, type HybridSecretKeys, type KyberEncapsulation, type KyberKeypair, type KyberKeypairB64, POLY1305_TAG_SIZE, SECRETBOX_KEY_SIZE, SECRETBOX_NONCE_SIZE, SECRETBOX_OVERHEAD, type SecretboxPayload, type X25519Keypair, type X25519KeypairHex, XCHACHA20_NONCE_SIZE, assertLen, b64, blake3, blake3DeriveKey, blake3Hex, blake3Mac, boxDecrypt, boxEncrypt, boxUnwrapWithX25519, boxWrapWithX25519, chaCha20Poly1305Decrypt, chaCha20Poly1305Encrypt, createChaCha20Poly1305, createXChaCha20Poly1305, deriveKeyFromShared, dilithiumSign, dilithiumSignRaw, dilithiumVerify, dilithiumVerifyRaw, fromB64, fromHex, generateDilithiumKeypair, generateDilithiumKeypairFromSeed, generateHybridIdentity, generateKyberKeypair, generateX25519Keypair, generateX25519KeypairFromSeed, getPublicKeys, getSecretKeys, hkdfDerive, hkdfExpand, hkdfExtract, hkdfSha256, hkdfSplitForNoise, hkdfTripleSplitForNoise, hybridDecrypt, hybridDecryptToString, hybridEncrypt, isDilithiumAvailable, isKyberAvailable, kyberDecapsulate, kyberEncapsulate, kyberUnwrapKey, kyberWrapKey, rand12, rand24, rand32, randN, rotateHybridIdentity, secretboxDecrypt, secretboxDecryptString, secretboxEncrypt, secretboxEncryptString, secretboxOpenRaw, secretboxRaw, sha256, sha256String, textDecoder, textEncoder, toB64, toHex, u8, ub64, x25519SharedSecret, xChaCha20Poly1305Decrypt, xChaCha20Poly1305Encrypt };
|