edu-sphincs
v0.1.0
Published
TypeScript implementation of SLH-DSA (SPHINCS+) as specified in NIST FIPS 205
Maintainers
Readme
edu-sphincs
An educational TypeScript implementation of SLH-DSA (Stateless Hash-based Digital Signature Algorithm) as specified in NIST FIPS 205 (formerly known as SPHINCS+). It has not been audited and must not be used in production.
This implementation was initially developed for visualization as part of my master's thesis and later factored out with the help of a generative AI coding assistant.
Features
- Post-Quantum Cryptography: Implements the NIST standardized SLH-DSA signature scheme
- All NIST Parameter Sets: Supports both SHAKE-based and SHA2-based NIST FIPS 205 parameter sets
- Type Safe: Written in TypeScript with full type definitions
- Event System: Built-in event emitter for algorithm monitoring and visualization
Installation
npm install edu-sphincsQuick Start
import { SLHDSA } from 'edu-sphincs';
// Initialize with a parameter set
const slhDSA = new SLHDSA('SLH-DSA-SHAKE-128s');
// Generate a key pair
const keyPair = await slhDSA.keygen();
if (!keyPair) {
throw new Error('Key generation failed');
}
const { SK, PK } = keyPair;
// Sign a message
const message = new Uint8Array([1, 2, 3, 4, 5]);
const signature = await slhDSA.sign(message, SK);
// Verify the signature
const isValid = await slhDSA.verify(message, signature, PK);
console.log('Signature valid:', isValid);Parameter Sets
All 12 NIST FIPS 205 parameter sets are supported, both SHAKE-based and SHA2-based:
SLH-DSA-SHAKE-128s/SLH-DSA-SHA2-128s- Small signaturesSLH-DSA-SHAKE-128f/SLH-DSA-SHA2-128f- Fast verificationSLH-DSA-SHAKE-192s/SLH-DSA-SHA2-192s- Small signatures, higher securitySLH-DSA-SHAKE-192f/SLH-DSA-SHA2-192f- Fast verification, higher securitySLH-DSA-SHAKE-256s/SLH-DSA-SHA2-256s- Small signatures, highest securitySLH-DSA-SHAKE-256f/SLH-DSA-SHA2-256f- Fast verification, highest security
Event Monitoring
The library supports event emission for monitoring and visualization purposes. You can pass a custom event emitter when creating an SLHDSA instance:
import { SLHDSA } from 'edu-sphincs';
const slhDSA = new SLHDSA('SLH-DSA-SHAKE-128s', undefined, {
emit: (event) => {
console.log(`${event.type}:`, event.data);
}
});The event emitter is designed to integrate with visualization frameworks for real-time algorithm monitoring.
API Reference
Core Class
SLHDSA- Main signature algorithm implementation with methods for key generation, signing, and verification
Utilities
ADRS- Address structure for hash function calls- Parameter management - Access to all NIST parameter sets
- Hash functions - SHAKE, SHA wrappers
Development
Dependencies are installed inside a Docker container, so nothing needs to be installed locally:
docker compose build # build the dev image (installs dependencies)
docker compose run --rm dev npm test # run the fast test suite
docker compose run --rm dev npm run test:full # run the full test suite (all parameter sets)
docker compose run --rm dev npm run build:check
docker compose run --rm dev npm run buildSecurity Notice
This is an educational implementation for learning post-quantum cryptography concepts. While it follows the NIST FIPS 205 specification, it is not suitable for production use.
License
MIT License - see LICENSE file for details.
