Example #1
0
class Bip44Const:
    """ Class container for BIP44 constants. """

    # Specification name
    SPEC_NAME = "BIP-0044"
    # Purpose
    PURPOSE = Bip32Utils.HardenIndex(44)
    # Allowed coins
    ALLOWED_COINS = \
        [
            Bip44Coins.BITCOIN            , Bip44Coins.BITCOIN_TESTNET,
            Bip44Coins.BITCOIN_CASH       , Bip44Coins.BITCOIN_CASH_TESTNET,
            Bip44Coins.BITCOIN_SV         , Bip44Coins.BITCOIN_SV_TESTNET,
            Bip44Coins.LITECOIN           , Bip44Coins.LITECOIN_TESTNET,
            Bip44Coins.DOGECOIN           , Bip44Coins.DOGECOIN_TESTNET,
            Bip44Coins.DASH               , Bip44Coins.DASH_TESTNET,
            Bip44Coins.ZCASH              , Bip44Coins.ZCASH_TESTNET,
            Bip44Coins.ETHEREUM           ,
            Bip44Coins.ETHEREUM_CLASSIC   ,
            Bip44Coins.RIPPLE             ,
            Bip44Coins.TRON               ,
            Bip44Coins.VECHAIN            ,
            Bip44Coins.COSMOS             ,
            Bip44Coins.BAND_PROTOCOL      ,
            Bip44Coins.KAVA               ,
            Bip44Coins.IRIS_NET           ,
            Bip44Coins.BINANCE_CHAIN      ,
            Bip44Coins.BINANCE_SMART_CHAIN,
            Bip44Coins.NINE_CHRONICLES_GOLD,
        ]
    # Map from Bip44Coins to coin classes
    COIN_TO_CLASS = \
        {
            Bip44Coins.BITCOIN              : Bip44BitcoinMainNet,
            Bip44Coins.BITCOIN_TESTNET      : Bip44BitcoinTestNet,
            Bip44Coins.BITCOIN_CASH         : Bip44BitcoinCashMainNet,
            Bip44Coins.BITCOIN_CASH_TESTNET : Bip44BitcoinCashTestNet,
            Bip44Coins.BITCOIN_SV           : Bip44BitcoinSvMainNet,
            Bip44Coins.BITCOIN_SV_TESTNET   : Bip44BitcoinSvTestNet,
            Bip44Coins.LITECOIN             : Bip44LitecoinMainNet,
            Bip44Coins.LITECOIN_TESTNET     : Bip44LitecoinTestNet,
            Bip44Coins.DOGECOIN             : Bip44DogecoinMainNet,
            Bip44Coins.DOGECOIN_TESTNET     : Bip44DogecoinTestNet,
            Bip44Coins.DASH                 : Bip44DashMainNet,
            Bip44Coins.DASH_TESTNET         : Bip44DashTestNet,
            Bip44Coins.ZCASH                : Bip44ZcashMainNet,
            Bip44Coins.ZCASH_TESTNET        : Bip44ZcashTestNet,
            Bip44Coins.ETHEREUM             : Bip44Ethereum,
            Bip44Coins.ETHEREUM_CLASSIC     : Bip44EthereumClassic,
            Bip44Coins.RIPPLE               : Bip44Ripple,
            Bip44Coins.TRON                 : Bip44Tron,
            Bip44Coins.VECHAIN              : Bip44VeChain,
            Bip44Coins.COSMOS               : Bip44Cosmos,
            Bip44Coins.BAND_PROTOCOL        : Bip44BandProtocol,
            Bip44Coins.KAVA                 : Bip44Kava,
            Bip44Coins.IRIS_NET             : Bip44IrisNet,
            Bip44Coins.BINANCE_CHAIN        : Bip44BinanceChain,
            Bip44Coins.BINANCE_SMART_CHAIN  : Bip44BinanceSmartChain,
            Bip44Coins.NINE_CHRONICLES_GOLD : Bip44NineChroniclesGold,
        }
Example #2
0
    def __GetElemIndex(path_elem: str) -> Optional[int]:
        """ Get index of a path element.

        Args:
            path_elem (str): Path element

        Returns:
            int: Index of the element
            None: If the element is not a valid index
        """

        # Get if hardened
        is_hardened = len(path_elem) > 0 and path_elem[
            -1] in Bip32PathParserConst.HARDENED_CHARS

        # If hardened, remove the last character from the string
        if is_hardened:
            path_elem = path_elem[:-1]

        # The remaining string shall be numeric
        if not path_elem.isnumeric():
            return None

        return int(path_elem) if not is_hardened else Bip32Utils.HardenIndex(
            int(path_elem))
