Esempio n. 1
0
    def FromSeed(cls, seed_bytes, coin_type):
        """ Create a Bip object (e.g. BIP44, BIP49, BIP84) from the specified seed (e.g. BIP39 seed).
        The test net flag is automatically set when the coin is derived. However, if you want to get the correct master
        or purpose keys, you have to specify here if it's a test net.

        Args:
            seed_bytes (bytes)   : Seed bytes
            coin_type (Bip44Coins): Coin type, must be a Bip44Coins enum

        Returns:
            Bip object: Bip object

        Raises:
            TypeError: If coin index is not a Bip44Coins enum
            ValueError: If the seed is too short
            Bip44CoinNotAllowedError: If the coin is not allowed to derive from the BIP specification
            Bip32KeyError: If the seed is not suitable for master key generation
        """
        if not cls.IsCoinAllowed(coin_type):
            raise Bip44CoinNotAllowedError(
                "Coin %s cannot derive from %s specification" %
                (coin_type, cls.SpecName()))
        return cls(
            Bip32.FromSeed(seed_bytes,
                           cls._GetCoinClass(coin_type).KeyNetVersions()),
            coin_type)
Esempio n. 2
0
    def FromAddressPrivKey(cls, key_bytes, coin_type):
        """ Create a Bip object (e.g. BIP44, BIP49, BIP84) from the specified private key related to an address.

        Args:
            key_bytes (bytes)     : Key bytes
            coin_type (Bip44Coins): Coin type, must be a Bip44Coins enum

        Returns:
            Bip object: Bip object

        Raises:
            TypeError: If coin index is not a Bip44Coins enum
            Bip44CoinNotAllowedError: If the coin is not allowed to derive from the BIP specification
            Bip32KeyError: If the key is not valid
        """
        if not cls.IsCoinAllowed(coin_type):
            raise Bip44CoinNotAllowedError(
                "Coin %s cannot derive from %s specification" %
                (coin_type, cls.SpecName()))
        return cls(
            Bip32(key_bytes,
                  b"",
                  Bip44Levels.ADDRESS_INDEX,
                  key_net_ver=cls._GetCoinClass(coin_type).KeyNetVersions()),
            coin_type)
Esempio n. 3
0
    def FromExtendedKey(cls, key_str, coin_type):
        """ Create a Bip object (e.g. BIP44, BIP49, BIP84) from the specified extended key.

        Args:
            key_str (str)        : Extended key string
            coin_type (Bip44Coins): Coin type, must be a Bip44Coins enum

        Returns:
            Bip object: Bip object

        Raises:
            TypeError: If coin index is not a Bip44Coins enum
            Bip44CoinNotAllowedError: If the coin is not allowed to derive from the BIP specification
            Bip32KeyError: If the extended key is not valid
        """
        if not cls.IsCoinAllowed(coin_type):
            raise Bip44CoinNotAllowedError("Coin %s cannot derive from %s specification" % (coin_type, cls.SpecName()))
        return cls(Bip32.FromExtendedKey(key_str, cls._GetCoinClass(coin_type).KeyNetVersions()), coin_type)