Socket
Socket
Sign inDemoInstall

bigint-crypto-utils

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bigint-crypto-utils - npm Package Compare versions

Comparing version 3.2.2 to 3.3.0

docs/interfaces/Egcd.md

16

dist/bundle.esm.js

@@ -1,2 +0,2 @@

function n(n){return n>=0?n:-n}function t(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++;}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,e=1n,o=1n,u=0n;for(;0n!==n;){const i=t/n,f=t%n,g=r-o*i,b=e-u*i;t=n,n=f,r=o,e=u,o=g,u=b;}return {g:t,x:r,y:e}}function e(t,r){let e="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof r?BigInt(n(r)):n(r);if(0n===e)return o;if(0n===o)return e;let u=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,u++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){const n=e;e=o,o=n;}o-=e;}while(0n!==o);return e<<u}function o(t,r){return "number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),0n===t&&0n===r?BigInt(0):n(t/e(t,r)*r)}function u(n,t){return n>=t?n:t}function i(n,t){return n>=t?t:n}function f(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const r=n%t;return r<0n?r+t:r}function g(n,t){const e=r(f(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return f(e.x,t)}function b(t,r,e){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),"number"==typeof e&&(e=BigInt(e)),e<=0n)throw new RangeError("n must be > 0");if(1n===e)return 0n;if(t=f(t,e),r<0n)return g(b(t,n(r),e),e);let o=1n;for(;r>0;)r%2n===1n&&(o=o*t%e),r/=2n,t=t**2n%e;return o}
function n(n){return n>=0?n:-n}function t(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++;}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,e=1n,o=1n,i=0n;for(;0n!==n;){const u=t/n,f=t%n,g=r-o*u,c=e-i*u;t=n,n=f,r=o,e=i,o=g,i=c;}return {g:t,x:r,y:e}}function e(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const r=n%t;return r<0n?r+t:r}function o(n,t){const o=r(e(n,t),t);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return e(o.x,t)}function i(n,t,r){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const i=r??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,r,u)=>{const f=i/r;return e(t+f*o(f,r)%i*n[u]%i,i)}),0n)}function u(t,r){let e="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof r?BigInt(n(r)):n(r);if(0n===e)return o;if(0n===o)return e;let i=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,i++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){const n=e;e=o,o=n;}o-=e;}while(0n!==o);return e<<i}function f(t,r){return "number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),0n===t&&0n===r?BigInt(0):n(t/u(t,r)*r)}function g(n,t){return n>=t?n:t}function c(n,t){return n>=t?t:n}function m(n,t){const r=BigInt(t);return e(n.map((n=>BigInt(n)%r)).reduce(((n,t)=>n+t%r),0n),r)}function p(n,t){const r=BigInt(t);return e(n.map((n=>BigInt(n)%r)).reduce(((n,t)=>n*t%r),1n),r)}function a(n){return n.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function s(t,r,u,f){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),"number"==typeof u&&(u=BigInt(u)),u<=0n)throw new RangeError("n must be > 0");if(1n===u)return 0n;if(t=e(t,u),r<0n)return o(s(t,n(r),u,f),u);if(void 0!==f)return function(n,t,r,e){const o=e.map((n=>n[0]**n[1])),u=e.map((n=>a([n]))),f=u.map(((r,e)=>s(n,t%r,o[e])));return i(f,o,r)}(t,r,u,function(n){const t={};return n.forEach((n=>{if("bigint"==typeof n||"number"==typeof n){const r=String(n);void 0===t[r]?t[r]={p:BigInt(n),k:1n}:t[r].k+=1n;}else {const r=String(n[0]);void 0===t[r]?t[r]={p:BigInt(n[0]),k:BigInt(n[1])}:t[r].k+=BigInt(n[1]);}})),Object.values(t).map((n=>[n.p,n.k]))}(f));let g=1n;for(;r>0;)r%2n===1n&&(g=g*t%u),r/=2n,t=t**2n%u;return g}

