kxco-post-quantum 1.1.11 → 1.2.0

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/src/derive.d.ts CHANGED
@@ -1,20 +1,20 @@
1
- /// <reference types="node" />
2
-
3
- /**
4
- * Derive a deterministic seed from a master secret + an info string,
5
- * using HKDF-SHA-512 with an empty salt.
6
- *
7
- * Same `master + info + length` always produces the same seed.
8
- *
9
- * @param master — high-entropy input keying material (≥16 bytes)
10
- * @param info — domain separation tag (eg. 'kxco-platform-ml-dsa-65-v1')
11
- * @param length — output seed length in bytes (32 for ML-DSA, 64 for ML-KEM)
12
- *
13
- * @throws {Error} if `master` is shorter than 16 bytes
14
- * @throws {Error} if `info` is empty or not a string
15
- */
16
- export function deriveSeed(
17
- master: Buffer | Uint8Array,
18
- info: string,
19
- length: number,
20
- ): Buffer
1
+ /// <reference types="node" />
2
+
3
+ /**
4
+ * Derive a deterministic seed from a master secret + an info string,
5
+ * using HKDF-SHA-512 with an empty salt.
6
+ *
7
+ * Same `master + info + length` always produces the same seed.
8
+ *
9
+ * @param master — high-entropy input keying material (≥16 bytes)
10
+ * @param info — domain separation tag (eg. 'kxco-platform-ml-dsa-65-v1')
11
+ * @param length — output seed length in bytes (32 for ML-DSA, 64 for ML-KEM)
12
+ *
13
+ * @throws {Error} if `master` is shorter than 16 bytes
14
+ * @throws {Error} if `info` is empty or not a string
15
+ */
16
+ export function deriveSeed(
17
+ master: Buffer | Uint8Array,
18
+ info: string,
19
+ length: number,
20
+ ): Buffer
package/src/derive.js CHANGED
@@ -1,47 +1,47 @@
1
- // Deterministic key derivation via HKDF-SHA-512.
2
- //
3
- // Same seed + same info = same keypair, every time. This is how the KXCO
4
- // platform reproduces its signing identity across replicas without storing
5
- // the private key in a database: the master key is the env var, the rest is
6
- // pure derivation.
7
- //
8
- // Domain separation through `info` is critical — using the same master key
9
- // for different purposes (signing vs encryption) MUST use distinct info
10
- // strings or you create a cross-protocol attack surface.
11
- //
12
- // Isomorphic: uses @noble/hashes/hkdf which runs identically in Node 18+ and
13
- // modern browsers. Returns Buffer when running on Node (for backwards
14
- // compatibility with existing callers), Uint8Array in browsers.
15
-
16
- import { hkdf } from '@noble/hashes/hkdf.js'
17
- import { sha512 } from '@noble/hashes/sha2.js'
18
-
19
- const HAS_BUFFER = typeof Buffer !== 'undefined'
20
- const enc = new TextEncoder()
21
-
22
- function toBytes(input) {
23
- if (input instanceof Uint8Array) return input
24
- if (typeof input === 'string') return enc.encode(input)
25
- throw new Error('expected Uint8Array or string')
26
- }
27
-
28
- /**
29
- * Derive a deterministic seed from a master secret + an info string.
30
- *
31
- * @param {Buffer|Uint8Array|string} master — high-entropy keying material (>= 16 bytes)
32
- * @param {string} info — domain separation tag
33
- * @param {number} length — output seed length in bytes
34
- * @returns {Buffer|Uint8Array}
35
- */
36
- export function deriveSeed(master, info, length) {
37
- const ikm = toBytes(master)
38
- if (!ikm || ikm.length < 16) {
39
- throw new Error('deriveSeed: master keying material must be at least 16 bytes')
40
- }
41
- if (!info || typeof info !== 'string') {
42
- throw new Error('deriveSeed: info string is required for domain separation')
43
- }
44
- const salt = new Uint8Array(32) // 32 zero bytes — fine with high-entropy IKM
45
- const out = hkdf(sha512, ikm, salt, enc.encode(info), length)
46
- return HAS_BUFFER ? Buffer.from(out) : out
47
- }
1
+ // Deterministic key derivation via HKDF-SHA-512.
2
+ //
3
+ // Same seed + same info = same keypair, every time. This is how the KXCO
4
+ // platform reproduces its signing identity across replicas without storing
5
+ // the private key in a database: the master key is the env var, the rest is
6
+ // pure derivation.
7
+ //
8
+ // Domain separation through `info` is critical — using the same master key
9
+ // for different purposes (signing vs encryption) MUST use distinct info
10
+ // strings or you create a cross-protocol attack surface.
11
+ //
12
+ // Isomorphic: uses @noble/hashes/hkdf which runs identically in Node 18+ and
13
+ // modern browsers. Returns Buffer when running on Node (for backwards
14
+ // compatibility with existing callers), Uint8Array in browsers.
15
+
16
+ import { hkdf } from '@noble/hashes/hkdf.js'
17
+ import { sha512 } from '@noble/hashes/sha2.js'
18
+
19
+ const HAS_BUFFER = typeof Buffer !== 'undefined'
20
+ const enc = new TextEncoder()
21
+
22
+ function toBytes(input) {
23
+ if (input instanceof Uint8Array) return input
24
+ if (typeof input === 'string') return enc.encode(input)
25
+ throw new Error('expected Uint8Array or string')
26
+ }
27
+
28
+ /**
29
+ * Derive a deterministic seed from a master secret + an info string.
30
+ *
31
+ * @param {Buffer|Uint8Array|string} master — high-entropy keying material (>= 16 bytes)
32
+ * @param {string} info — domain separation tag
33
+ * @param {number} length — output seed length in bytes
34
+ * @returns {Buffer|Uint8Array}
35
+ */
36
+ export function deriveSeed(master, info, length) {
37
+ const ikm = toBytes(master)
38
+ if (!ikm || ikm.length < 16) {
39
+ throw new Error('deriveSeed: master keying material must be at least 16 bytes')
40
+ }
41
+ if (!info || typeof info !== 'string') {
42
+ throw new Error('deriveSeed: info string is required for domain separation')
43
+ }
44
+ const salt = new Uint8Array(32) // 32 zero bytes — fine with high-entropy IKM
45
+ const out = hkdf(sha512, ikm, salt, enc.encode(info), length)
46
+ return HAS_BUFFER ? Buffer.from(out) : out
47
+ }
package/src/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- /// <reference types="node" />
2
-
3
- export * as mlDsa from './ml-dsa.js'
4
- export * as mlKem from './ml-kem.js'
5
- export * from './derive.js'
6
- export * from './kid.js'
7
- export * as webhook from './webhook.js'
1
+ /// <reference types="node" />
2
+
3
+ export * as mlDsa from './ml-dsa.js'
4
+ export * as mlKem from './ml-kem.js'
5
+ export * as slhDsa from './slh-dsa.js'
6
+ export * from './derive.js'
7
+ export * from './kid.js'
8
+ export * as webhook from './webhook.js'
package/src/index.js CHANGED
@@ -11,6 +11,7 @@
11
11
 
