identity: SD-JWT interoperability measured in both directions with @sd-jwt/core 0.23.0 and jose 6.2.12 (ML-DSA-65 included), nested _sd_alg refused, the SD-JWT VC profile (draft-19, dc+sd-jwt, vct, Token Status List offline); conformance: SD-JWT and SD-JWT VC enrolled (213 rules, 13 verifiers, 553 vectors)

This commit is contained in:
Aere Network committed 2026-10-18 11:07:27 +03:00
1 parent fab02f7952
commit e1bb4e25d8
109 files changed
+9823 -175

No files matched your search

+213
View File
@@ -33,6 +33,8 @@ import { newAgentIdentity, openLedger, agentIdFromKey, sessionId, canonical as c
import { construieste as lantAI } from '../ai-trust/lant-de-incredere.mjs';
import * as ID from '../identity/identity.mjs';
import * as DV from '../device-identity/device.mjs';
import * as SJ from '../identity/sdjwt.mjs';
import * as SV from '../identity/sdjwt-vc.mjs';
import { hartaPublica, LEVELS } from './reguli.mjs';
const AICI = path.dirname(fileURLToPath(import.meta.url));
@@ -40,6 +42,9 @@ const DIR = path.join(AICI, 'vectori'); const PROASPETE = path.join(AICI, 'surse
const DOV = { chitanta: new URL('../payments/dovezi/chitanta-28001-2026-10-02T1716Z.json', import.meta.url), piata: new URL('../market-settlement/dovezi/piata-28001-2026-10-02T1652Z.json', import.meta.url),
date: new URL('../verifiable-data/dovezi/notarizare-28001-2026-10-02T0820Z.json', import.meta.url),
lantAI: new URL('../ai-trust/dovezi/lant-28001-2026-10-02T0519Z.json', import.meta.url) };
// fixed inputs of the SD-JWT vectors (2026-10-18): the RFC 9901 vectors, and the tokens of @sd-jwt/core and @sd-jwt/sd-jwt-vc that the
// identity component's interop scripts derived from those libraries' real output (public test keys inside)
const FIX = { rfc: new URL('../identity/fixturi-rfc9901.json', import.meta.url), interop: new URL('../identity/interop/fixturi-interop-sdjwt.json', import.meta.url), interopVc: new URL('../identity/interop/fixturi-interop-sdjwt-vc.json', import.meta.url) };
const citeste = (u) => JSON.parse(fs.readFileSync(fileURLToPath(u), 'utf8'));
const clona = (x) => JSON.parse(JSON.stringify(x));
const sha256 = (b) => '0x' + crypto.createHash('sha256').update(b).digest('hex');
@@ -400,6 +405,86 @@ const PROASPETE_IN_PLUS = {
hardwareRoot: (() => { const st = clona(X1.statement); st.hardwareRoot = { type: 'tpm2-quote', evidence: 'AAAA' }; return { statement: st, signature: DV.signAttestation(st, dev) }; })(),
envelopeOfAnother: DV.proofOfDevice(atest({ now: la(61) }), buildProof) } };
},
// an SD-JWT (RFC 9901) issued with AERE keys (an issuer, a holder, a stranger: three hybrid key pairs that exist only in this call) at a
// fixed time, presented to one verifier, and the forged siblings only a key holder can make (signed again with the issuer or holder key)
sdjwt: async () => {
const NOW = Math.floor(Date.now() / 1000) - 3600; const iso = (s) => new Date(s * 1000).toISOString();
const iss = ID.generateKeys(), hol = ID.generateKeys(), strain = ID.generateKeys();
const AUD = 'https://verifier.example', NONCE = 'n-' + crypto.randomBytes(8).toString('hex'), ISS = 'https://issuer.example';
const CL = { given_name: 'Ada', family_name: 'Example', age_over_18: true, nationalities: ['RO', 'DE'], address: { locality: 'Cluj', country: 'RO' } };
const emite = (o = {}) => SJ.issueSdJwt({ issuer: iss, holder: hol, claims: CL, disclosable: ['given_name', 'family_name', 'age_over_18'], arrayDisclosable: ['nationalities'], iss: ISS, iat: NOW, exp: NOW + 365 * 86400, decoys: 2, ...o });
const arata = (sd, reveal, o = {}) => SJ.presentSdJwt({ sdJwt: sd, reveal, holder: hol, audience: AUD, nonce: NONCE, iat: NOW, ...o });
const b64u = (x) => Buffer.from(x).toString('base64url'); const dec = (s) => JSON.parse(Buffer.from(s, 'base64url').toString('utf8'));
const jwtDin = (antet, corp, cheie = iss.privat.ed25519) => { const cap = b64u(JSON.stringify(antet)) + '.' + b64u(JSON.stringify(corp)); return cap + '.' + b64u(crypto.sign(null, Buffer.from(cap), cheie)); };
const sha = (d) => crypto.createHash('sha256').update(d).digest('base64url');
const E = emite(), M = emite({ alg: 'ML-DSA-65', holderAlg: 'ML-DSA-65' });
const direct = arata(E.sdJwt, ['age_over_18', { element: 'RO', in: 'nationalities' }]);
const corp = dec(E.sdJwt.split('~')[0].split('.')[1]);
const bazaDirect = direct.split('~').slice(0, -1).join('~') + '~';
const kbPeste = (baza, corpKb = {}, cheie = hol.privat.ed25519, antet = { alg: 'EdDSA', typ: 'kb+jwt' }) => baza + jwtDin(antet, { iat: NOW, aud: AUD, nonce: NONCE, sd_hash: sha(baza), ...corpKb }, cheie);
// a hand-made issuer-signed JWT (EdDSA, typ aere+sd-jwt, cnf = the holder key), no key binding
const jeton = (extra, antet = { alg: 'EdDSA', typ: SJ.TYP }) => jwtDin(antet, { iss: ISS, iat: NOW, exp: NOW + 365 * 86400, _sd_alg: 'sha-256', cnf: { jwk: SJ.publicJwk(hol) }, ...extra }) + '~';
const dz = (c) => { const d = b64u(JSON.stringify(c)); return { d, dg: sha(d) }; };
const d1 = dz(['salt-1', 'a', 1]), dSd = dz(['salt-2', '_sd', ['x']]), dRole = dz(['salt-3', 'role', 'admin']), dUnu = dz(['only-a-salt']);
return { now: iso(NOW + 60), later: iso(NOW + 3660), muchLater: iso(NOW + 400 * 86400), audience: AUD, nonce: NONCE, issuer: ISS,
issuerJwk: SJ.publicJwk(iss), issuerJwkMlDsa: SJ.publicJwk(iss, 'ML-DSA-65'), holderJwk: SJ.publicJwk(hol),
issued: E.sdJwt, direct, directMlDsa: arata(M.sdJwt, ['age_over_18'], { holderAlg: 'ML-DSA-65' }),
forged: {
kbStranger: arata(E.sdJwt, ['age_over_18'], { holder: strain }),
kbNoNonce: kbPeste(bazaDirect, { nonce: undefined }),
kbTypJwt: kbPeste(bazaDirect, {}, hol.privat.ed25519, { alg: 'EdDSA', typ: 'JWT' }),
kbExpired: kbPeste(bazaDirect, { exp: NOW - 100 }),
kbNoCnf: kbPeste(jwtDin({ alg: 'EdDSA', typ: SJ.TYP }, { iss: ISS, iat: NOW, exp: NOW + 1000, _sd_alg: 'sha-256' }) + '~'),
expired: arata(emite({ exp: NOW - 1 }).sdJwt, ['age_over_18']),
notYet: arata(emite({ nbf: NOW + 3600 }).sdJwt, ['age_over_18']),
digestTwice: jeton({ _sd: [d1.dg, d1.dg] }) + d1.d + '~',
nestedSdAlg: jeton({ meta: { _sd_alg: 'sha-256', note: 1 } }),
sdAlg384: jeton({ _sd_alg: 'sha-384' }),
disclosureNamedSd: jeton({ _sd: [dSd.dg] }) + dSd.d + '~',
claimConflict: jeton({ role: 'user', _sd: [dRole.dg] }) + dRole.d + '~',
protoClaim: jwtDin({ alg: 'EdDSA', typ: SJ.TYP }, JSON.parse('{"iss":"' + ISS + '","iat":' + NOW + ',"exp":' + (NOW + 1000) + ',"_sd_alg":"sha-256","__proto__":{"admin":true}}')) + '~',
crit: jwtDin({ alg: 'EdDSA', typ: SJ.TYP, crit: ['b64'], b64: false }, corp) + '~',
typJwt: jwtDin({ alg: 'EdDSA', typ: 'JWT' }, corp) + '~',
algConfusion: jwtDin({ alg: 'ES256', typ: SJ.TYP }, corp) + '~',
algNone: b64u(JSON.stringify({ alg: 'none', typ: SJ.TYP })) + '.' + b64u(JSON.stringify(corp)) + '.~',
noExp: jeton({ exp: undefined }),
disclosureOneElement: jeton({ _sd: [dUnu.dg] }) + dUnu.d + '~',
disclosureNotJson: jeton({ _sd: [sha('bm90LWpzb24')] }) + 'bm90LWpzb24~',
sdNotList: jeton({ _sd: 'x' }) } };
},
// an SD-JWT VC (a PID-like credential: vct urn:eudi:pid:1, a Token Status List reference) issued with AERE keys, its Status List Tokens
// (clean, revoked, suspended, 8 bits, for another uri, expired, by a stranger, typed JWT, without iat, too short, ML-DSA-65) and the
// hand-made siblings that break the profile (no vct, status disclosed, a malformed status, a vct#integrity that is not a string)
sdjwtvc: async () => {
const NOW = Math.floor(Date.now() / 1000) - 3600; const iso = (s) => new Date(s * 1000).toISOString();
const iss = ID.generateKeys(), hol = ID.generateKeys(), strain = ID.generateKeys();
const AUD = 'https://verifier.example', NONCE = 'n-' + crypto.randomBytes(8).toString('hex'), ISS = 'https://issuer.example', VCT = 'urn:eudi:pid:1', URI = 'https://issuer.example/status/pid/1', IDX = 5;
const CL = { given_name: 'Ada', family_name: 'Example', birthdate: '1990-01-01', age_over_18: true, nationalities: ['RO', 'DE'], address: { locality: 'Cluj', country: 'RO' }, issuing_authority: 'Example Authority', issuing_country: 'RO' };
const emite = (o = {}) => SV.issueSdJwtVc({ issuer: iss, holder: hol, vct: VCT, claims: CL, disclosable: ['given_name', 'family_name', 'birthdate', 'age_over_18', 'address'], arrayDisclosable: ['nationalities'], iss: ISS, iat: NOW, nbf: NOW, exp: NOW + 365 * 86400, status: { status_list: { idx: IDX, uri: URI } }, decoys: 2, ...o });
const arata = (sd, reveal, o = {}) => SV.presentSdJwtVc({ sdJwt: sd, reveal, holder: hol, audience: AUD, nonce: NONCE, iat: NOW, ...o });
const lista = (statuses, bits = 1, o = {}) => SV.issueStatusListJwt({ issuer: iss, uri: URI, statuses, bits, iat: NOW, exp: NOW + 3600, ...o });
const b64u = (x) => Buffer.from(x).toString('base64url');
const jwtDin = (antet, corp, cheie = iss.privat.ed25519) => { const cap = b64u(JSON.stringify(antet)) + '.' + b64u(JSON.stringify(corp)); return cap + '.' + b64u(crypto.sign(null, Buffer.from(cap), cheie)); };
const sha = (d) => crypto.createHash('sha256').update(d).digest('base64url');
const T0 = new Array(16).fill(0), REV = T0.map((_, i) => (i === IDX ? 1 : 0)), SUS = T0.map((_, i) => (i === IDX ? 2 : 0));
const E = emite(), M = emite({ alg: 'ML-DSA-65', holderAlg: 'ML-DSA-65' }), faraStare = SV.issueSdJwtVc({ issuer: iss, holder: hol, vct: VCT, claims: CL, disclosable: ['birthdate'], iss: ISS, iat: NOW, exp: NOW + 365 * 86400 });
const reveal = ['birthdate', 'age_over_18', { element: 'RO', in: 'nationalities' }];
const corpL = JSON.parse(Buffer.from(lista(T0).split('.')[1], 'base64url').toString('utf8'));
const jeton = (extra, dezv = []) => jwtDin({ alg: 'EdDSA', typ: 'dc+sd-jwt' }, { vct: VCT, iss: ISS, iat: NOW, exp: NOW + 365 * 86400, _sd_alg: 'sha-256', cnf: { jwk: SJ.publicJwk(hol) }, ...extra }) + '~' + dezv.map((d) => d + '~').join('');
const dStatus = b64u(JSON.stringify(['salt-s', 'status', { status_list: { idx: 1, uri: URI } }]));
return { now: iso(NOW + 60), audience: AUD, nonce: NONCE, issuer: ISS, vct: VCT, uri: URI, idx: IDX, issuerJwk: SJ.publicJwk(iss), issuerJwkMlDsa: SJ.publicJwk(iss, 'ML-DSA-65'),
direct: arata(E.sdJwt, reveal), directMlDsa: arata(M.sdJwt, reveal, { holderAlg: 'ML-DSA-65' }), noStatus: arata(faraStare.sdJwt, ['birthdate']),
lists: { clean: lista(T0), revoked: lista(REV), suspended: lista(SUS, 2), eightBits: lista(T0, 8), otherUri: lista(T0, 1, { uri: URI + '-other' }), expired: lista(T0, 1, { exp: NOW + 30 }),
stranger: SV.issueStatusListJwt({ issuer: strain, uri: URI, statuses: T0, iat: NOW }), short: SV.issueStatusListJwt({ issuer: iss, uri: URI, statuses: [0, 0, 0, 0], bits: 8, iat: NOW }),
typJwt: jwtDin({ alg: 'EdDSA', typ: 'JWT' }, corpL), noIat: jwtDin({ alg: 'EdDSA', typ: 'statuslist+jwt' }, (({ iat, ...r }) => r)(corpL)),
mlDsa: SV.issueStatusListJwt({ issuer: iss, alg: 'ML-DSA-65', uri: URI, statuses: T0, iat: NOW, exp: NOW + 3600 }) },
forged: {
noVct: arata(SJ.issueSdJwt({ issuer: iss, holder: hol, claims: { given_name: 'Ada' }, iss: ISS, iat: NOW, exp: NOW + 365 * 86400, typ: 'dc+sd-jwt' }).sdJwt, []),
statusDisclosed: jeton({ _sd: [sha(dStatus)] }, [dStatus]),
statusIdxNegative: jeton({ status: { status_list: { idx: -1, uri: URI } } }),
statusNotObject: jeton({ status: 'revoked' }),
vctIntegrityNumber: jeton({ 'vct#integrity': 7 }) } };
},
};
// ---------- fixed inputs of the AIP-23 kinds (the inputs of the published AIP-23 kind vectors) ----------
@@ -998,6 +1083,134 @@ function construieste() {
mm('device-bundle/attestation-only.attestation-member-more', 'the attestation with a member more beside its statement and its signature', ba, ['bundle', 'attestation', 'note'], ['device.attestation-signature']);
mm('device-bundle/attestation-only.attestation-signature-member-more', 'the attestation with a member more in its signature object', ba, ['bundle', 'attestation', 'signature', 'note'], ['device.attestation-signature']);
tot('device-bundle/active-record-signature-member-more.partial', 'a status record with a member more in its signature object is not a signed record: the only "active" is not believed', bd, { op: 'add', path: ['statusRecords', 0, 'signature', 'note'], value: 'x' }, { ...AP, ...NI }); }
// (K) an SD-JWT presentation (IETF RFC 9901; 2026-10-18): the RFC's own example (ES256, the key of Appendix A.5), the tokens @sd-jwt/core
// issued and presented (the interop fixtures of the identity component, derived from that library's real output), and ours with AERE keys.
// The verifier stops at its first refusal: an integrity refusal leaves authenticity not reached, an authenticity refusal leaves integrity not reached
const curat = (o) => JSON.parse(JSON.stringify(o));
const schimbate = (a, b) => [...new Set([...Object.keys(a), ...Object.keys(b)])].filter((k) => JSON.stringify(a[k]) !== JSON.stringify(b[k])).sort().map((k) => [k]);
{ const SK = Object.keys(HARTA).filter((r) => r.startsWith('sdjwt.')); const A = 'sdjwt-presentation'; const RFC = citeste(FIX.rfc); const IO = citeste(FIX.interop); const X = P.sdjwt;
const AP = { authenticity: 'PASSED' }; const nivelul = (r) => (HARTA[r].level === 'authenticity' ? { integrity: 'NOT_MEASURED', authenticity: 'FAILED' } : { authenticity: 'NOT_MEASURED' });
const inv = (id, titlu, baza, op, r) => invalid(id, titlu, baza, op, [r], { levels: nivelul(r) });
const prod = (id, titlu, baza, sdJwt, r, nota, extra = {}) => { const b = V.find((x) => x.id === baza); if (!b) throw new Error('no base ' + baza); const input = curat({ ...clona(b.input), sdJwt, ...extra }); invalid(id, titlu, baza, null, [r], { levels: nivelul(r), producer: { note: nota, input, changed: schimbate(b.input, input) } }); };
const srcRfc = 'IETF RFC 9901 Section 5 and Appendix A.5 (code components, Revised BSD License), via fixturi-rfc9901.json of the identity component';
const kb = RFC.keyBindingPayload, laKb = new Date(kb.iat * 1000).toISOString(); const br = 'sdjwt-presentation/rfc9901.valid', bri = 'sdjwt-presentation/rfc9901-issued.valid';
valid(br, A, 'the presentation of RFC 9901 Section 5.2 (ES256, the issuer key of Appendix A.5) with its Key Binding JWT, judged at the time of that JWT with its audience and nonce', srcRfc, { sdJwt: RFC.presentation, issuerKey: RFC.issuerJwk, issuerAlg: 'ES256', audience: kb.aud, nonce: kb.nonce, now: laKb }, { exercises: SK, levels: AP });
valid(bri, A, 'the SD-JWT of RFC 9901 Section 5.1 as issued, every disclosure, no key binding (the verifier does not require one)', srcRfc, { sdJwt: RFC.sdJwt, issuerKey: RFC.issuerJwk, issuerAlg: 'ES256', now: laKb, requireKeyBinding: false }, { exercises: SK, levels: AP });
inv('sdjwt-presentation/rfc9901.kb-audience', 'the same presentation shown to another verifier', br, { op: 'set', path: ['audience'], value: 'https://other.example' }, 'sdjwt.kb-audience');
inv('sdjwt-presentation/rfc9901.kb-nonce', 'the verifier gave another nonce (a replay)', br, { op: 'set', path: ['nonce'], value: 'another-nonce' }, 'sdjwt.kb-nonce');
inv('sdjwt-presentation/rfc9901.kb-freshness', 'the verifier clock is an hour after the key binding JWT was made', br, { op: 'set', path: ['now'], value: new Date((kb.iat + 3600) * 1000).toISOString() }, 'sdjwt.kb-freshness');
inv('sdjwt-presentation/rfc9901.kb-context', 'the verifier gives no audience: a key binding cannot be judged, and the presentation is refused rather than taken on trust', br, { op: 'remove', path: ['audience'] }, 'sdjwt.kb-context');
inv('sdjwt-presentation/rfc9901.issuer', 'the verifier expects another issuer', br, { op: 'add', path: ['expectedIssuer'], value: 'https://other-issuer.example' }, 'sdjwt.issuer');
inv('sdjwt-presentation/rfc9901.key', 'the issuer key given is an RSA JWK, which this verifier does not take', br, { op: 'set', path: ['issuerKey'], value: { kty: 'RSA', n: 'AQAB', e: 'AQAB' } }, 'sdjwt.key');
inv('sdjwt-presentation/rfc9901.signature', 'the issuer key given is the holder key of the example (cnf.jwk): the issuer signature does not verify with it', br, { op: 'set', path: ['issuerKey'], value: RFC.processedPayload.cnf.jwk }, 'sdjwt.signature');
inv('sdjwt-presentation/rfc9901.typ', 'the verifier expects another explicit type', br, { op: 'add', path: ['expectedTyp'], value: 'other+sd-jwt' }, 'sdjwt.typ');
inv('sdjwt-presentation/rfc9901.form-clock', 'the verifier clock is not a time', br, { op: 'set', path: ['now'], value: 'yesterday' }, 'sdjwt.form');
inv('sdjwt-presentation/rfc9901.form', 'the token has no ~ at all (not an SD-JWT)', br, { op: 'set', path: ['sdJwt'], value: RFC.presentation.split('~')[0] }, 'sdjwt.form');
inv('sdjwt-presentation/rfc9901.kb-required', 'the SD-JWT as issued, no key binding, shown to a verifier that requires one', br, { op: 'set', path: ['sdJwt'], value: RFC.sdJwt }, 'sdjwt.kb-required');
const pr = RFC.presentation.split('~'); const kbR = pr.pop();
inv('sdjwt-presentation/rfc9901.kb-sd-hash', 'a disclosure taken out after the key binding JWT was signed', br, { op: 'set', path: ['sdJwt'], value: [...pr.slice(0, 2), ...pr.slice(3), kbR].join('~') }, 'sdjwt.kb-sd-hash');
const pi = RFC.sdJwt.split('~');
inv('sdjwt-presentation/rfc9901-issued.disclosure-twice', 'the same disclosure given twice', bri, { op: 'set', path: ['sdJwt'], value: [pi[0], pi[1], pi[1], ...pi.slice(2)].join('~') }, 'sdjwt.disclosure-twice');
inv('sdjwt-presentation/rfc9901-issued.form-empty', 'an empty disclosure between two ~', bri, { op: 'set', path: ['sdJwt'], value: [pi[0], '', ...pi.slice(1)].join('~') }, 'sdjwt.form');
{ const c = JSON.parse(Buffer.from(pi[1], 'base64url').toString('utf8')); c[2] = String(c[2]) + 'x'; const schimbat = Buffer.from(JSON.stringify(c)).toString('base64url');
inv('sdjwt-presentation/rfc9901-issued.unreferenced', 'the value of the first disclosure changed: its digest is in no _sd', bri, { op: 'set', path: ['sdJwt'], value: [pi[0], schimbat, ...pi.slice(2)].join('~') }, 'sdjwt.unreferenced'); }
// ours: AERE keys (EdDSA and ML-DSA-65), and the forged siblings only a key holder can make
const srcA = 'producers (sdjwt.mjs: issueSdJwt, presentSdJwt), three hybrid key pairs made and discarded at generation';
const bo = 'sdjwt-presentation/aere.valid', bom = 'sdjwt-presentation/aere-ml-dsa-65.valid', bi = 'sdjwt-presentation/aere-issued.valid';
const intrareA = (sdJwt, o = {}) => ({ sdJwt, issuerKey: X.issuerJwk, issuerAlg: 'EdDSA', audience: X.audience, nonce: X.nonce, now: X.now, expectedIssuer: X.issuer, ...o });
valid(bo, A, 'an SD-JWT issued with AERE keys (EdDSA): two of three disclosable claims and one list element shown, two decoy digests, a key binding JWT for this verifier', srcA, intrareA(X.direct), { exercises: SK, levels: AP });
valid(bom, A, 'the same credential, issuer and holder keys ML-DSA-65 (RFC 9964, JWK type AKP)', srcA, intrareA(X.directMlDsa, { issuerKey: X.issuerJwkMlDsa, issuerAlg: 'ML-DSA-65' }), { exercises: SK, levels: AP });
valid(bi, A, 'the same SD-JWT as issued (every disclosure, no key binding), judged by a verifier that does not require key binding', srcA, { sdJwt: X.issued, issuerKey: X.issuerJwk, issuerAlg: 'EdDSA', now: X.now, requireKeyBinding: false }, { exercises: SK, levels: AP });
const F = X.forged;
prod('sdjwt-presentation/aere.signature-kb', 'the key binding JWT is signed by another key than cnf.jwk', bo, F.kbStranger, 'sdjwt.signature', 'a stranger made the key binding JWT with its own key over the holder\'s SD-JWT');
prod('sdjwt-presentation/aere.kb-claims', 'the key binding JWT carries no nonce', bo, F.kbNoNonce, 'sdjwt.kb-claims', 'the holder signed a key binding JWT without the nonce claim');
prod('sdjwt-presentation/aere.typ-kb', 'the key binding JWT is typed JWT, not kb+jwt', bo, F.kbTypJwt, 'sdjwt.typ', 'the holder signed the key binding JWT with typ JWT');
prod('sdjwt-presentation/aere.kb-freshness-exp', 'the key binding JWT carries an exp that has passed', bo, F.kbExpired, 'sdjwt.kb-freshness', 'the holder signed a key binding JWT with exp in the past');
prod('sdjwt-presentation/aere.kb-cnf', 'the issuer-signed JWT names no holder key, and a key binding JWT is attached anyway', bo, F.kbNoCnf, 'sdjwt.kb-cnf', 'the issuer signed a JWT without cnf; a key binding JWT was attached to it');
prod('sdjwt-presentation/aere.time-expired', 'the credential expired a second before the verifier clock', bo, F.expired, 'sdjwt.time', 'the issuer issued the same claims with exp in the past, the holder presented them');
prod('sdjwt-presentation/aere.time-not-yet', 'the credential is not valid for another hour (nbf ahead of the clock by more than the skew)', bo, F.notYet, 'sdjwt.time', 'the issuer issued the same claims with nbf an hour ahead, the holder presented them');
prod('sdjwt-presentation/aere-issued.digest-twice', 'the issuer signed the same digest twice in _sd', bi, F.digestTwice, 'sdjwt.digest-twice', 'the issuer signed a payload whose _sd repeats a digest');
prod('sdjwt-presentation/aere-issued.sd-alg-nested', 'the issuer signed an _sd_alg below the top level (RFC 9901 Section 4.1.1 forbids it)', bi, F.nestedSdAlg, 'sdjwt.sd-alg', 'the issuer signed a payload with _sd_alg inside a nested object');
prod('sdjwt-presentation/aere-issued.sd-alg', 'the issuer signed _sd_alg sha-384, which this verifier does not understand', bi, F.sdAlg384, 'sdjwt.sd-alg', 'the issuer signed a payload with _sd_alg sha-384');
prod('sdjwt-presentation/aere-issued.disclosure-name', 'a disclosure named _sd, signed for by the issuer', bi, F.disclosureNamedSd, 'sdjwt.disclosure-name', 'the issuer put in _sd the digest of a disclosure named _sd');
prod('sdjwt-presentation/aere-issued.disclosure-name-proto', 'a plain claim named __proto__, signed by the issuer', bi, F.protoClaim, 'sdjwt.disclosure-name', 'the issuer signed a payload with a claim named __proto__');
prod('sdjwt-presentation/aere-issued.claim-conflict', 'a disclosure that would overwrite a claim the payload has in the clear', bi, F.claimConflict, 'sdjwt.claim-conflict', 'the issuer signed a plain claim role and the digest of a disclosure named role');
prod('sdjwt-presentation/aere-issued.crit', 'the issuer-signed JWT carries a crit header parameter', bi, F.crit, 'sdjwt.crit', 'the issuer signed the header with crit [b64] and b64 false');
prod('sdjwt-presentation/aere-issued.typ', 'the issuer-signed JWT is typed JWT, not an explicit SD-JWT type', bi, F.typJwt, 'sdjwt.typ', 'the issuer signed the header with typ JWT');
prod('sdjwt-presentation/aere-issued.key-confusion', 'the header says ES256 and the signature was made with the Ed25519 key (algorithm confusion)', bi, F.algConfusion, 'sdjwt.key', 'the issuer signed with its Ed25519 key under an ES256 header');
prod('sdjwt-presentation/aere-issued.alg-none', 'alg none, no signature', bi, F.algNone, 'sdjwt.alg', 'the payload re-encoded under an alg none header with an empty signature');
prod('sdjwt-presentation/aere-issued.time-no-exp', 'the issuer-signed JWT has no exp, and the verifier requires one', bi, F.noExp, 'sdjwt.time', 'the issuer signed a payload without exp');
prod('sdjwt-presentation/aere-issued.disclosure-form', 'a disclosure that is a one-element list', bi, F.disclosureOneElement, 'sdjwt.disclosure-form', 'the issuer signed the digest of a disclosure that is [salt] alone');
prod('sdjwt-presentation/aere-issued.disclosure-form-not-json', 'a disclosure that is base64url of text that is not JSON', bi, F.disclosureNotJson, 'sdjwt.disclosure-form', 'the issuer signed the digest of a disclosure whose bytes are not JSON');
prod('sdjwt-presentation/aere-issued.disclosure-form-sd', '_sd is a string, not a list of digests', bi, F.sdNotList, 'sdjwt.disclosure-form', 'the issuer signed a payload whose _sd is a string');
inv('sdjwt-presentation/aere-issued.time-years-later', 'the verifier clock is years later: the credential has expired', bi, { op: 'set', path: ['now'], value: X.muchLater }, 'sdjwt.time');
// @sd-jwt/core (openwallet-foundation-labs/identity-common-ts), from the interop fixtures: its tokens, with its public test keys
const srcIo = `@sd-jwt/core ${IO.biblioteci['@sd-jwt/core']} with jose ${IO.biblioteci.jose} (interop/fixturi-interop-sdjwt.json of the identity component, generated ${IO.generat.slice(0, 10)}; its test keys made and discarded at generation)`;
const laIo = new Date(IO.ceasVerificare * 1000).toISOString();
const intrareIo = (c) => ({ sdJwt: c.prezentare, issuerKey: c.issuerJwk, issuerAlg: c.alg, audience: IO.audience, nonce: IO.nonce, now: laIo, ...(c.optiuni || {}) });
const cazIo = (re) => { const c = IO.cazuri.find((x) => re.test(x.nume)); if (!c) throw new Error('the interop fixtures have no case ' + re); return c; };
const bioE = 'sdjwt-presentation/sd-jwt-core.valid';
for (const [alg, id, titlu] of [['EdDSA', bioE, 'an SD-JWT issued and presented by @sd-jwt/core (EdDSA): nested disclosures (address.locality), a list element, two decoys, a key binding JWT; the token carries no typ, so the verifier takes any (expectedTyp null)'], ['ES256', 'sdjwt-presentation/sd-jwt-core-es256.valid', 'the same from @sd-jwt/core with ES256 (P-256) keys'], ['ML-DSA-65', 'sdjwt-presentation/sd-jwt-core-ml-dsa-65.valid', 'the same from @sd-jwt/core with ML-DSA-65 keys (RFC 9964)']]) {
const c = cazIo(new RegExp('^' + alg + ': prezentare @sd-jwt/core cu dezvaluiri imbricate')); valid(id, A, titlu, srcIo, intrareIo(c), { exercises: SK, levels: AP }); }
{ const c = cazIo(/typ example\+sd-jwt/); valid('sdjwt-presentation/sd-jwt-core-typed.valid', A, 'an SD-JWT from @sd-jwt/core issued with typ example+sd-jwt, taken by the default type of the verifier', srcIo, intrareIo(c), { exercises: SK, levels: AP }); }
inv('sdjwt-presentation/sd-jwt-core.typ', 'the untyped token of @sd-jwt/core under the default type of the verifier (an explicit ...+sd-jwt is required)', bioE, { op: 'remove', path: ['expectedTyp'] }, 'sdjwt.typ');
const negIo = (id, titlu, re, r, nota) => { const c = cazIo(re); prod(id, titlu, bioE, c.prezentare, r, nota); };
negIo('sdjwt-presentation/sd-jwt-core.unreferenced', 'the value of a disclosure of @sd-jwt/core changed', /^NEGATIV: dezvaluirea age_over_18 cu valoarea schimbata/, 'sdjwt.unreferenced', 'a disclosure of the @sd-jwt/core token with its value changed (no key binding in that presentation)');
negIo('sdjwt-presentation/sd-jwt-core.kb-audience', 'presented by @sd-jwt/core for another audience', /^NEGATIV: KB pentru alt aud/, 'sdjwt.kb-audience', '@sd-jwt/core presented the token with a key binding JWT for https://other.example');
negIo('sdjwt-presentation/sd-jwt-core.alg', 'the @sd-jwt/core payload under alg none', /^NEGATIV: alg none/, 'sdjwt.alg', 'the issuer-signed payload of @sd-jwt/core re-encoded under alg none');
negIo('sdjwt-presentation/sd-jwt-core.digest-twice', 'the @sd-jwt/core payload with a digest repeated in _sd, signed again by its issuer key', /^NEGATIV: acelasi digest de doua ori/, 'sdjwt.digest-twice', 'the @sd-jwt/core issuer key signed its payload with the first digest of _sd repeated');
negIo('sdjwt-presentation/sd-jwt-core.signature-kb', 'presented by @sd-jwt/core with a key binding JWT signed by another key than cnf.jwk', /^NEGATIV: KB semnat de alta cheie/, 'sdjwt.signature', '@sd-jwt/core presented the token with a key binding JWT of another key');
negIo('sdjwt-presentation/sd-jwt-core.kb-sd-hash', 'a disclosure removed from the @sd-jwt/core presentation after key binding', /^NEGATIV: o dezvaluire scoasa/, 'sdjwt.kb-sd-hash', 'a disclosure taken out of the @sd-jwt/core presentation after its key binding JWT was signed');
{ const c = cazIo(/_sd_alg sha-384/); prod('sdjwt-presentation/sd-jwt-core.sd-alg', 'a token @sd-jwt/core issued with _sd_alg sha-384, which this verifier does not understand', bioE, c.prezentare, 'sdjwt.sd-alg', '@sd-jwt/core issued and presented the same claims with hashAlg sha-384 (another issuer key of its own)', { issuerKey: c.issuerJwk }); } }
// (L) an SD-JWT VC presentation (draft-ietf-oauth-sd-jwt-vc with the Token Status List; 2026-10-18): ours with AERE keys and its status
// lists, and the credentials and lists @sd-jwt/sd-jwt-vc and @owf/token-status-list produced (the interop fixtures). No vector here EXPECTS
// a rule of sdjwt: the profile imports sdjwt.mjs from its real file, so a planted copy of sdjwt is not reached through this artifact
{ const VK = Object.keys(HARTA).filter((r) => r.startsWith('sdjwt.') || r.startsWith('sdjwtvc.')); const A = 'sdjwt-vc-presentation'; const X = P.sdjwtvc; const IO = citeste(FIX.interopVc);
const AP = { authenticity: 'PASSED' }, NI = { integrity: 'NOT_MEASURED' }, OPR = { authenticity: 'NOT_MEASURED' };
const inv = (id, titlu, baza, op, r) => invalid(id, titlu, baza, op, [r], { levels: OPR });
const prod = (id, titlu, baza, sdJwt, r, nota, extra = {}) => { const b = V.find((x) => x.id === baza); if (!b) throw new Error('no base ' + baza); const input = curat({ ...clona(b.input), sdJwt, ...extra }); invalid(id, titlu, baza, null, [r], { levels: OPR, producer: { note: nota, input, changed: schimbate(b.input, input) } }); };
const srcA = 'producers (sdjwt-vc.mjs: issueSdJwtVc, presentSdJwtVc, issueStatusListJwt), three hybrid key pairs made and discarded at generation';
const intrare = (sdJwt, o = {}) => curat({ sdJwt, issuerKey: X.issuerJwk, issuerAlg: 'EdDSA', audience: X.audience, nonce: X.nonce, now: X.now, expectedIssuer: X.issuer, expectedVct: X.vct, statusListJwt: X.lists.clean, ...o });
const bv = 'sdjwt-vc-presentation/aere-pid.valid';
valid(bv, A, `an SD-JWT VC issued with AERE keys (EdDSA; vct ${X.vct}, typ dc+sd-jwt, a status_list reference), three claims shown, judged with the issuer's Status List Token (all VALID)`, srcA, intrare(X.direct), { exercises: VK, levels: AP });
valid('sdjwt-vc-presentation/aere-pid-ml-dsa-65.valid', A, 'the same credential and its status list, issuer and holder ML-DSA-65', srcA, intrare(X.directMlDsa, { issuerKey: X.issuerJwkMlDsa, issuerAlg: 'ML-DSA-65', statusListJwt: X.lists.mlDsa }), { exercises: VK, levels: AP });
valid('sdjwt-vc-presentation/aere-no-status.valid', A, 'a credential that names no status, judged without a list', srcA, intrare(X.noStatus, { statusListJwt: undefined }), { exercises: VK, levels: AP });
valid('sdjwt-vc-presentation/aere-pid-status-waived.partial', A, 'the same credential without its list, the verifier waiving the status (requireStatus false): nothing fails, the status it names was not judged, so it is not VALID', srcA, intrare(X.direct, { statusListJwt: undefined, requireStatus: false }), { exercises: VK, verdict: 'PARTIAL', levels: { ...AP, ...NI } });
{ const op = { op: 'set', path: ['statusListJwt'], value: X.lists.eightBits }; valid('sdjwt-vc-presentation/aere-pid-8-bits.valid', A, 'the same credential with a status list of 8 bits per entry (all VALID)', srcA, aplica(V.find((x) => x.id === bv).input, op), { exercises: VK, levels: AP, base: bv, mutation: op }); }
inv('sdjwt-vc-presentation/aere-pid.vct-expected', 'the verifier names no credential type it expects', bv, { op: 'remove', path: ['expectedVct'] }, 'sdjwtvc.vct-expected');
inv('sdjwt-vc-presentation/aere-pid.vct-mismatch', 'the verifier expects another credential type', bv, { op: 'set', path: ['expectedVct'], value: 'urn:eudi:pid:2' }, 'sdjwtvc.vct-mismatch');
inv('sdjwt-vc-presentation/aere-pid.status-revoked', 'the issuer\'s list has status 1 (INVALID) at the credential\'s index', bv, { op: 'set', path: ['statusListJwt'], value: X.lists.revoked }, 'sdjwtvc.status-revoked');
inv('sdjwt-vc-presentation/aere-pid.status-suspended', 'the issuer\'s list, 2 bits per entry, has status 2 (SUSPENDED) at the index', bv, { op: 'set', path: ['statusListJwt'], value: X.lists.suspended }, 'sdjwtvc.status-revoked');
inv('sdjwt-vc-presentation/aere-pid.status-list-other-uri', 'the list handed was published for another uri (sub)', bv, { op: 'set', path: ['statusListJwt'], value: X.lists.otherUri }, 'sdjwtvc.status-list');
inv('sdjwt-vc-presentation/aere-pid.status-list-expired', 'the list handed expired before the verifier clock', bv, { op: 'set', path: ['statusListJwt'], value: X.lists.expired }, 'sdjwtvc.status-list');
inv('sdjwt-vc-presentation/aere-pid.status-list-stranger', 'the list handed is signed by another key than the issuer\'s', bv, { op: 'set', path: ['statusListJwt'], value: X.lists.stranger }, 'sdjwtvc.status-list');
inv('sdjwt-vc-presentation/aere-pid.status-list-typ', 'the list handed is typed JWT, not statuslist+jwt', bv, { op: 'set', path: ['statusListJwt'], value: X.lists.typJwt }, 'sdjwtvc.status-list');
inv('sdjwt-vc-presentation/aere-pid.status-list-no-iat', 'the list handed has no iat', bv, { op: 'set', path: ['statusListJwt'], value: X.lists.noIat }, 'sdjwtvc.status-list');
inv('sdjwt-vc-presentation/aere-pid.status-index', 'the list handed is shorter than the index the credential names', bv, { op: 'set', path: ['statusListJwt'], value: X.lists.short }, 'sdjwtvc.status-index');
inv('sdjwt-vc-presentation/aere-pid.status-unjudged', 'no list handed, and the verifier did not waive the status', bv, { op: 'remove', path: ['statusListJwt'] }, 'sdjwtvc.status-unjudged');
const F = X.forged;
prod('sdjwt-vc-presentation/aere-pid.vct', 'a credential typed dc+sd-jwt with no vct at all', bv, F.noVct, 'sdjwtvc.vct', 'the issuer signed an SD-JWT typed dc+sd-jwt without vct; the holder presented it');
prod('sdjwt-vc-presentation/aere-pid.disclosed-protected', 'the status claim made selectively disclosable, and disclosed', bv, F.statusDisclosed, 'sdjwtvc.disclosed-protected', 'the issuer put status behind a disclosure (no key binding in this token)', { requireKeyBinding: false });
prod('sdjwt-vc-presentation/aere-pid.form-idx', 'a status reference with a negative index', bv, F.statusIdxNegative, 'sdjwtvc.form', 'the issuer signed status.status_list.idx -1 (no key binding in this token)', { requireKeyBinding: false });
prod('sdjwt-vc-presentation/aere-pid.form-status', 'a status claim that is a string', bv, F.statusNotObject, 'sdjwtvc.form', 'the issuer signed status "revoked" (no key binding in this token)', { requireKeyBinding: false });
prod('sdjwt-vc-presentation/aere-pid.form-integrity', 'a vct#integrity that is a number', bv, F.vctIntegrityNumber, 'sdjwtvc.form', 'the issuer signed vct#integrity 7 (no key binding in this token)', { requireKeyBinding: false });
// @sd-jwt/sd-jwt-vc and @owf/token-status-list, from the interop fixtures
const srcIo = `@sd-jwt/sd-jwt-vc ${IO.biblioteci['@sd-jwt/sd-jwt-vc']} and @owf/token-status-list ${IO.biblioteci['@owf/token-status-list']} with jose ${IO.biblioteci.jose} (interop/fixturi-interop-sdjwt-vc.json of the identity component, generated ${IO.generat.slice(0, 10)}; their test keys made and discarded at generation)`;
const laIo = new Date(IO.ceasVerificare * 1000).toISOString();
const intrareIo = (c) => curat({ sdJwt: c.prezentare, issuerKey: c.issuerJwk, issuerAlg: c.alg, audience: IO.audience, nonce: IO.nonce, now: laIo, expectedVct: c.expectedVct, statusListJwt: c.statusListJwt, ...(c.optiuni || {}) });
const cazIo = (re) => { const c = IO.cazuri.find((x) => re.test(x.nume)); if (!c) throw new Error('the VC interop fixtures have no case ' + re); return c; };
const bvE = 'sdjwt-vc-presentation/sd-jwt-vc.valid';
for (const [alg, id, titlu] of [['EdDSA', bvE, 'an SD-JWT VC issued and presented by @sd-jwt/sd-jwt-vc (EdDSA; typ dc+sd-jwt, vct urn:eudi:pid:1, a status_list reference) with the Status List Token of @owf/token-status-list (all VALID)'], ['ES256', 'sdjwt-vc-presentation/sd-jwt-vc-es256.valid', 'the same with ES256 keys'], ['ML-DSA-65', 'sdjwt-vc-presentation/sd-jwt-vc-ml-dsa-65.valid', 'the same with ML-DSA-65 keys']]) {
const c = cazIo(new RegExp('^' + alg + ': SD-JWT VC @sd-jwt/sd-jwt-vc')); valid(id, A, titlu, srcIo, intrareIo(c), { exercises: VK, levels: AP }); }
{ const c = cazIo(/^lista LOR pe 8 biti/); valid('sdjwt-vc-presentation/sd-jwt-vc-8-bits.valid', A, 'the same credential with the 8-bit list of @owf/token-status-list', srcIo, intrareIo(c), { exercises: VK, levels: AP }); }
{ const c = cazIo(/^fara lista, la noi cu requireStatus:false/); valid('sdjwt-vc-presentation/sd-jwt-vc-status-waived.partial', A, 'the @sd-jwt/sd-jwt-vc credential without its list, the status waived: not judged, so not VALID', srcIo, intrareIo(c), { exercises: VK, verdict: 'PARTIAL', levels: { ...AP, ...NI } }); }
const negIo = (id, titlu, re, r, nota) => { const c = cazIo(re); const b = V.find((x) => x.id === bvE); const input = intrareIo(c); invalid(id, titlu, bvE, null, [r], { levels: OPR, producer: { note: nota, input, changed: schimbate(b.input, input) } }); };
negIo('sdjwt-vc-presentation/sd-jwt-vc.status-revoked', 'the list of @owf/token-status-list with status 1 at the index', /^NEGATIV: lista LOR cu indexul 5 = 1/, 'sdjwtvc.status-revoked', '@owf/token-status-list wrote the list with INVALID at the credential\'s index');
negIo('sdjwt-vc-presentation/sd-jwt-vc.status-suspended', 'the 2-bit list of @owf/token-status-list with status 2 at the index', /^NEGATIV: lista LOR pe 2 biti/, 'sdjwtvc.status-revoked', '@owf/token-status-list wrote a 2-bit list with SUSPENDED at the credential\'s index');
negIo('sdjwt-vc-presentation/sd-jwt-vc.status-list-other-uri', 'the list of @owf/token-status-list published for another uri', /^NEGATIV: lista LOR pentru ALT uri/, 'sdjwtvc.status-list', '@owf/token-status-list wrote the list with another sub');
negIo('sdjwt-vc-presentation/sd-jwt-vc.status-list-expired', 'the list of @owf/token-status-list, expired', /^NEGATIV: lista LOR expirata/, 'sdjwtvc.status-list', '@owf/token-status-list wrote the list with exp before the verifier clock');
negIo('sdjwt-vc-presentation/sd-jwt-vc.vct-mismatch', 'the verifier expects another credential type than the @sd-jwt/sd-jwt-vc credential carries', /^NEGATIV: verificatorul asteapta alt vct/, 'sdjwtvc.vct-mismatch', 'the same credential and list, the verifier expecting urn:eudi:pid:2');
negIo('sdjwt-vc-presentation/sd-jwt-vc.status-unjudged', 'the @sd-jwt/sd-jwt-vc credential without its list, the status not waived', /^NEGATIV: fara lista, la noi implicit/, 'sdjwtvc.status-unjudged', 'the same credential, no list handed'); }
// (E) a dataset: a record, a range answer, a consistency proof, an availability sample
const DS = P.dataset; const REC = ['dataset.form', 'dataset.commitment', 'dataset.field', 'dataset.inclusion']; const src = 'producer (verifiable-data), random salts, generated ' + P.at;
valid('dataset-record/r5.valid', 'dataset-record', 'one record against the commitment of version 2, two fields disclosed', src, { record: DS.record, commitment: DS.newer }, { exercises: REC });