"""Network profiles (ADR-58): everything that differs between PLM mainnet and the regtest of the alpha. A `Profile` fixes the bech32 hrp, the base58 and extended-key prefixes, the genesis hash the Electrum handshake expects (ELC-30), the proof-of-work floor and the BIP44 coin type. The values come from `palladiumcore/src/chainparams.cpp` (mainnet and `CRegTestParams`) and the PalladiumWallet chain profiles. The profile is threaded explicitly through every call (`network=profile.embit`), never registered globally: this is a long-lived server and embit has no notion of a current network beyond what it is passed. """ from dataclasses import dataclass PLM_MAINNET = { "name": "PLM Mainnet", "wif": bytes([0x80]), "p2pkh": bytes([55]), "p2sh": bytes([5]), "bech32": "plm", "xprv": bytes.fromhex("0488ade4"), "xpub": bytes.fromhex("0488b21e"), "yprv": bytes.fromhex("049d7878"), "ypub": bytes.fromhex("049d7cb2"), "zprv": bytes.fromhex("04b2430c"), "zpub": bytes.fromhex("04b24746"), "Yprv": bytes.fromhex("0295b005"), "Ypub": bytes.fromhex("0295b43f"), "Zprv": bytes.fromhex("02aa7a99"), "Zpub": bytes.fromhex("02aa7ed3"), "bip32": 0, } BIP44_COIN_TYPE = 746 ACCOUNT_PATH = f"m/84h/{BIP44_COIN_TYPE}h/0h" # PLM shares Bitcoin's genesis block (palladiumcore chainparams.cpp) and its powLimit, so a # Bitcoin Electrum server would pass every header check; the handshake asks for this instead. GENESIS_HASH = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" MAINNET_POW_LIMIT = int("00000000" + "ff" * 28, 16) REGTEST_POW_LIMIT = int("7f" + "ff" * 31, 16) # Bitcoin's testnet SLIP-132 variants, which Palladium's testnet and regtest share. PLM_REGTEST = { "name": "PLM Regtest", "wif": bytes([0xFF]), "p2pkh": bytes([127]), "p2sh": bytes([115]), "bech32": "rplm", "xprv": bytes.fromhex("04358394"), "xpub": bytes.fromhex("043587cf"), "yprv": bytes.fromhex("044a4e28"), "ypub": bytes.fromhex("044a5262"), "zprv": bytes.fromhex("045f18bc"), "zpub": bytes.fromhex("045f1cf6"), "Yprv": bytes.fromhex("024285b5"), "Ypub": bytes.fromhex("024289ef"), "Zprv": bytes.fromhex("02575048"), "Zpub": bytes.fromhex("02575483"), "bip32": 1, } @dataclass(frozen=True) class Profile: name: str # the value of PLM_NETWORK embit: dict # what embit takes as `network=` genesis_hash: str pow_limit: int coin_type: int @property def hrp(self) -> str: return self.embit["bech32"] @property def account_path(self) -> str: return f"m/84h/{self.coin_type}h/0h" MAINNET = Profile("mainnet", PLM_MAINNET, GENESIS_HASH, MAINNET_POW_LIMIT, BIP44_COIN_TYPE) REGTEST = Profile( "regtest", PLM_REGTEST, "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", REGTEST_POW_LIMIT, 1 ) PROFILES = {profile.name: profile for profile in (MAINNET, REGTEST)} def get_profile(name: str) -> Profile: try: return PROFILES[name] except KeyError: raise ValueError(f"unknown network {name!r}: expected one of {sorted(PROFILES)}") from None