Bitcoin

Separated Witness – How to Take Litecoin Testnet SegWit Wallet Offline

hello. I’m using the bitcoinjs-lib package to generate wallet addresses and private keys locally, but it seems to be generating legacy type Litecoin addresses. My goal is to create a segwit type with the following prefix: tltc

Here is my code:

const bitcoin = require('bitcoinjs-lib');

function generateLtcAddress() 
    const litecoinTestnet = 
        messagePrefix: '\x19Litecoin Signed Message:\n',
        bip32: 
            public: 0x043587cf,
            private: 0x04358394
        ,
        pubKeyHash: 0x6f,
        scriptHash: 0xc4, //  for segwit (start with 2)
        wif: 0xef
    ;

    const keyPair = bitcoin.ECPair.makeRandom( network: litecoinTestnet );
    const  address  = bitcoin.payments.p2pkh(
        pubkey: keyPair.publicKey,
        network: litecoinTestnet
    );

    const privateKeyWIF = keyPair.toWIF();

    console.log("Litecoin Testnet Address:", address);
    console.log("Private Key (WIF):", privateKeyWIF);
    return 
        address: address,
        privateKey: privateKeyWIF
    ;

Calculation:

Litecoin Testnet Address: mnUDkLibVp1MhKSm6pvYgT26PUxeTjHJiR
Private Key (WIF): cQgM1FZSkJWJ3eFs4xfYozfCt37KYKr1rEGEYwuNdquwsfzjASnM

Please let me know how I can achieve this. Or should I use another npm package or something?

Related Articles

Back to top button