Skip to content
Snippets Groups Projects
secrets.js 820 B
Newer Older
  • Learn to ignore specific revisions
  • Sasha Ilieva's avatar
    Sasha Ilieva committed
    import { secrets } from "secrets.js-grempe";
    
    export /**
     * Function generates a random bits length string, and output it in hexadecimal format
     *
     * @param {number} bits
     */
    const generateRecoveryKey = bits => secrets.random(bits);
    
    /**
     * Divide a secret expressed in hexadecimal form into numShares number of shares, requiring that threshold number of shares be present for reconstructing the secret
     *
     * @param {string} secret
     * @param {number} numShares
     * @param {number} threshold
     * @param {number} [padLength=128]
     */
    export const divideSecretToShares = (
      secret,
      numShares,
      threshold,
      padLength = 128
    ) => secrets.share(secret, numShares, threshold, padLength);
    
    /**
     * Reconstructs a secret from shares
     *
     * @param {array} shares
     */
    export const combineSecret = shares => secrets.combine(shares);