encode method
Encodes a List<int>
of entropy bytes into an Electrum V1 mnemonic.
This method takes a List<int>
of entropy bytes as input and generates an Electrum V1 mnemonic by
dividing the entropy into 4-byte chunks and converting each chunk into a list of mnemonic words.
It checks the validity of the entropy byte length and throws an ArgumentException if it's not valid.
Returns an Electrum V1 mnemonic representing the encoded data.
entropyBytes
: The List<int>
of entropy bytes to encode.
Implementation
@override
Mnemonic encode(List<int> entropyBytes) {
// Check entropy length
final int entropyByteLen = entropyBytes.length;
if (!ElectrumV1EntropyGenerator.isValidEntropyByteLength(entropyByteLen)) {
throw ArgumentException(
'Entropy byte length ($entropyByteLen) is not valid');
}
// Build mnemonic
final List<String> mnemonic = [];
for (int i = 0; i < entropyBytes.length ~/ 4; i++) {
mnemonic.addAll(MnemonicUtils.bytesChunkToWords(
entropyBytes.sublist(i * 4, (i * 4) + 4), wordsList,
endian: Endian.big));
}
return ElectrumV1Mnemonic.fromList(mnemonic);
}