entropyToMnemonic function

String entropyToMnemonic(
  1. String entropyString, {
  2. String language = _defaultLanguage,
})

Implementation

String entropyToMnemonic(String entropyString,{String language=_defaultLanguage}) {
  final entropy = Uint8List.fromList(HEX.decode(entropyString));
  if (entropy.length < 4) {
    throw ArgumentError(_INVALID_ENTROPY);
  }
  if (entropy.length > 32) {
    throw ArgumentError(_INVALID_ENTROPY);
  }
  if (entropy.length % 4 != 0) {
    throw ArgumentError(_INVALID_ENTROPY);
  }
  final entropyBits = _bytesToBinary(entropy);
  final checksumBits = _deriveChecksumBits(entropy);
  final bits = entropyBits + checksumBits;
  final regex = new 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[language];
  String words = chunks.map((binary) => wordlist![_binaryToByte(binary)]).join(' ');
  return words;
}