mirror of
https://github.com/oed/seedsplit.git
synced 2026-01-10 13:17:59 -05:00
Made padding removal more robust
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user