secrets

secrets

Source:
Secrets management

Methods

(static) combine(shares, k, n) → {Buffer}

Source:
Since:
  • 0.8.0
Author:
K-of-N secret combining. Uses bitwise XOR for k=n, Shamir's Secret Sharing for 1 < K < N, and direct secret sharing for K = 1.
Example
// share secret using 2-of-3 shares
const shares = mfkdf.secrets.share(Buffer.from('hello world'), 2, 3) // -> [Buffer, Buffer, Buffer]

// recover secret using 2 shares
const secret = mfkdf.secrets.combine([shares[0], null, shares[2]], 2, 3)
secret.toString() // -> hello world

// recover original 3 shares
const recover = mfkdf.secrets.recover([shares[0], null, shares[2]], 2, 3) // -> [Buffer, Buffer, Buffer]
Parameters:
Name Type Description
shares Array.<Buffer> The secret shares to be combined
k number The threshold of shares required to reconstruct the secret
n number The number of shares that were originally generated
Returns:
The retrieved secret as a Buffer
Type
Buffer

(static) recover(shares, k, n) → {Buffer}

Source:
Since:
  • 0.8.0
Author:
K-of-N secret recovery. Uses bitwise XOR for k=n, Shamir's Secret Sharing for 1 < K < N, and direct secret sharing for K = 1.
Example
// share secret using 2-of-3 shares
const shares = mfkdf.secrets.share(Buffer.from('hello world'), 2, 3) // -> [Buffer, Buffer, Buffer]

// recover secret using 2 shares
const secret = mfkdf.secrets.combine([shares[0], null, shares[2]], 2, 3)
secret.toString() // -> hello world

// recover original 3 shares
const recover = mfkdf.secrets.recover([shares[0], null, shares[2]], 2, 3) // -> [Buffer, Buffer, Buffer]
Parameters:
Name Type Description
shares Array.<Buffer> The secret shares to be combined
k number The threshold of shares required to reconstruct the secret
n number The number of shares that were originally generated
Returns:
The retrieved secret as a Buffer
Type
Buffer

(static) share(secret, k, n) → {Array.<Buffer>}

Source:
Since:
  • 0.8.0
Author:
K-of-N secret sharing. Uses bitwise XOR for k=n, Shamir's Secret Sharing for 1 < K < N, and direct secret sharing for K = 1.
Example
// share secret using 2-of-3 shares
const shares = mfkdf.secrets.share(Buffer.from('hello world'), 2, 3) // -> [Buffer, Buffer, Buffer]

// recover secret using 2 shares
const secret = mfkdf.secrets.combine([shares[0], null, shares[2]], 2, 3)
secret.toString() // -> hello world

// recover original 3 shares
const recover = mfkdf.secrets.recover([shares[0], null, shares[2]], 2, 3) // -> [Buffer, Buffer, Buffer]
Parameters:
Name Type Description
secret Buffer The secret value to be shared
k number The threshold of shares required to reconstruct the secret
n number The number of shares to generate
Returns:
An array of N shares as Buffers
Type
Array.<Buffer>