-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mrtd): data parsing using @li0ard/tsemrtd (#41)
* feat: add @li0ard/tsemrtd and esbuild to esm compatibility * fix: update deps esm before jest * fix: update deps esm before jest * feat: testing * fix: adjust esm modules * fix: fix load params * feat: add testing for data process * fix: add testing for data process * fix: add testing for data process * fix: test * docs: update in testing * fix: parseEMrtdData * feat: typed parse results --------- Co-authored-by: Ariel Gentile <[email protected]>
- Loading branch information
1 parent
246432a
commit ab0fb73
Showing
13 changed files
with
410 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ didcomm.org/mrtd/1.0 | |
|
||
- mrz-data-request | ||
- mrz-data | ||
- emrtd-data-request | ||
- emrtd-data |
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 @@ | ||
bundle.js |
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,3 @@ | ||
import { COM, DG1, DG2, DG3, DG4, DG5, DG7, DG11, DG12, DG14, DG15, SOD, PKD } from '@li0ard/tsemrtd' | ||
|
||
export { COM, DG1, DG2, DG3, DG4, DG5, DG7, DG11, DG12, DG14, DG15, SOD, PKD } |
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,100 @@ | ||
import type { SecurityInfos } from '@li0ard/tsemrtd/dist/asn1/eac' | ||
import type { CSCAMasterList } from '@li0ard/tsemrtd/dist/asn1/pkd' | ||
import type { | ||
DecodedAdditionalDocumentData, | ||
DecodedAdditionalPersonalData, | ||
DecodedCom, | ||
DecodedFingerprint, | ||
DecodedImage, | ||
DecodedIris, | ||
DecodedSecurtyObjectOfDocument, | ||
} from '@li0ard/tsemrtd/dist/consts/interfaces' | ||
import type { SubjectPublicKeyInfo } from '@peculiar/asn1-x509' | ||
|
||
import { COM, DG1, DG2, DG3, DG4, DG5, DG7, DG11, DG12, DG14, DG15, SOD, PKD } from '../esm' | ||
|
||
import { EMrtdDataGroup } from './EMrtdDataGroup' | ||
|
||
export type EMrtdData = { | ||
raw: Record<string, string> | ||
parsed: { fields?: ParsedEMrtdData; valid: boolean } | ||
} | ||
|
||
export type ParsedEMrtdData = { | ||
com: DecodedCom | ||
mrzData: string | ||
images: DecodedImage[] | ||
fingerprints?: DecodedFingerprint[] | ||
iris?: DecodedIris[] | ||
displayedImages?: Buffer[] | ||
signatureImages?: Buffer[] | ||
additionalPersonalData?: DecodedAdditionalPersonalData | ||
additionalDocumentData?: DecodedAdditionalDocumentData | ||
securityInfos?: SecurityInfos | ||
subjectPublicKeyInfo?: SubjectPublicKeyInfo | ||
securityObjectOfDocument: DecodedSecurtyObjectOfDocument | ||
cscaMasterList?: CSCAMasterList | ||
} | ||
|
||
/** | ||
* | ||
* @param input object containing base64-encoded eMRTD data groups | ||
* @returns parsed eMRDT Data | ||
* @throws Error in case of missing mandatory data (EF_COM, EF_DG1, EF_DG2 or EF_SOD) | ||
*/ | ||
export function parseEMrtdData(input: Record<EMrtdDataGroup, string>): ParsedEMrtdData { | ||
const parsedData: Partial<ParsedEMrtdData> = {} | ||
|
||
for (const [key, value] of Object.entries(input)) { | ||
const decodedValue = Buffer.from(value, 'base64') | ||
switch (key as EMrtdDataGroup) { | ||
case EMrtdDataGroup.COM: | ||
parsedData.com = COM.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG1: | ||
parsedData.mrzData = DG1.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG2: | ||
parsedData.images = DG2.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG3: | ||
parsedData.fingerprints = DG3.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG4: | ||
parsedData.iris = DG4.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG5: | ||
parsedData.displayedImages = DG5.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG7: | ||
parsedData.signatureImages = DG7.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG11: | ||
parsedData.additionalPersonalData = DG11.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG12: | ||
parsedData.additionalDocumentData = DG12.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG14: | ||
parsedData.securityInfos = DG14.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.DG15: | ||
parsedData.subjectPublicKeyInfo = DG15.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.SOD: | ||
parsedData.securityObjectOfDocument = SOD.load(decodedValue) | ||
break | ||
case EMrtdDataGroup.PKD: | ||
parsedData.cscaMasterList = PKD.load(decodedValue) | ||
break | ||
default: | ||
break | ||
} | ||
} | ||
|
||
if (!parsedData.com || !parsedData.mrzData || !parsedData.images || !parsedData.securityObjectOfDocument) { | ||
throw Error('Parsed data misses mandatory files') | ||
} | ||
|
||
return parsedData as ParsedEMrtdData | ||
} |
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,15 @@ | ||
export enum EMrtdDataGroup { | ||
COM = 'COM', | ||
DG1 = 'DG1', | ||
DG2 = 'DG2', | ||
DG3 = 'DG3', | ||
DG4 = 'DG4', | ||
DG5 = 'DG5', | ||
DG7 = 'DG7', | ||
DG11 = 'DG11', | ||
DG12 = 'DG12', | ||
DG14 = 'DG14', | ||
DG15 = 'DG15', | ||
SOD = 'SOD', | ||
PKD = 'PKD', | ||
} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './DidCommMrtdRole' | ||
export * from './EMrtdData' | ||
export * from './EMrtdDataGroup' | ||
export * from './MrzData' |
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
Oops, something went wrong.