wordsToBytesChunk static method

List<int> wordsToBytesChunk(
  1. String word1,
  2. String word2,
  3. String word3,
  4. MnemonicWordsList wordsList, {
  5. Endian endian = Endian.big,
})

Converts a sequence of three words into a byte chunk using a specified word list.

The three input words are mapped to their respective indices within the wordsList. These indices are used to calculate an integer value that is then transformed into a byte chunk. The resulting byte chunk is returned.

You can also specify the endian order for byte interpretation (default is little-endian).

Example usage:

final chunk = MnemonicUtils.wordsToBytesChunk('word1', 'word2', 'word3', wordsList);

The method allows for encoding three words as a chunk of bytes for various mnemonic systems.

Implementation

static List<int> wordsToBytesChunk(
    String word1, String word2, String word3, MnemonicWordsList wordsList,
    {Endian endian = Endian.big}) {
  final n = wordsList.length();
  final word1Idx = wordsList.getWordIdx(word1);
  final word2Idx = wordsList.getWordIdx(word2) % n;
  final word3Idx = wordsList.getWordIdx(word3) % n;

  final intChunk = word1Idx +
      (n * ((word2Idx - word1Idx) % n)) +
      (n * n * ((word3Idx - word2Idx) % n));

  return IntUtils.toBytes(intChunk, byteOrder: endian, length: 4);
}