Skip to content

Commit 864cb0e

Browse files
authored
Merge pull request #41 from auth0-lab/age_over_xy
fix(issuance): stop including `age_over_{age}` and `age_over_21` when `birth_date` is set
2 parents a0d6be2 + 901a29f commit 864cb0e

File tree

3 files changed

+1
-20
lines changed

3 files changed

+1
-20
lines changed

__tests__/example/example5.tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('example 5: device response contains a partial x5chain of the issuer ce
7070

7171
expect(diagnosticInfo.issuerSignature).toEqual({
7272
alg: 'EdDSA',
73-
digests: { 'org.iso.18013.5.1': 5 },
73+
digests: { 'org.iso.18013.5.1': 3 },
7474
isValid: true,
7575
reasons: [],
7676
});

__tests__/issuing/issuingMDoc.tests.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,8 @@ describe('issuing an MDOC', () => {
104104

105105
it('should include the namespace and attributes', () => {
106106
const attrValues = parsedDocument.getIssuerNameSpace('org.iso.18013.5.1');
107-
// @ts-ignore
108-
const currentAge = new Date(Date.now() - new Date('2007-03-25')).getFullYear() - 1970;
109107
expect(attrValues).toMatchInlineSnapshot(`
110108
{
111-
"age_over_${currentAge}": true,
112-
"age_over_21": ${currentAge >= 21},
113109
"birth_date": "2007-03-25",
114110
"document_number": "01-856-5050",
115111
"driving_privileges": [

src/mdoc/model/Document.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ import { IssuerSignedDocument } from './IssuerSignedDocument';
99

1010
const DEFAULT_NS = 'org.iso.18013.5.1';
1111

12-
const getAgeInYears = (birth: string): number => {
13-
const birthDate = new Date(birth);
14-
birthDate.setHours(0, 0, 0, 0);
15-
// @ts-ignore
16-
const ageDifMs = Date.now() - birthDate;
17-
const ageDate = new Date(ageDifMs);
18-
return Math.abs(ageDate.getUTCFullYear() - 1970);
19-
};
20-
2112
const addYears = (date: Date, years: number): Date => {
2213
const r = new Date(date.getTime());
2314
r.setFullYear(date.getFullYear() + years);
@@ -89,12 +80,6 @@ export class Document {
8980

9081
for (const [key, value] of Object.entries(values)) {
9182
addAttribute(key, value);
92-
93-
if (key === 'birth_date' && namespace === DEFAULT_NS) {
94-
const ageInYears = getAgeInYears(value);
95-
addAttribute('age_over_21', ageInYears >= 21);
96-
addAttribute(`age_over_${Math.floor(ageInYears)}`, true);
97-
}
9883
}
9984

10085
return this;

0 commit comments

Comments
 (0)