def __EntropyBytesFromBinaryStr(self, mnemonic_bin_str: str) -> bytes: """ Get entropy bytes from mnemonic binary string. Args: mnemonic_bin_str (str): Mnemonic binary string Returns: bytes: Entropy bytes """ # Get checksum length checksum_len = self.__GetChecksumLen(mnemonic_bin_str) # Get back entropy binary string entropy_bin_str = mnemonic_bin_str[:-checksum_len] # Get entropy bytes from binary string return BytesUtils.FromBinaryStr(entropy_bin_str, checksum_len * 8)
def DecodeWithChecksum(self, mnemonic: Union[str, Mnemonic]) -> bytes: """ Decode a mnemonic phrase to bytes (with checksum). Args: mnemonic (str or Mnemonic object): Mnemonic Returns: bytes: Decoded bytes (with checksum) Raises: MnemonicChecksumError: If checksum is not valid ValueError: If mnemonic is not valid """ mnemonic_bin_str = self.__DecodeAndVerifyBinaryStr(mnemonic) # Compute pad bit length mnemonic_bit_len = len(mnemonic_bin_str) pad_bit_len = (mnemonic_bit_len if mnemonic_bit_len % 8 == 0 else mnemonic_bit_len + (8 - mnemonic_bit_len % 8)) return BytesUtils.FromBinaryStr(mnemonic_bin_str, pad_bit_len // 4)