tsimplify get_private_key, use base58 - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 76439beec53e545ef33f083a0c98f27a867ff732 DIR parent 5d6496f1f920aa70b129f1e54321ddd59c766b51 HTML Author: thomasv <thomasv@gitorious> Date: Fri, 22 Feb 2013 17:27:19 +0100 simplify get_private_key, use base58 Diffstat: M electrum | 6 +++--- M lib/gui_qt.py | 4 ++-- M lib/wallet.py | 36 +++++++++---------------------- 3 files changed, 15 insertions(+), 31 deletions(-) --- DIR diff --git a/electrum b/electrum t@@ -561,7 +561,7 @@ if __name__ == '__main__': else: b='' m_addr = "%34s"%addr if options.show_keys: - m_addr += ':' + str(wallet.get_private_key_base58(addr, password)) + m_addr += ':' + str(wallet.get_private_key(addr, password)) print_msg(flags, m_addr, b, label) if cmd == 'history': t@@ -703,7 +703,7 @@ if __name__ == '__main__': elif cmd == 'dumpprivkey': addr = args[1] - sec = wallet.get_private_key_base58(addr, password) + sec = wallet.get_private_key(addr, password) print_msg( sec ) t@@ -770,7 +770,7 @@ if __name__ == '__main__': if not private_keys: for txin in tx.inputs: addr = txin['address'] - private_keys[addr] = wallet.get_private_key_base58(addr, password) + private_keys[addr] = wallet.get_private_key(addr, password) else: pk = {} for sec in private_keys: DIR diff --git a/lib/gui_qt.py b/lib/gui_qt.py t@@ -1456,7 +1456,7 @@ class ElectrumWindow(QMainWindow): password = None try: - pk = self.wallet.get_private_key_base58(address, password) + pk = self.wallet.get_private_key(address, password) except BaseException, e: self.show_message(str(e)) return t@@ -1748,7 +1748,7 @@ class ElectrumWindow(QMainWindow): for addr in self.wallet.all_addresses(): m_addr = "%34s"%addr - transaction.writerow([m_addr, str(self.wallet.get_private_key_base58(addr, password))]) + transaction.writerow([m_addr, str(self.wallet.get_private_key(addr, password))]) self.show_message(_("Private keys exported.")) DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -174,23 +174,14 @@ class Wallet: def get_sequence(self,n,for_change): return string_to_number( Hash( "%d:%d:"%(n,for_change) + self.master_public_key.decode('hex') ) ) - def get_private_key_base58(self, address, password): - secexp, compressed = self.get_private_key(address, password) - if secexp is None: return None - pk = number_to_string( secexp, generator_secp256k1.order() ) - return SecretToASecret( pk, compressed ) - def get_private_key(self, address, password): """ Privatekey(type,n) = Master_private_key + H(n|S|type) """ - order = generator_secp256k1.order() - + + # decode seed in any case, in order to make test the password + seed = self.decode_seed(password) + if address in self.imported_keys.keys(): - sec = self.pw_decode( self.imported_keys[address], password ) - if not sec: return None, None - pkey = regenerate_key(sec) - compressed = is_compressed(sec) - secexp = pkey.secret - + return self.pw_decode( self.imported_keys[address], password ) else: if address in self.addresses: n = self.addresses.index(address) t@@ -201,23 +192,16 @@ class Wallet: else: raise BaseException("unknown address", address) - seed = self.pw_decode( self.seed, password) - if not seed: return None + order = generator_secp256k1.order() secexp = self.stretch_key(seed) secexp = ( secexp + self.get_sequence(n,for_change) ) % order + pk = number_to_string( secexp, generator_secp256k1.order() ) compressed = False - pkey = EC_KEY(secexp) - - public_key = GetPubKey(pkey.pubkey, compressed) - addr = public_key_to_bc_address(public_key) - if addr != address: - print_error('Invalid password with correct decoding') - raise BaseException('Invalid password') + return SecretToASecret( pk, compressed ) - return secexp, compressed def sign_message(self, address, message, password): - sec = self.get_private_key_base58(address, password) + sec = self.get_private_key(address, password) key = regenerate_key(sec) compressed = is_compressed(sec) return key.sign_message(message, compressed, address) t@@ -762,7 +746,7 @@ class Wallet: private_keys = {} for txin in tx.inputs: addr = txin['address'] - sec = self.get_private_key_base58(addr, password) + sec = self.get_private_key(addr, password) private_keys[addr] = sec tx.sign(private_keys) return str(tx)