Block a user
@taxi/nfc-card-utils (0.1.1)
Published 2025-09-12 15:36:27 +00:00 by omari.mohamed
Installation
@taxi:registry=npm install @taxi/nfc-card-utils@0.1.1"@taxi/nfc-card-utils": "0.1.1"About this package
@taxi/nfc-card-utils
Simple NFC card utilities for Node.js using nfc-pcsc, with helpers to encrypt/decrypt data and read/write from Mifare Classic cards.
Install
From the monorepo root, install deps in this package:
cd packages\nfc-card-utils
npm i
Build
npm run build
Outputs to dist/ with CJS and ESM builds and type declarations.
API
class NFCReader(options?: { logger?: boolean; defaultKey?: string; defaultKeyType?: 'A' | 'B' })- Wraps
nfc-pcscwith event emitter. Exposesreaderwhen connected. - Methods:
authenticate(blockNumber, keyType?, key?),read(blockNumber, length, blockSize),write(blockNumber, buffer, blockSize)
- Wraps
generateKey(): string– returns a 32-byte key as hex (64 chars)encryptValue(value: any, key: string): string– AES-256-CTR encrypt to hexdecryptValue(encryptedHex: string, key: string): any– decrypt from hex to objectembedKeyAndValue(encryptedHex: string, key: string): string– random64 + key + random64 + payloadextractKeyAndValue(str: string): { key: string; encryptedValue: string }readFromCard(reader: any): Promise<any>– reads sequential data, extracts key + payload, decryptswriteToNfc(reader: any, value: any, key?: string, keyType?: 'A' | 'B'): Promise<boolean>– encrypts, embeds key and writes across blocksclearCard(reader: any, key?: string, keyType?: 'A' | 'B'): Promise<boolean>– zero-fills blocks
Notes
- Requires a supported NFC reader and compatible cards (e.g., Mifare Classic 1K). On Windows, install vendor drivers.
- Default auth key is
ffffffffffffwith key type A. Adjust if your cards differ. - The write/read routines skip trailer blocks (block index 3 of each sector).
Example
import { NFCReader, generateKey, encryptValue, decryptValue } from '@taxi/nfc-card-utils';
const reader = new NFCReader({ logger: true });
reader.on('reader', r => console.log('connected', r.name));
reader.on('card', async card => {
if (!reader.reader) return;
const ok = await reader.authenticate(4, 'A', 'ffffffffffff');
if (!ok) return;
const payload = await readFromCard(reader.reader);
console.log('Card payload', payload);
});
Dependencies
Dependencies
| ID | Version |
|---|---|
| nfc-pcsc | ^0.8.1 |
Development Dependencies
| ID | Version |
|---|---|
| @types/node | ^20.19.13 |
| rimraf | ^6.0.1 |
| tsup | ^8.3.5 |
| typescript | ^5.6.3 |
Details
2025-09-12 15:36:27 +00:00
Assets (1)
Versions (2)
View all
npm
8
MIT
latest
8.5 KiB
nfc-card-utils-0.1.1.tgz
8.5 KiB