12
12
  export * as mlDsa from './ml-dsa.js'
13
13
  export * as mlKem from './ml-kem.js'
14
+ export * as slhDsa from './slh-dsa.js'
14
15
  export * from './derive.js'
15
16
  export * from './kid.js'
16
17
  export * as webhook from './webhook.js'
package/src/kid.d.ts CHANGED
@@ -1,21 +1,21 @@
1
- /// <reference types="node" />
2
-
3
- /**
4
- * Compute a 16-hex-character fingerprint of a public key:
5
- * the first 8 bytes of `SHA-256(public_key)`, hex-encoded.
6
- *
7
- * Stable for the lifetime of the keypair. Used to identify which
8
- * platform key signed an outbound delivery without including the
9
- * full 1952-byte public key in every request.
10
- *
11
- * @param publicKey — raw bytes or hex string
12
- */
13
- export function fingerprint(publicKey: Buffer | Uint8Array | string): string
14
-
15
- /**
16
- * Constant-time comparison of two kid strings.
17
- *
18
- * Use this instead of `===` when comparing kids that may be
19
- * influenced by untrusted input — eg. an `X-KXCO-PQ-Kid` header.
20
- */
21
- export function kidEquals(a: string, b: string): boolean
1
+ /// <reference types="node" />
2
+
3
+ /**
4
+ * Compute a 16-hex-character fingerprint of a public key:
5
+ * the first 8 bytes of `SHA-256(public_key)`, hex-encoded.
6
+ *
7
+ * Stable for the lifetime of the keypair. Used to identify which
8
+ * platform key signed an outbound delivery without including the
9
+ * full 1952-byte public key in every request.
10
+ *
11
+ * @param publicKey — raw bytes or hex string
12
+ */
13
+ export function fingerprint(publicKey: Buffer | Uint8Array | string): string
14
+
15
+ /**
16
+ * Constant-time comparison of two kid strings.
17
+ *
18
+ * Use this instead of `===` when comparing kids that may be
19
+ * influenced by untrusted input — eg. an `X-KXCO-PQ-Kid` header.
20
+ */
21
+ export function kidEquals(a: string, b: string): boolean
package/src/kid.js CHANGED
@@ -1,53 +1,53 @@
1
- // Public-key fingerprints (kid = "key identifier").
2
- //
3
- // Receivers pin a 16-hex fingerprint of the platform's public key, then
4
- // compare against an X-KXCO-PQ-Kid header on every webhook. Fast rejection of
5
- // stale or unknown keys without re-fetching the full 1952-byte public key on
6
- // every request.
7
- //
8
- // Isomorphic: uses @noble/hashes/sha256 — runs identically in Node and
9
- // browsers.
10
-
11
- import { sha256 } from '@noble/hashes/sha2.js'
12
-
13
- function hexToBytes(hex) {
14
- if (hex.length % 2) throw new Error('odd hex length')
15
- const b = new Uint8Array(hex.length / 2)
16
- for (let i = 0; i < b.length; i++) b[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16)
17
- return b
18
- }
19
-
20
- function bytesToHex(bytes) {
21
- let s = ''
22
- for (let i = 0; i < bytes.length; i++) s += bytes[i].toString(16).padStart(2, '0')
23
- return s
24
- }
25
-
26
- /**
27
- * Compute a stable 16-hex-character fingerprint of a public key.
28
- *
29
- * @param {Buffer|Uint8Array|string} publicKey — raw bytes or hex string
30
- * @returns {string} 16 hex chars (8 bytes of SHA-256)
31
- */
32
- export function fingerprint(publicKey) {
33
- const bytes = typeof publicKey === 'string'
34
- ? hexToBytes(publicKey)
35
- : (publicKey instanceof Uint8Array ? publicKey : new Uint8Array(publicKey))
36
- return bytesToHex(sha256(bytes)).slice(0, 16)
37
- }
38
-
39
- /**
40
- * Constant-time comparison of two kid strings.
41
- *
42
- * @param {string} a
43
- * @param {string} b
44
- * @returns {boolean}
45
- */
46
- export function kidEquals(a, b) {
47
- if (typeof a !== 'string' || typeof b !== 'string' || a.length !== b.length) {
48
- return false
49
- }
50
- let diff = 0
51
- for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i)
52
- return diff === 0
53
- }
1
+ // Public-key fingerprints (kid = "key identifier").
2
+ //
3
+ // Receivers pin a 16-hex fingerprint of the platform's public key, then
4
+ // compare against an X-KXCO-PQ-Kid header on every webhook. Fast rejection of
5
+ // stale or unknown keys without re-fetching the full 1952-byte public key on
6
+ // every request.
7
+ //
8
+ // Isomorphic: uses @noble/hashes/sha256 — runs identically in Node and
9
+ // browsers.
10
+
11
+ import { sha256 } from '@noble/hashes/sha2.js'
12
+
13
+ function hexToBytes(hex) {
14
+ if (hex.length % 2) throw new Error('odd hex length')
15
+ const b = new Uint8Array(hex.length / 2)
16
+ for (let i = 0; i < b.length; i++) b[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16)
17
+ return b
18
+ }
19
+
20
+ function bytesToHex(bytes) {
21
+ let s = ''
22
+ for (let i = 0; i < bytes.length; i++) s += bytes[i].toString(16).padStart(2, '0')
23
+ return s
24
+ }
25
+
26
+ /**
27
+ * Compute a stable 16-hex-character fingerprint of a public key.
28
+ *
29
+ * @param {Buffer|Uint8Array|string} publicKey — raw bytes or hex string
30
+ * @returns {string} 16 hex chars (8 bytes of SHA-256)
31
+ */
32
+ export function fingerprint(publicKey) {
33
+ const bytes = typeof publicKey === 'string'
34
+ ? hexToBytes(publicKey)
35
+ : (publicKey instanceof Uint8Array ? publicKey : new Uint8Array(publicKey))
36
+ return bytesToHex(sha256(bytes)).slice(0, 16)
37
+ }
38
+
39
+ /**
40
+ * Constant-time comparison of two kid strings.
41
+ *
42
+ * @param {string} a
43
+ * @param {string} b
44
+ * @returns {boolean}
45
+ */
46
+ export function kidEquals(a, b) {
47
+ if (typeof a !== 'string' || typeof b !== 'string' || a.length !== b.length) {
48
+ return false
49
+ }
50
+ let diff = 0
51
+ for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i)
52
+ return diff === 0
53
+ }
package/src/ml-dsa.d.ts CHANGED
@@ -1,45 +1,45 @@
1
- /// <reference types="node" />
2
-
3
- export interface MlDsaKeypair {
4
- /** 1952-byte public key */
5
- publicKey: Buffer
6
- /** 4032-byte secret key */
7
- secretKey: Buffer
8
- }
9
-
10
- /**
11
- * Generate an ML-DSA-65 (NIST FIPS 204) keypair deterministically
12
- * from a master + domain-separation info string.
13
- *
14
- * Same inputs always produce the same keypair — no state, no DB row.
15
- */
16
- export function keypairFromMaster(
17
- master: Buffer | Uint8Array,
18
- info?: string,
19
- ): MlDsaKeypair
20
-
21
- /**
22
- * Sign a message under an ML-DSA-65 secret key. Returns the signature
23
- * as a hex string (3309 bytes = 6618 hex characters).
24
- */
25
- export function sign(
26
- secretKey: Buffer | Uint8Array,
27
- message: Buffer | string,
28
- ): string
29
-
30
- /**
31
- * Verify a hex-encoded ML-DSA-65 signature against a public key + message.
32
- * Returns `false` on any error (invalid hex, wrong length, mismatch).
33
- */
34
- export function verify(
35
- publicKey: Buffer | Uint8Array,
36
- message: Buffer | string,
37
- sigHex: string,
38
- ): boolean
39
-
40
- /**
41
- * Raw `@noble/post-quantum` ML-DSA-65 primitive, re-exported for callers
42
- * who want the lower-level API. The wrapper functions above are
43
- * recommended for production use.
44
- */
45
- export const ml_dsa65: typeof import('@noble/post-quantum/ml-dsa').ml_dsa65
1
+ /// <reference types="node" />
2
+
3
+ export interface MlDsaKeypair {
4
+ /** 1952-byte public key */
5
+ publicKey: Buffer
6
+ /** 4032-byte secret key */
7
+ secretKey: Buffer
8
+ }
9
+
10
+ /**
11
+ * Generate an ML-DSA-65 (NIST FIPS 204) keypair deterministically
12
+ * from a master + domain-separation info string.
13
+ *
14
+ * Same inputs always produce the same keypair — no state, no DB row.
15
+ */
16
+ export function keypairFromMaster(
17
+ master: Buffer | Uint8Array,
18
+ info?: string,
19
+ ): MlDsaKeypair
20
+
21
+ /**
22
+ * Sign a message under an ML-DSA-65 secret key. Returns the signature
23
+ * as a hex string (3309 bytes = 6618 hex characters).
24
+ */
25
+ export function sign(
26
+ secretKey: Buffer | Uint8Array,
27
+ message: Buffer | string,
28
+ ): string
29
+
30
+ /**
31
+ * Verify a hex-encoded ML-DSA-65 signature against a public key + message.
32
+ * Returns `false` on any error (invalid hex, wrong length, mismatch).
33
+ */
34
+ export function verify(
35
+ publicKey: Buffer | Uint8Array,
36
+ message: Buffer | string,
37
+ sigHex: string,
38
+ ): boolean
39
+
40
+ /**
41
+ * Raw `@noble/post-quantum` ML-DSA-65 primitive, re-exported for callers
42
+ * who want the lower-level API. The wrapper functions above are
43
+ * recommended for production use.
44
+ */
45
+ export const ml_dsa65: typeof import('@noble/post-quantum/ml-dsa.js').ml_dsa65
package/src/ml-dsa.js CHANGED
@@ -1,78 +1,78 @@
1
- // ML-DSA-65 helpers (NIST FIPS 204, Dilithium3).
2
- //
3
- // Module-lattice signatures. Security Category 3 (≈ AES-192). Public key 1952
4
- // bytes, signature 3309 bytes. Resistant to attacks by quantum computers.
5
- //
6
- // Isomorphic: works in Node and modern browsers. Returns Buffer on Node
7
- // (backwards compatible), Uint8Array in browsers.
8
-
9
- import { ml_dsa65 } from '@noble/post-quantum/ml-dsa'
10
- import { deriveSeed } from './derive.js'
11
-
12
- const HAS_BUFFER = typeof Buffer !== 'undefined'
13
- const enc = new TextEncoder()
14
-
15
- function toBytes(input) {
16
- if (input instanceof Uint8Array) return input
17
- if (typeof input === 'string') return enc.encode(input)
18
- throw new Error('expected Uint8Array or string')
19
- }
20
- function hexToBytes(hex) {
21
- if (typeof hex !== 'string' || hex.length % 2) throw new Error('invalid hex')
22
- const b = new Uint8Array(hex.length / 2)
23
- for (let i = 0; i < b.length; i++) b[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16)
24
- return b
25
- }
26
- function bytesToHex(bytes) {
27
- let s = ''
28
- for (let i = 0; i < bytes.length; i++) s += bytes[i].toString(16).padStart(2, '0')
29
- return s
30
- }
31
- function wrap(bytes) {
32
- return HAS_BUFFER ? Buffer.from(bytes) : bytes
33
- }
34
-
35
- /**
36
- * Generate an ML-DSA-65 keypair from a master + domain-separation info.
37
- *
38
- * @returns {{ publicKey: Buffer|Uint8Array, secretKey: Buffer|Uint8Array }}
39
- */
40
- export function keypairFromMaster(master, info = 'ml-dsa-65-v1') {
41
- const seed = deriveSeed(master, info, 32)
42
- const seedU8 = seed instanceof Uint8Array ? seed : new Uint8Array(seed)
43
- const k = ml_dsa65.keygen(seedU8)
44
- return {
45
- publicKey: wrap(k.publicKey),
46
- secretKey: wrap(k.secretKey),
47
- }
48
- }
49
-
50
- /**
51
- * Sign a message. Returns the signature as a hex string.
52
- *
53
- * @param {Buffer|Uint8Array} secretKey
54
- * @param {Buffer|Uint8Array|string} message
55
- * @returns {string} hex-encoded signature (6618 chars)
56
- */
57
- export function sign(secretKey, message) {
58
- const sig = ml_dsa65.sign(secretKey, toBytes(message))
59
- return bytesToHex(sig)
60
- }
61
-
62
- /**
63
- * Verify a hex-encoded signature.
64
- *
65
- * @param {Buffer|Uint8Array} publicKey
66
- * @param {Buffer|Uint8Array|string} message
67
- * @param {string} sigHex
68
- * @returns {boolean}
69
- */
70
- export function verify(publicKey, message, sigHex) {
71
- try {
72
- return ml_dsa65.verify(publicKey, toBytes(message), hexToBytes(sigHex))
73
- } catch {
74
- return false
75
- }
76
- }
77
-
78
- export { ml_dsa65 }
1
+ // ML-DSA-65 helpers (NIST FIPS 204, Dilithium3).
2
+ //
3
+ // Module-lattice signatures. Security Category 3 (≈ AES-192). Public key 1952
4
+ // bytes, signature 3309 bytes. Resistant to attacks by quantum computers.
5
+ //
6
+ // Isomorphic: works in Node and modern browsers. Returns Buffer on Node
7
+ // (backwards compatible), Uint8Array in browsers.
8
+
9
+ import { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js'
10
+ import { deriveSeed } from './derive.js'
11
+
12
+ const HAS_BUFFER = typeof Buffer !== 'undefined'
13
+ const enc = new TextEncoder()
14
+
15
+ function toBytes(input) {
16
+ if (input instanceof Uint8Array) return input
17
+ if (typeof input === 'string') return enc.encode(input)
18
+ throw new Error('expected Uint8Array or string')
19
+ }
20
+ function hexToBytes(hex) {
21
+ if (typeof hex !== 'string' || hex.length % 2) throw new Error('invalid hex')
22
+ const b = new Uint8Array(hex.length / 2)
23
+ for (let i = 0; i < b.length; i++) b[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16)
24
+ return b
25
+ }
26
+ function bytesToHex(bytes) {
27
+ let s = ''
28
+ for (let i = 0; i < bytes.length; i++) s += bytes[i].toString(16).padStart(2, '0')
29
+ return s
30
+ }
31
+ function wrap(bytes) {
32
+ return HAS_BUFFER ? Buffer.from(bytes) : bytes
33
+ }
34
+
35
+ /**
36
+ * Generate an ML-DSA-65 keypair from a master + domain-separation info.
37
+ *
38
+ * @returns {{ publicKey: Buffer|Uint8Array, secretKey: Buffer|Uint8Array }}
39
+ */
40
+ export function keypairFromMaster(master, info = 'ml-dsa-65-v1') {
41
+ const seed = deriveSeed(master, info, 32)
42
+ const seedU8 = seed instanceof Uint8Array ? seed : new Uint8Array(seed)
43
+ const k = ml_dsa65.keygen(seedU8)
44
+ return {
45
+ publicKey: wrap(k.publicKey),
46
+ secretKey: wrap(k.secretKey),
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Sign a message. Returns the signature as a hex string.
52
+ *
53
+ * @param {Buffer|Uint8Array} secretKey
54
+ * @param {Buffer|Uint8Array|string} message
55
+ * @returns {string} hex-encoded signature (6618 chars)
56
+ */
57
+ export function sign(secretKey, message) {
58
+ const sig = ml_dsa65.sign(toBytes(message), secretKey)
59
+ return bytesToHex(sig)
60
+ }
61
+
62
+ /**
63
+ * Verify a hex-encoded signature.
64
+ *
65
+ * @param {Buffer|Uint8Array} publicKey
66
+ * @param {Buffer|Uint8Array|string} message
67
+ * @param {string} sigHex
68
+ * @returns {boolean}
69
+ */
70
+ export function verify(publicKey, message, sigHex) {
71
+ try {
72
+ return ml_dsa65.verify(hexToBytes(sigHex), toBytes(message), publicKey)
73
+ } catch {
74
+ return false
75
+ }
76
+ }
77
+
78
+ export { ml_dsa65 }
package/src/ml-kem.d.ts CHANGED
@@ -1,49 +1,49 @@
1
- /// <reference types="node" />
2
-
3
- export interface MlKemKeypair {
4
- /** 1184-byte public key */
5
- publicKey: Buffer
6
- /** 2400-byte secret key */
7
- secretKey: Buffer
8
- }
9
-
10
- export interface MlKemEncapsulation {
11
- /** 1088-byte KEM ciphertext to transmit to the recipient */
12
- ciphertext: Buffer
13
- /** Alias for `ciphertext` (mirrors @noble/post-quantum's camelCase) */
14
- cipherText: Buffer
15
- /** 32-byte shared secret to use as a symmetric AEAD key */
16
- sharedSecret: Buffer
17
- }
18
-
19
- /**
20
- * Generate an ML-KEM-768 (NIST FIPS 203) keypair deterministically
21
- * from a master + domain-separation info string.
22
- */
23
- export function keypairFromMaster(
24
- master: Buffer | Uint8Array,
25
- info?: string,
26
- ): MlKemKeypair
27
-
28
- /**
29
- * Encapsulate a shared secret to the recipient's ML-KEM-768 public key.
30
- *
31
- * The recipient calls `decapsulate(ciphertext, secretKey)` to recover
32
- * the same shared secret. Use the shared secret as a symmetric AEAD
33
- * key (eg. AES-256-GCM).
34
- */
35
- export function encapsulate(publicKey: Buffer | Uint8Array): MlKemEncapsulation
36
-
37
- /**
38
- * Decapsulate: recover the shared secret from a KEM ciphertext
39
- * using the recipient's secret key.
40
- */
41
- export function decapsulate(
42
- ciphertext: Buffer | Uint8Array,
43
- secretKey: Buffer | Uint8Array,
44
- ): Buffer
45
-
46
- /**
47
- * Raw `@noble/post-quantum` ML-KEM-768 primitive, re-exported.
48
- */
49
- export const ml_kem768: typeof import('@noble/post-quantum/ml-kem').ml_kem768
1
+ /// <reference types="node" />
2
+
3
+ export interface MlKemKeypair {
4
+ /** 1184-byte public key */
5
+ publicKey: Buffer
6
+ /** 2400-byte secret key */
7
+ secretKey: Buffer
8
+ }
9
+
10
+ export interface MlKemEncapsulation {
11
+ /** 1088-byte KEM ciphertext to transmit to the recipient */
12
+ ciphertext: Buffer
13
+ /** Alias for `ciphertext` (mirrors @noble/post-quantum's camelCase) */
14
+ cipherText: Buffer
15
+ /** 32-byte shared secret to use as a symmetric AEAD key */
16
+ sharedSecret: Buffer
17
+ }
18
+
19
+ /**
20
+ * Generate an ML-KEM-768 (NIST FIPS 203) keypair deterministically
21
+ * from a master + domain-separation info string.
22
+ */
23
+ export function keypairFromMaster(
24
+ master: Buffer | Uint8Array,
25
+ info?: string,
26
+ ): MlKemKeypair
27
+
28
+ /**
29
+ * Encapsulate a shared secret to the recipient's ML-KEM-768 public key.
30
+ *
31
+ * The recipient calls `decapsulate(ciphertext, secretKey)` to recover
32
+ * the same shared secret. Use the shared secret as a symmetric AEAD
33
+ * key (eg. AES-256-GCM).
34
+ */
35
+ export function encapsulate(publicKey: Buffer | Uint8Array): MlKemEncapsulation
36
+
37
+ /**
38
+ * Decapsulate: recover the shared secret from a KEM ciphertext
39
+ * using the recipient's secret key.
40
+ */
41
+ export function decapsulate(
42
+ ciphertext: Buffer | Uint8Array,
43
+ secretKey: Buffer | Uint8Array,
44
+ ): Buffer
45
+
46
+ /**
47
+ * Raw `@noble/post-quantum` ML-KEM-768 primitive, re-exported.
48
+ */
49
+ export const ml_kem768: typeof import('@noble/post-quantum/ml-kem.js').ml_kem768