1.1.15 • Published 3 months ago
smartledger-sdk v1.1.15
SmartLedger
A comprehensive blockchain and cryptographic operations SDK for JavaScript, providing a unified interface for key management, digital signatures, encryption, secret sharing, and hashing operations.
Features
Key Management
- Generate and manage BSV keys
- Multi-purpose key derivation (identity, financial, contractual, property, document, privacy)
- WIF import/export
- HD wallet support
Digital Signatures
- Sign with WIF or mnemonic
- Signature verification
- Purpose-specific signing
Encryption
- AES encryption/decryption
- JSON data support
Secret Sharing
- Shamir's Secret Sharing implementation
- Configurable shares and threshold
- Hex encoding for storage
Hashing
- SHA256, SHA512
- Double SHA256 (Bitcoin standard)
- HASH160 (RIPEMD160(SHA256))
- Hash verification
UUID Generation
- UUIDv4 (random)
- UUIDv5 (namespace-based)
Installation
npm install smartledger
Usage
import SmartLedger from 'smartledger';
// Create a new instance
const ledger = new SmartLedger();
// Generate a mnemonic
const mnemonic = SmartLedger.generateMnemonic();
// Generate keys for different purposes
const keys = ledger.generateAllKeys(mnemonic);
// Encryption
const encrypted = SmartLedger.encrypt({ message: "Hello, World!" }, "my-secret-key");
const decrypted = SmartLedger.decrypt(encrypted, "my-secret-key");
// Hashing
const message = "Hello, SmartLedger!";
const hash = SmartLedger.hash256(message);
const doubleHash = SmartLedger.doubleHash256(message);
const hash160 = SmartLedger.hash160(message);
// UUID Generation
const uuid = ledger.getUUID(); // Random UUIDv4
const uuidv5 = SmartLedger.generateUUIDv5("transaction/123"); // Namespace-based UUIDv5
Secret Sharing Example
// Split a secret into shares
const shares = ledger.splitSecret("my secret", 3, 2);
// Convert shares to hex for storage
const hexShares = shares.map(share => ledger.shareToHex(share));
// Reconstruct the secret using any 2 shares
const reconstructedShares = hexShares
.slice(0, 2)
.map(hexShare => ledger.hexToShare(hexShare));
const secret = ledger.combineShares(reconstructedShares);
API Documentation
Key Management
generateMnemonic()
: Generate a new mnemonic phrasegenerateKeyPair()
: Generate a new key pairfromWIF(wif)
: Create keys from WIFfromMnemonic(mnemonic, purpose)
: Create keys from mnemonic for specific purposegenerateAllKeys(mnemonic)
: Generate all purpose-specific keys
Digital Signatures
signWithWIF(data, wif)
: Sign data using WIFsignWithMnemonic(data, mnemonic, purpose)
: Sign data using mnemonicverifySignature(data, signature, publicKey)
: Verify a signature
Encryption
encrypt(data, key)
: Encrypt data using AESdecrypt(ciphertext, key)
: Decrypt AES encrypted data
Secret Sharing
splitSecret(secret, shares, threshold)
: Split a secret into sharescombineShares(shares)
: Combine shares to reconstruct secretshareToHex(share)
: Convert share to hex formathexToShare(hexShare)
: Convert hex back to share
Hashing
hash256(data)
: SHA256 hashhash512(data)
: SHA512 hashdoubleHash256(data)
: Double SHA256 hashhash160(data)
: RIPEMD160(SHA256) hashverifyHash(data, hash, algorithm)
: Verify a hash
UUID Generation
getUUID()
: Get a random UUIDv4generateUUIDv5(name, namespace?)
: Generate a namespace-based UUIDv5
License
MIT
1.1.15
3 months ago
1.1.14
3 months ago
1.1.13
3 months ago
1.1.12
3 months ago
1.1.11
3 months ago
1.1.10
3 months ago
1.1.9
3 months ago
1.1.8
3 months ago
1.1.7
3 months ago
1.1.6
3 months ago
1.1.5
3 months ago
1.1.4
3 months ago
1.1.3
3 months ago
1.1.2
3 months ago
1.1.0
3 months ago
1.0.9
3 months ago
1.0.0
3 months ago
1.0.8
3 months ago
1.0.7
3 months ago
1.0.6
3 months ago
1.0.5
3 months ago
1.0.4
3 months ago
1.0.3
3 months ago
1.0.2
3 months ago
1.0.1
3 months ago