Utils¶
- bip38.utils.get_bytes(data: AnyStr, unhexlify: bool = True) bytes¶
Convert input data to bytes format.
- Parameters:
data (Union[bytes, str]) – The input data to convert. Can be bytes or string.
unhexlify (bool) – Flag indicating whether to interpret strings as hexadecimal (default True).
- Returns:
The input data converted to bytes format.
- Return type:
bytes
- bip38.utils.bytes_reverse(data: bytes) bytes¶
Reverse the order of bytes in a bytes object.
- Parameters:
data (bytes) – The bytes object to reverse.
- Returns:
The bytes object with its byte order reversed.
- Return type:
bytes
- bip38.utils.bytes_to_string(data: bytes | str) str¶
Convert bytes or string data to a hexadecimal string representation.
- Parameters:
data (Union[bytes, str]) – The bytes or string data to convert to hexadecimal string.
- Returns:
The hexadecimal string representation of the input data.
- Return type:
str
- bip38.utils.bytes_to_integer(data: bytes, endianness: Literal['little', 'big'] = 'big', signed: bool = False) int¶
Convert bytes to an integer based on specified endianness and signedness.
- Parameters:
data (bytes) – The bytes object to convert to an integer.
endianness (Literal["little", "big"]) – The byte order (“little” or “big”).
signed (bool) – Flag indicating whether the integer is signed (default False).
- Returns:
The integer value converted from bytes.
- Return type:
int
- bip38.utils.integer_to_bytes(data: int, bytes_num: int | None = None, endianness: Literal['little', 'big'] = 'big', signed: bool = False) bytes¶
Convert an integer to bytes based on specified parameters.
- Parameters:
data (int) – The integer to convert to bytes.
bytes_num (Optional[int]) – Optional number of bytes to use for the conversion. If not provided, it is calculated based on the integer’s bit length.
endianness (Literal["little", "big"]) – The byte order (“little” or “big”).
signed (bool) – Flag indicating whether the integer is signed (default False).
- Returns:
The bytes object representing the integer.
- Return type:
bytes