Last active
September 18, 2020 17:50
-
-
Save 4tochka/7fce52966c816e4dcc52670dcc18cbb6 to your computer and use it in GitHub Desktop.
Sign bare MULTISIG 2 of 3 input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from pybtc import * | |
>>> | |
>>> # first step we need create 2 of 3 multisig output and add same btc | |
>>> | |
>>> a1 = Address("cPBuqn4ZsddXunx6EEev6khbfUzFnh3xxdEUPCrm5uy9qGcmbBEt", | |
address_type="P2PKH", testnet=True) | |
>>> a2 = Address("cVgShyj2q4YKFX8VzCffuQcrJVYhp522NFozNi7ih2KgNVbnysKX", | |
address_type="P2PKH", testnet=True) | |
>>> a3 = Address("cQWBhFENcN8bKEBsUHvpCyCfWVHDLfn1M65Gd6nenQkpEqL4DNUH", | |
address_type="P2PKH", testnet=True) | |
>>> script = b"".join([OP_2, | |
op_push_data(a1.public_key.key), | |
op_push_data(a2.public_key.key), | |
op_push_data(a3.public_key.key), | |
OP_3, OP_CHECKMULTISIG]) | |
>>> # script for 2 of 3 multisig ready | |
>>> | |
>>> a1.address | |
'mwJMtn5hW54pJC748EExvhRm6FRVmUZXQt' | |
>>> # add 0.65 btc from testnet faucet to this address | |
>>> # faucet tx d791f8386516bc464e7702159775734559d884a3fd50e45191c6207cdedac8ae | |
>>> # then sent this bitcoins to our multisig script | |
>>> tx = Transaction(testnet=True) | |
>>> tx.add_input("d791f8386516bc464e7702159775734559d884a3fd50e45191c6207cdedac8ae", 0) | |
>>> tx.add_output(64000000, script_pub_key=script) | |
>>> tx.sign_input(0, private_key="cPBuqn4ZsddXunx6EEev6khbfUzFnh3xxdEUPCrm5uy9qGcmbBEt", | |
address="mwJMtn5hW54pJC748EExvhRm6FRVmUZXQt") | |
>>> tx.serialize() | |
""" | |
0100000001aec8dade7c20c69151e450fda384d859457375971502774e46bc166538f891d7000000006a473 | |
04402200edb1ded443ea8015390c38afeb0564b52f6f9895c45952461f6ccfaf6639b8402206c0d3bfd2f7d | |
8c68d5cc3c774a9403d843cd27e33148927e3f575607b91d05c2012103b4603330291721c0a8e9cae65124a | |
7099ecf0df3b46921d0e30c4220597702cbffffffff010090d0030000000069522103b4603330291721c0a8 | |
e9cae65124a7099ecf0df3b46921d0e30c4220597702cb2102b2ec7de7e811c05aaf8443e3810483d5dbcf6 | |
71512d9999f9c9772b0ce9da47a2102c711ad61c9fbd3600716b981d101cf0a000ab3524525235c42f2cbcd | |
8c17c6da53ae00000000 | |
""" | |
>>> # broadcast this tx to network and we got bitcoins on our multisig script | |
>>> # tx cfe002d20590e2400a26b2dd9e2e6af2369cbb1f5442af286485841798590068 | |
>>> # lets do our main task sign multisig input | |
>>> | |
>>> tx = Transaction(testnet=True) | |
>>> tx.add_input("cfe002d20590e2400a26b2dd9e2e6af2369cbb1f5442af286485841798590068", 0) | |
>>> tx.add_output(63000000, address="mwJMtn5hW54pJC748EExvhRm6FRVmUZXQt") | |
>>> tx.sign_input(0, private_key=["cPBuqn4ZsddXunx6EEev6khbfUzFnh3xxdEUPCrm5uy9qGcmbBEt", | |
"cVgShyj2q4YKFX8VzCffuQcrJVYhp522NFozNi7ih2KgNVbnysKX"], | |
script_pub_key=script) | |
>>> tx.serialize() | |
""" | |
0100000001680059981784856428af42541fbb9c36f26a2e9eddb2260a40e29005d202e0cf00000000930048 | |
3045022100a7383d84ee35fb965978144d9243ca0892a1be81ce70058e70b2ba1ea5a762a7022058647d131f | |
cec2e3a63e57fa475b779b94c81a95b5c164fdfdbcee0124e3448c01483045022100b3945861a5a8a406bd57 | |
5857e19accdb0f6385ebf1c02938b35462cddeef400802205857f56d83e9ed7e98082d9127b8934262d3a046 | |
1429747e865b06345bbf8f9e01ffffffff01c04dc103000000001976a914ad204de226b3d11a70dc53b4998f | |
4603e138ff3f88ac00000000 | |
""" | |
>>> # in pybtc implemented order independent signing multisig algorithm | |
>>> # first private key owner is Alice and second owner is Bob | |
>>> alice_key = "cPBuqn4ZsddXunx6EEev6khbfUzFnh3xxdEUPCrm5uy9qGcmbBEt" | |
>>> bob_key = "cVgShyj2q4YKFX8VzCffuQcrJVYhp522NFozNi7ih2KgNVbnysKX" | |
>>> # Bob make fist turn and sign transaction with his key | |
>>> tx = Transaction(testnet=True) | |
>>> tx.add_input("cfe002d20590e2400a26b2dd9e2e6af2369cbb1f5442af286485841798590068", 0) | |
>>> tx.add_output(63000000, address="mwJMtn5hW54pJC748EExvhRm6FRVmUZXQt") | |
>>> tx.sign_input(0, private_key=bob_key, script_pub_key=script) | |
>>> bob_half_signed_tx = tx.serialize() | |
>>> # at this point bob sent half signed transaction to Alice | |
>>> # Alice turn | |
>>> tx = Transaction(bob_half_signed_tx, testnet=True) | |
>>> tx.sign_input(0, private_key=alice_key, script_pub_key=script) | |
>>> completed_tx = tx.serialize() | |
>>> # Alice broadcast transaction to network | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would it be possible to have the same sending to bare multisig please?
Or using a solution which would works offline and work also for Litecoin or Zcash?