Example #3
0
    def _AccountGeneric(cls, bip_obj, acc_idx):
        """ Derive a child key from the specified account index and return a new Bip object (e.g. BIP44, BIP49, BIP84).
        It shall be called from a child class.

        Args:
            bip_obj (Bip44Base child object): Bip44Base child object (e.g. BIP44, BIP49, BIP84)
            acc_idx (int)                   : Account index

        Returns:
            Bip44Base child object: Bip44Base child object

        Raises:
            Bip44DepthError: If the current depth is not suitable for deriving keys
            Bip32KeyError: If the derivation results in an invalid key
        """
        if not cls.IsLevel(bip_obj, Bip44Levels.COIN):
            raise Bip44DepthError("Current depth (%d) is not suitable for deriving account" % bip_obj.m_bip32.Depth())

        return cls(bip_obj.m_bip32.ChildKey(Bip32Utils.HardenIndex(acc_idx)), bip_obj.m_coin_type)
Example #4
0
    def _CoinGeneric(cls, bip_obj):
        """ Derive a child key from the coin type specified at construction and return a new Bip object (e.g. BIP44, BIP49, BIP84).
        It shall be called from a child class.

        Args:
            bip_obj (Bip44Base child object): Bip44Base child object (e.g. BIP44, BIP49, BIP84)

        Returns:
            Bip44Base child object: Bip44Base child object

        Raises:
            Bip44DepthError: If the current depth is not suitable for deriving keys
            Bip32KeyError: If the derivation results in an invalid key
        """
        if not cls.IsLevel(bip_obj, Bip44Levels.PURPOSE):
            raise Bip44DepthError("Current depth (%d) is not suitable for deriving coin" % bip_obj.m_bip32.Depth())

        coin_idx = Bip44BaseConst.COIN_TO_IDX[bip_obj.m_coin_type]

        return cls(bip_obj.m_bip32.ChildKey(Bip32Utils.HardenIndex(coin_idx)), bip_obj.m_coin_type)
Example #5
0
class Bip49Const:
    """ Class container for BIP44 constants. """

    # Specification name
    SPEC_NAME: str = "BIP-0049"
    # Purpose
    PURPOSE: int = Bip32Utils.HardenIndex(49)
    # Allowed coins
    ALLOWED_COINS: List[Bip44Coins] = [
        Bip44Coins.BITCOIN,
        Bip44Coins.BITCOIN_TESTNET,
        Bip44Coins.BITCOIN_CASH,
        Bip44Coins.BITCOIN_CASH_TESTNET,
        Bip44Coins.BITCOIN_SV,
        Bip44Coins.BITCOIN_SV_TESTNET,
        Bip44Coins.LITECOIN,
        Bip44Coins.LITECOIN_TESTNET,
        Bip44Coins.DOGECOIN,
        Bip44Coins.DOGECOIN_TESTNET,
        Bip44Coins.DASH,
        Bip44Coins.DASH_TESTNET,
        Bip44Coins.ZCASH,
        Bip44Coins.ZCASH_TESTNET,
    ]
    # Map from Bip44Coins to coin classes
    COIN_TO_CLASS: Dict[Bip44Coins, Type[BipCoinBase]] = {
        Bip44Coins.BITCOIN: Bip49BitcoinMainNet,
        Bip44Coins.BITCOIN_TESTNET: Bip49BitcoinTestNet,
        Bip44Coins.BITCOIN_CASH: Bip49BitcoinCashMainNet,
        Bip44Coins.BITCOIN_CASH_TESTNET: Bip49BitcoinCashTestNet,
        Bip44Coins.BITCOIN_SV: Bip49BitcoinSvMainNet,
        Bip44Coins.BITCOIN_SV_TESTNET: Bip49BitcoinSvTestNet,
        Bip44Coins.LITECOIN: Bip49LitecoinMainNet,
        Bip44Coins.LITECOIN_TESTNET: Bip49LitecoinTestNet,
        Bip44Coins.DOGECOIN: Bip49DogecoinMainNet,
        Bip44Coins.DOGECOIN_TESTNET: Bip49DogecoinTestNet,
        Bip44Coins.DASH: Bip49DashMainNet,
        Bip44Coins.DASH_TESTNET: Bip49DashTestNet,
        Bip44Coins.ZCASH: Bip49ZcashMainNet,
        Bip44Coins.ZCASH_TESTNET: Bip49ZcashTestNet,
    }
Example #6
0
class Bip84Const:
    """ Class container for BIP44 constants. """

    # Specification name
    SPEC_NAME: str = "BIP-0084"
    # Purpose
    PURPOSE: int = Bip32Utils.HardenIndex(84)
    # Allowed coins
    ALLOWED_COINS: List[Bip44Coins] = [
        Bip44Coins.BITCOIN,
        Bip44Coins.BITCOIN_TESTNET,
        Bip44Coins.LITECOIN,
        Bip44Coins.LITECOIN_TESTNET,
    ]
    # Map from Bip44Coins to coin classes
    COIN_TO_CLASS: Dict[Bip44Coins, Type[BipCoinBase]] = {
        Bip44Coins.BITCOIN: Bip84BitcoinMainNet,
        Bip44Coins.BITCOIN_TESTNET: Bip84BitcoinTestNet,
        Bip44Coins.LITECOIN: Bip84LitecoinMainNet,
        Bip44Coins.LITECOIN_TESTNET: Bip84LitecoinTestNet,
    }