mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-27 23:41:35 +00:00
simplify: public_key_from_private_key
This commit is contained in:
parent
4869d05841
commit
799c6571f5
2 changed files with 10 additions and 12 deletions
|
@ -244,18 +244,18 @@ def is_compressed(sec):
|
||||||
return len(b) == 33
|
return len(b) == 33
|
||||||
|
|
||||||
|
|
||||||
def address_from_private_key(sec):
|
def public_key_from_private_key(sec):
|
||||||
# rebuild public key from private key, compressed or uncompressed
|
# rebuild public key from private key, compressed or uncompressed
|
||||||
pkey = regenerate_key(sec)
|
pkey = regenerate_key(sec)
|
||||||
assert pkey
|
assert pkey
|
||||||
|
|
||||||
# figure out if private key is compressed
|
|
||||||
compressed = is_compressed(sec)
|
compressed = is_compressed(sec)
|
||||||
|
|
||||||
# rebuild private and public key from regenerated secret
|
|
||||||
private_key = GetPrivKey(pkey, compressed)
|
|
||||||
public_key = GetPubKey(pkey.pubkey, compressed)
|
public_key = GetPubKey(pkey.pubkey, compressed)
|
||||||
address = public_key_to_bc_address(public_key)
|
return public_key.encode('hex')
|
||||||
|
|
||||||
|
|
||||||
|
def address_from_private_key(sec):
|
||||||
|
public_key = public_key_from_private_key(sec)
|
||||||
|
address = public_key_to_bc_address(public_key.decode('hex'))
|
||||||
return address
|
return address
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -363,10 +363,8 @@ class Wallet:
|
||||||
# build a list of public/private keys
|
# build a list of public/private keys
|
||||||
keypairs = {}
|
keypairs = {}
|
||||||
for sec in private_keys:
|
for sec in private_keys:
|
||||||
compressed = is_compressed(sec)
|
pubkey = public_key_from_private_key(sec)
|
||||||
pkey = regenerate_key(sec)
|
keypairs[ pubkey ] = sec
|
||||||
pubkey = GetPubKey(pkey.pubkey, compressed)
|
|
||||||
keypairs[ pubkey.encode('hex') ] = sec
|
|
||||||
|
|
||||||
|
|
||||||
for txin in tx.inputs:
|
for txin in tx.inputs:
|
||||||
|
@ -404,10 +402,10 @@ class Wallet:
|
||||||
addr = hash_160_to_bc_address(hash_160(redeem_script.decode('hex')), 5)
|
addr = hash_160_to_bc_address(hash_160(redeem_script.decode('hex')), 5)
|
||||||
txin['address'] = addr
|
txin['address'] = addr
|
||||||
|
|
||||||
|
|
||||||
elif txin.get("raw_output_script"):
|
elif txin.get("raw_output_script"):
|
||||||
addr = deserialize.get_address_from_output_script(txin.get("raw_output_script").decode('hex'))
|
addr = deserialize.get_address_from_output_script(txin.get("raw_output_script").decode('hex'))
|
||||||
sec = self.get_private_key(addr, password)
|
sec = self.get_private_key(addr, password)
|
||||||
|
pubkey = public_key_from_private_key(sec)
|
||||||
if sec:
|
if sec:
|
||||||
keypairs[pubkey] = [sec]
|
keypairs[pubkey] = [sec]
|
||||||
txin['address'] = addr
|
txin['address'] = addr
|
||||||
|
|
Loading…
Add table
Reference in a new issue