-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: v0.1.2 | Add support for DG11 and DG12
- Loading branch information
Showing
12 changed files
with
325 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import TLV from "node-tlv" | ||
import { Enums, Interfaces } from "./index"; | ||
|
||
/** | ||
* Class for working with DG11 (Additional personal data) | ||
*/ | ||
export class DG11 { | ||
/** | ||
* Get additional personal data | ||
* @param data Data of EF.DG11 file | ||
*/ | ||
static load(data: string | Buffer): Interfaces.DecodedAdditionalPersonalData { | ||
const FULL_NAME_TAG = 0x5F0E; | ||
const OTHER_NAME_TAG = 0x5F0F; | ||
const OTHER_NAME_ARRAY_TAG = 0xA0; | ||
const PERSONAL_NUMBER_TAG = 0x5F10; | ||
|
||
// In 'CCYYMMDD' format. | ||
const FULL_DATE_OF_BIRTH_TAG = 0x5F2B; | ||
|
||
// Fields separated by '<' | ||
const PLACE_OF_BIRTH_TAG = 0x5F11; | ||
|
||
// Fields separated by '<' | ||
const PERMANENT_ADDRESS_TAG = 0x5F42; | ||
const TELEPHONE_TAG = 0x5F12; | ||
const PROFESSION_TAG = 0x5F13; | ||
const TITLE_TAG = 0x5F14; | ||
const PERSONAL_SUMMARY_TAG = 0x5F15; | ||
|
||
// Compressed image per ISO/IEC 10918 | ||
const PROOF_OF_CITIZENSHIP_TAG = 0x5F16; | ||
|
||
// Separated by '<' | ||
const OTHER_VALID_TD_NUMBERS_TAG = 0x5F17; | ||
const CUSTODY_INFORMATION_TAG = 0x5F18; | ||
|
||
let nameOfHolder: string = "", | ||
otherNames: string[] = [], | ||
personalNumber: string = "", | ||
fullDateOfBirth: number = 0, | ||
placeOfBirth: string[] = [], | ||
permanentAddress: string[] = [], | ||
telephone: string = "", | ||
profession: string = "", | ||
title: string = "", | ||
personalSummary: string = "", | ||
proofOfCitizenship: Buffer = Buffer.from(""), | ||
otherValidTDNumbers: string[] = [], | ||
custodyInformation: string = ""; | ||
|
||
|
||
let tlv = TLV.parse(data) | ||
if(parseInt(tlv.tag, 16) != Enums.TAGS.DG11) throw new Error(`Invalid DG1 tag "0x${tlv.tag}", expected 0x${Enums.TAGS.DG11.toString(16)}`); | ||
|
||
for(let i of tlv.child) { | ||
switch(parseInt(i.tag, 16)) { | ||
case FULL_NAME_TAG: | ||
nameOfHolder = i.bValue.toString("utf-8") | ||
break; | ||
case PERSONAL_NUMBER_TAG: | ||
personalNumber = i.bValue.toString("utf-8") | ||
break; | ||
case OTHER_NAME_ARRAY_TAG: | ||
for(let j of i.child) { | ||
if(parseInt(j.tag, 16) == OTHER_NAME_TAG) { | ||
otherNames.push(j.bValue.toString("utf-8")) | ||
} | ||
} | ||
break; | ||
case FULL_DATE_OF_BIRTH_TAG: | ||
fullDateOfBirth = parseInt(i.bValue.toString("hex")) | ||
break; | ||
case PLACE_OF_BIRTH_TAG: | ||
placeOfBirth = i.bValue.toString("utf-8").split("<") | ||
break; | ||
case PERMANENT_ADDRESS_TAG: | ||
permanentAddress = i.bValue.toString("utf-8").split("<") | ||
break; | ||
case TELEPHONE_TAG: | ||
telephone = i.bValue.toString("utf-8") | ||
break | ||
case PROFESSION_TAG: | ||
profession = i.bValue.toString("utf-8") | ||
break; | ||
case TITLE_TAG: | ||
title = i.bValue.toString("utf-8") | ||
break; | ||
case PERSONAL_SUMMARY_TAG: | ||
personalSummary = i.bValue.toString("utf-8") | ||
break; | ||
case PROOF_OF_CITIZENSHIP_TAG: | ||
proofOfCitizenship = i.bValue | ||
break; | ||
case OTHER_VALID_TD_NUMBERS_TAG: | ||
otherValidTDNumbers = i.bValue.toString("utf-8").split("<") | ||
break; | ||
case CUSTODY_INFORMATION_TAG: | ||
custodyInformation = i.bValue.toString("utf-8") | ||
break; | ||
} | ||
} | ||
return { | ||
nameOfHolder, | ||
otherNames, | ||
personalNumber, | ||
fullDateOfBirth, | ||
placeOfBirth, | ||
permanentAddress, | ||
telephone, | ||
profession, | ||
title, | ||
personalSummary, | ||
proofOfCitizenship, | ||
otherValidTDNumbers, | ||
custodyInformation | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import TLV from "node-tlv" | ||
import { Enums, Interfaces } from "./index"; | ||
|
||
/** | ||
* Class for working with DG12 (Additional document data) | ||
*/ | ||
export class DG12 { | ||
/** | ||
* Get additional document data | ||
* @param data Data of EF.DG12 file | ||
*/ | ||
static load(data: string | Buffer): Interfaces.DecodedAdditionalDocumentData { | ||
const ISSUING_AUTHORITY_TAG = 0x5F19; | ||
|
||
// yyyymmdd | ||
const DATE_OF_ISSUE_TAG = 0x5F26; | ||
|
||
// formatted per ICAO 9303 rules | ||
const NAME_OF_OTHER_PERSON_ARRAY_TAG = 0xA0; | ||
const NAME_OF_OTHER_PERSON_TAG = 0x5F1A; | ||
const ENDORSEMENTS_AND_OBSERVATIONS_TAG = 0x5F1B; | ||
const TAX_OR_EXIT_REQUIREMENTS_TAG = 0x5F1C; | ||
|
||
// Image per ISO/IEC 10918 | ||
const IMAGE_OF_FRONT_TAG = 0x5F1D; | ||
const IMAGE_OF_REAR_TAG = 0x5F1E; | ||
|
||
// yyyymmddhhmmss | ||
const DATE_AND_TIME_OF_PERSONALIZATION = 0x5F55; | ||
const PERSONALIZATION_SYSTEM_SERIAL_NUMBER_TAG = 0x5F56; | ||
|
||
let dateOfIssue: number = 0, | ||
issuingAuthority: string = "", | ||
namesOfOtherPersons: string[] = [], | ||
endorsements: string = "", | ||
taxAndExitReqs: string = "", | ||
imageOfFront: Buffer = Buffer.from(""), | ||
imageOfRear: Buffer = Buffer.from(""), | ||
dateOfPersonalization: number = 0, | ||
personalizationNumber: string = "" | ||
|
||
let tlv = TLV.parse(data) | ||
if(parseInt(tlv.tag, 16) != Enums.TAGS.DG12) throw new Error(`Invalid DG1 tag "0x${tlv.tag}", expected 0x${Enums.TAGS.DG12.toString(16)}`); | ||
|
||
for(let i of tlv.child) { | ||
switch(parseInt(i.tag, 16)) { | ||
case ISSUING_AUTHORITY_TAG: | ||
issuingAuthority = i.bValue.toString("utf-8") | ||
break; | ||
case DATE_OF_ISSUE_TAG: | ||
dateOfIssue = parseInt(i.bValue.toString("hex")) | ||
break; | ||
case NAME_OF_OTHER_PERSON_ARRAY_TAG: | ||
for(let j of i.child) { | ||
if(parseInt(j.tag, 16) == NAME_OF_OTHER_PERSON_TAG) { | ||
namesOfOtherPersons.push(j.bValue.toString("utf-8")) | ||
} | ||
} | ||
break; | ||
case ENDORSEMENTS_AND_OBSERVATIONS_TAG: | ||
endorsements = i.bValue.toString("utf-8") | ||
break; | ||
case TAX_OR_EXIT_REQUIREMENTS_TAG: | ||
taxAndExitReqs = i.bValue.toString("utf-8") | ||
break; | ||
case IMAGE_OF_FRONT_TAG: | ||
imageOfFront = i.bValue; | ||
break; | ||
case IMAGE_OF_REAR_TAG: | ||
imageOfRear = i.bValue; | ||
break; | ||
case DATE_AND_TIME_OF_PERSONALIZATION: | ||
dateOfPersonalization = parseInt(i.bValue.toString("hex")) | ||
break; | ||
case PERSONALIZATION_SYSTEM_SERIAL_NUMBER_TAG: | ||
personalizationNumber = i.bValue.toString("utf-8") | ||
break; | ||
} | ||
} | ||
|
||
return { | ||
dateOfIssue, | ||
issuingAuthority, | ||
namesOfOtherPersons, | ||
endorsements, | ||
taxAndExitReqs, | ||
imageOfFront, | ||
imageOfRear, | ||
dateOfPersonalization, | ||
personalizationNumber | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.