Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cryptnox_cli/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def _handle_execution(self, serial_number: int = None) -> int:
try:
self.serial_number = self.data.serial
except AttributeError:
# No serial provided in arguments; keep the passed-in serial_number
pass
try:
card = self._cards[self.serial_number]
Expand All @@ -65,7 +66,7 @@ def _handle_execution(self, serial_number: int = None) -> int:
print(f"Error in retrieving information: {error}")
return -1

self.run_execute(card)
return self.run_execute(card)

def run_execute(self, card) -> int:
print(f"Using card with serial number {card.serial_number}")
Expand Down
6 changes: 3 additions & 3 deletions cryptnox_cli/command/erc_token/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import gzip
import json
import urllib
import urllib.error
import urllib.parse
from argparse import Namespace
from typing import List
from urllib import parse

import cryptnox_sdk_py
import requests
Expand Down Expand Up @@ -202,7 +202,7 @@ def _token_slots() -> list[str]:
def _abi() -> str:
def uri_validator(x):
try:
result = parse.urlparse(x)
result = urllib.parse.urlparse(x)
return all([result.scheme, result.netloc])
except Exception:
return False
Expand Down
10 changes: 10 additions & 0 deletions cryptnox_cli/command/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def logs(self):
endpoint.block_number
save_to_config(self.card, self.config)

return None

@staticmethod
def _get_logs(event) -> List[Dict[str, Any]]:
min_offset = 0
Expand Down Expand Up @@ -256,6 +258,8 @@ def _execute(self, card):
print(error)
return -1

return None

def _get_endpoint(self, card):
config = get_configuration(card)

Expand Down Expand Up @@ -311,6 +315,8 @@ def _add(self, card):
print(f"Contract added to application. Use it with alias:"
f" {self.data.alias}")

return None

@staticmethod
def _list(card) -> int:
config = get_configuration(card)
Expand Down Expand Up @@ -356,6 +362,8 @@ def _functions(self, card):

print(tabulate(tabulate_table, headers=tabulate_header, tablefmt="grid"))

return None

def _call(self, card):
config = get_configuration(card)
try:
Expand Down Expand Up @@ -645,3 +653,5 @@ def _send_token(self, card):
contract.transfer(card, config["endpoint"], config["network"], config["api_key"],
self.data.contract, self.data.address, self.data.amount, self.data.price,
self.data.limit, derivation)

return None
1 change: 1 addition & 0 deletions cryptnox_cli/command/get_clearpubkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def _execute(self, card) -> int:
else:
card.derive(key_type, "m/44'/0'/0'")
except Exception:
# Best-effort derivation; clear pubkey read below handles failures
pass
pubkey_bytes = card.get_public_key_clear(derivation, path, compressed)
self._print_pubkey_info(key_type, compressed, pubkey_bytes)
Expand Down
3 changes: 2 additions & 1 deletion cryptnox_cli/command/helper/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def refresh(self, remote: bool = False) -> None:
except cryptnox_sdk_py.exceptions.ReaderException:
break
except cryptnox_sdk_py.exceptions.CryptnoxException:
# Card at this index is unreadable; skip it and continue scanning
pass

index += 1
Expand Down Expand Up @@ -194,7 +195,7 @@ def _open_card(self, index: int, remote: bool = False) -> cryptnox_sdk_py.Card:
if test_response:
if index in self._cards_by_index:
return self._cards_by_index[index]
except (BaseException, cryptnox_sdk_py.exceptions.ConnectionException):
except (Exception, cryptnox_sdk_py.exceptions.ConnectionException):
# Connection is stale, remove it and create new one
del _GLOBAL_CONNECTIONS[index]
if index in self._cards_by_index:
Expand Down
1 change: 1 addition & 0 deletions cryptnox_cli/command/helper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def write_config(card: cryptnox_sdk_py.Card, section: str, key: str, value: str)
print(error)
return 1
except AttributeError:
# Key not present on the validator instance; fall through to config handling
pass

try:
Expand Down
1 change: 1 addition & 0 deletions cryptnox_cli/command/helper/helper_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@ def try_eval(value: str) -> Any:
try:
value = ast.literal_eval(value)
except ValueError:
# Not a literal; keep the original string value
pass
return value
1 change: 1 addition & 0 deletions cryptnox_cli/command/helper/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def check(card, check_seed: bool = True) -> bool:
try:
result = user_keys.authenticate(card)
except NotImplementedError:
# User-key auth unsupported here; fall back to PIN authentication below
pass

if not result:
Expand Down
1 change: 1 addition & 0 deletions cryptnox_cli/command/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def _dual_seed(self, card: cryptnox_sdk_py.Card) -> int:
print(error)
return -1
except cryptnox_sdk_py.exceptions.DataValidationException:
# Expected when probing dual-seed support without a PIN; safe to proceed
pass

