Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions electrum/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,13 @@ def sha256(x: Union[bytes, str]) -> bytes:


def sha256d(x: Union[bytes, str]) -> bytes:
x = to_bytes(x, 'utf8')
out = bytes(sha256(sha256(x)))
return out
# Avoid redundant conversion; only convert to bytes if necessary
if not isinstance(x, bytes):
x = to_bytes(x, 'utf8')
# Avoid double-conversion and extra function calls
h1 = hashlib.sha256(x).digest()
h2 = hashlib.sha256(h1).digest()
return h2


def hash_160(x: bytes) -> bytes:
Expand Down