From f4790b65ecebed9c42326cfe98f37ec547db3f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Fari=C3=B1a?= Date: Mon, 22 Mar 2021 17:26:33 -0300 Subject: [PATCH] fix: gets btc publickey from privateKey --- src/common/transaction/btccoin.js | 4 +++- src/common/transaction/index.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/transaction/btccoin.js b/src/common/transaction/btccoin.js index c03c797ad..736861bbc 100644 --- a/src/common/transaction/btccoin.js +++ b/src/common/transaction/btccoin.js @@ -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; @@ -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; diff --git a/src/common/transaction/index.js b/src/common/transaction/index.js index e5500b815..0c4058f7b 100644 --- a/src/common/transaction/index.js +++ b/src/common/transaction/index.js @@ -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') { @@ -67,7 +67,7 @@ export default class Transaction { netType, amount, fees, - publicKey, + privateKey, }); result = btc.signTransaction({ transactionBuilder, inputs, privateKey, netType, addressType,