def validate_multisig(multisig: MultisigRedeemScriptType) -> None: if any(paths.is_hardened(n) for n in multisig.address_n): raise wire.DataError("Cannot perform hardened derivation from XPUB") for hd in multisig.pubkeys: if any(paths.is_hardened(n) for n in hd.address_n): raise wire.DataError( "Cannot perform hardened derivation from XPUB")
def validate_path_for_get_public_key(path: list) -> bool: """ This should be 44'/8217'/0', but other non-hardened items are allowed. """ length = len(path) if length < 3 or length > 5: return False if path[0] != 44 | HARDENED: return False if path[1] != 8217 | HARDENED: return False if path[2] != 0 | HARDENED: return False if length > 3 and paths.is_hardened(path[3]): return False if length > 4 and paths.is_hardened(path[4]): return False return True
def validate_path_for_bitcoin_public_key(path: list, coin: CoinInfo) -> bool: """ Validates derivation path to fit Bitcoin-like coins for GetPublicKey. """ length = len(path) if length < 3 or length > 5: return False if not validate_purpose(path[0], coin): return False if path[1] != coin.slip44 | HARDENED: return False if path[2] < HARDENED or path[2] > 20 | HARDENED: return False if length > 3 and paths.is_hardened(path[3]): return False if length > 4 and paths.is_hardened(path[4]): return False return True
def _validate_path_for_get_public_key(path: List[int]) -> bool: """ Modified version of paths.validate_path_for_get_public_key. Checks if path has at least three hardened items, Byron or Shelley purpose and slip44 id 1815. The path is allowed to have more than three items, but all the following items have to be non-hardened. """ length = len(path) if length < 3 or length > 5: return False if path[0] not in (purposes.BYRON, purposes.SHELLEY): return False if path[1] != 1815 | HARDENED: return False if path[2] < HARDENED or path[2] > 20 | HARDENED: return False if length > 3 and paths.is_hardened(path[3]): return False if length > 4 and paths.is_hardened(path[4]): return False return True
def test_is_hardened(self): self.assertTrue(is_hardened(44 | HARDENED)) self.assertTrue(is_hardened(0 | HARDENED)) self.assertTrue(is_hardened(99999 | HARDENED)) self.assertFalse(is_hardened(44)) self.assertFalse(is_hardened(0)) self.assertFalse(is_hardened(99999))