Blockchain Commons Shamir Secret Sharing TypeScript Library - v1.0.0-alpha.13
    Preparing search index...

    Function splitSecret

    • Splits a secret into shares using the Shamir secret sharing algorithm.

      Parameters

      • threshold: number

        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.

      • shareCount: number

        The total number of shares to generate. Must be at least threshold and less than or equal to MAX_SHARE_COUNT.

      • secret: Uint8Array

        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.

      • randomGenerator: RandomNumberGenerator

        An implementation of the RandomNumberGenerator interface, used to generate random data.

      Returns Uint8Array<ArrayBufferLike>[]

      An array of Uint8Array representing the shares of the secret.

      ShamirError if parameters are invalid

      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