/** * Selective disclosure — reveal only specific fields of a signed document. * * Problem: an issuer signs a set of claims about a subject (e.g. "name=Alice, * dob=1990-01-01, country=US, kyc-tier=3"). When the subject uses this to * access a service that only needs `kyc-tier >= 2`, they shouldn't have to * hand over their name and DOB. But they also can't just *say* "my kyc-tier * is 3" — the verifier needs to know the issuer signed that specific claim. * * Design: issuer commits to each field INDEPENDENTLY with a per-field salt, * then signs a commitment root = hash over the sorted field commitments. * The document holder can reveal any subset of fields by providing: * (1) the disclosed field values + their salts (verifier hashes those) * (2) the raw commitment hashes for the undisclosed fields * (3) the issuer's signature over the root * * Verifier recomputes the root from the pieces and checks the signature. * * Properties: * - Unlinkability: salts prevent correlation across presentations (the * verifier sees commitment hashes but those differ per document). * - Hiding: undisclosed field hashes reveal nothing about field contents * because each is salted with 32 random bytes. * - Integrity: verifier cannot be tricked into accepting a forged claim — * the signature is over the root, and the root depends on EVERY field. * * Non-goals: * - ZK proofs over ranges ("tier >= 2") — this only reveals exact values. * A holder who wants "tier >= 2" just reveals the tier field directly. * - Predicate proofs — use something like BBS+ for those. * * This is the simplest cryptographic selective disclosure that works, and * it composes cleanly with the existing attestation module. */ import { type CryptoProvider } from '../core/crypto-provider.js'; import { type HistoricalKeyLookup } from './historical-key-lookup.js'; /** A signed document the issuer produces. Holder stores this locally. */ export interface DisclosableDocument { /** Opaque document id. */ id: string; /** DID of the issuer. */ issuerDid: string; /** Issuer's base64 public key. */ issuerPublicKey: string; /** DID of the subject these claims are about. */ subjectDid: string; /** The full claim set (private — held by subject). */ claims: Record; /** Per-field base64 salts (32 bytes each). */ salts: Record; /** Merkle-ish root: hash of sorted per-field commitment hashes. */ commitmentRoot: string; /** When issued. */ issuedAt: number; /** When this expires, or null. */ expiresAt: number | null; /** Issuer's signature over canonical envelope (root + metadata). */ signature: string; } /** A presentation that reveals only some fields. */ export interface DisclosureProof { documentId: string; issuerDid: string; issuerPublicKey: string; subjectDid: string; commitmentRoot: string; issuedAt: number; expiresAt: number | null; signature: string; /** Fields being revealed: field name → {value, salt}. */ disclosed: Record; /** Commitment hashes for withheld fields: field name → commitment hash. */ undisclosedCommitments: Record; } export type DisclosureVerification = { valid: true; disclosed: Record; issuerDid: string; subjectDid: string; documentId: string; } | { valid: false; reason: string; }; export declare function createDisclosableDocument(opts: { issuerDid: string; issuerPublicKey: string; issuerSigningKey: Uint8Array; subjectDid: string; claims: Record; expiresAt?: number | null; provider?: CryptoProvider; }): DisclosableDocument; /** * Subject verifies the document they received is well-formed — issuer * signed the root, and the root matches the per-field commitments. */ export declare function verifyDisclosableDocument(doc: DisclosableDocument, provider?: CryptoProvider): { valid: boolean; reason?: string; }; /** * Holder builds a presentation revealing only `fieldsToReveal`. All other * fields' commitment hashes are included raw — they're already salted, so * they're opaque. */ export declare function createDisclosureProof(doc: DisclosableDocument, fieldsToReveal: readonly string[], provider?: CryptoProvider): DisclosureProof; export declare function verifyDisclosureProof(proof: DisclosureProof, opts?: { /** Current time for expiry check. */ now?: number; /** Required fields the verifier expects to see. */ requiredFields?: readonly string[]; provider?: CryptoProvider; /** * Rotation-aware key validity lookup. When provided, confirms the * issuer's public key was effective at the document's `issuedAt` * timestamp. Fail-closed if not found or not effective. */ lookup?: HistoricalKeyLookup; }): DisclosureVerification; //# sourceMappingURL=selective-disclosure.d.ts.map