electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit fed76bfffcf1b0130f13393c565b27d946872dad
parent e8b564c0e728e1ca15d39f48a0153c984e2acc3c
Author: ThomasV <thomasv@electrum.org>
Date:   Fri, 29 Sep 2017 15:36:01 +0200

Merge branch 'master' of github.com:spesmilo/electrum

Diffstat:
MREADME.rst | 6+++---
Mlib/bitcoin.py | 4++++
Mlib/keystore.py | 4+---
Mlib/tests/test_bitcoin.py | 22+++++++++++++++++++++-
4 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/README.rst b/README.rst @@ -86,16 +86,16 @@ To create binaries, create the 'packages' directory:: This directory contains the python dependencies used by Electrum. -Mac OS X +Mac OS X / macOS -------- :: # On MacPorts installs: - sudo python setup-release.py py2app + sudo python3 setup-release.py py2app # On Homebrew installs: - ARCHFLAGS="-arch i386 -arch x86_64" sudo python setup-release.py py2app --includes sip + ARCHFLAGS="-arch i386 -arch x86_64" sudo python3 setup-release.py py2app --includes sip sudo hdiutil create -fs HFS+ -volname "Electrum" -srcfolder dist/Electrum.app dist/electrum-VERSION-macosx.dmg diff --git a/lib/bitcoin.py b/lib/bitcoin.py @@ -611,6 +611,10 @@ def verify_message(address, sig, message): print_error("Verification error: {0}".format(e)) return False +def sign_message_with_wif_privkey(sec, message): + key = regenerate_key(sec) + compressed = is_compressed(sec) + return key.sign_message(message, compressed) def encrypt_message(message, pubkey): return EC_KEY.encrypt_message(message, bfh(pubkey)) diff --git a/lib/keystore.py b/lib/keystore.py @@ -88,9 +88,7 @@ class Software_KeyStore(KeyStore): def sign_message(self, sequence, message, password): sec = self.get_private_key(sequence, password) - key = regenerate_key(sec) - compressed = is_compressed(sec) - return key.sign_message(message, compressed) + return sign_message_with_wif_privkey(sec, message) def decrypt_message(self, sequence, message, password): sec = self.get_private_key(sequence, password) diff --git a/lib/tests/test_bitcoin.py b/lib/tests/test_bitcoin.py @@ -3,6 +3,7 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals +import base64 import six import unittest import sys @@ -13,7 +14,8 @@ from lib.bitcoin import ( bip32_root, bip32_public_derivation, bip32_private_derivation, pw_encode, pw_decode, Hash, public_key_from_private_key, address_from_private_key, is_address, is_private_key, xpub_from_xprv, is_new_seed, is_old_seed, - var_int, op_push, address_to_script) + var_int, op_push, address_to_script, sign_message_with_wif_privkey, + verify_message) from lib.util import bfh try: @@ -55,6 +57,24 @@ class Test_bitcoin(unittest.TestCase): #print signature EC_KEY.verify_message(eck, signature, message) + def test_msg_signing(self): + msg1 = b'Chancellor on brink of second bailout for banks' + msg2 = b'Electrum' + + sig1 = sign_message_with_wif_privkey( + 'L1TnU2zbNaAqMoVh65Cyvmcjzbrj41Gs9iTLcWbpJCMynXuap6UN', msg1) + sig2 = sign_message_with_wif_privkey( + 'KzyK8J8eQDLdFtd2Cr2K5w5YFKg6EnAudbGahzMvq5dVSpwyheCa', msg2) + + sig1_b64 = base64.b64encode(sig1) + sig2_b64 = base64.b64encode(sig2) + + self.assertEqual(sig1_b64, b'H/9jMOnj4MFbH3d7t4yCQ9i7DgZU/VZ278w3+ySv2F4yIsdqjsc5ng3kmN8OZAThgyfCZOQxZCWza9V5XzlVY0Y=') + self.assertEqual(sig2_b64, b'H/9tRQQ2cB/nv02yj6klatxGnrrDTfslM+0YOoUBHlkvHsAYhx+ldRNAPslSj/VI3nwjP2veNhqqidVlkr7IsFI=') + + self.assertTrue(verify_message('15hETetDmcXm1mM4sEf7U2KXC9hDHFMSzz', sig1, msg1)) + self.assertTrue(verify_message('1LcXfWmCJmvqgpFKDBRhjyN3QqzmawmEAj', sig2, msg2)) + def test_bip32(self): # see https://en.bitcoin.it/wiki/BIP_0032_TestVectors xpub, xprv = self._do_test_bip32("000102030405060708090a0b0c0d0e0f", "m/0'/1/2'/2/1000000000")