diff --git a/README.md b/README.md index f3d11fb..901f1c5 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)

modPow(b, e, n)bigint

Modular exponentiation b**e mod n. Currently using the right-to-left binary method

-
prime(bitLength, [iterations], sync)Promise
+
prime(bitLength, [iterations])Promise

A probably-prime (Miller-Rabin), cryptographically-secure, random-number generator. The browser version uses web workers to parallelise prime look up. Therefore, it does not lock the UI main process, and it can be much faster (if several cores or cpu are available). @@ -285,7 +285,7 @@ Modular exponentiation b**e mod n. Currently using the right-to-left binary meth -## prime(bitLength, [iterations], sync) ⇒ Promise +## prime(bitLength, [iterations]) ⇒ Promise A probably-prime (Miller-Rabin), cryptographically-secure, random-number generator. The browser version uses web workers to parallelise prime look up. Therefore, it does not lock the UI main process, and it can be much faster (if several cores or cpu are available). @@ -299,7 +299,6 @@ and can be enabled at runtime executing node --experimental-worker with node >=1 | --- | --- | --- | --- | | bitLength | number | | The required bit length for the generated prime | | [iterations] | number | 16 | The number of iterations for the Miller-Rabin Probabilistic Primality Test | -| sync | boolean | | NOT RECOMMENDED. Invoke the function synchronously. It won't use workers so it'll be slower and may freeze thw window in browser's javascript. | diff --git a/build/build.rollup.js b/build/build.rollup.js index 71acae9..4f9c7eb 100644 --- a/build/build.rollup.js +++ b/build/build.rollup.js @@ -27,24 +27,24 @@ const buildOptions = [ name: camelise(pkgJson.name) } }, - { // Browser minified - input: { - input: path.join(srcDir, 'main.js'), - plugins: [ - replace({ - 'process.browser': true - }), - minify({ - 'comments': false - }) - ], - }, - output: { - file: path.join(dstDir, `${pkgJson.name}-${pkgJson.version}.browser.min.js`), - format: 'iife', - name: camelise(pkgJson.name) - } - }, + // { // Browser minified + // input: { + // input: path.join(srcDir, 'main.js'), + // plugins: [ + // replace({ + // 'process.browser': true + // }), + // minify({ + // 'comments': false + // }) + // ], + // }, + // output: { + // file: path.join(dstDir, `${pkgJson.name}-${pkgJson.version}.browser.min.js`), + // format: 'iife', + // name: camelise(pkgJson.name) + // } + // }, { // Browser esm input: { input: path.join(srcDir, 'main.js'), diff --git a/dist/bigint-crypto-utils-latest.browser.js b/dist/bigint-crypto-utils-latest.browser.js index acf5ae0..dede38f 100644 --- a/dist/bigint-crypto-utils-latest.browser.js +++ b/dist/bigint-crypto-utils-latest.browser.js @@ -257,7 +257,6 @@ var bigintCryptoUtils = (function (exports) { * * @param {number} bitLength The required bit length for the generated prime * @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test - * @param {boolean} sync NOT RECOMMENDED. Invoke the function synchronously. It won't use workers so it'll be slower and may freeze thw window in browser's javascript. * * @returns {Promise} A promise that resolves to a bigint probable prime of bitLength bits. */ diff --git a/dist/bigint-crypto-utils-latest.browser.min.js b/dist/bigint-crypto-utils-latest.browser.min.js deleted file mode 100644 index 688bfdf..0000000 --- a/dist/bigint-crypto-utils-latest.browser.min.js +++ /dev/null @@ -1 +0,0 @@ -var bigintCryptoUtils=function(a){'use strict';function c(b){return b=BigInt(b),b>=s?b:-b}function d(b){if(b=BigInt(b),b===t)return 1;let c=1;do c++;while((b>>=t)>t);return c}function e(c,d){if(c=BigInt(c),d=BigInt(d),c<=s|d<=s)return NaN;let e=s,f=t,g=t,h=s;for(;c!==s;){let a=d/c,b=d%c,i=e-g*a,j=f-h*a;d=c,c=b,e=g,f=h,g=i,h=j}return{b:d,x:e,y:f}}function f(d,e){if(d=c(d),e=c(e),d===s)return e;if(e===s)return d;let f=s;for(;!((d|e)&t);)d>>=t,e>>=t,f++;for(;!(d&t);)d>>=t;do{for(;!(e&t);)e>>=t;if(d>e){let a=d;d=e,e=a}e-=d}while(e);return d<{const e=new Worker(o());e.onmessage=a=>{e.terminate(),c(a.data.isPrime)},e.onmessageerror=a=>{d(a)},e.postMessage({rnd:a,iterations:b,id:0})})}function h(b,a){if(b==s|a<=s)return NaN;let c=e(m(b,a),a);return c.b===t?m(c.x,a):NaN}function i(a,d,f){if(f=BigInt(f),f===s)return NaN;if(f===t)return s;if(a=m(a,f),d=BigInt(d),d min");const c=a-b;let e,f=d(c);do{let a=k(f);e=n(a)}while(e>c);return e+b}function k(a,b=!1){var c=Math.ceil;if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);const d=c(a/8);let e=l(d,!1);if(e[0]&=2**(a%8)-1,b){let b=a%8?2**(a%8-1):128;e[0]|=b}return e}function l(a,b=!1){if(1>a)throw new RangeError(`byteLength MUST be > 0 and it is ${a}`);let c;return c=new Uint8Array(a),self.crypto.getRandomValues(c),b&&(c[0]|=128),c}function m(b,c){return(c=BigInt(c),0>=c)?NaN:(b=BigInt(b)%c,0>b?b+c:b)}function n(a){let b=s;for(let c of a.values()){let a=BigInt(c);b=(b< {${a}})()`;const b=new Blob([a],{type:"text/javascript"});return window.URL.createObjectURL(b)}function q(c,b=16){if(c===u)return!0;if((c&t)===s||c===t)return!1;const e=[3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597];for(let a=0;a=d?c:d},a.min=function(c,d){return c=BigInt(c),d=BigInt(d),c>=d?d:c},a.modInv=h,a.modPow=i,a.prime=function(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);return new Promise(c=>{let d=[];const e=(e,f)=>{if(e.isPrime){for(let a=0;ae(a.data,b),d.push(b)}for(let e=0;ea)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);let c=s;do c=n(l(a/8,!0));while(!q(c,b));return c},a.randBetween=j,a.randBits=k,a.randBytes=function(a,b=!1){if(1>a)throw new RangeError(`byteLength MUST be > 0 and it is ${a}`);let c;return new Promise(function(d){c=new Uint8Array(a),self.crypto.getRandomValues(c),b&&(c[0]|=128),d(c)})},a.randBytesSync=l,a.toZn=m,a}({}); diff --git a/dist/bigint-crypto-utils-latest.browser.mod.js b/dist/bigint-crypto-utils-latest.browser.mod.js index 3036497..5e7502e 100644 --- a/dist/bigint-crypto-utils-latest.browser.mod.js +++ b/dist/bigint-crypto-utils-latest.browser.mod.js @@ -254,7 +254,6 @@ function modPow(b, e, n) { * * @param {number} bitLength The required bit length for the generated prime * @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test - * @param {boolean} sync NOT RECOMMENDED. Invoke the function synchronously. It won't use workers so it'll be slower and may freeze thw window in browser's javascript. * * @returns {Promise} A promise that resolves to a bigint probable prime of bitLength bits. */ diff --git a/dist/bigint-crypto-utils-latest.node.js b/dist/bigint-crypto-utils-latest.node.js index 4903d20..71c57d2 100644 --- a/dist/bigint-crypto-utils-latest.node.js +++ b/dist/bigint-crypto-utils-latest.node.js @@ -264,7 +264,6 @@ function modPow(b, e, n) { * * @param {number} bitLength The required bit length for the generated prime * @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test - * @param {boolean} sync NOT RECOMMENDED. Invoke the function synchronously. It won't use workers so it'll be slower and may freeze thw window in browser's javascript. * * @returns {Promise} A promise that resolves to a bigint probable prime of bitLength bits. */