1.0.0 • Published 5 months ago
bip44-registry v1.0.0
bip44-registry
BIP44-Registry provides a structured, high-performance implementation of the BIP44 cryptocurrency constants used for hierarchical deterministic wallets.
Install
npm i --save bip44-registry
Usage
Basic Usage
const bip44Registry = require('bip44-registry');
// Get coin details by symbol
const bitcoinCoins = bip44Registry.getBySymbol('BTC');
console.log(bitcoinCoins[0]);
// { code: 2147483648, symbol: 'BTC', name: 'Bitcoin' }
// Get coin by constant code (BIP44 path constant)
const litecoin = bip44Registry.getByCode(0x80000002);
console.log(litecoin);
// { code: 2147483650, symbol: 'LTC', name: 'Litecoin' }
// Get exact match when multiple coins share the same symbol
const liquidBitcoin = bip44Registry.getExactMatch('LBTC', 'Liquid BTC');
console.log(liquidBitcoin);
// { code: 2147485424, symbol: 'LBTC', name: 'Liquid BTC' }
// Access raw data array
const allCoins = bip44Registry.all;
console.log(`Total coins: ${allCoins.length}`);
TypeScript Support
import bip44Registry, { CoinData } from 'bip44-registry';
// Get a list of coins by symbol
const ethereumCoins: CoinData[] = bip44Registry.getBySymbol('ETH');
console.log(`Found ${ethereumCoins.length} Ethereum-related coins`);
// Look up by code (with proper typing)
const dogecoin: CoinData | undefined = bip44Registry.getByCode(0x80000003);
if (dogecoin) {
console.log(`Found ${dogecoin.name} with symbol ${dogecoin.symbol}`);
}
// Type-safe iteration
bip44Registry.getBySymbol('BTC').forEach((coin: CoinData) => {
console.log(`BTC coin: ${coin.name}, code: 0x${coin.code.toString(16)}`);
});
// Use in HD wallet derivation (example)
function getDerivationPath(symbol: string, account: number = 0): string | undefined {
const coins = bip44Registry.getBySymbol(symbol);
if (coins.length === 0) return undefined;
// Use the first matching coin's code
const coinType = coins[0].code & 0x7fffffff; // Remove hardened bit
return `m/44'/${coinType}'/${account}'/0/0`;
}
console.log(getDerivationPath('BTC')); // "m/44'/0'/0'/0/0"
console.log(getDerivationPath('ETH')); // "m/44'/60'/0'/0/0"
License
MIT
1.0.0
5 months ago