Sign a raw transaction manually

+2 votes

Hi!

Thank you for your work! I have successfully been using the multichain for building the distributed data storage based on streams.It's time to add the functionality of the assets and the wallets.The main condition is the sign raw transaction on the client side. I have read that multichain compatible this bitcoin and can use some client library to do this. Last week I'm trying to implement the functionality of the signature, but I can't do it. 

The sequence of actions is as follows:

- I created wallets addresses and made import them by importaddress

- createrawsendfrom via RPC call

For javascript i have tried to use bitcoinjs library - for import unsigned transaction and sign it. But result is internal excaption.

For C# i have tried to use NBitcoin. Nothing new. Internal exception.  As well as for php this BitWasp.

Finally i can tried to use this solution from this question http://www.multichain.com/qa/1923/manually-sign-a-raw-transaction. I left comments that I did not get the same signature as on the server.

Can you help me to understand what am I doing wrong? I hope for your help.

Thanks!

 

asked May 5, 2017 by strogen

2 Answers

0 votes

First you can test the process by using MultiChain to sign the transaction with external private key, using signrawtransaction with the key passed as a parameter. Please see this tutorial for examples:

http://www.multichain.com/developers/external-key-management/

Assuming that works, there could be a number of reasons why the particular bitcoin library you're using does not like the transactions and keys you're passing it. It's hard for us to know – perhaps you're passing the parameters in the wrong format, or perhaps it doesn't like some of MultiChain's metadata fields (even though they are legal according to bitcoin's transaction formatting). I would recommend choosing the language you're most familiar with, and trying to debug the process inside that library.

You may also be able to bypass some issues by using bitcoin-compatible addresses on your MultiChain blockchain – see the top section of this page for how: http://www.multichain.com/developers/address-key-format/

answered May 5, 2017 by MultiChain
Yes, of course, in order to compare the results I used signrawtransaction and its work exactly as described in the article http://www.multichain.com/developers/external-key-management/

For bitcoin-compatible addresses i used this
"If you want MultiChain’s addresses and private keys to be fully compatible with bitcoin’s, use the following values in the blockchain parameters: address-pubkeyhash-version=00, address-scripthash-version=05, private-key-version=80, address-checksum-value=00000000"
from your article http://www.multichain.com/developers/address-key-format/

For some reason I would prefer to use the approach from here
https://gist.github.com/daanporon/28087f042fb83507f5dc9389119a0508 ,
but the my result does not match the result of the signrawtransaction RPC call (secp256k1 signatures are different).
In this case i want to understand what i do wrong.
In other words, are there any example when it is required to do the sign raw transaction on the client?
I think you would have to ask the author of that Python script – unfortunately it's not within our scope to provide support for third-party libraries.
+1 vote

In finally, I found the right solution.

I reviewed this question http://www.multichain.com/qa/1923/manually-sign-a-raw-transaction and used the solution from daan (thanks a lot) https://github.com/Kunstmaan/multichain-address-node. To obtain scriptPubKeyI use RPC call decoderawtransaction and then for all vin items gettxout.

This is the solution I used for both JavaScript(for browser) and C#.

answered May 16, 2017 by strogen
I got signing to work using Kuntsmaan's multichain-address-node code.

Here's a snippet:

  .then( (unsignedTransaction) => {                                                                                                               
    // have all the inputs                                                                                                                        
    // sign the inputs                                                                                                                            
    let keys = Object.keys(indexToAddress)                                                                                                        
    let signedTransaction = clone(unsignedTransaction)                                                                                            
    let promises = [];                                                                                                                            
    keys.forEach( (index) => {                                                                                                                    
      let addr_str = indexToAddress[index]                                                                                                        
      let addr = myAddresses[addr_str]                                                                                                            
      promises.push( addr.sign( unsignedTransaction, index, myInputs[index].scriptPubKey, false )                                                 
        .then( (curSignedTransaction) => {                                                                                                        
          console.log('signed input ' + index)                                                                                                    
          signedTransaction.vin[index].script = curSignedTransaction.vin[index].script                                                            
          //return signedTransaction                                                                                                              
        }) )                                                                                                                                      
    })                                                                                                                                            
    return Promise.all(promises).then( () => {                                                                                                    
      console.log('done all signing')                                                                                                             
      return signedTransaction                                                                                                                    
    })                                                                                                                                            
  })

What I am looking for is the ability to do 'createRawTransaction' and 'decodeRawTransaction' in javascript.
...