Add basic segwit support #184
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds support for the segwit transaction structure and signing of P2WPKH segwit inputs.
New functions:
sign_segwit_struct(tx, i, priv, hashcode=SIGHASH_ALL, segwit=False, amount=0): Signs input i for a segwit transaction structure. Signes the input as a legacy P2PKH if segwit==False; or as a P2WPKH input if segwit==True.
mk_p2wpkh_script(pubkey): Creates a P2WPKH script using pubkey.
Also adds the following new internal functions used by sign_segwit_struct():
mk_p2wpkh_scriptcode(pubkey); mk_p2wpkh_redeemscript(pubkey); pubkey_to_hash(pubkey); signature_form_segwit(tx, i, scriptCode, amount, hashcode=SIGHASH_ALL); mk_hashOutputs(out, hashcode=SIGHASH_ALL); mk_hashInputs(inp, hashcode=SIGHASH_ALL); serialize_signature_form_segwit(txobj).
Example usage:
The example from the README using legacy transactio structure still works as expected.
This is only thought of as a first start to implement segwit and so many bugs are expected and more rigorous testing is necessary and implementation of other segwit types.