Skip to content

Commit

Permalink
functions added: verify_signature, address_from_pubkey
Browse files Browse the repository at this point in the history
this seems to support developers experience: simple SigVerify and independent address from public key generation
  • Loading branch information
vlzhr committed Nov 18, 2019
1 parent 11e6e3f commit 18c4415
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,16 @@ def sign(privateKey, message):
return base58.b58encode(curve.calculateSignature(random64, base58.b58decode(privateKey), message))

def id(message):
return base58.b58encode(hashlib.sha256(message).digest())
return base58.b58encode(hashlib.sha256(message).digest())

def verify_signature(pub_key, message, signature):
""" all of the arguments are expected in a string format """
return curve.verifySignature(base58.b58decode(pub_key), message.encode(), base58.b58decode(signature)) == 0

def address_from_pubkey(public_key):
""" public key is expected as a string """
pubKey = base58.b58decode(public_key)
unhashedAddress = chr(1) + str(pw.CHAIN_ID) + pw.crypto.hashChain(pubKey)[0:20]
addressHash = pw.crypto.hashChain(pw.crypto.str2bytes(unhashedAddress))[0:4]
address = base58.b58encode(pw.crypto.str2bytes(unhashedAddress + addressHash))
return address

0 comments on commit 18c4415

Please sign in to comment.