def create_keystore_file_of_wallet(keystore_file_path, password): """ create both a wallet and a keystore file :param keystore_file_path: File path for the keystore file of the wallet. :param password: Password including alphabet character, number, and special character. :return: Instance of Wallet class. """ if not validate_password(password): raise PasswordIsNotAcceptable try: signer = IcxSigner() byte_private_key = signer.private_key_bytes key_store_contents = create_keyfile_json(byte_private_key, bytes(password, 'utf-8'), iterations=262144) key_store_contents['address'] = "hx" + signer.address.hex() key_store_contents['coinType'] = 'icx' json_string_keystore_data = json.dumps(key_store_contents) store_wallet(keystore_file_path, json_string_keystore_data) wallet = Wallet(key_store_contents) return wallet, signer.private_key_bytes.hex() except FileExistsError: raise FileExists except PermissionError: raise NoPermissionToWriteFile except FileNotFoundError: raise FilePathIsWrong except IsADirectoryError: raise FilePathWithoutFileName
def create_wallet_by_private_key(password, hex_private_key=None): """ create wallet without keystore file :param hex_private_key: the private key with a hexadecimal number :param password :return: Instance of Wallet class. """ try: signer = IcxSigner( bytes.fromhex(hex_private_key) if hex_private_key else None, True if hex_private_key else None) key_store_contents = create_keyfile_json(signer.private_key_bytes, bytes(password, 'utf-8'), iterations=262144) key_store_contents['address'] = "hx" + signer.address.hex() key_store_contents['coinType'] = 'icx' wallet = Wallet(key_store_contents) return_value = (wallet, signer.private_key_bytes.hex()) return return_value except TypeError: raise TypeError
def get_address_by_privkey(privkey_bytes): """ Get address by Private key. :param privkey_bytes: Private key. type(string) """ account = IcxSigner.from_bytes(privkey_bytes) return f'hx{bytes_to_hex(account.address)}'
def create_wallet_by_private_key(hex_private_key=None): """ create wallet without keystore file :param hex_private_key: the private key with a hexadecimal number :return: Instance of Wallet class. """ byte_private_key, is_byte = None, None if hex_private_key: byte_private_key = bytes.fromhex(hex_private_key) is_byte = True try: signer = IcxSigner(byte_private_key, is_byte) wallet = Wallet() wallet.address = "hx" + signer.address.hex() return_value = (wallet, signer.private_key_bytes.hex()) return return_value except TypeError: raise TypeError
def sign_recoverable(private_key_bytes, tx_hash_bytes): """ :param private_key_bytes: Byte private key value. :param tx_hash_bytes: 32 byte tx_hash data. type(bytes) :return: signature_bytes + recovery_id(1) """ signer = IcxSigner.from_bytes(private_key_bytes) signature_bytes, recovery_id = signer.sign_recoverable(tx_hash_bytes) # append recover_id(1 byte) to signature_bytes. return bytes(bytearray(signature_bytes) + recovery_id.to_bytes(1, 'big'))
def make_key_store_content(password): """ Make a content of key_store. :param password: Password including alphabet character, number, and special character. :return: key_store_content(dict) """ signer = IcxSigner() private_key = signer.private_key key_store_contents = create_keyfile_json(private_key, bytes(password, 'utf-8'), iterations=262144) icx_address = "hx" + signer.address.hex() key_store_contents['address'] = icx_address key_store_contents['coinType'] = 'icx' return key_store_contents