Adds RIPMED160 hash function

This commit is contained in:
Sergi Delgado Segura
2020-03-26 17:13:38 +01:00
parent b3d67b4ce3
commit bbe93ae3f1

View File

@@ -1,5 +1,5 @@
import pyzbase32 import pyzbase32
from hashlib import sha256 from hashlib import sha256, new
from binascii import unhexlify, hexlify from binascii import unhexlify, hexlify
from coincurve.utils import int_to_bytes from coincurve.utils import int_to_bytes
from coincurve import PrivateKey, PublicKey from coincurve import PrivateKey, PublicKey
@@ -25,6 +25,24 @@ def sha256d(message):
return sha256(sha256(message).digest()).digest() return sha256(sha256(message).digest()).digest()
def hash_160(message):
""" Calculates the RIPEMD-160 hash of a given message.
Args:
message (:obj:`str`) the message to be hashed.
Returns:
:obj:`str`: the ripemd160 hash of the given message.
"""
# Calculate the RIPEMD-160 hash of the given data.
md = new("ripemd160")
md.update(unhexlify(message))
h160 = md.hexdigest()
return h160
def sigrec_encode(rsig_rid): def sigrec_encode(rsig_rid):
""" """
Encodes a pk-recoverable signature to be used in LN. ```rsig_rid`` can be obtained trough Encodes a pk-recoverable signature to be used in LN. ```rsig_rid`` can be obtained trough