chore(core): fix typing and kwargs usage

pull/1279/head
matejcik 4 years ago committed by matejcik
parent ef4022fbf5
commit 244b264b47

@ -17,4 +17,4 @@ async def get_public_key(ctx, msg: BinanceGetPublicKey, keychain: Keychain):
if msg.show_display:
await layout.show_pubkey(ctx, pubkey)
return BinancePublicKey(pubkey)
return BinancePublicKey(public_key=pubkey)

@ -10,10 +10,10 @@ from apps.common.writers import write_bitcoin_varint
if False:
from typing import List
from apps.common.coininfo import CoinType
from apps.common.coininfo import CoinInfo
def message_digest(coin: CoinType, message: bytes) -> bytes:
def message_digest(coin: CoinInfo, message: bytes) -> bytes:
if not utils.BITCOIN_ONLY and coin.decred:
h = utils.HashWriter(blake256())
else:
@ -21,7 +21,7 @@ def message_digest(coin: CoinType, message: bytes) -> bytes:
if not coin.signed_message_header:
raise wire.DataError("Empty message header not allowed.")
write_bitcoin_varint(h, len(coin.signed_message_header))
h.extend(coin.signed_message_header)
h.extend(coin.signed_message_header.encode())
write_bitcoin_varint(h, len(message))
h.extend(message)
ret = h.get_digest()
@ -44,9 +44,9 @@ async def require_confirm_sign_message(
ctx: wire.Context, coin: str, message: bytes
) -> None:
header = "Sign {} message".format(coin)
message = split_message(message)
message_lines = split_message(message)
text = Text(header, new_lines=False)
text.normal(*message)
text.normal(*message_lines)
await require_confirm(ctx, text)

@ -31,4 +31,4 @@ async def get_public_key(
wif, public_key = _get_public_key(node)
if msg.show_display:
await require_get_public_key(ctx, wif)
return EosPublicKey(wif, public_key)
return EosPublicKey(wif_public_key=wif, raw_public_key=public_key)

@ -19,4 +19,4 @@ async def get_next_u2f_counter(
text.normal("the U2F counter?")
await require_confirm(ctx, text, code=ButtonRequestType.ProtectCall)
return NextU2FCounter(storage.device.next_u2f_counter())
return NextU2FCounter(u2f_counter=storage.device.next_u2f_counter())

@ -122,7 +122,7 @@ async def _finish_recovery_dry_run(
await layout.show_dry_run_result(ctx, result, is_slip39)
if result:
return Success("The seed is valid and matches the one in the device")
return Success(message="The seed is valid and matches the one in the device")
else:
raise wire.ProcessError("The seed does not match the one in the device")

@ -34,7 +34,7 @@ async def sign_tx(ctx, msg: RippleSignTx, keychain):
signature = ecdsa_sign(node.private_key(), first_half_of_sha512(to_sign))
tx = serialize(msg, source_address, pubkey=node.public_key(), signature=signature)
return RippleSignedTx(signature, tx)
return RippleSignedTx(signature=signature, serialized_tx=tx)
def check_fee(fee: int):

@ -37,7 +37,7 @@ async def sign_tx(ctx, msg: StellarSignTx, keychain):
signature = ed25519.sign(node.private_key(), digest)
# Add the public key for verification that the right account was used for signing
return StellarSignedTx(pubkey, signature)
return StellarSignedTx(public_key=pubkey, signature=signature)
async def _final(ctx, w: bytearray, msg: StellarSignTx):

@ -38,4 +38,4 @@ async def list_resident_credentials(
)
for cred in resident_credentials.find_all()
]
return WebAuthnCredentials(creds)
return WebAuthnCredentials(credentials=creds)

@ -21,7 +21,13 @@
"""Reference implementation for Bech32 and segwit addresses."""
if False:
from typing import Iterable, List, Optional, Tuple
from typing import Iterable, List, Optional, Tuple, Union, TypeVar
A = TypeVar("A")
B = TypeVar("B")
# usage: OptionalTuple[int, List[int]] is either (None, None) or (someint, somelist)
# but not (None, somelist)
OptionalTuple = Union[Tuple[None, None], Tuple[A, B]]
CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
@ -61,9 +67,7 @@ def bech32_encode(hrp: str, data: List[int]) -> str:
return hrp + "1" + "".join([CHARSET[d] for d in combined])
def bech32_decode(
bech: str, max_bech_len: int = 90
) -> Tuple[Optional[str], Optional[List[int]]]:
def bech32_decode(bech: str, max_bech_len: int = 90) -> OptionalTuple[str, List[int]]:
"""Validate a Bech32 string, and determine HRP and data."""
if (any(ord(x) < 33 or ord(x) > 126 for x in bech)) or (
bech.lower() != bech and bech.upper() != bech
@ -107,7 +111,7 @@ def convertbits(
return ret
def decode(hrp: str, addr: str) -> Tuple[Optional[int], Optional[List[int]]]:
def decode(hrp: str, addr: str) -> OptionalTuple[int, List[int]]:
"""Decode a segwit address."""
hrpgot, data = bech32_decode(addr)
if data is None or hrpgot != hrp:

Loading…
Cancel
Save