def test_space_and_caps() -> None: net = " MainNet " assert xpubversions_from_network(net), f"unknown network: {net}" with pytest.raises(KeyError): net = " MainNet2 " xpubversions_from_network(net)
def _pub_keyinfo_from_xpub(xpub: BIP32Key, network: Optional[str] = None, compressed: Optional[bool] = None) -> PubkeyInfo: """Return the pub_key tuple (SEC-bytes, network) from a BIP32 xpub. BIP32Key is always compressed and includes network information: here the 'network, compressed' input parameters are passed only to allow consistency checks. """ compressed = True if compressed is None else compressed if not compressed: raise BTClibValueError("Uncompressed SEC / compressed BIP32 mismatch") if isinstance(xpub, BIP32KeyData): xpub.assert_valid() else: xpub = BIP32KeyData.b58decode(xpub) if xpub.key[0] not in (2, 3): err_msg = f"not a public key: {xpub.b58encode()}" raise BTClibValueError(err_msg) if network is None: return xpub.key, network_from_xkeyversion(xpub.version) allowed_versions = xpubversions_from_network(network) if xpub.version not in allowed_versions: err_msg = f"Not a {network} key: " err_msg += f"{xpub.b58encode()}" raise BTClibValueError(err_msg) return xpub.key, network
def test_curve_from_xkeyversion() -> None: for net in NETWORKS: all_versions = xpubversions_from_network(net) + xprvversions_from_network(net) for version in all_versions: # unfortunately 'regtest' shares same versions with 'testnet' if net != "regtest": assert net == network_from_xkeyversion(version) assert NETWORKS[net]["curve"] == curve_from_xkeyversion(version)
def test_curve_from_xkeyversion() -> None: for net_str, net in NETWORKS.items(): all_versions = xpubversions_from_network(net_str) all_versions += xprvversions_from_network(net_str) for version in all_versions: # unfortunately 'regtest' shares same versions with 'testnet' if net_str != "regtest": assert net_str == network_from_xkeyversion(version) assert net.curve == curve_from_xkeyversion(version)