Closed mchalise closed 5 years ago
What kind of address?
What derivation path?
Did you search the other answers for alternative HDkeys? ie ypub etc.
Public Address that my HD wallet uses(receiving address). Yup, I looked into old threads but all of them are Old ones and doesn't work at all. Could you please help me with this one. Thanks
Public Address that my HD wallet uses(receiving address).
Which one?
Please be specific, especially if you're asking someone to spend time to show you how to code for an unsupported currency.
LTC receiving address. LXDzdci9cKGa5CGYuHZroR4sBBXptAuXfV like this one. you get it right?
Which HDpath?
Hard derivation?
P2PKH?
Are you trying to recreate a Trezor address or something?
Please be specific.
Yes exactly. I want to pull out my LTC transaction history from HD wallets like Trezor, Exodus, so on. For that, I need addresses present in that wallet. correct me if I am wrong. Appreciate your help. Thanks
Each wallet has a different method.
Pick one.
Trezor?
@junderw Ok Trezor. then
Here you go.
const bitcoinjs = require('bitcoinjs-lib')
const bip32 = bitcoinjs.bip32
const coininfo = require('coininfo')
const litecoin = coininfo.litecoin.main
const litecoinBitcoinJSLib = litecoin.toBitcoinJS()
const ltub = 'Ltub2Zn7k8vFeTjWP8aefAjLJfRRigihzTRjEFVuEBGpKiAVX15K2GVgr73cqLSYgGtKnHgnucwevUmUXZARKhwACGPCtmpcfS9ELhMyqNq2gwz'
const firstAddress = 'LRJrTmGRcknZkNcpZPJNskyzbhxwLCSyvj'
const accountNode = bip32.fromBase58(ltub, litecoinBitcoinJSLib)
function getAddress (node, network) {
return bitcoinjs.payments.p2pkh({ pubkey: node.publicKey, network }).address
}
let firstTenReceiveAddress = []
let firstTenChangeAddress = []
const recvNode = accountNode.derive(0)
const changeNode = accountNode.derive(1)
for (let i = 0; i < 10; i++) {
firstTenReceiveAddress.push(getAddress(recvNode.derive(i), litecoinBitcoinJSLib))
firstTenChangeAddress.push(getAddress(changeNode.derive(i), litecoinBitcoinJSLib))
}
console.log(firstTenReceiveAddress)
console.log(firstTenChangeAddress)
console.log(firstAddress === firstTenReceiveAddress[0])
// true
Huge Thanks @junderw . !!!!
@junderw Quick question: It worked perfectly for Ltub but I also have like Mtub and xpub LTC keys. which is in BIP49, BIP44. Could you point me to some resource materials I can look into to generate for such keys also? Thanks. Appreciate All your Help and Time.
for non-standard xpub variants you need to base58check decode and replace the 4 version bytes with Ltub's etc. and then just do the same as above but with p2sh-p2wpkh.
So what you are suggesting is Change every address like xpub, Mtub to Ltub and use above one with p2sh-p2wph right?
yes
@junderw I tried your approach but it only worked for Ltub and Mtub. For xpub(Exodus wallet) its generating different address which is incorrect. For xpub and mtub I am using
const p2wpkh = bitcoinjs.payments.p2wpkh({ pubkey: node.publicKey, network }) return bitcoinjs.payments.p2sh({ redeem: p2wpkh, network }).address
Is there anything I am doing wrong ? thanks
could you give me an example wallet:
1.xpub6BurV3Ff8nB5CNM8MCkzJPV6rprymcbto7a7cesFWBorc1M4GqGkK8PkYoyBZN8RVSc1UwrEae4sYbmQZ9zvzZviL1Sv2GgCfDL8fdT8f28
const bitcoinjs = require('bitcoinjs-lib')
const bs58check = require('bs58check')
const bip32 = bitcoinjs.bip32
const coininfo = require('coininfo')
const litecoin = coininfo.litecoin.main
const litecoinBitcoinJSLib = litecoin.toBitcoinJS()
const extended_key = 'xpub6BurV3Ff8nB5CNM8MCkzJPV6rprymcbto7a7cesFWBorc1M4GqGkK8PkYoyBZN8RVSc1UwrEae4sYbmQZ9zvzZviL1Sv2GgCfDL8fdT8f28'
const type = extended_key.substr(0,4)
/*
Litecoin 0x019da462 - Ltub 0x019d9cfe - Ltpv P2PKH or P2SH m/44'/2'
Litecoin 0x01b26ef6 - Mtub 0x01b26792 - Mtpv P2WPKH in P2SH m/49'/1'
*/
function convertAnyAddressToLtub(extended_key, type) {
if(type == "Ltub"){
return extended_key
}else{
let data = bs58check.decode(extended_key)
data = data.slice(4)
data = Buffer.concat([Buffer.from('019da462','hex'), data])
return bs58check.encode(data)
}
}
const ltub = convertAnyAddressToLtub(extended_key, type)
const accountNode = bip32.fromBase58(ltub, litecoinBitcoinJSLib)
function getAddress (node, network, type) {
if(type == "Ltub"){
return bitcoinjs.payments.p2pkh({ pubkey: node.publicKey, network }).address
}else{
//segwit
const p2wpkh = bitcoinjs.payments.p2wpkh({ pubkey: node.publicKey, network })
return bitcoinjs.payments.p2sh({ redeem: p2wpkh, network }).address
}
}
let firstFiveReceiveAddress = []
const recvNode = accountNode.derive(0) // derive(0): Receiving Node & derive(1): Change Node
for (let i = 0; i < 5; i++) {
firstFiveReceiveAddress.push(getAddress(recvNode.derive(i), litecoinBitcoinJSLib, type))
}
console.log(firstFiveReceiveAddress)
[ 'MMVeqbK6F4GcrHG27Pp3wpQURNYdJvgmey', 'MCY1f6Qn8mWYZuiXM8EG6d5w4ZtUGMs3JJ', 'MVTBQNQVw5f73rQurocogkrFCJyK3g1giR', 'MQ4ZnSZqftrytGZKubGmxevdB3CkUuT4Zp', 'MNXRPYQ4n4Ns8VY2s2UZMV1AcjoZbdS28e' ]
Could you try changing this?
I got LXDzdci9cKGa5CGYuHZroR4sBBXptAuXfV
Looks like both Ltub and xpub uses p2pkh. Got it. Thanks for all your help. Appreciate it.
@junderw excuse me for reviving a new thread, but can i use litecoinBitcoinJSLib to create transactions?
Lets say my Ltub key is