@sops-node/qr-crypto
v1.1.4
Published
Secure QR code encryption utility for Sops
Maintainers
Readme
@sops-node/qr-crypto 🔐
Secure QR code encryption and terminal visualization utility designed for the Sops ecosystem.
🌟 Features
- AES-256-GCM Encryption: Military-grade, tamper-proof encryption with built-in data integrity (AuthTag).
- Specialized Handlers: Pre-defined interfaces and methods for Drugs, Patients, and Pharmacists.
- Terminal Visualization: Instant QR code generation in your terminal for rapid development and debugging.
- Type-Safe: Written in TypeScript with full ESM and CJS support.
- Compact & Secure: Optimized payload format to ensure high-density QR scan rates.
🚀 Installation
npm install @sops-node/qr-crypto🛠️ Usage
Initialize
The library requires a 32-byte hex key (64 characters).
import { QrCrypto } from '@sops-node/qr-crypto';
// Generate a secure key if you don't have one:
// openssl rand -hex 32
const ENCRYPTION_KEY = process.env.QR_ENCRYPTION_KEY; 💊 Specialized Drug Handling
const drugPayload = {
id: "uuid-123",
name: "Panadol",
barcode: "622123456789",
price: 15.50
};
// Encrypt
const qrToken = QrCrypto.encryptDrug(drugPayload, ENCRYPTION_KEY);
// Visualize in Terminal
QrCrypto.generateTerminalQr(qrToken);
// Decrypt & Validate
const data = QrCrypto.decryptDrug(qrToken, ENCRYPTION_KEY);
console.log(data.name); // Panadol👤 Patient & Pharmacist Handling
The library provides similar specialized methods for Patient and Pharmacist types to ensure payload consistency across the platform.
encryptPatient/decryptPatientencryptPharmacist/decryptPharmacist
🏗️ Generic Encryption
For any other data structures:
const data = { custom: "data" };
const token = QrCrypto.encrypt(data, ENCRYPTION_KEY);
const original = QrCrypto.decrypt(token, ENCRYPTION_KEY);🔒 Security Requirements
- Key Length: Must be exactly 32 bytes (64 hex characters).
- Key Storage: Never hardcode your keys. Use environment variables or a secret management service.
- Algorithm: Uses
aes-256-gcmwhich provides both confidentiality and authenticity.
🧪 Development & Testing
We use Jest for unit testing to ensure data integrity and cryptographic correctness.
# Run tests
npm test
# Build from source
npm run build📄 License
MIT © Youssef Hassan