print("Dual seed generation process starting...")
Expand Down
2 changes: 0 additions & 2 deletions cryptnox_cli/command/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

try:
import enums
from wallet import eth as wallet # noqa: F401
except ImportError:
from .. import enums
from ..wallet import eth as wallet # noqa: F401


class Transfer(Command):
Expand Down
2 changes: 2 additions & 0 deletions cryptnox_cli/command/user_keys/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
try:
importlib.import_module("." + submodule, package=__package__)
except Exception:
# Optional submodule unavailable in frozen build; skip it
pass
else:
# When running normally, dynamically discover submodules
Expand Down Expand Up @@ -155,6 +156,7 @@ def delete(name: str, card: cryptnox_sdk_py.Card, puk: str) -> bool:
try:
user_key.delete()
except user_key_base.UserKeyException:
# Best-effort local key removal; proceed to delete it from the card
pass

card.user_key_delete(user_key.slot_index, puk)
Expand Down
1 change: 1 addition & 0 deletions cryptnox_cli/command/user_keys/hello/windows_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ async def _get_user_credentials(account_id: str) -> KeyCredential:
return key_result.credential

_error_handle(key_result.status)
return None


async def _public_key(name: str) -> bytearray:
Expand Down
1 change: 1 addition & 0 deletions cryptnox_cli/command/user_keys/piv/piv_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def is_locked(self, pin_bank: int) -> bool:
try:
self.verify_pin(pin_bank, "")
except PinException:
# Empty PIN rejected as expected; card is not locked
pass
except PIVCardException as error:
if error.sw_code == 0x6983:
Expand Down
4 changes: 4 additions & 0 deletions cryptnox_cli/interactive_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def run(self) -> int:
self._cards.refresh(self.port and client is not None)
self._card_info = list(self._cards.values())[0].info
except IndexError:
# No cards found yet; leave _card_info unset and continue
pass

self._cards.print_card_list(show_warnings=True, print_with_one_card=True)
Expand Down Expand Up @@ -294,6 +295,7 @@ def _process_command(self):
if execute[0] not in ["use", "exit", "back"]:
execute[0:0] = self.subcommand
except LookupError:
# Empty command; nothing to prepend, ignore
pass
else:
self._prepare_parser()
Expand All @@ -312,6 +314,7 @@ def _process_command(self):
try:
self.parser.parse_args(execute)
except SystemExit:
# argparse exits on help/error; keep the interactive loop alive
pass
UsageParser.throw_error = True
else:
Expand Down Expand Up @@ -399,6 +402,7 @@ def _run_command(self, args: argparse.Namespace, to_always_run: List = None) ->
try:
self._card_info = self._cards[command.serial_number].info
except KeyError:
# Card no longer present; keep previous _card_info
pass
except (cryptnox_sdk_py.exceptions.CryptnoxException, ExitException, TimeoutException) as error:
print(error)
Expand Down
2 changes: 2 additions & 0 deletions cryptnox_cli/lib/cryptos/deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def bip32_descend(*args, prefixes=DEFAULT):
path = parse_bip32_path(args[1])
elif len(args):
key, path = args[0], list(map(int, args[1:]))
else:
raise TypeError("bip32_descend() requires at least one positional argument")
for p in path:
key = bip32_ckd(key, p, prefixes)
return bip32_extract_key(key, prefixes)
Expand Down
12 changes: 7 additions & 5 deletions cryptnox_cli/lib/cryptos/keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def get_pubkey_derivation(self, x_pubkey):
addr = self.coin.p2sh_scriptaddr(x_pubkey[2:])
if addr in self.addresses:
return self.addresses[addr].get('pubkey')
return None

def update_password(self, old_password, new_password):
self.check_password(old_password)
Expand Down Expand Up @@ -238,7 +239,7 @@ def derive_pubkey(self, for_change, n):
return self.get_pubkey_from_xpub(xpub, (n,), self.bip39_prefixes)

@classmethod
def get_pubkey_from_xpub(self, xpub, sequence, bip39_prefixes):
def get_pubkey_from_xpub(cls, xpub, sequence, bip39_prefixes):
return bip32_derive_key(xpub, sequence, bip39_prefixes)

