Browse Source

plugins/bitbox02: add support for p2wsh-p2sh multisig

patch-4
Marko Bencun 5 years ago
parent
commit
8fa019f65b
No known key found for this signature in database GPG Key ID: 804538928C37EAE8
  1. 32
      electrum/plugins/bitbox02/bitbox02.py

32
electrum/plugins/bitbox02/bitbox02.py

@ -229,6 +229,11 @@ class BitBox02Client(HardwareClientBase):
out_type = bitbox02.btc.BTCPubRequest.YPUB out_type = bitbox02.btc.BTCPubRequest.YPUB
else: else:
out_type = bitbox02.btc.BTCPubRequest.UPUB out_type = bitbox02.btc.BTCPubRequest.UPUB
elif xtype == "p2wsh-p2sh":
if coin_network == bitbox02.btc.BTC:
out_type = bitbox02.btc.BTCPubRequest.CAPITAL_YPUB
else:
out_type = bitbox02.btc.BTCPubRequest.CAPITAL_UPUB
elif xtype == "p2wsh": elif xtype == "p2wsh":
if coin_network == bitbox02.btc.BTC: if coin_network == bitbox02.btc.BTC:
out_type = bitbox02.btc.BTCPubRequest.CAPITAL_ZPUB out_type = bitbox02.btc.BTCPubRequest.CAPITAL_ZPUB
@ -276,13 +281,14 @@ class BitBox02Client(HardwareClientBase):
@runs_in_hwd_thread @runs_in_hwd_thread
def btc_multisig_config( def btc_multisig_config(
self, coin, bip32_path: List[int], wallet: Multisig_Wallet self, coin, bip32_path: List[int], wallet: Multisig_Wallet, xtype: str,
): ):
""" """
Set and get a multisig config with the current device and some other arbitrary xpubs. Set and get a multisig config with the current device and some other arbitrary xpubs.
Registers it on the device if not already registered. Registers it on the device if not already registered.
xtype: 'p2wsh' | 'p2wsh-p2sh'
""" """
assert xtype in ("p2wsh", "p2wsh-p2sh")
if self.bitbox02_device is None: if self.bitbox02_device is None:
raise Exception( raise Exception(
"Need to setup communication first before attempting any BitBox02 calls" "Need to setup communication first before attempting any BitBox02 calls"
@ -291,7 +297,7 @@ class BitBox02Client(HardwareClientBase):
account_keypath = bip32_path[:4] account_keypath = bip32_path[:4]
xpubs = wallet.get_master_public_keys() xpubs = wallet.get_master_public_keys()
our_xpub = self.get_xpub( our_xpub = self.get_xpub(
bip32.convert_bip32_intpath_to_strpath(account_keypath), "p2wsh" bip32.convert_bip32_intpath_to_strpath(account_keypath), xtype
) )
multisig_config = bitbox02.btc.BTCScriptConfig( multisig_config = bitbox02.btc.BTCScriptConfig(
@ -299,6 +305,10 @@ class BitBox02Client(HardwareClientBase):
threshold=wallet.m, threshold=wallet.m,
xpubs=[util.parse_xpub(xpub) for xpub in xpubs], xpubs=[util.parse_xpub(xpub) for xpub in xpubs],
our_xpub_index=xpubs.index(our_xpub), our_xpub_index=xpubs.index(our_xpub),
script_type={
"p2wsh": bitbox02.btc.BTCScriptConfig.Multisig.P2WSH,
"p2wsh-p2sh": bitbox02.btc.BTCScriptConfig.Multisig.P2WSH_P2SH,
}[xtype]
) )
) )
@ -341,13 +351,13 @@ class BitBox02Client(HardwareClientBase):
script_config = bitbox02.btc.BTCScriptConfig( script_config = bitbox02.btc.BTCScriptConfig(
simple_type=bitbox02.btc.BTCScriptConfig.P2WPKH_P2SH simple_type=bitbox02.btc.BTCScriptConfig.P2WPKH_P2SH
) )
elif address_type == "p2wsh": elif address_type in ("p2wsh-p2sh", "p2wsh"):
if type(wallet) is Multisig_Wallet: if type(wallet) is Multisig_Wallet:
script_config = self.btc_multisig_config( script_config = self.btc_multisig_config(
coin_network, address_keypath, wallet coin_network, address_keypath, wallet, address_type,
) )
else: else:
raise Exception("Can only use p2wsh with multisig wallets") raise Exception("Can only use p2wsh-p2sh or p2wsh with multisig wallets")
else: else:
raise Exception( raise Exception(
"invalid address xtype: {} is not supported by the BitBox02".format( "invalid address xtype: {} is not supported by the BitBox02".format(
@ -446,11 +456,11 @@ class BitBox02Client(HardwareClientBase):
tx_script_type = bitbox02.btc.BTCScriptConfig( tx_script_type = bitbox02.btc.BTCScriptConfig(
simple_type=bitbox02.btc.BTCScriptConfig.P2WPKH_P2SH simple_type=bitbox02.btc.BTCScriptConfig.P2WPKH_P2SH
) )
elif tx_script_type == "p2wsh": elif tx_script_type in ("p2wsh-p2sh", "p2wsh"):
if type(wallet) is Multisig_Wallet: if type(wallet) is Multisig_Wallet:
tx_script_type = self.btc_multisig_config(coin, full_path, wallet) tx_script_type = self.btc_multisig_config(coin, full_path, wallet, tx_script_type)
else: else:
raise Exception("Can only use p2wsh with multisig wallets") raise Exception("Can only use p2wsh-p2sh or p2wsh with multisig wallets")
else: else:
raise UserFacingException( raise UserFacingException(
"invalid input script type: {} is not supported by the BitBox02".format( "invalid input script type: {} is not supported by the BitBox02".format(
@ -602,7 +612,7 @@ class BitBox02Plugin(HW_PluginBase):
minimum_library = (5, 0, 0) minimum_library = (5, 0, 0)
DEVICE_IDS = [(0x03EB, 0x2403)] DEVICE_IDS = [(0x03EB, 0x2403)]
SUPPORTED_XTYPES = ("p2wpkh-p2sh", "p2wpkh", "p2wsh") SUPPORTED_XTYPES = ("p2wpkh-p2sh", "p2wpkh", "p2wsh", "p2wsh-p2sh")
def __init__(self, parent: HW_PluginBase, config: SimpleConfig, name: str): def __init__(self, parent: HW_PluginBase, config: SimpleConfig, name: str):
super().__init__(parent, config, name) super().__init__(parent, config, name)
@ -647,7 +657,7 @@ class BitBox02Plugin(HW_PluginBase):
): ):
if xtype not in self.SUPPORTED_XTYPES: if xtype not in self.SUPPORTED_XTYPES:
raise ScriptTypeNotSupported( raise ScriptTypeNotSupported(
_("This type of script is not supported with {}.").format(self.device) _("This type of script is not supported with {}: {}").format(self.device, xtype)
) )
client = self.scan_and_create_client_for_device(device_id=device_id, wizard=wizard) client = self.scan_and_create_client_for_device(device_id=device_id, wizard=wizard)
assert isinstance(client, BitBox02Client) assert isinstance(client, BitBox02Client)

Loading…
Cancel
Save