From bbe93ae3f141dd483c2407c105c1215928407283 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Thu, 26 Mar 2020 17:13:38 +0100 Subject: [PATCH] Adds RIPMED160 hash function --- common/cryptographer.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/common/cryptographer.py b/common/cryptographer.py index 4a1dbeb..f5427e7 100644 --- a/common/cryptographer.py +++ b/common/cryptographer.py @@ -1,5 +1,5 @@ import pyzbase32 -from hashlib import sha256 +from hashlib import sha256, new from binascii import unhexlify, hexlify from coincurve.utils import int_to_bytes from coincurve import PrivateKey, PublicKey @@ -25,6 +25,24 @@ def sha256d(message): 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): """ Encodes a pk-recoverable signature to be used in LN. ```rsig_rid`` can be obtained trough