mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 03:18:09 +00:00
src: cleanup "utf8" madness
This commit is contained in:
parent
4ebd7d2ad8
commit
bfbc6d5ab9
@ -39,10 +39,10 @@ async def cardano_get_public_key(ctx, msg):
|
||||
def _get_public_key(root_node, derivation_path: list):
|
||||
_, node = derive_address_and_node(root_node, derivation_path)
|
||||
|
||||
public_key = hexlify(seed.remove_ed25519_prefix(node.public_key())).decode("utf8")
|
||||
chain_code = hexlify(node.chain_code()).decode("utf8")
|
||||
public_key = hexlify(seed.remove_ed25519_prefix(node.public_key())).decode()
|
||||
chain_code = hexlify(node.chain_code()).decode()
|
||||
xpub_key = public_key + chain_code
|
||||
root_hd_passphrase = hexlify(_derive_hd_passphrase(root_node)).decode("utf8")
|
||||
root_hd_passphrase = hexlify(_derive_hd_passphrase(root_node)).decode()
|
||||
|
||||
node_type = HDNodeType(
|
||||
depth=node.depth(),
|
||||
|
@ -121,15 +121,15 @@ def _get_asset_data_bytes(msg):
|
||||
if msg.type == LiskTransactionType.Transfer:
|
||||
# Transfer transaction have optional data field
|
||||
if msg.asset.data is not None:
|
||||
return bytes(msg.asset.data, "utf8")
|
||||
return msg.asset.data.encode()
|
||||
else:
|
||||
return b""
|
||||
|
||||
if msg.type == LiskTransactionType.RegisterDelegate:
|
||||
return bytes(msg.asset.delegate.username, "utf8")
|
||||
return msg.asset.delegate.username.encode()
|
||||
|
||||
if msg.type == LiskTransactionType.CastVotes:
|
||||
return bytes("".join(msg.asset.votes), "utf8")
|
||||
return ("".join(msg.asset.votes)).encode()
|
||||
|
||||
if msg.type == LiskTransactionType.RegisterSecondPassphrase:
|
||||
return msg.asset.signature.public_key
|
||||
@ -138,7 +138,7 @@ def _get_asset_data_bytes(msg):
|
||||
data = b""
|
||||
data += ustruct.pack("<b", msg.asset.multisignature.min)
|
||||
data += ustruct.pack("<b", msg.asset.multisignature.life_time)
|
||||
data += bytes("".join(msg.asset.multisignature.keys_group), "utf8")
|
||||
data += ("".join(msg.asset.multisignature.keys_group)).encode()
|
||||
return data
|
||||
|
||||
raise wire.DataError("Invalid transaction type")
|
||||
|
@ -129,8 +129,8 @@ async def _require_confirm_transfer(ctx, recipient, value):
|
||||
await require_confirm(ctx, text, ButtonRequestType.ConfirmOutput)
|
||||
|
||||
|
||||
async def _require_confirm_payload(ctx, payload: bytes, encrypt=False):
|
||||
payload = str(payload, "utf-8")
|
||||
async def _require_confirm_payload(ctx, payload: bytearray, encrypt=False):
|
||||
payload = bytes(payload).decode()
|
||||
|
||||
if len(payload) > 48:
|
||||
payload = payload[:48] + ".."
|
||||
|
@ -191,7 +191,7 @@ async def load_message(reader, msg_type):
|
||||
elif ftype is UnicodeType:
|
||||
fvalue = bytearray(ivalue)
|
||||
await reader.areadinto(fvalue)
|
||||
fvalue = str(fvalue, "utf8")
|
||||
fvalue = bytes(fvalue).decode()
|
||||
elif issubclass(ftype, MessageType):
|
||||
fvalue = await load_message(LimitedReader(reader, ivalue), ftype)
|
||||
else:
|
||||
@ -247,7 +247,7 @@ async def dump_message(writer, msg):
|
||||
await writer.awrite(svalue)
|
||||
|
||||
elif ftype is UnicodeType:
|
||||
bvalue = bytes(svalue, "utf8")
|
||||
bvalue = svalue.encode()
|
||||
await dump_uvarint(writer, len(bvalue))
|
||||
await writer.awrite(bvalue)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user