bytesChunkToWords static method
List<String>
bytesChunkToWords(
- List<
int> bytesChunk, - MnemonicWordsList wordsList, {
- Endian endian = Endian.big,
Converts a chunk of bytes into a list of three words using a provided word list.
The bytesChunk
is converted into an integer and then divided into three
indices within the specified wordsList
. The resulting words are returned
as a list.
You can also specify the endian
order for interpreting the bytes.
Example usage:
final words = MnemonicUtils.bytesChunkToWords(List<int>.from([0, 1, 2, 3]), wordsList);
Implementation
static List<String> bytesChunkToWords(
List<int> bytesChunk, MnemonicWordsList wordsList,
{Endian endian = Endian.big}) {
final n = wordsList.length();
final intChunk = IntUtils.fromBytes(bytesChunk, byteOrder: endian);
final word1Idx = intChunk % n;
final word2Idx = ((intChunk ~/ n) + word1Idx) % n;
final word3Idx = ((intChunk ~/ (n * n) + word2Idx)) % n;
return [
wordsList.getWordAtIdx(word1Idx),
wordsList.getWordAtIdx(word2Idx),
wordsList.getWordAtIdx(word3Idx),
];
}