The minimum number of shares required to reconstruct the secret. Must be greater than or equal to 1 and less than or equal to shareCount.
The total number of shares to generate. Must be at least threshold and less than or equal to MAX_SHARE_COUNT.
A Uint8Array containing the secret to be split. Must be at least MIN_SECRET_LEN bytes long and at most MAX_SECRET_LEN bytes long. The length must be an even number.
An implementation of the RandomNumberGenerator interface, used to generate random data.
An array of Uint8Array representing the shares of the secret.
import { splitSecret } from "@bcts/shamir";
import { SecureRandomNumberGenerator } from "@bcts/rand";
const threshold = 2;
const shareCount = 3;
const secret = new TextEncoder().encode("my secret belongs to me.");
const rng = new SecureRandomNumberGenerator();
const shares = splitSecret(threshold, shareCount, secret, rng);
console.log(shares.length); // 3
Splits a secret into shares using the Shamir secret sharing algorithm.