@@ -896,33 +896,59 @@ def _sign_btc_tx(self) -> None:
896
896
def _sign_btc_message (self ) -> None :
897
897
# pylint: disable=no-member
898
898
899
- keypath = [49 + HARDENED , 0 + HARDENED , 0 + HARDENED , 0 , 0 ]
900
- script_config = bitbox02 .btc .BTCScriptConfig (
901
- simple_type = bitbox02 .btc .BTCScriptConfig .P2WPKH_P2SH
902
- )
903
- address = self ._device .btc_address (
904
- keypath = keypath , script_config = script_config , display = False
905
- )
899
+ def sign (
900
+ coin : "bitbox02.btc.BTCCoin.V" ,
901
+ keypath : Sequence [int ],
902
+ script_config : bitbox02 .btc .BTCScriptConfig ,
903
+ ) -> None :
904
+ address = self ._device .btc_address (
905
+ coin = coin , keypath = keypath , script_config = script_config , display = False
906
+ )
906
907
907
- print ("Address:" , address )
908
+ print ("Address:" , address )
908
909
909
- msg = input (r"Message to sign (\n = newline): " )
910
- if msg .startswith ("0x" ):
911
- msg_bytes = binascii .unhexlify (msg [2 :])
912
- else :
913
- msg_bytes = msg .replace (r"\n" , "\n " ).encode ("utf-8" )
910
+ msg = input (r"Message to sign (\n = newline): " )
911
+ if msg .startswith ("0x" ):
912
+ msg_bytes = binascii .unhexlify (msg [2 :])
913
+ else :
914
+ msg_bytes = msg .replace (r"\n" , "\n " ).encode ("utf-8" )
914
915
915
- try :
916
- _ , _ , sig65 = self ._device .btc_sign_msg (
917
- bitbox02 .btc .BTC ,
918
- bitbox02 .btc .BTCScriptConfigWithKeypath (
919
- script_config = script_config , keypath = keypath
920
- ),
921
- msg_bytes ,
916
+ try :
917
+ _ , _ , sig65 = self ._device .btc_sign_msg (
918
+ coin ,
919
+ bitbox02 .btc .BTCScriptConfigWithKeypath (
920
+ script_config = script_config , keypath = keypath
921
+ ),
922
+ msg_bytes ,
923
+ )
924
+ print ("Signature:" , base64 .b64encode (sig65 ).decode ("ascii" ))
925
+ except UserAbortException :
926
+ print ("Aborted by user" )
927
+
928
+ def sign_mainnet () -> None :
929
+ keypath = [49 + HARDENED , 0 + HARDENED , 0 + HARDENED , 0 , 0 ]
930
+ script_config = bitbox02 .btc .BTCScriptConfig (
931
+ simple_type = bitbox02 .btc .BTCScriptConfig .P2WPKH_P2SH
922
932
)
923
- print ("Signature:" , base64 .b64encode (sig65 ).decode ("ascii" ))
924
- except UserAbortException :
925
- print ("Aborted by user" )
933
+ sign (bitbox02 .btc .BTC , keypath , script_config )
934
+
935
+ def sign_testnet () -> None :
936
+ keypath = [49 + HARDENED , 1 + HARDENED , 0 + HARDENED , 0 , 0 ]
937
+ script_config = bitbox02 .btc .BTCScriptConfig (
938
+ simple_type = bitbox02 .btc .BTCScriptConfig .P2WPKH_P2SH
939
+ )
940
+ sign (bitbox02 .btc .TBTC , keypath , script_config )
941
+
942
+ choices = (
943
+ ("Mainnet" , sign_mainnet ),
944
+ ("Testnet" , sign_testnet ),
945
+ )
946
+ choice = ask_user (choices )
947
+ if callable (choice ):
948
+ try :
949
+ choice ()
950
+ except UserAbortException :
951
+ eprint ("Aborted by user" )
926
952
927
953
def _check_backup (self ) -> None :
928
954
print ("Your BitBox02 will now perform a backup check" )
0 commit comments