edu-sphincs
v0.0.1
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
- SHAKE Parameter Sets: Supports SHAKE-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
The following NIST FIPS 205 parameter sets are currently supported (SHAKE-based):
SLH-DSA-SHAKE-128s- Small signaturesSLH-DSA-SHAKE-128f- Fast verificationSLH-DSA-SHAKE-192s- Small signatures, higher securitySLH-DSA-SHAKE-192f- Fast verification, higher securitySLH-DSA-SHAKE-256s- Small signatures, highest securitySLH-DSA-SHAKE-256f- Fast verification, highest security
Note: SHA2-based parameter sets (SLH-DSA-SHA2-*) are defined but not yet fully supported in this implementation (bugs).
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
Security 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.
