encodeShares static method
Implementation
static Iterable<Uint8List> encodeShares(
{required Uint8List secretBytes, int threshold = 2, int? seed}) sync* {
if (threshold < 1 || threshold > 255) {
throw Exception('Threshold must be 1-255');
}
Random random = seed == null ? Random.secure() : Random(seed);
List<Uint8List> coefficients = [];
BytesBuilder bb = BytesBuilder();
for (int j = 0; j < secretBytes.length; j++) {
Uint8List coef = Uint8List(threshold);
coef[0] = secretBytes[j];
for (int d = 1; d < threshold; d++) {
coef[d] = random.nextInt(256);
}
bb.add(coef);
coefficients.add(bb.takeBytes());
}
int shareIndex = 0;
while (shareIndex < 256) {
shareIndex++;
bb.addByte(shareIndex);
for (int j = 0; j < secretBytes.length; j++) {
bb.addByte(evaluate(coefficients[j], shareIndex));
}
yield bb.takeBytes();
}
}