Created
January 3, 2023 14:19
-
-
Save earthchie/ac5b548a5b578182194312b222ac91c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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