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

    Function recoverSecret

    • Recovers the secret from the given shares using the Shamir secret sharing algorithm.

      Parameters

      • indexes: number[]

        An array of indexes of the shares to be used for recovering the secret. These are the indexes of the shares returned by splitSecret.

      • shares: Uint8Array<ArrayBufferLike>[]

        An array of shares of the secret matching the indexes in indexes. These are the shares returned by splitSecret.

      Returns Uint8Array

      A Uint8Array representing the recovered secret.

      ShamirError if parameters are invalid or checksum verification fails

      import { recoverSecret } from "@bcts/shamir";

      const indexes = [0, 2];
      const shares = [
      new Uint8Array([47, 165, 102, 232, ...]),
      new Uint8Array([221, 174, 116, 201, ...]),
      ];

      const secret = recoverSecret(indexes, shares);
      console.log(new TextDecoder().decode(secret)); // "my secret belongs to me."