Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
fix: gets btc publickey from privateKey
Browse files Browse the repository at this point in the history
  • Loading branch information
itofarina committed Mar 22, 2021
1 parent 705fd84 commit f4790b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/common/transaction/btccoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const getTransactionInputs = async ({
* @returns {object} Transaction builder
*/
export const buildTransaction = ({
inputs, fromAddress, addressType, toAddress, netType, amount, fees, publicKey,
inputs, fromAddress, addressType, toAddress, netType, amount, fees, privateKey,
}) => {
const network = netType === 'Mainnet' ? bitcoin.networks.bitcoin : bitcoin.networks.testnet;
const cost = amount + fees;
Expand All @@ -63,6 +63,8 @@ export const buildTransaction = ({
// Calculate redeem script
let redeemScript = null;
if (addressType === BtcAddressType.segwit) {
const buf = Buffer.from(privateKey, 'hex');
const { publicKey } = bitcoin.ECPair.fromPrivateKey(buf, { network });
const p2wpkh = bitcoin.payments.p2wpkh({ pubkey: publicKey, network });
const p2sh = bitcoin.payments.p2sh({ redeem: p2wpkh, network });
redeemScript = p2sh.redeem.output;
Expand Down
4 changes: 2 additions & 2 deletions src/common/transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class Transaction {
console.log('Transaction.processTransaction start');
let result = null;
const {
symbol, privateKey, netType, sender, receiver, value, data, memo, gasFee, contractAddress, addressType, publicKey,
symbol, privateKey, netType, sender, receiver, value, data, memo, gasFee, contractAddress, addressType,
} = this;
try {
if (symbol === 'BTC') {
Expand All @@ -67,7 +67,7 @@ export default class Transaction {
netType,
amount,
fees,
publicKey,
privateKey,
});
result = btc.signTransaction({
transactionBuilder, inputs, privateKey, netType, addressType,
Expand Down

0 comments on commit f4790b6

Please sign in to comment.