All files / src/lib eudi-patient-map.ts

100% Statements 4/4
100% Branches 4/4
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                                  2x     6x 12x     6x            
/**
 * Maps a cryptographically-verified EUDI Wallet PID presentation to a demo
 * patient identity in this dataspace.
 *
 * Demo semantics (decided for the hackathon): every successfully verified wallet
 * is mapped to a fixed synthetic patient (`patient1`). A real wallet's PID will
 * not match the synthetic Synthea cohort, so a name+birthDate lookup would lock
 * the holder out. The *identity* is therefore cosmetic — the point is that the
 * holder proved control of a real EUDI Wallet credential. The verified name is
 * surfaced as the display name so the demo shows "you, verified via your wallet"
 * over a synthetic health record.
 *
 * Swap `mapPidToPatient` for a real Neo4j name+birthDate resolver later; the
 * call sites (status route, Credentials provider) depend only on this contract.
 */
import type { EudiVerifiedPatient } from "@/lib/eudi-store";
 
/** Normalised PID claims (mdoc eu.europa.ec.eudi.pid.1 / SD-JWT pid). */
export interface VerifiedPid {
  familyName?: string;
  givenName?: string;
  birthDate?: string;
}
 
/** Fixed demo patient every verified wallet resolves to. */
export const DEMO_EUDI_PATIENT_USERNAME = "patient1";
 
export function mapPidToPatient(pid: VerifiedPid): EudiVerifiedPatient {
  const fullName = [pid.givenName, pid.familyName]
    .filter((s) => Boolean(s && s.trim()))
    .join(" ")
    .trim();
  return {
    username: DEMO_EUDI_PATIENT_USERNAME,
    displayName: fullName || "EUDI Wallet Patient",
    roles: ["PATIENT"],
  };
}