Example #1
0
    def test_serialize_for_sig(self):
        vin = {'prevout_hash': '27c7c43cfde0943d2397b9fd5106d0a1f6927074a5fa6dfcf7fe50a2cb6b8d10',
               'prevout_n': 0, 'scriptSig': '', 'sequence': 0xffffffff}
        block_hash = '0000009784f43ea4c4158631a7b638f452e3ed8783eeac00d995e860de12e69f'
        sig_time = 1460397824
        ping = MasternodePing(vin=vin, block_hash=block_hash, sig_time=sig_time)

        expected = 'CTxIn(COutPoint(27c7c43cfde0943d2397b9fd5106d0a1f6927074a5fa6dfcf7fe50a2cb6b8d10, 0), scriptSig=)0000009784f43ea4c4158631a7b638f452e3ed8783eeac00d995e860de12e69f1460397824'
        self.assertEqual(expected, ping.serialize_for_sig())
Example #2
0
    def test_sign(self):
        vin = {'prevout_hash': '00'*32, 'prevout_n': 0, 'scriptSig': '', 'sequence':0xffffffff}
        block_hash = 'ff'*32
        current_time = 1461858375
        ping = MasternodePing(vin=vin, block_hash=block_hash, sig_time=current_time)

        expected_sig = 'H6k0M7G15GLnJ7i7Zcs8uCHcVRsn1P0hKK4lVMkgY4byaOvUECCsfxA9ktUiFT8scfFYYb/sxkcD8ifU/SEnBUg='
        wif = 'XCbhXBc2N9q8kxqBF41rSuLWVpVVbDm7P1oPv9GxcrS9QXYBWZkB'
        sig = ping.sign(wif, current_time = current_time)
        address = bitcoin.address_from_private_key(wif)
        self.assertTrue(bitcoin.verify_message(address, sig, ping.serialize_for_sig()))
        self.assertEqual(expected_sig, base64.b64encode(sig))
Example #3
0
    def test_create_and_sign(self):
        collateral_pub = '038ae57bd0fa5b45640e771614ec571c7326a2266c78bb444f1971c85188411ba1'  # XahPxwmCuKjPq69hzVxP18V1eASwDWbUrn
        delegate_pub = '02526201c87c1b4630aabbd04572eec3e2545e442503e57e60880fafcc1f684dbc'  # Xx2nSdhaT7c9SREKBPAgzpkhu518XFgkgh
        protocol_version = 70103

        ip = '0.0.0.0'
        port = 20000
        addr = NetworkAddress(ip=ip, port=port)

        vin = {
            'prevout_hash': '00' * 32,
            'prevout_n': 0,
            'scriptSig': '',
            'sequence': 0xffffffff
        }

        last_ping = MasternodePing(vin=vin, block_hash='ff' * 32)

        announce = MasternodeAnnounce(vin=vin,
                                      addr=addr,
                                      collateral_key=collateral_pub,
                                      delegate_key=delegate_pub,
                                      protocol_version=protocol_version,
                                      last_ping=last_ping)

        collateral_wif = 'XJqCcyfnLYK4Y7ZDVjLrgPnsrq2cWMF6MX9cyhKgfMajwqrCwZaS'
        delegate_wif = 'XCbhXBc2N9q8kxqBF41rSuLWVpVVbDm7P1oPv9GxcrS9QXYBWZkB'
        announce.last_ping.sign(delegate_wif, bfh(delegate_pub), 1461858375)
        sig = announce.sign(collateral_wif, 1461858375)

        address = 'XahPxwmCuKjPq69hzVxP18V1eASwDWbUrn'
        self.assertTrue(announce.verify(address))
        self.assertTrue(
            bitcoin.verify_message(address, sig, announce.serialize_for_sig()))
