Exemplo n.º 1
0
 def private_key(self):
     if self.mnemonic and self.network_type == NetworkType.ETHEREUM_LIKE:
         hd_wallet = BIP44HDWallet(symbol=ETH,
                                   account=0,
                                   change=False,
                                   address=0)
         hd_wallet.from_mnemonic(mnemonic=self.mnemonic)
         return hd_wallet.private_key()
     else:
         return self._private_key
Exemplo n.º 2
0
    def generate_wallet_from_private_key(self, private_key):
        bip44_hdwallet: BIP44HDWallet = BIP44HDWallet(
            cryptocurrency=EthereumMainnet)

        # Get Ethereum BIP44HDWallet from private_key
        bip44_hdwallet.from_private_key(private_key=private_key)

        # Clean default BIP44 derivation indexes/paths
        bip44_hdwallet.clean_derivation()

        self.wallet = bip44_hdwallet
Exemplo n.º 3
0
    def generate_wallet(self, mnemonic: str = None):
        bip44_hdwallet: BIP44HDWallet = BIP44HDWallet(
            cryptocurrency=EthereumMainnet)

        if not mnemonic:
            mnemonic = generate_mnemonic(language="english", strength=128)

        # Get Ethereum BIP44HDWallet from mnemonic
        bip44_hdwallet.from_mnemonic(
            mnemonic=mnemonic,
            language="english",
            # passphrase=PASSPHRASE
        )
        # Clean default BIP44 derivation indexes/paths
        bip44_hdwallet.clean_derivation()

        # print("Mnemonic:", bip44_hdwallet.mnemonic())
        self.wallet = bip44_hdwallet
Exemplo n.º 4
0
def generate_hdwallet(mnemonic: str = MNEMONIC,
                      cryptocurrency=EthereumMainnet,
                      passphrase: Optional[str] = None) -> BIP44HDWallet:
    """[summary]
    Args:
        cryptocurrency (hdwallet.cryptocurrencies, optional): crypto of the wallet. Defaults to EthereumMainnet.
        mnemonic (str, optional): mnemonic phrase from where we generate the wallet. Defaults to MNEMONIC.
        passphrase (Optional[str], optional): Secret passphrase/password for mnemonic. Defaults to None.
    Returns:
        BIP44HDWallet : wallet generate from mnemonic
    """

    ## Initialize Ethereum mainnet BIP44HDWallet
    bip44_hdwallet = BIP44HDWallet(cryptocurrency=EthereumMainnet)
    ## Get Ethereum BIP44HDWallet from mnemonic
    bip44_hdwallet.from_mnemonic(mnemonic=mnemonic, passphrase=passphrase)
    # print("Mnemonic:", bip44_hdwallet.mnemonic())

    ## Clean default BIP44 derivation indexes/paths
    bip44_hdwallet.clean_derivation()

    return bip44_hdwallet
Exemplo n.º 5
0
def generate_list_adresses_keys(bip44_hdwallet: BIP44HDWallet,
                                n_address: int) -> List[str]:
    list_of_addresses_keys = []
    for address_index in range(n_address):
        ## Derivation from Ethereum BIP44 derivation path
        bip44_derivation = BIP44Derivation(cryptocurrency=EthereumMainnet,
                                           account=0,
                                           change=False,
                                           address=address_index)
        ## Drive Ethereum HDWallet
        bip44_hdwallet.from_path(path=bip44_derivation)

        ## Append public and private key to the list
        list_of_addresses_keys.append(
            (bip44_hdwallet.address(), bip44_hdwallet.private_key()))

        # Clean derivation indexes/paths
        bip44_hdwallet.clean_derivation()

    return list_of_addresses_keys
Exemplo n.º 6
0
def get_whitelabel_address(contract_id):
    hd_wallet = BIP44HDWallet(symbol=ETH, account=0, change=False, address=0)
    hd_wallet.from_root_xprivate_key(ROOT_EXT_KEY)
    derived_wallet = hd_wallet.from_index(contract_id)
    address = derived_wallet.address()
    return address
Exemplo n.º 7
0
#!/usr/bin/env python3

from hdwallet import BIP44HDWallet
from hdwallet.cryptocurrencies import EthereumMainnet
from hdwallet.derivations import BIP44Derivation
from hdwallet.utils import generate_mnemonic
from typing import Optional

# Generate english mnemonic words
MNEMONIC: str = generate_mnemonic(language="english", strength=128)
# Secret passphrase/password for mnemonic
PASSPHRASE: Optional[str] = None  # str("meherett")

# Initialize Ethereum mainnet BIP44HDWallet
bip44_hdwallet: BIP44HDWallet = BIP44HDWallet(cryptocurrency=EthereumMainnet)
# Get Ethereum BIP44HDWallet from mnemonic
bip44_hdwallet.from_mnemonic(mnemonic=MNEMONIC, passphrase=PASSPHRASE)
# Clean default BIP44 derivation indexes/paths
bip44_hdwallet.clean_derivation()

print("Mnemonic:", bip44_hdwallet.mnemonic())
print("Base HD Path:  m/44'/60'/0'/0/{address_index}", "\n")

# Get Ethereum BIP44HDWallet information's from address index
for address_index in range(10):
    # Derivation from Ethereum BIP44 derivation path
    bip44_derivation: BIP44Derivation = BIP44Derivation(
        cryptocurrency=EthereumMainnet,
        account=0,
        change=False,
        address=address_index)
Exemplo n.º 8
0
# Choose strength 128, 160, 192, 224 or 256
STRENGTH: int = 160  # Default is 128
# Choose language english, french, italian, spanish, chinese_simplified, chinese_traditional, japanese or korean
LANGUAGE: str = "italian"  # Default is english
# Generate new mnemonic words
MNEMONIC: str = generate_mnemonic(language=LANGUAGE, strength=STRENGTH)
# Secret passphrase/password for mnemonic
PASSPHRASE: str = "meherett"

# Check mnemonic words
assert is_mnemonic(mnemonic=MNEMONIC, language=LANGUAGE)

# Initialize Litecoin mainnet HDWallet
bip44_hdwallet: BIP44HDWallet = BIP44HDWallet(
    cryptocurrency=Cryptocurrency, account=0, change=False, address=0
)
# Get Litecoin HDWallet from mnemonic
bip44_hdwallet.from_mnemonic(
    mnemonic=MNEMONIC, passphrase=PASSPHRASE, language=LANGUAGE
)

# Print all Litecoin HDWallet information's
# print(json.dumps(bip44_hdwallet.dumps(), indent=4, ensure_ascii=False))

print("Cryptocurrency:", bip44_hdwallet.cryptocurrency())
print("Symbol:", bip44_hdwallet.symbol())
print("Network:", bip44_hdwallet.network())
print("Strength:", bip44_hdwallet.strength())
print("Entropy:", bip44_hdwallet.entropy())
print("Mnemonic:", bip44_hdwallet.mnemonic())