Beispiel #1
0
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            'L1TnU2zbNaAqMoVh65Cyvmcjzbrj41Gs9iTLcWbpJCMynXuap6UN', msg1)
        addr1 = '15hETetDmcXm1mM4sEf7U2KXC9hDHFMSzz'
        sig2 = sign_message_with_wif_privkey(
            '5Hxn5C4SQuiV6e62A1MtZmbSeQyrLFhu5uYks62pU5VBUygK2KD', msg2)
        addr2 = '1GPHVTY8UD9my6jyP4tb2TYJwUbDetyNC6'

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        self.assertEqual(sig1_b64, b'Hzsu0U/THAsPz/MSuXGBKSULz2dTfmrg1NsAhFp+wH5aKfmX4Db7ExLGa7FGn0m6Mf43KsbEOWpvUUUBTM3Uusw=')
        self.assertEqual(sig2_b64, b'HBQdYfv7kOrxmRewLJnG7sV6KlU71O04hUnE4tai97p7Pg+D+yKaWXsdGgHTrKw90caQMo/D6b//qX50ge9P9iI=')

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
Beispiel #2
0
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            'L1TnU2zbNaAqMoVh65Cyvmcjzbrj41Gs9iTLcWbpJCMynXuap6UN', msg1)
        addr1 = '15hETetDmcXm1mM4sEf7U2KXC9hDHFMSzz'
        sig2 = sign_message_with_wif_privkey(
            '5Hxn5C4SQuiV6e62A1MtZmbSeQyrLFhu5uYks62pU5VBUygK2KD', msg2)
        addr2 = '1GPHVTY8UD9my6jyP4tb2TYJwUbDetyNC6'

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        self.assertEqual(sig1_b64, b'H/9jMOnj4MFbH3d7t4yCQ9i7DgZU/VZ278w3+ySv2F4yIsdqjsc5ng3kmN8OZAThgyfCZOQxZCWza9V5XzlVY0Y=')
        self.assertEqual(sig2_b64, b'G84dmJ8TKIDKMT9qBRhpX2sNmR0y5t+POcYnFFJCs66lJmAs3T8A6Sbpx7KA6yTQ9djQMabwQXRrDomOkIKGn18=')

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
Beispiel #3
0
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            'L1TnU2zbNaAqMoVh65Cyvmcjzbrj41Gs9iTLcWbpJCMynXuap6UN', msg1)
        addr1 = '15hETetDmcXm1mM4sEf7U2KXC9hDHFMSzz'
        sig2 = sign_message_with_wif_privkey(
            '5Hxn5C4SQuiV6e62A1MtZmbSeQyrLFhu5uYks62pU5VBUygK2KD', msg2)
        addr2 = '1GPHVTY8UD9my6jyP4tb2TYJwUbDetyNC6'

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        self.assertEqual(
            sig1_b64,
            b'H/9jMOnj4MFbH3d7t4yCQ9i7DgZU/VZ278w3+ySv2F4yIsdqjsc5ng3kmN8OZAThgyfCZOQxZCWza9V5XzlVY0Y='
        )
        self.assertEqual(
            sig2_b64,
            b'G84dmJ8TKIDKMT9qBRhpX2sNmR0y5t+POcYnFICUs66lJmAs3T8A6Sbpx7KA6yTQ9djQMabwQXRrDomOkIKGn18='
        )

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(
            addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
Beispiel #4
0
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            'KwqmxP2G5pjqSTTCij6uDp9DDSbYS2Lb49r8hnt7ZYGouje76Ng9', msg1)
        addr1 = 'VR1HHTPq86MCvcNo3eCDxUERzXemxP5rvj'
        sig2 = sign_message_with_wif_privkey(
            'L3n3B8vKzj5GmeykZFpVktpfT6dKi7tZpjtD2QUxQ2rosxoRpMBC', msg2)
        addr2 = 'VLykx31DCZ4CarDoyZgqtZ4DTSweBqv7SJ'

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        self.assertEqual(
            sig1_b64,
            b'IFOdxRPvXomCUEyenrIOAk4OA+xvfe9wYboCNOayTce7fBiuB5AGFGXG+qVFWKzTLezyoauyAboqsVRAtLcD01w='
        )
        self.assertEqual(
            sig2_b64,
            b'H16eV2is7D7pMs9OXgWkAp+9eJJQk9NcyQPB/A6YP/nLefiNRWwYQOtYMJ69WF+fDXszN/ry3ozLNUHL6nk0ouI='
        )

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(
            addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            'Ky9ZiNPrLeKBpLbmmj7fevA7jmj3je87uF5YghBeDJAVdC7hVCsj', msg1)
        addr1 = 'k1GceERXeDFM5Dz8umDPgCb7Yy9AG9amjdj'
        sig2 = sign_message_with_wif_privkey(
            'KxECU4oeJpngze88Zb8qzMDSRTUVXy5AG4sP3RgS9rSfkT8eWTxw', msg2)
        addr2 = 'k1Fhdcy8sY7XgJSLeMpcdyrsiEhjAaCeeAB'

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        self.assertEqual(
            sig1_b64,
            b'H2xHDhY+0uCTElnpnYNHhksaRKMTWNwwKGJ0ed34H29eRSsMl6pGidRTKhTnQuZ1jLzWzwX7XKJXYgKYJu/OnEc='
        )
        self.assertEqual(
            sig2_b64,
            b'IB3+kdxVqziwOcmJUAL4b15p3PQvJd8aWsHAJKfcs8iqD30uz2Z88UL0WWU0Q1o/uA0JUU6qK3zBI1caJsmZHG8='
        )

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(
            addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
    def test_msg_signing(self):
        msg1 = b'wakiyama tamami chan'
        msg2 = b'tottemo kawaii'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            'T8UqLXgii9iBbQAoypL8Yz7Zta7w8QTt2qq66ViLSGXGQCGbo7rv', msg1)
        addr1 = 'MRHx4jW2KAQeEDMuK7pGLUGWvPRQT1Epmj'
        sig2 = sign_message_with_wif_privkey(
            'T3o9vVd82bASRouYDpSHo2KyFR82LB7FezpZAFDpLcbNd7AGuEJQ', msg2)
        addr2 = 'MLBCmvG4A7AqCD6MMYjf7YdV96YK5teZ5N'

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        self.assertEqual(sig1_b64, b'IDldTozCVViZ/m/gzvSf6EmZZ3ItDdM+RsI4PAxZdsb6ZQUmv3IgaJK+U4naOExaoTIVn0IY3Hoky0MWFAO6ac4=')
        self.assertEqual(sig2_b64, b'IOr6v1UPcFEoeon11dPNo+TbbLuAu8k8ccG527zmmDf/a26W6z+yAbsfTt01PKF7/UGhwJeCwybdnRXpPC2x4Hk=')

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            'L4wEdaVMPietaMiMikisy92PovAzy2Z4zroDXP3cm9Rb8rzcEUbg', msg1)
        addr1 = 'ZrkMRXJ2izfuVQYuggQhwh3fMhJnqTMaVN'
        sig2 = sign_message_with_wif_privkey(
            'KweGsZLptDsKGPvsWkVLJkuWtTgKHHgxYiNyWuZQjoTzBxmVaSFz', msg2)
        addr2 = 'ZzDD6zYb7VrKChhZ9Ric1HvFBUoy8xb1Hr'

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        self.assertEqual(
            sig1_b64,
            b'H7rYMRe0AArej5m8ly7ZmYTo+8HJwIA8IWzUbrROu8QdPyF3c/YHd1GrnT2z2R7VPsHMgU0y0I5pQIt8cfb5e88='
        )
        self.assertEqual(
            sig2_b64,
            b'H/nqcaAudmTSpZxrxndxUbGYN2QWc3wc15Keia2yCDnpT4pIQ+Vfsu4njUf80oRlOJ60FGx7htMmLyJymn/MhQw='
        )

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(
            addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
Beispiel #8
0
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            'N5acUJ3Bpizm13gSq8jV5CwZUgfrjs53RuBASsT9AtuwjAgetARW', msg1)
        addr1 = '6iRgFB4Fi922TqJHD7KaFn8Y1DJRHNy9BL'
        sig2 = sign_message_with_wif_privkey(
            '5mBCYSLtLsBez8Dtr83svFzHU1buS7WA6rYGHBfNPFacPfYWwuT', msg2)
        addr2 = '6u7jGyiAQje3RAhBiwZ3pDMKkYCRXuLu76'

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        self.assertEqual(
            sig1_b64,
            b'H0YLLJku6jqtfMAiDHHlY9Dr7blntXd0T7CPGLfKm0XtWjleM+DJ5HCgRs55EdQsj6KL0v0TjsuVI7Ij3//X84E='
        )
        self.assertEqual(
            sig2_b64,
            b'GweSYB1TXaNWFIo4eOGDLUvtvMcAB5rwXDGQIm3al/22PsERMOLz+pl1fjuV4zCBI7ERqPHfmXZxF3G+3UZyBuQ='
        )

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(
            addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
    def sign_message(self, sequence, message, password):
        sig = None
        try:
            message = message.encode('utf8')
            inputPath = self.get_derivation() + "/%d/%d" % sequence
            msg_hash = Hash(msg_magic(message))
            inputHash = to_hexstr(msg_hash)
            hasharray = []
            hasharray.append({'hash': inputHash, 'keypath': inputPath})
            hasharray = json.dumps(hasharray)

            msg = ('{"sign":{"meta":"sign message", "data":%s}}' % hasharray).encode('utf8')

            dbb_client = self.plugin.get_client(self)

            if not dbb_client.is_paired():
                raise Exception(_("Could not sign message."))

            reply = dbb_client.hid_send_encrypt(msg)
            self.handler.show_message(_("Signing message ...") + "\n\n" +
                                      _("To continue, touch the Digital Bitbox's blinking light for 3 seconds.") + "\n\n" +
                                      _("To cancel, briefly touch the blinking light or wait for the timeout."))
            reply = dbb_client.hid_send_encrypt(msg) # Send twice, first returns an echo for smart verification (not implemented)
            self.handler.finished()

            if 'error' in reply:
                raise Exception(reply['error']['message'])

            if 'sign' not in reply:
                raise Exception(_("Could not sign message."))

            if 'recid' in reply['sign'][0]:
                # firmware > v2.1.1
                sig_string = binascii.unhexlify(reply['sign'][0]['sig'])
                recid = int(reply['sign'][0]['recid'], 16)
                sig = ecc.construct_sig65(sig_string, recid, True)
                pubkey, compressed = ecc.ECPubkey.from_signature65(sig, msg_hash)
                addr = public_key_to_p2pkh(pubkey.get_public_key_bytes(compressed=compressed))
                if ecc.verify_message_with_address(addr, sig, message) is False:
                    raise Exception(_("Could not sign message"))
            elif 'pubkey' in reply['sign'][0]:
                # firmware <= v2.1.1
                for recid in range(4):
                    sig_string = binascii.unhexlify(reply['sign'][0]['sig'])
                    sig = ecc.construct_sig65(sig_string, recid, True)
                    try:
                        addr = public_key_to_p2pkh(binascii.unhexlify(reply['sign'][0]['pubkey']))
                        if ecc.verify_message_with_address(addr, sig, message):
                            break
                    except Exception:
                        continue
                else:
                    raise Exception(_("Could not sign message"))


        except BaseException as e:
            self.give_error(e)
        return sig
Beispiel #10
0
    def sign_message(self, sequence, message, password):
        sig = None
        try:
            message = message.encode('utf8')
            inputPath = self.get_derivation() + "/%d/%d" % sequence
            msg_hash = sha256d(msg_magic(message))
            inputHash = to_hexstr(msg_hash)
            hasharray = []
            hasharray.append({'hash': inputHash, 'keypath': inputPath})
            hasharray = json.dumps(hasharray)

            msg = ('{"sign":{"meta":"sign message", "data":%s}}' % hasharray).encode('utf8')

            dbb_client = self.plugin.get_client(self)

            if not dbb_client.is_paired():
                raise Exception(_("Could not sign message."))

            reply = dbb_client.hid_send_encrypt(msg)
            self.handler.show_message(_("Signing message ...") + "\n\n" +
                                      _("To continue, touch the Digital Bitbox's blinking light for 3 seconds.") + "\n\n" +
                                      _("To cancel, briefly touch the blinking light or wait for the timeout."))
            reply = dbb_client.hid_send_encrypt(msg) # Send twice, first returns an echo for smart verification (not implemented)
            self.handler.finished()

            if 'error' in reply:
                raise Exception(reply['error']['message'])

            if 'sign' not in reply:
                raise Exception(_("Could not sign message."))

            if 'recid' in reply['sign'][0]:
                # firmware > v2.1.1
                sig_string = binascii.unhexlify(reply['sign'][0]['sig'])
                recid = int(reply['sign'][0]['recid'], 16)
                sig = ecc.construct_sig65(sig_string, recid, True)
                pubkey, compressed = ecc.ECPubkey.from_signature65(sig, msg_hash)
                addr = public_key_to_p2pkh(pubkey.get_public_key_bytes(compressed=compressed))
                if ecc.verify_message_with_address(addr, sig, message) is False:
                    raise Exception(_("Could not sign message"))
            elif 'pubkey' in reply['sign'][0]:
                # firmware <= v2.1.1
                for recid in range(4):
                    sig_string = binascii.unhexlify(reply['sign'][0]['sig'])
                    sig = ecc.construct_sig65(sig_string, recid, True)
                    try:
                        addr = public_key_to_p2pkh(binascii.unhexlify(reply['sign'][0]['pubkey']))
                        if ecc.verify_message_with_address(addr, sig, message):
                            break
                    except Exception:
                        continue
                else:
                    raise Exception(_("Could not sign message"))


        except BaseException as e:
            self.give_error(e)
        return sig
Beispiel #11
0
 async def get_update_info(self):
     async with make_aiohttp_session(
             proxy=self.main_window.network.proxy) as session:
         async with session.get(UpdateCheck.url) as result:
             signed_version_dict = await result.json(content_type=None)
             # example signed_version_dict:
             # {
             #     "version": "3.9.9",
             #     "signatures": {
             #         "1Lqm1HphuhxKZQEawzPse8gJtgjm9kUKT4": "IA+2QG3xPRn4HAIFdpu9eeaCYC7S5wS/sDxn54LJx6BdUTBpse3ibtfq8C43M7M1VfpGkD5tsdwl5C6IfpZD/gQ="
             #     }
             # }
             version_num = signed_version_dict['version']
             sigs = signed_version_dict['signatures']
             for address, sig in sigs.items():
                 if address not in UpdateCheck.VERSION_ANNOUNCEMENT_SIGNING_KEYS:
                     continue
                 sig = base64.b64decode(sig)
                 msg = version_num.encode('utf-8')
                 if ecc.verify_message_with_address(
                         address=address,
                         sig65=sig,
                         message=msg,
                         net=constants.BitcoinMainnet):
                     self.print_error(
                         f"valid sig for version announcement '{version_num}' from address '{address}'"
                     )
                     break
             else:
                 raise Exception(
                     'no valid signature for version announcement')
             return StrictVersion(version_num.strip())
 async def get_update_info(self):
     # note: Use long timeout here as it is not critical that we get a response fast,
     #       and it's bad not to get an update notification just because we did not wait enough.
     async with make_aiohttp_session(proxy=self.network.proxy,
                                     timeout=120) as session:
         async with session.get(UpdateCheck.url) as result:
             signed_version_dict = await result.json(content_type=None)
             # example signed_version_dict:
             # {
             #     "version": "3.9.9",
             #     "signatures": {
             #         "1Lqm1HphuhxKZQEawzPse8gJtgjm9kUKT4": "IA+2QG3xPRn4HAIFdpu9eeaCYC7S5wS/sDxn54LJx6BdUTBpse3ibtfq8C43M7M1VfpGkD5tsdwl5C6IfpZD/gQ="
             #     }
             # }
             version_num = signed_version_dict['version']
             sigs = signed_version_dict['signatures']
             for address, sig in sigs.items():
                 if address not in VERSION_ANNOUNCEMENT_SIGNING_KEYS:
                     continue
                 sig = base64.b64decode(sig)
                 msg = version_num.encode('utf-8')
                 if ecc.verify_message_with_address(
                         address=address,
                         sig65=sig,
                         message=msg,
                         net=constants.RavencoinMainnet):
                     self.logger.info(
                         f"valid sig for version announcement '{version_num}' from address '{address}'"
                     )
                     break
             else:
                 raise Exception(
                     'no valid signature for version announcement')
             return StrictVersion(version_num.strip())
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            frombtc('L1TnU2zbNaAqMoVh65Cyvmcjzbrj41Gs9iTLcWbpJCMynXuap6UN'),
            msg1)
        addr1 = frombtc('15hETetDmcXm1mM4sEf7U2KXC9hDHFMSzz')
        sig2 = sign_message_with_wif_privkey(
            frombtc('5Hxn5C4SQuiV6e62A1MtZmbSeQyrLFhu5uYks62pU5VBUygK2KD'),
            msg2)
        addr2 = frombtc('1GPHVTY8UD9my6jyP4tb2TYJwUbDetyNC6')

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        # Re-signed these with Xaya Core, since the upstream Namecoin ones are invalid for Xaya's msg_magic.
        self.assertEqual(
            sig1_b64,
            b'H8FU6ku4jO82lAtIVxT2nEl++MKMe0N+lcOStNQAhcGZV8MGqeWkxSvcUZSl0YAexEZG5qlMs289V+RV6qyQV7k='
        )
        self.assertEqual(
            sig2_b64,
            b'G7CwmsisI1gzC06FPrROr37S0CLiKvxkIYB7issD2mTdLCIf/iRMgFOu16v978Qgc6awdZLUjMOZw1I7WKNmKms='
        )

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(
            addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
Beispiel #14
0
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            frombtc('L1TnU2zbNaAqMoVh65Cyvmcjzbrj41Gs9iTLcWbpJCMynXuap6UN'),
            msg1)
        addr1 = frombtc('15hETetDmcXm1mM4sEf7U2KXC9hDHFMSzz')
        sig2 = sign_message_with_wif_privkey(
            frombtc('5Hxn5C4SQuiV6e62A1MtZmbSeQyrLFhu5uYks62pU5VBUygK2KD'),
            msg2)
        addr2 = frombtc('1GPHVTY8UD9my6jyP4tb2TYJwUbDetyNC6')

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        # Re-signed these with Namecoin Core, since the upstream Electrum ones are invalid for Namecoin's msg_magic.
        self.assertEqual(
            sig1_b64,
            b'IKqxjcFykcFJPUsIJtUvR5901nJnD/WN326bDVHqnvxjX6+E/mXH9FY+MNpNyl/liXQDhd53BihaVH2lOGknzFU='
        )
        self.assertEqual(
            sig2_b64,
            b'HMBdVzZJfSqhGsrJ6NgUoLUxPmTS0NSxA2Y/q3Te69MVNtt4aWbJORq+0MCllDfqiKo9IIaWpSmXk0VXlaIMxx4='
        )

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(
            addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
Beispiel #15
0
    def test_msg_signing(self):
        msg1 = b'Chancellor on brink of second bailout for banks'
        msg2 = b'Electrum'

        def sign_message_with_wif_privkey(wif_privkey, msg):
            txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
            key = ecc.ECPrivkey(privkey)
            return key.sign_message(msg, compressed)

        sig1 = sign_message_with_wif_privkey(
            #'L1TnU2zbNaAqMoVh65Cyvmcjzbrj41Gs9iTLcWbpJCMynXuap6UN', msg1)
            # Converted to Namecoin using `contrib/convertAddress.py` from Namecoin Core.
            'ThcaCRjNUZoz2iBdr1jRKpY4wCJeTmNfcgr7i8cjq5YzRkJND5Cr', msg1)
        #addr1 = '15hETetDmcXm1mM4sEf7U2KXC9hDHFMSzz'
        # Converted to Namecoin using `contrib/convertAddress.py` from Namecoin Core.
        addr1 = 'N1GbfJPCgzdKYJba93yggYURvP6GFAr31b'
        sig2 = sign_message_with_wif_privkey(
            #'5Hxn5C4SQuiV6e62A1MtZmbSeQyrLFhu5uYks62pU5VBUygK2KD', msg2)
            # Converted to Namecoin using `contrib/convertAddress.py` from Namecoin Core.
            '733VFFQ6j2tG7JJhJ9drASmiGM1C8sXS19EMYsoSA9qM9KD7Kx8', msg2)
        #addr2 = '1GPHVTY8UD9my6jyP4tb2TYJwUbDetyNC6'
        # Converted to Namecoin using `contrib/convertAddress.py` from Namecoin Core.
        addr2 = 'NBxeh737PbFLVdzUetDAEyhDfhzGaNr6y6'

        sig1_b64 = base64.b64encode(sig1)
        sig2_b64 = base64.b64encode(sig2)

        # Re-signed these with Namecoin Core, since the upstream Electrum ones are invalid for Namecoin's msg_magic.
        self.assertEqual(sig1_b64, b'IKqxjcFykcFJPUsIJtUvR5901nJnD/WN326bDVHqnvxjX6+E/mXH9FY+MNpNyl/liXQDhd53BihaVH2lOGknzFU=')
        self.assertEqual(sig2_b64, b'HMBdVzZJfSqhGsrJ6NgUoLUxPmTS0NSxA2Y/q3Te69MVNtt4aWbJORq+0MCllDfqiKo9IIaWpSmXk0VXlaIMxx4=')

        self.assertTrue(ecc.verify_message_with_address(addr1, sig1, msg1))
        self.assertTrue(ecc.verify_message_with_address(addr2, sig2, msg2))

        self.assertFalse(ecc.verify_message_with_address(addr1, b'wrong', msg1))
        self.assertFalse(ecc.verify_message_with_address(addr1, sig2, msg1))
 def verify(self, message, signature):
     message = message.toPlainText().strip().encode('utf-8')
     verified = False
     for address in VERSION_ANNOUNCEMENT_SIGNING_KEYS:
         try:
             # This can throw on invalid base64
             sig = base64.b64decode(str(signature.toPlainText()))
             verified = ecc.verify_message_with_address(
                 address, sig, message, net=constants.RavencoinMainnet)
             break
         except:
             pass
     if verified:
         self.message.setText(_("Signature verified"))
         self.message.setStyleSheet(ColorScheme.GREEN.as_stylesheet())
     else:
         self.message.setText(_("Wrong signature"))
         self.message.setStyleSheet(ColorScheme.RED.as_stylesheet())
 def verify_mapping_sig(self):
     nsig = len(self.amap["sigs"])
     if nsig < self.amap["n"]:
         return False
     jsonstring = json.dumps(self.amap["assets"],sort_keys=True)
     jsonstring += str(self.amap["n"]) + str(self.amap["m"]) + str(self.amap["time"]) + str(self.amap["height"])
     message = jsonstring.encode('utf-8')
     nvalid = 0
     for key in self.controller_pubkeys:
         for i,j in self.amap["sigs"].items():
             txin_type = 'p2pkh'
             address = bitcoin.pubkey_to_address(txin_type, key)
             sig = base64.b64decode(j)
             verified = ecc.verify_message_with_address(address, sig, message)
             if verified: nvalid += 1
     if nvalid >= self.amap["n"]:
         return True
     else:
         return False