Using scure-bip32 with Litecoin
glinisdev opened this issue · 0 comments
glinisdev commented
Is it possible to use this lib for Litecoin? For HDKey class I see VERSION property but it changes nothing.
import { generateMnemonic as _generateMnemonic, mnemonicToSeed } from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
import { HDKey } from '@scure/bip32';
import { network } from './constants';
import * as crypto from '@scure/btc-signer';
type AllowedKeyEntropyBits = 128 | 256;
export const network = {
testnet: {
private: 0x043587cf,
public: 0x04358394,
},
};
export function generateMnemonic(entropy: AllowedKeyEntropyBits = 256): string {
if (entropy !== 256 && entropy !== 128)
throw TypeError(
`Incorrect entropy bits provided, expected 256 or 128 (24 or 12 word results), got: "${String(
entropy
)}".`
);
return _generateMnemonic(wordlist, entropy);
}
async function generateWallet() {
const mnemonic = generateMnemonic();
const masterseed = await mnemonicToSeed(mnemonic);
const hdkey = HDKey.fromMasterSeed(masterseed, network.testnet);
const addresses = []
for (let i = 0; i < 5; i++) {
const path = `m/44'/2'/0'/0/${i}`;
const node = hdkey.derive(path);
const address = crypto.getAddress('wpkh', node.privateKey!);
addresses.push(address);
}
console.log("Addresses:", addresses);
}
generateWallet();
It returns these addresses (apparently taking some default BTC values for network keys):
Addresses: [
'bc1q6jrqgz7vk7nlqk5z8nlfpksycjpxtgf3r90a8e',
'bc1qwm9py9nh7ml0p623u9cj64ps97aykd96j84x60',
'bc1q57utqrw02h0vcuk4txathp2gktlvw75wap9e9q',
'bc1qekjw3qsk7r4qpe83rggu823pd7lz7amc2jnrhe',
'bc1qkj9cx5x49knq59ux5q9zf8gkq9apgrxxd2twru'
]