def do_new_hdkey(self, msg): 'make hd_key, [-m] - from mnemonic phrase' msg = msg.split() testnet = True if self.net == 0x6f else False if (len(msg) == 0): try: e = secrets.token_bytes(32) self.hd_key = bip32.bip32_key.from_entropy(entropy=e,testnet= testnet) print (f'mnemonic phrase:\n{bip39.mnemonic_from_entropy(e)}') priv_key = self.hd_key.Prv_key()[1:] self.key_pair = k_box(priv_key.hex()) with open(_program_dir + "/address", 'a') as f: f.write(f"{self.key_pair.get_address()}\n") print(f"key pair generated") print(f"Private key(WIF): {wallet.to_WIF(self.key_pair.get_secret_key().hex())}") print(f"Address : {self.key_pair.get_address()}") except Exception as e: print (f'Error [{e}]') return False elif msg[0] == "-m": mnemonic = " ".join(msg[1:]) try: e = bip39.entropy_from_mnemonic(mnemonic) self.hd_key = bip32.bip32_key.from_entropy(entropy= e ,testnet=testnet) print (f'mnemonic phrase:\n{bip39.mnemonic_from_entropy(e)}') priv_key = self.hd_key.Prv_key()[1:] self.key_pair = k_box(priv_key.hex()) with open(_program_dir + "/address", 'a') as f: f.write(f"{self.key_pair.get_address()}\n") print(f"key pair generated") print(f"Private key(WIF): {wallet.to_WIF(self.key_pair.get_secret_key().hex())}") print(f"Address : {self.key_pair.get_address()}") except Exception as e: print (f'Error [{e}]') return False
def do_import_hd_key(self, inp): try: self.hd_key = bip32.bip32_key.from_xpub(inp) priv_key = self.hd_key.Prv_key()[1:] self.key_pair = k_box(priv_key.hex()) with open(_program_dir + "/address", 'a') as f: f.write(f"{self.key_pair.get_address()}\n") print(f"Private key(WIF): {wallet.to_WIF(self.key_pair.get_secret_key().hex())}") print(f"Address : {self.key_pair.get_address()}") except Exception as e: print(f'Error [{e}]') return False
def do_new(self, inp): 'Make new key pair' if self.key_pair != 0: print( "Already there is key pair, if continue it would be deleted. Continue ? (n/y):" ) if input() == "n": return False print(f"key pair generated") self.key_pair = k_box() print( f"Private key(WIF): {wallet.to_WIF(self.key_pair.get_secret_key().hex())}" ) print(f"Address : {self.key_pair.get_address()}")
def do_chain(self, inp): if self.hd_key == 0: print(" Haven`t hd key") return False try: tmp = bip32.chain(inp, self.hd_key) self.hd_key = tmp priv_key = self.hd_key.Prv_key()[1:] self.key_pair = k_box(priv_key.hex()) with open(_program_dir + "/address", 'a') as f: f.write(f"{self.key_pair.get_address()}\n") print(f"key pair generated") print(f"extended_format") print(f"Private key(WIF): {wallet.to_WIF(self.key_pair.get_secret_key().hex())}") print(f"Address : {self.key_pair.get_address()}") except Exception as e: print(f"Error [{e}]")
def do_new(self, inp): 'Make new key pair' if self.key_pair != 0: print("Already there is key pair, if continue it would be deleted. Continue ? (n/y):") if input() == "n": return False try: self.key_pair = k_box(net = self.net) with open(_program_dir + "/address", 'a') as f: f.write(f"{self.key_pair.get_address()}\n") print(f"key pair generated") print(f"Private key(WIF): {wallet.to_WIF(self.key_pair.get_secret_key().hex())}") print(f"Address : {self.key_pair.get_address()}") return False except Exception as e: print (f'Error: [{e}]') return False