@digitaldefiance/secrets 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd/secrets.min.js +1 -1
- package/package.json +7 -7
package/dist/umd/secrets.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @digitaldefiance/secrets 2026-01-
|
|
1
|
+
/*! @digitaldefiance/secrets 2026-01-14 */
|
|
2
2
|
(e=>{"object"==typeof module&&"object"==typeof module.exports?e(require,exports):"function"==typeof define&&define.amd&&define(["require","exports"],e)})(function(i,e){var f,b,n,o,s,a;function h(){f={bits:8,radix:16,minBits:3,maxBits:20,bytesPerChar:2,maxBytesPerChar:6,primitivePolynomials:[null,null,1,3,3,5,3,3,29,17,9,5,83,27,43,3,45,9,39,39,9,5,3,33,27,9,71,39,9,5,83]},b={},n=new Array(1024).join("0"),o=!0,a=[];for(var e=0;e<=255;e++){var t=e.toString(16);1===t.length&&(t="0"+t),a.push(t)}s=["nodeCryptoRandomBytes","browserCryptoGetRandomValues","testRandom"]}function u(){return!(!b||!b.rng||"function"!=typeof b.rng)}function m(e,t){var r;if(0===t||1===t)return e;if(t&&1024<t)throw new Error("Padding must be multiples of no larger than 1024 bits.");t=t||b.bits;return(r=e?e.length%t:r)?(n+e).slice(-(t-r+e.length)):e}function p(e){for(var t,r="",n=e.length-1;0<=n;n--){if(t=parseInt(e[n],16),isNaN(t))throw new Error("Invalid hex character.");r=m(t.toString(2),4)+r}return r}function g(e){for(var t,r="",n=(e=m(e,4)).length;4<=n;n-=4){if(t=parseInt(e.slice(n-4,n),2),isNaN(t))throw new Error("Invalid binary character.");r=t.toString(16)+r}return r}function l(e){for(var t="",r=0;r<e.length;r++)t+=a[e[r]];return t}function c(){var e="undefined"!=typeof window&&window.crypto||global.crypto;return!(!e||"object"!=typeof e||"function"!=typeof e.getRandomValues&&"object"!=typeof e.getRandomValues||"function"!=typeof Uint32Array&&"object"!=typeof Uint32Array)}function d(){var e;try{e=i("crypto")}catch(e){return!1}return"object"==typeof e&&"function"==typeof e.randomBytes}function w(e){function o(e,t,r,n){var i,o=0,a="";for(t&&(i=t.length-1);o<i||a.length<e;)a+=m(Math.abs(parseInt(t[o],r)).toString(2),n),o++;return((a=a.substr(-e)).match(/0/g)||[]).length===a.length?null:a}function t(e){for(var t=null,r=Math.ceil(e/8),n=i("crypto");null===t;)t=o(e,l(n.randomBytes(r)),16,4);return t}function r(e){for(var t=null,r=Math.ceil(e/32),n="undefined"!=typeof window&&window.crypto||global.crypto;null===t;)t=o(e,n.getRandomValues(new Uint32Array(r)),10,32);return t}return e&&"testRandom"===e?(b.typeCSPRNG=e,function(e){for(var t=null,r=Math.ceil(e/32),n=new Uint32Array(r),i=0;i<n.length;i++)n[i]=123456789;for(;null===t;)t=o(e,n,10,32);return t}):e&&"nodeCryptoRandomBytes"===e?(b.typeCSPRNG=e,t):e&&"browserCryptoGetRandomValues"===e?(b.typeCSPRNG=e,r):d()?(b.typeCSPRNG="nodeCryptoRandomBytes",t):c()?(b.typeCSPRNG="browserCryptoGetRandomValues",r):void 0}function y(e,t){for(var r=[],n=(e=t?m(e,t):e).length;n>b.bits;n-=b.bits)r.push(parseInt(e.slice(n-b.bits,n),2));return r.push(parseInt(e.slice(0,n),2)),r}function x(e,t){for(var r=b.logs[e],n=0,i=t.length-1;0<=i;i--)n=0!==n?b.exps[(r+b.logs[n])%b.maxShares]^t[i]:t[i];return n}function v(e,t,r){for(var n=0,i=t.length,o=0;o<i;o++)if(r[o]){for(var a=b.logs[r[o]],s=0;s<i;s++)if(o!==s){if(e===t[s]){a=-1;break}a=(a+b.logs[e^t[s]]-b.logs[t[o]^t[s]]+b.maxShares)%b.maxShares}n=-1===a?n:n^b.exps[a]}return n}function S(e,t,r){for(var n=[],i=[e],o=1;o<r;o++)i[o]=parseInt(b.rng(b.bits),2);for(var o=1,a=t+1;o<a;o++)n[o-1]={x:o,y:x(o,i)};return n}function N(e,t,r){var e="string"==typeof e?parseInt(e,10):e,n=e.toString(36).toUpperCase(),e=Math.pow(2,e)-1,t="number"==typeof t?t:"string"==typeof t?parseInt(t,10):NaN;if("number"!=typeof t||t%1!=0||t<1||e<t||isNaN(t))throw new Error("Share id must be an integer between 1 and "+e+", inclusive.");e=e.toString(b.radix).length;return n+m(t.toString(b.radix),e)+r}Object.defineProperty(e,"__esModule",{value:!0}),e.newShare=e.share=e.random=e.hex2str=e.str2hex=e.setRNG=e.extractShareComponents=e.getConfig=e.combine=e.init=void 0;var t={init:function(e,t){var r=[],n=[],i=1;if(h(),e&&("number"!=typeof e||e%1!=0||e<f.minBits||e>f.maxBits))throw new Error("Number of bits must be an integer between "+f.minBits+" and "+f.maxBits+", inclusive.");if(t&&-1===s.indexOf(t))throw new Error("Invalid RNG type argument : '"+t+"'");b.radix=f.radix,b.bits=e||f.bits,b.size=Math.pow(2,b.bits),b.maxShares=b.size-1;for(var o=f.primitivePolynomials[b.bits],a=0;a<b.size;a++)r[n[a]=i]=a,(i<<=1)>=b.size&&(i=(i^=o)&b.maxShares);if(b.logs=r,b.exps=n,t&&this.setRNG(t),u()||this.setRNG(),!(u()&&b.bits&&b.size&&b.maxShares&&b.logs&&b.exps&&b.logs.length===b.size&&b.exps.length===b.size))throw new Error("Initialization failed.")},combine:function(e,t){var r,n,i=[],o=[],a="";t=t||0;for(var s=0,h=e.length;s<h;s++){if(n=this.extractShareComponents(e[s]),void 0===r)r=n.bits;else if(n.bits!==r)throw new Error("Mismatched shares: Different bit settings.");if(b.bits!==r&&this.init(r),-1===i.indexOf(n.id)){i.push(n.id);for(var f,u=0,l=(f=y(p(n.data))).length;u<l;u++)o[u]=o[u]||[],o[u][i.length-1]=f[u]}}for(s=0,h=o.length;s<h;s++)a=m(v(t,i,o[s]).toString(2))+a;return g(1<=t?a:a.slice(a.indexOf("1")+1))},getConfig:function(){return{radix:b.radix,bits:b.bits,maxShares:b.maxShares,hasCSPRNG:u(),typeCSPRNG:b.typeCSPRNG}},extractShareComponents:function(e){var t,r,n,i=parseInt(e.substr(0,1),36);if(i&&("number"!=typeof i||i%1!=0||i<f.minBits||i>f.maxBits))throw new Error("Invalid share : Number of bits must be an integer between "+f.minBits+" and "+f.maxBits+", inclusive.");if(r=Math.pow(2,i)-1,n=(Math.pow(2,i)-1).toString(b.radix).length,"number"!=typeof(t=(n=new RegExp("^([a-kA-K3-9]{1})([a-fA-F0-9]{"+n+"})([a-fA-F0-9]+)$").exec(e))?parseInt(n[2],b.radix):t)||t%1!=0||t<1||r<t)throw new Error("Invalid share : Share id must be an integer between 1 and "+b.maxShares+", inclusive.");if(n&&n[3])return{bits:i,id:t,data:n[3]};throw new Error("The share data provided is invalid : "+e)},setRNG:function(e){var t="Random number generator is invalid ",r=" Supply an CSPRNG of the form function(bits){} that returns a string containing 'bits' number of random 1's and 0's.";if(e&&"string"==typeof e&&-1===s.indexOf(e))throw new Error("Invalid RNG type argument : '"+e+"'");if(e=e?"string"==typeof e?w(e):e:w(),o&&e){if("function"!=typeof e)throw new Error(t+"(Not a function)."+r);if("string"!=typeof e(b.bits))throw new Error(t+"(Output is not a string)."+r);if(!parseInt(e(b.bits),2))throw new Error(t+"(Binary string output not parseable to an Integer)."+r);if(e(b.bits).length>b.bits)throw new Error(t+"(Output length is greater than config.bits)."+r);if(e(b.bits).length<b.bits)throw new Error(t+"(Output length is less than config.bits)."+r)}return b.rng=e,!0},str2hex:function(e,t){var r,n,i="";if("string"!=typeof e)throw new Error("Input must be a character string.");if("number"!=typeof(t=t||f.bytesPerChar)||t<1||t>f.maxBytesPerChar||t%1!=0)throw new Error("Bytes per character must be an integer between 1 and "+f.maxBytesPerChar+", inclusive.");for(var o=2*t,a=Math.pow(16,o)-1,s=0,h=e.length;s<h;s++){if(n=e[s].charCodeAt(0),isNaN(n))throw new Error("Invalid character: "+e[s]);if(a<n)throw r=Math.ceil(Math.log(n+1)/Math.log(256)),new Error("Invalid character code ("+n+"). Maximum allowable is 256^bytes-1 ("+a+"). To convert this character, use at least "+r+" bytes.");i=m(n.toString(16),o)+i}return i},hex2str:function(e,t){var r="";if("string"!=typeof e)throw new Error("Input must be a hexadecimal string.");if("number"!=typeof(t=t||f.bytesPerChar)||t%1!=0||t<1||t>f.maxBytesPerChar)throw new Error("Bytes per character must be an integer between 1 and "+f.maxBytesPerChar+", inclusive.");for(var n,i=0,o=(e=m(e,n=2*t)).length;i<o;i+=n)r=String.fromCharCode(parseInt(e.slice(i,i+n),16))+r;return r},random:function(e){if("number"!=typeof e||e%1!=0||e<2||65536<e)throw new Error("Number of bits must be an Integer between 1 and 65536.");return g(b.rng(e))},share:function(e,t,r,n){var i,o=new Array(t),a=new Array(t);if(n=n||128,"string"!=typeof e)throw new Error("Secret must be a string.");if("number"!=typeof t||t%1!=0||t<2)throw new Error("Number of shares must be an integer between 2 and 2^bits-1 ("+b.maxShares+"), inclusive.");if(t>b.maxShares)throw i=Math.ceil(Math.log(t+1)/Math.LN2),new Error("Number of shares must be an integer between 2 and 2^bits-1 ("+b.maxShares+"), inclusive. To create "+t+" shares, use at least "+i+" bits.");if("number"!=typeof r||r%1!=0||r<2)throw new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 ("+b.maxShares+"), inclusive.");if(r>b.maxShares)throw i=Math.ceil(Math.log(r+1)/Math.LN2),new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 ("+b.maxShares+"), inclusive. To use a threshold of "+r+", use at least "+i+" bits.");if(t<r)throw new Error("Threshold number of shares was "+r+" but must be less than or equal to the "+t+" shares specified as the total to generate.");if("number"!=typeof n||n%1!=0||n<0||1024<n)throw new Error("Zero-pad length must be an integer between 0 and 1024 inclusive.");for(var s=y("1"+p(e),n),h=0,f=s.length;h<f;h++)for(var u=S(s[h],t,r),l=0;l<t;l++)o[l]=o[l]||u[l].x,a[l]=m(u[l].y.toString(2))+(a[l]||"");for(h=0;h<t;h++)o[h]=N(b.bits,o[h],g(a[h]));return o},newShare:function(e,t){e="string"==typeof e?parseInt(e,10):"number"==typeof e?Math.floor(e):NaN;if(e&&t&&t[0])return N(this.extractShareComponents(t[0]).bits,e,this.combine(t,e));throw new Error("Invalid 'id' or 'shares' Array argument to newShare().")},_reset:h,_padLeft:m,_hex2bin:p,_bin2hex:g,_bytesToHex:l,_hasCryptoGetRandomValues:c,_hasCryptoRandomBytes:d,_getRNG:w,_isSetRNG:u,_splitNumStringToIntArray:y,_horner:x,_lagrange:v,_getShares:S,_constructPublicShareString:N};t.init(),"undefined"!=typeof module&&module.exports&&(module.exports=t),"undefined"!=typeof window&&(window.secrets=t),e.default=t,e.init=t.init,e.combine=t.combine,e.getConfig=t.getConfig,e.extractShareComponents=t.extractShareComponents,e.setRNG=t.setRNG,e.str2hex=t.str2hex,e.hex2str=t.hex2str,e.random=t.random,e.share=t.share,e.newShare=t.newShare});
|
package/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/secrets",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "Shamir's threshold secret sharing scheme",
|
|
5
5
|
"main": "dist/secrets.js",
|
|
6
6
|
"module": "dist/esm/secrets.js",
|
|
7
7
|
"types": "dist/secrets.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
+
"types": "./dist/secrets.d.ts",
|
|
10
11
|
"import": "./dist/esm/secrets.js",
|
|
11
|
-
"require": "./dist/secrets.js"
|
|
12
|
-
"types": "./dist/secrets.d.ts"
|
|
12
|
+
"require": "./dist/secrets.js"
|
|
13
13
|
},
|
|
14
14
|
"./umd": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"types": "./dist/umd/secrets.d.ts",
|
|
16
|
+
"default": "./dist/umd/secrets.js"
|
|
17
17
|
},
|
|
18
18
|
"./types": {
|
|
19
|
+
"types": "./dist/types.d.ts",
|
|
19
20
|
"import": "./dist/esm/types.js",
|
|
20
|
-
"require": "./dist/types.js"
|
|
21
|
-
"types": "./dist/types.d.ts"
|
|
21
|
+
"require": "./dist/types.js"
|
|
22
22
|
},
|
|
23
23
|
"./package.json": "./package.json"
|
|
24
24
|
},
|