Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/functions/bip39_mnemonic.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ module.exports = function (S) {
checkSum: A.checkSumVerify, hex: false});
let bits;
if (A.embeddedIndex)
bits = Math.ceil(Math.log2(total))+1;
bits = S.__secret_index_bits(e);
else
bits = 8;

Expand Down Expand Up @@ -366,4 +366,4 @@ module.exports = function (S) {
return S.entropyToMnemonic(S.__restore_secret(s), A);
}

};
};
19 changes: 16 additions & 3 deletions src/functions/shamir_secret_sharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,24 @@ module.exports = function (S) {
};


S.__split_secret = (threshold, total, secret, indexBits=8) => {
S.__secret_index_bits = (secret) => {
const checksumBitsByEntropyLength = {
16: 4,
20: 5,
24: 6,
28: 7,
32: 8,
};

return checksumBitsByEntropyLength[secret.length] || 8;
};

S.__split_secret = (threshold, total, secret, indexBits=null) => {
if (threshold > 255) throw new Error("threshold limit 255");
if (total > 255) throw new Error("total limit 255");
if (indexBits === null) indexBits = S.__secret_index_bits(secret);
let index_mask = 2**indexBits - 1;
if (total > index_mask) throw new Error("index bits is to low");
if (total > index_mask) throw new Error("index bits is too low");
if (threshold > total) throw new Error("invalid threshold");
let shares = {};
let sharesIndexes = [];
Expand Down Expand Up @@ -167,4 +180,4 @@ module.exports = function (S) {
};

S.__precompute_GF256_expLog(S);
};
};
15 changes: 15 additions & 0 deletions test/jsbtc.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.