1.0.0-beta.8 • Published 9 months ago
@scintilla-network/keys v1.0.0-beta.8
@scintilla-network/keys
Key management and derivation library for Scintilla Network with support for multiple key types, personas, and chains.
Features
- 🔑 Key Management
- Extended key derivation (BIP32)
- Mnemonic support (BIP39)
- Multiple chain support (BIP44)
- Secure key storage
- 👤 Persona Management
- Personal personas
- Shared personas
- Moniker-based derivation
- Watch-only support
- ⛓️ Chain Support
- Bitcoin (BIP44/49/84)
- Ethereum
- Cosmos
- Scintilla
- 🔒 Security
- Secure key derivation
- Watch-only mode
- Private key protection
- Zero dependencies beyond Scintilla core
Installation
npm install @scintilla/keysQuick Start
import { SeedKeyring } from '@scintilla-network/keys';
// Create from mnemonic
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
const keyring = SeedKeyring.fromMnemonic(mnemonic);
// Get chain-specific keyring (scintilla chain)
const chainKeyring = keyring.getChainKeyring();
// Get specific account (account: 0, see bip44)
const accountKeyring = chainKeyring.getAccountKeyring(0);
const addressKeyring = accountKeyring.getAddressKeyring();
const address = addressKeyring.getAddress().toString(); // sct170psr9zhfp9nd9qeyp0mdggxj9m7y6el2ezeq5
// Create shared persona (between two users)
const sharedKeyring = accountKeyring.getSharedPersonaKeyring('sct.alice', 'sct.bob');Usage Guide
Seed Management
import { SeedKeyring } from '@scintilla-network/keys';
// From mnemonic
const keyring = SeedKeyring.fromMnemonic(mnemonic);
// From seed
const seedBuffer = Buffer.from('your-seed-hex', 'hex');
const keyring = SeedKeyring.fromSeed(seedBuffer);
// Get chain keyring
const chainKeyring = keyring.getChainKeyring({
chain: 'scintilla', // or 'scintilla', 'ethereum', 'cosmos', 'bitcoin'
purpose: 44, // optional: BIP44/49/84
coinType: 8888 // optional: chain-specific (btc: 0, eth: 60)
});Persona Management
import { SharedPersonaKeyring } from '@scintilla-network/keys';
// Create shared persona
const sharedKeyring = new SharedPersonaKeyring(extendedKey,'alice','bob');
// Get address keyring
const addressKeyring = sharedKeyring.getAddressKeyring(0, { change: 0 });
// Create watch-only persona
const watchOnly = SharedPersonaKeyring.fromExtendedPublicKey(extendedPublicKey,'alice','bob');SignableMessage
Handles message signing and verification:
const message = new SignableMessage("Hello World");
const signer = new Signer(derivableKey);
// Sign message
const [signature, publicKey] = message.sign(signer);
// Verify signature
const isValid = message.verify(signature, publicKey);Signer
Provides advanced signing capabilities with multiple algorithms:
// Create signer with optional moniker
const signer = new Signer(derivableKey, "myKey");
// Sign with default SECP256K1
const [signature, pubKey] = signer.signMessage("message");
// Sign with BLS
const [blsSignature, blsPubKey] = signer.signMessage("message", Signer.ALGORITHM.BLS);
// Verify signatures
const isValid = signer.verifyMessage(signature, "message", pubKey);Utils
The library provides utility functions:
const { bech32, bech32m, escapeHTML, isHexadecimal, sortObjectByKey } = utils;Key Types
SeedKeyring
- Root key management
- Chain derivation
- BIP32/39/44 support
SharedPersonaKeyring
- Shared key derivation
- Moniker-based paths
- Watch-only support
ChainKeyring
- Chain-specific derivation
- Multiple address types
- BIP44/49/84 support
AddressKeyring
- Single address management
- Transaction signing
- Public/private key handling
Security Considerations
Key Storage
- Never store private keys in plaintext
- Use secure key derivation
- Consider hardware security modules
- Enable watch-only mode when possible
Persona Management
- Validate monikers carefully
- Use consistent derivation paths
- Protect shared keys appropriately
Chain Support
- Follow BIP standards
- Use appropriate address types
- Validate derivation paths
API Reference
DerivableKey
Constructor Options
privateKey: (string | Buffer) - Either a hex string private key or a seed buffernode: (HDKey) - Optional HD key nodeisMaster: (boolean) - Whether this is a master key for derivation
Methods
derive(path: string): DerivableKey- Derives a child key from the given pathtoAddress(prefix?: string): string- Generates an address with optional prefixgetAccount(accountIndex?: number, coinType?: number): Account- Derives a child account
SignableMessage
Methods
toHex(): string- Converts message to hex formatsign(signer: Signer): [string, string]- Signs message, returns signature, publicKeyverify(signature: string, publicKey: string): boolean- Verifies signature
Signer
Constructor Options
derivableKey: (DerivableKey | string) - Key for signingmoniker: (string | null) - Optional identifiertype: (string) - Signer type, defaults to 'persona.owner'
Methods
signMessage(message: any, algorithm?: ALGORITHM): [string, string]- Signs message with specified algorithmverifyMessage(signature: string, message: any, publicKey: string, algorithm?: ALGORITHM): boolean- Verifies signaturetoAddress(bech32Prefix?: string): string- Generates address from signer's key
Related Packages
License
MIT License - see the LICENSE file for details
Credits
This library builds upon the work of the Scintilla Network team and community. Special thanks for the excellent work of paul miller work on hashes, key exchange and signatures.
1.0.0-beta.8
9 months ago
1.0.0-beta.7
9 months ago
1.0.0-beta.6
9 months ago
1.0.0-beta.5
10 months ago
1.0.0-beta.4
1 year ago
1.0.0-beta.3
1 year ago
1.0.0-beta.2
1 year ago
1.0.0-beta.1
1 year ago