conformance: 97 rules of 9 verifiers, 206 vectors; verify-layer and agents refuse a classical key under an ML-DSA-65 name; market-settlement reads the notarization time from the certified read; proof-of-ai README in English

This commit is contained in:
Aere Network committed 2026-10-05 17:17:59 +03:00
1 parent c9f2932e04
commit c9798a0013
111 files changed
+15871 -292

No files matched your search

+23 -19
View File
@@ -33,14 +33,18 @@ export function capDeArbore(intrari, { host = 'sidecar', createdAt = new Date().
const plic = { v: 1, kind: TREE_HEAD + '-attestation', statement, statementHash: sha256(Buffer.from(JSON.stringify(statement), 'utf8')) };
return signKeyPem ? semneazaCap(plic, signKeyPem) : plic;
}
// Every refusal of the checks below NAMES its rule (`regula`); the refusals of a head's signature carry the rules of the sidecar
// (cap-*). Each check of a rule carries its marker (see sidecar.mjs).
export const REGULI = ['dovada-forma', 'arbore-forma', 'arbore-hash', 'includere-index', 'includere-intrare', 'includere-plic', 'includere-frunza', 'includere-drum', 'includere-cap', 'consistenta-inceput', 'consistenta-sfarsit', 'consistenta'];
const refuz = (regula, motiv) => { if (!REGULI.includes(regula)) throw new Error('tree: undeclared rule ' + regula); return { ok: false, regula, motiv }; };
// un cap de arbore intreg (statementHash se reface), semnat de cine se cere (daca se cere)
function capBun(cap, semnatar) {
const st = cap && cap.statement;
if (!cap || cap.kind !== TREE_HEAD + '-attestation' || !st || st.kind !== TREE_HEAD) return { ok: false, motiv: `not an ${TREE_HEAD} attestation` };
if (!H.test(String(cap.statementHash)) || sha256(Buffer.from(JSON.stringify(st), 'utf8')) !== cap.statementHash) return { ok: false, motiv: 'the tree head statementHash does not match its statement (modified head)' };
if (!Number.isInteger(st.treeSize) || st.treeSize < 1 || !H.test(String(st.rootHash))) return { ok: false, motiv: 'the tree head has no valid size and root' };
if (!(!!cap && cap.kind === TREE_HEAD + '-attestation' && !!st && st.kind === TREE_HEAD /*PAZA:arbore-forma*/)) return refuz('arbore-forma', `not an ${TREE_HEAD} attestation`);
if (!(!!cap && H.test(String(cap.statementHash)) && sha256(Buffer.from(String(JSON.stringify(st)), 'utf8')) === cap.statementHash /*PAZA:arbore-hash*/)) return refuz('arbore-hash', 'the tree head statementHash does not match its statement (modified head)');
if (!(!!st && Number.isInteger(st.treeSize) && st.treeSize >= 1 && H.test(String(st.rootHash)) /*PAZA:arbore-forma*/)) return refuz('arbore-forma', 'the tree head has no valid size and root');
const s = verificaSemnaturaCap(cap, semnatar);
if (!s.ok) return { ok: false, motiv: s.motiv };
if (!s.ok) return { ok: false, regula: s.regula, motiv: s.motiv };
return { ok: true, semnatDe: s.semnat ? s.keyId : null };
}
@@ -55,20 +59,20 @@ export function dovadaIncludere(intrari, seq, treeSize = intrari.length) {
*/
export function verificaIncludere(d, { cap = null, semnatar = null } = {}) {
try {
if (!d || d.kind !== 'aere-audit-inclusion-proof' || !d.entry) return { ok: false, motiv: 'not an aere-audit-inclusion-proof' };
if (!(!!d && d.kind === 'aere-audit-inclusion-proof' && !!d.entry && typeof d.entry === 'object' /*PAZA:dovada-forma*/)) return refuz('dovada-forma', 'not an aere-audit-inclusion-proof');
const e = d.entry;
if (e.seq !== d.index) return { ok: false, motiv: `the entry is seq ${e.seq}, the proof is for index ${d.index}` };
if (hashIntrare(e.seq, e.prev, e.proof) !== e.hash) return { ok: false, motiv: 'the entry hash does not match its content (modified entry)' };
if (!e.proof || !e.proof.statement || sha256(Buffer.from(JSON.stringify(e.proof.statement), 'utf8')) !== String(e.proof.statementHash).toLowerCase()) return { ok: false, motiv: 'the entry\'s envelope statementHash does not match its statement' };
if (d.leafHash !== frunza(e.hash)) return { ok: false, motiv: 'the leaf is not this entry' };
if (!verifyInclusion(d)) return { ok: false, motiv: `the path does not lead from the entry to root ${String(d.rootHash).slice(0, 18)}.. of a tree of ${d.treeSize}` };
if (!(e.seq === d.index /*PAZA:includere-index*/)) return refuz('includere-index', `the entry is seq ${e.seq}, the proof is for index ${d.index}`);
if (!(hashIntrare(e.seq, e.prev, e.proof) === e.hash /*PAZA:includere-intrare*/)) return refuz('includere-intrare', 'the entry hash does not match its content (modified entry)');
if (!(!!e.proof && !!e.proof.statement && sha256(Buffer.from(JSON.stringify(e.proof.statement), 'utf8')) === String(e.proof.statementHash).toLowerCase() /*PAZA:includere-plic*/)) return refuz('includere-plic', 'the entry\'s envelope statementHash does not match its statement');
if (!(d.leafHash === frunza(e.hash) /*PAZA:includere-frunza*/)) return refuz('includere-frunza', 'the leaf is not this entry');
if (!(verifyInclusion(d) /*PAZA:includere-drum*/)) return refuz('includere-drum', `the path does not lead from the entry to root ${String(d.rootHash).slice(0, 18)}.. of a tree of ${d.treeSize}`);
if (cap) {
const c = capBun(cap, semnatar); if (!c.ok) return c;
if (cap.statement.treeSize !== d.treeSize || cap.statement.rootHash !== d.rootHash) return { ok: false, motiv: `the proof is for a tree of ${d.treeSize} with another root than the head's (${cap.statement.treeSize})` };
if (!(cap.statement.treeSize === d.treeSize && cap.statement.rootHash === d.rootHash /*PAZA:includere-cap*/)) return refuz('includere-cap', `the proof is for a tree of ${d.treeSize} with another root than the head's (${cap.statement.treeSize})`);
return { ok: true, semnatDe: c.semnatDe };
}
return { ok: true, semnatDe: null };
} catch (x) { return { ok: false, motiv: 'the proof cannot be read: ' + x.message }; }
} catch (x) { return refuz('dovada-forma', 'the proof cannot be read: ' + x.message); }
}
/** Dovada ca arborele de marime `firstSize` e un prefix al celui de marime `secondSize` (implicit tot jurnalul). */
@@ -78,14 +82,14 @@ export function dovadaConsistenta(intrari, firstSize, secondSize = intrari.lengt
/** Verifica, FARA jurnal, ca un cap nou continua unul vechi: ambele capete intregi (si semnate de `semnatar`), dovada intre ele. */
export function verificaConsistenta(d, { vechi, nou, semnatar = null }) {
try {
if (!d || d.kind !== 'aere-audit-consistency-proof') return { ok: false, motiv: 'not an aere-audit-consistency-proof' };
const a = capBun(vechi, semnatar); if (!a.ok) return { ok: false, motiv: 'old head: ' + a.motiv };
const b = capBun(nou, semnatar); if (!b.ok) return { ok: false, motiv: 'new head: ' + b.motiv };
if (vechi.statement.treeSize !== d.firstSize || vechi.statement.rootHash !== d.firstRoot) return { ok: false, motiv: 'the proof does not start at the old head' };
if (nou.statement.treeSize !== d.secondSize || nou.statement.rootHash !== d.secondRoot) return { ok: false, motiv: 'the proof does not end at the new head' };
if (!verifyConsistency(d)) return { ok: false, motiv: `the new head (${d.secondSize}) does not extend the old one (${d.firstSize}): the history was rewritten` };
if (!(!!d && d.kind === 'aere-audit-consistency-proof' /*PAZA:dovada-forma*/)) return refuz('dovada-forma', 'not an aere-audit-consistency-proof');
const a = capBun(vechi, semnatar); if (!a.ok) return { ok: false, regula: a.regula, motiv: 'old head: ' + a.motiv };
const b = capBun(nou, semnatar); if (!b.ok) return { ok: false, regula: b.regula, motiv: 'new head: ' + b.motiv };
if (!(vechi.statement.treeSize === d.firstSize && vechi.statement.rootHash === d.firstRoot /*PAZA:consistenta-inceput*/)) return refuz('consistenta-inceput', 'the proof does not start at the old head');
if (!(nou.statement.treeSize === d.secondSize && nou.statement.rootHash === d.secondRoot /*PAZA:consistenta-sfarsit*/)) return refuz('consistenta-sfarsit', 'the proof does not end at the new head');
if (!(verifyConsistency(d) /*PAZA:consistenta*/)) return refuz('consistenta', `the new head (${d.secondSize}) does not extend the old one (${d.firstSize}): the history was rewritten`);
// B-25 (2026-09-30): cine semneaza fiecare cap se intoarce si se spune; fara `semnatar`, doua capete nesemnate (sau semnate de
// oricine) care se continua trec, si cititorul trebuie sa vada asta, nu doar "EXTENDS"
return { ok: true, semnatVechi: a.semnatDe, semnatNou: b.semnatDe };
} catch (x) { return { ok: false, motiv: 'the proof cannot be read: ' + x.message }; }
} catch (x) { return refuz('dovada-forma', 'the proof cannot be read: ' + x.message); }
}