jdogresorg / freewallet-desktop

Desktop wallet for Win/Mac/Linux which supports Bitcoin and Counterparty
https://freewallet.io
MIT License
68 stars 54 forks source link

Signing a TX - input: legacy - Output: native segwit #151

Open davestaxcp opened 11 months ago

davestaxcp commented 11 months ago

Below was mentioned as an issue with signing Tx's by @openstamp_support on Telegram:

Hi. We have an issue when try to use freewallet to sign a transaction with a legacy address as input and a native segwit address as output.

We create an unsigned transaction using bitcoinjs.Transaction in lib 'bitcoinjs-lib'. The sign process works fine with freewallet in the following three cases:

  1. Input: legacy address, Output: legacy address
  2. Input: native segwit address, Output: native segwit address
  3. Input: native segwit address, Output: legacy address

But freewallet has no response when click 'sign' in the following case:

Input: legacy address, Output: native segwit address

Any ideas about this? Appreciate for your help.

btcopenstamp commented 11 months ago

Part of the code as follows,

import * as bitcoinjs from 'bitcoinjs-lib';

export function createRawTx(sender, utxos, recipient, change){
    try{
        const txb = new bitcoinjs.Transaction();
        txb.version = 2
        for (let utxo of utxos) {
            txb.addInput(utxo.hash, utxo.vout, 0xfffffffd, Buffer.from(utxo.script, 'hex'))
        }
        txb.addOutput(bitcoinjs.address.toOutputScript(recipient), 547);

        if(change >= 546) {
            txb.addOutput(bitcoinjs.address.toOutputScript(sender), change);
        }
        txRaw = txb.toHex();
        // try to sign 'txRaw' with FreeWallet, but failed when sender starts with 1 and recipient starts with bc1q

    }catch(e) {
      console.log(e)
    }
  }
pataegrillo commented 11 months ago

Hi, i created a transaction legacy ----> segwit and signed it with freewallet and it worked. Perhaps, there is something wrong with the transaction built. In this case I would need to check the unsigned tx to know what's happening.

btcopenstamp commented 11 months ago

Hi @pataegrillo. Please help check the following two unsigned txs:

  1. Tx without bare multi-sig:

02000000018e1ec7a8f09cd94e0cbf6b0bb379f1688fad639c9cb0c628866757cce193d4a2000000001976a9144cb70be9830de47ab66d4a81b8a96109ab53603f88acfdffffff02230200000000000016001440769a48db8ca9d44b7d025fe42b8edea4cb52a8c5258900000000001976a9144cb70be9830de47ab66d4a81b8a96109ab53603f88ac00000000

  1. Tx with bare multi-sig:

02000000018e1ec7a8f09cd94e0cbf6b0bb379f1688fad639c9cb0c628866757cce193d4a2000000001976a9144cb70be9830de47ab66d4a81b8a96109ab53603f88acfdffffff04230200000000000016001440769a48db8ca9d44b7d025fe42b8edea4cb52a81c0300000000000069512102c3f5eeb228edff520e04f5aceb26e20b14597cd78bcf72147804669811ba634721028740c339eb16edda66135fe8491e00aa516fbfda2c4e5118c5ae16d7f06aa09d2102222222222222222222222222222222222222222222222222222222222222222253ae1c0300000000000069512102db5e5bed72dc192587b980ce9a91249c5c150ac0600ddf351f3e9ddc002ec0eb2102a81d2177de73a70a2a2fffda0fd09c1e3bbb332c43006336850a184867b9e08d2102020202020202020202020202020202020202020202020202020202020202020253aec5258900000000001976a9144cb70be9830de47ab66d4a81b8a96109ab53603f88ac00000000

pataegrillo commented 10 months ago

Hi, sorry for the delay, i'm been very busy. I saw you already spent that utxo. Did you solve the problem? do you still have issues with that?

btcopenstamp commented 10 months ago

Still have the issue. The UTXO was spent in another way.