Crypto¶
- hdwallet.crypto.hmac_sha256(key: bytes | str, data: bytes | str) bytes¶
Generate an HMAC-SHA256 hash of the given data using the provided key.
- Parameters:
key (Union[bytes, str]) – The key for the HMAC algorithm, as bytes or a string.
data (Union[bytes, str]) – The data to be hashed, as bytes or a string.
- Returns:
The resulting HMAC-SHA256 hash as bytes.
- Return type:
bytes
- hdwallet.crypto.hmac_sha512(key: bytes | str, data: bytes | str) bytes¶
Generate an HMAC-SHA512 hash of the given data using the provided key.
- Parameters:
key (Union[bytes, str]) – The key for the HMAC algorithm, as bytes or a string.
data (Union[bytes, str]) – The data to be hashed, as bytes or a string.
- Returns:
The resulting HMAC-SHA512 hash as bytes.
- Return type:
bytes
- hdwallet.crypto.blake2b(data: bytes | str, digest_size: int, key: bytes | str = b'', salt: bytes | str = b'') bytes¶
Generate a BLAKE2b hash of the given data with optional key and salt.
- Parameters:
data (Union[bytes, str]) – The data to be hashed, as bytes or a string.
digest_size (int) – The size of the resulting digest in bytes.
key (Union[bytes, str]) – Optional key for keyed hashing, as bytes or a string. Default is an empty byte string.
salt (Union[bytes, str], optional) – Optional salt for added randomness, as bytes or a string. Default is an empty byte string.
- Returns:
The resulting BLAKE2b hash as bytes.
- Return type:
bytes
- hdwallet.crypto.blake2b_32(data: bytes | str, key: bytes | str = b'', salt: bytes | str = b'') bytes¶
Generate a 32-byte BLAKE2b hash of the given data with optional key and salt.
- Parameters:
data (Union[bytes, str]) – The data to be hashed, as bytes or a string.
key (Union[bytes, str]) – Optional key for keyed hashing, as bytes or a string. Default is an empty byte string.
salt (Union[bytes, str], optional) – Optional salt for added randomness, as bytes or a string. Default is an empty byte string.
- Returns:
The resulting 32-byte BLAKE2b hash as bytes.
- Return type:
bytes
- hdwallet.crypto.blake2b_40(data: bytes | str, key: bytes | str = b'', salt: bytes | str = b'') bytes¶
Generate a 40-byte BLAKE2b hash of the given data with optional key and salt.
- Parameters:
data (Union[bytes, str]) – The data to be hashed, as bytes or a string.
key (Union[bytes, str]) – Optional key for keyed hashing, as bytes or a string. Default is an empty byte string.
salt (Union[bytes, str], optional) – Optional salt for added randomness, as bytes or a string. Default is an empty byte string.
- Returns:
The resulting 40-byte BLAKE2b hash as bytes.
- Return type:
bytes
- hdwallet.crypto.blake2b_160(data: bytes | str, key: bytes | str = b'', salt: bytes | str = b'') bytes¶
Generate a 160-bit (20-byte) BLAKE2b hash of the given data with optional key and salt.
- Parameters:
data (Union[bytes, str]) – The data to be hashed, as bytes or a string.
key (Union[bytes, str]) – Optional key for keyed hashing, as bytes or a string. Default is an empty byte string.
salt (Union[bytes, str], optional) – Optional salt for added randomness, as bytes or a string. Default is an empty byte string.
- Returns:
The resulting 20-byte BLAKE2b hash as bytes.
- Return type:
bytes
- hdwallet.crypto.blake2b_224(data: bytes | str, key: bytes | str = b'', salt: bytes | str = b'') bytes¶
Generate a 224-bit (28-byte) BLAKE2b hash of the given data with optional key and salt.
- Parameters:
data (Union[bytes, str]) – The data to be hashed, as bytes or a string.
key (Union[bytes, str]) – Optional key for keyed hashing, as bytes or a string. Default is an empty byte string.
salt (Union[bytes, str], optional) – Optional salt for added randomness, as bytes or a string. Default is an empty byte string.
- Returns:
The resulting 28-byte BLAKE2b hash as bytes.
- Return type:
bytes
- hdwallet.crypto.blake2b_256(data: bytes | str, key: bytes | str = b'', salt: bytes | str = b'') bytes¶
Generate a 256-bit (32-byte) BLAKE2b hash of the given data with optional key and salt.
- Parameters:
data (Union[bytes, str]) – The data to be hashed, as bytes or a string.
key (Union[bytes, str]) – Optional key for keyed hashing, as bytes or a string. Default is an empty byte string.
salt (Union[bytes, str], optional) – Optional salt for added randomness, as bytes or a string. Default is an empty byte string.
- Returns:
The resulting 32-byte BLAKE2b hash as bytes.
- Return type:
bytes
- hdwallet.crypto.blake2b_512(data: bytes | str, key: bytes | str = b'', salt: bytes | str = b'') bytes¶
Generate a 512-bit (64-byte) BLAKE2b hash of the given data with optional key and salt.
- Parameters:
data (Union[bytes, str]) – The data to be hashed, as bytes or a string.
key (Union[bytes, str]) – Optional key for keyed hashing, as bytes or a string. Default is an empty byte string.
salt (Union[bytes, str], optional) – Optional salt for added randomness, as bytes or a string. Default is an empty byte string.
- Returns:
The resulting 64-byte BLAKE2b hash as bytes.
- Return type:
bytes
- hdwallet.crypto.chacha20_poly1305_encrypt(key: bytes | str, nonce: bytes | str, assoc_data: bytes | str, plain_text: bytes | str) Tuple[bytes, bytes]¶
Encrypt data using ChaCha20-Poly1305 AEAD cipher.
- Parameters:
key (Union[bytes, str]) – The encryption key, as bytes or a string.
nonce (Union[bytes, str]) – The nonce value, as bytes or a string.
assoc_data (Union[bytes, str]) – The associated data to authenticate, as bytes or a string.
plain_text (Union[bytes, str]) – The plaintext data to be encrypted, as bytes or a string.
- Returns:
A tuple containing the encrypted data and the authentication tag.
- Return type:
Tuple[bytes, bytes]
- hdwallet.crypto.chacha20_poly1305_decrypt(key: bytes | str, nonce: bytes | str, assoc_data: bytes | str, cipher_text: bytes | str, tag: bytes | str) bytes¶
Decrypt data using ChaCha20-Poly1305 AEAD cipher.
- Parameters:
key (Union[bytes, str]) – The decryption key, as bytes or a string.
nonce (Union[bytes, str]) – The nonce value, as bytes or a string.
assoc_data (Union[bytes, str]) – The associated data used during encryption, as bytes or a string.
cipher_text (Union[bytes, str]) – The encrypted data to be decrypted, as bytes or a string.
tag (Union[bytes, str]) – The authentication tag associated with the encrypted data, as bytes or a string.
- Returns:
The decrypted plaintext data.
- Return type:
bytes
- hdwallet.crypto.sha256(data: str | bytes) bytes¶
Calculate the SHA-256 hash of the given data.
- Parameters:
data (Union[str, bytes]) – The data to hash, as bytes or a string.
- Returns:
The SHA-256 hash digest as bytes.
- Return type:
bytes
- hdwallet.crypto.double_sha256(data: str | bytes) bytes¶
Calculate the double SHA-256 hash of the given data.
- Parameters:
data (Union[str, bytes]) – The data to hash, as bytes or a string.
- Returns:
The double SHA-256 hash digest as bytes.
- Return type:
bytes
- hdwallet.crypto.hash160(data: str | bytes) bytes¶
Calculate the HASH160 hash (RIPEMD-160 of SHA-256) of the given data.
- Parameters:
data (Union[str, bytes]) – The data to hash, as bytes or a string.
- Returns:
The HASH160 hash digest as bytes.
- Return type:
bytes
- hdwallet.crypto.crc32(data: bytes | str) bytes¶
Calculate the CRC-32 checksum of the given data.
- Parameters:
data (Union[bytes, str]) – The data to calculate the CRC-32 checksum for, as bytes or a string.
- Returns:
The CRC-32 checksum as a 4-byte bytes object.
- Return type:
bytes
- hdwallet.crypto.xmodem_crc(data: bytes | str) bytes¶
Calculate the XMODEM CRC checksum of the given data.
- Parameters:
data (Union[bytes, str]) – The data to calculate the XMODEM CRC checksum for, as bytes or a string.
- Returns:
The XMODEM CRC checksum as a bytes object.
- Return type:
bytes
- hdwallet.crypto.pbkdf2_hmac_sha512(password: bytes | str, salt: bytes | str, iteration_num: int, derived_key_length: int | None = None) bytes¶
Derive a key using PBKDF2-HMAC-SHA512.
- Parameters:
password (Union[bytes, str]) – The password to derive the key from, as bytes or a string.
salt (Union[bytes, str]) – The salt value used in the key derivation process, as bytes or a string.
iteration_num (int) – The number of iterations of the HMAC-SHA512 hashing to apply.
derived_key_length (Optional[int]) – Optional. The desired length of the derived key in bytes. If not provided, it defaults to SHA-512 digest size.
- Returns:
The derived key as bytes.
- Return type:
bytes
- hdwallet.crypto.kekkak256(data: str | bytes) bytes¶
Calculate the Keccak-256 hash of the given data.
- Parameters:
data (Union[str, bytes]) – The data to hash, as bytes or a string.
- Returns:
The Keccak-256 hash digest as bytes.
- Return type:
bytes
- hdwallet.crypto.ripemd160(data: str | bytes) bytes¶
Calculate the RIPEMD-160 hash of the given data.
- Parameters:
data (Union[str, bytes]) – The data to hash, as bytes or a string.
- Returns:
The RIPEMD-160 hash digest as bytes.
- Return type:
bytes
- hdwallet.crypto.get_checksum(data: str | bytes) bytes¶
Calculate the checksum for the given raw bytes.
The checksum is derived by performing a double SHA-256 hash on the input and returning the first few bytes, as determined by CHECKSUM_BYTE_LENGTH.
- Parameters:
data (Union[str, bytes]) – The raw data to checksum.
- Returns:
The checksum of the data.
- Return type:
bytes
- hdwallet.crypto.sha512(data: str | bytes) bytes¶
Calculate the SHA-512 hash of the given data.
- Parameters:
data (Union[str, bytes]) – The data to hash, as bytes or a string.
- Returns:
The SHA-512 hash digest as bytes.
- Return type:
bytes
- hdwallet.crypto.sha512_256(data: str | bytes) bytes¶
Calculate the SHA-512/256 hash of the given data.
- Parameters:
data (Union[str, bytes]) – The data to hash, as bytes or a string.
- Returns:
The SHA-512/256 hash digest as bytes.
- Return type:
bytes
- hdwallet.crypto.sha3_256(data: str | bytes) bytes¶
Calculate the SHA3-256 hash of the given data.
- Parameters:
data (Union[str, bytes]) – The data to hash, as bytes or a string.
- Returns:
The SHA3-256 hash digest as bytes.
- Return type:
bytes