cryptnoxpy package
Subpackages
- cryptnoxpy.card package
- Submodules
- cryptnoxpy.card.authenticity module
- cryptnoxpy.card.base module
UserSignatureCheckResultBaseBase.PUK_LENGTHBase.pin_ruleBase.typeBase.user_dataBase.custom_bitsBase.__init__()Base.select_apduBase.puk_ruleBase.aliveBase.change_pairing_key()Base.change_pin()Base.change_puk()Base.check_init()Base.derive()Base.dual_seed_public_key()Base.dual_seed_load()Base.extended_public_keyBase.generate_random_number()Base.generate_seed()Base.get_public_key()Base.get_public_key_extended()Base.get_public_key_clear()Base.set_pubexport()Base.set_xpubread()Base.set_clearpubkey()Base.decrypt()Base.history()Base.infoBase.init()Base.initializedBase.load_seed()Base.openBase.originBase.pin_authenticationBase.pinless_enabledBase.reset()Base.seed_sourceBase.set_pin_authentication()Base.set_pinless_path()Base.set_extended_public_key()Base.sign()Base.signature_check()Base.signing_counterBase.unblock_pin()Base.user_key_add()Base.user_key_delete()Base.user_key_info()Base.user_key_enabled()Base.user_key_challenge_response_nonce()Base.user_key_challenge_response_open()Base.user_key_signature_open()Base.valid_keyBase.valid_pin()Base.valid_puk()Base.verify_pin()
- cryptnoxpy.card.basic_g1 module
BasicG1BasicG1.select_apduBasicG1.puk_ruleBasicG1.PUK_LENGTHBasicG1.__init__()BasicG1.change_pairing_key()BasicG1.derive()BasicG1.dual_seed_public_key()BasicG1.dual_seed_load()BasicG1.extended_public_keyBasicG1.generate_random_number()BasicG1.generate_seed()BasicG1.get_manufacturer_certificate()BasicG1.get_public_key()BasicG1.get_public_key_extended()BasicG1.get_public_key_clear()BasicG1.decrypt()BasicG1.history()BasicG1.initializedBasicG1.load_wrapped_seed()BasicG1.load_seed()BasicG1.pin_authenticationBasicG1.pinless_enabledBasicG1.reset()BasicG1.seed_sourceBasicG1.set_pin_authentication()BasicG1.set_pinless_path()BasicG1.set_extended_public_key()BasicG1.signing_counterBasicG1.user_key_add()BasicG1.user_key_delete()BasicG1.user_key_info()BasicG1.user_key_enabled()BasicG1.user_key_challenge_response_nonce()BasicG1.user_key_challenge_response_open()BasicG1.user_key_signature_open()BasicG1.generate_seed_wrapper()BasicG1.sign_public()BasicG1.sign()BasicG1.valid_keyBasicG1.valid_puk()BasicG1.verify_pin()BasicG1.set_pubexport()BasicG1.set_xpubread()BasicG1.set_clearpubkey()
- cryptnoxpy.card.custom_bits module
- cryptnoxpy.card.nft module
NftNft.typeNft.__init__()Nft.derive()Nft.get_public_key()Nft.get_public_key_clear()Nft.set_pubexport()Nft.set_clearpubkey()Nft.generate_random_number()Nft.load_seed()Nft.set_pin_authentication()Nft.set_pinless_path()Nft.user_key_add()Nft.user_key_delete()Nft.user_key_info()Nft.user_key_enabled()Nft.user_key_challenge_response_nonce()Nft.user_key_challenge_response_open()Nft.user_key_signature_open()Nft.signature_check()
- cryptnoxpy.card.user_data module
- Module contents
BaseBase.PUK_LENGTHBase.__init__()Base.aliveBase.change_pairing_key()Base.change_pin()Base.change_puk()Base.check_init()Base.custom_bitsBase.decrypt()Base.derive()Base.dual_seed_load()Base.dual_seed_public_key()Base.extended_public_keyBase.generate_random_number()Base.generate_seed()Base.get_public_key()Base.get_public_key_clear()Base.get_public_key_extended()Base.history()Base.infoBase.init()Base.initializedBase.load_seed()Base.openBase.originBase.pin_authenticationBase.pin_ruleBase.pinless_enabledBase.puk_ruleBase.reset()Base.seed_sourceBase.select_apduBase.set_clearpubkey()Base.set_extended_public_key()Base.set_pin_authentication()Base.set_pinless_path()Base.set_pubexport()Base.set_xpubread()Base.sign()Base.signature_check()Base.signing_counterBase.typeBase.unblock_pin()Base.user_dataBase.user_key_add()Base.user_key_challenge_response_nonce()Base.user_key_challenge_response_open()Base.user_key_delete()Base.user_key_enabled()Base.user_key_info()Base.user_key_signature_open()Base.valid_keyBase.valid_pin()Base.valid_puk()Base.verify_pin()Base.applet_versionBase.serial_numberBase.auth_type
BasicG1BasicG1.PUK_LENGTHBasicG1.__init__()BasicG1.change_pairing_key()BasicG1.decrypt()BasicG1.derive()BasicG1.dual_seed_load()BasicG1.dual_seed_public_key()BasicG1.extended_public_keyBasicG1.generate_random_number()BasicG1.generate_seed()BasicG1.generate_seed_wrapper()BasicG1.get_manufacturer_certificate()BasicG1.get_public_key()BasicG1.get_public_key_clear()BasicG1.get_public_key_extended()BasicG1.history()BasicG1.initializedBasicG1.load_seed()BasicG1.load_wrapped_seed()BasicG1.pin_authenticationBasicG1.pinless_enabledBasicG1.puk_ruleBasicG1.reset()BasicG1.seed_sourceBasicG1.select_apduBasicG1.set_clearpubkey()BasicG1.set_extended_public_key()BasicG1.set_pin_authentication()BasicG1.set_pinless_path()BasicG1.set_pubexport()BasicG1.set_xpubread()BasicG1.sign()BasicG1.sign_public()BasicG1.signing_counterBasicG1.user_key_add()BasicG1.user_key_challenge_response_nonce()BasicG1.user_key_challenge_response_open()BasicG1.user_key_delete()BasicG1.user_key_enabled()BasicG1.user_key_info()BasicG1.user_key_signature_open()BasicG1.valid_keyBasicG1.valid_puk()BasicG1.verify_pin()BasicG1.applet_versionBasicG1.serial_numberBasicG1.auth_type
NftNft.__init__()Nft.derive()Nft.generate_random_number()Nft.get_public_key()Nft.get_public_key_clear()Nft.load_seed()Nft.set_clearpubkey()Nft.set_pin_authentication()Nft.set_pinless_path()Nft.set_pubexport()Nft.signature_check()Nft.typeNft.user_key_add()Nft.user_key_challenge_response_nonce()Nft.user_key_challenge_response_open()Nft.user_key_delete()Nft.user_key_enabled()Nft.user_key_info()Nft.user_key_signature_open()Nft.applet_versionNft.serial_numberNft.auth_type
- cryptnoxpy.cryptos package
- Submodules
- cryptnoxpy.cryptos.main module
change_curve()getG()inv()access()multiaccess()slice()count()sum()isinf()to_jacobian()jacobian_double()jacobian_add()fast_add()get_pubkey_format()encode_pubkey()decode_pubkey()get_privkey_format()encode_privkey()decode_privkey()add_pubkeys()add_privkeys()divide()compress()decompress()neg_pubkey()neg_privkey()subtract_pubkeys()subtract_privkeys()bin_hash160()hash160()hex_to_hash160()bin_sha256()sha256()bin_ripemd160()ripemd160()bin_dbl_sha256()dbl_sha256()bin_slowsha()slowsha()hash_to_int()num_to_var_int()electrum_sig_hash()b58check_to_bin()get_version_byte()hex_to_b58check()b58check_to_hex()pubkey_to_hash()pubkey_to_hash_hex()pubkey_to_address()pubtoaddr()is_privkey()is_pubkey()encode_sig()decode_sig()deterministic_generate_k()ecdsa_verify_addr()ecdsa_verify()add()subtract()magicbyte_to_prefix()
- cryptnoxpy.cryptos.py2specials module
- cryptnoxpy.cryptos.py3specials module
- cryptnoxpy.cryptos.ripemd module
- Module contents
Submodules
cryptnoxpy.binary_utils module
Utility module for handling binary data
- cryptnoxpy.binary_utils.list_to_hexadecimal(data: List[int], sep: str = '') str[source]
Convert list of integers into hexadecimal representation
- Parameters:
data (List[int]) – List of integer to return in hexadecimal string form
sep (str) – (optional) Separator to use to join the hexadecimal numbers
- Returns:
list
- Return type:
str
- cryptnoxpy.binary_utils.hexadecimal_to_list(value: str) List[int][source]
Convert given string containing hexadecimal representation of numbers into list of integers
- Parameters:
value (string) – String containing hexadecimal numbers
- Returns:
List of hexadecimal values in integer form
- Return type:
List[int]
- cryptnoxpy.binary_utils.path_to_bytes(path_str: str) bytes[source]
Convert given path for format that the card uses
- Parameters:
path_str (str) – path to convert
- Returns:
path formatted for use with the card.
- Return type:
bytes
- cryptnoxpy.binary_utils.binary_to_list(data: bytes) List[int][source]
Convert given binary data to it’s representation as a list of hexadecimal values.
- Parameters:
data (bytes) – Binary data to convert to
- Returns:
List containing data in hexadecimal numbers in integer format
- Return type:
List[int]
cryptnoxpy.connection module
Module for keeping the connection to the reader.
Sending and receiving information from the card through the reader.
- class cryptnoxpy.connection.Connection(index: int = 0, debug: bool = False, conn: List = None, remote: bool = False)[source]
Bases:
ContextDecoratorConnection to the reader.
Sends and receives messages from the card using the reader.
- Parameters:
index (int) – Index of the reader to initialize the connection with
debug (bool) – Show debug information during requests
conn (List) – List of sockets to use for remote connections
remote (bool) – Use remote sockets for communications with the cards
- Variables:
self.card (Card) – Information about the card.
- send_apdu(apdu: List[int]) Tuple[List[int], int, int][source]
Send data to the card in plain format
- Parameters:
apdu (int) – list of the APDU header
- Return bytes:
Result of the query that was sent to the card
- Return type:
bytes
- Raises:
ConnectionException – Issue in the connection
- send_encrypted(apdu: List[int], data: bytes, receive_long: bool = False) bytes[source]
Send data to the card in encrypted format
- Parameters:
apdu (int) – list of the APDU header
data – bytes of the data payload (in clear, will be encrypted)
receive_long (bool)
- Return bytes:
Result of the query that was sent to the card
- Return type:
bytes
- Raises:
CryptnoxException – General exceptions
cryptnoxpy.crypto_utils module
Module containing cryptographic methods used by the library
- cryptnoxpy.crypto_utils.aes_encrypt(key: bytes, initialization_vector: bytes, data: bytes) bytes[source]
AES encrypt data using key and initialization vector.
- Parameters:
key (bytes) – Key to use for encryption
initialization_vector (bytes) – Initialization vector
data (bytes) – Data to encrypt
- Returns:
Encrypted data
- Return type:
bytes
- cryptnoxpy.crypto_utils.aes_decrypt(key: bytes, initialization_vector: bytes, data: bytes) bytes[source]
AES decrypt data using key and initialization vector.
- Parameters:
key (bytes) – Key to use for encryption
initialization_vector (bytes) – Initialization vector
data (bytes) – Data to decrypt
- Returns:
Decrypted data
- Return type:
bytes
cryptnoxpy.enums module
Enum classes used by the module
- class cryptnoxpy.enums.AuthType(*values)[source]
Bases:
EnumPredefined values for authentication type.
- NO_AUTH = 0
- PIN = 1
- USER_KEY = 2
- class cryptnoxpy.enums.Derivation(*values)[source]
Bases:
IntEnumPredefined values to use for parameters as Derivation.
- CURRENT_KEY = 0
- DERIVE = 1
- DERIVE_AND_MAKE_CURRENT = 2
- PINLESS_PATH = 3
- class cryptnoxpy.enums.KeyType(*values)[source]
Bases:
IntEnumPredefined values to use for parameters as KeyType.
- K1 = 0
- R1 = 16
- class cryptnoxpy.enums.Origin(*values)[source]
Bases:
EnumPredefined values for keeping the origin of the card
- UNKNOWN = 0
- ORIGINAL = 1
- FAKE = 2
cryptnoxpy.exceptions module
Module containing all exceptions that CryptnoxPy module can raise.
- exception cryptnoxpy.exceptions.CryptnoxException[source]
Bases:
ExceptionBase exception for the class exceptions.
- exception cryptnoxpy.exceptions.CardClosedException[source]
Bases:
ExceptionThe card wasn’t opened with PIN code or challenge-response
- exception cryptnoxpy.exceptions.CardException[source]
Bases:
CryptnoxExceptionNo card was detected in the card reader.
- exception cryptnoxpy.exceptions.CardTypeException[source]
Bases:
CryptnoxExceptionThe detected card is not supported by this library
- exception cryptnoxpy.exceptions.CertificateException[source]
Bases:
CryptnoxExceptionThere was an issue with the certification
- exception cryptnoxpy.exceptions.ConnectionException[source]
Bases:
CryptnoxExceptionAn issue occurred in the communication with the reader
- exception cryptnoxpy.exceptions.DataException[source]
Bases:
CryptnoxExceptionThe reader returned an empty message.
- exception cryptnoxpy.exceptions.DataValidationException[source]
Bases:
CryptnoxExceptionThe sent data is not valid.
- exception cryptnoxpy.exceptions.DerivationSelectionException[source]
Bases:
CryptnoxExceptionNot a valid derivation selection.
- exception cryptnoxpy.exceptions.KeySelectionException[source]
Bases:
CryptnoxExceptionNot a valid key type selection
- exception cryptnoxpy.exceptions.EOSKeyError[source]
Bases:
CryptnoxExceptionThe signature wasn’t compatible with EOS standard after 10 tries
- exception cryptnoxpy.exceptions.FirmwareException[source]
Bases:
CryptnoxExceptionThere is an issue with the firmware on the card
- exception cryptnoxpy.exceptions.GenuineCheckException[source]
Bases:
CryptnoxExceptionThe detected card is not a genuine Cryptnox product.
- exception cryptnoxpy.exceptions.GenericException(status: bytes)[source]
Bases:
CryptnoxExceptionGeneric exception that can mean multiple things depending on the call to the card
Process stats and throw a specific Exception from it.
- exception cryptnoxpy.exceptions.InitializationException[source]
Bases:
CryptnoxExceptionThe card hasn’t been initialized.
- exception cryptnoxpy.exceptions.KeyAlreadyGenerated[source]
Bases:
CryptnoxExceptionKey can not be generated twice.
- exception cryptnoxpy.exceptions.SeedException[source]
Bases:
CryptnoxExceptionKeys weren’t found on the card.
- exception cryptnoxpy.exceptions.KeyGenerationException[source]
Bases:
CryptnoxExceptionError in key generation.
- exception cryptnoxpy.exceptions.PinAuthenticationException[source]
Bases:
CryptnoxExceptionError in turning off PIN authentication. There is no user key in the card
- exception cryptnoxpy.exceptions.PinException(message: str = 'Invalid PIN code was provided', number_of_retries: int = 0)[source]
Bases:
CryptnoxExceptionSent PIN code is not valid.
- Parameters:
number_of_retries (int) – Number of retries to send the PIN code before the card is locked.
message (str) – Optional message
- exception cryptnoxpy.exceptions.PukException(message: str = 'Invalid PUK code was provided', number_of_retries: int = 0)[source]
Bases:
CryptnoxExceptionSent PUK code is not valid.
- Parameters:
number_of_retries (int) – Number of retries to send the PIN code before the card is locked.
message (str) – Optional message
- exception cryptnoxpy.exceptions.ReadPublicKeyException[source]
Bases:
CryptnoxExceptionData received during public key reading is not valid.
- exception cryptnoxpy.exceptions.ReaderException[source]
Bases:
CryptnoxExceptionCard reader wasn’t found attached to the device.
- exception cryptnoxpy.exceptions.SecureChannelException[source]
Bases:
CryptnoxExceptionSecure channel couldn’t be established.
- exception cryptnoxpy.exceptions.SoftLock[source]
Bases:
CryptnoxExceptionThe card is soft locked, and requires power cycle before it can be opened
- exception cryptnoxpy.exceptions.CardNotBlocked[source]
Bases:
CryptnoxExceptionTrying to unlock unblocked card
cryptnoxpy.factory module
Module for getting Cryptnox cards information and getting instance of card from connection
- cryptnoxpy.factory.get_card(connection: Connection, debug: bool = False) Base[source]
Get card instance that is using given connection.
- Parameters:
connection (Connection) – Connection to use for operation
debug (bool) – Prints information about communication
- Returns:
Instance of card
- Return type:
- Raises:
CardException – Card with given serial number not found
cryptnoxpy.reader module
Module that handles different card reader types and their drivers.
- exception cryptnoxpy.reader.ReaderException[source]
Bases:
ExceptionReader hasn’t been found or other reader related issues
- exception cryptnoxpy.reader.CardException[source]
Bases:
ExceptionThe reader is present but there is an issue in connecting to the card
- exception cryptnoxpy.reader.ConnectionException[source]
Bases:
ExceptionAn issue has occurred in the communication with the card.
- class cryptnoxpy.reader.Reader[source]
Bases:
objectAbstract class describing methods to be implemented. Holds the connection.
- abstractmethod connect() None[source]
Connect to the card found in the selected reader.
- Returns:
None
- class cryptnoxpy.reader.NfcReader[source]
Bases:
ReaderSpecialized reader using xantares/nfc-binding
Module contents
This is a library for communicating with Cryptnox cards
See the README.md for API details and general information.
- class cryptnoxpy.Connection(index: int = 0, debug: bool = False, conn: List = None, remote: bool = False)[source]
Bases:
ContextDecoratorConnection to the reader.
Sends and receives messages from the card using the reader.
- Parameters:
index (int) – Index of the reader to initialize the connection with
debug (bool) – Show debug information during requests
conn (List) – List of sockets to use for remote connections
remote (bool) – Use remote sockets for communications with the cards
- Variables:
self.card (Card) – Information about the card.
- send_apdu(apdu: List[int]) Tuple[List[int], int, int][source]
Send data to the card in plain format
- Parameters:
apdu (int) – list of the APDU header
- Return bytes:
Result of the query that was sent to the card
- Return type:
bytes
- Raises:
ConnectionException – Issue in the connection
- send_encrypted(apdu: List[int], data: bytes, receive_long: bool = False) bytes[source]
Send data to the card in encrypted format
- Parameters:
apdu (int) – list of the APDU header
data – bytes of the data payload (in clear, will be encrypted)
receive_long (bool)
- Return bytes:
Result of the query that was sent to the card
- Return type:
bytes
- Raises:
CryptnoxException – General exceptions
- class cryptnoxpy.SlotIndex(*values)[source]
Bases:
IntEnumPredefined values to use for parameters as SlotIndex.
- EC256R1 = 1
- RSA = 2
- FIDO = 3
- class cryptnoxpy.Derivation(*values)[source]
Bases:
IntEnumPredefined values to use for parameters as Derivation.
- CURRENT_KEY = 0
- DERIVE = 1
- DERIVE_AND_MAKE_CURRENT = 2
- PINLESS_PATH = 3
- class cryptnoxpy.KeyType(*values)[source]
Bases:
IntEnumPredefined values to use for parameters as KeyType.
- K1 = 0
- R1 = 16
- class cryptnoxpy.AuthType(*values)[source]
Bases:
EnumPredefined values for authentication type.
- NO_AUTH = 0
- PIN = 1
- USER_KEY = 2
- class cryptnoxpy.SeedSource(*values)[source]
Bases:
EnumPredefined values for how seed was created
- NO_SEED = 0
- SINGLE = 75
- EXTENDED = 88
- EXTERNAL = 76
- INTERNAL = 83
- DUAL = 68
- WRAPPED = 82
- class cryptnoxpy.Origin(*values)[source]
Bases:
EnumPredefined values for keeping the origin of the card
- UNKNOWN = 0
- ORIGINAL = 1
- FAKE = 2
The cryptnoxpy package is a library for communicating with Cryptnox cards. It exports:
- class cryptnoxpy.Card
Main card interface class. Alias for
cryptnoxpy.card.base.Base.
- class cryptnoxpy.Connection[source]
Connection handler for card communication. See
cryptnoxpy.connection.Connectionfor details.
Factory module for creating card instances. See cryptnoxpy.factory for details.
Enumeration types module. See cryptnoxpy.enums for details.
Exception classes module. See cryptnoxpy.exceptions for details.
- class exceptions.SlotIndex
Card slot index enumeration. See
cryptnoxpy.enums.SlotIndexfor details.
- class exceptions.Derivation
Key derivation method enumeration. See
cryptnoxpy.enums.Derivationfor details.
- class exceptions.KeyType
Cryptographic key type enumeration. See
cryptnoxpy.enums.KeyTypefor details.
- class exceptions.AuthType
Authentication type enumeration. See
cryptnoxpy.enums.AuthTypefor details.
- class exceptions.SeedSource
Seed source enumeration. See
cryptnoxpy.enums.SeedSourcefor details.
- class exceptions.Origin
Origin enumeration. See
cryptnoxpy.enums.Originfor details.
- exceptions.__version__: str = "2.5.5"
Current version of the cryptnoxpy library.