decodeShareBase64 method
Takes a string array of shares encoded in Base64 created via Shamir's Algorithm; each string must be of equal length of a multiple of 88 characters as a single 88 character share is a pair of 256-bit numbers (x, y).
Implementation
List<List<List<BigInt>>> decodeShareBase64(List<String> shares) {
String first = shares[0];
int parts = first.length ~/ 88;
// Recreate the original object of x, y points, based upon number of shares
// and size of each share (number of parts in the secret).
//
// points[shares][parts][2]
var points = List<List<List<BigInt>>>.generate(
shares.length, (i) => List<List<BigInt>>.generate(parts, (j) => List<BigInt>.generate(2, (k) => BigInt.zero)));
// For each share...
for (int i = 0; i < shares.length; i++) {
// ensure that it is valid
if (isValidShareBase64(shares[i]) == false) {
throw new Exception("one of the shares is invalid");
}
// find the number of parts it represents.
String share = shares[i];
int count = share.length ~/ 88;
// and for each part, find the x,y pair...
for (int j = 0; j < count; j++) {
String cshare = share.substring(j * 88, (j + 1) * 88);
// decoding from Hex.
points[i][j][0] = fromBase64Url(cshare.substring(0, 44));
points[i][j][1] = fromBase64Url(cshare.substring(44, 88));
}
}
return points;
}