"""needed?
Expand Down Expand Up @@ -352,7 +353,7 @@ class Hardware_KeyStore(KeyStore, Xpub):
max_change_outputs = 1

def __init__(self, d, coin):
Xpub.__init__(self, coin)
Xpub.__init__(self)
KeyStore.__init__(self, coin)
# Errors and other user interaction is done through the wallet's
# handler. The handler is per-window and preserved across
Expand Down Expand Up @@ -483,7 +484,7 @@ def xpubkey_to_address(x_pubkey, coin):
pubkey = x_pubkey
elif x_pubkey[0:2] == 'ff':
xpub, s = BIP32_KeyStore.parse_xpubkey(x_pubkey)
pubkey = BIP32_KeyStore.get_pubkey_from_xpub(xpub, s)
pubkey = BIP32_KeyStore.get_pubkey_from_xpub(xpub, s, coin.bip39_prefixes)
else:
raise BaseException("Cannot parse pubkey")
address = coin.pubtoaddr(pubkey)
Expand Down Expand Up @@ -516,11 +517,12 @@ def get_private_keys(text):
parts = list(filter(bool, parts))
if bool(parts) and all(bitcoin.is_private_key(x) for x in parts):
return parts
return None

def is_private_key_list(text):
return bool(get_private_keys(text))

is_mpk = lambda x: is_xpub(x)
is_mpk = is_xpub
is_private = lambda x: is_seed(x) or is_xprv(x) or is_private_key_list(x)
is_master_key = lambda x: is_xprv(x) or is_xpub(x)
is_private_key = lambda x: is_xprv(x) or is_private_key_list(x)
Expand Down Expand Up @@ -568,7 +570,7 @@ def from_master_key(text, coin):
if is_xprv(text, prefixes):
k = from_xprv(text, coin)
elif is_xpub(text, prefixes):
k = from_xpub(text, coin)
k = from_xpub(text, coin, 'p2pkh')
else:
raise BaseException('Invalid key')
return k
21 changes: 14 additions & 7 deletions cryptnox_cli/lib/cryptos/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def jacobian_multiply(a, n):
return jacobian_multiply(a, n % N)
if (n % 2) == 0:
return jacobian_double(jacobian_multiply(a, n // 2))
if (n % 2) == 1:
else:
return jacobian_add(jacobian_double(jacobian_multiply(a, n // 2)), a)


Expand Down Expand Up @@ -333,6 +333,7 @@ def compress(pubkey):
return encode_pubkey(decode_pubkey(pubkey, f), 'bin_compressed')
elif f == 'hex' or f == 'decimal':
return encode_pubkey(decode_pubkey(pubkey, f), 'hex_compressed')
return None


def decompress(pubkey):
Expand All @@ -343,6 +344,7 @@ def decompress(pubkey):
return encode_pubkey(decode_pubkey(pubkey, f), 'bin')
elif f == 'hex_compressed' or f == 'decimal':
return encode_pubkey(decode_pubkey(pubkey, f), 'hex')
return None


def privkey_to_pubkey(privkey):
Expand Down Expand Up @@ -398,7 +400,9 @@ def bin_hash160(string):
digest = ''
try:
digest = hashlib.new('ripemd160', intermed).digest()
except:
except Exception:
# 'ripemd160' may be unavailable (e.g. OpenSSL 3 legacy provider off);
# fall back to the bundled pure-Python implementation.
digest = RIPEMD160(intermed).digest()
return digest

Expand All @@ -423,7 +427,9 @@ def sha256(string):
def bin_ripemd160(string):
try:
digest = hashlib.new('ripemd160', string).digest()
except:
except Exception:
# 'ripemd160' may be unavailable (e.g. OpenSSL 3 legacy provider off);
# fall back to the bundled pure-Python implementation.
digest = RIPEMD160(string).digest()
return digest

Expand Down Expand Up @@ -541,15 +547,15 @@ def is_privkey(priv):
try:
get_privkey_format(priv)
return True
except:
except Exception:
return False


def is_pubkey(pubkey):
try:
get_pubkey_format(pubkey)
return True
except:
except Exception:
return False


Expand Down Expand Up @@ -677,8 +683,9 @@ def subtract(p1, p2):


def magicbyte_to_prefix(magicbyte):
# Always return a 2-tuple of the low/high address prefix characters.
# Callers only test membership over these, so a repeated character when
# first == last is harmless and keeps the return shape consistent.
first = bin_to_b58check(hash160Low, magicbyte=magicbyte)[0]
last = bin_to_b58check(hash160High, magicbyte=magicbyte)[0]
if first == last:
return (first,)
return (first, last)
5 changes: 3 additions & 2 deletions cryptnox_cli/lib/cryptos/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from .specials import *
from .wallet_utils import is_new_seed

wordlist_english = [word.strip() for word in
list(open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'english.txt'), 'r'))]
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'english.txt'), 'r') as _wordlist_file:
wordlist_english = [word.strip() for word in _wordlist_file]

ELECTRUM_VERSION = '3.0.5' # version of the client package
PROTOCOL_VERSION = '1.1' # protocol version requested
Expand Down Expand Up @@ -226,6 +226,7 @@ def seed_prefix(seed_type):
return SEED_PREFIX_SW
elif seed_type == '2fa':
return SEED_PREFIX_2FA
return None


def seed_type(x):
Expand Down
Loading
Loading