From 59e326673c03ff161a55cf468bfd9cd00bff2874 Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Thu, 6 Feb 2025 18:08:24 +0800 Subject: [PATCH] fix: do not include age_over_NN attributes by default (#56) Signed-off-by: Timo Glastra --- .changeset/orange-jeans-build.md | 5 +++ src/__tests__/issuing/issuing-mdoc.tests.ts | 6 ---- src/mdoc/model/document.ts | 36 +-------------------- 3 files changed, 6 insertions(+), 41 deletions(-) create mode 100644 .changeset/orange-jeans-build.md diff --git a/.changeset/orange-jeans-build.md b/.changeset/orange-jeans-build.md new file mode 100644 index 0000000..6155874 --- /dev/null +++ b/.changeset/orange-jeans-build.md @@ -0,0 +1,5 @@ +--- +"@animo-id/mdoc": minor +--- + +fix: do not include age_over_NN attributes by default diff --git a/src/__tests__/issuing/issuing-mdoc.tests.ts b/src/__tests__/issuing/issuing-mdoc.tests.ts index af2f788..c8963ee 100644 --- a/src/__tests__/issuing/issuing-mdoc.tests.ts +++ b/src/__tests__/issuing/issuing-mdoc.tests.ts @@ -108,12 +108,6 @@ describe('issuing an MDOC', () => { "family_name" => "Jones", "given_name" => "Ava", "birth_date" => "2007-03-25", - "age_over_12" => true, - "age_over_14" => true, - "age_over_16" => true, - "age_over_18" => false, - "age_over_21" => false, - "age_over_65" => false, "issue_date" => "2023-09-01", "expiry_date" => "2028-09-30", "issuing_country" => "US", diff --git a/src/mdoc/model/document.ts b/src/mdoc/model/document.ts index 99eb342..e85ac2b 100644 --- a/src/mdoc/model/document.ts +++ b/src/mdoc/model/document.ts @@ -38,26 +38,6 @@ export default function isObject(input: unknown): input is Record { - const birthDate = new Date(birth) - birthDate.setHours(0, 0, 0, 0) - // @ts-expect-error this works - const ageDifMs = Date.now() - birthDate - const ageDate = new Date(ageDifMs) - return Math.abs(ageDate.getUTCFullYear() - 1970) -} - const addYears = (date: Date, years: number): Date => { const r = new Date(date.getTime()) r.setFullYear(date.getFullYear() + years) @@ -138,24 +118,10 @@ export class Document { for (const [key, value] of Object.entries(values)) { addAttribute(key, value) - if (this.docType === 'org.iso.18013.5.1.mDL' && key === 'birth_date') { + if (this.docType === 'org.iso.18013.5.1.mDL' && namespace === DEFAULT_NS && key === 'birth_date') { if (typeof value !== 'string') { throw new Error(`Invalid type for 'birth_date'. Expected 'string', received '${typeof value}'`) } - - const ageInYears = getAgeInYears(value) - const addAgePredicate = (predicate: number) => addAttribute(`age_over_${predicate}`, ageInYears >= predicate) - - // Age predicates. - // Values defined in: https://bmi.usercontent.opencode.de/eudi-wallet/eidas-2.0-architekturkonzept/functions/00-pid-issuance-and-presentation/#pid-contents - // ISO/IEC 18013-5: 7.2.5 does not define which ages should be included. - - addAgePredicate(12) - addAgePredicate(14) - addAgePredicate(16) - addAgePredicate(18) - addAgePredicate(21) - addAgePredicate(65) } }