diff --git a/bin/lib/ail_core.py b/bin/lib/ail_core.py index 1af20e30..7aea993e 100755 --- a/bin/lib/ail_core.py +++ b/bin/lib/ail_core.py @@ -74,7 +74,7 @@ def get_object_all_subtypes(obj_type): # TODO Dynamic subtype if obj_type == 'chat-thread': return r_object.smembers(f'all_chat-thread:subtypes') if obj_type == 'cryptocurrency': - return ['bitcoin', 'bitcoin-cash', 'dash', 'ethereum', 'litecoin', 'monero', 'tron', 'zcash'] + return ['bitcoin', 'bitcoin-cash', 'dash', 'ethereum', 'litecoin', 'monero', 'ripple', 'tron', 'zcash'] if obj_type == 'pgp': return ['key', 'mail', 'name'] if obj_type == 'username': diff --git a/bin/lib/objects/CryptoCurrencies.py b/bin/lib/objects/CryptoCurrencies.py index 0e048927..d85d9870 100755 --- a/bin/lib/objects/CryptoCurrencies.py +++ b/bin/lib/objects/CryptoCurrencies.py @@ -22,6 +22,7 @@ baseurl = config_loader.get_config_str("Notifications", "ail_domain") config_loader = None digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' +digits58_ripple = 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz' digits32 = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l' @@ -56,7 +57,6 @@ def decode_base58(bc, length): n = n * 58 + digits58.index(char) return n.to_bytes(length, 'big') - # http://rosettacode.org/wiki/Bitcoin/address_validation#Python def check_base58_address(bc): try: @@ -65,6 +65,19 @@ def check_base58_address(bc): except Exception: return False +def decode_base58_ripple(bc, length): + n = 0 + for char in bc: + n = n * 58 + digits58_ripple.index(char) + return n.to_bytes(length, 'big') + +def check_base58_ripple_address(bc): + try: + bcbytes = decode_base58_ripple(bc, 25) + return bcbytes[-4:] == sha256(sha256(bcbytes[:-4]).digest()).digest()[:4] + except Exception: + return False + class CryptoCurrency(AbstractSubtypeObject): """ @@ -92,6 +105,8 @@ class CryptoCurrency(AbstractSubtypeObject): return check_base58_address(self.id) elif self.subtype == 'dash' or self.subtype == 'litecoin' or self.subtype == 'tron': return check_base58_address(self.id) + elif self.subtype == 'ripple': + return check_base58_ripple_address(self.id) else: return True @@ -110,6 +125,8 @@ class CryptoCurrency(AbstractSubtypeObject): return 'ZEC' elif self.subtype == 'dash': return 'DASH' + elif self.subtype == 'ripple': + return 'XRP' elif self.subtype == 'tron': return 'TRX' return None @@ -197,7 +214,7 @@ class CryptoCurrencies(AbstractSubtypeObjects): def get_all_subtypes(): # return ail_core.get_object_all_subtypes(self.type) - return ['bitcoin', 'bitcoin-cash', 'dash', 'ethereum', 'litecoin', 'monero', 'tron', 'zcash'] + return ['bitcoin', 'bitcoin-cash', 'dash', 'ethereum', 'litecoin', 'monero', 'ripple', 'tron', 'zcash'] # def build_crypto_regex(subtype, search_id): @@ -229,6 +246,8 @@ def get_subtype_by_symbol(symbol): return 'zcash' elif symbol == 'DASH': return 'dash' + elif symbol == 'XRP': + return 'ripple' elif symbol == 'TRX': return 'tron' return None diff --git a/bin/modules/Cryptocurrencies.py b/bin/modules/Cryptocurrencies.py index 8b5607b8..1e9e00dd 100755 --- a/bin/modules/Cryptocurrencies.py +++ b/bin/modules/Cryptocurrencies.py @@ -97,7 +97,13 @@ CURRENCIES = { 'regex': r'\b(?