diff --git a/basicswap/__init__.py b/basicswap/__init__.py index 06944a5..e85830f 100644 --- a/basicswap/__init__.py +++ b/basicswap/__init__.py @@ -1,3 +1,3 @@ name = "basicswap" -__version__ = "0.12.1" +__version__ = "0.12.2" diff --git a/basicswap/interface/contrib/firo_test_framework/mininode.py b/basicswap/interface/contrib/firo_test_framework/mininode.py index 4212a80..6313ffe 100644 --- a/basicswap/interface/contrib/firo_test_framework/mininode.py +++ b/basicswap/interface/contrib/firo_test_framework/mininode.py @@ -83,9 +83,6 @@ def set_regtest() -> None: def sha256(s): return hashlib.new('sha256', s).digest() -def ripemd160(s): - return hashlib.new('ripemd160', s).digest() - def hash256(s): return sha256(sha256(s)) diff --git a/basicswap/interface/contrib/firo_test_framework/script.py b/basicswap/interface/contrib/firo_test_framework/script.py index 83bbf20..4783b76 100644 --- a/basicswap/interface/contrib/firo_test_framework/script.py +++ b/basicswap/interface/contrib/firo_test_framework/script.py @@ -37,10 +37,6 @@ MAX_SCRIPT_OPCODES = 201 OPCODE_NAMES = {} -def hash160(s): - return hashlib.new('ripemd160', sha256(s)).digest() - - _opcode_instances = [] class CScriptOp(int): """A single script opcode""" diff --git a/basicswap/interface/contrib/nav_test_framework/mininode.py b/basicswap/interface/contrib/nav_test_framework/mininode.py index 46a6471..bec35ba 100755 --- a/basicswap/interface/contrib/nav_test_framework/mininode.py +++ b/basicswap/interface/contrib/nav_test_framework/mininode.py @@ -68,9 +68,6 @@ mininode_lock = RLock() def sha256(s): return hashlib.new('sha256', s).digest() -def ripemd160(s): - return hashlib.new('ripemd160', s).digest() - def hash256(s): return sha256(sha256(s)) diff --git a/basicswap/interface/contrib/nav_test_framework/script.py b/basicswap/interface/contrib/nav_test_framework/script.py index a1e0580..d23934e 100755 --- a/basicswap/interface/contrib/nav_test_framework/script.py +++ b/basicswap/interface/contrib/nav_test_framework/script.py @@ -37,10 +37,6 @@ MAX_SCRIPT_OPCODES = 201 OPCODE_NAMES = {} -def hash160(s): - return hashlib.new('ripemd160', sha256(s)).digest() - - _opcode_instances = [] class CScriptOp(int): """A single script opcode""" diff --git a/basicswap/interface/contrib/pivx_test_framework/messages.py b/basicswap/interface/contrib/pivx_test_framework/messages.py index f6c84be..256b822 100755 --- a/basicswap/interface/contrib/pivx_test_framework/messages.py +++ b/basicswap/interface/contrib/pivx_test_framework/messages.py @@ -51,9 +51,6 @@ MSG_TYPE_MASK = 0xffffffff >> 2 def sha256(s): return hashlib.new('sha256', s).digest() -def ripemd160(s): - return hashlib.new('ripemd160', s).digest() - def hash256(s): return sha256(sha256(s)) diff --git a/basicswap/interface/firo.py b/basicswap/interface/firo.py index 5d0207d..c5dcba0 100644 --- a/basicswap/interface/firo.py +++ b/basicswap/interface/firo.py @@ -13,6 +13,7 @@ from basicswap.util import ( i2b, ensure, ) +from basicswap.util.crypto import hash160 from basicswap.util.address import decodeAddress from basicswap.chainparams import Coins from basicswap.interface.contrib.firo_test_framework.script import ( @@ -22,7 +23,6 @@ from basicswap.interface.contrib.firo_test_framework.script import ( OP_HASH160, OP_CHECKSIG, OP_EQUALVERIFY, - hash160, ) from basicswap.interface.contrib.firo_test_framework.mininode import ( CBlock, diff --git a/basicswap/interface/nav.py b/basicswap/interface/nav.py index d2481a8..df18ddd 100644 --- a/basicswap/interface/nav.py +++ b/basicswap/interface/nav.py @@ -25,6 +25,7 @@ from basicswap.interface.contrib.nav_test_framework.mininode import ( FromHex, uint256_from_str, ) +from basicswap.util.crypto import hash160 from basicswap.util.address import ( decodeWif, pubkeyToAddress, @@ -39,7 +40,6 @@ from basicswap.basicswap_util import ( ) from basicswap.interface.contrib.nav_test_framework.script import ( - hash160, CScript, OP_0, OP_EQUAL, diff --git a/basicswap/util/crypto.py b/basicswap/util/crypto.py index 00d4ef7..22b80fc 100644 --- a/basicswap/util/crypto.py +++ b/basicswap/util/crypto.py @@ -1,13 +1,23 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2022 tecnovert +# Copyright (c) 2022-2023 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. -from Crypto.Hash import RIPEMD160 # pycryptodome +from Crypto.Hash import RIPEMD160, SHA256 # pycryptodome + + +def sha256(data): + h = SHA256.new() + h.update(data) + return h.digest() def ripemd160(data): h = RIPEMD160.new() h.update(data) return h.digest() + + +def hash160(s): + return ripemd160(sha256(s)) diff --git a/doc/release-notes.md b/doc/release-notes.md index e3fcbad..96db556 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -1,3 +1,11 @@ +0.12.2 +============== + +- Updated coincurve and libsecp256k1 versions. + - Avoids needing secp256k1_generator_const_g as it's not accessible from a dll. +- Fix missing ripemd160 on some systems. + + 0.12.1 ============== diff --git a/tests/basicswap/test_other.py b/tests/basicswap/test_other.py index 1fa6d7d..8edd54e 100644 --- a/tests/basicswap/test_other.py +++ b/tests/basicswap/test_other.py @@ -22,7 +22,7 @@ from coincurve.keys import ( PrivateKey) from basicswap.util import i2b, h2b -from basicswap.util.crypto import ripemd160 +from basicswap.util.crypto import ripemd160, hash160 from basicswap.util.rfc2440 import rfc2440_hash_password from basicswap.interface.btc import BTCInterface from basicswap.interface.xmr import XMRInterface @@ -40,6 +40,7 @@ from basicswap.messages_pb2 import ( BidMessage, BidMessage_v1Deprecated, ) +from basicswap.contrib.test_framework.script import hash160 as hash160_btc class Test(unittest.TestCase): @@ -317,6 +318,12 @@ class Test(unittest.TestCase): input_data = b'hash this' assert (ripemd160(input_data).hex() == 'd5443a154f167e2c1332f6de72cfb4c6ab9c8c17') + def test_hash160(self): + # hash160 is RIPEMD(SHA256(data)) + input_data = b'hash this' + assert (hash160(input_data).hex() == '072985b3583a4a71f548494a5e1d5f6b00d0fe13') + assert (hash160_btc(input_data).hex() == '072985b3583a4a71f548494a5e1d5f6b00d0fe13') + def test_protobuf(self): # Ensure old protobuf templates can be read