util: rm hfu, cleaner bh2u
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import binascii
|
||||||
|
|
||||||
from . import bitcoin, ecc, constants, bip32
|
from . import bitcoin, ecc, constants, bip32
|
||||||
from .bitcoin import (deserialize_privkey, serialize_privkey,
|
from .bitcoin import (deserialize_privkey, serialize_privkey,
|
||||||
@@ -35,9 +36,9 @@ from .bip32 import (bip32_public_derivation, deserialize_xpub, CKD_pub,
|
|||||||
bip32_private_key, bip32_derivation, BIP32_PRIME,
|
bip32_private_key, bip32_derivation, BIP32_PRIME,
|
||||||
is_xpub, is_xprv)
|
is_xpub, is_xprv)
|
||||||
from .ecc import string_to_number, number_to_string
|
from .ecc import string_to_number, number_to_string
|
||||||
from .crypto import (pw_decode, pw_encode, sha256d, PW_HASH_VERSION_LATEST,
|
from .crypto import (pw_decode, pw_encode, sha256, sha256d, PW_HASH_VERSION_LATEST,
|
||||||
SUPPORTED_PW_HASH_VERSIONS, UnsupportedPasswordHashVersion)
|
SUPPORTED_PW_HASH_VERSIONS, UnsupportedPasswordHashVersion)
|
||||||
from .util import (PrintError, InvalidPassword, hfu, WalletFileException,
|
from .util import (PrintError, InvalidPassword, WalletFileException,
|
||||||
BitcoinException, bh2u, bfh, print_error, inv_dict)
|
BitcoinException, bh2u, bfh, print_error, inv_dict)
|
||||||
from .mnemonic import Mnemonic, load_wordlist
|
from .mnemonic import Mnemonic, load_wordlist
|
||||||
from .plugin import run_hook
|
from .plugin import run_hook
|
||||||
@@ -625,7 +626,7 @@ def bip39_is_checksum_valid(mnemonic):
|
|||||||
while len(h) < entropy_length/4:
|
while len(h) < entropy_length/4:
|
||||||
h = '0'+h
|
h = '0'+h
|
||||||
b = bytearray.fromhex(h)
|
b = bytearray.fromhex(h)
|
||||||
hashed = int(hfu(hashlib.sha256(b).digest()), 16)
|
hashed = int(binascii.hexlify(sha256(b)), 16)
|
||||||
calculated_checksum = hashed >> (256 - checksum_length)
|
calculated_checksum = hashed >> (256 - checksum_length)
|
||||||
return checksum == calculated_checksum, True
|
return checksum == calculated_checksum, True
|
||||||
|
|
||||||
|
|||||||
@@ -462,7 +462,6 @@ def to_bytes(something, encoding='utf8') -> bytes:
|
|||||||
|
|
||||||
|
|
||||||
bfh = bytes.fromhex
|
bfh = bytes.fromhex
|
||||||
hfu = binascii.hexlify
|
|
||||||
|
|
||||||
|
|
||||||
def bh2u(x: bytes) -> str:
|
def bh2u(x: bytes) -> str:
|
||||||
@@ -473,7 +472,7 @@ def bh2u(x: bytes) -> str:
|
|||||||
>>> bh2u(x)
|
>>> bh2u(x)
|
||||||
'01020A'
|
'01020A'
|
||||||
"""
|
"""
|
||||||
return hfu(x).decode('ascii')
|
return x.hex()
|
||||||
|
|
||||||
|
|
||||||
def user_dir():
|
def user_dir():
|
||||||
|
|||||||
Reference in New Issue
Block a user