Exemplo n.º 1
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()))
Exemplo n.º 2
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()))
Exemplo n.º 3
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()))
Exemplo n.º 4
0
    def test_verify(self):
        announce = MasternodeAnnounce.deserialize(raw_announce)
        message = announce.serialize_for_sig()

        pk = bitcoin.public_key_to_p2pkh(bfh(announce.collateral_key))
        self.assertTrue(announce.verify())

        raw = '7ca6564432d0e0920b811887e1f9077a92924c83564e6ea8ea874fc8843ccd2b0000000000ffffffff00000000000000000000ffffc0a801014e1f410411e2638aeb4584ff2e027b6ee20e05655ff05583185b1d87188185d6955534fe02ad35caabb5e6e9ce8747ba73fdccccd2369feb9a6f2b0bdee93378e7c8f1c0410411e2638aeb4584ff2e027b6ee20e05655ff05583185b1d87188185d6955534fe02ad35caabb5e6e9ce8747ba73fdccccd2369feb9a6f2b0bdee93378e7c8f1c0411bab132617d8e6a0e3b5434c91a5a64ff13a9cfadc6c178a47b87691f13a26e7440c08660e488ddf927bba1bf04c1ec196370452a30fd3381ea8ba27d627f9d4468be80e5700000000d71101007ca6564432d0e0920b811887e1f9077a92924c83564e6ea8ea874fc8843ccd2b0000000000ffffffffd75eb4fa0cb71dd2e99d7b242784a5601c5c86d7c1cf0362a3391575070000008be80e5700000000411b6d5985008e0821c936fafc192f31963141ae2fab837e84bb9f12422711c1952d5750f9a781c89117a6f4576edc1149a1bf211e7151c5c88cf3252e2d83cb154a0000000000000000'
        announce = MasternodeAnnounce.deserialize(raw)
        msg = announce.serialize_for_sig()

        pk = bitcoin.public_key_to_p2pkh(bfh(announce.collateral_key))
        self.assertTrue(announce.verify(pk))
Exemplo n.º 5
0
    def test_serialization(self):
        announce = MasternodeAnnounce.deserialize(raw_announce)

        self.assertEqual('27c7c43cfde0943d2397b9fd5106d0a1f6927074a5fa6dfcf7fe50a2cb6b8d10', announce.vin['prevout_hash'])
        self.assertEqual(0, announce.vin['prevout_n'])
        self.assertEqual('', announce.vin['scriptSig'])
        self.assertEqual(0xffffffff, announce.vin['sequence'])

        self.assertEqual('192.168.1.101:19999', str(announce.addr))

        self.assertEqual('02d3879cdf9afcc59c42d8d858e44ba0e3d51df7792c6c0bbb6dd5e9de41f5580e', announce.collateral_key)
        self.assertEqual('04431873cf0a6ae3f6903e72ed915f0e21029e59c1c279358f98e3d4136250c774a4b14bbd8a1ffb800c85310a8379869f05a24a6b99ce3d79f6194881ed7091d6', announce.delegate_key)
        self.assertEqual('H6vjQtcmZ4riE5xeVocIAxEfnOAMDfi0jU06p+8MlflWeSO7U9zns6HqaUERq7+Vb4T/FxmSLgjb0FMPyiPOFEQ=', base64.b64encode(announce.sig))
        self.assertEqual(1460397824, announce.sig_time)
        self.assertEqual(70103, announce.protocol_version)

        self.assertEqual('27c7c43cfde0943d2397b9fd5106d0a1f6927074a5fa6dfcf7fe50a2cb6b8d10', announce.last_ping.vin['prevout_hash'])
        self.assertEqual(0, announce.last_ping.vin['prevout_n'])
        self.assertEqual('', announce.last_ping.vin['scriptSig'])
        self.assertEqual(0xffffffff, announce.last_ping.vin['sequence'])
        self.assertEqual('0000009784f43ea4c4158631a7b638f452e3ed8783eeac00d995e860de12e69f', announce.last_ping.block_hash)
        self.assertEqual(1460397824, announce.last_ping.sig_time)
        self.assertEqual('G1xOVjKTYrg9/LuqcDl8jEnLfmnt+FsOgjLSeYtxluxwUDYGndyREm35jbT2dVsuwBV3ykF9+qLpCgOCvWZ+QQ0=', base64.b64encode(announce.last_ping.sig))

        self.assertEqual(0, announce.last_dsq)

        self.assertEqual(raw_announce, announce.serialize())
Exemplo n.º 6
0
    def test_hash(self):
        announce = MasternodeAnnounce.deserialize(raw_announce)

        expected_hash = 'a8a3dc1782191f28f613c8971709a57ee58a4d0d7a11138804f89a0b088d67d1'
        msg = announce.serialize_for_sig()

        h = bitcoin.Hash(bitcoin.msg_magic(msg))
        h = bitcoin.hash_encode(h)
        self.assertEqual(expected_hash, h)
Exemplo n.º 7
0
    def test_hash(self):
        announce = MasternodeAnnounce.deserialize(raw_announce_70210)

        expected_hash = '5f69e59f5ea327be16e649fb6c72ed02e39ef9dae8ecb27d222419e94dcd89b7'
        msg = announce.serialize_for_sig()

        h = bitcoin.Hash(ecc.msg_magic(msg))
        h = bitcoin.hash_encode(h)
        self.assertEqual(expected_hash, h)
Exemplo n.º 8
0
    def test_serialize_protocol_version_70201(self):
        raw = '08108933d948aed6a107cd01e7862ed61ef9bf14e87da0a14e8d17791e9f9c570100000000ffffffff00000000000000000000ffff7f0000014e1f210269e1abb1ffe231ea045068272a06f0fae231d11b11a54225867d89267faa4e23210269e1abb1ffe231ea045068272a06f0fae231d11b11a54225867d89267faa4e234120b8bc547ce2471125eddfdfd5af30ea1e892e750acfe2896b241097b7f21442a61da073d47c885535769bf215eb3e97eca692d868db1bfb9dee469a1ece5acb92a1945457000000003912010008108933d948aed6a107cd01e7862ed61ef9bf14e87da0a14e8d17791e9f9c570100000000ffffffffefc894d8431c1774a19aeb732ea7fc56925b740ed80486f30424109a05000000a1945457000000004120818f17742e6644359c8b9a91e56b595615bd2c593de713304435dcfd07ceb6a815559fd3b2f05f531d9b9918b22b8748491c3f36cb25e8397ff950f74030444f0000000000000000'
        announce = MasternodeAnnounce.deserialize(raw)
        announce.sig_time = 1465161129
        msg = announce.serialize_for_sig()
        expected = ''.join([
            '127.0.0.1:19999',
            '1465161129',
            bitcoin.hash_encode(bitcoin.hash_160('0269e1abb1ffe231ea045068272a06f0fae231d11b11a54225867d89267faa4e23'.decode('hex'))),
            bitcoin.hash_encode(bitcoin.hash_160('0269e1abb1ffe231ea045068272a06f0fae231d11b11a54225867d89267faa4e23'.decode('hex'))),
            '70213',
        ])

        self.assertEqual(expected, msg)
Exemplo n.º 9
0
    def test_serialize_protocol_version_70210(self):
        announce = MasternodeAnnounce.deserialize(raw_announce_70210)
        msg = announce.serialize_for_sig()
        expected = to_bytes(''.join([
            '178.151.192.107:19999',
            '1530021571',
            bitcoin.hash_encode(
                bitcoin.hash_160(
                    bfh('0221088c51bef8c9c891b385fa1e8a78b016f01db41741aea7e43e67a7415ab7be'
                        ))),
            bitcoin.hash_encode(
                bitcoin.hash_160(
                    bfh('042379a871a10ae6bf06e756262f69d7f0ce9b8b562f223bde964db573fb7d0f1e219c246a4b3a6133c5cec136d83f4049df51321ba2cb01d676cc3982c7e24d1f'
                        ))),
            '70210',
        ]))
        print('7' * 50, expected)
        print('8' * 50, msg)

        self.assertEqual(expected, msg)
