Package Exports
- libsilver-nodejs
- libsilver-nodejs/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (libsilver-nodejs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
LibSilver Node.js Bindings
High-performance cryptography library for Node.js, built with Rust and RustCrypto.
๐ Features
- Symmetric Encryption: AES-256-GCM, ChaCha20-Poly1305
- Asymmetric Encryption: RSA-OAEP (2048+ bit keys)
- Digital Signatures: ECDSA P-256, Ed25519
- Cryptographic Hashing: SHA-256, SHA-512, BLAKE3, HMAC
- Key Derivation Functions: Argon2, HKDF, PBKDF2
- Secure Random Generation: OS-backed cryptographically secure random number generation
- Memory Safety: Automatic zeroization of sensitive data
- Cross-Platform: Works on Windows (x64/ARM64), macOS (Intel/ARM64), and Linux (via CI/CD)
- TypeScript Support: Full TypeScript definitions included
๐ฆ Installation
npm install libsilver-nodejs๐ง Quick Start
const { SymmetricCrypto, AsymmetricCrypto, HashFunctions, KeyDerivation, RandomGenerator } = require('libsilver-nodejs');
// Symmetric encryption
const key = SymmetricCrypto.generateAesKey();
const plaintext = Buffer.from('Hello, World!', 'utf8');
const ciphertext = SymmetricCrypto.encryptAes(plaintext, key);
const decrypted = SymmetricCrypto.decryptAes(ciphertext, key);
console.log('Decrypted:', decrypted.toString('utf8')); // "Hello, World!"๐ API Documentation
Symmetric Encryption
AES-256-GCM
const key = SymmetricCrypto.generateAesKey();
const ciphertext = SymmetricCrypto.encryptAes(plaintext, key);
const decrypted = SymmetricCrypto.decryptAes(ciphertext, key);ChaCha20-Poly1305
const key = SymmetricCrypto.generateChacha20Key();
const ciphertext = SymmetricCrypto.encryptChacha20(plaintext, key);
const decrypted = SymmetricCrypto.decryptChacha20(ciphertext, key);Asymmetric Encryption
RSA-OAEP
const keypair = AsymmetricCrypto.generateRsaKeypair();
const ciphertext = AsymmetricCrypto.encryptRsa(plaintext, keypair.publicKeyPem);
const decrypted = AsymmetricCrypto.decryptRsa(ciphertext, keypair.privateKeyPem);Digital Signatures
Ed25519
const keypair = AsymmetricCrypto.generateEd25519Keypair();
const signature = AsymmetricCrypto.signEd25519(message, keypair.signingKeyBytes);
const isValid = AsymmetricCrypto.verifyEd25519(message, signature, keypair.verifyingKeyBytes);ECDSA P-256
const keypair = AsymmetricCrypto.generateEcdsaKeypair();
const signature = AsymmetricCrypto.signEcdsa(message, keypair.signingKeyBytes);
const isValid = AsymmetricCrypto.verifyEcdsa(message, signature, keypair.verifyingKeyBytes);Cryptographic Hashing
// SHA-256
const hash = HashFunctions.sha256(data);
const hexHash = HashFunctions.sha256Hex(data);
// BLAKE3
const blake3Hash = HashFunctions.blake3(data);
const customLengthHash = HashFunctions.blake3WithLength(data, 64);
// HMAC
const mac = HashFunctions.hmacSha256(key, message);
const isValid = HashFunctions.verifyHmacSha256(key, message, mac);Key Derivation Functions
// Argon2 (recommended for password hashing)
const salt = RandomGenerator.generateSalt();
const key = KeyDerivation.argon2(password, salt, 32);
// PBKDF2
const pbkdf2Key = KeyDerivation.pbkdf2Sha256(password, salt, 100000, 32);
// HKDF (for key expansion)
const hkdfKey = KeyDerivation.hkdfSha256(inputKey, salt, info, 32);Secure Random Generation
const randomBytes = RandomGenerator.generateBytes(32);
const secureKey = RandomGenerator.generateKey(32);
const nonce = RandomGenerator.generateNonce(12);
const salt = RandomGenerator.generateSalt();๐ก๏ธ Security Features
- Memory Safety: All sensitive data is automatically zeroized when no longer needed
- Secure Defaults: Uses secure parameters and algorithms by default
- Constant-Time Operations: Leverages RustCrypto's constant-time implementations
- No Unsafe Code: Pure safe Rust implementation with secure FFI bindings
- Audited Dependencies: Built on well-audited RustCrypto crates
๐๏ธ Building from Source
# Clone the repository
git clone https://github.com/DangVTNhan/libsilver.git
cd libsilver
# Install dependencies
npm install
# Build the native module
npm run build
# Run tests
npm test
# Run examples
node examples/nodejs-example.js๐งช Testing
npm test๐ฅ๏ธ Platform Support
| Platform | Architecture | Status | Notes |
|---|---|---|---|
| macOS | ARM64 (M1/M2) | โ | Native compilation |
| macOS | Intel x64 | โ | Cross-compilation |
| Windows | x64 | โ | Cross-compilation |
| Windows | ARM64 | โ | Cross-compilation |
| Linux | x64 | โ ๏ธ | CI/CD builds |
| Linux | ARM64 | โ ๏ธ | CI/CD builds |
Pre-built binaries are available for all supported platforms via npm.
๐ License
MIT License - see LICENSE file for details.
๐ค Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests.
๐ Related Projects
- LibSilver Core - The main Rust library
- LibSilver Swift - Swift bindings
- LibSilver Kotlin - Kotlin/Android bindings