@@ -415,4 +415,4 @@ function fromBuffer(buf) {

do {
const b$1 = randBetween(d, 2n);
let z = b(b$1, m, w);
const b = randBetween(d, 2n);
let z = s(b, m, w);
if (z === 1n || z === d)

@@ -422,3 +422,3 @@ continue;

while (j < a) {
z = b(z, 2n, w);
z = s(z, 2n, w);
if (z === d)

@@ -439,5 +439,5 @@ break;

const ${r.name} = ${r.toString()};
const ${g.name} = ${g.toString()};
const ${b.name} = ${b.toString()};
const ${f.name} = ${f.toString()};
const ${o.name} = ${o.toString()};
const ${s.name} = ${s.toString()};
const ${e.name} = ${e.toString()};
const ${randBitsSync.name} = ${randBitsSync.toString()};

@@ -536,2 +536,2 @@ const ${randBytesSync.name} = ${randBytesSync.toString()};

export { n as abs, t as bitLength, r as eGcd, e as gcd, isProbablyPrime, o as lcm, u as max, i as min, g as modInv, b as modPow, prime, primeSync, randBetween, randBits, randBitsSync, randBytes, randBytesSync, f as toZn };
export { n as abs, t as bitLength, i as crt, r as eGcd, u as gcd, isProbablyPrime, f as lcm, g as max, c as min, m as modAdd, o as modInv, p as modMultiply, s as modPow, a as phi, prime, primeSync, randBetween, randBits, randBitsSync, randBytes, randBytesSync, e as toZn };

@@ -1,1 +0,1 @@

function n(n){return n>=0?n:-n}function t(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function e(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const s=t/n,u=t%n,a=e-o*s,c=r-i*s;t=n,n=u,e=o,r=i,o=a,i=c}return{g:t,x:e,y:r}}function r(t,e){let r="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof e?BigInt(n(e)):n(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function o(t,e){return"number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),0n===t&&0n===e?BigInt(0):n(t/r(t,e)*e)}function i(n,t){return n>=t?n:t}function s(n,t){return n>=t?t:n}function u(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function a(n,t){const r=e(u(n,t),t);if(1n!==r.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return u(r.x,t)}function c(t,e,r){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),r<=0n)throw new RangeError("n must be > 0");if(1n===r)return 0n;if(t=u(t,r),e<0n)return a(c(t,n(e),r),r);let o=1n;for(;e>0;)e%2n===1n&&(o=o*t%r),e/=2n,t=t**2n%r;return o}function f(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}function g(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){{const r=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(r);else for(let t=0;t<Math.ceil(n/65536);t++){const e=65536*t,o=e+65535<n?e+65535:n-1;self.crypto.getRandomValues(r.subarray(e,o))}t&&(r[0]=128|r[0]),e(r)}}))}function m(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(e);else for(let t=0;t<Math.ceil(n/65536);t++){const r=65536*t,o=r+65535<n?r+65535:n-1;self.crypto.getRandomValues(e.subarray(r,o))}return t&&(e[0]=128|e[0]),e}}function d(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{g(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function b(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=m(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function l(n,e=1n){if(n<=e)throw new RangeError("Arguments MUST be: max > min");const r=n-e,o=t(r);let i;do{i=f(b(o))}while(i>r);return i+e}let w=!1;function h(n,t=16,e=!1){if("number"==typeof n&&(n=BigInt(n)),n<0n)throw RangeError("w MUST be >= 0");return new Promise(((e,r)=>{const o=new Worker(p());o.onmessage=n=>{void 0!==n?.data?._bcu?.isPrime&&(o.terminate(),e(n.data._bcu.isPrime))},o.onmessageerror=n=>{r(n)};const i={_bcu:{rnd:n,iterations:t,id:0}};o.postMessage(i)}))}function y(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const s=o/2n**r;do{let t=c(l(o,2n),s,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=c(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}function p(){let n=`\n 'use strict';\n const ${e.name} = ${e.toString()};\n const ${a.name} = ${a.toString()};\n const ${c.name} = ${c.toString()};\n const ${u.name} = ${u.toString()};\n const ${b.name} = ${b.toString()};\n const ${m.name} = ${m.toString()};\n const ${l.name} = ${l.toString()};\n const ${h.name} = ${y.toString()};\n ${t.toString()};\n ${f.toString()};`;return n+=`\n onmessage = async function(msg) {\n if (msg !== undefined && msg.data !== undefined && msg.data._bcu !== undefined && msg.data._bcu.id !== undefined && msg.data._bcu.iterations !== undefined && msg.data._bcu.rnd !== undefined) {\n const msgToParent = {\n _bcu: {\n isPrime: await ${h.name}(msg.data._bcu.rnd, msg.data._bcu.iterations),\n value: msg.data._bcu.rnd,\n id: msg.data._bcu.id\n }\n };\n postMessage(msgToParent);\n }\n }`,function(n){n=`(() => {${n}})()`;const t=new Blob([n],{type:"text/javascript"});return window.URL.createObjectURL(t)}(n)}function $(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");if(!w){let e=0n;do{e=f(b(n,!0))}while(!y(e,t));return new Promise((n=>{n(e)}))}return new Promise(((e,r)=>{const o=[],i=(r,i)=>{if(r._bcu.isPrime){for(let n=0;n<o.length;n++)o[n].terminate();for(;o.length>0;)o.pop();e(r._bcu.value)}else{const e=f(b(n,!0));try{const n={_bcu:{rnd:e,iterations:t,id:r._bcu.id}};i.postMessage(n)}catch(n){}}};{const n=p();for(let t=0;t<self.navigator.hardwareConcurrency-1;t++){const t=new Worker(n);t.onmessage=n=>i(n.data,t),o.push(t)}}for(let e=0;e<o.length;e++)d(n,!0).then((function(n){const r=f(n);o[e].postMessage({_bcu:{rnd:r,iterations:t,id:e}})})).catch(r)}))}function S(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=f(b(n,!0))}while(!y(e,t));return e}void 0!==self.Worker&&(w=!0);export{n as abs,t as bitLength,e as eGcd,r as gcd,h as isProbablyPrime,o as lcm,i as max,s as min,a as modInv,c as modPow,$ as prime,S as primeSync,l as randBetween,d as randBits,b as randBitsSync,g as randBytes,m as randBytesSync,u as toZn};
function n(n){return n>=0?n:-n}function t(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function e(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const s=t/n,u=t%n,a=e-o*s,c=r-i*s;t=n,n=u,e=o,r=i,o=a,i=c}return{g:t,x:e,y:r}}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function o(n,t){const o=e(r(n,t),t);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return r(o.x,t)}function i(n,t,e){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const i=e??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,e,s)=>{const u=i/e;return r(t+u*o(u,e)%i*n[s]%i,i)}),0n)}function s(t,e){let r="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof e?BigInt(n(e)):n(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function u(t,e){return"number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),0n===t&&0n===e?BigInt(0):n(t/s(t,e)*e)}function a(n,t){return n>=t?n:t}function c(n,t){return n>=t?t:n}function f(n,t){const e=BigInt(t);return r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n+t%e),0n),e)}function g(n,t){const e=BigInt(t);return r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n*t%e),1n),e)}function m(n){return n.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function d(t,e,s,u){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof s&&(s=BigInt(s)),s<=0n)throw new RangeError("n must be > 0");if(1n===s)return 0n;if(t=r(t,s),e<0n)return o(d(t,n(e),s,u),s);if(void 0!==u)return function(n,t,e,r){const o=r.map((n=>n[0]**n[1])),s=r.map((n=>m([n]))),u=s.map(((e,r)=>d(n,t%e,o[r])));return i(u,o,e)}(t,e,s,function(n){const t={};return n.forEach((n=>{if("bigint"==typeof n||"number"==typeof n){const e=String(n);void 0===t[e]?t[e]={p:BigInt(n),k:1n}:t[e].k+=1n}else{const e=String(n[0]);void 0===t[e]?t[e]={p:BigInt(n[0]),k:BigInt(n[1])}:t[e].k+=BigInt(n[1])}})),Object.values(t).map((n=>[n.p,n.k]))}(u));let a=1n;for(;e>0;)e%2n===1n&&(a=a*t%s),e/=2n,t=t**2n%s;return a}function l(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}function b(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){{const r=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(r);else for(let t=0;t<Math.ceil(n/65536);t++){const e=65536*t,o=e+65535<n?e+65535:n-1;self.crypto.getRandomValues(r.subarray(e,o))}t&&(r[0]=128|r[0]),e(r)}}))}function h(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(e);else for(let t=0;t<Math.ceil(n/65536);t++){const r=65536*t,o=r+65535<n?r+65535:n-1;self.crypto.getRandomValues(e.subarray(r,o))}return t&&(e[0]=128|e[0]),e}}function w(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{b(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function p(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=h(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function y(n,e=1n){if(n<=e)throw new RangeError("Arguments MUST be: max > min");const r=n-e,o=t(r);let i;do{i=l(p(o))}while(i>r);return i+e}let B=!1;function I(n,t=16,e=!1){if("number"==typeof n&&(n=BigInt(n)),n<0n)throw RangeError("w MUST be >= 0");return new Promise(((e,r)=>{const o=new Worker($());o.onmessage=n=>{void 0!==n?.data?._bcu?.isPrime&&(o.terminate(),e(n.data._bcu.isPrime))},o.onmessageerror=n=>{r(n)};const i={_bcu:{rnd:n,iterations:t,id:0}};o.postMessage(i)}))}function S(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const s=o/2n**r;do{let t=d(y(o,2n),s,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=d(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}function $(){let n=`\n 'use strict';\n const ${e.name} = ${e.toString()};\n const ${o.name} = ${o.toString()};\n const ${d.name} = ${d.toString()};\n const ${r.name} = ${r.toString()};\n const ${p.name} = ${p.toString()};\n const ${h.name} = ${h.toString()};\n const ${y.name} = ${y.toString()};\n const ${I.name} = ${S.toString()};\n ${t.toString()};\n ${l.toString()};`;return n+=`\n onmessage = async function(msg) {\n if (msg !== undefined && msg.data !== undefined && msg.data._bcu !== undefined && msg.data._bcu.id !== undefined && msg.data._bcu.iterations !== undefined && msg.data._bcu.rnd !== undefined) {\n const msgToParent = {\n _bcu: {\n isPrime: await ${I.name}(msg.data._bcu.rnd, msg.data._bcu.iterations),\n value: msg.data._bcu.rnd,\n id: msg.data._bcu.id\n }\n };\n postMessage(msgToParent);\n }\n }`,function(n){n=`(() => {${n}})()`;const t=new Blob([n],{type:"text/javascript"});return window.URL.createObjectURL(t)}(n)}function R(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");if(!B){let e=0n;do{e=l(p(n,!0))}while(!S(e,t));return new Promise((n=>{n(e)}))}return new Promise(((e,r)=>{const o=[],i=(r,i)=>{if(r._bcu.isPrime){for(let n=0;n<o.length;n++)o[n].terminate();for(;o.length>0;)o.pop();e(r._bcu.value)}else{const e=l(p(n,!0));try{const n={_bcu:{rnd:e,iterations:t,id:r._bcu.id}};i.postMessage(n)}catch(n){}}};{const n=$();for(let t=0;t<self.navigator.hardwareConcurrency-1;t++){const t=new Worker(n);t.onmessage=n=>i(n.data,t),o.push(t)}}for(let e=0;e<o.length;e++)w(n,!0).then((function(n){const r=l(n);o[e].postMessage({_bcu:{rnd:r,iterations:t,id:e}})})).catch(r)}))}function M(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=l(p(n,!0))}while(!S(e,t));return e}void 0!==self.Worker&&(B=!0);export{n as abs,t as bitLength,i as crt,e as eGcd,s as gcd,I as isProbablyPrime,u as lcm,a as max,c as min,f as modAdd,o as modInv,g as modMultiply,d as modPow,m as phi,R as prime,M as primeSync,y as randBetween,w as randBits,p as randBitsSync,b as randBytes,h as randBytesSync,r as toZn};

@@ -1,1 +0,1 @@

var bigintCryptoUtils=function(n){"use strict";function t(n){return n>=0?n:-n}function e(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const s=t/n,u=t%n,a=e-o*s,c=r-i*s;t=n,n=u,e=o,r=i,o=a,i=c}return{g:t,x:e,y:r}}function o(n,e){let r="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof e?BigInt(t(e)):t(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function i(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function s(n,t){const e=r(i(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return i(e.x,t)}function u(n,e,r){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),r<=0n)throw new RangeError("n must be > 0");if(1n===r)return 0n;if(n=i(n,r),e<0n)return s(u(n,t(e),r),r);let o=1n;for(;e>0;)e%2n===1n&&(o=o*n%r),e/=2n,n=n**2n%r;return o}function a(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}function c(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){{const r=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(r);else for(let t=0;t<Math.ceil(n/65536);t++){const e=65536*t,o=e+65535<n?e+65535:n-1;self.crypto.getRandomValues(r.subarray(e,o))}t&&(r[0]=128|r[0]),e(r)}}))}function f(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(e);else for(let t=0;t<Math.ceil(n/65536);t++){const r=65536*t,o=r+65535<n?r+65535:n-1;self.crypto.getRandomValues(e.subarray(r,o))}return t&&(e[0]=128|e[0]),e}}function g(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{c(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function m(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=f(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function d(n,t=1n){if(n<=t)throw new RangeError("Arguments MUST be: max > min");const r=n-t,o=e(r);let i;do{i=a(m(o))}while(i>r);return i+t}let b=!1;function l(n,t=16,e=!1){if("number"==typeof n&&(n=BigInt(n)),n<0n)throw RangeError("w MUST be >= 0");return new Promise(((e,r)=>{const o=new Worker(h());o.onmessage=n=>{void 0!==n?.data?._bcu?.isPrime&&(o.terminate(),e(n.data._bcu.isPrime))},o.onmessageerror=n=>{r(n)};const i={_bcu:{rnd:n,iterations:t,id:0}};o.postMessage(i)}))}function w(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const s=o/2n**r;do{let t=u(d(o,2n),s,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=u(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}function h(){let n=`\n 'use strict';\n const ${r.name} = ${r.toString()};\n const ${s.name} = ${s.toString()};\n const ${u.name} = ${u.toString()};\n const ${i.name} = ${i.toString()};\n const ${m.name} = ${m.toString()};\n const ${f.name} = ${f.toString()};\n const ${d.name} = ${d.toString()};\n const ${l.name} = ${w.toString()};\n ${e.toString()};\n ${a.toString()};`;return n+=`\n onmessage = async function(msg) {\n if (msg !== undefined && msg.data !== undefined && msg.data._bcu !== undefined && msg.data._bcu.id !== undefined && msg.data._bcu.iterations !== undefined && msg.data._bcu.rnd !== undefined) {\n const msgToParent = {\n _bcu: {\n isPrime: await ${l.name}(msg.data._bcu.rnd, msg.data._bcu.iterations),\n value: msg.data._bcu.rnd,\n id: msg.data._bcu.id\n }\n };\n postMessage(msgToParent);\n }\n }`,function(n){n=`(() => {${n}})()`;const t=new Blob([n],{type:"text/javascript"});return window.URL.createObjectURL(t)}(n)}return void 0!==self.Worker&&(b=!0),n.abs=t,n.bitLength=e,n.eGcd=r,n.gcd=o,n.isProbablyPrime=l,n.lcm=function(n,e){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),0n===n&&0n===e?BigInt(0):t(n/o(n,e)*e)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modInv=s,n.modPow=u,n.prime=function(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");if(!b){let e=0n;do{e=a(m(n,!0))}while(!w(e,t));return new Promise((n=>{n(e)}))}return new Promise(((e,r)=>{const o=[],i=(r,i)=>{if(r._bcu.isPrime){for(let n=0;n<o.length;n++)o[n].terminate();for(;o.length>0;)o.pop();e(r._bcu.value)}else{const e=a(m(n,!0));try{const n={_bcu:{rnd:e,iterations:t,id:r._bcu.id}};i.postMessage(n)}catch(n){}}};{const n=h();for(let t=0;t<self.navigator.hardwareConcurrency-1;t++){const t=new Worker(n);t.onmessage=n=>i(n.data,t),o.push(t)}}for(let e=0;e<o.length;e++)g(n,!0).then((function(n){const r=a(n);o[e].postMessage({_bcu:{rnd:r,iterations:t,id:e}})})).catch(r)}))},n.primeSync=function(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=a(m(n,!0))}while(!w(e,t));return e},n.randBetween=d,n.randBits=g,n.randBitsSync=m,n.randBytes=c,n.randBytesSync=f,n.toZn=i,n}({});
var bigintCryptoUtils=function(n){"use strict";function t(n){return n>=0?n:-n}function e(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const u=t/n,s=t%n,c=e-o*u,a=r-i*u;t=n,n=s,e=o,r=i,o=c,i=a}return{g:t,x:e,y:r}}function o(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function i(n,t){const e=r(o(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return o(e.x,t)}function u(n,t,e){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const r=e??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,e,u)=>{const s=r/e;return o(t+s*i(s,e)%r*n[u]%r,r)}),0n)}function s(n,e){let r="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof e?BigInt(t(e)):t(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function c(n){return n.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function a(n,e,r,s){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),r<=0n)throw new RangeError("n must be > 0");if(1n===r)return 0n;if(n=o(n,r),e<0n)return i(a(n,t(e),r,s),r);if(void 0!==s)return function(n,t,e,r){const o=r.map((n=>n[0]**n[1])),i=r.map((n=>c([n]))),s=i.map(((e,r)=>a(n,t%e,o[r])));return u(s,o,e)}(n,e,r,function(n){const t={};return n.forEach((n=>{if("bigint"==typeof n||"number"==typeof n){const e=String(n);void 0===t[e]?t[e]={p:BigInt(n),k:1n}:t[e].k+=1n}else{const e=String(n[0]);void 0===t[e]?t[e]={p:BigInt(n[0]),k:BigInt(n[1])}:t[e].k+=BigInt(n[1])}})),Object.values(t).map((n=>[n.p,n.k]))}(s));let f=1n;for(;e>0;)e%2n===1n&&(f=f*n%r),e/=2n,n=n**2n%r;return f}function f(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}function g(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){{const r=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(r);else for(let t=0;t<Math.ceil(n/65536);t++){const e=65536*t,o=e+65535<n?e+65535:n-1;self.crypto.getRandomValues(r.subarray(e,o))}t&&(r[0]=128|r[0]),e(r)}}))}function m(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(e);else for(let t=0;t<Math.ceil(n/65536);t++){const r=65536*t,o=r+65535<n?r+65535:n-1;self.crypto.getRandomValues(e.subarray(r,o))}return t&&(e[0]=128|e[0]),e}}function d(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{g(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function l(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=m(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function b(n,t=1n){if(n<=t)throw new RangeError("Arguments MUST be: max > min");const r=n-t,o=e(r);let i;do{i=f(l(o))}while(i>r);return i+t}let h=!1;function w(n,t=16,e=!1){if("number"==typeof n&&(n=BigInt(n)),n<0n)throw RangeError("w MUST be >= 0");return new Promise(((e,r)=>{const o=new Worker(y());o.onmessage=n=>{void 0!==n?.data?._bcu?.isPrime&&(o.terminate(),e(n.data._bcu.isPrime))},o.onmessageerror=n=>{r(n)};const i={_bcu:{rnd:n,iterations:t,id:0}};o.postMessage(i)}))}function p(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const u=o/2n**r;do{let t=a(b(o,2n),u,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=a(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}function y(){let n=`\n 'use strict';\n const ${r.name} = ${r.toString()};\n const ${i.name} = ${i.toString()};\n const ${a.name} = ${a.toString()};\n const ${o.name} = ${o.toString()};\n const ${l.name} = ${l.toString()};\n const ${m.name} = ${m.toString()};\n const ${b.name} = ${b.toString()};\n const ${w.name} = ${p.toString()};\n ${e.toString()};\n ${f.toString()};`;return n+=`\n onmessage = async function(msg) {\n if (msg !== undefined && msg.data !== undefined && msg.data._bcu !== undefined && msg.data._bcu.id !== undefined && msg.data._bcu.iterations !== undefined && msg.data._bcu.rnd !== undefined) {\n const msgToParent = {\n _bcu: {\n isPrime: await ${w.name}(msg.data._bcu.rnd, msg.data._bcu.iterations),\n value: msg.data._bcu.rnd,\n id: msg.data._bcu.id\n }\n };\n postMessage(msgToParent);\n }\n }`,function(n){n=`(() => {${n}})()`;const t=new Blob([n],{type:"text/javascript"});return window.URL.createObjectURL(t)}(n)}return void 0!==self.Worker&&(h=!0),n.abs=t,n.bitLength=e,n.crt=u,n.eGcd=r,n.gcd=s,n.isProbablyPrime=w,n.lcm=function(n,e){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),0n===n&&0n===e?BigInt(0):t(n/s(n,e)*e)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modAdd=function(n,t){const e=BigInt(t);return o(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n+t%e),0n),e)},n.modInv=i,n.modMultiply=function(n,t){const e=BigInt(t);return o(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n*t%e),1n),e)},n.modPow=a,n.phi=c,n.prime=function(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");if(!h){let e=0n;do{e=f(l(n,!0))}while(!p(e,t));return new Promise((n=>{n(e)}))}return new Promise(((e,r)=>{const o=[],i=(r,i)=>{if(r._bcu.isPrime){for(let n=0;n<o.length;n++)o[n].terminate();for(;o.length>0;)o.pop();e(r._bcu.value)}else{const e=f(l(n,!0));try{const n={_bcu:{rnd:e,iterations:t,id:r._bcu.id}};i.postMessage(n)}catch(n){}}};{const n=y();for(let t=0;t<self.navigator.hardwareConcurrency-1;t++){const t=new Worker(n);t.onmessage=n=>i(n.data,t),o.push(t)}}for(let e=0;e<o.length;e++)d(n,!0).then((function(n){const r=f(n);o[e].postMessage({_bcu:{rnd:r,iterations:t,id:e}})})).catch(r)}))},n.primeSync=function(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=f(l(n,!0))}while(!p(e,t));return e},n.randBetween=b,n.randBits=d,n.randBitsSync=l,n.randBytes=g,n.randBytesSync=m,n.toZn=o,n}({});

@@ -1,1 +0,1 @@

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).bigintCryptoUtils={})}(this,(function(n){"use strict";function t(n){return n>=0?n:-n}function e(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const s=t/n,u=t%n,f=e-o*s,a=r-i*s;t=n,n=u,e=o,r=i,o=f,i=a}return{g:t,x:e,y:r}}function o(n,e){let r="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof e?BigInt(t(e)):t(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function i(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function s(n,t){const e=r(i(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return i(e.x,t)}function u(n,e,r){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),r<=0n)throw new RangeError("n must be > 0");if(1n===r)return 0n;if(n=i(n,r),e<0n)return s(u(n,t(e),r),r);let o=1n;for(;e>0;)e%2n===1n&&(o=o*n%r),e/=2n,n=n**2n%r;return o}function f(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}function a(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){{const r=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(r);else for(let t=0;t<Math.ceil(n/65536);t++){const e=65536*t,o=e+65535<n?e+65535:n-1;self.crypto.getRandomValues(r.subarray(e,o))}t&&(r[0]=128|r[0]),e(r)}}))}function c(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(e);else for(let t=0;t<Math.ceil(n/65536);t++){const r=65536*t,o=r+65535<n?r+65535:n-1;self.crypto.getRandomValues(e.subarray(r,o))}return t&&(e[0]=128|e[0]),e}}function g(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{a(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function d(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=c(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function m(n,t=1n){if(n<=t)throw new RangeError("Arguments MUST be: max > min");const r=n-t,o=e(r);let i;do{i=f(d(o))}while(i>r);return i+t}let l=!1;function b(n,t=16,e=!1){if("number"==typeof n&&(n=BigInt(n)),n<0n)throw RangeError("w MUST be >= 0");return new Promise(((e,r)=>{const o=new Worker(h());o.onmessage=n=>{void 0!==n?.data?._bcu?.isPrime&&(o.terminate(),e(n.data._bcu.isPrime))},o.onmessageerror=n=>{r(n)};const i={_bcu:{rnd:n,iterations:t,id:0}};o.postMessage(i)}))}function w(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const s=o/2n**r;do{let t=u(m(o,2n),s,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=u(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}function h(){let n=`\n 'use strict';\n const ${r.name} = ${r.toString()};\n const ${s.name} = ${s.toString()};\n const ${u.name} = ${u.toString()};\n const ${i.name} = ${i.toString()};\n const ${d.name} = ${d.toString()};\n const ${c.name} = ${c.toString()};\n const ${m.name} = ${m.toString()};\n const ${b.name} = ${w.toString()};\n ${e.toString()};\n ${f.toString()};`;return n+=`\n onmessage = async function(msg) {\n if (msg !== undefined && msg.data !== undefined && msg.data._bcu !== undefined && msg.data._bcu.id !== undefined && msg.data._bcu.iterations !== undefined && msg.data._bcu.rnd !== undefined) {\n const msgToParent = {\n _bcu: {\n isPrime: await ${b.name}(msg.data._bcu.rnd, msg.data._bcu.iterations),\n value: msg.data._bcu.rnd,\n id: msg.data._bcu.id\n }\n };\n postMessage(msgToParent);\n }\n }`,function(n){n=`(() => {${n}})()`;const t=new Blob([n],{type:"text/javascript"});return window.URL.createObjectURL(t)}(n)}void 0!==self.Worker&&(l=!0),n.abs=t,n.bitLength=e,n.eGcd=r,n.gcd=o,n.isProbablyPrime=b,n.lcm=function(n,e){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),0n===n&&0n===e?BigInt(0):t(n/o(n,e)*e)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modInv=s,n.modPow=u,n.prime=function(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");if(!l){let e=0n;do{e=f(d(n,!0))}while(!w(e,t));return new Promise((n=>{n(e)}))}return new Promise(((e,r)=>{const o=[],i=(r,i)=>{if(r._bcu.isPrime){for(let n=0;n<o.length;n++)o[n].terminate();for(;o.length>0;)o.pop();e(r._bcu.value)}else{const e=f(d(n,!0));try{const n={_bcu:{rnd:e,iterations:t,id:r._bcu.id}};i.postMessage(n)}catch(n){}}};{const n=h();for(let t=0;t<self.navigator.hardwareConcurrency-1;t++){const t=new Worker(n);t.onmessage=n=>i(n.data,t),o.push(t)}}for(let e=0;e<o.length;e++)g(n,!0).then((function(n){const r=f(n);o[e].postMessage({_bcu:{rnd:r,iterations:t,id:e}})})).catch(r)}))},n.primeSync=function(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=f(d(n,!0))}while(!w(e,t));return e},n.randBetween=m,n.randBits=g,n.randBitsSync=d,n.randBytes=a,n.randBytesSync=c,n.toZn=i}));
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).bigintCryptoUtils={})}(this,(function(n){"use strict";function t(n){return n>=0?n:-n}function e(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const u=t/n,s=t%n,c=e-o*u,a=r-i*u;t=n,n=s,e=o,r=i,o=c,i=a}return{g:t,x:e,y:r}}function o(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function i(n,t){const e=r(o(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return o(e.x,t)}function u(n,t,e){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const r=e??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,e,u)=>{const s=r/e;return o(t+s*i(s,e)%r*n[u]%r,r)}),0n)}function s(n,e){let r="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof e?BigInt(t(e)):t(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function c(n){return n.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function a(n,e,r,s){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),r<=0n)throw new RangeError("n must be > 0");if(1n===r)return 0n;if(n=o(n,r),e<0n)return i(a(n,t(e),r,s),r);if(void 0!==s)return function(n,t,e,r){const o=r.map((n=>n[0]**n[1])),i=r.map((n=>c([n]))),s=i.map(((e,r)=>a(n,t%e,o[r])));return u(s,o,e)}(n,e,r,function(n){const t={};return n.forEach((n=>{if("bigint"==typeof n||"number"==typeof n){const e=String(n);void 0===t[e]?t[e]={p:BigInt(n),k:1n}:t[e].k+=1n}else{const e=String(n[0]);void 0===t[e]?t[e]={p:BigInt(n[0]),k:BigInt(n[1])}:t[e].k+=BigInt(n[1])}})),Object.values(t).map((n=>[n.p,n.k]))}(s));let f=1n;for(;e>0;)e%2n===1n&&(f=f*n%r),e/=2n,n=n**2n%r;return f}function f(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}function g(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){{const r=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(r);else for(let t=0;t<Math.ceil(n/65536);t++){const e=65536*t,o=e+65535<n?e+65535:n-1;self.crypto.getRandomValues(r.subarray(e,o))}t&&(r[0]=128|r[0]),e(r)}}))}function d(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(e);else for(let t=0;t<Math.ceil(n/65536);t++){const r=65536*t,o=r+65535<n?r+65535:n-1;self.crypto.getRandomValues(e.subarray(r,o))}return t&&(e[0]=128|e[0]),e}}function m(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{g(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function l(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=d(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function b(n,t=1n){if(n<=t)throw new RangeError("Arguments MUST be: max > min");const r=n-t,o=e(r);let i;do{i=f(l(o))}while(i>r);return i+t}let h=!1;function p(n,t=16,e=!1){if("number"==typeof n&&(n=BigInt(n)),n<0n)throw RangeError("w MUST be >= 0");return new Promise(((e,r)=>{const o=new Worker(y());o.onmessage=n=>{void 0!==n?.data?._bcu?.isPrime&&(o.terminate(),e(n.data._bcu.isPrime))},o.onmessageerror=n=>{r(n)};const i={_bcu:{rnd:n,iterations:t,id:0}};o.postMessage(i)}))}function w(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const u=o/2n**r;do{let t=a(b(o,2n),u,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=a(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}function y(){let n=`\n 'use strict';\n const ${r.name} = ${r.toString()};\n const ${i.name} = ${i.toString()};\n const ${a.name} = ${a.toString()};\n const ${o.name} = ${o.toString()};\n const ${l.name} = ${l.toString()};\n const ${d.name} = ${d.toString()};\n const ${b.name} = ${b.toString()};\n const ${p.name} = ${w.toString()};\n ${e.toString()};\n ${f.toString()};`;return n+=`\n onmessage = async function(msg) {\n if (msg !== undefined && msg.data !== undefined && msg.data._bcu !== undefined && msg.data._bcu.id !== undefined && msg.data._bcu.iterations !== undefined && msg.data._bcu.rnd !== undefined) {\n const msgToParent = {\n _bcu: {\n isPrime: await ${p.name}(msg.data._bcu.rnd, msg.data._bcu.iterations),\n value: msg.data._bcu.rnd,\n id: msg.data._bcu.id\n }\n };\n postMessage(msgToParent);\n }\n }`,function(n){n=`(() => {${n}})()`;const t=new Blob([n],{type:"text/javascript"});return window.URL.createObjectURL(t)}(n)}void 0!==self.Worker&&(h=!0),n.abs=t,n.bitLength=e,n.crt=u,n.eGcd=r,n.gcd=s,n.isProbablyPrime=p,n.lcm=function(n,e){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),0n===n&&0n===e?BigInt(0):t(n/s(n,e)*e)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modAdd=function(n,t){const e=BigInt(t);return o(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n+t%e),0n),e)},n.modInv=i,n.modMultiply=function(n,t){const e=BigInt(t);return o(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n*t%e),1n),e)},n.modPow=a,n.phi=c,n.prime=function(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");if(!h){let e=0n;do{e=f(l(n,!0))}while(!w(e,t));return new Promise((n=>{n(e)}))}return new Promise(((e,r)=>{const o=[],i=(r,i)=>{if(r._bcu.isPrime){for(let n=0;n<o.length;n++)o[n].terminate();for(;o.length>0;)o.pop();e(r._bcu.value)}else{const e=f(l(n,!0));try{const n={_bcu:{rnd:e,iterations:t,id:r._bcu.id}};i.postMessage(n)}catch(n){}}};{const n=y();for(let t=0;t<self.navigator.hardwareConcurrency-1;t++){const t=new Worker(n);t.onmessage=n=>i(n.data,t),o.push(t)}}for(let e=0;e<o.length;e++)m(n,!0).then((function(n){const r=f(n);o[e].postMessage({_bcu:{rnd:r,iterations:t,id:e}})})).catch(r)}))},n.primeSync=function(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=f(l(n,!0))}while(!w(e,t));return e},n.randBetween=b,n.randBits=m,n.randBitsSync=l,n.randBytes=g,n.randBytesSync=d,n.toZn=o}));

