Beispiel #1
0
    def _do_test_crypto(self, message):
        G = ecc.generator()
        _r = G.order()
        pvk = ecdsa.util.randrange(_r)

        Pub = pvk * G
        pubkey_c = Pub.get_public_key_bytes(True)
        #pubkey_u = point_to_ser(Pub,False)
        addr_c = public_key_to_p2pkh(pubkey_c)

        #print "Private key            ", '%064x'%pvk
        eck = ecc.ECPrivkey(number_to_string(pvk, _r))

        #print "Compressed public key  ", pubkey_c.encode('hex')
        enc = ecc.ECPubkey(pubkey_c).encrypt_message(message)
        dec = eck.decrypt_message(enc)
        self.assertEqual(message, dec)

        #print "Uncompressed public key", pubkey_u.encode('hex')
        #enc2 = EC_KEY.encrypt_message(message, pubkey_u)
        dec2 = eck.decrypt_message(enc)
        self.assertEqual(message, dec2)

        signature = eck.sign_message(message, True)
        #print signature
        eck.verify_message_for_address(signature, message)
Beispiel #2
0
 def test_public_key_from_private_key(self):
     for priv_details in self.priv_pub_addr:
         txin_type, privkey, compressed = deserialize_privkey(
             priv_details['priv'])
         result = ecc.ECPrivkey(privkey).get_public_key_hex(
             compressed=compressed)
         self.assertEqual(priv_details['pub'], result)
         self.assertEqual(priv_details['txin_type'], txin_type)
         self.assertEqual(priv_details['compressed'], compressed)
Beispiel #3
0
    def test_sign_transaction(self):
        eckey1 = ecc.ECPrivkey(
            bfh('7e1255fddb52db1729fc3ceb21a46f95b8d9fe94cc83425e936a6c5223bb679d'
                ))
        sig1 = eckey1.sign_transaction(
            bfh('5a548b12369a53faaa7e51b5081829474ebdd9c924b3a8230b69aa0be254cd94'
                ))
        self.assertEqual(
            bfh('3045022100902a288b98392254cd23c0e9a49ac6d7920f171b8249a48e484b998f1874a2010220723d844826828f092cf400cb210c4fa0b8cd1b9d1a7f21590e78e022ff6476b9'
                ), sig1)

        eckey2 = ecc.ECPrivkey(
            bfh('c7ce8c1462c311eec24dff9e2532ac6241e50ae57e7d1833af21942136972f23'
                ))
        sig2 = eckey2.sign_transaction(
            bfh('642a2e66332f507c92bda910158dfe46fc10afbf72218764899d3af99a043fac'
                ))
        self.assertEqual(
            bfh('30440220618513f4cfc87dde798ce5febae7634c23e7b9254a1eabf486be820f6a7c2c4702204fef459393a2b931f949e63ced06888f35e286e446dc46feb24b5b5f81c6ed52'
                ), sig2)
Beispiel #4
0
    def on_receive(self, keyhash, message):
        self.print_error("signal arrived for", keyhash)
        for key, _hash, window in self.keys:
            if _hash == keyhash:
                break
        else:
            self.print_error("keyhash not found")
            return

        wallet = window.wallet
        if isinstance(wallet.keystore, keystore.Hardware_KeyStore):
            window.show_warning(
                _('An encrypted transaction was retrieved from cosigning pool.'
                  ) + '\n' +
                _('However, hardware wallets do not support message decryption, '
                  'which makes them not compatible with the current design of cosigner pool.'
                  ))
            return
        elif wallet.has_keystore_encryption():
            password = window.password_dialog(
                _('An encrypted transaction was retrieved from cosigning pool.'
                  ) + '\n' + _('Please enter your password to decrypt it.'))
            if not password:
                return
        else:
            password = None
            if not window.question(
                    _("An encrypted transaction was retrieved from cosigning pool."
                      ) + '\n' + _("Do you want to open it now?")):
                return

        xprv = wallet.keystore.get_master_private_key(password)
        if not xprv:
            return
        try:
            k = bitcoin.deserialize_xprv(xprv)[-1]
            EC = ecc.ECPrivkey(k)
            message = bh2u(EC.decrypt_message(message))
        except Exception as e:
            traceback.print_exc(file=sys.stdout)
            window.show_error(_('Error decrypting message') + ':\n' + str(e))
            return

        self.listener.clear(keyhash)
        tx = transaction.Transaction(message)
        show_transaction(tx, window, prompt_if_unsaved=True)
Beispiel #5
0
 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)