cryptnox_sdk_py package
Subpackages
- cryptnox_sdk_py.card package
- Submodules
- cryptnox_sdk_py.card.authenticity module
- cryptnox_sdk_py.card.base module
UserSignatureCheckResultBaseBase.PUK_LENGTHBase.pin_ruleBase.typeBase.user_dataBase.custom_bitsBase.__init__()Base.applet_versionBase.serial_numberBase.auth_typeBase.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()Base.get_manufacturer_certificate()
- cryptnox_sdk_py.card.basic_g1 module
BasicG1BasicG1.select_apduBasicG1.puk_ruleBasicG1.PUK_LENGTHBasicG1.MAX_ASCII_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.signature_check()BasicG1.verify_pin()BasicG1.set_pubexport()BasicG1.set_xpubread()BasicG1.set_clearpubkey()
- cryptnox_sdk_py.card.custom_bits module
- cryptnox_sdk_py.card.nft module
NftNft.typeNft.__init__()Nft.derive()Nft.get_public_key()Nft.get_public_key_clear()Nft.set_pubexport()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()
- cryptnox_sdk_py.card.user_data module
- Module contents
BaseBase.PUK_LENGTHBase.pin_ruleBase.typeBase.user_dataBase.custom_bitsBase.__init__()Base.applet_versionBase.serial_numberBase.auth_typeBase.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()Base.get_manufacturer_certificate()
BasicG1BasicG1.select_apduBasicG1.puk_ruleBasicG1.PUK_LENGTHBasicG1.MAX_ASCII_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.signature_check()BasicG1.verify_pin()BasicG1.set_pubexport()BasicG1.set_xpubread()BasicG1.set_clearpubkey()
NftNft.typeNft.__init__()Nft.derive()Nft.get_public_key()Nft.get_public_key_clear()Nft.set_pubexport()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()
- cryptnox_sdk_py.cryptos package
- Submodules
- cryptnox_sdk_py.cryptos.main module
change_curve()getG()inv()access()multiaccess()obj_slice()count()obj_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()
- cryptnox_sdk_py.cryptos.py2specials module
- cryptnox_sdk_py.cryptos.py3specials module
bin_dbl_sha256()lpad()get_code_string()changebase()bin_to_b58check()bytes_to_hex_string()safe_from_hex()from_int_representation_to_bytes()from_int_to_byte()from_byte_to_int()from_string_to_bytes()safe_hexlify()encode()decode()random_string()from_jacobian()multiply()ecdsa_raw_verify()ecdsa_recover()
- cryptnox_sdk_py.cryptos.ripemd module
- Module contents
Submodules
cryptnox_sdk_py.binary_utils module
Utility module for handling binary data
- cryptnox_sdk_py.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
- cryptnox_sdk_py.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]
- cryptnox_sdk_py.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
- cryptnox_sdk_py.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]
cryptnox_sdk_py.connection module
Module for keeping the connection to the reader.
Sending and receiving information from the card through the reader.
- class cryptnox_sdk_py.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.
- disconnect() None[source]
Disconnect from the card reader and clean up the connection.
This method properly closes the connection to the card reader without deleting the Connection object itself.
- 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
cryptnox_sdk_py.crypto_utils module
Module containing cryptographic methods used by the library
- cryptnox_sdk_py.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
- cryptnox_sdk_py.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
cryptnox_sdk_py.enums module
Enum classes used by the module
- class cryptnox_sdk_py.enums.AuthType(*values)[source]
Bases:
EnumPredefined values for authentication type.
- NO_AUTH = 0
- PIN = 1
- USER_KEY = 2
- class cryptnox_sdk_py.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 cryptnox_sdk_py.enums.KeyType(*values)[source]
Bases:
IntEnumPredefined values to use for parameters as KeyType.
- K1 = 0
- R1 = 16
- class cryptnox_sdk_py.enums.Origin(*values)[source]
Bases:
EnumPredefined values for keeping the origin of the card
- UNKNOWN = 0
- ORIGINAL = 1
- FAKE = 2
cryptnox_sdk_py.exceptions module
Module containing all exceptions that Cryptnox SDK Python module can raise.
- exception cryptnox_sdk_py.exceptions.CryptnoxException[source]
Bases:
ExceptionBase exception for the class exceptions.
- exception cryptnox_sdk_py.exceptions.CardClosedException[source]
Bases:
ExceptionThe card wasn’t opened with PIN code or challenge-response
- exception cryptnox_sdk_py.exceptions.CardException[source]
Bases:
CryptnoxExceptionNo card was detected in the card reader.
- exception cryptnox_sdk_py.exceptions.CardTypeException[source]
Bases:
CryptnoxExceptionThe detected card is not supported by this library
- exception cryptnox_sdk_py.exceptions.CertificateException[source]
Bases:
CryptnoxExceptionThere was an issue with the certification
- exception cryptnox_sdk_py.exceptions.ConnectionException[source]
Bases:
CryptnoxExceptionAn issue occurred in the communication with the reader
- exception cryptnox_sdk_py.exceptions.DataException[source]
Bases:
CryptnoxExceptionThe reader returned an empty message.
- exception cryptnox_sdk_py.exceptions.DataValidationException[source]
Bases:
CryptnoxExceptionThe sent data is not valid.
- exception cryptnox_sdk_py.exceptions.DerivationSelectionException[source]
Bases:
CryptnoxExceptionNot a valid derivation selection.
- exception cryptnox_sdk_py.exceptions.KeySelectionException[source]
Bases:
CryptnoxExceptionNot a valid key type selection
- exception cryptnox_sdk_py.exceptions.EOSKeyError[source]
Bases:
CryptnoxExceptionThe signature wasn’t compatible with EOS standard after 10 tries
- exception cryptnox_sdk_py.exceptions.FirmwareException[source]
Bases:
CryptnoxExceptionThere is an issue with the firmware on the card
- exception cryptnox_sdk_py.exceptions.GenuineCheckException[source]
Bases:
CryptnoxExceptionThe detected card is not a genuine Cryptnox product.
- exception cryptnox_sdk_py.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 cryptnox_sdk_py.exceptions.InitializationException[source]
Bases:
CryptnoxExceptionThe card hasn’t been initialized.
- exception cryptnox_sdk_py.exceptions.KeyAlreadyGenerated[source]
Bases:
CryptnoxExceptionKey can not be generated twice.
- exception cryptnox_sdk_py.exceptions.SeedException[source]
Bases:
CryptnoxExceptionKeys weren’t found on the card.
- exception cryptnox_sdk_py.exceptions.KeyGenerationException[source]
Bases:
CryptnoxExceptionError in key generation.
- exception cryptnox_sdk_py.exceptions.PinAuthenticationException[source]
Bases:
CryptnoxExceptionError in turning off PIN authentication. There is no user key in the card
- exception cryptnox_sdk_py.exceptions.PinBlockedException[source]
Bases:
CryptnoxExceptionPIN is fully blocked (0 retries remaining). Unblock the card before attempting this operation.
- exception cryptnox_sdk_py.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 cryptnox_sdk_py.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 cryptnox_sdk_py.exceptions.ReadPublicKeyException[source]
Bases:
CryptnoxExceptionData received during public key reading is not valid.
- exception cryptnox_sdk_py.exceptions.ReaderException[source]
Bases:
CryptnoxExceptionCard reader wasn’t found attached to the device.
- exception cryptnox_sdk_py.exceptions.SecureChannelException[source]
Bases:
CryptnoxExceptionSecure channel couldn’t be established.
- exception cryptnox_sdk_py.exceptions.SoftLock[source]
Bases:
CryptnoxExceptionThe card is soft locked, and requires power cycle before it can be opened
- exception cryptnox_sdk_py.exceptions.CardNotBlocked[source]
Bases:
CryptnoxExceptionTrying to unlock unblocked card
cryptnox_sdk_py.factory module
Module for getting Cryptnox cards information and getting instance of card from connection
- cryptnox_sdk_py.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
cryptnox_sdk_py.reader module
Module that handles different card reader types and their drivers.
- exception cryptnox_sdk_py.reader.ReaderException[source]
Bases:
ExceptionReader hasn’t been found or other reader related issues
- exception cryptnox_sdk_py.reader.CardException[source]
Bases:
ExceptionThe reader is present but there is an issue in connecting to the card
- exception cryptnox_sdk_py.reader.ConnectionException[source]
Bases:
ExceptionAn issue has occurred in the communication with the card.
- class cryptnox_sdk_py.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
- abstractmethod send(apdu: List[int]) Tuple[List[str], int, int][source]
Send APDU to the reader and card and retrieve the result with status codes.
- Parameters:
apdu (List[int]) – Command to be sent
- Returns:
Return the result of the query and two status codes
- Return type:
Tuple[List[str], int, int]
- class cryptnox_sdk_py.reader.NfcReader[source]
Bases:
ReaderSpecialized reader using xantares/nfc-binding
- class cryptnox_sdk_py.reader.SmartCard(index: int = 0)[source]
Bases:
ReaderGeneric smart card reader class
- Parameters:
index (int) – Index of the reader to initialize.
Module contents
This is a library for communicating with Cryptnox cards
See the README.md for API details and general information.
- class cryptnox_sdk_py.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.
- disconnect() None[source]
Disconnect from the card reader and clean up the connection.
This method properly closes the connection to the card reader without deleting the Connection object itself.
- 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 cryptnox_sdk_py.SlotIndex(*values)[source]
Bases:
IntEnumPredefined values to use for parameters as SlotIndex.
- EC256R1 = 1
- RSA = 2
- FIDO = 3
- class cryptnox_sdk_py.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 cryptnox_sdk_py.KeyType(*values)[source]
Bases:
IntEnumPredefined values to use for parameters as KeyType.
- K1 = 0
- R1 = 16
- class cryptnox_sdk_py.AuthType(*values)[source]
Bases:
EnumPredefined values for authentication type.
- NO_AUTH = 0
- PIN = 1
- USER_KEY = 2
- class cryptnox_sdk_py.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 cryptnox_sdk_py.Origin(*values)[source]
Bases:
EnumPredefined values for keeping the origin of the card
- UNKNOWN = 0
- ORIGINAL = 1
- FAKE = 2
The cryptnox_sdk_py package is a library for communicating with Cryptnox cards. It exports:
- class cryptnox_sdk_py.Card
Main card interface class. Alias for
cryptnox_sdk_py.card.base.Base.
- class cryptnox_sdk_py.Connection[source]
Connection handler for card communication. See
cryptnox_sdk_py.connection.Connectionfor details.
Factory module for creating card instances. See cryptnox_sdk_py.factory for details.
Enumeration types module. See cryptnox_sdk_py.enums for details.
Exception classes module. See cryptnox_sdk_py.exceptions for details.
- class exceptions.SlotIndex
Card slot index enumeration. See
cryptnox_sdk_py.enums.SlotIndexfor details.
- class exceptions.Derivation
Key derivation method enumeration. See
cryptnox_sdk_py.enums.Derivationfor details.
- class exceptions.KeyType
Cryptographic key type enumeration. See
cryptnox_sdk_py.enums.KeyTypefor details.
- class exceptions.AuthType
Authentication type enumeration. See
cryptnox_sdk_py.enums.AuthTypefor details.
- class exceptions.SeedSource
Seed source enumeration. See
cryptnox_sdk_py.enums.SeedSourcefor details.
- class exceptions.Origin
Origin enumeration. See
cryptnox_sdk_py.enums.Originfor details.
- exceptions.__version__: str = "1.0.3"
Current version of the cryptnox_sdk_py library.