diff --git a/.changeset/tiny-chefs-drum.md b/.changeset/tiny-chefs-drum.md new file mode 100644 index 0000000..f45ba2c --- /dev/null +++ b/.changeset/tiny-chefs-drum.md @@ -0,0 +1,5 @@ +--- +"@animo-id/mdoc": patch +--- + +Include different age*over_NN values and exclude age_over* diff --git a/src/__tests__/issuing/issuing-mdoc.tests.ts b/src/__tests__/issuing/issuing-mdoc.tests.ts index d41e889..af2f788 100644 --- a/src/__tests__/issuing/issuing-mdoc.tests.ts +++ b/src/__tests__/issuing/issuing-mdoc.tests.ts @@ -103,15 +103,17 @@ describe('issuing an MDOC', () => { it('should include the namespace and attributes', () => { const attrValues = parsedDocument.getIssuerNameSpace('org.iso.18013.5.1') - // @ts-expect error this will work - const currentAge = new Date(Date.now() - new Date('2007-03-25').getTime()).getFullYear() - 1970 expect(attrValues).toMatchInlineSnapshot(` Map { "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_17" => true, + "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 d4d13f5..99eb342 100644 --- a/src/mdoc/model/document.ts +++ b/src/mdoc/model/document.ts @@ -38,6 +38,17 @@ export default function isObject(input: unknown): input is Record { const birthDate = new Date(birth) birthDate.setHours(0, 0, 0, 0) @@ -131,9 +142,20 @@ export class Document { if (typeof value !== 'string') { throw new Error(`Invalid type for 'birth_date'. Expected 'string', received '${typeof value}'`) } + const ageInYears = getAgeInYears(value) - addAttribute('age_over_21', ageInYears >= 21) - addAttribute(`age_over_${Math.floor(ageInYears)}`, true) + 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) } }