Skip to content

Instantly share code, notes, and snippets.

@earthchie
Created January 3, 2023 14:19
Show Gist options
  • Save earthchie/ac5b548a5b578182194312b222ac91c3 to your computer and use it in GitHub Desktop.
Save earthchie/ac5b548a5b578182194312b222ac91c3 to your computer and use it in GitHub Desktop.
const slip39 = require('slip39');
const original = 'Secret Message Here';
const shares = splitSLIP39(original);
console.log('Shares', shares);
const recoverd = recoverSLIP39([shares[1], shares[0]]); // pick any two to recover
console.log(recoverd);
function splitSLIP39(str, threashold = {need: 2, from: 3}){
const slip = slip39.fromArray(str.slip39EncodeHex(), {
passphrase: '',
groups: [
[threashold.need, threashold.from]
]
});
return slip.fromPath('r/0').children.map(i=>i.mnemonic);
}
function recoverSLIP39(shares){
return slip39.recoverSecret(shares, '').slip39DecodeHex();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment