@@ -640,6 +640,8 @@ def sign_message(wif: str, addr_type: str, message: str, /, *, deterministic=Fal
640
640
deterministic - if you want your signatures be produced deterministically, set this flag to True,
641
641
and each unique combination of private key and message will yield only one signature
642
642
643
+ electrum - if set to True segwit addresses will produce signatures with Legacy headers
644
+
643
645
"""
644
646
m_bytes = msg_magic (message )
645
647
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
651
653
else :
652
654
sig = rfc_sign (privkey , msg , secp256k1 .n_curve )
653
655
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
658
658
r = sig .r .to_bytes (32 , 'big' )
659
659
s = sig .s .to_bytes (32 , 'big' )
660
660
for header in headers [ver ]:
@@ -835,3 +835,13 @@ def main():
835
835
836
836
if __name__ == '__main__' :
837
837
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