README
node-nist
A simple low-level ANSI/NIST-ITL 1-2011 (update 2015) encoding and decoding utility library. Written in Typescript for Node.
Table of contents
Installation
Install package
npm install --save node-nist
Usage
Encoding and decoding are described separately but they share many concepts.
In particular, nistEncode
and nistDecode
return a result (they do not throw exceptions).
A Result
is a TypeScript discriminated union where a Success
is tagged with tag === 'success
and a Failure
with tag === 'failure
.
In fact, Result
is very similar to Either
monad known from functional programming languages.
nistEncode
and nistDecode
could work on the NIST object alone. But they work best when codec
options are specific as their second argument. This way you can specify default values and impose
validation checks on individual NIST fields.
Encoding
- Encode a simple NIST object containing only Type-1 and Type-2 records:
import { nistEncode, NistFile } from 'node-nist';
const nist: NistFile = {
1: {
2: '0502', // version
4: 'CRM', // TOT
5: '20190717', // date
7: 'DAI035454', // DAI
8: 'ORI38574354', // ORI
9: 'TCN2487S054' // TCN
},
2: {
4: 'John',
5: 'Doe',
7: '1978-05-12'
}
};
const encodeResult = nistEncode(nist, {});
if (encodeResult.tag === 'success') {
const buffer = encodeResult.value;
// perform action on successfull encode, such as sending out the buffer
} else {
const error = encodeResult.error;
// perform action on unsuccessfull encode, such as logging an error
}
- Encode a NIST object with a different set of Type-2 record fields, containing also two fingerprints:
import { nistEncode, NistFile } from 'node-nist';
const nist: NistFile = {
1: {
2: '0300', // version
4: 'IDN', // TOT
5: '20190722', // date
7: 'ABIS', // DAI
8: 'MID00001', // ORI
9: 'SEN20190722093422-IDE-00040' // TCN
},
2: {
901: 'MID00001'
},
4: [
{
3: '0', // flat finger
4: ['7'], // left index finger
9: 'fingerprint binary data'
},
{
3: '0', // flat finger
4: ['2'], // right index finger
9: 'fingerprint binary data'
}
]
};
const encodeResult = nistEncode(nist, {});
if (encodeResult.tag === 'success') {
const buffer = encodeResult.value;
// perform action on successfull encode, such as sending out the buffer
} else {
const error = encodeResult.error;
// perform action on unsuccessfull encode, such as logging an error
}
- Encode a NIST object containing two fingerprints. Specify also NistEncodeOptions which are used to automatically populate default values and to check whether the input NIST object conforms to all the validation rules.
import { nistEncode, NistEncodeOptions, NistFile } from 'node-nist';
const nistEncodeOptions: NistEncodeOptions = {
codecOptions: {
MAP: { // TOT-specific encode options
1: {
6: {
defaultValue: '5',
mandatory: true,
regexs: [{ regex: '^[1-9]{1}