@@ -1,2 +0,1 @@

function n(n){return n>=0?n:-n}function t(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function e(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const s=t/n,u=t%n,a=e-o*s,c=r-i*s;t=n,n=u,e=o,r=i,o=a,i=c}return{g:t,x:e,y:r}}function r(t,e){let r="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof e?BigInt(n(e)):n(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function o(t,e){return"number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),0n===t&&0n===e?BigInt(0):n(t/r(t,e)*e)}function i(n,t){return n>=t?n:t}function s(n,t){return n>=t?t:n}function u(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function a(n,t){const r=e(u(n,t),t);if(1n!==r.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return u(r.x,t)}function c(t,e,r){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),r<=0n)throw new RangeError("n must be > 0");if(1n===r)return 0n;if(t=u(t,r),e<0n)return a(c(t,n(e),r),r);let o=1n;for(;e>0;)e%2n===1n&&(o=o*t%r),e/=2n,t=t**2n%r;return o}function f(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}function g(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){{const r=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(r);else for(let t=0;t<Math.ceil(n/65536);t++){const e=65536*t,o=e+65535<n?e+65535:n-1;self.crypto.getRandomValues(r.subarray(e,o))}t&&(r[0]=128|r[0]),e(r)}}))}function m(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(e);else for(let t=0;t<Math.ceil(n/65536);t++){const r=65536*t,o=r+65535<n?r+65535:n-1;self.crypto.getRandomValues(e.subarray(r,o))}return t&&(e[0]=128|e[0]),e}}function d(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{g(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function b(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=m(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function l(n,e=1n){if(n<=e)throw new RangeError("Arguments MUST be: max > min");const r=n-e,o=t(r);let i;do{i=f(b(o))}while(i>r);return i+e}let w=!1;function h(n,t=16,e=!1){if("number"==typeof n&&(n=BigInt(n)),n<0n)throw RangeError("w MUST be >= 0");return new Promise(((e,r)=>{const o=new Worker(p());o.onmessage=n=>{void 0!==n?.data?._bcu?.isPrime&&(o.terminate(),e(n.data._bcu.isPrime))},o.onmessageerror=n=>{r(n)};const i={_bcu:{rnd:n,iterations:t,id:0}};o.postMessage(i)}))}function y(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const s=o/2n**r;do{let t=c(l(o,2n),s,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=c(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}function p(){let n=`\n 'use strict';\n const ${e.name} = ${e.toString()};\n const ${a.name} = ${a.toString()};\n const ${c.name} = ${c.toString()};\n const ${u.name} = ${u.toString()};\n const ${b.name} = ${b.toString()};\n const ${m.name} = ${m.toString()};\n const ${l.name} = ${l.toString()};\n const ${h.name} = ${y.toString()};\n ${t.toString()};\n ${f.toString()};`;return n+=`\n onmessage = async function(msg) {\n if (msg !== undefined && msg.data !== undefined && msg.data._bcu !== undefined && msg.data._bcu.id !== undefined && msg.data._bcu.iterations !== undefined && msg.data._bcu.rnd !== undefined) {\n const msgToParent = {\n _bcu: {\n isPrime: await ${h.name}(msg.data._bcu.rnd, msg.data._bcu.iterations),\n value: msg.data._bcu.rnd,\n id: msg.data._bcu.id\n }\n };\n postMessage(msgToParent);\n }\n }`,function(n){n=`(() => {${n}})()`;const t=new Blob([n],{type:"text/javascript"});return window.URL.createObjectURL(t)}(n)}function $(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");if(!w){let e=0n;do{e=f(b(n,!0))}while(!y(e,t));return new Promise((n=>{n(e)}))}return new Promise(((e,r)=>{const o=[],i=(r,i)=>{if(r._bcu.isPrime){for(let n=0;n<o.length;n++)o[n].terminate();for(;o.length>0;)o.pop();e(r._bcu.value)}else{const e=f(b(n,!0));try{const n={_bcu:{rnd:e,iterations:t,id:r._bcu.id}};i.postMessage(n)}catch(n){}}};{const n=p();for(let t=0;t<self.navigator.hardwareConcurrency-1;t++){const t=new Worker(n);t.onmessage=n=>i(n.data,t),o.push(t)}}for(let e=0;e<o.length;e++)d(n,!0).then((function(n){const r=f(n);o[e].postMessage({_bcu:{rnd:r,iterations:t,id:e}})})).catch(r)}))}function S(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=f(b(n,!0))}while(!y(e,t));return e}void 0!==self.Worker&&(w=!0);export{n as abs,t as bitLength,e as eGcd,r as gcd,h as isProbablyPrime,o as lcm,i as max,s as min,a as modInv,c as modPow,$ as prime,S as primeSync,l as randBetween,d as randBits,b as randBitsSync,g as randBytes,m as randBytesSync,u as toZn};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguYnJvd3Nlci5lc20uanMiLCJzb3VyY2VzIjpbIi4uL25vZGVfbW9kdWxlcy9iaWdpbnQtbW9kLWFyaXRoL2Rpc3QvaW5kZXguYnJvd3Nlci5lc20uanMiLCIuLi9zcmMvdHMvZnJvbUJ1ZmZlci50cyIsIi4uL3NyYy90cy9yYW5kQnl0ZXMudHMiLCIuL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UFJdkMsT0FBTzRDLEdBQzdCTCxFQUFVckMsVUFBYUMsR0FBVW1DLEVBQVduQyxFQUFNRSxLQUFNa0MsR0FDeERGLEVBQVdVLEtBQUtSLEVBQ2pCLENBT0YsQ0FDRCxJQUFLLElBQUlyRixFQUFJLEVBQUdBLEVBQUltRixFQUFXdEIsT0FBUTdELElBQ3JDMkIsRUFBU0MsR0FBVyxHQUFNRSxNQUFLLFNBQVV0QixHQUN2QyxNQUFNK0IsRUFBTWhDLEVBQVdDLEdBQ3ZCMkUsRUFBV25GLEdBQUcwRCxZQUFZLENBQ3hCTixLQUFNLENBQ0piLE1BQ0FJLGFBQ0FjLEdBQUl6RCxJQUdWLElBQUc4RixNQUFNOUUsRUFDVixHQUVMLFVBYWdCK0UsRUFBV25FLEVBQW1CZSxFQUFxQixJQUNqRSxHQUFJZixFQUFZLEVBQUcsTUFBTSxJQUFJaEMsV0FBVyx5QkFDeEMsSUFBSTJDLEVBQU0sR0FDVixHQUNFQSxFQUFNaEMsRUFBVzBCLEVBQWFMLEdBQVcsV0FDakMrQixFQUFpQnBCLEVBQUtJLElBQ2hDLE9BQU9KLENBQ1QsTUYvRnNCVyxJQUFoQmhDLEtBQUs0QixTQUFzQk4sR0FBYyIsInhfZ29vZ2xlX2lnbm9yZUxpc3QiOlswXX0=
function n(n){return n>=0?n:-n}function t(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function e(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const s=t/n,u=t%n,a=e-o*s,c=r-i*s;t=n,n=u,e=o,r=i,o=a,i=c}return{g:t,x:e,y:r}}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function o(n,t){const o=e(r(n,t),t);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return r(o.x,t)}function i(n,t,e){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const i=e??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,e,s)=>{const u=i/e;return r(t+u*o(u,e)%i*n[s]%i,i)}),0n)}function s(t,e){let r="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof e?BigInt(n(e)):n(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function u(t,e){return"number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),0n===t&&0n===e?BigInt(0):n(t/s(t,e)*e)}function a(n,t){return n>=t?n:t}function c(n,t){return n>=t?t:n}function f(n,t){const e=BigInt(t);return r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n+t%e),0n),e)}function g(n,t){const e=BigInt(t);return r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n*t%e),1n),e)}function m(n){return n.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function d(t,e,s,u){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof s&&(s=BigInt(s)),s<=0n)throw new RangeError("n must be > 0");if(1n===s)return 0n;if(t=r(t,s),e<0n)return o(d(t,n(e),s,u),s);if(void 0!==u)return function(n,t,e,r){const o=r.map((n=>n[0]**n[1])),s=r.map((n=>m([n]))),u=s.map(((e,r)=>d(n,t%e,o[r])));return i(u,o,e)}(t,e,s,function(n){const t={};return n.forEach((n=>{if("bigint"==typeof n||"number"==typeof n){const e=String(n);void 0===t[e]?t[e]={p:BigInt(n),k:1n}:t[e].k+=1n}else{const e=String(n[0]);void 0===t[e]?t[e]={p:BigInt(n[0]),k:BigInt(n[1])}:t[e].k+=BigInt(n[1])}})),Object.values(t).map((n=>[n.p,n.k]))}(u));let a=1n;for(;e>0;)e%2n===1n&&(a=a*t%s),e/=2n,t=t**2n%s;return a}function l(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}function b(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){{const r=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(r);else for(let t=0;t<Math.ceil(n/65536);t++){const e=65536*t,o=e+65535<n?e+65535:n-1;self.crypto.getRandomValues(r.subarray(e,o))}t&&(r[0]=128|r[0]),e(r)}}))}function h(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=new Uint8Array(n);if(n<=65536)self.crypto.getRandomValues(e);else for(let t=0;t<Math.ceil(n/65536);t++){const r=65536*t,o=r+65535<n?r+65535:n-1;self.crypto.getRandomValues(e.subarray(r,o))}return t&&(e[0]=128|e[0]),e}}function w(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{b(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function p(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=h(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function y(n,e=1n){if(n<=e)throw new RangeError("Arguments MUST be: max > min");const r=n-e,o=t(r);let i;do{i=l(p(o))}while(i>r);return i+e}let B=!1;function I(n,t=16,e=!1){if("number"==typeof n&&(n=BigInt(n)),n<0n)throw RangeError("w MUST be >= 0");return new Promise(((e,r)=>{const o=new Worker($());o.onmessage=n=>{void 0!==n?.data?._bcu?.isPrime&&(o.terminate(),e(n.data._bcu.isPrime))},o.onmessageerror=n=>{r(n)};const i={_bcu:{rnd:n,iterations:t,id:0}};o.postMessage(i)}))}function S(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const s=o/2n**r;do{let t=d(y(o,2n),s,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=d(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}function $(){let n=`\n 'use strict';\n const ${e.name} = ${e.toString()};\n const ${o.name} = ${o.toString()};\n const ${d.name} = ${d.toString()};\n const ${r.name} = ${r.toString()};\n const ${p.name} = ${p.toString()};\n const ${h.name} = ${h.toString()};\n const ${y.name} = ${y.toString()};\n const ${I.name} = ${S.toString()};\n ${t.toString()};\n ${l.toString()};`;return n+=`\n onmessage = async function(msg) {\n if (msg !== undefined && msg.data !== undefined && msg.data._bcu !== undefined && msg.data._bcu.id !== undefined && msg.data._bcu.iterations !== undefined && msg.data._bcu.rnd !== undefined) {\n const msgToParent = {\n _bcu: {\n isPrime: await ${I.name}(msg.data._bcu.rnd, msg.data._bcu.iterations),\n value: msg.data._bcu.rnd,\n id: msg.data._bcu.id\n }\n };\n postMessage(msgToParent);\n }\n }`,function(n){n=`(() => {${n}})()`;const t=new Blob([n],{type:"text/javascript"});return window.URL.createObjectURL(t)}(n)}function R(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");if(!B){let e=0n;do{e=l(p(n,!0))}while(!S(e,t));return new Promise((n=>{n(e)}))}return new Promise(((e,r)=>{const o=[],i=(r,i)=>{if(r._bcu.isPrime){for(let n=0;n<o.length;n++)o[n].terminate();for(;o.length>0;)o.pop();e(r._bcu.value)}else{const e=l(p(n,!0));try{const n={_bcu:{rnd:e,iterations:t,id:r._bcu.id}};i.postMessage(n)}catch(n){}}};{const n=$();for(let t=0;t<self.navigator.hardwareConcurrency-1;t++){const t=new Worker(n);t.onmessage=n=>i(n.data,t),o.push(t)}}for(let e=0;e<o.length;e++)w(n,!0).then((function(n){const r=l(n);o[e].postMessage({_bcu:{rnd:r,iterations:t,id:e}})})).catch(r)}))}function M(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=l(p(n,!0))}while(!S(e,t));return e}void 0!==self.Worker&&(B=!0);export{n as abs,t as bitLength,i as crt,e as eGcd,s as gcd,I as isProbablyPrime,u as lcm,a as max,c as min,f as modAdd,o as modInv,g as modMultiply,d as modPow,m as phi,R as prime,M as primeSync,y as randBetween,w as randBits,p as randBitsSync,b as randBytes,h as randBytesSync,r as toZn};
/// <reference types="node" />
/**
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
*
* @param a
*
* @returns The absolute value of a
*/
declare function abs(a: number | bigint): number | bigint;
/**
* Returns the (minimum) length of a number expressed in bits.
*
* @param a
* @returns The bit length
*/
declare function bitLength(a: number | bigint): number;
/**
* Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime (no two divisors share a common factor other than 1). Provided that n_i are pairwise coprime, and a_i any integers, this function returns a solution for the following system of equations:
x ≡ a_1 mod n_1
x ≡ a_2 mod n_2
x ≡ a_k mod n_k
*
* @param remainders the array of remainders a_i. For example [17n, 243n, 344n]
* @param modulos the array of modulos n_i. For example [769n, 2017n, 47701n]
* @param modulo the product of all modulos. Provided here just to save some operations if it is already known
* @returns x
*/
declare function crt(remainders: bigint[], modulos: bigint[], modulo?: bigint): bigint;
interface Egcd {

@@ -11,31 +38,221 @@ g: bigint;

}
/**
* An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
* Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
*
* @param a
* @param b
*
* @throws {@link RangeError} if a or b are <= 0
*
* @returns A triple (g, x, y), such that ax + by = g = gcd(a, b).
*/
declare function eGcd(a: number | bigint, b: number | bigint): Egcd;
/**
* Greatest common divisor of two integers based on the iterative binary algorithm.
*
* @param a
* @param b
*
* @returns The greatest common divisor of a and b
*/
declare function gcd(a: number | bigint, b: number | bigint): bigint;
/**
* The least common multiple computed as abs(a*b)/gcd(a,b)
* @param a
* @param b
*
* @returns The least common multiple of a and b
*/
declare function lcm(a: number | bigint, b: number | bigint): bigint;
/**
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<b
*
* @param a
* @param b
*
* @returns Maximum of numbers a and b
*/
declare function max(a: number | bigint, b: number | bigint): number | bigint;
/**
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<b
*
* @param a
* @param b
*
* @returns Minimum of numbers a and b
*/
declare function min(a: number | bigint, b: number | bigint): number | bigint;
/**
* Modular addition of (a_1 + ... + a_r) mod n
* @param addends an array of the numbers a_i to add. For example [3, 12353251235n, 1243, -12341232545990n]
* @param n the modulo
* @returns The smallest positive integer that is congruent with (a_1 + ... + a_r) mod n
*/
declare function modAdd(addends: Array<number | bigint>, n: number | bigint): bigint;
/**
* Modular inverse.
*
* @param a The number to find an inverse for
* @param n The modulo
*
* @throws {@link RangeError} if a does not have inverse modulo n
*
* @returns The inverse modulo n
*/
declare function modInv(a: number | bigint, n: number | bigint): bigint;
declare function modPow(b: number | bigint, e: number | bigint, n: number | bigint): bigint;
/**
* Modular addition of (a_1 * ... * a_r) mod n
* @param factors an array of the numbers a_i to multiply. For example [3, 12353251235n, 1243, -12341232545990n]
* @param n the modulo
* @returns The smallest positive integer that is congruent with (a_1 * ... * a_r) mod n
*/
declare function modMultiply(factors: Array<number | bigint>, n: number | bigint): bigint;
type PrimePower = [number | bigint, number | bigint];
type PrimeFactor = number | bigint | PrimePower;
/**
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method if the prime factorization is not provided, or the chinese remainder theorem otherwise.
*
* @param b base
* @param e exponent
* @param n modulo
* @param primeFactorization an array of the prime factors, for example [5n, 5n, 13n, 27n], or prime powers as [p, k], for instance [[5, 2], [13, 1], [27, 1]]. If the prime factorization is provided the chinese remainder theorem is used to greatly speed up the exponentiation.
*
* @throws {@link RangeError} if n <= 0
*
* @returns b**e mod n
*/
declare function modPow(b: number | bigint, e: number | bigint, n: number | bigint, primeFactorization?: PrimeFactor[]): bigint;
type PrimeFactorization = Array<[bigint, bigint]>;
/**
* A function that computes the Euler's totien function of a number n, whose prime power factorization is known
*
* @param primeFactorization an array of arrays containing the prime power factorization of a number n. For example, for n = (p1**k1)*(p2**k2)*...*(pr**kr), one should provide [[p1, k1], [p2, k2], ... , [pr, kr]]
* @returns phi((p1**k1)*(p2**k2)*...*(pr**kr))
*/
declare function phi(primeFactorization: PrimeFactorization): bigint;
/**
* Finds the smallest positive element that is congruent to a in modulo n
*
* @remarks
* a and b must be the same type, either number or bigint
*
* @param a - An integer
* @param n - The modulo
*
* @throws {@link RangeError} if n <= 0
*
* @returns A bigint with the smallest positive representation of a modulo n
*/
declare function toZn(a: number | bigint, n: number | bigint): bigint;
/**
* The test first tries if any of the first 250 small primes are a factor of the input number and then passes several
* iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)
*
* @param w - A positive integer to be tested for primality
* @param iterations - The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3 of FIPS 186-4
* @param disableWorkers - Disable the use of workers for the primality test
*
* @throws {@link RangeError} if w<0
*
* @returns A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
*/
declare function isProbablyPrime(w: number | bigint, iterations?: number, disableWorkers?: boolean): Promise<boolean>;
/**
* 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).
* The node version can also use worker_threads if they are available (enabled by default with Node 11 and
* and can be enabled at runtime executing node --experimental-worker with node >=10.5.0).
*
* @param bitLength - The required bit length for the generated prime
* @param iterations - The number of iterations for the Miller-Rabin Probabilistic Primality Test
*
* @throws {@link RangeError} if bitLength < 1
*
* @returns A promise that resolves to a bigint probable prime of bitLength bits.
*/
declare function prime(bitLength: number, iterations?: number): Promise<bigint>;
/**
* A probably-prime (Miller-Rabin), cryptographically-secure, random-number generator.
* The sync version is NOT RECOMMENDED since it won't use workers and thus it'll be slower and may freeze thw window in browser's javascript. Please consider using prime() instead.
*
* @param bitLength - The required bit length for the generated prime
* @param iterations - The number of iterations for the Miller-Rabin Probabilistic Primality Test
*
* @throws {@link RangeError} if bitLength < 1
*
* @returns A bigint probable prime of bitLength bits.
*/
declare function primeSync(bitLength: number, iterations?: number): bigint;
/**
* Returns a cryptographically secure random integer between [min,max].
* @param max Returned value will be <= max
* @param min Returned value will be >= min
*
* @throws {@link RangeError} if max <= min
*
* @returns A cryptographically secure random bigint between [min,max]
*/
declare function randBetween(max: bigint, min?: bigint): bigint;
/**
* Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
*
* @param bitLength - The desired number of random bits
* @param forceLength - Set to true if you want to force the output to have a specific bit length. It basically forces the msb to be 1
*
* @throws {@link RangeError} if bitLength < 1
*
* @returns A Promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bits
*/
declare function randBits(bitLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
/**
* Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
* @param bitLength - The desired number of random bits
* @param forceLength - Set to true if you want to force the output to have a specific bit length. It basically forces the msb to be 1
*
* @throws {@link RangeError} if bitLength < 1
*
* @returns A Uint8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bits
*/
declare function randBitsSync(bitLength: number, forceLength?: boolean): Uint8Array | Buffer;
/**
* Secure random bytes for both node and browsers. Node version uses crypto.randomBytes() and browser one self.crypto.getRandomValues()
*
* @param byteLength - The desired number of random bytes
* @param forceLength - Set to true if you want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*
* @throws {@link RangeError} if byteLength < 1
*
* @returns A promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bytes
*/
declare function randBytes(byteLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
/**
* Secure random bytes for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
* This is the synchronous version, consider using the asynchronous one for improved efficiency.
*
* @param byteLength - The desired number of random bytes
* @param forceLength - Set to true if you want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*
* @throws {@link RangeError} if byteLength < 1
*
* @returns A UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bytes
*/
declare function randBytesSync(byteLength: number, forceLength?: boolean): Uint8Array | Buffer;
export { abs, bitLength, eGcd, gcd, isProbablyPrime, lcm, max, min, modInv, modPow, prime, primeSync, randBetween, randBits, randBitsSync, randBytes, randBytesSync, toZn };
export { Egcd, PrimeFactor, PrimeFactorization, PrimePower, abs, bitLength, crt, eGcd, gcd, isProbablyPrime, lcm, max, min, modAdd, modInv, modMultiply, modPow, phi, prime, primeSync, randBetween, randBits, randBitsSync, randBytes, randBytesSync, toZn };

@@ -1,2 +0,1 @@

import{fileURLToPath as n}from"url";function t(n){return n>=0?n:-n}function e(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const u=t/n,s=t%n,a=e-o*u,c=r-i*u;t=n,n=s,e=o,r=i,o=a,i=c}return{g:t,x:e,y:r}}function o(n,e){let r="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof e?BigInt(t(e)):t(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function i(n,e){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),0n===n&&0n===e?BigInt(0):t(n/o(n,e)*e)}function u(n,t){return n>=t?n:t}function s(n,t){return n>=t?t:n}function a(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function c(n,t){const e=r(a(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return a(e.x,t)}function f(n,e,r){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),r<=0n)throw new RangeError("n must be > 0");if(1n===r)return 0n;if(n=a(n,r),e<0n)return c(f(n,t(e),r),r);let o=1n;for(;e>0;)e%2n===1n&&(o=o*n%r),e/=2n,n=n**2n%r;return o}function g(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}var m=await import("crypto");function b(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){m.randomBytes(n,(function(n,o){null!==n&&r(n),t&&(o[0]=128|o[0]),e(o)}))}))}function h(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=m.randomBytes(n);return t&&(e[0]=128|e[0]),e}}function l(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{b(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function w(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=h(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function d(n,t=1n){if(n<=t)throw new RangeError("Arguments MUST be: max > min");const r=n-t,o=e(r);let i;do{i=g(w(o))}while(i>r);return i+t}let p=!1;try{await import("worker_threads"),p=!0}catch(o){console.log("[bigint-crypto-utils] WARNING:\nThis node version doesn't support worker_threads. You should enable them in order to greatly speedup the generation of big prime numbers.\n · With Node >=11 it is enabled by default (consider upgrading).\n · With Node 10, starting with 10.5.0, you can enable worker_threads at runtime executing node --experimental-worker ")}function y(t,e=16,r=!1){if("number"==typeof t&&(t=BigInt(t)),t<0n)throw RangeError("w MUST be >= 0");return new Promise(!r&&p?(r,o)=>{const i=new B.Worker(n(import.meta.url));i.on("message",(n=>{void 0!==n?._bcu?.isPrime&&(i.terminate().catch(o),r(n._bcu.isPrime))})),i.on("error",o);const u={_bcu:{rnd:t,iterations:e,id:0}};i.postMessage(u)}:n=>{n(_(t,e))})}function _(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const u=o/2n**r;do{let t=f(d(o,2n),u,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=f(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}if(p)try{var B=await import("worker_threads");if(!B.isMainThread&&null!==B.parentPort){const n=B.parentPort;n.on("message",(function(t){if(void 0!==t?._bcu?.iterations&&void 0!==t?._bcu?.rnd){const e={_bcu:{isPrime:_(t._bcu.rnd,t._bcu.iterations),value:t._bcu.rnd,id:t._bcu.id}};n.postMessage(e)}}))}}catch(n){}var I=await import("os");try{var M=await import("worker_threads")}catch{}function v(t,e=16){if(t<1)throw new RangeError("bitLength MUST be > 0");if(!p){let n=0n;do{n=g(w(t,!0))}while(!_(n,e));return new Promise((t=>{t(n)}))}return new Promise(((r,o)=>{const i=[],u=(n,o)=>{if(n._bcu.isPrime){for(let n=0;n<i.length;n++)i[n].terminate();for(;i.length>0;)i.pop();r(n._bcu.value)}else{const r=g(w(t,!0));try{const t={_bcu:{rnd:r,iterations:e,id:n._bcu.id}};o.postMessage(t)}catch(n){}}};for(let t=0;t<I.cpus().length-1;t++){const t=new M.Worker(n(import.meta.url));t.on("message",(n=>u(n,t))),i.push(t)}for(let n=0;n<i.length;n++)l(t,!0).then((function(t){const r=g(t);i[n].postMessage({_bcu:{rnd:r,iterations:e,id:n}})})).catch(o)}))}function R(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=g(w(n,!0))}while(!_(e,t));return e}export{t as abs,e as bitLength,r as eGcd,o as gcd,y as isProbablyPrime,i as lcm,u as max,s as min,c as modInv,f as modPow,v as prime,R as primeSync,d as randBetween,l as randBits,w as randBitsSync,b as randBytes,h as randBytesSync,a as toZn};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXgubm9kZS5lc20uanMiLCJzb3VyY2VzIjpbIi4uL25vZGVfbW9kdWxlcy9iaWdpbnQtbW9kLWFyaXRoL2Rpc3QvaW5kZXgubm9kZS5lc20uanMiLCIuLi9zcmMvdHMvZnJvbUJ1ZmZlci50cyIsIi4uL3NyYy90cy9yYW5kQnl0ZXMudHMiLCIuLi9zcmMvdHMvcmFuZEJpdHMudHMiLCIuLi9zcmMvdHMvcmFuZEJldHdlZW4udHMiLCIuLi9zcmMvdHMvd29ya2VyVXRpbHMudHMiLCIuLi9zcmMvdHMvaXNQcm9iYWJseVByaW1lLnRzIiwiLi4vc3JjL3RzL3ByaW1lLnRzIl0sInNvdXJjZXNDb250ZW50IjpudWxsLCJuYW1lcyI6WyJuIiwidCIsIkJpZ0ludCIsInIiLCJSYW5nZUVycm9yIiwiZSIsIm8iLCJ1IiwiaSIsImYiLCJnIiwiYiIsIngiLCJ5IiwidG9TdHJpbmciLCJmcm9tQnVmZmVyIiwiYnVmIiwicmV0IiwidmFsdWVzIiwiY3J5cHRvIiwiaW1wb3J0IiwicmFuZEJ5dGVzIiwiYnl0ZUxlbmd0aCIsImZvcmNlTGVuZ3RoIiwiUHJvbWlzZSIsInJlc29sdmUiLCJyZWplY3QiLCJyYW5kb21CeXRlcyIsImVyciIsInJhbmRCeXRlc1N5bmMiLCJyYW5kQml0cyIsImJpdExlbmd0aCIsIk1hdGgiLCJjZWlsIiwiYml0TGVuZ3RoTW9kOCIsInRoZW4iLCJybmRCeXRlcyIsIm1hc2siLCJyYW5kQml0c1N5bmMiLCJyYW5kQmV0d2VlbiIsIm1heCIsIm1pbiIsImludGVydmFsIiwiYml0TGVuIiwicm5kIiwiX3VzZVdvcmtlcnMiLCJjb25zb2xlIiwibG9nIiwiaXNQcm9iYWJseVByaW1l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DQUN4Qk4sS0FBTSxDQUNKaEIsTUFDQU0sYUFDQWUsR0FBSXpELElBR1YsSUFBR3VELE1BQU1yQyxFQUNWLEdBRUwsVUFhZ0JnRSxFQUFXM0QsRUFBbUJtQixFQUFxQixJQUNqRSxHQUFJbkIsRUFBWSxFQUFHLE1BQU0sSUFBSTNCLFdBQVcseUJBQ3hDLElBQUl3QyxFQUFNLEdBQ1YsR0FDRUEsRUFBTTdCLEVBQVd1QixFQUFhUCxHQUFXLFdBQ2pDb0MsRUFBaUJ2QixFQUFLTSxJQUNoQyxPQUFPTixDQUNUIiwieF9nb29nbGVfaWdub3JlTGlzdCI6WzBdfQ==
import{fileURLToPath as n}from"url";function t(n){return n>=0?n:-n}function e(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const u=t/n,s=t%n,a=e-o*u,c=r-i*u;t=n,n=s,e=o,r=i,o=a,i=c}return{g:t,x:e,y:r}}function o(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const e=n%t;return e<0n?e+t:e}function i(n,t){const e=r(o(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return o(e.x,t)}function u(n,t,e){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const r=e??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,e,u)=>{const s=r/e;return o(t+s*i(s,e)%r*n[u]%r,r)}),0n)}function s(n,e){let r="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof e?BigInt(t(e)):t(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r<<i}function a(n,e){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),0n===n&&0n===e?BigInt(0):t(n/s(n,e)*e)}function c(n,t){return n>=t?n:t}function f(n,t){return n>=t?t:n}function g(n,t){const e=BigInt(t);return o(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n+t%e),0n),e)}function m(n,t){const e=BigInt(t);return o(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n*t%e),1n),e)}function h(n){return n.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function d(n,e,r,s){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),r<=0n)throw new RangeError("n must be > 0");if(1n===r)return 0n;if(n=o(n,r),e<0n)return i(d(n,t(e),r,s),r);if(void 0!==s)return function(n,t,e,r){const o=r.map((n=>n[0]**n[1])),i=r.map((n=>h([n]))),s=i.map(((e,r)=>d(n,t%e,o[r])));return u(s,o,e)}(n,e,r,function(n){const t={};return n.forEach((n=>{if("bigint"==typeof n||"number"==typeof n){const e=String(n);void 0===t[e]?t[e]={p:BigInt(n),k:1n}:t[e].k+=1n}else{const e=String(n[0]);void 0===t[e]?t[e]={p:BigInt(n[0]),k:BigInt(n[1])}:t[e].k+=BigInt(n[1])}})),Object.values(t).map((n=>[n.p,n.k]))}(s));let a=1n;for(;e>0;)e%2n===1n&&(a=a*n%r),e/=2n,n=n**2n%r;return a}function l(n){let t=0n;for(const e of n.values()){t=(t<<8n)+BigInt(e)}return t}var b=await import("crypto");function p(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");return new Promise((function(e,r){b.randomBytes(n,(function(n,o){null!==n&&r(n),t&&(o[0]=128|o[0]),e(o)}))}))}function w(n,t=!1){if(n<1)throw new RangeError("byteLength MUST be > 0");{const e=b.randomBytes(n);return t&&(e[0]=128|e[0]),e}}function y(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=Math.ceil(n/8),r=n%8;return new Promise(((n,o)=>{p(e,!1).then((function(e){if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}n(e)}))}))}function B(n,t=!1){if(n<1)throw new RangeError("bitLength MUST be > 0");const e=w(Math.ceil(n/8),!1),r=n%8;if(0!==r&&(e[0]=e[0]&2**r-1),t){const n=0!==r?2**(r-1):128;e[0]=e[0]|n}return e}function I(n,t=1n){if(n<=t)throw new RangeError("Arguments MUST be: max > min");const r=n-t,o=e(r);let i;do{i=l(B(o))}while(i>r);return i+t}let _=!1;try{await import("worker_threads"),_=!0}catch(o){console.log("[bigint-crypto-utils] WARNING:\nThis node version doesn't support worker_threads. You should enable them in order to greatly speedup the generation of big prime numbers.\n · With Node >=11 it is enabled by default (consider upgrading).\n · With Node 10, starting with 10.5.0, you can enable worker_threads at runtime executing node --experimental-worker ")}function v(t,e=16,r=!1){if("number"==typeof t&&(t=BigInt(t)),t<0n)throw RangeError("w MUST be >= 0");return new Promise(!r&&_?(r,o)=>{const i=new E.Worker(n(import.meta.url));i.on("message",(n=>{void 0!==n?._bcu?.isPrime&&(i.terminate().catch(o),r(n._bcu.isPrime))})),i.on("error",o);const u={_bcu:{rnd:t,iterations:e,id:0}};i.postMessage(u)}:n=>{n(M(t,e))})}function M(n,t){if(2n===n)return!0;if(0n===(1n&n)||1n===n)return!1;const e=[3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n,503n,509n,521n,523n,541n,547n,557n,563n,569n,571n,577n,587n,593n,599n,601n,607n,613n,617n,619n,631n,641n,643n,647n,653n,659n,661n,673n,677n,683n,691n,701n,709n,719n,727n,733n,739n,743n,751n,757n,761n,769n,773n,787n,797n,809n,811n,821n,823n,827n,829n,839n,853n,857n,859n,863n,877n,881n,883n,887n,907n,911n,919n,929n,937n,941n,947n,953n,967n,971n,977n,983n,991n,997n,1009n,1013n,1019n,1021n,1031n,1033n,1039n,1049n,1051n,1061n,1063n,1069n,1087n,1091n,1093n,1097n,1103n,1109n,1117n,1123n,1129n,1151n,1153n,1163n,1171n,1181n,1187n,1193n,1201n,1213n,1217n,1223n,1229n,1231n,1237n,1249n,1259n,1277n,1279n,1283n,1289n,1291n,1297n,1301n,1303n,1307n,1319n,1321n,1327n,1361n,1367n,1373n,1381n,1399n,1409n,1423n,1427n,1429n,1433n,1439n,1447n,1451n,1453n,1459n,1471n,1481n,1483n,1487n,1489n,1493n,1499n,1511n,1523n,1531n,1543n,1549n,1553n,1559n,1567n,1571n,1579n,1583n,1597n];for(let t=0;t<e.length&&e[t]<=n;t++){const r=e[t];if(n===r)return!0;if(n%r===0n)return!1}let r=0n;const o=n-1n;let i=o;for(;i%2n===0n;)i/=2n,++r;const u=o/2n**r;do{let t=d(I(o,2n),u,n);if(1n===t||t===o)continue;let e=1;for(;e<r&&(t=d(t,2n,n),t!==o);){if(1n===t)return!1;e++}if(t!==o)return!1}while(0!=--t);return!0}if(_)try{var E=await import("worker_threads");if(!E.isMainThread&&null!==E.parentPort){const n=E.parentPort;n.on("message",(function(t){if(void 0!==t?._bcu?.iterations&&void 0!==t?._bcu?.rnd){const e={_bcu:{isPrime:M(t._bcu.rnd,t._bcu.iterations),value:t._bcu.rnd,id:t._bcu.id}};n.postMessage(e)}}))}}catch(n){}var R=await import("os");try{var k=await import("worker_threads")}catch{}function S(t,e=16){if(t<1)throw new RangeError("bitLength MUST be > 0");if(!_){let n=0n;do{n=l(B(t,!0))}while(!M(n,e));return new Promise((t=>{t(n)}))}return new Promise(((r,o)=>{const i=[],u=(n,o)=>{if(n._bcu.isPrime){for(let n=0;n<i.length;n++)i[n].terminate();for(;i.length>0;)i.pop();r(n._bcu.value)}else{const r=l(B(t,!0));try{const t={_bcu:{rnd:r,iterations:e,id:n._bcu.id}};o.postMessage(t)}catch(n){}}};for(let t=0;t<R.cpus().length-1;t++){const t=new k.Worker(n(import.meta.url));t.on("message",(n=>u(n,t))),i.push(t)}for(let n=0;n<i.length;n++)y(t,!0).then((function(t){const r=l(t);i[n].postMessage({_bcu:{rnd:r,iterations:e,id:n}})})).catch(o)}))}function P(n,t=16){if(n<1)throw new RangeError("bitLength MUST be > 0");let e=0n;do{e=l(B(n,!0))}while(!M(e,t));return e}export{t as abs,e as bitLength,u as crt,r as eGcd,s as gcd,v as isProbablyPrime,a as lcm,c as max,f as min,g as modAdd,i as modInv,m as modMultiply,d as modPow,h as phi,S as prime,P as primeSync,I as randBetween,y as randBits,B as randBitsSync,p as randBytes,w as randBytesSync,o as toZn};

@@ -1,5 +0,15 @@

# bigint-crypto-utils - v3.2.2
# bigint-crypto-utils - v3.3.0
## Table of contents
### Interfaces
- [Egcd](interfaces/Egcd.md)
### Type Aliases
- [PrimeFactor](API.md#primefactor)
- [PrimeFactorization](API.md#primefactorization)
- [PrimePower](API.md#primepower)
### Functions

@@ -9,2 +19,3 @@

- [bitLength](API.md#bitlength)
- [crt](API.md#crt)
- [eGcd](API.md#egcd)

@@ -16,4 +27,7 @@ - [gcd](API.md#gcd)

- [min](API.md#min)
- [modAdd](API.md#modadd)
- [modInv](API.md#modinv)
- [modMultiply](API.md#modmultiply)
- [modPow](API.md#modpow)
- [phi](API.md#phi)
- [prime](API.md#prime)

@@ -28,2 +42,20 @@ - [primeSync](API.md#primesync)

## Type Aliases
### PrimeFactor
Ƭ **PrimeFactor**: `number` \| `bigint` \| [`PrimePower`](API.md#primepower)
___
### PrimeFactorization
Ƭ **PrimeFactorization**: [`bigint`, `bigint`][]
___
### PrimePower
Ƭ **PrimePower**: [`number` \| `bigint`, `number` \| `bigint`]
## Functions

@@ -35,2 +67,4 @@

Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
#### Parameters

@@ -46,6 +80,4 @@

#### Defined in
The absolute value of a
node_modules/bigint-mod-arith/dist/index.d.ts:1
___

@@ -57,2 +89,4 @@

Returns the (minimum) length of a number expressed in bits.
#### Parameters

@@ -68,6 +102,30 @@

#### Defined in
The bit length
node_modules/bigint-mod-arith/dist/index.d.ts:3
___
### crt
▸ **crt**(`remainders`, `modulos`, `modulo?`): `bigint`
Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime (no two divisors share a common factor other than 1). Provided that n_i are pairwise coprime, and a_i any integers, this function returns a solution for the following system of equations:
x ≡ a_1 mod n_1
x ≡ a_2 mod n_2
x ≡ a_k mod n_k
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `remainders` | `bigint`[] | the array of remainders a_i. For example [17n, 243n, 344n] |
| `modulos` | `bigint`[] | the array of modulos n_i. For example [769n, 2017n, 47701n] |
| `modulo?` | `bigint` | the product of all modulos. Provided here just to save some operations if it is already known |
#### Returns
`bigint`
x
___

@@ -77,4 +135,11 @@

▸ **eGcd**(`a`, `b`): `Egcd`
▸ **eGcd**(`a`, `b`): [`Egcd`](interfaces/Egcd.md)
An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm.
Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).
**`Throws`**
RangeError if a or b are <= 0
#### Parameters

@@ -89,8 +154,6 @@

`Egcd`
[`Egcd`](interfaces/Egcd.md)
#### Defined in
A triple (g, x, y), such that ax + by = g = gcd(a, b).
node_modules/bigint-mod-arith/dist/index.d.ts:10
___

@@ -102,2 +165,4 @@

Greatest common divisor of two integers based on the iterative binary algorithm.
#### Parameters

@@ -114,6 +179,4 @@

#### Defined in
The greatest common divisor of a and b
node_modules/bigint-mod-arith/dist/index.d.ts:12
___

@@ -146,6 +209,2 @@

#### Defined in
[src/ts/isProbablyPrime.ts:20](https://github.com/juanelas/bigint-crypto-utils/blob/f4ea3d5/src/ts/isProbablyPrime.ts#L20)
___

@@ -157,2 +216,4 @@

The least common multiple computed as abs(a*b)/gcd(a,b)
#### Parameters

@@ -169,6 +230,4 @@

#### Defined in
The least common multiple of a and b
node_modules/bigint-mod-arith/dist/index.d.ts:14
___

@@ -180,2 +239,4 @@

Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<b
#### Parameters

@@ -192,6 +253,4 @@

#### Defined in
Maximum of numbers a and b
node_modules/bigint-mod-arith/dist/index.d.ts:16
___

@@ -203,2 +262,4 @@

Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<b
#### Parameters

@@ -215,6 +276,25 @@

#### Defined in
Minimum of numbers a and b
node_modules/bigint-mod-arith/dist/index.d.ts:18
___
### modAdd
▸ **modAdd**(`addends`, `n`): `bigint`
Modular addition of (a_1 + ... + a_r) mod n
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `addends` | (`number` \| `bigint`)[] | an array of the numbers a_i to add. For example [3, 12353251235n, 1243, -12341232545990n] |
| `n` | `number` \| `bigint` | the modulo |
#### Returns
`bigint`
The smallest positive integer that is congruent with (a_1 + ... + a_r) mod n
___

@@ -226,8 +306,14 @@

Modular inverse.
**`Throws`**
RangeError if a does not have inverse modulo n
#### Parameters
| Name | Type |
| :------ | :------ |
| `a` | `number` \| `bigint` |
| `n` | `number` \| `bigint` |
| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | `number` \| `bigint` | The number to find an inverse for |
| `n` | `number` \| `bigint` | The modulo |

@@ -238,6 +324,26 @@ #### Returns

#### Defined in
The inverse modulo n
node_modules/bigint-mod-arith/dist/index.d.ts:20
___
### modMultiply
▸ **modMultiply**(`factors`, `n`): `bigint`
Modular addition of (a_1 * ... * a_r) mod n
*
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `factors` | (`number` \| `bigint`)[] | an array of the numbers a_i to multiply. For example [3, 12353251235n, 1243, -12341232545990n] * |
| `n` | `number` \| `bigint` | the modulo * |
#### Returns
`bigint`
The smallest positive integer that is congruent with (a_1 * ... * a_r) mod n
___

@@ -247,11 +353,18 @@

▸ **modPow**(`b`, `e`, `n`): `bigint`
▸ **modPow**(`b`, `e`, `n`, `primeFactorization?`): `bigint`
Modular exponentiation b**e mod n. Currently using the right-to-left binary method if the prime factorization is not provided, or the chinese remainder theorem otherwise.
**`Throws`**
RangeError if n <= 0
#### Parameters
| Name | Type |
| :------ | :------ |
| `b` | `number` \| `bigint` |
| `e` | `number` \| `bigint` |
| `n` | `number` \| `bigint` |
| Name | Type | Description |
| :------ | :------ | :------ |
| `b` | `number` \| `bigint` | base |
| `e` | `number` \| `bigint` | exponent |
| `n` | `number` \| `bigint` | modulo |
| `primeFactorization?` | [`PrimeFactor`](API.md#primefactor)[] | an array of the prime factors, for example [5n, 5n, 13n, 27n], or prime powers as [p, k], for instance [[5, 2], [13, 1], [27, 1]]. If the prime factorization is provided the chinese remainder theorem is used to greatly speed up the exponentiation. |

@@ -262,6 +375,24 @@ #### Returns

#### Defined in
b**e mod n
node_modules/bigint-mod-arith/dist/index.d.ts:22
___
### phi
▸ **phi**(`primeFactorization`): `bigint`
A function that computes the Euler's totien function of a number n, whose prime power factorization is known
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `primeFactorization` | [`PrimeFactorization`](API.md#primefactorization) | an array of arrays containing the prime power factorization of a number n. For example, for n = (p1**k1)*(p2**k2)*...*(pr**kr), one should provide [[p1, k1], [p2, k2], ... , [pr, kr]] |
#### Returns
`bigint`
phi((p1**k1)*(p2**k2)*...*(pr**kr))
___

@@ -296,6 +427,2 @@

#### Defined in
[src/ts/prime.ts:28](https://github.com/juanelas/bigint-crypto-utils/blob/f4ea3d5/src/ts/prime.ts#L28)
___

@@ -327,6 +454,2 @@

#### Defined in
[src/ts/prime.ts:109](https://github.com/juanelas/bigint-crypto-utils/blob/f4ea3d5/src/ts/prime.ts#L109)
___

@@ -357,6 +480,2 @@

#### Defined in
[src/ts/randBetween.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/f4ea3d5/src/ts/randBetween.ts#L14)
___

@@ -387,6 +506,2 @@

#### Defined in
[src/ts/randBits.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/f4ea3d5/src/ts/randBits.ts#L13)
___

@@ -417,6 +532,2 @@

#### Defined in
[src/ts/randBits.ts:43](https://github.com/juanelas/bigint-crypto-utils/blob/f4ea3d5/src/ts/randBits.ts#L43)
___

@@ -447,6 +558,2 @@

#### Defined in
[src/ts/randBytes.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/f4ea3d5/src/ts/randBytes.ts#L13)
___

@@ -478,6 +585,2 @@

#### Defined in
[src/ts/randBytes.ts:54](https://github.com/juanelas/bigint-crypto-utils/blob/f4ea3d5/src/ts/randBytes.ts#L54)
___

@@ -489,8 +592,18 @@

Finds the smallest positive element that is congruent to a in modulo n
**`Remarks`**
a and b must be the same type, either number or bigint
**`Throws`**
RangeError if n <= 0
#### Parameters
| Name | Type |
| :------ | :------ |
| `a` | `number` \| `bigint` |
| `n` | `number` \| `bigint` |
| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | `number` \| `bigint` | An integer |
| `n` | `number` \| `bigint` | The modulo |

@@ -501,4 +614,2 @@ #### Returns

#### Defined in
node_modules/bigint-mod-arith/dist/index.d.ts:24
A bigint with the smallest positive representation of a modulo n
{
"name": "bigint-crypto-utils",
"version": "3.2.2",
"version": "3.3.0",
"description": "Arbitrary precision modular arithmetic, cryptographically secure random numbers and strong probable prime generation/testing. It works in modern browsers, Angular, React, Node.js, etc. since it uses the native JS implementation of BigInt",

@@ -139,3 +139,3 @@ "keywords": [

"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-commonjs": "^25.0.2",
"@rollup/plugin-inject": "^5.0.3",

@@ -150,4 +150,4 @@ "@rollup/plugin-json": "^6.0.0",

"@types/mocha": "^10.0.0",
"bigint-mod-arith": "^3.2.1",
"c8": "^7.12.0",
"bigint-mod-arith": "^3.3.1",
"c8": "^8.0.0",
"chai": "^4.3.3",

@@ -161,3 +161,3 @@ "dotenv": "^16.0.3",

"pirates": "^4.0.1",
"puppeteer": "^19.1.2",
"puppeteer": "^20.7.3",
"rimraf": "^5.0.0",

@@ -170,4 +170,4 @@ "rollup": "^3.20.2",

"typedoc-plugin-markdown": "~3.14.0",
"typescript": "^5.0.3"
"typescript": "^4.4.3"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc