identity: the Travel Rule and compliance-policy verifiers name their rules; a missing originator id or nonce is now a refusal in acceptBeneficiary; conformance: Travel Rule and compliance presentations enrolled (239 rules, 15 verifiers, 21 kinds, 619 vectors), nothing of identity left out

This commit is contained in:
Aere Network committed 2026-10-18 13:13:50 +03:00
1 parent e1bb4e25d8
commit ea695dcf32
81 files changed
+17246 -127

No files matched your search

+15 -5
View File
@@ -11,12 +11,21 @@
// O politica e { v:1, kind:'aere-compliance-policy', id, trustedIssuers:[id], requireStatus, maxAgeS, require:[regula] }, cu regula
// { claim, equals } | { claim, in:[...] } | { claim, notIn:[...] } | { claim, atLeast:number } | { claim, present:true }. Hash-ul ei
// se recalculeaza din forma canonica, deci o politica mai laxa nu poate trece sub hash-ul uneia stricte.
//
// REGULILE NUMITE (2026-10-18, pentru suita de conformitate tools/aere-conformance): fiecare motiv al lui `checkCompliance` numeste regula
// lui, din REGULI (`presentation`: prezentarea e valida pentru acest verificator, judecata de identity.mjs cu emitentii politicii; `status`:
// starea credentialului e judecata cand politica o cere; `rule`: fiecare regula a politicii tine pe afirmatiile aratate); fiecare verificare
// e un rand { rule, pass, detail } si poarta /*PAZA:<regula>*/ pe conditia ei buna. Rezultatul poarta, pe langa `compliant` si `reasons`
// (neschimbate), `rules` (id-urile refuzate, sortate), `rows` si `unjudged` (cauzele lasate nejudecate de verificatorul de identitate).
// O prezentare invalida nu stabileste nicio afirmatie, deci si fiecare regula a politicii iese "not met" (asa spunea si ieri).
import crypto from 'node:crypto';
import { verifyPresentation, canonical, idOf } from './identity.mjs';
const sha = (s) => '0x' + crypto.createHash('sha256').update(Buffer.from(s, 'utf8')).digest('hex');
const ID = /^aere-id:[0-9a-f]{40}$/;
const OPERATORI = ['equals', 'in', 'notIn', 'atLeast', 'present'];
/** regulile pe care le poate numi un motiv al lui checkCompliance */
export const REGULI = ['presentation', 'status', 'rule'];
/** Forma normala a unei politici si hash-ul ei; refuza campuri necunoscute si reguli fara inteles. */
export function definePolicy(p) {
@@ -65,19 +74,20 @@ export function checkCompliance(p, politica, { audience, nonce, now = new Date()
const { policy, policyHash } = definePolicy(politica);
if (typeof audience !== 'string' || !audience || typeof nonce !== 'string' || !nonce) throw new Error('compliance: the verifier\'s audience and nonce are required (without them a presentation can be replayed)');
const v = verifyPresentation(p, { audience, nonce, now, trustedIssuers: policy.trustedIssuers, statusLists, revocations, maxAgeS: policy.maxAgeS });
const motive = [];
if (!v.valid) motive.push('the presentation is not valid: ' + v.rows.filter((r) => r.pass === false).map((r) => r.name + (r.detail ? ' (' + r.detail + ')' : '')).join('; '));
const rows = []; const ok = (rule, pass, detail) => { if (!REGULI.includes(rule)) throw new Error('compliance: undeclared rule ' + rule); rows.push({ rule, pass: !!pass, detail: pass ? '' : detail }); };
ok('presentation', v.valid /*PAZA:presentation*/, 'the presentation is not valid: ' + v.rows.filter((r) => r.pass === false).map((r) => r.name + (r.detail ? ' (' + r.detail + ')' : '')).join('; '));
const status = v.rows.find((r) => /^credential: (not revoked|status)/.test(r.name));
if (policy.requireStatus && !(status && status.pass === true)) motive.push('the policy requires the credential status to be judged: ' + (status ? status.detail || 'not judged' : 'no status row'));
ok('status', !policy.requireStatus || !!(status && status.pass === true) /*PAZA:status*/, 'the policy requires the credential status to be judged: ' + (status ? status.detail || 'not judged' : 'no status row'));
const claims = v.claims || {};
for (const r of policy.require) if (!regula(r, claims)) motive.push(`rule not met: ${canonical(r)}`);
for (const r of policy.require) ok('rule', regula(r, claims) /*PAZA:rule*/, `rule not met: ${canonical(r)}`);
const motive = rows.filter((r) => !r.pass).map((r) => r.detail);
const holder = p && p.credential && p.credential.statement && p.credential.statement.holder ? p.credential.statement.holder.id : null;
// B-29 (2026-09-30, revizuirea API-ului): digestul e al LEGATURII semnate de cel care prezinta (ea numeste prin hash credentialul intreg,
// dezvaluirile, lantul de delegare, publicul, nonce-ul si momentul), nu al obiectului intreg: un camp de sus nesemnat, adaugat de
// oricine, schimba obiectul fara sa schimbe nimic semnat, deci digestul vechi nu numea unic prezentarea. Semnatura nu intra: ML-DSA
// semneaza aleator, deci aceeasi legatura poate avea oricate semnaturi valide. Fara legatura (prezentare stricata), obiectul intreg.
const legatura = p && typeof p === 'object' && p.binding && typeof p.binding === 'object' && !Array.isArray(p.binding) ? p.binding : null;
return { compliant: !motive.length, reasons: motive, policyHash, policyId: policy.id, holder, notJudged: v.notJudged,
return { compliant: !motive.length, reasons: motive, rules: [...new Set(rows.filter((r) => !r.pass).map((r) => r.rule))].sort(), rows, unjudged: v.unjudged, policyHash, policyId: policy.id, holder, notJudged: v.notJudged,
presentationHash: sha(canonical(legatura || p || null)), ...(keepClaims && !motive.length ? { claims } : {}) };
}