identity: the SD-JWT form of an AERE hybrid identity is judged on its ML-DSA-65 half by default, the Ed25519 half only on explicit request, and every verdict says postQuantum (rule sdjwt.hybrid-half); pq-pki: the signature algorithm a certificate or a revocation list declares must be its issuer key's (ALG_KEY, CRL_ALG_KEY); agents: an equivocation proof requires the agent's ML-DSA-65 key; pq-gateway: the status names the path to the backend and hybrid-only refuses a plain-HTTP backend; conformance 241 rules, 631 vectors

This commit is contained in:
Aere Network committed 2026-10-19 05:19:21 +03:00
1 parent 3ff21f7758
commit 0c8f1de3fd
122 files changed
+1205 -262

No files matched your search

+25 -15
View File
@@ -18,8 +18,12 @@
// CE NU FACE: nu aduce nimic de pe internet (nici metadatele de tip ale lui `vct`, s.5, nici lista de stare: verificatorul le aduce si le da,
// ca `--status-list` la credentialul AERE); nu rezolva cheia emitentului din `iss` (s.2.5: JWT VC Issuer Metadata sau x5c): cheia e intrarea
// verificatorului, niciodata din jeton; nu e mdoc (ISO/IEC 18013-5, CBOR/COSE): formatul de proximitate al ARF e alt format, nefacut aici.
//
// AIP-25 C1 (2026-10-19, D-535): lista de stare a unui emitent AERE se semneaza si se judeca implicit cu jumatatea ML-DSA-65 a cheilor lui,
// ca jetonul (sdjwt.mjs); jumatatea Ed25519 numai cu classicalHalf: true. Altfel cine spargea numai cheia clasica putea "dezrevoca" un
// credential cu o lista semnata de ea. `postQuantum` al verdictului VC e true numai daca si lista judecata e ML-DSA-65.
import zlib from 'node:zlib';
import { issueSdJwt, presentSdJwt, verifySdJwt, publicJwk, verifyJws, signJws, privateKeyOf, ALGS } from './sdjwt.mjs';
import { issueSdJwt, presentSdJwt, verifySdJwt, verifyJws, signJws, privateKeyOf, judgedJwk, headerAlgOf, defaultAlg, ALGS } from './sdjwt.mjs';
export const TYP_VC = 'dc+sd-jwt';
export const TYP_STATUS_LIST = 'statuslist+jwt';
@@ -66,8 +70,9 @@ export function issueSdJwtVc({ vct, vctIntegrity, status, claims = {}, disclosab
* fiecare sub 2^bits; bits din {1, 2, 4, 8}. Impachetarea (s.4.1): indexul i sta la octetul floor(i*bits/8), de la bitul (i*bits) mod 8, adica
* de la bitul cel mai putin semnificativ catre cel mai semnificativ. lst = base64url(ZLIB(DEFLATE(octeti))).
*/
export function issueStatusListJwt({ issuer, alg = 'EdDSA', uri, statuses, bits = 1, iat = Math.floor(Date.now() / 1000), exp, ttl, aggregationUri }) {
if (!ALGS.includes(alg)) throw new Error('status-list: unknown alg');
export function issueStatusListJwt({ issuer, alg, classicalHalf = false, uri, statuses, bits = 1, iat = Math.floor(Date.now() / 1000), exp, ttl, aggregationUri }) {
const algL = alg ?? defaultAlg(issuer); // AIP-25 C1: ML-DSA-65 pentru chei AERE
if (!ALGS.includes(algL)) throw new Error('status-list: unknown alg');
if (typeof uri !== 'string' || !uri) throw new Error('status-list: uri (the sub of the token) is required');
if (![1, 2, 4, 8].includes(bits)) throw new Error('status-list: bits is 1, 2, 4 or 8');
if (!Array.isArray(statuses) || !statuses.length || !statuses.every((s) => Number.isInteger(s) && s >= 0 && s < 2 ** bits)) throw new Error(`status-list: statuses is a non-empty list of integers below 2^${bits}`);
@@ -75,20 +80,22 @@ export function issueStatusListJwt({ issuer, alg = 'EdDSA', uri, statuses, bits
statuses.forEach((s, i) => { octeti[Math.floor(i * bits / 8)] |= s << ((i * bits) % 8); });
const lst = b64u(zlib.deflateSync(octeti, { level: 9 }));
const corp = { sub: uri, iat, ...(exp != null ? { exp } : {}), ...(ttl != null ? { ttl } : {}), status_list: { bits, lst, ...(aggregationUri ? { aggregation_uri: aggregationUri } : {}) } };
return signJws({ alg, typ: TYP_STATUS_LIST }, corp, privateKeyOf(issuer, alg));
return signJws({ alg: algL, typ: TYP_STATUS_LIST }, corp, privateKeyOf(issuer, algL, classicalHalf));
}
/**
* Citeste si verifica un Status List Token JWT cu cheia DATA (a emitentului listei; de obicei emitentul credentialului), pentru URI-ul cerut.
* Intoarce { ok, reason, entries, bits, statusAt(idx) -> 0..2^bits-1 sau null (dincolo de lista), payload }. Toate verificarile de aici
* Cu chei AERE se judeca implicit jumatatea ML-DSA-65; jumatatea Ed25519 numai cu classicalHalf (AIP-25 C1).
* Intoarce { ok, reason, entries, bits, statusAt(idx) -> 0..2^bits-1 sau null (dincolo de lista), payload, alg }. Toate verificarile de aici
* sunt regula `status-list` a profilului.
*/
export function readStatusListJwt(jwt, { key, alg = 'EdDSA', uri, now = new Date(), clockSkewS = 60 } = {}) {
const nu = (reason) => ({ ok: false, reason, entries: 0, bits: 0, statusAt: () => null, payload: null });
export function readStatusListJwt(jwt, { key, alg, classicalHalf = false, uri, now = new Date(), clockSkewS = 60 } = {}) {
const nu = (reason) => ({ ok: false, reason, entries: 0, bits: 0, statusAt: () => null, payload: null, alg: null });
const motiv = (e) => String((e && e.message) || e).replace(/^sd-jwt: /, '');
// semnatura, typ-ul si potrivirea alg/cheie le judeca verifyJws (o lista semnata ML-DSA-65 judecata cu cheia Ed25519 cade acolo: "does not match")
let corp = {};
try { ({ corp } = verifyJws(jwt, publicJwk(key, alg), { typ: TYP_STATUS_LIST })); } catch (e) { if (!(false /*PAZA:status-list*/)) return nu(motiv(e)); }
// semnatura, typ-ul si potrivirea alg/cheie le judeca verifyJws (o lista semnata ML-DSA-65 judecata cu cheia Ed25519 cade acolo: "does not match");
// jumatatea cheilor AERE o alege judgedJwk (o lista semnata numai cu jumatatea Ed25519 cade acolo, "Ed25519 half", fara classicalHalf)
let corp = {}, antet = {};
try { ({ antet, corp } = verifyJws(jwt, judgedJwk(key, alg, { classicalHalf, headerAlg: headerAlgOf(jwt) }), { typ: TYP_STATUS_LIST })); } catch (e) { if (!(false /*PAZA:status-list*/)) return nu(motiv(e)); }
if (!(typeof uri === 'string' && !!uri /*PAZA:status-list*/)) return nu('the verifier must give the uri the list was fetched for');
if (!(corp.sub === uri /*PAZA:status-list*/)) return nu(`sub ${JSON.stringify(corp.sub)} is not the uri referenced (${uri})`);
const acum = Math.floor(new Date(now).getTime() / 1000);
@@ -104,7 +111,7 @@ export function readStatusListJwt(jwt, { key, alg = 'EdDSA', uri, now = new Date
} catch (e) { if (!(false /*PAZA:status-list*/)) return nu('lst cannot be inflated: ' + String(e.message || e).slice(0, 80)); }
const bits = obiect(sl) && [1, 2, 4, 8].includes(sl.bits) ? sl.bits : 1, entries = Math.floor(octeti.length * 8 / bits);
const statusAt = (idx) => (Number.isInteger(idx) && idx >= 0 && idx < entries ? (octeti[Math.floor(idx * bits / 8)] >> ((idx * bits) % 8)) & ((1 << bits) - 1) : null);
return { ok: true, reason: '', entries, bits, statusAt, payload: corp };
return { ok: true, reason: '', entries, bits, statusAt, payload: corp, alg: antet.alg };
}
/**
@@ -116,7 +123,7 @@ export function readStatusListJwt(jwt, { key, alg = 'EdDSA', uri, now = new Date
* regula care a refuzat (a profilului sau a lui sdjwt.mjs), null cand e valid.
*/
export function verifySdJwtVc(token, { expectedVct, statusListJwt = null, statusListKey = null, statusListAlg = null, requireStatus = true, expectedTyp = TYP_VC, ...o } = {}) {
const refuz = (rule, reason, extra = {}) => ({ valid: false, rule, reason, payload: null, disclosed: [], keyBinding: null, vct: null, status: null, ...extra });
const refuz = (rule, reason, extra = {}) => ({ valid: false, rule, reason, payload: null, disclosed: [], keyBinding: null, postQuantum: false, vct: null, status: null, ...extra });
const vcts = Array.isArray(expectedVct) ? expectedVct : expectedVct == null ? null : [expectedVct];
if (!(Array.isArray(vcts) && vcts.length > 0 && vcts.every((v) => typeof v === 'string' && !!v) /*PAZA:vct-expected*/)) return refuz('vct-expected', 'the verifier must name the vct it expects (expectedVct)');
const tipuri = Array.isArray(vcts) ? vcts : [];
@@ -128,7 +135,7 @@ export function verifySdJwtVc(token, { expectedVct, statusListJwt = null, status
const dez = r.disclosed.filter((n) => NEDEZVALUIBILE.includes(n));
if (!(dez.length === 0 /*PAZA:disclosed-protected*/)) return refuz('disclosed-protected', `${dez[0]} was selectively disclosed; an SD-JWT VC carries it in the clear (s.2.2.2.3)`);
if (!(p['vct#integrity'] === undefined || typeof p['vct#integrity'] === 'string' /*PAZA:form*/)) return refuz('form', 'vct#integrity is not a string');
let status = { present: false, judged: false };
let status = { present: false, judged: false }, pqLista = true;
if (p.status !== undefined) {
if (!(obiect(p.status) /*PAZA:form*/)) return refuz('form', 'status is not an object');
const ref = obiect(p.status) ? p.status.status_list : undefined;
@@ -138,7 +145,9 @@ export function verifySdJwtVc(token, { expectedVct, statusListJwt = null, status
if (!(e === null /*PAZA:form*/)) return refuz('form', 'status.status_list: ' + e);
status.uri = ref.uri; status.idx = ref.idx;
if (statusListJwt != null) {
const l = readStatusListJwt(statusListJwt, { key: statusListKey ?? o.issuerKey, alg: statusListAlg ?? o.issuerAlg ?? 'EdDSA', uri: ref.uri, now: o.now, clockSkewS: o.clockSkewS });
// AIP-25 C1: fara statusListAlg, o lista a unei chei AERE se judeca pe jumatatea ML-DSA-65 (Ed25519 numai cu classicalHalf)
const l = readStatusListJwt(statusListJwt, { key: statusListKey ?? o.issuerKey, alg: statusListAlg ?? o.issuerAlg, classicalHalf: o.classicalHalf, uri: ref.uri, now: o.now, clockSkewS: o.clockSkewS });
pqLista = l.alg === 'ML-DSA-65';
if (!(l.ok /*PAZA:status-list*/)) return refuz('status-list', 'status list: ' + l.reason, { vct: p.vct, status });
const v = l.statusAt(ref.idx);
if (!(v !== null /*PAZA:status-index*/)) return refuz('status-index', `status list: index ${ref.idx} is beyond the list (${l.entries} entries)`, { vct: p.vct, status });
@@ -148,5 +157,6 @@ export function verifySdJwtVc(token, { expectedVct, statusListJwt = null, status
}
if (!(status.judged || !requireStatus /*PAZA:status-unjudged*/)) return refuz('status-unjudged', `the credential names a status (${status.mechanism}) that was not judged: give statusListJwt fetched from ${status.uri ?? 'the issuer'}, or set requireStatus:false`, { vct: p.vct, status });
}
return { ...r, vct: p.vct, status };
// AIP-25 C1: post-cuantic numai daca si lista de stare judecata (cand a fost judecata) e semnata ML-DSA-65
return { ...r, postQuantum: r.postQuantum && pqLista, vct: p.vct, status };
}