Example #4
0
    def test_create_and_sign(self):
        collateral_pub = '02c59b76fabcfc146c75365da6475f33d8fa596ef76b4b301d66da74180c429c78'  # XJtSNWxWufU5XAh59JfXPx9peodJwTqPqf
        delegate_pub = '03fa334250ddb2a51b30b31a98922a5e1c107042a482b68fc74999c6962ae3276e'  # XMy7W6qnXjKQzjKCD4JpkNBccMXwqQdGjn
        protocol_version = 70103

        ip = '0.0.0.0'
        port = 20000
        addr = NetworkAddress(ip=ip, port=port)

        vin = {
            'prevout_hash': '00' * 32,
            'prevout_n': 0,
            'scriptSig': '',
            'sequence': 0xffffffff
        }

        last_ping = MasternodePing(vin=vin, block_hash='ff' * 32)

        announce = MasternodeAnnounce(vin=vin,
                                      addr=addr,
                                      collateral_key=collateral_pub,
                                      delegate_key=delegate_pub,
                                      protocol_version=protocol_version,
                                      last_ping=last_ping)

        collateral_wif = 'YV56icVrjNioXn9kpZeL3DvtC7aN7kt8tr5ur2wqpMaXeJ3YQirG'
        delegate_wif = 'YQ6GbE34bXDgMgJEEJ87Buri6MCCcCNZoozpc34ima1PBjKqA8fj'
        announce.last_ping.sign(delegate_wif, bfh(delegate_pub), 1461858375)
        sig = announce.sign(collateral_wif, 1461858375)

        address = 'XJtSNWxWufU5XAh59JfXPx9peodJwTqPqf'
        self.assertTrue(announce.verify(address))
        self.assertTrue(
            bitcoin.verify_message(address, sig, announce.serialize_for_sig()))
Example #5
0
    def test_create_and_sign(self):
        collateral_pub = '0218864d879997fefbb2846e54ac4db0df99029b91cd12be32312d7e0da45029a8'  # PUFpXCipFhCM1n3CvY1pdJnsuBYGXopNoZ
        delegate_pub = '0329e04e958045a2866e59d13423772e16551cc1bedc50adb0e10b33ae28146cfc'  # P9h6zCz253jmc4TvqgKPRNpkx5qELdNWWT
        protocol_version = 70103

        ip = '0.0.0.0'
        port = 20000
        addr = NetworkAddress(ip=ip, port=port)

        vin = {
            'prevout_hash': '00' * 32,
            'prevout_n': 0,
            'scriptSig': '',
            'sequence': 0xffffffff
        }

        last_ping = MasternodePing(vin=vin, block_hash='ff' * 32)

        announce = MasternodeAnnounce(vin=vin,
                                      addr=addr,
                                      collateral_key=collateral_pub,
                                      delegate_key=delegate_pub,
                                      protocol_version=protocol_version,
                                      last_ping=last_ping)

        collateral_wif = 'XDL8kYsDheEviC7EYMNbo3Myy1txzKyfhZFZBaYUSPDPm9BZZae8'
        delegate_wif = 'XFsDL1FgC4VWQWZQu1NZAs5ri1rUP8mu1CviQYBbXedBTK37uppF'
        announce.last_ping.sign(delegate_wif, bfh(delegate_pub), 1461858375)
        sig = announce.sign(collateral_wif, 1461858375)

        address = 'PUFpXCipFhCM1n3CvY1pdJnsuBYGXopNoZ'
        self.assertTrue(announce.verify(address))
        self.assertTrue(
            ecc.verify_message_with_address(address, sig,
                                            announce.serialize_for_sig()))
Example #6
0
    def test_sign(self):
        vin = {
            'prevout_hash': '00' * 32,
            'prevout_n': 0,
            'scriptSig': '',
            'sequence': 0xffffffff
        }
        block_hash = 'ff' * 32
        current_time = 1461858375
        ping = MasternodePing(vin=vin,
                              block_hash=block_hash,
                              sig_time=current_time)

        expected_sig = 'H0Vh6xI0by9A1OcghrUz2vFxDPbLwyO63L45p7sNTo7QR/TvzTu9tMUlP4QBSl2KVLusoDvDkiyk+BZu3mMqJU4='
        wif = 'YV56icVrjNioXn9kpZeL3DvtC7aN7kt8tr5ur2wqpMaXeJ3YQirG'
        sig = ping.sign(wif, current_time=current_time)
        address = bitcoin.address_from_private_key(wif)
        self.assertTrue(
            bitcoin.verify_message(address, sig, ping.serialize_for_sig()))
        self.assertEqual(expected_sig, base64.b64encode(sig).decode('utf-8'))