Exemplo n.º 10
0
    def test_serialization(self):
        announce = MasternodeAnnounce.deserialize(raw_announce_70210)

        self.assertEqual(
            '54db7eb00977d96b8f0a78fec4689f0a2d9ac0792676790a32265d4b0c82a3d0',
            announce.vin['prevout_hash'])
        self.assertEqual(1, announce.vin['prevout_n'])
        self.assertEqual('', announce.vin['scriptSig'])
        self.assertEqual(0xffffffff, announce.vin['sequence'])

        self.assertEqual('178.151.192.107:19999', str(announce.addr))

        self.assertEqual(
            '0221088c51bef8c9c891b385fa1e8a78b016f01db41741aea7e43e67a7415ab7be',
            announce.collateral_key)
        self.assertEqual(
            '042379a871a10ae6bf06e756262f69d7f0ce9b8b562f223bde964db573fb7d0f1e219c246a4b3a6133c5cec136d83f4049df51321ba2cb01d676cc3982c7e24d1f',
            announce.delegate_key)
        self.assertEqual(
            'ICj1/mZo5pqUMlYFghCA9BeTAsDpu4fnVzUnPmMHRTSUPtSbNPeUokmH1Q4hfp9JCOt+RypYFc1QlCuaa5P/hWc=',
            base64.b64encode(announce.sig).decode('utf-8'))
        self.assertEqual(1530021571, announce.sig_time)
        self.assertEqual(70210, announce.protocol_version)

        self.assertEqual(
            '54db7eb00977d96b8f0a78fec4689f0a2d9ac0792676790a32265d4b0c82a3d0',
            announce.last_ping.vin['prevout_hash'])
        self.assertEqual(1, announce.last_ping.vin['prevout_n'])
        self.assertEqual('', announce.last_ping.vin['scriptSig'])
        self.assertEqual(0xffffffff, announce.last_ping.vin['sequence'])
        self.assertEqual(
            '00000000004eeaf1ee1a0b0bd957ed3d905052efad13d05e3f6aa756ceb2cbd8',
            announce.last_ping.block_hash)
        self.assertEqual(1530021570, announce.last_ping.sig_time)
        self.assertEqual(
            'HEajdRdRbdZNWe47RIvIr4mT8p3Q4Zg2YCEuhk4owmLPXyIiOmBP/FA8Q8m/dwv0SO/ibAB3ORlE49ls3Cri9gk=',
            base64.b64encode(announce.last_ping.sig).decode('utf-8'))

        self.assertEqual(raw_announce_70210, announce.serialize())
Exemplo n.º 11
0
 def test_get_hash(self):
     announce = MasternodeAnnounce.deserialize(raw_announce)
     expected = 'ef3fe643adc638044b32879bc644a0fb1ebe6ca75281368184c891da9c07986b'
     self.assertEqual(expected, announce.get_hash())
Exemplo n.º 12
0
    def test_verify(self):
        announce = MasternodeAnnounce.deserialize(raw_announce_70210)
        message = announce.serialize_for_sig()

        pk = bitcoin.public_key_to_p2pkh(bfh(announce.collateral_key))
        self.assertTrue(announce.verify())
Exemplo n.º 13
0
 def test_get_hash(self):
     announce = MasternodeAnnounce.deserialize(raw_announce_70210)
     expected = '154f19205294c3c1077d0f34473673998b6f6139209110705cee10d66e7d73af'
     self.assertEqual(expected, announce.get_hash())