Example #1
0
def sign_p2pk(tx, i, priv, pub, hashtype = SIGHASH_ALL):
    assert isinstance(tx, dict)
    i = int(i)
    assert isinstance(priv, int)
    assert isinstance(pub, bytes)

    prev_script = script.make_p2pk(pub)
    txhash = sighash(tx, i, prev_script, hashtype)
    sig = ecdsa.sign(txhash, priv)
    sig = ecdsa.serialize_sig(sig) + convert.int_to_byte(hashtype)
    tx["ins"][i]["script"] = script.serialize([sig])
Example #2
0
    def test_build(self):
        self.assertEqual(
            script.make_p2pk(b'\x02\x8dO@#`d\x9c\x9e"\xec\x8f\xd2\x01\xa3\xcc\xe5\x8c|aL\xc4d\xb0\xd8b}\xed\xe2\xa9G\xb1\xd7'),
            b'!\x02\x8dO@#`d\x9c\x9e"\xec\x8f\xd2\x01\xa3\xcc\xe5\x8c|aL\xc4d\xb0\xd8b}\xed\xe2\xa9G\xb1\xd7\xac'
        )

        self.assertEqual(
            script.make_p2pkh(b'\xf5\x8e:\xac\xc8BO\x04)\\\x14\xacfu\x11\x8b\x7f\n8\r'),
            b'v\xa9\x14\xf5\x8e:\xac\xc8BO\x04)\\\x14\xacfu\x11\x8b\x7f\n8\r\x88\xac'
        )

        self.assertEqual(
            script.make_p2sh(b'\xf5\x8e:\xac\xc8BO\x04)\\\x14\xacfu\x11\x8b\x7f\n8\r'),
            b'\xa9\x14\xf5\x8e:\xac\xc8BO\x04)\\\x14\xacfu\x11\x8b\x7f\n8\r\x87'
        )

        self.assertEqual(
            script.make_data(b'g\x8b\xe5\xdc\x96m\x10\xed\xf1\xaf\xe6\xf9\x1e\xce\x8b\xd8Gt\xad3'),
            b'j\x14g\x8b\xe5\xdc\x96m\x10\xed\xf1\xaf\xe6\xf9\x1e\xce\x8b\xd8Gt\xad3'
        )