Browse Source

util: rm hfu, cleaner bh2u

sqlite_db
SomberNight 6 years ago
parent
commit
3ad6f738bd
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 7
      electrum/keystore.py
  2. 3
      electrum/util.py

7
electrum/keystore.py

@ -26,6 +26,7 @@
from unicodedata import normalize
import hashlib
import binascii
from . import bitcoin, ecc, constants, bip32
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,
is_xpub, is_xprv)
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)
from .util import (PrintError, InvalidPassword, hfu, WalletFileException,
from .util import (PrintError, InvalidPassword, WalletFileException,
BitcoinException, bh2u, bfh, print_error, inv_dict)
from .mnemonic import Mnemonic, load_wordlist
from .plugin import run_hook
@ -625,7 +626,7 @@ def bip39_is_checksum_valid(mnemonic):
while len(h) < entropy_length/4:
h = '0'+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)
return checksum == calculated_checksum, True

3
electrum/util.py

@ -462,7 +462,6 @@ def to_bytes(something, encoding='utf8') -> bytes:
bfh = bytes.fromhex
hfu = binascii.hexlify
def bh2u(x: bytes) -> str:
@ -473,7 +472,7 @@ def bh2u(x: bytes) -> str:
>>> bh2u(x)
'01020A'
"""
return hfu(x).decode('ascii')
return x.hex()
def user_dir():

Loading…
Cancel
Save