@gwydion-id/icao-9303-models 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSES/CC0-1.0.txt +121 -0
  2. package/LICENSES/LGPL-3.0-or-later.txt +304 -0
  3. package/README.md +79 -0
  4. package/package.json +17 -0
  5. package/package.json.license +3 -0
  6. package/src/digitalseal.js +234 -0
  7. package/src/digitalsealv3.js +359 -0
  8. package/src/digitalsealv4.js +369 -0
  9. package/src/index.js +41 -0
  10. package/src/mrvadocument.js +465 -0
  11. package/src/mrvadocumentwithvds3.js +559 -0
  12. package/src/mrvadocumentwithvds4.js +559 -0
  13. package/src/mrvbdocument.js +466 -0
  14. package/src/mrvbdocumentwithvds3.js +560 -0
  15. package/src/mrvbdocumentwithvds4.js +560 -0
  16. package/src/td1document.js +408 -0
  17. package/src/td1documentwithvds3.js +479 -0
  18. package/src/td1documentwithvds4.js +479 -0
  19. package/src/td2document.js +379 -0
  20. package/src/td2documentwithvds3.js +466 -0
  21. package/src/td2documentwithvds4.js +466 -0
  22. package/src/td3document.js +391 -0
  23. package/src/td3documentwithvds3.js +466 -0
  24. package/src/td3documentwithvds4.js +466 -0
  25. package/src/traveldocument.js +306 -0
  26. package/src/utilities/bytes-to-date.js +23 -0
  27. package/src/utilities/c40-decode.js +225 -0
  28. package/src/utilities/c40-encode.js +254 -0
  29. package/src/utilities/c40-shift1.js +10 -0
  30. package/src/utilities/date-to-bytes.js +38 -0
  31. package/src/utilities/der-length-to-length.js +33 -0
  32. package/src/utilities/expand-year.js +26 -0
  33. package/src/utilities/gender-marker-to-mrz.js +14 -0
  34. package/src/utilities/generate-mrz-check-digit.js +139 -0
  35. package/src/utilities/icao-date.js +234 -0
  36. package/src/utilities/length-to-der-length.js +41 -0
  37. package/src/utilities/nationality-codes.js +303 -0
  38. package/src/utilities/normalize-mrz-string.js +19 -0
  39. package/src/utilities/optional-data-mrz.js +29 -0
  40. package/src/utilities/pad-mrz-string.js +16 -0
  41. package/src/utilities/set-signature-zone.js +34 -0
  42. package/src/utilities/stringify-validation-array.js +27 -0
  43. package/src/utilities/validate-hex-string.js +41 -0
  44. package/src/utilities/validate-identifier-code.js +38 -0
  45. package/src/utilities/validate-mrz-string.js +44 -0
  46. package/src/utilities/vds-magic.js +9 -0
  47. package/src/utilities/vds-signature-marker.js +9 -0
  48. package/src/utilities/vds-version-3.js +9 -0
  49. package/src/utilities/vds-version-4.js +9 -0
  50. package/src/visadocument.js +114 -0
  51. package/tests/models/digitalsealv4.test.js +67 -0
  52. package/tests/models/mrvadocument.test.js +61 -0
  53. package/tests/models/mrvbdocument.test.js +61 -0
  54. package/tests/models/td1document.test.js +50 -0
  55. package/tests/models/td2document.test.js +49 -0
  56. package/tests/models/td3document.test.js +88 -0
  57. package/tests/utilities/c40-encodation-scheme.test.js +34 -0
  58. package/tests/utilities/der-tlv-length-conversion.test.js +99 -0
  59. package/tests/utilities/document-utilities.test.js +199 -0
  60. package/tests/utilities/icao-constants.test.js +35 -0
  61. package/tests/utilities/icao-date.test.js +141 -0
  62. package/tests/utilities/vds-date-conversions.test.js +28 -0
@@ -0,0 +1,88 @@
1
+ // SPDX-FileCopyrightText: 2026 Don Geronimo <https://sentamal.in>
2
+ // SPDX-License-Identifier: LGPL-3.0-or-later
3
+
4
+ import { describe, it } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import { TD3Document } from '../../src/td3document.js';
7
+
8
+ describe('TD3-sized Machine Readable Travel Document', () => {
9
+
10
+ describe('Use properties to reconstruct exemplary MRZ from documentation [REF ICAO 9303 Part 4 Appendix A]', () => {
11
+ it('should equal the exemplary TD3 MRTD MRZ in Appendix A-1 and A-2.', () => {
12
+ const document = new TD3Document({
13
+ typeCode: 'PP',
14
+ authorityCode: 'UTO',
15
+ number: 'L898902C3',
16
+ birthDate: '1974-08-12',
17
+ genderMarker: 'F',
18
+ expirationDate: '2034-04-15',
19
+ nationalityCode: 'UTO',
20
+ primaryIdentifier: 'Eriksson',
21
+ secondaryIdentifier: 'Anna-Maria',
22
+ optionalData: 'ZE184226B'
23
+ });
24
+ assert.deepStrictEqual(document.mrzLine1, 'PPUTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<');
25
+ assert.deepStrictEqual(document.mrzLine2, 'L898902C36UTO7408122F3404159ZE184226B<<<<<16');
26
+ assert.deepStrictEqual(document.machineReadableZone, 'PPUTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<L898902C36UTO7408122F3404159ZE184226B<<<<<16');
27
+ });
28
+ });
29
+
30
+ describe('Import exemplary MRZ data from documentation [REF ICAO 9303 Part 4 Appendix A]', () => {
31
+ it('document properties should equal the values from the exemplary TD3 MRTD in Appendix A-1 and A-2', () => {
32
+ const document = new TD3Document({
33
+ machineReadableZone: 'PPUTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<L898902C36UTO7408122F3404159ZE184226B<<<<<16'
34
+ });
35
+ assert.deepStrictEqual(document.typeCode, 'PP');
36
+ assert.deepStrictEqual(document.authorityCode, 'UTO');
37
+ assert.deepStrictEqual(document.number, 'L898902C3');
38
+ assert.deepStrictEqual(document.birthDate.toISOString(), '1974-08-12');
39
+ assert.deepStrictEqual(document.genderMarker, 'F');
40
+ assert.deepStrictEqual(document.expirationDate.toISOString(), '2034-04-15');
41
+ assert.deepStrictEqual(document.nationalityCode, 'UTO');
42
+ assert.deepStrictEqual(document.primaryIdentifier, 'ERIKSSON');
43
+ assert.deepStrictEqual(document.secondaryIdentifier, 'ANNA MARIA');
44
+ assert.deepStrictEqual(document.optionalData, 'ZE184226B');
45
+ });
46
+ });
47
+
48
+ describe('Use properties to reconstruct a MRZ from the additional exemplary TD3 for "Anna Ivanova" [REF ICAO 9303 Part 4 Appendix A]', () => {
49
+ // The MRZ is 90 characters long, 45 characters each line, in the exemplary TD3. The specifications require 88 characters long, 44 characters per line.
50
+ it('should equal the MRZ in the exemplary TD3 MRTD MRZ for "Anna Ivanova" in Appendix A-1', () => {
51
+ const document = new TD3Document({
52
+ typeCode: 'PP',
53
+ authorityCode: 'UTO',
54
+ primaryIdentifier: 'Ivanova',
55
+ secondaryIdentifier: 'Anna',
56
+ number: 'L898902C3',
57
+ nationalityCode: 'UTO',
58
+ birthDate: '1974-08-12',
59
+ genderMarker: 'F',
60
+ expirationDate: '2025-04-15',
61
+ optionalData: '184226'
62
+ });
63
+ assert.deepStrictEqual(document.mrzLine1, 'PPUTOIVANOVA<<ANNA<<<<<<<<<<<<<<<<<<<<<<<<<<');
64
+ assert.deepStrictEqual(document.mrzLine2, 'L898902C36UTO7408122F2504155184226<<<<<<<<18');
65
+ assert.deepStrictEqual(document.machineReadableZone, 'PPUTOIVANOVA<<ANNA<<<<<<<<<<<<<<<<<<<<<<<<<<L898902C36UTO7408122F2504155184226<<<<<<<<18');
66
+ });
67
+ });
68
+
69
+ describe('Import MRZ data of the additional exemplary TD3 for "Anna Ivanova" [REF ICAO 9303 Part 4 Appendix A]', () => {
70
+ it('document properties should equal the values from the exemplary TD3 MRTD for "Anna Ivanova" in Appendix A-1.', () => {
71
+ const document = new TD3Document({
72
+ machineReadableZone: 'PPUTOIVANOVA<<ANNA<<<<<<<<<<<<<<<<<<<<<<<<<<L898902C36UTO7408122F2504155184226<<<<<<<<18'
73
+ });
74
+ assert.deepStrictEqual(document.typeCode, 'PP');
75
+ assert.deepStrictEqual(document.authorityCode, 'UTO');
76
+ assert.deepStrictEqual(document.primaryIdentifier, 'IVANOVA');
77
+ assert.deepStrictEqual(document.secondaryIdentifier, 'ANNA');
78
+ assert.deepStrictEqual(document.number, 'L898902C3');
79
+ assert.deepStrictEqual(document.nationalityCode, 'UTO');
80
+ assert.deepStrictEqual(document.birthDate.toISOString(), '1974-08-12');
81
+ assert.deepStrictEqual(document.genderMarker, 'F');
82
+ assert.deepStrictEqual(document.expirationDate.toISOString(), '2025-04-15');
83
+ assert.deepStrictEqual(document.optionalData, '184226');
84
+ });
85
+ });
86
+
87
+ });
88
+
@@ -0,0 +1,34 @@
1
+ // SPDX-FileCopyrightText: 2026 Don Geronimo <https://sentamal.in>
2
+ // SPDX-License-Identifier: LGPL-3.0-or-later
3
+
4
+ import { describe, it } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import { c40Encode } from '../../src/utilities/c40-encode.js';
7
+ import { c40Decode } from '../../src/utilities/c40-decode.js';
8
+
9
+ describe('C40 Encodation Scheme', () => {
10
+
11
+ describe('c40Encode - Encode a string using the C40 encoding scheme [REF ICAO Doc 9303 Part 13, Appendix C]', () => {
12
+ it('should encode "XK<CD" into [0xEB, 0x04, 0x66, 0xA9].', () => {
13
+ assert.deepStrictEqual(c40Encode('XK<CD'), [0xeb, 0x04, 0x66, 0xa9]);
14
+ });
15
+ it('should encode "XKCD" into [0xEB, 0x11, 0xFE, 0x45].', () => {
16
+ // Note that there is an error in the document as it states Byte 2 should be 11 (decimal), 0x11 (hexadecimal).
17
+ // 0x11 (hexidecimal) equals 17 (decimal)
18
+ assert.deepStrictEqual(c40Encode('XKCD'), [0xeb, 0x11, 0xfe, 0x45]);
19
+ });
20
+ });
21
+
22
+ describe('c40Decode - Decode a byte array using the C40 decoding scheme [REF ICAO Doc 9303 Part 13, Appendix C]', () => {
23
+ it('should decode [0xEB, 0x04, 0x66, 0xA9] into "XK CD".', () => {
24
+ assert.deepStrictEqual(c40Decode([0xeb, 0x04, 0x66, 0xa9]), 'XK CD');
25
+ });
26
+ it('should decode [0xEB, 0x11, 0xFE, 0x45] into "XKCD".', () => {
27
+ // Note that there is an error in the document as it states Byte 2 should be 11 (decimal), 0x11 (hexadecimal).
28
+ // 0x11 (hexidecimal) equals 17 (decimal)
29
+ assert.deepStrictEqual(c40Decode([0xeb, 0x11, 0xfe, 0x45]), 'XKCD');
30
+ });
31
+ });
32
+
33
+ });
34
+
@@ -0,0 +1,99 @@
1
+ // SPDX-FileCopyrightText: 2026 Don Geronimo <https://sentamal.in>
2
+ // SPDX-License-Identifier: LGPL-3.0-or-later
3
+
4
+ import { describe, it } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import { lengthToDERLength } from '../../src/utilities/length-to-der-length.js';
7
+ import { derLengthToLength } from '../../src/utilities/der-length-to-length.js';
8
+
9
+ describe('DER-TLV Length Conversion', () => {
10
+
11
+ describe('lengthToDERLength - Convert a length into the shortest DER definite form for a number', () => {
12
+ it('should output [0x00] from 0.', () => {
13
+ assert.deepStrictEqual(lengthToDERLength(0), [0x00]);
14
+ });
15
+ it('should output [0x01] from 1.', () => {
16
+ assert.deepStrictEqual(lengthToDERLength(1), [0x01]);
17
+ });
18
+ it('should output [0x7F] from 127.', () => {
19
+ assert.deepStrictEqual(lengthToDERLength(127), [0x7f]);
20
+ });
21
+ it('should output [0x81, 0x80] from 128.', () => {
22
+ assert.deepStrictEqual(lengthToDERLength(128), [0x81, 0x80]);
23
+ });
24
+ it('should output [0x81, 0xFF] from 255.', () => {
25
+ assert.deepStrictEqual(lengthToDERLength(255), [0x81, 0xFF]);
26
+ });
27
+ it('should output [0x82, 0x01, 0x00] from 256.', () => {
28
+ assert.deepStrictEqual(lengthToDERLength(256), [0x82, 0x01, 0x00]);
29
+ });
30
+ it('should output [0x82, 0xFF, 0xFF] from 65535.', () => {
31
+ assert.deepStrictEqual(lengthToDERLength(65535), [0x82, 0xff, 0xff]);
32
+ });
33
+ it('should output [0x83, 0x01, 0x00, 0x00] from 65536.', () => {
34
+ assert.deepStrictEqual(lengthToDERLength(65536), [0x83, 0x01, 0x00, 0x00]);
35
+ });
36
+ it('should output [0x83, 0xFF, 0xFF, 0xFF] from 16777215.', () => {
37
+ assert.deepStrictEqual(lengthToDERLength(16777215), [0x83, 0xff, 0xff, 0xff]);
38
+ });
39
+ it('should output [0x84, 0x01, 0x00, 0x00, 0x00] from 16777216.', () => {
40
+ assert.deepStrictEqual(lengthToDERLength(16777216), [0x84, 0x01, 0x00, 0x00, 0x00]);
41
+ });
42
+ it('should output [0x84, 0xFF, 0xFF, 0xFF, 0xFF] from 4294967295.', () => {
43
+ assert.deepStrictEqual(lengthToDERLength(4294967295), [0x84, 0xff, 0xff, 0xff, 0xff]);
44
+ });
45
+ it('should throw a RangeError if, in the context of VDS, the length value is larger than five bytes.', () => {
46
+ assert.throws( () => {
47
+ lengthToDERLength(4294967296);
48
+ }, RangeError);
49
+ });
50
+ });
51
+
52
+ describe('derLengthToLength - Convert a DER definite form for a number into a length', () => {
53
+ it('should output 0 from [0x00].', () => {
54
+ assert.deepStrictEqual(derLengthToLength([0x00]), 0);
55
+ });
56
+ it('should output 1 from [0x01].', () => {
57
+ assert.deepStrictEqual(derLengthToLength([0x01]), 1);
58
+ });
59
+ it('should output 127 from [0x7F].', () => {
60
+ assert.deepStrictEqual(derLengthToLength([0x7f]), 127);
61
+ });
62
+ it('should output 128 from [0x81, 0x80].', () => {
63
+ assert.deepStrictEqual(derLengthToLength([0x81, 0x80]), 128);
64
+ });
65
+ it('should output 255 from [0x81, 0xFF].', () => {
66
+ assert.deepStrictEqual(derLengthToLength([0x81, 0xff]), 255);
67
+ });
68
+ it('should output 256 from [0x82, 0x01, 0x00].', () => {
69
+ assert.deepStrictEqual(derLengthToLength([0x82, 0x01, 0x00]), 256);
70
+ });
71
+ it('should output 65535 from [0x82, 0xFF, 0xFF].', () => {
72
+ assert.deepStrictEqual(derLengthToLength([0x82, 0xff, 0xff]), 65535);
73
+ });
74
+ it('should output 65536 from [0x83, 0x01, 0x00, 0x00].', () => {
75
+ assert.deepStrictEqual(derLengthToLength([0x83, 0x01, 0x00, 0x00]), 65536);
76
+ });
77
+ it('should output 16777215 from [0x83, 0xFF, 0xFF, 0xFF].', () => {
78
+ assert.deepStrictEqual(derLengthToLength([0x83, 0xff, 0xff, 0xff]), 16777215);
79
+ });
80
+ it('should output 16777216 from [0x84, 0x01, 0x00, 0x00, 0x00].', () => {
81
+ assert.deepStrictEqual(derLengthToLength([0x84, 0x01, 0x00, 0x00, 0x00]), 16777216);
82
+ });
83
+ it('should output 4294967295 from [0x84, 0xFF, 0xFF, 0xFF, 0xFF].', () => {
84
+ assert.deepStrictEqual(derLengthToLength([0x84, 0xff, 0xff, 0xff, 0xff]), 4294967295);
85
+ });
86
+ it('should throw a RangeError if, in the context of VDS, the DER definite form is larger than five bytes.', () => {
87
+ assert.throws( () => {
88
+ derLengthToLength([0x85, 0x01, 0x00, 0x00, 0x00, 0x00]);
89
+ }, RangeError);
90
+ });
91
+ it('should throw a RangeError if the initial length byte is set to indefinite length (0x80).', () => {
92
+ assert.throws( () => {
93
+ derLengthToLength([0x80]);
94
+ }, RangeError);
95
+ });
96
+ });
97
+
98
+ });
99
+
@@ -0,0 +1,199 @@
1
+ // SPDX-FileCopyrightText: 2026 Don Geronimo <https://sentamal.in>
2
+ // SPDX-License-Identifier: LGPL-3.0-or-later
3
+
4
+ import { describe, it } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import { expandYear } from "../../src/utilities/expand-year.js";
7
+ import { genderMarkerToMRZ } from '../../src/utilities/gender-marker-to-mrz.js';
8
+ import { generateMRZCheckDigit } from '../../src/utilities/generate-mrz-check-digit.js';
9
+ import { normalizeMRZString } from '../../src/utilities/normalize-mrz-string.js';
10
+ import { optionalDataMRZ } from '../../src/utilities/optional-data-mrz.js';
11
+ import { padMRZString } from '../../src/utilities/pad-mrz-string.js';
12
+ import { setSignatureZone } from '../../src/utilities/set-signature-zone.js';
13
+ import { validateHexString } from '../../src/utilities/validate-hex-string.js';
14
+ import { validateIdentifierCode } from '../../src/utilities/validate-identifier-code.js';
15
+ import { validateMRZString } from '../../src/utilities/validate-mrz-string.js';
16
+
17
+ describe('Document Utility Functions', () => {
18
+
19
+ describe('expandYear - Expands a two-digit year into a four-digit year within the window (maxYear - 100, maxYear]', () => {
20
+ it('should expand birth dates correctly. (maxYear = 2026)', () => {
21
+ const maxYear = 2026;
22
+ assert.equal(expandYear('26', maxYear), 2026);
23
+ assert.equal(expandYear(26, maxYear), 2026);
24
+ assert.equal(expandYear('99', maxYear), 1999);
25
+ assert.equal(expandYear('55', maxYear), 1955);
26
+ assert.equal(expandYear('27', maxYear), 1927);
27
+ });
28
+ it('should expand expiration dates correctly. (maxYear = 2046)', () => {
29
+ const maxYear = 2046;
30
+ assert.equal(expandYear('30', maxYear), 2030);
31
+ assert.equal(expandYear('46', maxYear), 2046);
32
+ assert.equal(expandYear('90', maxYear), 1990);
33
+ assert.equal(expandYear('50', maxYear), 1950);
34
+ assert.equal(expandYear('47', maxYear), 1947);
35
+ });
36
+ it('should handle zero-padded string and numeric inputs identically.', () => {
37
+ const maxYear = 2026;
38
+ assert.equal(expandYear('00', maxYear), 2000);
39
+ assert.equal(expandYear(0, maxYear), 2000);
40
+ assert.equal(expandYear('05', maxYear), 2005);
41
+ assert.equal(expandYear(5, maxYear), 2005);
42
+ });
43
+ it('should handle multi-century century boundaries.', () => {
44
+ const maxYear = 2105;
45
+ assert.equal(expandYear('05', maxYear), 2105);
46
+ assert.equal(expandYear('06', maxYear), 2006);
47
+ assert.equal(expandYear('99', maxYear), 2099);
48
+ });
49
+ it('should throw errors for invalid two-digit year values.', () => {
50
+ const maxYear = 2026;
51
+ assert.throws( () => { expandYear(-1, maxYear) }, RangeError);
52
+ assert.throws( () => { expandYear(100, maxYear) }, RangeError);
53
+ assert.throws( () => { expandYear('abc', maxYear) }, RangeError);
54
+ assert.throws( () => { expandYear(NaN, maxYear) }, RangeError);
55
+ });
56
+ });
57
+
58
+ describe('genderMarkerToMRZ - If the gender marker is X convert to a < in the MRZ', () => {
59
+ it('should output "M" for "M".', () => {
60
+ assert.deepStrictEqual(genderMarkerToMRZ('M'), 'M');
61
+ });
62
+ it('should output "F" for "F".', () => {
63
+ assert.deepStrictEqual(genderMarkerToMRZ('F'), 'F');
64
+ });
65
+ it('should output "<" for "X".', () => {
66
+ assert.deepStrictEqual(genderMarkerToMRZ('X'), '<');
67
+ });
68
+ });
69
+
70
+ describe('generateMRZCheckDigit - Generate a check digit for a MRZ string [REF ICAO Doc 9303 Part 3 SS 4.9, Page 19]', () => {
71
+ it('should output "3" for "520727".', () => {
72
+ assert.deepStrictEqual(generateMRZCheckDigit('520727'), '3');
73
+ });
74
+ it('should output "5" for "AB2134<<<".', () => {
75
+ assert.deepStrictEqual(generateMRZCheckDigit('AB2134<<<'), '5');
76
+ });
77
+ it('should output "8" for composite check digit of exemplary TD3 MRZ in Appendix A-2.', () => {
78
+ assert.deepStrictEqual(generateMRZCheckDigit(
79
+ 'HA672242<6' + '5802254' + '9601086<<<<<<<<<<<<<<0'
80
+ ), '8');
81
+ });
82
+ it('should output "2" for composite check digit of exemplary TD1 MRZ in Appendix A-3.', () => {
83
+ assert.deepStrictEqual(generateMRZCheckDigit(
84
+ 'D231458907<<<<<<<<<<<<<<<' + '3407127' + '9507122' + '<<<<<<<<<<<'
85
+ ), '2');
86
+ });
87
+ it('should output "8" for composite check digit of exemplary TD2 MRZ in Appendix A-4.', () => {
88
+ assert.deepStrictEqual(generateMRZCheckDigit(
89
+ 'HA672242<6' + '5802254' + '9601086<<<<<<<'
90
+ ), '8');
91
+ });
92
+ });
93
+
94
+ describe('normalizeMRZString - Remove diacritics and punctuation from a MRZ string', () => {
95
+ it('should return "ADRIAN<CLAUDE<DEVELEAU" from "ADRIAN-CLAUDE D\'EVELEAU".', () => {
96
+ assert.deepStrictEqual(normalizeMRZString('ADRIAN-CLAUDE D\'EVELEAU'), 'ADRIAN<CLAUDE<DEVELEAU');
97
+ });
98
+ });
99
+
100
+ describe('optionalDataMRZ - Normalize and pad additional data for the optional data area of the MRZ', () => {
101
+ it('should return "EXAMPLE<<<<<<<" from "EXAMPLE" with a length 14.', () => {
102
+ assert.deepStrictEqual(optionalDataMRZ("EXAMPLE", 14), 'EXAMPLE<<<<<<<');
103
+ });
104
+ });
105
+
106
+ describe('padMRZString - Pad the end of a MRZ string to the desired length with the filler character', () => {
107
+ it('should return "ALFALFA<<" from "ALFALFA" with length 9.', () => {
108
+ assert.deepStrictEqual(padMRZString('ALFALFA', 9), 'ALFALFA<<');
109
+ });
110
+ });
111
+
112
+ describe('setSignatureZone - Given a starting point in a byte array extract the raw signature data', () => {
113
+ const validSignatureZone = [ 0xFF, 0x40, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88 ];
114
+ const invalidLength = [ 0xFF, 0x40, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99 ];
115
+ const invalidMarker = [ 0xFE, 0x40, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88 ];
116
+
117
+ it('should return the raw signature data from a valid signature zone.', () => {
118
+ assert.deepStrictEqual(setSignatureZone(0, validSignatureZone), [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88 ]);
119
+ });
120
+ it('should throw a RangeError if the length is invalid.', () => {
121
+ assert.throws( () => {
122
+ setSignatureZone(0, invalidLength);
123
+ }, RangeError);
124
+ });
125
+ it('should throw a TypeError if the first byte is not the signature marker.', () => {
126
+ assert.throws( () => {
127
+ setSignatureZone(0, invalidMarker);
128
+ }, TypeError);
129
+ });
130
+ });
131
+
132
+ describe('validateHexString - Check to see if a string is a hexidecimal string and optionally meets a min/max length', () => {
133
+ it('should return an empty string if all checks validate.', () => {
134
+ assert.ok(validateHexString('123456789ABCDEF', {
135
+ minimum: 1,
136
+ maximum: 15
137
+ }).length === 0);
138
+ });
139
+ it('should not return an empty string if minimum characters not met.', () => {
140
+ assert.ok(validateHexString('123456789ABCDEF', {
141
+ minimum: 16,
142
+ maximum: 32
143
+ }).length > 0);
144
+ });
145
+ it('should not return an empty string if maximum characters not met.', () => {
146
+ assert.ok(validateHexString('123456789ABCDEF', {
147
+ minimum: 1,
148
+ maximum: 14
149
+ }).length > 0);
150
+ });
151
+ it('should not return an empty string if using characters other than 0-9 or A-F.', () => {
152
+ assert.ok(validateHexString('123456789ABCDEG', {
153
+ minimum: 1,
154
+ maximum: 15
155
+ }).length > 0);
156
+ });
157
+ });
158
+
159
+ describe('validateIdentifierCode - Check to see if a string meets the requirements of a VDS identifier code [REF ICAO 9303 Part 13 SS 2.2.1, Page 4]', () => {
160
+ it('should return an empty string if all checks validate.', () => {
161
+ assert.ok(validateIdentifierCode('UT01').length === 0);
162
+ });
163
+ it('should not return an empty string if using characters other than A-Z in the country code.', () => {
164
+ assert.ok(validateIdentifierCode('U9T1').length > 0);
165
+ });
166
+ it('should not return an empty string if using characters other than 0-9 or A-Z in the signer code.', () => {
167
+ assert.ok(validateIdentifierCode('UT0!').length > 0);
168
+ });
169
+ });
170
+
171
+ describe('validateMRZString - Check to see if a string meets the requirements to be used in a document\'s MRZ', () => {
172
+ it('should return an empty string if all checks validate.', () => {
173
+ assert.ok(validateMRZString('UTOPIOPOLIS<UTOPIA', {
174
+ minimum: 1,
175
+ maximum: 18
176
+ }).length === 0);
177
+ });
178
+ it('should not return an empty string if minimum characters not met.', () => {
179
+ assert.ok(validateMRZString('UTOPIOPOLIS<UTOPIA', {
180
+ minimum: 19,
181
+ maximum: 36
182
+ }).length > 0);
183
+ });
184
+ it('should not return an empty string if maximum characters not met.', () => {
185
+ assert.ok(validateMRZString('UTOPIOPOLIS<UTOPIA', {
186
+ minimum: 1,
187
+ maximum: 17
188
+ }).length > 0);
189
+ });
190
+ it('should not return an empty string if using characters other than 0-9, A-Z, SPACE, or <', () => {
191
+ assert.ok(validateMRZString('UTOP!OPOLIS<UTOPIA', {
192
+ minimum: 1,
193
+ maximum: 18
194
+ }).length > 0);
195
+ });
196
+ });
197
+
198
+ });
199
+
@@ -0,0 +1,35 @@
1
+ // SPDX-FileCopyrightText: 2026 Don Geronimo <https://sentamal.in>
2
+ // SPDX-License-Identifier: LGPL-3.0-or-later
3
+
4
+ import { describe, it } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import { VDS_MAGIC } from '../../src/utilities/vds-magic.js';
7
+ import { VDS_SIGNATURE_MARKER } from '../../src/utilities/vds-signature-marker.js';
8
+ import { VDS_VERSION_3 } from '../../src/utilities/vds-version-3.js';
9
+ import { VDS_VERSION_4 } from '../../src/utilities/vds-version-4.js';
10
+
11
+ describe('ICAO Doc 9303 Specification Constants', () => {
12
+
13
+ describe('VDS_MAGIC - Identify a byte stream as a VDS [REF ICAO Doc 9303 Part 13 SS 2.2, Page 3]', () => {
14
+ it('should equal fixed value 0xDC.', () => {
15
+ assert.deepStrictEqual(VDS_MAGIC, 0xdc);
16
+ });
17
+ });
18
+ describe('VDS_VERSION_3 - Identify a byte stream as VDS version 3 [REF ICAO Doc 9303 Part 13 SS 2.2, Page 3]', () => {
19
+ it('should equal fixed value 0x02.', () => {
20
+ assert.deepStrictEqual(VDS_VERSION_3, 0x02);
21
+ });
22
+ });
23
+ describe('VDS_VERSION_4 - Identify a byte stream as VDS version 4 [REF ICAO Doc 9303 Part 13 SS 2.2, Page 3]', () => {
24
+ it('should equal fixed value 0x03.', () => {
25
+ assert.deepStrictEqual(VDS_VERSION_4, 0x03);
26
+ });
27
+ });
28
+ describe('VDS_SIGNATURE_MARKER - Identify the beginning of a VDS signature zone [REF ICAO Doc 9303 Part 13 SS 2.4, Page 6]', () => {
29
+ it('should equal fixed value 0xFF.', () => {
30
+ assert.deepStrictEqual(VDS_SIGNATURE_MARKER, 0xff);
31
+ });
32
+ });
33
+
34
+ });
35
+
@@ -0,0 +1,141 @@
1
+ // SPDX-FileCopyrightText: 2026 Don Geronimo <https://sentamal.in>
2
+ // SPDX-License-Identifier: LGPL-3.0-or-later
3
+
4
+ import { describe, it } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import { IcaoDate } from '../../src/utilities/icao-date.js';
7
+
8
+ describe('IcaoDate - Custom date object for ICAO 9303 MRTDs', () => {
9
+
10
+ describe('Pass 1957-03-25 through constructor', () => {
11
+ const date = new IcaoDate('1957-03-25');
12
+ it('.toISOString() should equal "1957-03-25".', () => {
13
+ assert.deepStrictEqual(date.toISOString(), '1957-03-25');
14
+ });
15
+ it('.toMRZString() should equal "570325".', () => {
16
+ assert.deepStrictEqual(date.toMRZString(), '570325');
17
+ });
18
+ it('.toVDSArray() should equal [0x31, 0x9E, 0xF5].', () => {
19
+ assert.deepStrictEqual(date.toVDSArray(), [0x31, 0x9e, 0xf5]);
20
+ });
21
+ });
22
+
23
+ describe('Pass 570325 through constructor', () => {
24
+ const date = new IcaoDate('570325', 2046);
25
+ it('.toISOString() should equal "1957-03-25".', () => {
26
+ assert.deepStrictEqual(date.toISOString(), '1957-03-25');
27
+ });
28
+ it('.toMRZString() should equal "570325".', () => {
29
+ assert.deepStrictEqual(date.toMRZString(), '570325');
30
+ });
31
+ it('.toVDSArray() should equal [0x31, 0x9E, 0xF5].', () => {
32
+ assert.deepStrictEqual(date.toVDSArray(), [0x31, 0x9e, 0xf5]);
33
+ });
34
+ });
35
+
36
+ describe('Pass new Date("1957-03-25T00:00:00") through constructor', () => {
37
+ const date = new IcaoDate(new Date('1957-03-25T00:00:00'));
38
+ it('.toISOString() should equal "1957-03-25".', () => {
39
+ assert.deepStrictEqual(date.toISOString(), '1957-03-25');
40
+ });
41
+ it('.toMRZString() should equal "570325".', () => {
42
+ assert.deepStrictEqual(date.toMRZString(), '570325');
43
+ });
44
+ it('.toVDSArray() should equal [0x31, 0x9E, 0xF5].', () => {
45
+ assert.deepStrictEqual(date.toVDSArray(), [0x31, 0x9e, 0xf5]);
46
+ });
47
+ });
48
+
49
+ describe('Pass [0x31, 0x9E, 0xF5] through constructor', () => {
50
+ const date = new IcaoDate([0x31, 0x9e, 0xf5]);
51
+ it('.toISOString() should equal "1957-03-25".', () => {
52
+ assert.deepStrictEqual(date.toISOString(), '1957-03-25');
53
+ });
54
+ it('.toMRZString() should equal "570325".', () => {
55
+ assert.deepStrictEqual(date.toMRZString(), '570325');
56
+ });
57
+ it('.toVDSArray() should equal [0x31, 0x9E, 0xF5].', () => {
58
+ assert.deepStrictEqual(date.toVDSArray(), [0x31, 0x9e, 0xf5]);
59
+ });
60
+ });
61
+
62
+ describe('Pass XXXX-03-25 through constructor', () => {
63
+ const date = new IcaoDate('XXXX-03-25');
64
+ it('.toISOString() should equal "XXXX-03-25".', () => {
65
+ assert.deepStrictEqual(date.toISOString(), 'XXXX-03-25');
66
+ });
67
+ it('.toMRZString() should equal "<<0325".', () => {
68
+ assert.deepStrictEqual(date.toMRZString(), '<<0325');
69
+ });
70
+ it('.toVDSArray() should throw a RangeError.', () => {
71
+ assert.throws( () => {
72
+ date.toVDSArray();
73
+ }, RangeError);
74
+ });
75
+ });
76
+
77
+ describe('Pass 57<<25 through constructor', () => {
78
+ const date = new IcaoDate('57<<25', 2046);
79
+ it('.toISOString() should equal "1957-XX-25".', () => {
80
+ assert.deepStrictEqual(date.toISOString(), '1957-XX-25');
81
+ });
82
+ it('.toMRZString() should equal "57<<25".', () => {
83
+ assert.deepStrictEqual(date.toMRZString(), '57<<25');
84
+ });
85
+ it('.toVDSArray() should throw a RangeError.', () => {
86
+ assert.throws( () => {
87
+ date.toVDSArray();
88
+ }, RangeError);
89
+ });
90
+ });
91
+
92
+ describe('Pass 1957-03-XX through constructor', () => {
93
+ const date = new IcaoDate('1957-03-XX');
94
+ it('.toISOString() should equal "1957-03-XX".', () => {
95
+ assert.deepStrictEqual(date.toISOString(), '1957-03-XX');
96
+ });
97
+ it('.toMRZString() should equal "5703<<".', () => {
98
+ assert.deepStrictEqual(date.toMRZString(), '5703<<');
99
+ });
100
+ it('.toVDSArray() should throw a RangeError.', () => {
101
+ assert.throws( () => {
102
+ date.toVDSArray();
103
+ }, RangeError);
104
+ });
105
+ });
106
+
107
+ describe('Pass invalid values through constructor', () => {
108
+ it('should throw a TypeError on passing "Not a date".', () => {
109
+ assert.throws( () => {
110
+ const date = new IcaoDate('Not a date');
111
+ }, TypeError);
112
+ });
113
+ it('should throw a TypeError on passing "1957-03-<<".', () => {
114
+ assert.throws( () => {
115
+ const date = new IcaoDate('1957-03-<<');
116
+ }, TypeError);
117
+ });
118
+ it('should throw a TypeError on passing "57XX25".', () => {
119
+ assert.throws( () => {
120
+ const date = new IcaoDate('57XX25', 2046);
121
+ }, TypeError);
122
+ });
123
+ it('should throw a RangeError on passing "1957-02-31".', () => {
124
+ assert.throws( () => {
125
+ const date = new IcaoDate('1957-02-31');
126
+ }, RangeError);
127
+ });
128
+ it('should throw a TypeError on passing new Date("1957-99-31T00:00:00").', () => {
129
+ assert.throws( () => {
130
+ const date = new IcaoDate(new Date('1957-99-31'));
131
+ }, TypeError);
132
+ });
133
+ it('should throw a TypeError on passing [0x31, 0x9E, 0xF5, 0x34].', () => {
134
+ assert.throws( () => {
135
+ const date = new IcaoDate([0x31, 0x9e, 0xf5, 0x34]);
136
+ }, TypeError);
137
+ });
138
+ });
139
+
140
+ });
141
+
@@ -0,0 +1,28 @@
1
+ // SPDX-FileCopyrightText: 2026 Don Geronimo <https://sentamal.in>
2
+ // SPDX-License-Identifier: LGPL-3.0-or-later
3
+
4
+ import { describe, it } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import { bytesToDate } from '../../src/utilities/bytes-to-date.js';
7
+ import { dateToBytes } from '../../src/utilities/date-to-bytes.js';
8
+
9
+ describe('Digital Seal Date Encodation Scheme', () => {
10
+
11
+ describe('dateToBytes - JavaScript Date object or date string into date byte sequence [REF ICAO 9303 Part 13 SS 2.3.1, Page 5]', () => {
12
+ it('should output [0x31, 0x9E, 0xF5] from a JavaScript Date object with date "1957-03-25".', () => {
13
+ assert.deepStrictEqual(dateToBytes(new Date('1957-03-25T00:00:00')), [0x31, 0x9e, 0xf5]);
14
+ });
15
+
16
+ it('should output [0x31, 0x9E, 0xF5] from date string "1957-03-25".', () => {
17
+ assert.deepStrictEqual(dateToBytes('1957-03-25'), [0x31, 0x9e, 0xf5]);
18
+ });
19
+ });
20
+
21
+ describe('bytesToDate - Date byte sequence into JavaScript Date object REF [ICAO 9303 Part 13 SS 2.3.1, Page 5]', () => {
22
+ it('should create a Date object with date 1957-03-25 from [0x31, 0x9E, 0xF5].', () => {
23
+ assert.deepStrictEqual(bytesToDate([0x31, 0x9e, 0xf5]), new Date('1957-03-25T00:00:00'));
24
+ });
25
+ });
26
+
27
+ });
28
+