def __init__(self, network: str = config["network"]): if network == "mainnet": self._network: str = "mainnet" self._cryptocurrency: Any = BitcoinMainnet self._hdwallet: HDWallet = HDWallet(cryptocurrency=BitcoinMainnet) elif network == "testnet": self._network: str = "testnet" self._cryptocurrency: Any = BitcoinTestnet self._hdwallet: HDWallet = HDWallet(cryptocurrency=BitcoinTestnet) else: raise NetworkError(f"Invalid Bitcoin '{network}' network", "choose only 'mainnet' or 'testnet' networks.") super().__init__(cryptocurrency=self._cryptocurrency)
def __init__(self, network: str = config["network"], provider: str = config["provider"]): super().__init__(cryptocurrency=XinFinMainnet) # Check parameter instances if not is_network(network=network): raise NetworkError( f"Invalid XinFin '{network}' network", "choose only 'mainnet', 'apothem' or 'testnet' networks.") self._network, self._provider, = network, provider self._hdwallet: HDWallet = HDWallet(cryptocurrency=XinFinMainnet, use_default_path=False)
def __init__(self, network: str = config["network"], provider: str = config["provider"], token: Optional[str] = None): super().__init__(cryptocurrency=EthereumMainnet) # Check parameter instances if not is_network(network=network): raise NetworkError( f"Invalid Ethereum '{network}' network", "choose only 'mainnet', 'ropsten', 'kovan', 'rinkeby' or 'testnet' networks." ) self._network, self._provider, self._token = network, provider, token self._hdwallet: HDWallet = HDWallet(cryptocurrency=EthereumMainnet, use_default_path=False)
def __init__(self, network: str = config["network"], use_default_path: bool = False): # Check parameter instances if not is_network(network=network): raise NetworkError(f"Invalid Bitcoin '{network}' network", "choose only 'mainnet' or 'testnet' networks.") self._network: str = network self._cryptocurrency: Any = (BitcoinMainnet if self._network == "mainnet" else BitcoinTestnet) self._hdwallet: HDWallet = HDWallet( cryptocurrency=self._cryptocurrency, use_default_path=use_default_path) super().__init__(cryptocurrency=self._cryptocurrency)
#!/usr/bin/env python3 from hdwallet import HDWallet from hdwallet.symbols import DOGE as SYMBOL import json # Mnemonic words seed SEED: str = "b3337a2fe409afbb257b504e4c09d36b57c32c452b71a0ed413298a5172f727a06bf660548" \ "8723bc545a4bd51f5cd29a3e8bd1433bd1d26e6bf866ff53d1493f" # Initialize Dogecoin mainnet HDWallet hdwallet: HDWallet = HDWallet(symbol=SYMBOL) # Get Dogecoin HDWallet from seed hdwallet.from_seed(seed=SEED) # Derivation from path # hdwallet.from_path("m/44'/3'/0'/0/0") # Or derivation from index hdwallet.from_index(44, hardened=True) hdwallet.from_index(3, hardened=True) hdwallet.from_index(0, hardened=True) hdwallet.from_index(0) hdwallet.from_index(0) # Print all Dogecoin HDWallet information's # print(json.dumps(hdwallet.dumps(), indent=4, ensure_ascii=False)) print("Cryptocurrency:", hdwallet.cryptocurrency()) print("Symbol:", hdwallet.symbol()) print("Network:", hdwallet.network())
def test_from_seed(): hdwallet: HDWallet = HDWallet(symbol=_["bitcoin"]["testnet"]["symbol"]) hdwallet.from_seed(seed=_["bitcoin"]["testnet"]["seed"]).from_path( path=_["bitcoin"]["testnet"]["path"]) assert hdwallet.cryptocurrency( ) == _["bitcoin"]["testnet"]["cryptocurrency"] assert hdwallet.symbol() == _["bitcoin"]["testnet"]["symbol"] assert hdwallet.network() == _["bitcoin"]["testnet"]["network"] assert hdwallet.strength() is None assert hdwallet.entropy() is None assert hdwallet.mnemonic() is None assert hdwallet.language() is None assert hdwallet.passphrase() is None assert hdwallet.seed() == _["bitcoin"]["testnet"]["seed"] assert hdwallet.root_xprivate_key( encoded=False) == _["bitcoin"]["testnet"]["root_xprivate_key_hex"] assert hdwallet.root_xprivate_key( ) == _["bitcoin"]["testnet"]["root_xprivate_key"] assert hdwallet.root_xpublic_key( encoded=False) == _["bitcoin"]["testnet"]["root_xpublic_key_hex"] assert hdwallet.root_xpublic_key( ) == _["bitcoin"]["testnet"]["root_xpublic_key"] assert hdwallet.xprivate_key( encoded=False) == _["bitcoin"]["testnet"]["xprivate_key_hex"] assert hdwallet.xprivate_key() == _["bitcoin"]["testnet"]["xprivate_key"] assert hdwallet.xpublic_key( encoded=False) == _["bitcoin"]["testnet"]["xpublic_key_hex"] assert hdwallet.xpublic_key() == _["bitcoin"]["testnet"]["xpublic_key"] assert hdwallet.uncompressed() == _["bitcoin"]["testnet"]["uncompressed"] assert hdwallet.compressed() == _["bitcoin"]["testnet"]["compressed"] assert hdwallet.chain_code() == _["bitcoin"]["testnet"]["chain_code"] assert hdwallet.private_key() == _["bitcoin"]["testnet"]["private_key"] assert hdwallet.public_key() == _["bitcoin"]["testnet"]["public_key"] assert hdwallet.wif() == _["bitcoin"]["testnet"]["wif"] assert hdwallet.finger_print() == _["bitcoin"]["testnet"]["finger_print"] assert hdwallet.semantic() == _["bitcoin"]["testnet"]["semantic"] assert hdwallet.path() == _["bitcoin"]["testnet"]["path"] assert hdwallet.hash() == _["bitcoin"]["testnet"]["hash"] assert hdwallet.p2pkh_address( ) == _["bitcoin"]["testnet"]["addresses"]["p2pkh"] assert hdwallet.p2sh_address( ) == _["bitcoin"]["testnet"]["addresses"]["p2sh"] assert hdwallet.p2wpkh_address( ) == _["bitcoin"]["testnet"]["addresses"]["p2wpkh"] assert hdwallet.p2wpkh_in_p2sh_address( ) == _["bitcoin"]["testnet"]["addresses"]["p2wpkh_in_p2sh"] assert hdwallet.p2wsh_address( ) == _["bitcoin"]["testnet"]["addresses"]["p2wsh"] assert hdwallet.p2wsh_in_p2sh_address( ) == _["bitcoin"]["testnet"]["addresses"]["p2wsh_in_p2sh"] assert isinstance(hdwallet.dumps(), dict) dumps: dict = _["bitcoin"]["testnet"] dumps["strength"] = None dumps["entropy"] = None dumps["mnemonic"] = None dumps["language"] = None dumps["passphrase"] = None del dumps["root_xprivate_key_hex"] del dumps["root_xpublic_key_hex"] del dumps["xprivate_key_hex"] del dumps["xpublic_key_hex"] assert hdwallet.dumps() == dumps
#!/usr/bin/env python3 from hdwallet import HDWallet from hdwallet.symbols import BTCTEST import json # Bitcoin wallet important format WALLET_IMPORTANT_FORMAT: str = "cVpnZ6XRfL5VVggwZDyndAU5KGVdT2TP1j1HB3td6ZKWCbh5wYvf" # Initialize Bitcoin testnet HDWallet hdwallet: HDWallet = HDWallet(symbol=BTCTEST) # Get Bitcoin HDWallet from wallet important format hdwallet.from_wif(wif=WALLET_IMPORTANT_FORMAT) # Print all Bitcoin HDWallet information's # print(json.dumps(hdwallet.dumps(), indent=4, ensure_ascii=False)) print("Cryptocurrency:", hdwallet.cryptocurrency()) print("Symbol:", hdwallet.symbol()) print("Network:", hdwallet.network()) print("Uncompressed:", hdwallet.uncompressed()) print("Compressed:", hdwallet.compressed()) print("Private Key:", hdwallet.private_key()) print("Public Key:", hdwallet.public_key()) print("Wallet Important Format:", hdwallet.wif()) print("Finger Print:", hdwallet.finger_print()) print("Semantic:", hdwallet.semantic()) print("Path:", hdwallet.path()) print("Hash:", hdwallet.hash()) print("P2PKH Address:", hdwallet.p2pkh_address())
def generate_addresses( symbol: str, strength: int, entropy: Optional[str], mnemonic: Optional[str], language: Optional[str], passphrase: Optional[str], seed: Optional[str], xprivate_key: Optional[str], xpublic_key: Optional[str], strict: bool, account: int, change: bool, path: Optional[str], semantic: str, start_index: int, end_index: int, hardened: bool, show: str ): try: hdwallet: HDWallet = HDWallet( symbol=symbol, semantic=semantic ) if entropy: hdwallet.from_entropy( entropy=entropy, language=language, passphrase=passphrase ) elif mnemonic: hdwallet.from_mnemonic( mnemonic=mnemonic, language=language, passphrase=passphrase ) elif seed: hdwallet.from_seed( seed=seed ) elif xprivate_key: hdwallet.from_xprivate_key( xprivate_key=xprivate_key, strict=strict ) elif xpublic_key: hdwallet.from_xpublic_key( xpublic_key=xpublic_key, strict=strict ) else: mnemonic = generate_mnemonic(language=language, strength=strength) hdwallet.from_mnemonic( mnemonic=mnemonic, language=language, passphrase=passphrase ) for index in range(start_index, end_index): if path: derivation: Derivation = Derivation(path=path) derivation.from_index(index=index, hardened=hardened) hdwallet.from_path(path=derivation) else: cryptocurrency: Cryptocurrency = get_cryptocurrency(symbol=symbol) bip32_derivation: BIP32Derivation = BIP32Derivation( purpose=( 44, False if xpublic_key else True ), coin_type=( cryptocurrency.COIN_TYPE.INDEX, False if xpublic_key else cryptocurrency.COIN_TYPE.HARDENED ), account=( account, False if xpublic_key else True ), change=change, address=index ) hdwallet.from_path(path=bip32_derivation) rows: str = "" dumps = hdwallet.dumps() for i, key in enumerate([keys.split(":") for keys in show.split(",")]): rows += ( f"{dumps[key[0]][key[1]] if len(key) == 2 else dumps[key[0]]}" if i == 0 else f" {dumps[key[0]][key[1]] if len(key) == 2 else dumps[key[0]]}" ) click.echo(rows) hdwallet.clean_derivation() except TimeoutError as exception: click.echo(click.style(f"Error: {str(exception)}"), err=True) sys.exit()
#!/usr/bin/env python3 from hdwallet import HDWallet from hdwallet.symbols import DOGE import json # Mnemonic words seed SEED: str = "b3337a2fe409afbb257b504e4c09d36b57c32c452b71a0ed413298a5172f727a06bf660548" \ "8723bc545a4bd51f5cd29a3e8bd1433bd1d26e6bf866ff53d1493f" # Initialize Dogecoin mainnet HDWallet hdwallet: HDWallet = HDWallet(symbol=DOGE) # Get Dogecoin HDWallet from seed hdwallet.from_seed(seed=SEED) # Derivation from path # hdwallet.from_path("m/44'/3'/0'/0/0") # Or derivation from index hdwallet.from_index(44, hardened=True) hdwallet.from_index(3, hardened=True) hdwallet.from_index(0, hardened=True) hdwallet.from_index(0) hdwallet.from_index(0) # Print all Dogecoin HDWallet information's # print(json.dumps(hdwallet.dumps(), indent=4, ensure_ascii=False)) print("Cryptocurrency:", hdwallet.cryptocurrency()) print("Symbol:", hdwallet.symbol()) print("Network:", hdwallet.network())
#!/usr/bin/env python3 from hdwallet import HDWallet from hdwallet.symbols import QTUM import json # Qtum private key PRIVATE_KEY: str = "f86d5afe2a457c29357485ebf853a1e5ff5f6fcf1ba4d7d1412665e01449902e" # Initialize Qtum mainnet HDWallet hdwallet: HDWallet = HDWallet(symbol=QTUM) # Get Qtum HDWallet from private key hdwallet.from_private_key(private_key=PRIVATE_KEY) # Print all Qtum HDWallet information's # print(json.dumps(hdwallet.dumps(), indent=4, ensure_ascii=False)) print("Cryptocurrency:", hdwallet.cryptocurrency()) print("Symbol:", hdwallet.symbol()) print("Network:", hdwallet.network()) print("Uncompressed:", hdwallet.uncompressed()) print("Compressed:", hdwallet.compressed()) print("Private Key:", hdwallet.private_key()) print("Public Key:", hdwallet.public_key()) print("Wallet Important Format:", hdwallet.wif()) print("Finger Print:", hdwallet.finger_print()) print("Semantic:", hdwallet.semantic()) print("Path:", hdwallet.path()) print("Hash:", hdwallet.hash()) print("P2PKH Address:", hdwallet.p2pkh_address())
def test_from_xpublic_key(): hdwallet: HDWallet = HDWallet( symbol=_["bitcoin"]["mainnet"]["symbol"] ) hdwallet.from_xpublic_key( xpublic_key=_["bitcoin"]["mainnet"]["root_xpublic_key"], strict=True ) hdwallet.from_path( path="m/44/0/0/0/0" ) assert hdwallet.cryptocurrency() == _["bitcoin"]["mainnet"]["cryptocurrency"] assert hdwallet.symbol() == _["bitcoin"]["mainnet"]["symbol"] assert hdwallet.network() == _["bitcoin"]["mainnet"]["network"] assert hdwallet.strength() is None assert hdwallet.entropy() is None assert hdwallet.mnemonic() is None assert hdwallet.language() is None assert hdwallet.passphrase() is None assert hdwallet.seed() is None assert hdwallet.root_xprivate_key(encoded=False) is None assert hdwallet.root_xprivate_key() is None assert hdwallet.root_xpublic_key(encoded=False) == "0488b21e000000000000000000ad41ef910cdcae932cb4060777b4284ee38f5b29c5fb60fda8416f298a14702c02949b9f64223e124eb9a8383fba0b21b5845fcfbdc84dec7692d21c716410eab0" assert hdwallet.root_xpublic_key() == "xpub661MyMwAqRbcGGUtsoFw2d6ARvD2ABd7z327zxt2XiBBwMx9GAuNrrE7tbRuWF5MjjZ1BzDsRdaSHc9nVKAgHzQrv6pwYW3Hd7LSzbh8sWS" assert hdwallet.xprivate_key(encoded=False) is None assert hdwallet.xprivate_key() is None assert hdwallet.xpublic_key(encoded=False) == "0488b21e052c0269af000000006c95c19e932b9e8f3d834e874526768ca1b3d89933ad71fd8253bcca67ac283d038f24175db513b40c75503c25040e5f0ea4d38e912d1f83daf5fd8c4b9512ad87" assert hdwallet.xpublic_key() == "xpub6FjoSaU1JaG6fC6wTYmb1mJzaZxSunxASN7nTRHhFynh33gKRfmmNrtQ82s8YouLCrEniskjumfACiiTyVmi4aXyLL8HvLdZc8mjKsbzT9z" assert hdwallet.uncompressed() == "8f24175db513b40c75503c25040e5f0ea4d38e912d1f83daf5fd8c4b9512ad8750a64d9e0ee3555225e4130c7e36a443ec20330bf0be1e4de913e31e00202993" assert hdwallet.compressed() == "038f24175db513b40c75503c25040e5f0ea4d38e912d1f83daf5fd8c4b9512ad87" assert hdwallet.chain_code() == "6c95c19e932b9e8f3d834e874526768ca1b3d89933ad71fd8253bcca67ac283d" assert hdwallet.private_key() is None assert hdwallet.public_key() == "038f24175db513b40c75503c25040e5f0ea4d38e912d1f83daf5fd8c4b9512ad87" assert hdwallet.wif() is None assert hdwallet.finger_print() == "4e749a26" assert hdwallet.semantic() == "p2pkh" assert hdwallet.path() == "m/44/0/0/0/0" assert hdwallet.hash() == "4e749a26934bca5091a05ee6f55e7d0e21482647" assert hdwallet.p2pkh_address() == "189qPd6J81ns9LEGx6kun7Xtg1bJV8GJXh" assert hdwallet.p2sh_address() == "3C71bNRojv3Gc7zHvWygas4AFt34rKezcF" assert hdwallet.p2wpkh_address() == "bc1qfe6f5f5nf099pydqtmn02hnapcs5sfj86dpqjm" assert hdwallet.p2wpkh_in_p2sh_address() == "3NykoodgJ7Li43JPt5xsezQz8xfwwwFZUs" assert hdwallet.p2wsh_address() == "bc1qazm6kznlgs06exh4cq2qxh567xrffppwujje5zg84upnng4essusd08nhz" assert hdwallet.p2wsh_in_p2sh_address() == "32yGj8ncXBBTjXqg188ZHxd1xffoQDcjin" assert isinstance(hdwallet.dumps(), dict) hdwallet: HDWallet = HDWallet( symbol=_["bitcoin"]["testnet"]["symbol"] ) hdwallet.from_xpublic_key( xpublic_key=_["bitcoin"]["testnet"]["xpublic_key"], strict=False ) assert hdwallet.cryptocurrency() == _["bitcoin"]["testnet"]["cryptocurrency"] assert hdwallet.symbol() == _["bitcoin"]["testnet"]["symbol"] assert hdwallet.network() == _["bitcoin"]["testnet"]["network"] assert hdwallet.strength() is None assert hdwallet.entropy() is None assert hdwallet.mnemonic() is None assert hdwallet.language() is None assert hdwallet.passphrase() is None assert hdwallet.seed() is None assert hdwallet.root_xprivate_key(encoded=False) is None assert hdwallet.root_xprivate_key() is None assert hdwallet.root_xpublic_key(encoded=False) == _["bitcoin"]["testnet"]["xpublic_key_hex"] assert hdwallet.root_xpublic_key() == _["bitcoin"]["testnet"]["xpublic_key"] assert hdwallet.xprivate_key(encoded=False) is None assert hdwallet.xprivate_key() is None assert hdwallet.xpublic_key(encoded=False) == _["bitcoin"]["testnet"]["xpublic_key_hex"] assert hdwallet.xpublic_key() == _["bitcoin"]["testnet"]["xpublic_key"] assert hdwallet.uncompressed() == _["bitcoin"]["testnet"]["uncompressed"] assert hdwallet.uncompressed(compressed=_["bitcoin"]["testnet"]["compressed"]) == _["bitcoin"]["testnet"]["uncompressed"] assert hdwallet.compressed() == _["bitcoin"]["testnet"]["compressed"] assert hdwallet.compressed(uncompressed=_["bitcoin"]["testnet"]["uncompressed"]) == _["bitcoin"]["testnet"]["compressed"] assert hdwallet.chain_code() == _["bitcoin"]["testnet"]["chain_code"] assert hdwallet.private_key() is None assert hdwallet.public_key() == _["bitcoin"]["testnet"]["public_key"] assert hdwallet.wif() is None assert hdwallet.finger_print() == _["bitcoin"]["testnet"]["finger_print"] assert hdwallet.semantic() == _["bitcoin"]["testnet"]["semantic"] assert hdwallet.path() == None assert hdwallet.hash() == _["bitcoin"]["testnet"]["hash"] assert hdwallet.p2pkh_address() == _["bitcoin"]["testnet"]["addresses"]["p2pkh"] assert hdwallet.p2sh_address() == _["bitcoin"]["testnet"]["addresses"]["p2sh"] assert hdwallet.p2wpkh_address() == _["bitcoin"]["testnet"]["addresses"]["p2wpkh"] assert hdwallet.p2wpkh_in_p2sh_address() == _["bitcoin"]["testnet"]["addresses"]["p2wpkh_in_p2sh"] assert hdwallet.p2wsh_address() == _["bitcoin"]["testnet"]["addresses"]["p2wsh"] assert hdwallet.p2wsh_in_p2sh_address() == _["bitcoin"]["testnet"]["addresses"]["p2wsh_in_p2sh"] assert isinstance(hdwallet.dumps(), dict) dumps: dict = _["bitcoin"]["testnet"] dumps["strength"] = None dumps["entropy"] = None dumps["mnemonic"] = None dumps["language"] = None dumps["passphrase"] = None dumps["seed"] = None dumps["root_xprivate_key"] = None dumps["xprivate_key"] = None dumps["private_key"] = None dumps["wif"] = None dumps["path"] = None dumps["root_xpublic_key"] = _["bitcoin"]["testnet"]["xpublic_key"] del dumps["root_xprivate_key_hex"] del dumps["root_xpublic_key_hex"] del dumps["xprivate_key_hex"] del dumps["xpublic_key_hex"] assert hdwallet.dumps() == dumps
def generate_hdwallet(symbol: str, strength: Optional[int], entropy: Optional[str], mnemonic: Optional[str], language: Optional[str], passphrase: Optional[str], seed: Optional[str], xprivate_key: Optional[str], xpublic_key: Optional[str], strict: Optional[bool], account: int, change: bool, address: int, path: Optional[str], private_key: Optional[str], public_key: Optional[str], wif: Optional[str], semantic: str): try: hdwallet: HDWallet = HDWallet(symbol=symbol, semantic=semantic) if entropy: hdwallet.from_entropy(entropy=entropy, language=language, passphrase=passphrase) elif mnemonic: hdwallet.from_mnemonic(mnemonic=mnemonic, language=language, passphrase=passphrase) elif seed: hdwallet.from_seed(seed=seed) elif xprivate_key: hdwallet.from_xprivate_key(xprivate_key=xprivate_key, strict=strict) elif xpublic_key: hdwallet.from_xpublic_key(xpublic_key=xpublic_key, strict=strict) elif private_key: hdwallet.from_private_key(private_key=private_key) elif public_key: hdwallet.from_public_key(public_key=public_key) elif wif: hdwallet.from_wif(wif=wif) else: mnemonic = generate_mnemonic(language=language, strength=strength) hdwallet.from_mnemonic(mnemonic=mnemonic, language=language, passphrase=passphrase) if wif or private_key or public_key: pass else: if path: derivation: Derivation = Derivation(path=path) hdwallet.from_path(path=derivation) else: cryptocurrency: Cryptocurrency = get_cryptocurrency( symbol=symbol) bip32_derivation: BIP32Derivation = BIP32Derivation( purpose=(44, False if xpublic_key else True), coin_type=(cryptocurrency.COIN_TYPE.INDEX, False if xpublic_key else cryptocurrency.COIN_TYPE.HARDENED), account=(account, False if xpublic_key else True), change=change, address=address) hdwallet.from_path(path=bip32_derivation) click.echo(json.dumps(hdwallet.dumps(), indent=4, ensure_ascii=False)) except Exception as exception: click.echo(click.style(f"Error: {str(exception)}"), err=True) sys.exit()
#!/usr/bin/env python3 from hdwallet import HDWallet from hdwallet.symbols import ETH import json # Ethereum xprivate key XPRIVATE_KEY = "xprvA3KRgVDh45mbQT1VmWPx73YeAWM4629Q2D9pMuqjFMnjTqDGhKiww6H" \ "532rgYRNj37fngd4Mvp7GfUD8rKeQzUZjCWeisT92tX8FfjWx3BL" # Initialize Ethereum mainnet HDWallet hdwallet: HDWallet = HDWallet(symbol=ETH) # Get Ethereum HDWallet from xprivate key hdwallet.from_xprivate_key(xprivate_key=XPRIVATE_KEY) # Print all Ethereum HDWallet information's # print(json.dumps(hdwallet.dumps(), indent=4, ensure_ascii=False)) print("Cryptocurrency:", hdwallet.cryptocurrency()) print("Symbol:", hdwallet.symbol()) print("Network:", hdwallet.network()) print("XPrivate Key:", hdwallet.xprivate_key()) print("XPublic Key:", hdwallet.xpublic_key()) print("Uncompressed:", hdwallet.uncompressed()) print("Compressed:", hdwallet.compressed()) print("Chain Code:", hdwallet.chain_code()) print("Private Key:", hdwallet.private_key()) print("Public Key:", hdwallet.public_key()) print("Wallet Important Format:", hdwallet.wif()) print("Finger Print:", hdwallet.finger_print())