entropyToMnemonic function
Implementation
String entropyToMnemonic(String entropyString, {String language = 'english'}) {
final entropy;
try {
entropy = Uint8List.fromList(HexCoder.instance.decode(entropyString));
} catch (err) {
throw ArgumentError('Invalid entropy');
}
if (entropy.length < 16) {
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 = RegExp(r'.{1,11}', caseSensitive: false, multiLine: false);
final chunks = regex
.allMatches(bits)
.map((match) => match.group(0)!)
.toList(growable: false);
final dictionary =
DefaultDictionary((Language_Registry[language] ?? const []), language);
var words =
chunks.map((binary) => dictionary.words[_binaryToByte(binary)]).join(' ');
return nfkd(words);
}