Closed N3IMYS closed 8 months ago
const masterNode: BIP32Interface = bip32.fromSeed(seed, litecoinNetwork.testnet);
const masterPrivateKey: string = masterNode.toBase58();
const masterPublicKey: string = masterNode.derivePath(`m/44'/2'/0'`).neutered().toBase58();
const xpubNode = bip32.fromBase58(masterPublicKey, litecoinNetwork.testnet);
const firstAddressChild = xpubNode.derivePath(`0/0`);
const firstAddressPrivChild = masterNode.derivePath(`m/44'/2'/0'/0/0`);
const rawSignature = firstAddressPrivChild.sign(...);
@junderw Hi thank you so much for your reply , but can you please also extend a bit logic of creating a partially signed bitcoin transaction in litecoin network ?
I want to send 10000 satoshis from this public address by creating a psbpt (don't know other ways to send crypto from HD wallet address) => then broadcast the transaction to the blockchain
I have this code :
//create a new Psbt
const psbt = new Psbt({ network: this.network });
my utxos is just a public addresses which is got one time faucet deposit on testnet with 1.5 LTC
so I am going to add the only input to my utxo
// don't really understand what I should put in the "script" property of an witnesUtxo object
psbt.addInput({
hash: '940b2a13f13404be0e16e3499018a682626c34a1bb37be444a6600e9ac49c216',
index: 0,
witnessUtxo: {
script: Buffer.from('0014072ad96f57b57b9731c7999648ea0a486a3a507d', 'hex'),
value: 150000000,
}
})
.addOutput({
address: toAddress,
value: 10000,
});
const xpriv: string = masterNode.toBase58();
const xprivChildNode = bip32.fromBase58(masterPrivateKey, this.network).derivePath('0/0');
So the question is: am I using right the psbt in this way:
const ecPair = ECPairFactory(ecc);
const keyPair = ecPair.fromWIF(xprivChildNode.toWIF(), this.network);
// sign inputs
psbt.signAllInputs(keyPair);
// finalaize the tx
psbt.finalizeAllInputs();
Its just eventually returns me an error of psbt: no inputs were signed ....
don't really understand what I should put in the "script" property of an witnesUtxo object
The input points to a UTXO which is an output of a previous transaction.
The hash points to the transaction.
The index tells it which output of the transaction with txid hash
we need to look at.
The witnessUtxo tells it the script and the value contained in the output.
Given all the info (1. Where to find the output. 2. What is the content of the output.) we can sign the input.
Its just eventually returns me an error of psbt: no inputs were signed ....
That means you are mixing up keys.
Any number of mix up in your brain/code can cause you to generate the wrong key.
It could also be that the script in your witnessUtxo is incorrect, since that's what the signing code uses to compare against when searching for inputs to sign.
Thanks a lot for your help !!
Hello everyone, hope you are doing well. I just started to delve into the Bitcoin and Litecoin chains world to achieve some results regarding my work tasks:
I found Litecoin testnet and mainnet network type objects and just pasted them into code:
I am trying to generate an HD Wallet with bip39 and bip32:
I am not pretty sure that I am deriving the xpub from xpriv in a right way (don't know what derivation path should be for reaching the xpub) But at this point I have xpriv and xpub like:
So next when I am generating the new public addresses with derivationPath I am changing the fifth digit of the derivation meaning: m/44'/2'/0'/0/0 will be the derivation path for the frist public address, m/44'/2'/0'/0/1 for the second e.t.c And I get them as :
So the question how can I check if these pks really related to the xpub and how can I sign them using xpriv ?