Made padding removal more robust

This commit is contained in:
Joel Torstensson
2017-04-01 11:33:49 +02:00
parent 8d7f9eb10e
commit 81c6d11564

View File

@@ -2,6 +2,7 @@ const bip39 = require('bip39')
const ssss = require('secrets.js')
const paddingWord = 'abandon '
const numPaddingZeros = 3
function split(seed, numShards, threshold) {
if (threshold > numShards) {
@@ -11,7 +12,7 @@ function split(seed, numShards, threshold) {
let shards = ssss.share(ent, numShards, threshold)
let shardMnemonics = shards.map(shard => {
let padding = '0'.repeat(8 - shard.length%8)
let padding = '0'.repeat(numPaddingZeros)
return bip39.entropyToMnemonic(padding + shard)
})
// due to padding first word is always the same
@@ -20,8 +21,8 @@ function split(seed, numShards, threshold) {
function combine(shardMnemonics) {
let shards = shardMnemonics.map(sm =>
// due to padding first word is always the same
bip39.mnemonicToEntropy(paddingWord + sm).replace(/^(0+)/g, ''))
// due to padding first word is always the same
bip39.mnemonicToEntropy(paddingWord + sm).slice(numPaddingZeros))
let comb = ssss.combine(shards)
try {
return bip39.entropyToMnemonic(comb)