shapeshift / hdwallet

A library for interacting with hardware wallets from JS/TS.
https://hdwallet.shapeshift.now.sh/
MIT License
208 stars 89 forks source link

Cant Sign Transaction - Encountered invalid prevhash #165

Open metaspartan opened 4 years ago

metaspartan commented 4 years ago

image

Getting encountered invalid prevhash when attempting to sign a transaction with a coin that has no client typically (Denarius) but is in the firmware of Keepkey...Address derivation and all of that works great, and now pulling unspent transactions from the address and then attempting to sign it...this fails everytime with the "Encountered invalid prevhash" which seems to be linked to the Trezor firmware libs? This is all on a Keepkey though fyi and using WebUSB, other transactions are able to sign just fine like Dogecoin, Bitcoin, Litecoin, etc.

My btcSignTx call:

    const txid = "fb11728d7afbf705279dbe3ce8d964b903b23d1d75cda3e0b27b24e008321dca"; //UTXO TXID
    const hex =
      "010000003b4afc5e01acf0bb4ad63d880e590b80c5a3ee66e950fddeb8c5cc72578a1c89bbcf597251010000006a473044022003ddac31ed3d2dffc50169c0bcece812207876467d9863d78d6064d92349b915022066fc8187ec60dbff205878c570e13f7ca5377ebb8b5181d206a844f968942de6012103f5b29d1f63e06568912c4ca0ca2bf8827ed2bef532446ef3d379590e0d3316aeffffffff02a0bb0d00000000001976a914032c2288699a64540e81e9980b3e6598040ba10288aca8609200000000001976a9145ef9da5d87a0c17eb8dc08ad4c14ab948af8777b88ac00000000";
    // Raw TX HEX of TXID getrawtransaction

    const inputs = [
      {
        addressNList: denariusBip44.addressNList,
        scriptType: BTCInputScriptType.SpendAddress,
        amount: String(2160258),
        vout: 1, 
        txid,
        segwit: false,
        tx: dTxJson, 
        hex,
      },
    ];

    const outputs = [
      {
        address: "DFaSN5xF8Y7o9ifFuBcHQsub9UoT3yn7kx",
        addressType: BTCOutputAddressType.Spend,
        scriptType: BTCOutputScriptType.PayToAddress,
        amount: String(261614),
        isChange: false,
      },
    ];

    const res = await wallet.btcSignTx({
      coin: "Denarius",
      inputs,
      outputs,
      version: 1,
      locktime: 0,
    });

The dxTxJson just includes the full raw transaction json of the main input TXID as followed by other coins.

Denarius was added as a cointype under the bitcoin.ts file (Number 116) if anyone can test this and assist.

metaspartan commented 4 years ago

@keepkeyjon Maybe?

metaspartan commented 4 years ago

@kaladinlight maybe?

metaspartan commented 4 years ago

This is the dTXjson I am attempting to use with it, the txid is valid and on chain according to block explorers and unspent.

{
  "txid": "fb11728d7afbf705279dbe3ce8d964b903b23d1d75cda3e0b27b24e008321dca",
  "size": 229,
  "version": 1,
  "time": 1593592379,
  "locktime": 0,
  "vin": [
    {
      "txid": "517259cfbb891c8a5772ccc5b8defd50e966eea3c5800b590e883dd64abbf0ac",
      "vout": 1,
      "scriptSig": {
        "asm": "3044022003ddac31ed3d2dffc50169c0bcece812207876467d9863d78d6064d92349b915022066fc8187ec60dbff205878c570e13f7ca5377ebb8b5181d206a844f968942de601 03f5b29d1f63e06568912c4ca0ca2bf8827ed2bef532446ef3d379590e0d3316ae",
        "hex": "473044022003ddac31ed3d2dffc50169c0bcece812207876467d9863d78d6064d92349b915022066fc8187ec60dbff205878c570e13f7ca5377ebb8b5181d206a844f968942de6012103f5b29d1f63e06568912c4ca0ca2bf8827ed2bef532446ef3d379590e0d3316ae"
      },
      "sequence": 4294967295,
      "n": 0,
      "addr": "DMicSbP8Jt7LZ38QSfco8q3uKCrjPbMD29",
      "valueSat": 1049400,
      "value": 0.10494000,
      "doubleSpentTxID": null
    }
  ],
  "vout": [
    {
      "value": "0.009",
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 032c2288699a64540e81e9980b3e6598040ba102 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914032c2288699a64540e81e9980b3e6598040ba10288ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "D5RsSNzzfeiLyDrhVkPePv8DK4Ayxyi1fu"
        ]
      }
    },
    {
      "value": "0.09593",
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 5ef9da5d87a0c17eb8dc08ad4c14ab948af8777b OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9145ef9da5d87a0c17eb8dc08ad4c14ab948af8777b88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "DDoHNP2U1gqv77bwdUk59dXUWbsWjbw1L1"
        ]
      }
    }
  ],
  "blockhash": "0000000017238a5befc1d0b6cbd1057863f26d2f3eead225195ffe27be717eb2",
  "confirmations": 3590,
  "valueOut": 0.10493000,
  "valueIn": 0.10494000
}
mrnerdhair commented 2 years ago

Possibly related: https://github.com/shapeshift/web/issues/792

mrnerdhair commented 2 years ago

Possibly related: #404