UNPKG

capacitor-shamir

Version:

Provides Shamir's Secret Sharing (SSS) functionality for secure splitting and recovering secrets natively on iOS, Android, and Web.

36 lines (35 loc) 1.59 kB
import { Parts, RandomBytes } from './GF256'; /** * Splits the given secret into {@code n} parts, of which any {@code k} or more can be combined to * recover the original secret. * @param {(number) => Uint8Array} randomBytes Takes a length and returns a random * Uint8Array of that length * @param {number} n the number of parts to produce (must be `>1`) * @param {number} k the threshold of joinable parts (must be `<= n`}) * @param {Uint8Array} secret The secret to split as an array of bytes * @return {Parts} an map of `n` parts that are arrays of bytes of the * secret length */ export declare function split(randomBytes: RandomBytes, n: number, k: number, secret: Uint8Array): Parts; /** * Joins the given parts to recover the original secret. * * <p><b>N.B.:</b> There is no way to determine whether or not the returned value is actually the * original secret. If the parts are incorrect, or are under the threshold value used to split the * secret, a random value will be returned. * * @param {Parts} parts an map of {@code n} parts that are arrays of bytes * of the secret length * @return {Uint8Array} the original secret * */ export declare function join(parts: Parts): Uint8Array; /** * Restores a part given a map of parts and a new index. * * @param {Parts} parts a map of part IDs to part values * @param {number} partIdx the new index for the part * @return {Uint8Array} the restored part * @throws {Error} if parts is empty or contains values of varying lengths */ export declare function restorePart(parts: Parts, partIdx: number): Uint8Array;