diff --git a/secrets.js b/secrets.js index 29bd08f..afc1ce5 100644 --- a/secrets.js +++ b/secrets.js @@ -243,7 +243,7 @@ exports.share = function(secret, numShares, threshold, padLength, withoutPrefix) } }else{ for(var i=0; idefaults.maxBits)){ throw new Error('Number of bits must be an integer between ' + defaults.minBits + ' and ' + defaults.maxBits + ', inclusive.') } @@ -308,7 +308,7 @@ function processShare(share){ var max = Math.pow(2, bits) - 1; var idLength = max.toString(config.radix).length; - var id = parseInt(share.substr(1, idLength), config.radix); + var id = parseInt(share.substr(2, idLength), config.radix); if(typeof id !== 'number' || id%1 !== 0 || id<1 || id>max){ throw new Error('Share id must be an integer between 1 and ' + config.max + ', inclusive.'); } @@ -392,7 +392,7 @@ exports.newShare = function(id, shares){ } var padding = max.toString(config.radix).length; - return config.bits.toString(36).toUpperCase() + padLeft(id.toString(config.radix), padding) + combine(id, shares); + return padLeft(config.bits.toString(36).toUpperCase(), 2) + padLeft(id.toString(config.radix), padding) + combine(id, shares); }; // Evaluate the Lagrange interpolation polynomial at x = `at` @@ -529,4 +529,4 @@ exports.hex2str = function(str, bytesPerChar){ // by default, initialize without an RNG exports.init(); -})(typeof module !== 'undefined' && module['exports'] ? module['exports'] : (window['secrets'] = {}), typeof GLOBAL !== 'undefined' ? GLOBAL : window ); \ No newline at end of file +})(typeof module !== 'undefined' && module['exports'] ? module['exports'] : (window['secrets'] = {}), typeof GLOBAL !== 'undefined' ? GLOBAL : window );