Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using scure-bip32 with Litecoin #15

Open
glinisdev opened this issue Apr 4, 2024 · 0 comments
Open

Using scure-bip32 with Litecoin #15

glinisdev opened this issue Apr 4, 2024 · 0 comments

Comments

@glinisdev
Copy link

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'
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant