Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy way to specify redeemScript while signing transaction #73

Open
motatoes opened this issue Jan 8, 2017 · 5 comments
Open

Easy way to specify redeemScript while signing transaction #73

motatoes opened this issue Jan 8, 2017 · 5 comments

Comments

@motatoes
Copy link

motatoes commented Jan 8, 2017

I ran into a problem when I was trying to use coinbin within a multisig spending. I've documented what I was tyring to do here. In summary, I was trying to generate a transaction in the core to spend out funds from a 2-of-2 multisig address. I wanted to partially sign the transaction on coinbin using 1 of the private keys, and then do the second signature in bitcoind. I kept getting the message error": "Script evaluated without error but finished with a false/empty top stack elementwhen I was tyring to get the final signature inbitocoind`.

After debugging this issue further I realised that bitcoind generates a transaction with an empty scriptSig for the inputs, and so coinbin signs it as if it were a normal pay to address transaction (I think). Unfortunately I was not able to solve my issue in the UI, but I did manage to solve it by manually modifying the transaction in JS as follows:

var rawtx2 = "01000000021a1f40dba3ab5c208b165d47bdcf2aadc517c4f2b90b781eab53dadcb35d61200100000000ffffffff05ec447a886d8711db0d5f4cbf1f61956cf227c82c5594ee195bb179e86faa910100000000ffffffff0138c70000000000001976a91472a2a94468e42593656cc9803c7a48c1863fc3e588ac00000000";


(function partialSignMultisig(window) {
	var coinjs = window.coinjs;
	var wifkey = "<WIFKEYHERE>";
	var script = rawtx2;
	var redeemScript = "5221020150ce6954f0cdcc2c5d57cf249f25eab0eed23e39549c4f06bcb42a37f308ce2102224aca2849ddad9c663c0bcfdac5ce3ca06f784ac8eca83404a4ea4ac61dbe7d52ae";

	var tx = coinjs.transaction();
  	var t = tx.deserialize(script);
        
        // Manually specify scripts for inputs ..
	for (var i = 0; i < t.ins.length; i++) {
		t.ins[i].script = coinjs.script(redeemScript);
	}

	var signed = t.sign(wifkey);
	console.log( signed );


})(window);

However, I think the UI responsible for signing should also allow us to specify the redeemScript to use during the signature .. In particular I think we can merge the transaction verification UI as a first step for the signature. So the user can decode the transaction as a first step, and optionally specify the private key for each input in the transaction, and also a redeemScript (?) if any. This is also similar to the API that bitcoind facilities as a second argument to the signrawtransaction endpoint. This issue is also related to #62

@dabura667
Copy link
Contributor

Currently there is no specification of partially signed transactions, so Bitcoin Core uses one method, Electrum uses another, Coinb.in another, Copay another...

Someone should write a BIP to standardize serialization for partially signed / unsigned raw transactions...

@motatoes
Copy link
Author

motatoes commented Feb 1, 2017

Maybe until standardization we should ensure that it works with the most popular client (core) ?

@dabura667
Copy link
Contributor

we should ensure that it works with the most popular client (core) ?

Pull requests are welcome. Just be sure to keep backwards compatibility in case someone is sitting on a partially signed transaction waiting to finish it in 5 years.

@motatoes
Copy link
Author

motatoes commented Feb 4, 2017

@dabura667 How should I do it in the UI side ? Should it be like adding a field "redeem Script" and setting all the input scripts to that value before signing?

image

@killingdex20

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants