INNER CODE UNIT · TypeScript
newCoordinates
privy-io/shamir-secret-sharing · src/index.ts:157
function newCoordinates(): Readonly<Uint8Array> {
const coordinates = new Uint8Array(255);
for (let i = 0; i < 255; i++) {
coordinates[i] = i + 1;
}
// Pseudo-randomize the array of coordinates.
//
// This impl maps almost perfectly because both of the lists (coordinates and randomIndices)
// have a length of 255 and byte values are between 0 and 255 inclusive. The only value that
// does not map neatly here is if the random byte is 255, since that value used as an index
// would be out of bounds. Thus, for bytes whose value is 255, wrap around to 0.
//
// WARNING: This shuffle is biased and should NOT be used if an unbiased shuffle is required.
//
// However, Shamir-based secret sharing does not require any particular indexing (shuffled or
// not) for its security properties to hold; this means including the biased shuffle is not
// itself problematic here.