ntag424
Version:
A Node.js implementation for interop with NTAG 424 DNA.
93 lines (92 loc) • 3.8 kB
TypeScript
import { type EncryptionParams } from "./crypto/session.ts";
import type { CommMode } from "./serializer/commMode.ts";
import type { ConfigurationUpdate } from "./serializer/configuration.ts";
import type { FileSettings, GetFileSettings, TagParams } from "./serializer/fileSettings.ts";
export type Reader = {
transmit(data: Buffer, responseMaxLength: number): Promise<Buffer<ArrayBuffer>>;
};
type LogParams = Parameters<(typeof console)["log"]>;
export type LogFunction = (...args: LogParams) => void;
export type Logger = {
trace: LogFunction;
debug: LogFunction;
info: LogFunction;
warn: LogFunction;
success: LogFunction;
error: LogFunction;
};
export type TagSessionOptions = {
authentication: EncryptionParams;
logger: Logger;
initialCommandCounter: number;
};
export type TagSession = {
isAuthenticated: () => boolean;
getUid: () => Promise<Buffer>;
getFileSettings: (fileId: number) => Promise<GetFileSettings>;
getFileSettingsRaw: (fileId: number) => Promise<Buffer>;
/**
* ISOSelectFile
* @param {number} mode See {@link isoSelectFileMode}.
* @see Section 10.9.1
*/
selectFile: (fileId: Buffer, mode: number) => Promise<void>;
readStandardFile: () => Promise<Buffer>;
writeStandardFile: (contents: Buffer) => Promise<void>;
/**
* `getCardUid` command is required to get the 7-byte UID from the card. In case "Random ID" at activation is configured,
* encrypted secure messaging is applied for this command and response.
* An authentication with any key needs to be performed prior to the command `getCardUid`.
* This command returns the UID and gives the opportunity to retrieve the UID, even if the Random ID is used.
*/
getCardUid(commMode: CommMode): Promise<Buffer>;
/**
* @remarks Requires CommMode full (an authenticated session).
* @param config
*/
setConfiguration(config: ConfigurationUpdate): Promise<void>;
/**
* The `getKeyVersion` command retrieves the current key version of any key.
* Key version can be changed with the {@link changeKey} command together with the key.
* @param keyNumber Must be in the range `[0, 4]`.
*
* @returns {number} Key version. `0x00` if requesting key version of disabled keys or originality keys.
*/
getKeyVersion(keyNumber: number): Promise<number>;
/**
* The `getFileCounters` command supports retrieving of the current values associated with
* the SDMReadCtr related with a StandardData file after enabling Secure Dynamic Messaging.
*
* @remarks Requires CommMode "full" (authenticated session).
*
* @param {number} fileNumber
*/
getFileCounters(fileNumber: number): Promise<number>;
writeData(commMode: CommMode, fileNumber: number, data: Buffer, offset?: number): Promise<void>;
authenticate: (keyNumber: number, key: Buffer) => Promise<void>;
setFileSettings: (fileId: number, value: FileSettings, tagParams: TagParams) => Promise<void>;
setFileSettingsRaw: (fileId: number, value: Buffer) => Promise<void>;
changeKey: (keyNumber: number, oldKey: Buffer, newKey: Buffer, newKeyVersion: number) => Promise<void>;
};
/**
* Terms:
* - Elementary File (EF)
* - Dedicated File (DF)
* - Master File (MF)
*
* Table 39, ISO IEC 7816-4-1
*/
export declare const isoSelectFileMode: Readonly<{
MF_DF_EF: 0;
CHILD_DF: 1;
EF_UNDER_CURRENT_DF: 2;
PARENT_DF_OF_CURRENT_DF: 3;
/** Eg, application identifier */
BY_DF_NAME: 4;
/** Path without the MF identifier */
FROM_MF: 8;
/** Path without the MF identifier */
FROM_CURRENT_DF: 9;
}>;
export declare function createTagSession(reader: Reader, options?: Partial<TagSessionOptions>): TagSession;
export {};