def _btc_multisig_config( self, coin: bitbox02.btc.BTCCoin) -> bitbox02.btc.BTCScriptConfig: """ Get a mock multisig 1-of-2 multisig with the current device and some other arbitrary xpub. Registers it on the device if not already registered. """ account_keypath = [ 48 + HARDENED, 0 + HARDENED, 0 + HARDENED, 2 + HARDENED ] my_xpub = self._device.btc_xpub( keypath=account_keypath, coin=coin, xpub_type=bitbox02.btc.BTCPubRequest.XPUB, # pylint: disable=no-member, display=False, ) multisig_config = bitbox02.btc.BTCScriptConfig( multisig=bitbox02.btc.BTCScriptConfig.Multisig( threshold=1, xpubs=[ util.parse_xpub(my_xpub), util.parse_xpub( "xpub6FEZ9Bv73h1vnE4TJG4QFj2RPXJhhsPbnXgFyH3ErLvpcZrDcynY65bhWga8PazW" "HLSLi23PoBhGcLcYW6JRiJ12zXZ9Aop4LbAqsS3gtcy"), ], our_xpub_index=0, )) is_registered = self._device.btc_is_script_config_registered( coin, multisig_config, account_keypath) if is_registered: print("Multisig account already registered on the device.") else: multisig_name = input( "Enter a name for the multisig account: ").strip() self._device.btc_register_script_config( coin=coin, script_config=multisig_config, keypath=account_keypath, name=multisig_name, ) return multisig_config
def btc_multisig_config( 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. 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: raise Exception( "Need to setup communication first before attempting any BitBox02 calls" ) account_keypath = bip32_path[:-2] xpubs = wallet.get_master_public_keys() our_xpub = self.get_xpub( bip32.convert_bip32_intpath_to_strpath(account_keypath), xtype) multisig_config = bitbox02.btc.BTCScriptConfig( multisig=bitbox02.btc.BTCScriptConfig.Multisig( threshold=wallet.m, xpubs=[util.parse_xpub(xpub) for xpub in xpubs], our_xpub_index=xpubs.index(our_xpub), script_type={ "p2wsh": bitbox02.btc.BTCScriptConfig.Multisig.P2WSH, "p2wsh-p2sh": bitbox02.btc.BTCScriptConfig.Multisig.P2WSH_P2SH, }[xtype])) is_registered = self.bitbox02_device.btc_is_script_config_registered( coin, multisig_config, account_keypath) if not is_registered: name = self.handler.name_multisig_account() try: self.bitbox02_device.btc_register_script_config( coin=coin, script_config=multisig_config, keypath=account_keypath, name=name, ) except bitbox02.DuplicateEntryException: raise except: raise UserFacingException( "Failed to register multisig\naccount configuration on BitBox02" ) return multisig_config
def _multisig_scriptconfig( self, threshold: int, origin_infos: Mapping[bytes, KeyOriginInfo], script_type: bitbox02.btc.BTCScriptConfig.Multisig.ScriptType, ) -> Tuple[bytes, bitbox02.btc.BTCScriptConfigWithKeypath]: """ From a threshold, {xpub: KeyOriginInfo} mapping and multisig script type, return our xpub and the BitBox02 multisig script config. """ # Figure out which of the cosigners is us. device_fingerprint = self.get_master_fingerprint() our_xpub_index = None our_account_keypath = None xpubs: List[bytes] = [] for i, (xpub, keyinfo) in builtins.enumerate(origin_infos.items()): xpubs.append(xpub) if device_fingerprint == keyinfo.fingerprint and keyinfo.path: if _xpubs_equal_ignoring_version( base58.b58decode_check(self._get_xpub(keyinfo.path)), xpub): our_xpub_index = i our_account_keypath = keyinfo.path if our_xpub_index is None: raise BadArgumentError("This BitBox02 is not one of the cosigners") assert our_account_keypath if len(xpubs) != len(set(xpubs)): raise BadArgumentError("Duplicate xpubs not supported") return ( xpubs[our_xpub_index], bitbox02.btc.BTCScriptConfigWithKeypath( script_config=bitbox02.btc.BTCScriptConfig( multisig=bitbox02.btc.BTCScriptConfig.Multisig( threshold=threshold, xpubs=[ util.parse_xpub( base58.b58encode_check(xpub).decode()) for xpub in xpubs ], our_xpub_index=our_xpub_index, script_type=script_type, )), keypath=our_account_keypath, ), )