Browse Source

simplification: hex encode master_public_key directly

283
thomasv 12 years ago
parent
commit
da4b974dfd
  1. 2
      lib/gui_lite.py
  2. 10
      lib/wallet.py
  3. 5
      scripts/merchant.py

2
lib/gui_lite.py

@ -749,7 +749,7 @@ class MiniActuator:
return self.wallet.is_valid(address) return self.wallet.is_valid(address)
def acceptbit(self, currency): def acceptbit(self, currency):
master_pubkey = self.wallet.master_public_key.encode("hex") master_pubkey = self.wallet.master_public_key
url = "http://acceptbit.com/mpk/%s/%s" % (master_pubkey, currency) url = "http://acceptbit.com/mpk/%s/%s" % (master_pubkey, currency)
webbrowser.open(url) webbrowser.open(url)

10
lib/wallet.py

@ -270,7 +270,7 @@ class Wallet:
self.use_change = config.get('use_change',True) self.use_change = config.get('use_change',True)
self.fee = int(config.get('fee',100000)) self.fee = int(config.get('fee',100000))
self.num_zeros = int(config.get('num_zeros',0)) self.num_zeros = int(config.get('num_zeros',0))
self.master_public_key = config.get('master_public_key','').decode('hex') self.master_public_key = config.get('master_public_key','')
self.use_encryption = config.get('use_encryption', False) self.use_encryption = config.get('use_encryption', False)
self.addresses = config.get('addresses', []) # receiving addresses visible for user self.addresses = config.get('addresses', []) # receiving addresses visible for user
self.change_addresses = config.get('change_addresses', []) # addresses used as change self.change_addresses = config.get('change_addresses', []) # addresses used as change
@ -347,7 +347,7 @@ class Wallet:
curve = SECP256k1 curve = SECP256k1
secexp = self.stretch_key(seed) secexp = self.stretch_key(seed)
master_private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve = SECP256k1 ) master_private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve = SECP256k1 )
self.master_public_key = master_private_key.get_verifying_key().to_string() self.master_public_key = master_private_key.get_verifying_key().to_string().encode('hex')
def all_addresses(self): def all_addresses(self):
return self.addresses + self.change_addresses + self.imported_keys.keys() return self.addresses + self.change_addresses + self.imported_keys.keys()
@ -374,7 +374,7 @@ class Wallet:
return string_to_number( seed ) return string_to_number( seed )
def get_sequence(self,n,for_change): def get_sequence(self,n,for_change):
return string_to_number( Hash( "%d:%d:"%(n,for_change) + self.master_public_key ) ) return string_to_number( Hash( "%d:%d:"%(n,for_change) + self.master_public_key.decode('hex') ) )
def get_private_key_base58(self, address, password): def get_private_key_base58(self, address, password):
pk = self.get_private_key(address, password) pk = self.get_private_key(address, password)
@ -488,7 +488,7 @@ class Wallet:
""" Publickey(type,n) = Master_public_key + H(n|S|type)*point """ """ Publickey(type,n) = Master_public_key + H(n|S|type)*point """
curve = SECP256k1 curve = SECP256k1
z = self.get_sequence(n, for_change) z = self.get_sequence(n, for_change)
master_public_key = ecdsa.VerifyingKey.from_string( self.master_public_key, curve = SECP256k1 ) master_public_key = ecdsa.VerifyingKey.from_string( self.master_public_key.decode('hex'), curve = SECP256k1 )
pubkey_point = master_public_key.pubkey.point + z*curve.generator pubkey_point = master_public_key.pubkey.point + z*curve.generator
public_key2 = ecdsa.VerifyingKey.from_public_point( pubkey_point, curve = SECP256k1 ) public_key2 = ecdsa.VerifyingKey.from_public_point( pubkey_point, curve = SECP256k1 )
address = public_key_to_bc_address( '04'.decode('hex') + public_key2.to_string() ) address = public_key_to_bc_address( '04'.decode('hex') + public_key2.to_string() )
@ -1009,7 +1009,7 @@ class Wallet:
'seed_version': self.seed_version, 'seed_version': self.seed_version,
'use_encryption': self.use_encryption, 'use_encryption': self.use_encryption,
'use_change': self.use_change, 'use_change': self.use_change,
'master_public_key': self.master_public_key.encode('hex'), 'master_public_key': self.master_public_key,
'fee': self.fee, 'fee': self.fee,
'seed': self.seed, 'seed': self.seed,
'addresses': self.addresses, 'addresses': self.addresses,

5
scripts/merchant.py

@ -33,7 +33,6 @@ db_password = config.get('db','password')
db_name = config.get('db','name') db_name = config.get('db','name')
electrum_server = config.get('electrum','server') electrum_server = config.get('electrum','server')
mpk = config.get('electrum','mpk')
my_password = config.get('main','password') my_password = config.get('main','password')
my_host = config.get('main','host') my_host = config.get('main','host')
@ -44,7 +43,7 @@ cb_expired = config.get('callback','expired')
cb_password = config.get('callback','password') cb_password = config.get('callback','password')
wallet = Wallet() wallet = Wallet()
wallet.master_public_key = mpk.decode('hex') wallet.master_public_key = config.get('electrum','mpk')
@ -114,7 +113,7 @@ def process_request(i, amount, confirmations, expires_in, password):
return addr return addr
def get_mpk(): def get_mpk():
return wallet.master_public_key.encode('hex') return wallet.master_public_key
def server_thread(conn): def server_thread(conn):

Loading…
Cancel
Save