@weave_protocol/yoxallismus 0.0.1 → 0.2.0-beta.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/README.md +236 -16
- package/SECURITY.md +110 -0
- package/SECURITY_ADVISORIES.md +86 -0
- package/SKILL.md +52 -0
- package/THREAT_MODEL.md +187 -0
- package/WIRE_FORMAT.md +102 -0
- package/dist/aead.d.ts +44 -0
- package/dist/aead.d.ts.map +1 -0
- package/dist/aead.js +96 -0
- package/dist/aead.js.map +1 -0
- package/dist/cascade.d.ts +31 -0
- package/dist/cascade.d.ts.map +1 -0
- package/dist/cascade.js +74 -0
- package/dist/cascade.js.map +1 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +501 -0
- package/dist/cli.js.map +1 -0
- package/dist/double-ratchet.d.ts +106 -0
- package/dist/double-ratchet.d.ts.map +1 -0
- package/dist/double-ratchet.js +238 -0
- package/dist/double-ratchet.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/dist/kdf.d.ts +33 -0
- package/dist/kdf.d.ts.map +1 -0
- package/dist/kdf.js +45 -0
- package/dist/kdf.js.map +1 -0
- package/dist/kem.d.ts +79 -0
- package/dist/kem.d.ts.map +1 -0
- package/dist/kem.js +220 -0
- package/dist/kem.js.map +1 -0
- package/dist/labels.d.ts +51 -0
- package/dist/labels.d.ts.map +1 -0
- package/dist/labels.js +93 -0
- package/dist/labels.js.map +1 -0
- package/dist/ratchet.d.ts +38 -0
- package/dist/ratchet.d.ts.map +1 -0
- package/dist/ratchet.js +91 -0
- package/dist/ratchet.js.map +1 -0
- package/dist/sealed.d.ts +33 -0
- package/dist/sealed.d.ts.map +1 -0
- package/dist/sealed.js +40 -0
- package/dist/sealed.js.map +1 -0
- package/dist/serialize.d.ts +20 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +97 -0
- package/dist/serialize.js.map +1 -0
- package/dist/types.d.ts +67 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/v1-compat.d.ts +37 -0
- package/dist/v1-compat.d.ts.map +1 -0
- package/dist/v1-compat.js +58 -0
- package/dist/v1-compat.js.map +1 -0
- package/dist/wire.d.ts +21 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +114 -0
- package/dist/wire.js.map +1 -0
- package/package.json +53 -7
- package/index.js +0 -27
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Double Ratchet (wire format yoxall/2).
|
|
3
|
+
*
|
|
4
|
+
* Follows the Signal Double Ratchet specification
|
|
5
|
+
* (https://signal.org/docs/specifications/doubleratchet/):
|
|
6
|
+
*
|
|
7
|
+
* KDF_RK(rk, dh_out) = HKDF-SHA-256(ikm = dh_out, salt = rk,
|
|
8
|
+
* info = "weave-yoxall/2 dr-rk", 64) → (rk', ck)
|
|
9
|
+
* KDF_CK(ck) = (HMAC-SHA-256(ck, 0x02) → ck', HMAC-SHA-256(ck, 0x01) → mk)
|
|
10
|
+
* ENCRYPT(mk, pt, ad) = AES-256-GCM with key ‖ nonce = HKDF(mk, "weave-yoxall/2 dr-msg", 44)
|
|
11
|
+
*
|
|
12
|
+
* PROPERTIES
|
|
13
|
+
* - Forward secrecy: message keys are deleted after use and chain keys
|
|
14
|
+
* only move forward.
|
|
15
|
+
* - Post-compromise security: each round trip performs a fresh X25519
|
|
16
|
+
* exchange, so an attacker who stole session state stops being able
|
|
17
|
+
* to read messages once both parties have sent again.
|
|
18
|
+
* - Post-quantum session start: the initial root key comes from the
|
|
19
|
+
* hybrid X25519 + ML-KEM-768 KEM, so the first messages are
|
|
20
|
+
* protected against harvest-now-decrypt-later. (The ongoing DH
|
|
21
|
+
* ratchet is classical X25519, as in Signal; see THREAT_MODEL.md.)
|
|
22
|
+
* - Out-of-order delivery: keys for skipped messages are kept, bounded
|
|
23
|
+
* by MAX_SKIP per chain and MAX_SKIPPED_TOTAL overall.
|
|
24
|
+
* - Transactional decrypt: a forged, replayed or corrupted message
|
|
25
|
+
* throws and leaves the session unchanged.
|
|
26
|
+
*
|
|
27
|
+
* SESSION START
|
|
28
|
+
* The initiator encapsulates to the responder's hybrid public key and
|
|
29
|
+
* sends first. Until the responder replies, every initiator message
|
|
30
|
+
* carries the KEM ciphertext (the "handshake"), so losing the first
|
|
31
|
+
* message doesn't strand the session. The responder creates its
|
|
32
|
+
* session from any of those messages with acceptSession().
|
|
33
|
+
*/
|
|
34
|
+
import { createHash, createHmac } from 'node:crypto';
|
|
35
|
+
import { encapsulate, decapsulate, generateX25519, x25519 } from './kem.js';
|
|
36
|
+
import { hkdf } from './kdf.js';
|
|
37
|
+
import { aeadEncryptWithNonce, aeadDecrypt } from './aead.js';
|
|
38
|
+
export const MAX_SKIP = 1000;
|
|
39
|
+
export const MAX_SKIPPED_TOTAL = 2000;
|
|
40
|
+
const ZERO32 = new Uint8Array(32);
|
|
41
|
+
function kdfRk(rk, dhOut) {
|
|
42
|
+
const okm = hkdf(dhOut, rk, 'weave-yoxall/2 dr-rk', 64);
|
|
43
|
+
return [okm.slice(0, 32), okm.slice(32)];
|
|
44
|
+
}
|
|
45
|
+
function kdfCk(ck) {
|
|
46
|
+
const next = new Uint8Array(createHmac('sha256', ck).update(Uint8Array.of(0x02)).digest());
|
|
47
|
+
const mk = new Uint8Array(createHmac('sha256', ck).update(Uint8Array.of(0x01)).digest());
|
|
48
|
+
return [next, mk];
|
|
49
|
+
}
|
|
50
|
+
function messageKeyMaterial(mk) {
|
|
51
|
+
const okm = hkdf(mk, ZERO32, 'weave-yoxall/2 dr-msg', 44);
|
|
52
|
+
return { key: okm.slice(0, 32), nonce: okm.slice(32) };
|
|
53
|
+
}
|
|
54
|
+
export function encodeHeader(h) {
|
|
55
|
+
if (h.dh.length !== 32)
|
|
56
|
+
throw new Error('ratchet header: dh must be 32 bytes');
|
|
57
|
+
const out = new Uint8Array(40);
|
|
58
|
+
out.set(h.dh, 0);
|
|
59
|
+
const dv = new DataView(out.buffer);
|
|
60
|
+
dv.setUint32(32, h.pn, false);
|
|
61
|
+
dv.setUint32(36, h.n, false);
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
function concat(...parts) {
|
|
65
|
+
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
66
|
+
let off = 0;
|
|
67
|
+
for (const p of parts) {
|
|
68
|
+
out.set(p, off);
|
|
69
|
+
off += p.length;
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/** Session AD = SHA-256(label ‖ KEM ciphertext ‖ responder public key). */
|
|
74
|
+
function sessionAd(handshake, responder) {
|
|
75
|
+
return new Uint8Array(createHash('sha256')
|
|
76
|
+
.update('weave-yoxall/2 dr-ad')
|
|
77
|
+
.update(handshake.x25519EphemeralPublicKey)
|
|
78
|
+
.update(handshake.mlkemCiphertext)
|
|
79
|
+
.update(responder.x25519PublicKey)
|
|
80
|
+
.update(responder.mlkemPublicKey)
|
|
81
|
+
.digest());
|
|
82
|
+
}
|
|
83
|
+
function rootFromSecret(ss) {
|
|
84
|
+
const okm = hkdf(ss, ZERO32, 'weave-yoxall/2 dr-init', 64);
|
|
85
|
+
return [okm.slice(0, 32), okm.slice(32)];
|
|
86
|
+
}
|
|
87
|
+
const b64 = (u) => Buffer.from(u).toString('base64url');
|
|
88
|
+
const eq = (a, b) => !!a && a.length === b.length && Buffer.compare(Buffer.from(a), Buffer.from(b)) === 0;
|
|
89
|
+
/** Start a session as the initiator. Send first with ratchetEncrypt(). */
|
|
90
|
+
export function initiateSession(responder) {
|
|
91
|
+
const kem = encapsulate(responder, 2);
|
|
92
|
+
const [rk, ck0] = rootFromSecret(kem.sharedSecret);
|
|
93
|
+
return {
|
|
94
|
+
version: 2,
|
|
95
|
+
role: 'initiator',
|
|
96
|
+
ad: sessionAd(kem.ciphertext, responder),
|
|
97
|
+
rk,
|
|
98
|
+
dhs: generateX25519(),
|
|
99
|
+
dhr: null,
|
|
100
|
+
cks: ck0,
|
|
101
|
+
ckr: null,
|
|
102
|
+
ns: 0,
|
|
103
|
+
nr: 0,
|
|
104
|
+
pn: 0,
|
|
105
|
+
skipped: new Map(),
|
|
106
|
+
pendingHandshake: kem.ciphertext,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create the responder's session from an initiator message that carries
|
|
111
|
+
* the handshake, and decrypt that message.
|
|
112
|
+
*/
|
|
113
|
+
export function acceptSession(responder, first, associatedData) {
|
|
114
|
+
if (!first.handshake)
|
|
115
|
+
throw new Error('acceptSession: message carries no handshake (not an initiator message)');
|
|
116
|
+
const ss = decapsulate(responder, first.handshake, 2);
|
|
117
|
+
const [rk0, ck0] = rootFromSecret(ss);
|
|
118
|
+
const dhs = generateX25519();
|
|
119
|
+
const [rk, cks] = kdfRk(rk0, x25519(dhs.privateKey, first.header.dh));
|
|
120
|
+
const session = {
|
|
121
|
+
version: 2,
|
|
122
|
+
role: 'responder',
|
|
123
|
+
ad: sessionAd(first.handshake, responder),
|
|
124
|
+
rk,
|
|
125
|
+
dhs,
|
|
126
|
+
dhr: new Uint8Array(first.header.dh),
|
|
127
|
+
cks,
|
|
128
|
+
ckr: ck0,
|
|
129
|
+
ns: 0,
|
|
130
|
+
nr: 0,
|
|
131
|
+
pn: 0,
|
|
132
|
+
skipped: new Map(),
|
|
133
|
+
pendingHandshake: null,
|
|
134
|
+
};
|
|
135
|
+
const plaintext = ratchetDecrypt(session, first, associatedData);
|
|
136
|
+
return { session, plaintext };
|
|
137
|
+
}
|
|
138
|
+
/** Encrypt the next message. Mutates the session. */
|
|
139
|
+
export function ratchetEncrypt(session, plaintext, associatedData) {
|
|
140
|
+
if (!session.cks)
|
|
141
|
+
throw new Error('ratchetEncrypt: session has no sending chain');
|
|
142
|
+
const [cks, mk] = kdfCk(session.cks);
|
|
143
|
+
const header = { dh: new Uint8Array(session.dhs.publicKey), pn: session.pn, n: session.ns };
|
|
144
|
+
const { key, nonce } = messageKeyMaterial(mk);
|
|
145
|
+
const aad = concat(session.ad, encodeHeader(header), associatedData ?? new Uint8Array(0));
|
|
146
|
+
const { ciphertext } = aeadEncryptWithNonce(key, plaintext, nonce, aad);
|
|
147
|
+
session.cks = cks;
|
|
148
|
+
session.ns += 1;
|
|
149
|
+
return {
|
|
150
|
+
version: 2,
|
|
151
|
+
header,
|
|
152
|
+
...(session.pendingHandshake ? { handshake: session.pendingHandshake } : {}),
|
|
153
|
+
ciphertext,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Decrypt a message. Throws on forgery, replay, too many skipped
|
|
158
|
+
* messages or wrong associated data, and in that case the session is
|
|
159
|
+
* left exactly as it was.
|
|
160
|
+
*/
|
|
161
|
+
export function ratchetDecrypt(session, msg, associatedData) {
|
|
162
|
+
if (msg.version !== 2)
|
|
163
|
+
throw new Error(`ratchetDecrypt: unsupported message version ${msg.version}`);
|
|
164
|
+
const s = cloneSession(session);
|
|
165
|
+
const plaintext = decryptInto(s, msg, associatedData);
|
|
166
|
+
if (s.role === 'initiator')
|
|
167
|
+
s.pendingHandshake = null; // the responder has a session now
|
|
168
|
+
Object.assign(session, s);
|
|
169
|
+
return plaintext;
|
|
170
|
+
}
|
|
171
|
+
function decryptInto(s, msg, associatedData) {
|
|
172
|
+
const h = msg.header;
|
|
173
|
+
const aad = concat(s.ad, encodeHeader(h), associatedData ?? new Uint8Array(0));
|
|
174
|
+
const skippedId = `${b64(h.dh)}:${h.n}`;
|
|
175
|
+
const skippedMk = s.skipped.get(skippedId);
|
|
176
|
+
if (skippedMk) {
|
|
177
|
+
s.skipped.delete(skippedId);
|
|
178
|
+
return open(skippedMk, msg.ciphertext, aad);
|
|
179
|
+
}
|
|
180
|
+
if (!eq(s.dhr, h.dh)) {
|
|
181
|
+
skipMessageKeys(s, h.pn);
|
|
182
|
+
// DH ratchet step
|
|
183
|
+
s.pn = s.ns;
|
|
184
|
+
s.ns = 0;
|
|
185
|
+
s.nr = 0;
|
|
186
|
+
s.dhr = new Uint8Array(h.dh);
|
|
187
|
+
[s.rk, s.ckr] = kdfRk(s.rk, x25519(s.dhs.privateKey, s.dhr));
|
|
188
|
+
s.dhs = generateX25519();
|
|
189
|
+
[s.rk, s.cks] = kdfRk(s.rk, x25519(s.dhs.privateKey, s.dhr));
|
|
190
|
+
}
|
|
191
|
+
skipMessageKeys(s, h.n);
|
|
192
|
+
if (!s.ckr)
|
|
193
|
+
throw new Error('ratchetDecrypt: no receiving chain');
|
|
194
|
+
const [ckr, mk] = kdfCk(s.ckr);
|
|
195
|
+
s.ckr = ckr;
|
|
196
|
+
s.nr += 1;
|
|
197
|
+
return open(mk, msg.ciphertext, aad);
|
|
198
|
+
}
|
|
199
|
+
function skipMessageKeys(s, until) {
|
|
200
|
+
if (!s.ckr || !s.dhr)
|
|
201
|
+
return;
|
|
202
|
+
if (until - s.nr > MAX_SKIP)
|
|
203
|
+
throw new Error(`ratchetDecrypt: more than ${MAX_SKIP} skipped messages`);
|
|
204
|
+
while (s.nr < until) {
|
|
205
|
+
const [ckr, mk] = kdfCk(s.ckr);
|
|
206
|
+
s.ckr = ckr;
|
|
207
|
+
s.skipped.set(`${b64(s.dhr)}:${s.nr}`, mk);
|
|
208
|
+
s.nr += 1;
|
|
209
|
+
while (s.skipped.size > MAX_SKIPPED_TOTAL) {
|
|
210
|
+
s.skipped.delete(s.skipped.keys().next().value);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function open(mk, ciphertext, aad) {
|
|
215
|
+
const { key, nonce } = messageKeyMaterial(mk);
|
|
216
|
+
try {
|
|
217
|
+
return aeadDecrypt(key, { nonce, ciphertext, associatedData: aad });
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
throw new Error('ratchetDecrypt: authentication failed (forged, replayed, out of window, or wrong AAD)');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function cloneSession(s) {
|
|
224
|
+
const c = (u) => (u ? new Uint8Array(u) : null);
|
|
225
|
+
return {
|
|
226
|
+
...s,
|
|
227
|
+
ad: new Uint8Array(s.ad),
|
|
228
|
+
rk: new Uint8Array(s.rk),
|
|
229
|
+
dhs: { publicKey: new Uint8Array(s.dhs.publicKey), privateKey: new Uint8Array(s.dhs.privateKey) },
|
|
230
|
+
dhr: c(s.dhr),
|
|
231
|
+
cks: c(s.cks),
|
|
232
|
+
ckr: c(s.ckr),
|
|
233
|
+
skipped: new Map([...s.skipped].map(([k, v]) => [k, new Uint8Array(v)])),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/** Internal KDFs, exposed for known-answer test vectors only (not exported from the package index). */
|
|
237
|
+
export const __kdf = { kdfRk, kdfCk, messageKeyMaterial, rootFromSecret };
|
|
238
|
+
//# sourceMappingURL=double-ratchet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"double-ratchet.js","sourceRoot":"","sources":["../src/double-ratchet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE9D,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC;AAC7B,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAqCtC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;AAElC,SAAS,KAAK,CAAC,EAAc,EAAE,KAAiB;IAC9C,MAAM,G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C;QACb,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACb,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACzE,CAAC;AACJ,CAAC;AAED,uGAAuG;AACvG,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @weave_protocol/yoxallismus — EXPERIMENTAL post-quantum
|
|
3
|
+
* cryptographic composition layer for AI agents.
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ NOT AUDITED. Beta software. See THREAT_MODEL.md and SECURITY.md
|
|
6
|
+
* before use. Do not use for regulated, medical, financial, or
|
|
7
|
+
* legal data.
|
|
8
|
+
*/
|
|
9
|
+
export { STATUS } from './labels.js';
|
|
10
|
+
export { generateHybridKeypair, encapsulate, decapsulate, publicKeyOf, } from './kem.js';
|
|
11
|
+
export { aeadEncrypt, aeadDecrypt, aeadEncryptWithNonce, KEY_LEN, NONCE_LEN, TAG_LEN, } from './aead.js';
|
|
12
|
+
export { hkdf, deriveAeadKey, deriveNonce, HKDF_HASH, } from './kdf.js';
|
|
13
|
+
export { initRatchet, ratchetEncrypt, ratchetDecrypt, } from './ratchet.js';
|
|
14
|
+
export { serializePublicKey, deserializePublicKey, serializeKeypair, deserializeKeypair, serializeCiphertext, deserializeCiphertext, serializePayload, deserializePayload, } from './serialize.js';
|
|
15
|
+
export { seal, open, type SealedMessage, type SealMode, type SealOptions } from './sealed.js';
|
|
16
|
+
export { cascadeEncrypt, cascadeDecrypt, CASCADE_OVERHEAD, type CascadePayload } from './cascade.js';
|
|
17
|
+
export { initiateSession, acceptSession, ratchetEncrypt as drEncrypt, ratchetDecrypt as drDecrypt, encodeHeader, MAX_SKIP, MAX_SKIPPED_TOTAL, type DoubleRatchetSession, type RatchetMessage, type RatchetHeader, } from './double-ratchet.js';
|
|
18
|
+
export { WIRE_VERSION_2, serializeSealed, deserializeSealed, serializeRatchetMessage, deserializeRatchetMessage, serializeSession, deserializeSession, } from './wire.js';
|
|
19
|
+
export type { CombinerVersion } from './kem.js';
|
|
20
|
+
export { readV1, inspectV1, V1PayloadUnrecoverableError, type V1HeaderInfo } from './v1-compat.js';
|
|
21
|
+
export type { HybridKeypair, HybridPublicKey, EncapsulationResult, HybridCiphertext, EncryptedPayload, RatchetSession, } from './types.js';
|
|
22
|
+
import { serializeKeypair, deserializeKeypair, serializePublicKey, deserializePublicKey, serializePayload, deserializePayload, serializeCiphertext, deserializeCiphertext } from './serialize.js';
|
|
23
|
+
import type { HybridKeypair, HybridPublicKey, EncryptedPayload, HybridCiphertext } from './types.js';
|
|
24
|
+
/**
|
|
25
|
+
* The high-level "just encrypt this for that person" facade.
|
|
26
|
+
* Under the hood: hybrid KEM → HKDF → AES-256-GCM.
|
|
27
|
+
*/
|
|
28
|
+
export declare class PQCipher {
|
|
29
|
+
/** Generate a fresh hybrid keypair. */
|
|
30
|
+
static generateKeypair(): HybridKeypair;
|
|
31
|
+
/** Get the public half of a keypair for sharing. */
|
|
32
|
+
static publicKeyOf(kp: HybridKeypair): HybridPublicKey;
|
|
33
|
+
/**
|
|
34
|
+
* Encrypt a message to a recipient's public key.
|
|
35
|
+
* Returns a bundle: { ciphertext (KEM), payload (AEAD) }.
|
|
36
|
+
* Sender does not need their own keypair for this (KEM is sender-anonymous).
|
|
37
|
+
*/
|
|
38
|
+
static encryptTo(recipientPub: HybridPublicKey, plaintext: Uint8Array, associatedData?: Uint8Array): {
|
|
39
|
+
ciphertext: HybridCiphertext;
|
|
40
|
+
payload: EncryptedPayload;
|
|
41
|
+
};
|
|
42
|
+
/** Decrypt a message received from a sender. */
|
|
43
|
+
static decryptFrom(recipientPriv: HybridKeypair, ciphertext: HybridCiphertext, payload: EncryptedPayload): Uint8Array;
|
|
44
|
+
/** All serialization helpers exposed as static methods. */
|
|
45
|
+
static serializeKeypair: typeof serializeKeypair;
|
|
46
|
+
static deserializeKeypair: typeof deserializeKeypair;
|
|
47
|
+
static serializePublicKey: typeof serializePublicKey;
|
|
48
|
+
static deserializePublicKey: typeof deserializePublicKey;
|
|
49
|
+
static serializePayload: typeof serializePayload;
|
|
50
|
+
static deserializePayload: typeof deserializePayload;
|
|
51
|
+
static serializeCiphertext: typeof serializeCiphertext;
|
|
52
|
+
static deserializeCiphertext: typeof deserializeCiphertext;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,WAAW,EACX,WAAW,GACZ,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,WAAW,EACX,WAAW,EACX,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,OAAO,GACR,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,IAAI,EACJ,aAAa,EACb,WAAW,EACX,SAAS,GACV,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ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AAc,CAAC,EAAE,UAAU,GAC1B;QAAE,UAAU,EAAE,gBAAgB,CAAC;QAAC,OAAO,EAAE,gBAAgB,CAAA;KAAE;IAS9D,gDAAgD;IAChD,MAAM,CAAC,WAAW,CAChB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,gBAAgB,EAC5B,OAAO,EAAE,gBAAgB,GACxB,UAAU;IAMb,2DAA2D;IAC3D,MAAM,CAAC,gBAAgB,0BAAoB;IAC3C,MAAM,CAAC,kBAAkB,4BAAsB;IAC/C,MAAM,CAAC,kBAAkB,4BAAsB;IAC/C,MAAM,CAAC,oBAAoB,8BAAwB;IACnD,MAAM,CAAC,gBAAgB,0BAAoB;IAC3C,MAAM,CAAC,kBAAkB,4BAAsB;IAC/C,MAAM,CAAC,mBAAmB,6BAAuB;IACjD,MAAM,CAAC,qBAAqB,+BAAyB;CACtD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @weave_protocol/yoxallismus — EXPERIMENTAL post-quantum
|
|
3
|
+
* cryptographic composition layer for AI agents.
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ NOT AUDITED. Beta software. See THREAT_MODEL.md and SECURITY.md
|
|
6
|
+
* before use. Do not use for regulated, medical, financial, or
|
|
7
|
+
* legal data.
|
|
8
|
+
*/
|
|
9
|
+
import { showBetaBanner } from './labels.js';
|
|
10
|
+
// Show the beta warning banner on first import (silenceable via env var)
|
|
11
|
+
showBetaBanner();
|
|
12
|
+
// ─── Public API ─────────────────────────────────────────────────
|
|
13
|
+
// Labels & status metadata
|
|
14
|
+
export { STATUS } from './labels.js';
|
|
15
|
+
// KEM
|
|
16
|
+
export { generateHybridKeypair, encapsulate, decapsulate, publicKeyOf, } from './kem.js';
|
|
17
|
+
// AEAD
|
|
18
|
+
export { aeadEncrypt, aeadDecrypt, aeadEncryptWithNonce, KEY_LEN, NONCE_LEN, TAG_LEN, } from './aead.js';
|
|
19
|
+
// KDF
|
|
20
|
+
export { hkdf, deriveAeadKey, deriveNonce, HKDF_HASH, } from './kdf.js';
|
|
21
|
+
// Ratchet (v0.1 symmetric ratchet — deprecated; use initiateSession/acceptSession)
|
|
22
|
+
export { initRatchet, ratchetEncrypt, ratchetDecrypt, } from './ratchet.js';
|
|
23
|
+
// Serialization
|
|
24
|
+
export { serializePublicKey, deserializePublicKey, serializeKeypair, deserializeKeypair, serializeCiphertext, deserializeCiphertext, serializePayload, deserializePayload, } from './serialize.js';
|
|
25
|
+
// v0.2: sealed boxes, cascade AEAD, double ratchet, locked yoxall/2 wire format
|
|
26
|
+
export { seal, open } from './sealed.js';
|
|
27
|
+
export { cascadeEncrypt, cascadeDecrypt, CASCADE_OVERHEAD } from './cascade.js';
|
|
28
|
+
export { initiateSession, acceptSession, ratchetEncrypt as drEncrypt, ratchetDecrypt as drDecrypt, encodeHeader, MAX_SKIP, MAX_SKIPPED_TOTAL, } from './double-ratchet.js';
|
|
29
|
+
export { WIRE_VERSION_2, serializeSealed, deserializeSealed, serializeRatchetMessage, deserializeRatchetMessage, serializeSession, deserializeSession, } from './wire.js';
|
|
30
|
+
// v1 (Hord YoxallismusCipher): detection only, v1 payloads are unrecoverable
|
|
31
|
+
export { readV1, inspectV1, V1PayloadUnrecoverableError } from './v1-compat.js';
|
|
32
|
+
// ─── High-level facade ──────────────────────────────────────────
|
|
33
|
+
import { generateHybridKeypair, encapsulate, decapsulate, publicKeyOf, } from './kem.js';
|
|
34
|
+
import { aeadEncrypt, aeadDecrypt } from './aead.js';
|
|
35
|
+
import { deriveAeadKey } from './kdf.js';
|
|
36
|
+
import { serializeKeypair, deserializeKeypair, serializePublicKey, deserializePublicKey, serializePayload, deserializePayload, serializeCiphertext, deserializeCiphertext, } from './serialize.js';
|
|
37
|
+
/**
|
|
38
|
+
* The high-level "just encrypt this for that person" facade.
|
|
39
|
+
* Under the hood: hybrid KEM → HKDF → AES-256-GCM.
|
|
40
|
+
*/
|
|
41
|
+
export class PQCipher {
|
|
42
|
+
/** Generate a fresh hybrid keypair. */
|
|
43
|
+
static generateKeypair() {
|
|
44
|
+
return generateHybridKeypair();
|
|
45
|
+
}
|
|
46
|
+
/** Get the public half of a keypair for sharing. */
|
|
47
|
+
static publicKeyOf(kp) {
|
|
48
|
+
return publicKeyOf(kp);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Encrypt a message to a recipient's public key.
|
|
52
|
+
* Returns a bundle: { ciphertext (KEM), payload (AEAD) }.
|
|
53
|
+
* Sender does not need their own keypair for this (KEM is sender-anonymous).
|
|
54
|
+
*/
|
|
55
|
+
static encryptTo(recipientPub, plaintext, associatedData) {
|
|
56
|
+
// PQCipher is the v0.1 API and keeps the v0.1 combiner so existing
|
|
57
|
+
// data still decrypts. New code should use seal()/open().
|
|
58
|
+
const kem = encapsulate(recipientPub, 1);
|
|
59
|
+
const aeadKey = deriveAeadKey(kem.sharedSecret, 'weave-yoxall v0.1 pqcipher-encrypt');
|
|
60
|
+
const payload = aeadEncrypt(aeadKey, plaintext, associatedData);
|
|
61
|
+
return { ciphertext: kem.ciphertext, payload };
|
|
62
|
+
}
|
|
63
|
+
/** Decrypt a message received from a sender. */
|
|
64
|
+
static decryptFrom(recipientPriv, ciphertext, payload) {
|
|
65
|
+
const sharedSecret = decapsulate(recipientPriv, ciphertext, 1);
|
|
66
|
+
const aeadKey = deriveAeadKey(sharedSecret, 'weave-yoxall v0.1 pqcipher-encrypt');
|
|
67
|
+
return aeadDecrypt(aeadKey, payload);
|
|
68
|
+
}
|
|
69
|
+
/** All serialization helpers exposed as static methods. */
|
|
70
|
+
static serializeKeypair = serializeKeypair;
|
|
71
|
+
static deserializeKeypair = deserializeKeypair;
|
|
72
|
+
static serializePublicKey = serializePublicKey;
|
|
73
|
+
static deserializePublicKey = deserializePublicKey;
|
|
74
|
+
static serializePayload = serializePayload;
|
|
75
|
+
static deserializePayload = deserializePayload;
|
|
76
|
+
static serializeCiphertext = serializeCiphertext;
|
|
77
|
+
static deserializeCiphertext = deserializeCiphertext;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAU,MAAM,aAAa,CAAC;AAErD,yEAAyE;AACzE,cAAc,EAAE,CAAC;AAEjB,mEAAmE;AAEnE,2BAA2B;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM;AACN,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,WAAW,EACX,WAAW,GACZ,MAAM,UAAU,CAAC;AAElB,OAAO;AACP,OAAO,EACL,WAAW,EACX,WAAW,EACX,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,OAAO,GACR,MAAM,WAAW,CAAC;AAEnB,MAAM;AACN,OAAO,EACL,IAAI,EACJ,aAAa,EACb,WAAW,EACX,SAAS,GACV,MAAM,UAAU,CAAC;AAElB,mFAAmF;AACnF,OAAO,EACL,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,gBAAgB;AAChB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,gFAAgF;AAChF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAuD,MAAM,aAAa,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAuB,MAAM,cAAc,CAAC;AACrG,OAAO,EACL,eAAe,EACf,aAAa,EACb,cAAc,IAAI,SAAS,EAC3B,cAAc,IAAI,SAAS,EAC3B,YAAY,EACZ,QAAQ,EACR,iBAAiB,GAIlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,cAAc,EACd,eA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WAAW,CAChB,aAA4B,EAC5B,UAA4B,EAC5B,OAAyB;QAEzB,MAAM,YAAY,GAAG,WAAW,CAAC,aAAa,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QAC/D,MAAM,OAAO,GAAG,aAAa,CAAC,YAAY,EAAE,oCAAoC,CAAC,CAAC;QAClF,OAAO,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,2DAA2D;IAC3D,MAAM,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,MAAM,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,MAAM,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,MAAM,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IACnD,MAAM,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,MAAM,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,MAAM,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACjD,MAAM,CAAC,qBAAqB,GAAG,qBAAqB,CAAC"}
|
package/dist/kdf.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HKDF (HMAC-based Key Derivation Function) wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Uses Node's built-in HKDF via crypto.hkdfSync. SHA-256 chosen for v0.1
|
|
5
|
+
* because it's ubiquitous and fast; the reduced quantum strength (~128
|
|
6
|
+
* bits via Grover) is adequate for the beta scope.
|
|
7
|
+
*
|
|
8
|
+
* DESIGN NOTES:
|
|
9
|
+
* - We use HKDF-Extract-then-Expand as a single hkdfSync call
|
|
10
|
+
* - Salt SHOULD be a random per-session value when combining independent
|
|
11
|
+
* shared secrets (as in PQ-hybrid KEM combination)
|
|
12
|
+
* - Info SHOULD be an application-context string ("weave-yoxall v0.1
|
|
13
|
+
* kem-combine", "chain-key-advance", etc.) — this domain-separates
|
|
14
|
+
* derived keys so a leak in one context doesn't cross-contaminate
|
|
15
|
+
*/
|
|
16
|
+
export declare const HKDF_HASH = "sha256";
|
|
17
|
+
export declare const HKDF_OUTPUT_LEN = 32;
|
|
18
|
+
/**
|
|
19
|
+
* Derive `length` bytes of keying material from an input keying material,
|
|
20
|
+
* salt, and info context string.
|
|
21
|
+
*/
|
|
22
|
+
export declare function hkdf(inputKeyMaterial: Uint8Array, salt: Uint8Array, info: string | Uint8Array, length?: number): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* Derive a 32-byte AEAD key from a shared secret and a context info string.
|
|
25
|
+
* Convenience wrapper — most callers want this.
|
|
26
|
+
*/
|
|
27
|
+
export declare function deriveAeadKey(sharedSecret: Uint8Array, info: string, salt?: Uint8Array): Uint8Array;
|
|
28
|
+
/**
|
|
29
|
+
* Derive a 12-byte AEAD nonce deterministically from a chain key + counter.
|
|
30
|
+
* This is what the ratchet uses to avoid random-nonce reuse across sessions.
|
|
31
|
+
*/
|
|
32
|
+
export declare function deriveNonce(chainKey: Uint8Array, counter: number): Uint8Array;
|
|
33
|
+
//# sourceMappingURL=kdf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kdf.d.ts","sourceRoot":"","sources":["../src/kdf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC;;;GAGG;AACH,wBAAgB,IAAI,CAClB,gBAAgB,EAAE,UAAU,EAC5B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,MAAM,GAAE,MAAwB,GAC/B,UAAU,CAUZ;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,UAAU,CAEnG;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CAK7E"}
|
package/dist/kdf.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HKDF (HMAC-based Key Derivation Function) wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Uses Node's built-in HKDF via crypto.hkdfSync. SHA-256 chosen for v0.1
|
|
5
|
+
* because it's ubiquitous and fast; the reduced quantum strength (~128
|
|
6
|
+
* bits via Grover) is adequate for the beta scope.
|
|
7
|
+
*
|
|
8
|
+
* DESIGN NOTES:
|
|
9
|
+
* - We use HKDF-Extract-then-Expand as a single hkdfSync call
|
|
10
|
+
* - Salt SHOULD be a random per-session value when combining independent
|
|
11
|
+
* shared secrets (as in PQ-hybrid KEM combination)
|
|
12
|
+
* - Info SHOULD be an application-context string ("weave-yoxall v0.1
|
|
13
|
+
* kem-combine", "chain-key-advance", etc.) — this domain-separates
|
|
14
|
+
* derived keys so a leak in one context doesn't cross-contaminate
|
|
15
|
+
*/
|
|
16
|
+
import { hkdfSync } from 'node:crypto';
|
|
17
|
+
export const HKDF_HASH = 'sha256';
|
|
18
|
+
export const HKDF_OUTPUT_LEN = 32;
|
|
19
|
+
/**
|
|
20
|
+
* Derive `length` bytes of keying material from an input keying material,
|
|
21
|
+
* salt, and info context string.
|
|
22
|
+
*/
|
|
23
|
+
export function hkdf(inputKeyMaterial, salt, info, length = HKDF_OUTPUT_LEN) {
|
|
24
|
+
const infoBytes = typeof info === 'string' ? new TextEncoder().encode(info) : info;
|
|
25
|
+
const derived = hkdfSync(HKDF_HASH, Buffer.from(inputKeyMaterial), Buffer.from(salt), Buffer.from(infoBytes), length);
|
|
26
|
+
return new Uint8Array(derived);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Derive a 32-byte AEAD key from a shared secret and a context info string.
|
|
30
|
+
* Convenience wrapper — most callers want this.
|
|
31
|
+
*/
|
|
32
|
+
export function deriveAeadKey(sharedSecret, info, salt) {
|
|
33
|
+
return hkdf(sharedSecret, salt || new Uint8Array(32), info, 32);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Derive a 12-byte AEAD nonce deterministically from a chain key + counter.
|
|
37
|
+
* This is what the ratchet uses to avoid random-nonce reuse across sessions.
|
|
38
|
+
*/
|
|
39
|
+
export function deriveNonce(chainKey, counter) {
|
|
40
|
+
const counterBytes = new Uint8Array(8);
|
|
41
|
+
const dv = new DataView(counterBytes.buffer);
|
|
42
|
+
dv.setBigUint64(0, BigInt(counter), false);
|
|
43
|
+
return hkdf(chainKey, counterBytes, 'weave-yoxall v0.1 nonce-derive', 12);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=kdf.js.map
|
package/dist/kdf.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kdf.js","sourceRoot":"","sources":["../src/kdf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;AAClC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,IAAI,CAClB,gBAA4B,EAC5B,IAAgB,EAChB,IAAyB,EACzB,SAAiB,eAAe;IAEhC,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnF,MAAM,OAAO,GAAG,QAAQ,CACtB,SAAS,EACT,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAC7B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EACjB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EACtB,MAAM,CACP,CAAC;IACF,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,YAAwB,EAAE,IAAY,EAAE,IAAiB;IACrF,OAAO,IAAI,CAAC,YAAY,EAAE,IAAI,IAAI,IAAI,UAAU,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,QAAoB,EAAE,OAAe;IAC/D,MAAM,YAAY,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IACvC,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7C,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;IAC3C,OAAO,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE,gCAAgC,EAAE,EAAE,CAAC,CAAC;AAC5E,CAAC"}
|
package/dist/kem.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PQ-hybrid Key Encapsulation Mechanism.
|
|
3
|
+
*
|
|
4
|
+
* Combines X25519 (classical elliptic-curve KEM) with ML-KEM-768
|
|
5
|
+
* (post-quantum lattice KEM, NIST FIPS 203) via HKDF-SHA-256.
|
|
6
|
+
*
|
|
7
|
+
* The security guarantee: an attacker must break BOTH primitives to
|
|
8
|
+
* recover the shared secret. If Shor's algorithm arrives and breaks
|
|
9
|
+
* X25519, the ML-KEM component keeps the secret confidential. If a
|
|
10
|
+
* classical or quantum attack on ML-KEM emerges, X25519 keeps the
|
|
11
|
+
* secret confidential.
|
|
12
|
+
*
|
|
13
|
+
* This is the same construction Signal ships as PQXDH and Cloudflare
|
|
14
|
+
* ships as X25519Kyber768Draft00 in TLS 1.3. The design pattern is
|
|
15
|
+
* well-established; the primitives are NIST-standardized.
|
|
16
|
+
*
|
|
17
|
+
* COMBINERS
|
|
18
|
+
* v2 (default, wire format yoxall/2):
|
|
19
|
+
* ss = HKDF-SHA-256(ikm = ss_mlkem || ss_x25519 || eph_x25519_pub || recip_x25519_pub,
|
|
20
|
+
* salt = 32 zero bytes, info = "weave-yoxall/2 kem-combine")
|
|
21
|
+
* Same shape as X-Wing: binding the X25519 ephemeral and recipient
|
|
22
|
+
* public keys means the combined secret is IND-CCA even if only the
|
|
23
|
+
* X25519 half is relied on. ML-KEM is already IND-CCA, so its
|
|
24
|
+
* ciphertext doesn't need to be hashed in.
|
|
25
|
+
* v1 (legacy, v0.1.0-beta.0): HKDF over ss_x25519 || ss_mlkem, salted
|
|
26
|
+
* with the recipient public keys, without the ephemeral key. Kept
|
|
27
|
+
* only so data from v0.1 can still be decrypted (YOXALL-2026-002).
|
|
28
|
+
*
|
|
29
|
+
* WIRE FORMAT (byte sizes, unchanged since v0.1):
|
|
30
|
+
* Public key: [X25519 32B][ML-KEM-768 pub 1184B] = 1216 bytes
|
|
31
|
+
* Private key: [X25519 32B][ML-KEM-768 priv 2400B] = 2432 bytes
|
|
32
|
+
* Ciphertext: [X25519 eph pub 32B][ML-KEM-768 ct 1088B] = 1120 bytes
|
|
33
|
+
* Shared sec: 32 bytes (HKDF-combined)
|
|
34
|
+
*/
|
|
35
|
+
import type { HybridKeypair, HybridPublicKey, EncapsulationResult, HybridCiphertext } from './types.js';
|
|
36
|
+
/** KEM combiner version: 2 (default) or 1 (legacy v0.1 data only). */
|
|
37
|
+
export type CombinerVersion = 1 | 2;
|
|
38
|
+
/**
|
|
39
|
+
* Generate a fresh hybrid keypair. Both halves are generated with
|
|
40
|
+
* independent randomness from Node's crypto RNG.
|
|
41
|
+
*/
|
|
42
|
+
export declare function generateHybridKeypair(): HybridKeypair;
|
|
43
|
+
/**
|
|
44
|
+
* Encapsulate a shared secret to the recipient's hybrid public key.
|
|
45
|
+
*
|
|
46
|
+
* Returns:
|
|
47
|
+
* - sharedSecret: 32 bytes that both parties will hold
|
|
48
|
+
* - ciphertext: the hybrid KEM output that recipient decapsulates
|
|
49
|
+
*/
|
|
50
|
+
export declare function encapsulate(recipientPub: HybridPublicKey, version?: CombinerVersion): EncapsulationResult;
|
|
51
|
+
/**
|
|
52
|
+
* Deterministic encapsulation from caller-supplied randomness. Used for
|
|
53
|
+
* known-answer test vectors only — NEVER call with non-random inputs in
|
|
54
|
+
* real use. Not exported from the package index.
|
|
55
|
+
*/
|
|
56
|
+
export declare function encapsulateWith(recipientPub: HybridPublicKey, version: CombinerVersion, x25519EphemeralPrivate: Uint8Array, mlkemRandomness: Uint8Array): EncapsulationResult;
|
|
57
|
+
/**
|
|
58
|
+
* Decapsulate a shared secret from a ciphertext using the recipient's
|
|
59
|
+
* private key. Both halves must succeed; either failure means the
|
|
60
|
+
* derived shared secret will not match the sender's.
|
|
61
|
+
*
|
|
62
|
+
* ML-KEM has "implicit rejection" — a malformed ML-KEM ciphertext
|
|
63
|
+
* doesn't throw, it silently returns garbage. That's a feature (it
|
|
64
|
+
* prevents timing attacks) but means the caller MUST verify the
|
|
65
|
+
* shared secret was correct out-of-band (typically via AEAD auth-tag
|
|
66
|
+
* verification on subsequent messages).
|
|
67
|
+
*/
|
|
68
|
+
export declare function decapsulate(recipientPriv: HybridKeypair, ct: HybridCiphertext, version?: CombinerVersion): Uint8Array;
|
|
69
|
+
export declare function publicKeyOf(kp: HybridKeypair): HybridPublicKey;
|
|
70
|
+
/** Deterministic keypair from seeds — known-answer test vectors only. */
|
|
71
|
+
export declare function keypairFromSeeds(x25519Private: Uint8Array, mlkemSeed: Uint8Array): HybridKeypair;
|
|
72
|
+
/** Raw X25519 Diffie-Hellman on 32-byte keys (used by the double ratchet). */
|
|
73
|
+
export declare function x25519(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
|
|
74
|
+
/** Fresh raw X25519 keypair (used by the double ratchet). */
|
|
75
|
+
export declare function generateX25519(): {
|
|
76
|
+
publicKey: Uint8Array;
|
|
77
|
+
privateKey: Uint8Array;
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=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