mirror of
https://github.com/basicswap/basicswap.git
synced 2024-11-17 00:07:56 +00:00
Replace all hashlib ripemd160 functions.
This commit is contained in:
parent
08f0156b75
commit
0a9db22828
11 changed files with 31 additions and 23 deletions
|
@ -1,3 +1,3 @@
|
||||||
name = "basicswap"
|
name = "basicswap"
|
||||||
|
|
||||||
__version__ = "0.12.1"
|
__version__ = "0.12.2"
|
||||||
|
|
|
@ -83,9 +83,6 @@ def set_regtest() -> None:
|
||||||
def sha256(s):
|
def sha256(s):
|
||||||
return hashlib.new('sha256', s).digest()
|
return hashlib.new('sha256', s).digest()
|
||||||
|
|
||||||
def ripemd160(s):
|
|
||||||
return hashlib.new('ripemd160', s).digest()
|
|
||||||
|
|
||||||
def hash256(s):
|
def hash256(s):
|
||||||
return sha256(sha256(s))
|
return sha256(sha256(s))
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,6 @@ MAX_SCRIPT_OPCODES = 201
|
||||||
|
|
||||||
OPCODE_NAMES = {}
|
OPCODE_NAMES = {}
|
||||||
|
|
||||||
def hash160(s):
|
|
||||||
return hashlib.new('ripemd160', sha256(s)).digest()
|
|
||||||
|
|
||||||
|
|
||||||
_opcode_instances = []
|
_opcode_instances = []
|
||||||
class CScriptOp(int):
|
class CScriptOp(int):
|
||||||
"""A single script opcode"""
|
"""A single script opcode"""
|
||||||
|
|
|
@ -68,9 +68,6 @@ mininode_lock = RLock()
|
||||||
def sha256(s):
|
def sha256(s):
|
||||||
return hashlib.new('sha256', s).digest()
|
return hashlib.new('sha256', s).digest()
|
||||||
|
|
||||||
def ripemd160(s):
|
|
||||||
return hashlib.new('ripemd160', s).digest()
|
|
||||||
|
|
||||||
def hash256(s):
|
def hash256(s):
|
||||||
return sha256(sha256(s))
|
return sha256(sha256(s))
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,6 @@ MAX_SCRIPT_OPCODES = 201
|
||||||
|
|
||||||
OPCODE_NAMES = {}
|
OPCODE_NAMES = {}
|
||||||
|
|
||||||
def hash160(s):
|
|
||||||
return hashlib.new('ripemd160', sha256(s)).digest()
|
|
||||||
|
|
||||||
|
|
||||||
_opcode_instances = []
|
_opcode_instances = []
|
||||||
class CScriptOp(int):
|
class CScriptOp(int):
|
||||||
"""A single script opcode"""
|
"""A single script opcode"""
|
||||||
|
|
|
@ -51,9 +51,6 @@ MSG_TYPE_MASK = 0xffffffff >> 2
|
||||||
def sha256(s):
|
def sha256(s):
|
||||||
return hashlib.new('sha256', s).digest()
|
return hashlib.new('sha256', s).digest()
|
||||||
|
|
||||||
def ripemd160(s):
|
|
||||||
return hashlib.new('ripemd160', s).digest()
|
|
||||||
|
|
||||||
def hash256(s):
|
def hash256(s):
|
||||||
return sha256(sha256(s))
|
return sha256(sha256(s))
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ from basicswap.util import (
|
||||||
i2b,
|
i2b,
|
||||||
ensure,
|
ensure,
|
||||||
)
|
)
|
||||||
|
from basicswap.util.crypto import hash160
|
||||||
from basicswap.util.address import decodeAddress
|
from basicswap.util.address import decodeAddress
|
||||||
from basicswap.chainparams import Coins
|
from basicswap.chainparams import Coins
|
||||||
from basicswap.interface.contrib.firo_test_framework.script import (
|
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_HASH160,
|
||||||
OP_CHECKSIG,
|
OP_CHECKSIG,
|
||||||
OP_EQUALVERIFY,
|
OP_EQUALVERIFY,
|
||||||
hash160,
|
|
||||||
)
|
)
|
||||||
from basicswap.interface.contrib.firo_test_framework.mininode import (
|
from basicswap.interface.contrib.firo_test_framework.mininode import (
|
||||||
CBlock,
|
CBlock,
|
||||||
|
|
|
@ -25,6 +25,7 @@ from basicswap.interface.contrib.nav_test_framework.mininode import (
|
||||||
FromHex,
|
FromHex,
|
||||||
uint256_from_str,
|
uint256_from_str,
|
||||||
)
|
)
|
||||||
|
from basicswap.util.crypto import hash160
|
||||||
from basicswap.util.address import (
|
from basicswap.util.address import (
|
||||||
decodeWif,
|
decodeWif,
|
||||||
pubkeyToAddress,
|
pubkeyToAddress,
|
||||||
|
@ -39,7 +40,6 @@ from basicswap.basicswap_util import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from basicswap.interface.contrib.nav_test_framework.script import (
|
from basicswap.interface.contrib.nav_test_framework.script import (
|
||||||
hash160,
|
|
||||||
CScript,
|
CScript,
|
||||||
OP_0,
|
OP_0,
|
||||||
OP_EQUAL,
|
OP_EQUAL,
|
||||||
|
|
|
@ -1,13 +1,23 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2022 tecnovert
|
# Copyright (c) 2022-2023 tecnovert
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# 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):
|
def ripemd160(data):
|
||||||
h = RIPEMD160.new()
|
h = RIPEMD160.new()
|
||||||
h.update(data)
|
h.update(data)
|
||||||
return h.digest()
|
return h.digest()
|
||||||
|
|
||||||
|
|
||||||
|
def hash160(s):
|
||||||
|
return ripemd160(sha256(s))
|
||||||
|
|
|
@ -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
|
0.12.1
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ from coincurve.keys import (
|
||||||
PrivateKey)
|
PrivateKey)
|
||||||
|
|
||||||
from basicswap.util import i2b, h2b
|
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.util.rfc2440 import rfc2440_hash_password
|
||||||
from basicswap.interface.btc import BTCInterface
|
from basicswap.interface.btc import BTCInterface
|
||||||
from basicswap.interface.xmr import XMRInterface
|
from basicswap.interface.xmr import XMRInterface
|
||||||
|
@ -40,6 +40,7 @@ from basicswap.messages_pb2 import (
|
||||||
BidMessage,
|
BidMessage,
|
||||||
BidMessage_v1Deprecated,
|
BidMessage_v1Deprecated,
|
||||||
)
|
)
|
||||||
|
from basicswap.contrib.test_framework.script import hash160 as hash160_btc
|
||||||
|
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
@ -317,6 +318,12 @@ class Test(unittest.TestCase):
|
||||||
input_data = b'hash this'
|
input_data = b'hash this'
|
||||||
assert (ripemd160(input_data).hex() == 'd5443a154f167e2c1332f6de72cfb4c6ab9c8c17')
|
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):
|
def test_protobuf(self):
|
||||||
# Ensure old protobuf templates can be read
|
# Ensure old protobuf templates can be read
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue