Skip to content

Commit c1b7c36

Browse files
author
shadowy-pycoder
committed
added experimental support for Electrum signatures
1 parent 7d38c8f commit c1b7c36

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

bitcoin_message_tool/bmt.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ def sign_message(wif: str, addr_type: str, message: str, /, *, deterministic=Fal
640640
deterministic - if you want your signatures be produced deterministically, set this flag to True,
641641
and each unique combination of private key and message will yield only one signature
642642
643+
electrum - if set to True segwit addresses will produce signatures with Legacy headers
644+
643645
"""
644646
m_bytes = msg_magic(message)
645647
msg = int.from_bytes(double_sha256(m_bytes), 'big')
@@ -651,10 +653,8 @@ def sign_message(wif: str, addr_type: str, message: str, /, *, deterministic=Fal
651653
else:
652654
sig = rfc_sign(privkey, msg, secp256k1.n_curve)
653655
address, ver = derive_address(pubkey, addr_type)
654-
if electrum and uncompressed:
655-
ver = 0
656-
if electrum and not uncompressed:
657-
ver = 1
656+
if electrum:
657+
ver = 0 if uncompressed else 1
658658
r = sig.r.to_bytes(32, 'big')
659659
s = sig.s.to_bytes(32, 'big')
660660
for header in headers[ver]:
@@ -835,3 +835,13 @@ def main():
835835

836836
if __name__ == '__main__':
837837
main()
838+
839+
840+
# -----BEGIN BITCOIN SIGNED MESSAGE-----
841+
# ECDSA is the most fun I have ever experienced
842+
# -----BEGIN BITCOIN SIGNATURE-----
843+
# bc1qsexve09agl8e9gwkflr85x6s2szh27efcts6v5
844+
845+
# KAaU/5cb7jPkNQxTtapPqR3EKyDU1Esjd4aZly+5Rwd6Cjlvgw6X0gUQjkrMa8Z+vl/tNcfgcuwzcCE3NtRk6Gk=
846+
# -----END BITCOIN SIGNATURE-----
847+
# KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU9EMfkHW6w

0 commit comments

Comments
 (0)