Classes
CardError
A card answered with an error: sw is its status word (0x6982: security status not satisfied, and so on).
Extends
Error
Constructors
Constructor
new CardError(message, sw): CardError;
Parameters
| Parameter | Type |
|---|---|
message | string |
sw | number |
Returns
Overrides
Error.constructor
Properties
Interfaces
CardTransport
The port: send one APDU, get the response data followed by the two status-word bytes.
Methods
transceive()
transceive(apdu): Promise<Uint8Array<ArrayBufferLike>>;
Parameters
| Parameter | Type |
|---|---|
apdu | Uint8Array |
Returns
Promise<Uint8Array<ArrayBufferLike>>
TrustStore
The port: where CSCA certificates come from.
Methods
cscas()
cscas(country?): Promise<Certificate[]>;
Candidate CSCAs for a country (ISO 3166 alpha-2 or alpha-3 as in the MRZ), or all of them.
Parameters
| Parameter | Type |
|---|---|
country? | string |
Returns
Promise<Certificate[]>
Type Aliases
Access
type Access =
| {
cardAccess: "absent" | "present";
paceOffered?: string[];
protocol: "BAC";
status?: string;
}
| {
cipher: PaceCipher;
curve: string;
password: "MRZ" | "CAN";
protocol: "PACE";
};
How the chip was unlocked. For BAC, what EF.CardAccess said: absent (with the chip's status), or the
PACE variants it offered that this library can't run yet.
AccessKey
type AccessKey =
| BacKey
| {
can: string;
};
What unlocks the chip: the MRZ details (as for BAC), or the card access number.
BacKey
type BacKey = object;
What the BAC keys come from: document number, date of birth and date of expiry.
Properties
Certificate
type Certificate = object;
An X.509 certificate, parsed as far as checking a document signer's chain needs.
Properties
ChipResult
type ChipResult = object;
Whether the chip proved it's genuine, and how (Chip Authentication, or Active Authentication).
Properties
| Property | Type |
|---|---|
detail | string |
method? | "chip-authentication" | "active-authentication" |
status | "valid" | "invalid" | "not-checked" |
Mrz
type Mrz = object;
A document's machine-readable zone, parsed: the fields as printed, and whether each check digit holds.
Properties
MrzScan
type MrzScan = object;
An MRZ read off a camera frame: enough to unlock the chip (the BAC key), and what kind of document it is.
Properties
| Property | Type | Description |
|---|---|---|
documentCode | string | P for passports; I, A or C for identity cards. |
format | "TD3" | "TD1" | - |
issuingState? | string | - |
key | BacKey | - |
PassiveAuthentication
type PassiveAuthentication = object;
Whether the issuing state signed the data (passive authentication): the SOD's signature and its certificate chain.
Properties
PassportRead
type PassportRead = object;
What a read found, and how far each check got.
Properties
| Property | Type | Description |
|---|---|---|
access | Access | How the chip was unlocked. |
chip | ChipResult | Is the chip genuine, not a copy (Chip or Active Authentication)? |
face? | object | The face image from DG2, if asked for. |
face.image | Uint8Array | - |
face.mime | string | - |
files | Map<number, Uint8Array> | Raw files as read, by data-group number (0 = the SOD), for storage and later re-verification. |
integrity | object | Whether each data group read matches its hash in the SOD. |
integrity.allMatch | boolean | - |
integrity.dataGroups | Map<number, boolean> | - |
integrity.hashAlgorithm | string | - |
mrz | Mrz | The document's data, from DG1. |
passive | PassiveAuthentication | Was the data signed by the issuing state (passive authentication)? |
Progress
type Progress = (step, detail?) => void;
Called as a read goes: the step, and for reads the file and how much of it has come.
Parameters
| Parameter | Type |
|---|---|
step | Step |
detail? | { bytes?: number; file?: string; total?: number; } |
detail.bytes? | number |
detail.file? | string |
detail.total? | number |
Returns
void
ReadOptions
type ReadOptions = object;
What to read, and how to check it.
Properties
| Property | Type | Description |
|---|---|---|
face? | boolean | Also read DG2, the face image (tens of kilobytes; a few seconds over NFC). |
onProgress? | Progress | Told how the read is going. |
random? | (bytes) => Uint8Array | Where randomness comes from. Defaults to crypto.getRandomValues. |
trust? | TrustStore | Country signing certificates, for passive authentication. Without them the SOD's signature is still checked. |
Scene
type Scene =
| {
kind: "mrz";
scan: MrzScan;
}
| {
kind: "mrz-partial";
}
| {
kind: "passport-other-page";
}
| {
kind: "card-front";
}
| {
kind: "driving-licence";
}
| {
kind: "nothing";
};
What a camera frame shows, for guiding the holder: an MRZ, part of one, or another page or side.
SecurityObject
type SecurityObject = object;
The document's security object (EF.SOD): each data group's hash, and the issuer's signature over them.
Properties
| Property | Type | Description |
|---|---|---|
hashAlgorithm | string | - |
hashes | Map<number, Uint8Array> | - |
signedData | Uint8Array | The DER of the whole SignedData, for signature verification (passive authentication). |
Step
type Step = "select" | "authenticate" | "read" | "verify" | "done";
Where a read has got to, for a progress display.
Variables
FILES
const FILES: object;
The elementary files an eMRTD read uses, by their file identifiers.
Type Declaration
| Name | Type | Default value |
|---|---|---|
COM | 286 | 0x011e |
DG1 | 257 | 0x0101 |
DG14 | 270 | 0x010e |
DG15 | 271 | 0x010f |
DG2 | 258 | 0x0102 |
SOD | 285 | 0x011d |
GERMAN_CSCA_SHA256
const GERMAN_CSCA_SHA256: "20:84:AE:D7:A9:91:B3:15:8E:63:AD:75:0D:3D:C3:8B:C6:C9:DC:F5:95:8F:28:D1:16:2F:49:88:4E:91:AD:A8" = '20:84:AE:D7:A9:91:B3:15:8E:63:AD:75:0D:3D:C3:8B:C6:C9:DC:F5:95:8F:28:D1:16:2F:49:88:4E:91:AD:A8';
The German CSCA (certificate 10/24), as the BSI publishes its SHA-256 fingerprint: the anchor for the BSI's master list. Never taken from the list itself.
PASSPORT_AID
const PASSPORT_AID: Uint8Array<ArrayBuffer>;
The eMRTD application's AID (ICAO 9303-10): what a transport selects, and what an app declares for NFC.
readPassport
const readPassport: (transport, key, options) => Promise<PassportRead> = readDocument;
The old name: reads with BAC or PACE alike.
Reads a passport or ID card: PACE when the chip offers it (with the MRZ or the CAN), otherwise BAC (MRZ only). Then DG1, optionally DG2, and the SOD, checked against each other.
Parameters
| Parameter | Type |
|---|---|
transport | CardTransport |
key | AccessKey |
options | ReadOptions |
Returns
Promise<PassportRead>
Functions
alpha2()
function alpha2(mrzState): string | undefined;
The two-letter code for an MRZ issuing state, or undefined if it isn't a state we know.
Parameters
| Parameter | Type |
|---|---|
mrzState | string |
Returns
string | undefined
checkDigit()
function checkDigit(field): string;
The ICAO 9303 check digit for a field.
Parameters
| Parameter | Type |
|---|---|
field | string |
Returns
string
checkHashes()
function checkHashes(sod, groups): Map<number, boolean>;
Hashes each data group read and compares it with the SOD. Detects altered data; the SOD's signature is checked separately.
Parameters
| Parameter | Type |
|---|---|
sod | SecurityObject |
groups | Map<number, Uint8Array<ArrayBufferLike>> |
Returns
Map<number, boolean>
classify()
function classify(lines): Scene;
What the camera is looking at, from all the text it read, and so what the holder should do next.
Parameters
| Parameter | Type |
|---|---|
lines | string[] |
Returns
findMrz()
function findMrz(lines): MrzScan | undefined;
Finds a readable MRZ in OCR text lines, trying every alignment near the expected line lengths.
Parameters
| Parameter | Type |
|---|---|
lines | string[] |
Returns
MrzScan | undefined
fromHex()
function fromHex(text): Uint8Array;
Hex (either case; whitespace ignored) as bytes. Throws on anything else.
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
Uint8Array
hex()
function hex(bytes): string;
Bytes as uppercase hex.
Parameters
| Parameter | Type |
|---|---|
bytes | Uint8Array |
Returns
string
hint()
function hint(scene): string;
What to tell the holder for each scene.
Parameters
| Parameter | Type |
|---|---|
scene | Scene |
Returns
string
isCan()
function isCan(key): key is { can: string };
Whether an access key is a card access number (CAN) rather than the MRZ's BAC key.
Parameters
| Parameter | Type |
|---|---|
key | AccessKey |
Returns
key is { can: string }
mrzInformation()
function mrzInformation(__namedParameters): string;
The "MRZ information" string (ICAO 9303-11 §9.7.1.1): each field followed by its check digit.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | BacKey |
Returns
string
normalise()
function normalise(line): string;
Uppercase, '<' look-alikes to '<', everything outside the MRZ alphabet dropped.
Parameters
| Parameter | Type |
|---|---|
line | string |
Returns
string
parseCertificate()
function parseCertificate(der): Certificate;
Parses a DER certificate. Throws on one it can't read.
Parameters
| Parameter | Type |
|---|---|
der | Uint8Array |
Returns
parseDg1()
function parseDg1(dg1): Mrz;
DG1: the MRZ, as stored on the chip (tag 61 { 5F1F <MRZ> }).
Parameters
| Parameter | Type |
|---|---|
dg1 | Uint8Array |
Returns
parseDg2()
function parseDg2(dg2):
| {
image: Uint8Array;
mime: "image/jpeg" | "image/jp2";
}
| undefined;
DG2: the facial image. Returns the first image and its type (JPEG, or JPEG 2000, which few browsers show).
Parameters
| Parameter | Type |
|---|---|
dg2 | Uint8Array |
Returns
| {
image: Uint8Array;
mime: "image/jpeg" | "image/jp2";
}
| undefined
parseMasterList()
function parseMasterList(bytes): Certificate[];
Reads the CSCA certificates out of a CSCA master list (a CMS SignedData over a CscaMasterList).
Parameters
| Parameter | Type |
|---|---|
bytes | Uint8Array |
Returns
parseMrz()
function parseMrz(text): Mrz;
Parses a TD3 (passport, 2 × 44) or TD1 (ID card, 3 × 30) MRZ. Whitespace and line breaks are ignored between lines.
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
parseSod()
function parseSod(sod): SecurityObject;
Reads the LDS security object out of EF.SOD (77 { ContentInfo { signedData, [0] SignedData } }).
Parameters
| Parameter | Type |
|---|---|
sod | Uint8Array |
Returns
passiveAuthentication()
function passiveAuthentication( sod, issuingState, trust? ): Promise<PassiveAuthentication>;
Passive authentication of an SOD, for a document whose MRZ names issuingState. The data-group
hashes are checked separately (lds.ts checkHashes): together they say the data is what the state signed.
Parameters
| Parameter | Type |
|---|---|
sod | Uint8Array |
issuingState | string |
trust? | TrustStore |
Returns
Promise<PassiveAuthentication>
readDocument()
function readDocument( transport, key, options? ): Promise<PassportRead>;
Reads a passport or ID card: PACE when the chip offers it (with the MRZ or the CAN), otherwise BAC (MRZ only). Then DG1, optionally DG2, and the SOD, checked against each other.
Parameters
| Parameter | Type |
|---|---|
transport | CardTransport |
key | AccessKey |
options | ReadOptions |
Returns
Promise<PassportRead>
trustStore()
function trustStore(certificates): TrustStore;
A TrustStore over certificates in memory, e.g. from master lists.
Parameters
| Parameter | Type |
|---|---|
certificates | Certificate[] |
Returns
verifyMasterList()
function verifyMasterList(bytes, anchors): object;
Verifies a CSCA master list before trusting what's in it: its CMS signature, and its signer certificate signed by an anchor, a CSCA pinned by the SHA-256 fingerprint its issuer publishes (for Germany's list, on the BSI's website). Returns the CSCAs it carries, or throws.
Parameters
| Parameter | Type |
|---|---|
bytes | Uint8Array |
anchors | string[] |
Returns
object
| Name | Type |
|---|---|
anchor | string |
cscas | Certificate[] |
signer | string |