entropyToMnemonic function

String entropyToMnemonic(
  1. String entropyString
)

Implementation

String entropyToMnemonic(String entropyString) {
  final entropy = Uint8List.fromList(HEX.decode(entropyString));
  if (entropy.length < 16) {
    throw ArgumentError(invalidEntropy);
  }
  if (entropy.length > 32) {
    throw ArgumentError(invalidEntropy);
  }
  if (entropy.length % 4 != 0) {
    throw ArgumentError(invalidEntropy);
  }
  final entropyBits = _bytesToBinary(entropy);
  final checksumBits = _deriveChecksumBits(entropy);
  final bits = entropyBits + checksumBits;
  final regex = RegExp(r'.{1,11}', caseSensitive: false, multiLine: false);
  final chunks = regex
      .allMatches(bits)
      .map((match) => match.group(0)!)
      .toList(growable: false);
  List<String> wordlist = WORDLIST;
  String words =
      chunks.map((binary) => wordlist[_binaryToByte(binary)]).join(' ');
  return words;
}