Skip to content

Commit ff41f06

Browse files
chore: add better age_over_NN attributes (#46)
Signed-off-by: Berend Sliedrecht <[email protected]>
1 parent d45598d commit ff41f06

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

.changeset/tiny-chefs-drum.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@animo-id/mdoc": patch
3+
---
4+
5+
Include different age*over_NN values and exclude age_over*<CURRENT_AGE>

src/__tests__/issuing/issuing-mdoc.tests.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,17 @@ describe('issuing an MDOC', () => {
103103

104104
it('should include the namespace and attributes', () => {
105105
const attrValues = parsedDocument.getIssuerNameSpace('org.iso.18013.5.1')
106-
// @ts-expect error this will work
107-
const currentAge = new Date(Date.now() - new Date('2007-03-25').getTime()).getFullYear() - 1970
108106
expect(attrValues).toMatchInlineSnapshot(`
109107
Map {
110108
"family_name" => "Jones",
111109
"given_name" => "Ava",
112110
"birth_date" => "2007-03-25",
111+
"age_over_12" => true,
112+
"age_over_14" => true,
113+
"age_over_16" => true,
114+
"age_over_18" => false,
113115
"age_over_21" => false,
114-
"age_over_17" => true,
116+
"age_over_65" => false,
115117
"issue_date" => "2023-09-01",
116118
"expiry_date" => "2028-09-30",
117119
"issuing_country" => "US",

src/mdoc/model/document.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ export default function isObject(input: unknown): input is Record<string, unknow
3838

3939
const DEFAULT_NS = 'org.iso.18013.5.1'
4040

41+
// TODO:
42+
//
43+
// This should be calculated from the `validFrom` field in device retrieval
44+
// and the `iat` from server retrieval. Not `Date.now()`
45+
//
46+
// In case of device retrieval, the value of an age_over_NN data element
47+
// shall be calculated by the issuing authority infrastructure to be valid
48+
// at the value of the timestamp in the validFrom element in the MSO
49+
// from 9.1.2.4. In case of server retrieval, the value of an age_over_NN
50+
// data element shall be valid at the value of the iat timestamp as
51+
// defined in 8.3.2.2.2.2 and 8.3.3.2.2.
4152
const getAgeInYears = (birth: string): number => {
4253
const birthDate = new Date(birth)
4354
birthDate.setHours(0, 0, 0, 0)
@@ -131,9 +142,20 @@ export class Document {
131142
if (typeof value !== 'string') {
132143
throw new Error(`Invalid type for 'birth_date'. Expected 'string', received '${typeof value}'`)
133144
}
145+
134146
const ageInYears = getAgeInYears(value)
135-
addAttribute('age_over_21', ageInYears >= 21)
136-
addAttribute(`age_over_${Math.floor(ageInYears)}`, true)
147+
const addAgePredicate = (predicate: number) => addAttribute(`age_over_${predicate}`, ageInYears >= predicate)
148+
149+
// Age predicates.
150+
// Values defined in: https://bmi.usercontent.opencode.de/eudi-wallet/eidas-2.0-architekturkonzept/functions/00-pid-issuance-and-presentation/#pid-contents
151+
// ISO/IEC 18013-5: 7.2.5 does not define which ages should be included.
152+
153+
addAgePredicate(12)
154+
addAgePredicate(14)
155+
addAgePredicate(16)
156+
addAgePredicate(18)
157+
addAgePredicate(21)
158+
addAgePredicate(65)
137159
}
138160
}
139161

0 commit comments

Comments
 (0)