From 1375c85bb54787797ab4c64ba3ad8e0d170b7ad4 Mon Sep 17 00:00:00 2001 From: Juanelas Date: Wed, 28 Jun 2023 16:42:09 +0200 Subject: [PATCH] modpow with crt; crt; modAdd; modMultiply --- .github/workflows/build-and-test.yml | 46 +- build/rollup.config.js | 36 +- build/testing/browser/index.cjs | 8 +- build/testing/browser/server.cjs | 5 +- build/typings/is-browser.d.ts | 2 - dist/bundle.esm.js | 106 +++- dist/bundle.esm.min.js | 2 +- dist/bundle.iife.js | 2 +- dist/bundle.umd.js | 2 +- dist/index.browser.esm.js | 4 +- dist/index.d.ts | 15 +- dist/index.node.cjs | 4 +- dist/index.node.esm.js | 4 +- docs/API.md | 170 +++++- docs/interfaces/Egcd.md | 6 +- package-lock.json | 863 ++++++++++++++++++++------- package.json | 26 +- src/ts/gcd.ts | 1 + src/ts/index.ts | 6 +- src/ts/lcm.ts | 1 + src/ts/modInv.ts | 1 + src/ts/modPow.ts | 53 +- test/modPow.ts | 87 ++- 23 files changed, 1112 insertions(+), 338 deletions(-) delete mode 100644 build/typings/is-browser.d.ts diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 4e44c5c..3c74b40 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -86,31 +86,31 @@ jobs: # VARIABLE1: ${{ secrets.VARIABLE1 }} # VARIABLE2: ${{ secrets.VARIABLE2 }} - publish: - needs: [nodetests, browsertests] - runs-on: ubuntu-latest - steps: - - name: Git checkout - uses: actions/checkout@v3 + # publish: + # needs: [nodetests, browsertests] + # runs-on: ubuntu-latest + # steps: + # - name: Git checkout + # uses: actions/checkout@v3 - - name: Install Node.js, NPM and Yarn - uses: actions/setup-node@v3 - with: - node-version: "18.x" - registry-url: "https://registry.npmjs.org" + # - name: Install Node.js, NPM and Yarn + # uses: actions/setup-node@v3 + # with: + # node-version: "18.x" + # registry-url: "https://registry.npmjs.org" - - name: install - run: npm ci + # # - name: install + # # run: npm ci - - name: coverage - run: npm run coverage + # # - name: coverage + # # run: npm run coverage - - name: send report to coveralls.io - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} + # # - name: send report to coveralls.io + # # uses: coverallsapp/github-action@master + # # with: + # # github-token: ${{ secrets.GITHUB_TOKEN }} - - name: NPM publish - run: npm publish --access public - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file + # - name: NPM publish + # run: npm publish --access public + # env: + # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/build/rollup.config.js b/build/rollup.config.js index c556e73..5d360db 100644 --- a/build/rollup.config.js +++ b/build/rollup.config.js @@ -8,10 +8,10 @@ import replace from '@rollup/plugin-replace' import terser from '@rollup/plugin-terser' import rollupPluginTs from '@rollup/plugin-typescript' import { existsSync, readFileSync } from 'fs' -import { dirname, join } from 'path' +import { builtinModules } from 'module' +import { join } from 'path' import dts from 'rollup-plugin-dts' import { compile } from './rollup-plugin-dts.js' -import { builtinModules } from 'module' import * as url from 'url' const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) @@ -45,7 +45,7 @@ if (existsSync(input) !== true) throw new Error('The entry point should be index const tsPluginOptions = { tsconfig: tsConfigPath, outDir: undefined, - include: ['src/ts/**/*', 'build/typings/is-browser.d.ts'], + include: ['src/ts/**/*', 'build/typings/**/*.d.ts'], exclude: ['src/**/*.spec.ts'] } @@ -100,7 +100,9 @@ export default [ plugins: [ replace({ IS_BROWSER: true, + environment: 'browser', _MODULE_TYPE: "'ESM'", + _NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'", preventAssignment: true }), rollupPluginTs(tsPluginOptions), @@ -142,7 +144,9 @@ export default [ plugins: [ replace({ IS_BROWSER: true, + environment: 'browser', _MODULE_TYPE: "'BUNDLE'", + _NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'", preventAssignment: true }), rollupPluginTs({ @@ -162,20 +166,17 @@ export default [ ...sourcemapOutputOptions, format: 'cjs', exports: 'auto', - plugins: [ - terser() - ] + interop: 'auto', + dynamicImportInCjs: false, + plugins: [terser()] } ], plugins: [ - replace({ - 'await import(': 'require(', - delimiters: ['', ''], - preventAssignment: true - }), replace({ IS_BROWSER: false, + environment: 'nodejs', _MODULE_TYPE: "'CJS'", + _NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'", preventAssignment: true }), rollupPluginTs(tsPluginOptions), @@ -197,23 +198,24 @@ export default [ file: join(rootDir, pkgJson.exports['.'].node.import.default), ...sourcemapOutputOptions, format: 'es', - plugins: [ - terser() - ] + plugins: [terser()] } ], plugins: [ replace({ IS_BROWSER: false, + environment: 'nodejs', _MODULE_TYPE: "'ESM'", - __filename: `'${pkgJson.exports['.'].node.import.default}'`, - __dirname: `'${dirname(pkgJson.exports['.'].node.import.default)}'`, + _NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'", + __filename: 'fileURLToPath(import.meta.url)', + __dirname: 'fileURLToPath(new URL(\'.\', import.meta.url))', preventAssignment: true }), rollupPluginTs(tsPluginOptions), compileDts(tmpDeclarationsDir), inject({ - crypto: ['crypto', 'webcrypto'] + crypto: ['crypto', 'webcrypto'], + fileURLToPath: ['url', 'fileURLToPath'] }), commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }), json(), diff --git a/build/testing/browser/index.cjs b/build/testing/browser/index.cjs index 32ab5f4..41eee01 100644 --- a/build/testing/browser/index.cjs +++ b/build/testing/browser/index.cjs @@ -61,7 +61,7 @@ const browserTests = async ( await watchDog.catch(async (reason) => { console.error(reason) }) - if (puppeteerOptions.headless === true) { + if (puppeteerOptions.headless === 'new') { await close() } }).catch(async (reason) => { @@ -102,9 +102,9 @@ const opts = { // puppeteer options puppeteerOptions: { headless: false, - devtools: true + devtools: true, // slowMo: 100, - // timeout: 10000 + timeout: 0 }, logWarnings: false, // log warnings in Node console (usually not needed) keepServerRunning: false, // keep server running until manually closed with ctrl-c. In combination with puppeteerOptions.headless (or just connecting any browser to the test page) allows debugging in browser @@ -113,7 +113,7 @@ const opts = { const args = process.argv.slice(2) if (args[0] === 'headless') { - opts.puppeteerOptions.headless = true + opts.puppeteerOptions.headless = 'new' args.shift() } diff --git a/build/testing/browser/server.cjs b/build/testing/browser/server.cjs index ea1ebb6..64a68c0 100644 --- a/build/testing/browser/server.cjs +++ b/build/testing/browser/server.cjs @@ -51,7 +51,7 @@ const tsBundleOptions = { tsconfig: path.join(rootDir, 'tsconfig.json'), outDir: undefined, // ignore outDir in tsconfig.json sourceMap: false - // include: ['build/typings/is-browser.d.ts'] + // include: ['src/ts/**/*', 'build/typings/**/*.d.ts'] } async function buildTests (testFiles) { @@ -63,6 +63,7 @@ async function buildTests (testFiles) { replace({ IS_BROWSER: true, _MODULE_TYPE: "'ESM'", + _NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'", preventAssignment: true }), typescriptPlugin(tsBundleOptions), @@ -202,7 +203,7 @@ function _getEnvVarsReplacements (testsCode) { } } if (missingEnvVars.length > 0) { - console.warn('The folloinwg environment variables are missing in your .env file and will be replaced with "undefined": ' + [...(new Set(missingEnvVars)).values()].join(', ')) + console.warn('The following environment variables are missing in your .env file and will be replaced with "undefined": ' + [...(new Set(missingEnvVars)).values()].join(', ')) } return replacements } diff --git a/build/typings/is-browser.d.ts b/build/typings/is-browser.d.ts deleted file mode 100644 index 3adc8c8..0000000 --- a/build/typings/is-browser.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare const IS_BROWSER: boolean -declare const _MODULE_TYPE: string diff --git a/dist/bundle.esm.js b/dist/bundle.esm.js index 14d0a19..8a7647a 100644 --- a/dist/bundle.esm.js +++ b/dist/bundle.esm.js @@ -45,6 +45,41 @@ function eGcd(a, b) { }; } +function toZn(a, n) { + if (typeof a === 'number') + a = BigInt(a); + if (typeof n === 'number') + n = BigInt(n); + if (n <= 0n) { + throw new RangeError('n must be > 0'); + } + const aZn = a % n; + return (aZn < 0n) ? aZn + n : aZn; +} + +function modInv(a, n) { + const egcd = eGcd(toZn(a, n), n); + if (egcd.g !== 1n) { + throw new RangeError(`${a.toString()} does not have inverse modulo ${n.toString()}`); + } + else { + return toZn(egcd.x, n); + } +} + +function crt(remainders, modulos, modulo) { + if (remainders.length !== modulos.length) { + throw new RangeError('The remainders and modulos arrays should have the same length'); + } + const product = modulo ?? modulos.reduce((acc, val) => acc * val, 1n); + return modulos.reduce((sum, mod, index) => { + const partialProduct = product / mod; + const inverse = modInv(partialProduct, mod); + const toAdd = ((partialProduct * inverse) % product * remainders[index]) % product; + return toZn(sum + toAdd, product); + }, 0n); +} + function gcd(a, b) { let aAbs = (typeof a === 'number') ? BigInt(abs(a)) : abs(a); let bAbs = (typeof b === 'number') ? BigInt(abs(b)) : abs(b); @@ -93,29 +128,25 @@ function min(a, b) { return (a >= b) ? b : a; } -function toZn(a, n) { - if (typeof a === 'number') - a = BigInt(a); - if (typeof n === 'number') - n = BigInt(n); - if (n <= 0n) { - throw new RangeError('n must be > 0'); - } - const aZn = a % n; - return (aZn < 0n) ? aZn + n : aZn; +function modAdd(addends, n) { + const mod = BigInt(n); + const as = addends.map(a => BigInt(a) % mod); + return toZn(as.reduce((sum, a) => sum + a % mod, 0n), mod); } -function modInv(a, n) { - const egcd = eGcd(toZn(a, n), n); - if (egcd.g !== 1n) { - throw new RangeError(`${a.toString()} does not have inverse modulo ${n.toString()}`); - } - else { - return toZn(egcd.x, n); - } +function modMultiply(factors, n) { + const mod = BigInt(n); + const as = factors.map(a => BigInt(a) % mod); + return toZn(as.reduce((prod, a) => prod * a % mod, 1n), mod); } -function modPow(b, e, n) { +function phi(primeFactorization) { + return primeFactorization.map(v => (v[0] ** (v[1] - 1n)) * (v[0] - 1n)).reduce((prev, curr) => { + return curr * prev; + }, 1n); +} + +function modPow(b, e, n, primeFactorization) { if (typeof b === 'number') b = BigInt(b); if (typeof e === 'number') @@ -130,7 +161,10 @@ function modPow(b, e, n) { } b = toZn(b, n); if (e < 0n) { - return modInv(modPow(b, abs(e), n), n); + return modInv(modPow(b, abs(e), n, primeFactorization), n); + } + if (primeFactorization !== undefined) { + return modPowWithFactorization(b, e, n, primePowerArguments(primeFactorization)); } let r = 1n; while (e > 0) { @@ -142,5 +176,35 @@ function modPow(b, e, n) { } return r; } +function primePowerArguments(primeFactors) { + const primePowers = {}; + primeFactors.forEach((primeFactor) => { + if (typeof primeFactor === 'bigint' || typeof primeFactor === 'number') { + const key = String(primeFactor); + if (primePowers[key] === undefined) { + primePowers[key] = { p: BigInt(primeFactor), k: 1n }; + } + else { + primePowers[key].k += 1n; + } + } + else { + const key = String(primeFactor[0]); + if (primePowers[key] === undefined) { + primePowers[key] = { p: BigInt(primeFactor[0]), k: BigInt(primeFactor[1]) }; + } + else { + primePowers[key].k += BigInt(primeFactor[1]); + } + } + }); + return Object.values(primePowers).map(val => [val.p, val.k]); +} +function modPowWithFactorization(b, e, n, primeFactorization) { + const mods = primeFactorization.map(v => v[0] ** v[1]); + const phis = primeFactorization.map(v => phi([v])); + const remainders = phis.map((phi, i) => modPow(b, e % phi, mods[i])); + return crt(remainders, mods, n); +} -export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn }; +export { abs, bitLength, crt, eGcd, gcd, lcm, max, min, modAdd, modInv, modMultiply, modPow, phi, toZn }; diff --git a/dist/bundle.esm.min.js b/dist/bundle.esm.min.js index 1e96a87..4b41c67 100644 --- a/dist/bundle.esm.min.js +++ b/dist/bundle.esm.min.js @@ -1 +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 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<=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}export{n as abs,t as bitLength,r as eGcd,e as gcd,o as lcm,u as max,i as min,g as modInv,b as modPow,f 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 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<=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}export{n as abs,t as bitLength,i as crt,r as eGcd,u as gcd,f as lcm,g as max,c as min,m as modAdd,o as modInv,p as modMultiply,s as modPow,a as phi,e as toZn}; diff --git a/dist/bundle.iife.js b/dist/bundle.iife.js index 8d3d12c..9cf0c55 100644 --- a/dist/bundle.iife.js +++ b/dist/bundle.iife.js @@ -1 +1 @@ -var bigintModArith=function(n){"use strict";function t(n){return n>=0?n:-n}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,m=e-i*u;t=n,n=f,r=o,e=i,o=g,i=m}return{g:t,x:r,y:e}}function e(n,r){let e="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof r?BigInt(t(r)):t(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< 0");const r=n%t;return r<0n?r+t:r}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)}return n.abs=t,n.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.eGcd=r,n.gcd=e,n.lcm=function(n,r){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof r&&(r=BigInt(r)),0n===n&&0n===r?BigInt(0):t(n/e(n,r)*r)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modInv=i,n.modPow=function n(r,e,u){if("number"==typeof r&&(r=BigInt(r)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof u&&(u=BigInt(u)),u<=0n)throw new RangeError("n must be > 0");if(1n===u)return 0n;if(r=o(r,u),e<0n)return i(n(r,t(e),u),u);let f=1n;for(;e>0;)e%2n===1n&&(f=f*r%u),e/=2n,r=r**2n%u;return f},n.toZn=o,n}({}); +var bigintModArith=function(n){"use strict";function t(n){return n>=0?n:-n}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,c=r-o*u,g=e-i*u;t=n,n=f,r=o,e=i,o=c,i=g}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(n,r){let e="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof r?BigInt(t(r)):t(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<n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function c(n,r,u,g){if("number"==typeof n&&(n=BigInt(n)),"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(n=e(n,u),r<0n)return o(c(n,t(r),u,g),u);if(void 0!==g)return function(n,t,r,e){const o=e.map((n=>n[0]**n[1])),u=e.map((n=>f([n]))),g=u.map(((r,e)=>c(n,t%r,o[e])));return i(g,o,r)}(n,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]))}(g));let m=1n;for(;r>0;)r%2n===1n&&(m=m*n%u),r/=2n,n=n**2n%u;return m}return n.abs=t,n.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.crt=i,n.eGcd=r,n.gcd=u,n.lcm=function(n,r){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof r&&(r=BigInt(r)),0n===n&&0n===r?BigInt(0):t(n/u(n,r)*r)},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 r=BigInt(t);return e(n.map((n=>BigInt(n)%r)).reduce(((n,t)=>n+t%r),0n),r)},n.modInv=o,n.modMultiply=function(n,t){const r=BigInt(t);return e(n.map((n=>BigInt(n)%r)).reduce(((n,t)=>n*t%r),1n),r)},n.modPow=c,n.phi=f,n.toZn=e,n}({}); diff --git a/dist/bundle.umd.js b/dist/bundle.umd.js index 8973ac7..a70ee58 100644 --- a/dist/bundle.umd.js +++ b/dist/bundle.umd.js @@ -1 +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).bigintModArith={})}(this,(function(n){"use strict";function t(n){return n>=0?n:-n}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 f=t/n,u=t%n,g=e-o*f,b=r-i*f;t=n,n=u,e=o,r=i,o=g,i=b}return{g:t,x:e,y:r}}function r(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< 0");const e=n%t;return e<0n?e+t:e}function i(n,t){const r=e(o(n,t),t);if(1n!==r.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return o(r.x,t)}n.abs=t,n.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.eGcd=e,n.gcd=r,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/r(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=i,n.modPow=function n(e,r,f){if("number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),"number"==typeof f&&(f=BigInt(f)),f<=0n)throw new RangeError("n must be > 0");if(1n===f)return 0n;if(e=o(e,f),r<0n)return i(n(e,t(r),f),f);let u=1n;for(;r>0;)r%2n===1n&&(u=u*e%f),r/=2n,e=e**2n%f;return u},n.toZn=o})); +!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).bigintModArith={})}(this,(function(n){"use strict";function t(n){return n>=0?n:-n}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 u=t/n,f=t%n,c=e-o*u,g=r-i*u;t=n,n=f,e=o,r=i,o=c,i=g}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,u)=>{const f=i/e;return r(t+f*o(f,e)%i*n[u]%i,i)}),0n)}function u(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<n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function c(n,e,u,g){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof u&&(u=BigInt(u)),u<=0n)throw new RangeError("n must be > 0");if(1n===u)return 0n;if(n=r(n,u),e<0n)return o(c(n,t(e),u,g),u);if(void 0!==g)return function(n,t,e,r){const o=r.map((n=>n[0]**n[1])),u=r.map((n=>f([n]))),g=u.map(((e,r)=>c(n,t%e,o[r])));return i(g,o,e)}(n,e,u,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]))}(g));let d=1n;for(;e>0;)e%2n===1n&&(d=d*n%u),e/=2n,n=n**2n%u;return d}n.abs=t,n.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.crt=i,n.eGcd=e,n.gcd=u,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/u(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 r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n+t%e),0n),e)},n.modInv=o,n.modMultiply=function(n,t){const e=BigInt(t);return r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n*t%e),1n),e)},n.modPow=c,n.phi=f,n.toZn=r})); diff --git a/dist/index.browser.esm.js b/dist/index.browser.esm.js index 6e5131c..7fe3a26 100644 --- a/dist/index.browser.esm.js +++ b/dist/index.browser.esm.js @@ -1,2 +1,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<=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}export{n as abs,t as bitLength,r as eGcd,e as gcd,o as lcm,u as max,i as min,g as modInv,b as modPow,f as toZn}; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguYnJvd3Nlci5lc20uanMiLCJzb3VyY2VzIjpbIi4uL3NyYy90cy9hYnMudHMiLCIuLi9zcmMvdHMvYml0TGVuZ3RoLnRzIiwiLi4vc3JjL3RzL2VnY2QudHMiLCIuLi9zcmMvdHMvZ2NkLnRzIiwiLi4vc3JjL3RzL2xjbS50cyIsIi4uL3NyYy90cy9tYXgudHMiLCIuLi9zcmMvdHMvbWluLnRzIiwiLi4vc3JjL3RzL3RvWm4udHMiLCIuLi9zcmMvdHMvbW9kSW52LnRzIiwiLi4vc3JjL3RzL21vZFBvdy50cyJdLCJzb3VyY2VzQ29udGVudCI6bnVsbCwibmFtZXMiOlsiYWJzIiwiYSIsImJpdExlbmd0aCIsIkJpZ0ludCIsImJpdHMiLCJlR2NkIiwiYiIsIlJhbmdlRXJyb3IiLCJ4IiwieSIsInUiLCJ2IiwicSIsInIiLCJtIiwibiIsImciLCJnY2QiLCJhQWJzIiwiYkFicyIsInNoaWZ0IiwibGNtIiwibWF4IiwibWluIiwidG9abiIsImFabiIsIm1vZEludiIsImVnY2QiLCJ0b1N0cmluZyIsIm1vZFBv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VFVLEVBQU0sR0FBTUEsRUFBTVYsRUFBSVUsQ0FDaEMsQ0NYZ0IsU0FBQUMsRUFBUXpCLEVBQW9CYyxHQUMxQyxNQUFNWSxFQUFPdEIsRUFBS21CLEVBQUt2QixFQUFHYyxHQUFJQSxHQUM5QixHQUFlLEtBQVhZLEVBQUtYLEVBQ1AsTUFBTSxJQUFJVCxXQUFXLEdBQUdOLEVBQUUyQiwyQ0FBMkNiLEVBQUVhLGNBRXZFLE9BQU9KLEVBQUtHLEVBQUtuQixFQUFHTyxFQUV4QixVQ0xnQmMsRUFBUXZCLEVBQW9Cd0IsRUFBb0JmLEdBSzlELEdBSmlCLGlCQUFOVCxJQUFnQkEsRUFBSUgsT0FBT0csSUFDckIsaUJBQU53QixJQUFnQkEsRUFBSTNCLE9BQU8yQixJQUNyQixpQkFBTmYsSUFBZ0JBLEVBQUlaLE9BQU9ZLElBRWxDQSxHQUFLLEdBQ1AsTUFBTSxJQUFJUixXQUFXLGlCQUNoQixHQUFVLEtBQU5RLEVBQ1QsT0FBTyxHQUtULEdBRkFULEVBQUlrQixFQUFLbEIsRUFBR1MsR0FFUmUsRUFBSSxHQUNOLE9BQU9KLEVBQU9HLEVBQU92QixFQUFHTixFQUFJOEIsR0FBSWYsR0FBSUEsR0FHdEMsSUFBSUYsRUFBSSxHQUNSLEtBQU9pQixFQUFJLEdBQ0pBLEVBQUksS0FBUSxLQUNmakIsRUFBSUEsRUFBSVAsRUFBSVMsR0FFZGUsR0FBUSxHQUNSeEIsRUFBSUEsR0FBSyxHQUFLUyxFQUVoQixPQUFPRixDQUNUIn0= +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<=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}export{n as abs,t as bitLength,i as crt,r as eGcd,u as gcd,f as lcm,g as max,c as min,m as modAdd,o as modInv,p as modMultiply,s as modPow,a as phi,e as toZn}; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguYnJvd3Nlci5lc20uanMiLCJzb3VyY2VzIjpbIi4uL3NyYy90cy9hYnMudHMiLCIuLi9zcmMvdHMvYml0TGVuZ3RoLnRzIiwiLi4vc3JjL3RzL2VnY2QudHMiLCIuLi9zcmMvdHMvdG9abi50cyIsIi4uL3NyYy90cy9tb2RJbnYudHMiLCIuLi9zcmMvdHMvY3J0LnRzIiwiLi4vc3JjL3RzL2djZC50cyIsIi4uL3NyYy90cy9sY20udHMiLCIuLi9zcmMvdHMvbWF4LnRzIiwiLi4vc3JjL3RzL21pbi50cyIsIi4uL3NyYy90cy9tb2RBZGQudHMiLCIuLi9zcmMvdHMvbW9kTXVsdGlwbHkudHMiLCIuLi9zcmMvdHMvcGhpLnRzIiwiLi4vc3JjL3RzL21vZFBvdy50cyJdLCJzb3VyY2VzQ29udGVudCI6bnVsbCwibmFtZXMiOlsiYWJzIiwiYSIsImJpdExlbmd0aCIsIkJpZ0ludCIsImJpdHMiLCJlR2NkIiwiYiIsIlJhbmdlRXJyb3IiLCJ4IiwieSIsInUiLCJ2IiwicSIsInIiLCJtIiwibiIsImciLCJ0b1puIiwiYVpuIiwibW9kSW52IiwiZWdjZCIsInRvU3RyaW5nIiwiY3J0IiwicmVtYWluZGVycyIsIm1vZHVsb3MiLCJtb2R1bG8iLCJsZW5ndGgiLCJwcm9kdWN0I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yxPQUFPQyxPQUFPUixHQUFhaEIsS0FBSWQsR0FBTyxDQUFDQSxFQUFJbUMsRUFBR25DLEVBQUlvQyxJQUMzRCxDQXhDNENHLENBQW9CcEIsSUFHOUQsSUFBSXBDLEVBQUksR0FDUixLQUFPd0MsRUFBSSxHQUNKQSxFQUFJLEtBQVEsS0FDZnhDLEVBQUlBLEVBQUlQLEVBQUlTLEdBRWRzQyxHQUFRLEdBQ1IvQyxFQUFJQSxHQUFLLEdBQUtTLEVBRWhCLE9BQU9GLENBQ1QifQ== diff --git a/dist/index.d.ts b/dist/index.d.ts index 39c5a6f..9cb3689 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -2,6 +2,8 @@ declare function abs(a: number | bigint): number | bigint; declare function bitLength(a: number | bigint): number; +declare function crt(remainders: bigint[], modulos: bigint[], modulo?: bigint): bigint; + interface Egcd { g: bigint; x: bigint; @@ -17,10 +19,19 @@ declare function max(a: number | bigint, b: number | bigint): number | bigint; declare function min(a: number | bigint, b: number | bigint): number | bigint; +declare function modAdd(addends: Array, n: number | bigint): bigint; + declare function modInv(a: number | bigint, n: number | bigint): bigint; -declare function modPow(b: number | bigint, e: number | bigint, n: number | bigint): bigint; +declare function modMultiply(factors: Array, n: number | bigint): bigint; + +type PrimePower = [number | bigint, number | bigint]; +type PrimeFactor = number | bigint | PrimePower; +declare function modPow(b: number | bigint, e: number | bigint, n: number | bigint, primeFactorization?: PrimeFactor[]): bigint; + +type PrimeFactorization = Array<[bigint, bigint]>; +declare function phi(primeFactorization: PrimeFactorization): bigint; declare function toZn(a: number | bigint, n: number | bigint): bigint; -export { Egcd, abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn }; +export { Egcd, PrimeFactor, PrimeFactorization, PrimePower, abs, bitLength, crt, eGcd, gcd, lcm, max, min, modAdd, modInv, modMultiply, modPow, phi, toZn }; diff --git a/dist/index.node.cjs b/dist/index.node.cjs index 5a5ad99..dc0fc74 100644 --- a/dist/index.node.cjs +++ b/dist/index.node.cjs @@ -1,2 +1,2 @@ -"use strict";function n(n){return n>=0?n:-n}function t(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,p=e-i*u;t=n,n=f,r=o,e=i,o=g,i=p}return{g:t,x:r,y:e}}function r(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< 0");const r=n%t;return r<0n?r+t:r}function o(n,r){const o=t(e(n,r),r);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${r.toString()}`);return e(o.x,r)}exports.abs=n,exports.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},exports.eGcd=t,exports.gcd=r,exports.lcm=function(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)},exports.max=function(n,t){return n>=t?n:t},exports.min=function(n,t){return n>=t?t:n},exports.modInv=o,exports.modPow=function t(r,i,u){if("number"==typeof r&&(r=BigInt(r)),"number"==typeof i&&(i=BigInt(i)),"number"==typeof u&&(u=BigInt(u)),u<=0n)throw new RangeError("n must be > 0");if(1n===u)return 0n;if(r=e(r,u),i<0n)return o(t(r,n(i),u),u);let f=1n;for(;i>0;)i%2n===1n&&(f=f*r%u),i/=2n,r=r**2n%u;return f},exports.toZn=e; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXgubm9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HQUZBVixFQUFJZ0IsRUFBS2hCLEVBQUdVLEdBRVJhLEVBQUksR0FDTixPQUFPTCxFQUFPSSxFQUFPdEIsRUFBR0gsRUFBSTBCLEdBQUliLEdBQUlBLEdBR3RDLElBQUlGLEVBQUksR0FDUixLQUFPZSxFQUFJLEdBQ0pBLEVBQUksS0FBUSxLQUNmZixFQUFJQSxFQUFJUixFQUFJVSxHQUVkYSxHQUFRLEdBQ1J2QixFQUFJQSxHQUFLLEdBQUtVLEVBRWhCLE9BQU9GLENBQ1QifQ== +"use strict";function n(n){return n>=0?n:-n}function t(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,c=r-o*u,p=e-i*u;t=n,n=f,r=o,e=i,o=c,i=p}return{g:t,x:r,y:e}}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 r=n%t;return r<0n?r+t:r}function e(n,e){const o=t(r(n,e),e);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${e.toString()}`);return r(o.x,e)}function o(n,t,o){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const i=o??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,o,u)=>{const f=i/o;return r(t+f*e(f,o)%i*n[u]%i,i)}),0n)}function i(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<n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function f(t,i,c,p){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof i&&(i=BigInt(i)),"number"==typeof c&&(c=BigInt(c)),c<=0n)throw new RangeError("n must be > 0");if(1n===c)return 0n;if(t=r(t,c),i<0n)return e(f(t,n(i),c,p),c);if(void 0!==p)return function(n,t,r,e){const i=e.map((n=>n[0]**n[1])),c=e.map((n=>u([n]))),p=c.map(((r,e)=>f(n,t%r,i[e])));return o(p,i,r)}(t,i,c,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]))}(p));let s=1n;for(;i>0;)i%2n===1n&&(s=s*t%c),i/=2n,t=t**2n%c;return s}exports.abs=n,exports.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},exports.crt=o,exports.eGcd=t,exports.gcd=i,exports.lcm=function(t,r){return"number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),0n===t&&0n===r?BigInt(0):n(t/i(t,r)*r)},exports.max=function(n,t){return n>=t?n:t},exports.min=function(n,t){return n>=t?t:n},exports.modAdd=function(n,t){const e=BigInt(t);return r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n+t%e),0n),e)},exports.modInv=e,exports.modMultiply=function(n,t){const e=BigInt(t);return r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n*t%e),1n),e)},exports.modPow=f,exports.phi=u,exports.toZn=r; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXgubm9kZS5janMiLCJzb3VyY2VzIjpbIi4uL3NyYy90cy9hYnMudHMiLCIuLi9zcmMvdHMvZWdjZC50cyIsIi4uL3NyYy90cy90b1puLnRzIiwiLi4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lCQUFORixJQUFnQkEsRUFBSUcsT0FBT0gsSUFDckIsaUJBQU5FLElBQWdCQSxFQUFJQyxPQUFPRCxJQUU1QixLQUFORixHQUFrQixLQUFORSxFQUFpQkMsT0FBTyxHQUVqQ0osRUFBS0MsRUFBSWdDLEVBQUloQyxFQUFHRSxHQUFNQSxFQUMvQixjQ1RnQixTQUFLRixFQUFvQkUsR0FDdkMsT0FBUUYsR0FBS0UsRUFBS0YsRUFBSUUsQ0FDeEIsY0NGZ0IsU0FBS0YsRUFBb0JFLEdBQ3ZDLE9BQVFGLEdBQUtFLEVBQUtBLEVBQUlGLENBQ3hCLGlCQ0ZnQixTQUFRNEQsRUFBaUNoRCxHQUN2RCxNQUFNaUIsRUFBTTFCLE9BQU9TLEdBRW5CLE9BQU9FLEVBREk4QyxFQUFRdEIsS0FBSXRDLEdBQUtHLE9BQU9ILEdBQUs2QixJQUN6QkosUUFBTyxDQUFDRyxFQUFLNUIsSUFBTTRCLEVBQU01QixFQUFJNkIsR0FBSyxJQUFLQSxFQUN4RCx1Q0NKZ0IsU0FBYWdDLEVBQWlDakQsR0FDNUQsTUFBTWlCLEVBQU0xQixPQUFPUyxHQUVuQixPQUFPRSxFQURJK0MsRUFBUXZCLEtBQUl0QyxHQUFLRyxPQUFPSCxHQUFLNkIsSUFDekJKLFFBQU8sQ0FBQ3FDLEVBQU05RCxJQUFNOEQsRUFBTzlELEVBQUk2QixHQUFLLElBQUtBLEVBQzFEIn0= diff --git a/dist/index.node.esm.js b/dist/index.node.esm.js index c0704d6..20fdb6b 100644 --- a/dist/index.node.esm.js +++ b/dist/index.node.esm.js @@ -1,2 +1,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<=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}export{n as abs,t as bitLength,r as eGcd,e as gcd,o as lcm,u as max,i as min,g as modInv,b as modPow,f as toZn}; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXgubm9kZS5lc20uanMiLCJzb3VyY2VzIjpbIi4uL3NyYy90cy9hYnMudHMiLCIuLi9zcmMvdHMvYml0TGVuZ3RoLnRzIiwiLi4vc3JjL3RzL2VnY2QudHMiLCIuLi9zcmMvdHMvZ2NkLnRzIiwiLi4vc3JjL3RzL2xjbS50cyIsIi4uL3NyYy90cy9tYXgudHMiLCIuLi9zcmMvdHMvbWluLnRzIiwiLi4vc3JjL3RzL3RvWm4udHMiLCIuLi9zcmMvdHM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QUksS0FBUSxLQUNmakIsRUFBSUEsRUFBSVAsRUFBSVMsR0FFZGUsR0FBUSxHQUNSeEIsRUFBSUEsR0FBSyxHQUFLUyxFQUVoQixPQUFPRixDQUNUIn0= +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<=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}export{n as abs,t as bitLength,i as crt,r as eGcd,u as gcd,f as lcm,g as max,c as min,m as modAdd,o as modInv,p as modMultiply,s as modPow,a as phi,e as toZn}; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXgubm9kZS5lc20uanMiLCJzb3VyY2VzIjpbIi4uL3NyYy90cy9hYnMudHMiLCIuLi9zcmMvdHMvYml0TGVuZ3RoLnRzIiwiLi4vc3JjL3RzL2VnY2QudHMiLCIuLi9zcmMvdHMvdG9abi50cyIsIi4uL3NyYy90cy9tb2RJbnYudHMiLCIuLi9zcmMvdHMvY3J0LnRzIiwiLi4vc3JjL3RzL2djZC50cyIsIi4uL3NyYy90cy9sY20udHMiLCIuLi9zcmMvdHMvbWF4LnRzIiwiLi4vc3JjL3RzL21pbi50cyIsIi4uL3NyYy90cy9tb2RBZGQudHMiLCIuLi9zcmMvdHMvbW9kTXVsdGlwbHkudHMiLCIuLi9zcmMvdHMvcGhpLnRzIiw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BQVlHLEdBQU8sQ0FBRUUsRUFBRzlELE9BQU8yRCxHQUFjSSxFQUFHLElBRWhETixFQUFZRyxHQUFLRyxHQUFLLEVBRXpCLEtBQU0sQ0FDTCxNQUFNSCxFQUFNQyxPQUFPRixFQUFZLFNBQ05SLElBQXJCTSxFQUFZRyxHQUNkSCxFQUFZRyxHQUFPLENBQUVFLEVBQUc5RCxPQUFPMkQsRUFBWSxJQUFLSSxFQUFHL0QsT0FBTzJELEVBQVksS0FFdEVGLEVBQVlHLEdBQUtHLEdBQUsvRCxPQUFPMkQsRUFBWSxHQUU1QyxLQUVJSyxPQUFPQyxPQUFPUixHQUFhaEIsS0FBSWQsR0FBTyxDQUFDQSxFQUFJbUMsRUFBR25DLEVBQUlvQyxJQUMzRCxDQXhDNENHLENBQW9CcEIsSUFHOUQsSUFBSXBDLEVBQUksR0FDUixLQUFPd0MsRUFBSSxHQUNKQSxFQUFJLEtBQVEsS0FDZnhDLEVBQUlBLEVBQUlQLEVBQUlTLEdBRWRzQyxHQUFRLEdBQ1IvQyxFQUFJQSxHQUFLLEdBQUtTLEVBRWhCLE9BQU9GLENBQ1QifQ== diff --git a/docs/API.md b/docs/API.md index 16bb64f..1bfc50b 100644 --- a/docs/API.md +++ b/docs/API.md @@ -8,19 +8,59 @@ Some common functions for modular arithmetic using native JS implementation of B - [Egcd](interfaces/Egcd.md) +### Type Aliases + +- [PrimeFactor](API.md#primefactor) +- [PrimeFactorization](API.md#primefactorization) +- [PrimePower](API.md#primepower) + ### Functions - [abs](API.md#abs) - [bitLength](API.md#bitlength) +- [crt](API.md#crt) - [eGcd](API.md#egcd) - [gcd](API.md#gcd) - [lcm](API.md#lcm) - [max](API.md#max) - [min](API.md#min) +- [modAdd](API.md#modadd) - [modInv](API.md#modinv) +- [modMultiply](API.md#modmultiply) - [modPow](API.md#modpow) +- [phi](API.md#phi) - [toZn](API.md#tozn) +## Type Aliases + +### PrimeFactor + +Ƭ **PrimeFactor**: `number` \| `bigint` \| [`PrimePower`](API.md#primepower) + +#### Defined in + +[modPow.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/modPow.ts#L8) + +___ + +### PrimeFactorization + +Ƭ **PrimeFactorization**: [`bigint`, `bigint`][] + +#### Defined in + +phi.ts:1 + +___ + +### PrimePower + +Ƭ **PrimePower**: [`number` \| `bigint`, `number` \| `bigint`] + +#### Defined in + +[modPow.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/modPow.ts#L7) + ## Functions ### abs @@ -43,7 +83,7 @@ The absolute value of a #### Defined in -[abs.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/abs.ts#L8) +[abs.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/abs.ts#L8) ___ @@ -67,7 +107,37 @@ The bit length #### Defined in -[bitLength.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/bitLength.ts#L7) +[bitLength.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/bitLength.ts#L7) + +___ + +### 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 + +#### Defined in + +crt.ts:16 ___ @@ -97,7 +167,7 @@ A triple (g, x, y), such that ax + by = g = gcd(a, b). #### Defined in -[egcd.ts:17](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/egcd.ts#L17) +[egcd.ts:17](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/egcd.ts#L17) ___ @@ -122,7 +192,7 @@ The greatest common divisor of a and b #### Defined in -[gcd.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/gcd.ts#L10) +[gcd.ts:11](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/gcd.ts#L11) ___ @@ -147,7 +217,7 @@ The least common multiple of a and b #### Defined in -[lcm.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/lcm.ts#L10) +[lcm.ts:11](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/lcm.ts#L11) ___ @@ -172,7 +242,7 @@ Maximum of numbers a and b #### Defined in -[max.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/max.ts#L9) +[max.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/max.ts#L9) ___ @@ -197,7 +267,32 @@ Minimum of numbers a and b #### Defined in -[min.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/min.ts#L9) +[min.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/min.ts#L9) + +___ + +### 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 + +#### Defined in + +modAdd.ts:9 ___ @@ -226,15 +321,41 @@ The inverse modulo n #### Defined in -[modInv.ts:13](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/modInv.ts#L13) +[modInv.ts:14](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/modInv.ts#L14) + +___ + +### 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 + +#### Defined in + +modMultiply.ts:9 ___ ### modPow -▸ **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 +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`** @@ -247,6 +368,7 @@ RangeError if n <= 0 | `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. | #### Returns @@ -256,7 +378,31 @@ b**e mod n #### Defined in -[modPow.ts:15](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/modPow.ts#L15) +[modPow.ts:22](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/modPow.ts#L22) + +___ + +### 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, i.e. 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)) + +#### Defined in + +phi.ts:9 ___ @@ -289,4 +435,4 @@ A bigint with the smallest positive representation of a modulo n #### Defined in -[toZn.ts:14](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/toZn.ts#L14) +[toZn.ts:14](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/toZn.ts#L14) diff --git a/docs/interfaces/Egcd.md b/docs/interfaces/Egcd.md index 18a676d..e8e99ba 100644 --- a/docs/interfaces/Egcd.md +++ b/docs/interfaces/Egcd.md @@ -16,7 +16,7 @@ #### Defined in -[egcd.ts:2](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/egcd.ts#L2) +[egcd.ts:2](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/egcd.ts#L2) ___ @@ -26,7 +26,7 @@ ___ #### Defined in -[egcd.ts:3](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/egcd.ts#L3) +[egcd.ts:3](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/egcd.ts#L3) ___ @@ -36,4 +36,4 @@ ___ #### Defined in -[egcd.ts:4](https://github.com/juanelas/bigint-mod-arith/blob/84ebe88/src/ts/egcd.ts#L4) +[egcd.ts:4](https://github.com/juanelas/bigint-mod-arith/blob/80793b3/src/ts/egcd.ts#L4) diff --git a/package-lock.json b/package-lock.json index c721813..82e4180 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,33 +43,33 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.21.4", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.21.4.tgz", - "integrity": "sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.5.tgz", + "integrity": "sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ==", "dev": true, "dependencies": { - "@babel/highlight": "^7.18.6" + "@babel/highlight": "^7.22.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", - "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz", + "integrity": "sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", - "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.5.tgz", + "integrity": "sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.18.6", + "@babel/helper-validator-identifier": "^7.22.5", "chalk": "^2.0.0", "js-tokens": "^4.0.0" }, @@ -170,23 +170,23 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.5.0.tgz", - "integrity": "sha512-vITaYzIcNmjn5tF5uxcZ/ft7/RXGrMUIS9HalWckEOF6ESiwXKoMzAQf2UW0aVd6rnOeExTJVd5hmWXucBKGXQ==", + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.5.1.tgz", + "integrity": "sha512-Z5ba73P98O1KUYCCJTUeVpja9RcGoMdncZ6T49FCUl2lN38JtCJ+3WgIDBv0AuY4WChU5PmtJmOCTlN6FZTFKQ==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, "node_modules/@eslint/eslintrc": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.2.tgz", - "integrity": "sha512-3W4f5tDUra+pA+FzgugqL2pRimUTDJWKr7BINqOpkZrC0uYI0NIc0/JFgBROCU07HR6GieA5m3/rsPIhDmCXTQ==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.3.tgz", + "integrity": "sha512-+5gy6OQfk+xx3q0d6jGZZC3f3KzAkXc/IanVxd1is/VIIziRqqt3ongQz0FiTUXqTk0c7aDB3OaFuKnuSoJicQ==", "dev": true, "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.5.1", + "espree": "^9.5.2", "globals": "^13.19.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", @@ -224,18 +224,18 @@ } }, "node_modules/@eslint/js": { - "version": "8.38.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.38.0.tgz", - "integrity": "sha512-IoD2MfUnOV58ghIHCiil01PcohxjbYR/qCxsoC+xNgUwh1EY8jOOrYmu3d3a71+tJJ23uscEV4X2HJWMsPJu4g==", + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.43.0.tgz", + "integrity": "sha512-s2UHCoiXfxMvmfzqoN+vrQ84ahUSYde9qNO1MdxmoEhyHWsfmwOpFlwYV+ePJEVc7gFnATGUi376WowX1N7tFg==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.8", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", - "integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==", + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", + "integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==", "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^1.2.1", @@ -287,6 +287,23 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@istanbuljs/schema": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", @@ -395,10 +412,20 @@ "node": ">= 8" } }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, + "optional": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@puppeteer/browsers": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-0.4.1.tgz", - "integrity": "sha512-4IICvy1McAkT/HyNZHIs7sp8ngBX1dmO0TPQ+FWq9ATQMqI8p+Ulm5A3kS2wYDh5HDHHkYrrETOu6rlj64VuTw==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-0.5.0.tgz", + "integrity": "sha512-Uw6oB7VvmPRLE4iKsjuOh8zgDabhNX67dzo8U/BB0f9527qx+4eeUs+korU98OhG5C4ubg7ufBgVi63XYwS6TQ==", "dev": true, "dependencies": { "debug": "4.3.4", @@ -425,6 +452,15 @@ } } }, + "node_modules/@puppeteer/browsers/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/@puppeteer/browsers/node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", @@ -439,6 +475,55 @@ "node": ">=12" } }, + "node_modules/@puppeteer/browsers/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/@puppeteer/browsers/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@puppeteer/browsers/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@puppeteer/browsers/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/@puppeteer/browsers/node_modules/yargs": { "version": "17.7.1", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.1.tgz", @@ -586,9 +671,9 @@ } }, "node_modules/@rollup/plugin-node-resolve": { - "version": "15.0.2", - "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.0.2.tgz", - "integrity": "sha512-Y35fRGUjC3FaurG722uhUuG8YHOJRJQbI6/CkbRkdPotSpDj9NtIN85z1zrcyDcCQIW4qp5mgG72U+gJ0TAFEg==", + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.1.0.tgz", + "integrity": "sha512-xeZHCgsiZ9pzYVgAo9580eCGqwh/XCEUM9q6iQfGNocjgkufHAqC3exA+45URvhiYV8sBF9RlBai650eNs7AsA==", "dev": true, "dependencies": { "@rollup/pluginutils": "^5.0.1", @@ -632,14 +717,14 @@ } }, "node_modules/@rollup/plugin-terser": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@rollup/plugin-terser/-/plugin-terser-0.4.1.tgz", - "integrity": "sha512-aKS32sw5a7hy+fEXVy+5T95aDIwjpGHCTv833HXVtyKMDoVS7pBr5K3L9hEQoNqbJFjfANPrNpIXlTQ7is00eA==", + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/@rollup/plugin-terser/-/plugin-terser-0.4.3.tgz", + "integrity": "sha512-EF0oejTMtkyhrkwCdg0HJ0IpkcaVg1MMSf2olHb2Jp+1mnLM04OhjpJWGma4HobiDTF0WCyViWuvadyE9ch2XA==", "dev": true, "dependencies": { - "serialize-javascript": "^6.0.0", - "smob": "^0.0.6", - "terser": "^5.15.1" + "serialize-javascript": "^6.0.1", + "smob": "^1.0.0", + "terser": "^5.17.4" }, "engines": { "node": ">=14.0.0" @@ -654,9 +739,9 @@ } }, "node_modules/@rollup/plugin-typescript": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.0.tgz", - "integrity": "sha512-86flrfE+bSHB69znnTV6kVjkncs2LBMhcTCyxWgRxLyfXfQrxg4UwlAqENnjrrxnSNS/XKCDJCl8EkdFJVHOxw==", + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.1.tgz", + "integrity": "sha512-Ioir+x5Bejv72Lx2Zbz3/qGg7tvGbxQZALCLoJaGrkNXak/19+vKgKYJYM3i/fJxvsb23I9FuFQ8CUBEfsmBRg==", "dev": true, "dependencies": { "@rollup/pluginutils": "^5.0.1", @@ -719,15 +804,15 @@ } }, "node_modules/@types/chai": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.4.tgz", - "integrity": "sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw==", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.5.tgz", + "integrity": "sha512-mEo1sAde+UCE6b2hxn332f1g1E8WfYRu6p5SvTKr2ZKC1f7gFJXk4h5PyGP9Dt6gCaG8y8XhwnXWC6Iy2cmBng==", "dev": true }, "node_modules/@types/estree": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz", - "integrity": "sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", + "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", "dev": true }, "node_modules/@types/istanbul-lib-coverage": { @@ -737,9 +822,9 @@ "dev": true }, "node_modules/@types/json-schema": { - "version": "7.0.11", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", - "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", + "version": "7.0.12", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz", + "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==", "dev": true }, "node_modules/@types/json5": { @@ -755,9 +840,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.15.11", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz", - "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==", + "version": "20.3.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.2.tgz", + "integrity": "sha512-vOBLVQeCQfIcF/2Y7eKFTqrMnizK5lRNQ7ykML/5RuwVXVWxYkgwS7xbt4B6fKCUPgbSL5FSsjHQpaGQP/dQmw==", "dev": true, "optional": true }, @@ -768,9 +853,9 @@ "dev": true }, "node_modules/@types/semver": { - "version": "7.3.13", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz", - "integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz", + "integrity": "sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==", "dev": true }, "node_modules/@types/yauzl": { @@ -784,15 +869,15 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.58.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.58.0.tgz", - "integrity": "sha512-vxHvLhH0qgBd3/tW6/VccptSfc8FxPQIkmNTVLWcCOVqSBvqpnKkBTYrhcGlXfSnd78azwe+PsjYFj0X34/njA==", + "version": "5.60.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.60.1.tgz", + "integrity": "sha512-KSWsVvsJsLJv3c4e73y/Bzt7OpqMCADUO846bHcuWYSYM19bldbAeDv7dYyV0jwkbMfJ2XdlzwjhXtuD7OY6bw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.4.0", - "@typescript-eslint/scope-manager": "5.58.0", - "@typescript-eslint/type-utils": "5.58.0", - "@typescript-eslint/utils": "5.58.0", + "@typescript-eslint/scope-manager": "5.60.1", + "@typescript-eslint/type-utils": "5.60.1", + "@typescript-eslint/utils": "5.60.1", "debug": "^4.3.4", "grapheme-splitter": "^1.0.4", "ignore": "^5.2.0", @@ -830,9 +915,9 @@ } }, "node_modules/@typescript-eslint/eslint-plugin/node_modules/semver": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.4.0.tgz", - "integrity": "sha512-RgOxM8Mw+7Zus0+zcLEUn8+JfoLpj/huFTItQy2hsM4khuC1HYRDp0cU482Ewn/Fcy6bCjufD8vAj7voC66KQw==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -845,14 +930,14 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "5.58.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.58.0.tgz", - "integrity": "sha512-ixaM3gRtlfrKzP8N6lRhBbjTow1t6ztfBvQNGuRM8qH1bjFFXIJ35XY+FC0RRBKn3C6cT+7VW1y8tNm7DwPHDQ==", + "version": "5.60.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.60.1.tgz", + "integrity": "sha512-pHWlc3alg2oSMGwsU/Is8hbm3XFbcrb6P5wIxcQW9NsYBfnrubl/GhVVD/Jm/t8HXhA2WncoIRfBtnCgRGV96Q==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.58.0", - "@typescript-eslint/types": "5.58.0", - "@typescript-eslint/typescript-estree": "5.58.0", + "@typescript-eslint/scope-manager": "5.60.1", + "@typescript-eslint/types": "5.60.1", + "@typescript-eslint/typescript-estree": "5.60.1", "debug": "^4.3.4" }, "engines": { @@ -872,13 +957,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "5.58.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.58.0.tgz", - "integrity": "sha512-b+w8ypN5CFvrXWQb9Ow9T4/6LC2MikNf1viLkYTiTbkQl46CnR69w7lajz1icW0TBsYmlpg+mRzFJ4LEJ8X9NA==", + "version": "5.60.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.60.1.tgz", + "integrity": "sha512-Dn/LnN7fEoRD+KspEOV0xDMynEmR3iSHdgNsarlXNLGGtcUok8L4N71dxUgt3YvlO8si7E+BJ5Fe3wb5yUw7DQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.58.0", - "@typescript-eslint/visitor-keys": "5.58.0" + "@typescript-eslint/types": "5.60.1", + "@typescript-eslint/visitor-keys": "5.60.1" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -889,13 +974,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "5.58.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.58.0.tgz", - "integrity": "sha512-FF5vP/SKAFJ+LmR9PENql7fQVVgGDOS+dq3j+cKl9iW/9VuZC/8CFmzIP0DLKXfWKpRHawJiG70rVH+xZZbp8w==", + "version": "5.60.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.60.1.tgz", + "integrity": "sha512-vN6UztYqIu05nu7JqwQGzQKUJctzs3/Hg7E2Yx8rz9J+4LgtIDFWjjl1gm3pycH0P3mHAcEUBd23LVgfrsTR8A==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "5.58.0", - "@typescript-eslint/utils": "5.58.0", + "@typescript-eslint/typescript-estree": "5.60.1", + "@typescript-eslint/utils": "5.60.1", "debug": "^4.3.4", "tsutils": "^3.21.0" }, @@ -916,9 +1001,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "5.58.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.58.0.tgz", - "integrity": "sha512-JYV4eITHPzVQMnHZcYJXl2ZloC7thuUHrcUmxtzvItyKPvQ50kb9QXBkgNAt90OYMqwaodQh2kHutWZl1fc+1g==", + "version": "5.60.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.60.1.tgz", + "integrity": "sha512-zDcDx5fccU8BA0IDZc71bAtYIcG9PowaOwaD8rjYbqwK7dpe/UMQl3inJ4UtUK42nOCT41jTSCwg76E62JpMcg==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -929,13 +1014,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.58.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.58.0.tgz", - "integrity": "sha512-cRACvGTodA+UxnYM2uwA2KCwRL7VAzo45syNysqlMyNyjw0Z35Icc9ihPJZjIYuA5bXJYiJ2YGUB59BqlOZT1Q==", + "version": "5.60.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.60.1.tgz", + "integrity": "sha512-hkX70J9+2M2ZT6fhti5Q2FoU9zb+GeZK2SLP1WZlvUDqdMbEKhexZODD1WodNRyO8eS+4nScvT0dts8IdaBzfw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.58.0", - "@typescript-eslint/visitor-keys": "5.58.0", + "@typescript-eslint/types": "5.60.1", + "@typescript-eslint/visitor-keys": "5.60.1", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -968,9 +1053,9 @@ } }, "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.4.0.tgz", - "integrity": "sha512-RgOxM8Mw+7Zus0+zcLEUn8+JfoLpj/huFTItQy2hsM4khuC1HYRDp0cU482Ewn/Fcy6bCjufD8vAj7voC66KQw==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -983,17 +1068,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "5.58.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.58.0.tgz", - "integrity": "sha512-gAmLOTFXMXOC+zP1fsqm3VceKSBQJNzV385Ok3+yzlavNHZoedajjS4UyS21gabJYcobuigQPs/z71A9MdJFqQ==", + "version": "5.60.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.60.1.tgz", + "integrity": "sha512-tiJ7FFdFQOWssFa3gqb94Ilexyw0JVxj6vBzaSpfN/8IhoKkDuSAenUKvsSHw2A/TMpJb26izIszTXaqygkvpQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@types/json-schema": "^7.0.9", "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.58.0", - "@typescript-eslint/types": "5.58.0", - "@typescript-eslint/typescript-estree": "5.58.0", + "@typescript-eslint/scope-manager": "5.60.1", + "@typescript-eslint/types": "5.60.1", + "@typescript-eslint/typescript-estree": "5.60.1", "eslint-scope": "^5.1.1", "semver": "^7.3.7" }, @@ -1021,9 +1106,9 @@ } }, "node_modules/@typescript-eslint/utils/node_modules/semver": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.4.0.tgz", - "integrity": "sha512-RgOxM8Mw+7Zus0+zcLEUn8+JfoLpj/huFTItQy2hsM4khuC1HYRDp0cU482Ewn/Fcy6bCjufD8vAj7voC66KQw==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -1036,12 +1121,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.58.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.58.0.tgz", - "integrity": "sha512-/fBraTlPj0jwdyTwLyrRTxv/3lnU2H96pNTVM6z3esTWLtA5MZ9ghSMJ7Rb+TtUAdtEw9EyJzJ0EydIMKxQ9gA==", + "version": "5.60.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.60.1.tgz", + "integrity": "sha512-xEYIxKcultP6E/RMKqube11pGjXH1DCo60mQoWhVYyKfLkwbIVVjYxmOenNMxILx0TjCujPTjjnTIVzm09TXIw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.58.0", + "@typescript-eslint/types": "5.60.1", "eslint-visitor-keys": "^3.3.0" }, "engines": { @@ -1053,9 +1138,9 @@ } }, "node_modules/acorn": { - "version": "8.8.2", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", - "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz", + "integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -1111,12 +1196,15 @@ } }, "node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", "dev": true, "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, "node_modules/ansi-sequence-parser": { @@ -1416,9 +1504,9 @@ } }, "node_modules/builtins/node_modules/semver": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.4.0.tgz", - "integrity": "sha512-RgOxM8Mw+7Zus0+zcLEUn8+JfoLpj/huFTItQy2hsM4khuC1HYRDp0cU482Ewn/Fcy6bCjufD8vAj7voC66KQw==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -1431,9 +1519,9 @@ } }, "node_modules/c8": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/c8/-/c8-7.13.0.tgz", - "integrity": "sha512-/NL4hQTv1gBL6J6ei80zu3IiTrmePDKXKXOTLpHvcIWZTVYQlDhVWjjWvkhICylE8EwwnMVzDZugCvdx0/DIIA==", + "version": "7.14.0", + "resolved": "https://registry.npmjs.org/c8/-/c8-7.14.0.tgz", + "integrity": "sha512-i04rtkkcNcCf7zsQcSv/T9EbUn4RXQ6mropeMcjFOsQXQ0iGLAr/xT6TImQg4+U9hmNpN9XdvPkjUL1IzbgxJw==", "dev": true, "dependencies": { "@bcoe/v8-coverage": "^0.2.3", @@ -1624,9 +1712,9 @@ "dev": true }, "node_modules/chromium-bidi": { - "version": "0.4.6", - "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-0.4.6.tgz", - "integrity": "sha512-TQOkWRaLI/IWvoP8XC+7jO4uHTIiAUiklXU1T0qszlUFEai9LgKXIBXy3pOS3EnQZ3bQtMbKUPkug0fTAEHCSw==", + "version": "0.4.7", + "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-0.4.7.tgz", + "integrity": "sha512-6+mJuFXwTMU6I3vYLs6IL8A1DyQTPjCfIL971X0aMPVGRbGnNfl6i6Cl0NMbxi2bRYLGESt9T2ZIMRM5PAEcIQ==", "dev": true, "dependencies": { "mitt": "3.0.0" @@ -1646,6 +1734,64 @@ "wrap-ansi": "^7.0.0" } }, + "node_modules/cliui/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/cliui/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -1847,18 +1993,27 @@ } }, "node_modules/dotenv": { - "version": "16.0.3", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", - "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", "dev": true, "engines": { "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" } }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true + }, "node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", "dev": true }, "node_modules/end-of-stream": { @@ -1989,16 +2144,16 @@ } }, "node_modules/eslint": { - "version": "8.38.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.38.0.tgz", - "integrity": "sha512-pIdsD2jwlUGf/U38Jv97t8lq6HpaU/G9NKbYmpWpZGw3LdTNhZLbJePqxOXGB5+JEKfOPU/XLxYxFh03nr1KTg==", + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.43.0.tgz", + "integrity": "sha512-aaCpf2JqqKesMFGgmRPessmVKjcGXqdlAYLLC3THM8t5nBRZRQ+st5WM/hoJXkdioEXLLbXgclUpM0TXo5HX5Q==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.4.0", - "@eslint/eslintrc": "^2.0.2", - "@eslint/js": "8.38.0", - "@humanwhocodes/config-array": "^0.11.8", + "@eslint/eslintrc": "^2.0.3", + "@eslint/js": "8.43.0", + "@humanwhocodes/config-array": "^0.11.10", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", "ajv": "^6.10.0", @@ -2007,9 +2162,9 @@ "debug": "^4.3.2", "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.1.1", - "eslint-visitor-keys": "^3.4.0", - "espree": "^9.5.1", + "eslint-scope": "^7.2.0", + "eslint-visitor-keys": "^3.4.1", + "espree": "^9.5.2", "esquery": "^1.4.2", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -2017,13 +2172,12 @@ "find-up": "^5.0.0", "glob-parent": "^6.0.2", "globals": "^13.19.0", - "grapheme-splitter": "^1.0.4", + "graphemer": "^1.4.0", "ignore": "^5.2.0", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", - "js-sdsl": "^4.1.4", "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", @@ -2134,9 +2288,9 @@ } }, "node_modules/eslint-module-utils": { - "version": "2.7.4", - "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.7.4.tgz", - "integrity": "sha512-j4GT+rqzCoRKHwURX7pddtIPGySnX9Si/cgMI5ztrcqOPtk5dDEeZ34CQVPphnqkJytlc97Vuk05Um2mJ3gEQA==", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.8.0.tgz", + "integrity": "sha512-aWajIYfsqCKRDgUfjEXNN/JlrzauMuSEy5sbd7WXbtW3EH6A6MpwEh42c7qD+MqQo9QMJ6fWLAeIJynx0g6OAw==", "dev": true, "dependencies": { "debug": "^3.2.7" @@ -2334,9 +2488,9 @@ } }, "node_modules/eslint-plugin-n/node_modules/semver": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.4.0.tgz", - "integrity": "sha512-RgOxM8Mw+7Zus0+zcLEUn8+JfoLpj/huFTItQy2hsM4khuC1HYRDp0cU482Ewn/Fcy6bCjufD8vAj7voC66KQw==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -2490,9 +2644,9 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz", - "integrity": "sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.1.tgz", + "integrity": "sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -2501,6 +2655,15 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/eslint/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -2512,9 +2675,9 @@ } }, "node_modules/eslint/node_modules/eslint-scope": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", - "integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.0.tgz", + "integrity": "sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw==", "dev": true, "dependencies": { "esrecurse": "^4.3.0", @@ -2522,6 +2685,9 @@ }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, "node_modules/eslint/node_modules/glob-parent": { @@ -2548,15 +2714,27 @@ "node": "*" } }, + "node_modules/eslint/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/espree": { - "version": "9.5.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.1.tgz", - "integrity": "sha512-5yxtHSZXRSW5pvv3hAlXM5+/Oswi1AUFqBmbibKb5s6bp3rGIDkyXU6xCoyuuLhijr4SFwPrXRoZjz0AZDN9tg==", + "version": "9.5.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.2.tgz", + "integrity": "sha512-7OASN1Wma5fum5SrNhFMAMJxOUAbhyfQ8dQ//PJaJbNw0URTPWqIghHWt1MmAANKhHZIYOHruW4Kw4ruUWOdGw==", "dev": true, "dependencies": { "acorn": "^8.8.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.0" + "eslint-visitor-keys": "^3.4.1" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -2910,13 +3088,14 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz", - "integrity": "sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", + "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", "dev": true, "dependencies": { "function-bind": "^1.1.1", "has": "^1.0.3", + "has-proto": "^1.0.1", "has-symbols": "^1.0.3" }, "funding": { @@ -2967,15 +3146,19 @@ } }, "node_modules/glob": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.0.0.tgz", - "integrity": "sha512-zmp9ZDC6NpDNLujV2W2n+3lH+BafIVZ4/ct+Yj3BMZTH/+bgm/eVjHzeFLwxJrrIGgjjS2eiQLlpurHsNlEAtQ==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.0.tgz", + "integrity": "sha512-AQ1/SB9HH0yCx1jXAT4vmCbTOPe5RQ+kCurjbel5xSCGhebumUv+GJZfa1rEqor3XIViqwSEmlkZCQD43RWrBg==", "dev": true, "dependencies": { - "fs.realpath": "^1.0.0", - "minimatch": "^9.0.0", - "minipass": "^5.0.0", - "path-scurry": "^1.6.4" + "foreground-child": "^3.1.0", + "jackspeak": "^2.0.3", + "minimatch": "^9.0.1", + "minipass": "^5.0.0 || ^6.0.2", + "path-scurry": "^1.7.0" + }, + "bin": { + "glob": "dist/cjs/src/bin.js" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -2996,6 +3179,34 @@ "node": ">= 6" } }, + "node_modules/glob/node_modules/foreground-child": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", + "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob/node_modules/signal-exit": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.0.2.tgz", + "integrity": "sha512-MY2/qGx4enyjprQnFaZsHib3Yadh3IXyV2C321GY0pjGfVBu4un0uDJkwgdxqO+Rdx8JMT8IfJIRwbYVz3Ob3Q==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/globals": { "version": "13.20.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", @@ -3070,6 +3281,12 @@ "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", "dev": true }, + "node_modules/graphemer": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", + "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", + "dev": true + }, "node_modules/handlebars": { "version": "4.7.7", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", @@ -3378,9 +3595,9 @@ } }, "node_modules/is-core-module": { - "version": "2.12.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.0.tgz", - "integrity": "sha512-RECHCBCd/viahWmwj6enj19sKbHfJrddi/6cBDsNTKbNq0f7VeaUkBo60BqzvPqo/W54ChS62Z5qyun7cfOMqQ==", + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.1.tgz", + "integrity": "sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==", "dev": true, "dependencies": { "has": "^1.0.3" @@ -3646,14 +3863,22 @@ "node": ">=8" } }, - "node_modules/js-sdsl": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.0.tgz", - "integrity": "sha512-FfVSdx6pJ41Oa+CF7RDaFmTnCaFhua+SNYQX74riGOpl96x+2jQCqEfQ2bnXu/5DPCqlRuiqyvTJM0Qjz26IVg==", + "node_modules/jackspeak": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.2.1.tgz", + "integrity": "sha512-MXbxovZ/Pm42f6cDIDkl3xpwv1AGwObKwfmjs2nQePiy85tP3fatofl3FC1aBsOtP/6fq5SbtgHwWcMsLP+bDw==", "dev": true, + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "engines": { + "node": ">=14" + }, "funding": { - "type": "opencollective", - "url": "https://opencollective.com/js-sdsl" + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" } }, "node_modules/js-tokens": { @@ -3835,9 +4060,9 @@ } }, "node_modules/lru-cache": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-9.0.1.tgz", - "integrity": "sha512-C8QsKIN1UIXeOs3iWmiZ1lQY+EnKDojWd37fXy1aSbJvH4iSma1uy2OWuoB3m4SYRli5+CUjDv3Dij5DVoetmg==", + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-9.1.2.tgz", + "integrity": "sha512-ERJq3FOzJTxBbFjZ7iDs+NiK4VI9Wz+RdrrAB8dio1oV+YvdPzUEE4QNiT2VD51DkIbCYRUUzCRkssXCHqSnKQ==", "dev": true, "engines": { "node": "14 || >=16.14" @@ -3978,9 +4203,9 @@ } }, "node_modules/minimatch": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.0.tgz", - "integrity": "sha512-0jJj8AvgKqWN05mrwuqi8QYKx1WmYSUoKSxu5Qhs9prezTz10sxAHGNZe9J9cqIJzta8DWsleh2KaVaLl6Ru2w==", + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.2.tgz", + "integrity": "sha512-PZOT9g5v2ojiTL7r1xF6plNHLtOeTpSlDI007As2NlA2aYBMfVom17yqa6QzhmDP8QOhn7LjHTg7DFCVSSa6yg==", "dev": true, "dependencies": { "brace-expansion": "^2.0.1" @@ -4002,12 +4227,12 @@ } }, "node_modules/minipass": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", - "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-6.0.2.tgz", + "integrity": "sha512-MzWSV5nYVT7mVyWCwn2o7JH13w2TBRmmSqSRCKzTw+lmft9X4z+3wjvs06Tzijo5z4W/kahUCDpRXTF+ZrmF/w==", "dev": true, "engines": { - "node": ">=8" + "node": ">=16 || 14 >=14.17" } }, "node_modules/mitt": { @@ -4661,13 +4886,13 @@ "dev": true }, "node_modules/path-scurry": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.6.4.tgz", - "integrity": "sha512-Qp/9IHkdNiXJ3/Kon++At2nVpnhRiPq/aSvQN+H3U1WZbvNRK0RIQK/o4HMqPoXjpuGJUEWpHSs6Mnjxqh3TQg==", + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.9.2.tgz", + "integrity": "sha512-qSDLy2aGFPm8i4rsbHd4MNyTcrzHFsLQykrtbuGRknZZCBBVXSv2tSCDN2Cg6Rt/GFRw8GoW9y9Ecw5rIPG1sg==", "dev": true, "dependencies": { - "lru-cache": "^9.0.0", - "minipass": "^5.0.0" + "lru-cache": "^9.1.1", + "minipass": "^5.0.0 || ^6.0.2" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -4734,9 +4959,9 @@ } }, "node_modules/pirates": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.5.tgz", - "integrity": "sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==", + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.6.tgz", + "integrity": "sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==", "dev": true, "engines": { "node": ">= 6" @@ -4907,28 +5132,28 @@ } }, "node_modules/puppeteer": { - "version": "19.9.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.9.0.tgz", - "integrity": "sha512-JDx8WwGlkdQYTaa3OMYDF+uFWimiwNnacg5FGEC5J6+VxDsLK30wHKU/Db2LqEhtAoIu4RwS+BRH4zRPlCsFpA==", + "version": "19.11.1", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.11.1.tgz", + "integrity": "sha512-39olGaX2djYUdhaQQHDZ0T0GwEp+5f9UB9HmEP0qHfdQHIq0xGQZuAZ5TLnJIc/88SrPLpEflPC+xUqOTv3c5g==", "dev": true, "hasInstallScript": true, "dependencies": { - "@puppeteer/browsers": "0.4.1", + "@puppeteer/browsers": "0.5.0", "cosmiconfig": "8.1.3", "https-proxy-agent": "5.0.1", "progress": "2.0.3", "proxy-from-env": "1.1.0", - "puppeteer-core": "19.9.0" + "puppeteer-core": "19.11.1" } }, "node_modules/puppeteer-core": { - "version": "19.9.0", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.9.0.tgz", - "integrity": "sha512-IJYfCE0oFpi5dTvNFqOwo8Dey6zzx7hANy7z6K2bjpCux9oPOSOIubq40awNhaHlfi8soYtgU4qabnzMXB7xBQ==", + "version": "19.11.1", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.11.1.tgz", + "integrity": "sha512-qcuC2Uf0Fwdj9wNtaTZ2OvYRraXpAK+puwwVW8ofOhOgLPZyz1c68tsorfIZyCUOpyBisjr+xByu7BMbEYMepA==", "dev": true, "dependencies": { - "@puppeteer/browsers": "0.4.1", - "chromium-bidi": "0.4.6", + "@puppeteer/browsers": "0.5.0", + "chromium-bidi": "0.4.7", "cross-fetch": "3.1.5", "debug": "4.3.4", "devtools-protocol": "0.0.1107588", @@ -5039,14 +5264,14 @@ } }, "node_modules/regexp.prototype.flags": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.3.tgz", - "integrity": "sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.0.tgz", + "integrity": "sha512-0SutC3pNudRKgquxGoRGIz946MZVHqbNfPjBdxeOhBrdgDKlRoXmYLQN9xRbrR09ZXWeGAdPuif7egofn6v5LA==", "dev": true, "dependencies": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "functions-have-names": "^1.2.2" + "define-properties": "^1.2.0", + "functions-have-names": "^1.2.3" }, "engines": { "node": ">= 0.4" @@ -5113,12 +5338,12 @@ } }, "node_modules/rimraf": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.0.tgz", - "integrity": "sha512-Jf9llaP+RvaEVS5nPShYFhtXIrb3LRKP281ib3So0KkeZKo2wIKyq0Re7TOSwanasA423PSr6CCIL4bP6T040g==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.1.tgz", + "integrity": "sha512-OfFZdwtd3lZ+XZzYP/6gTACubwFcHdLRqS9UX3UwpU2dnGQYkPFISRwvM3w9IiB2w7bW5qGo/uAwE4SmXXSKvg==", "dev": true, "dependencies": { - "glob": "^10.0.0" + "glob": "^10.2.5" }, "bin": { "rimraf": "dist/cjs/src/bin.js" @@ -5131,9 +5356,9 @@ } }, "node_modules/rollup": { - "version": "3.20.2", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.20.2.tgz", - "integrity": "sha512-3zwkBQl7Ai7MFYQE0y1MeQ15+9jsi7XxfrqwTb/9EK8D9C9+//EBR4M+CuA1KODRaNbFez/lWxA5vhEGZp4MUg==", + "version": "3.25.3", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.25.3.tgz", + "integrity": "sha512-ZT279hx8gszBj9uy5FfhoG4bZx8c+0A1sbqtr7Q3KNWIizpTdDEPZbV2xcbvHsnFp4MavCQYZyzApJ+virB8Yw==", "dev": true, "bin": { "rollup": "dist/bin/rollup" @@ -5286,9 +5511,9 @@ } }, "node_modules/shiki": { - "version": "0.14.1", - "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.14.1.tgz", - "integrity": "sha512-+Jz4nBkCBe0mEDqo1eKRcCdjRtrCjozmcbTUjbPTX7OOJfEbTZzlUWlZtGe3Gb5oV1/jnojhG//YZc3rs9zSEw==", + "version": "0.14.3", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.14.3.tgz", + "integrity": "sha512-U3S/a+b0KS+UkTyMjoNojvTgrBHjgp7L6ovhFVZsXmBGnVdQ4K4U9oK0z63w538S91ATngv1vXigHCSWOwnr+g==", "dev": true, "dependencies": { "ansi-sequence-parser": "^1.1.0", @@ -5327,9 +5552,9 @@ } }, "node_modules/smob": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/smob/-/smob-0.0.6.tgz", - "integrity": "sha512-V21+XeNni+tTyiST1MHsa84AQhT1aFZipzPpOFAVB8DkHzwJyjjAmt9bgwnuZiZWnIbMo2duE29wybxv/7HWUw==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/smob/-/smob-1.4.0.tgz", + "integrity": "sha512-MqR3fVulhjWuRNSMydnTlweu38UhQ0HXM4buStD/S3mc/BzX3CuM9OmhyQpmtYCvoYdl5ris6TI0ZqH355Ymqg==", "dev": true }, "node_modules/source-map": { @@ -5384,9 +5609,9 @@ "dev": true }, "node_modules/standard-engine": { - "version": "15.0.0", - "resolved": "https://registry.npmjs.org/standard-engine/-/standard-engine-15.0.0.tgz", - "integrity": "sha512-4xwUhJNo1g/L2cleysUqUv7/btn7GEbYJvmgKrQ2vd/8pkTmN8cpqAZg+BT8Z1hNeEH787iWUdOpL8fmApLtxA==", + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/standard-engine/-/standard-engine-15.1.0.tgz", + "integrity": "sha512-VHysfoyxFu/ukT+9v49d4BRXIokFRZuH3z1VRxzFArZdjSCFpro6rEIU3ji7e4AoAtuSfKBkiOmsrDqKW5ZSRw==", "dev": true, "funding": [ { @@ -5543,6 +5768,24 @@ } }, "node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/string-width-cjs": { + "name": "string-width", "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", @@ -5556,6 +5799,33 @@ "node": ">=8" } }, + "node_modules/string-width-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width-cjs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/string-width-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/string.prototype.matchall": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.8.tgz", @@ -5638,6 +5908,22 @@ } }, "node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", @@ -5649,6 +5935,15 @@ "node": ">=8" } }, + "node_modules/strip-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -5723,13 +6018,13 @@ } }, "node_modules/terser": { - "version": "5.16.9", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.16.9.tgz", - "integrity": "sha512-HPa/FdTB9XGI2H1/keLFZHxl6WNvAI4YalHGtDQTlMnJcoqSab1UwL4l1hGEhs6/GmLHBZIg/YgB++jcbzoOEg==", + "version": "5.18.1", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.18.1.tgz", + "integrity": "sha512-j1n0Ao919h/Ai5r43VAnfV/7azUYW43GPxK7qSATzrsERfW7+y2QW9Cp9ufnRF5CQUWbnLSo7UJokSWCqg4tsQ==", "dev": true, "dependencies": { - "@jridgewell/source-map": "^0.3.2", - "acorn": "^8.5.0", + "@jridgewell/source-map": "^0.3.3", + "acorn": "^8.8.2", "commander": "^2.20.0", "source-map-support": "~0.5.20" }, @@ -5880,9 +6175,9 @@ } }, "node_modules/tslib": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", - "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz", + "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==", "dev": true }, "node_modules/tsutils": { @@ -6192,6 +6487,24 @@ "dev": true }, "node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", @@ -6208,6 +6521,59 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrap-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/wrap-ansi-cjs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -6301,6 +6667,47 @@ "node": ">=10" } }, + "node_modules/yargs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/yargs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/yauzl": { "version": "2.10.0", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", diff --git a/package.json b/package.json index bee773a..1dd40ac 100644 --- a/package.json +++ b/package.json @@ -50,10 +50,26 @@ } }, "./esm-browser-bundle": "./dist/bundle.esm.min.js", + "./dist/bundle.esm.min.js": "./dist/bundle.esm.min.js", "./esm-browser-bundle-nomin": "./dist/bundle.esm.js", + "./dist/bundle.esm.js": "./dist/bundle.esm.js", "./iife-browser-bundle": "./dist/bundle.iife.js", + "./dist/bundle.iife.js": "./dist/bundle.iife.js", "./umd-browser-bundle": "./dist/bundle.umd.js", - "./types": "./dist/index.d.ts" + "./dist/bundle.umd.js": "./dist/bundle.umd.js", + "./dist/index.node": { + "types": "./dist/index.d.ts", + "default": "./dist/index.node.cjs" + }, + "./dist/index.node.esm": { + "types": "./dist/index.d.ts", + "default": "./dist/index.node.esm.js" + }, + "./dist/index.browser.esm": { + "types": "./dist/index.d.ts", + "default": "./dist/index.browser.esm.js" + }, + "./package.json": "./package.json" }, "imports": { "#pkg": { @@ -66,7 +82,7 @@ "default": "./dist/index.node.esm.js" }, "default": { - "types": "./dist/esm/index.d.ts", + "types": "./dist/index.d.ts", "default": "./dist/index.browser.esm.js" } } @@ -135,7 +151,7 @@ } }, "devDependencies": { - "@rollup/plugin-commonjs": "^24.0.1", + "@rollup/plugin-commonjs": "^25.0.2", "@rollup/plugin-inject": "^5.0.3", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-multi-entry": "^6.0.0", @@ -145,7 +161,7 @@ "@rollup/plugin-typescript": "^11.1.0", "@types/chai": "^4.2.22", "@types/mocha": "^10.0.0", - "c8": "^7.12.0", + "c8": "^8.0.0", "chai": "^4.3.3", "dotenv": "^16.0.3", "glob": "^10.0.0", @@ -154,7 +170,7 @@ "mocha": "^10.0.0", "npm-run-all": "^4.1.5", "pirates": "^4.0.1", - "puppeteer": "^19.1.2", + "puppeteer": "^20.7.3", "rimraf": "^5.0.0", "rollup": "^3.20.2", "rollup-plugin-dts": "^5.3.0", diff --git a/src/ts/gcd.ts b/src/ts/gcd.ts index 9a6f683..67e2543 100644 --- a/src/ts/gcd.ts +++ b/src/ts/gcd.ts @@ -1,4 +1,5 @@ import { abs } from './abs.js' + /** * Greatest common divisor of two integers based on the iterative binary algorithm. * diff --git a/src/ts/index.ts b/src/ts/index.ts index c9df863..6b3e726 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -6,11 +6,15 @@ export { abs } from './abs.js' export { bitLength } from './bitLength.js' +export { crt } from './crt.js' export { Egcd, eGcd } from './egcd.js' export { gcd } from './gcd.js' export { lcm } from './lcm.js' export { max } from './max.js' export { min } from './min.js' +export { modAdd } from './modAdd.js' export { modInv } from './modInv.js' -export { modPow } from './modPow.js' +export { modMultiply } from './modMultiply.js' +export { PrimeFactor, PrimePower, modPow } from './modPow.js' +export { PrimeFactorization, phi } from './phi.js' export { toZn } from './toZn.js' diff --git a/src/ts/lcm.ts b/src/ts/lcm.ts index 4eb19c7..0df277b 100644 --- a/src/ts/lcm.ts +++ b/src/ts/lcm.ts @@ -1,5 +1,6 @@ import { abs } from './abs.js' import { gcd } from './gcd.js' + /** * The least common multiple computed as abs(a*b)/gcd(a,b) * @param a diff --git a/src/ts/modInv.ts b/src/ts/modInv.ts index abf299b..aed4bd9 100644 --- a/src/ts/modInv.ts +++ b/src/ts/modInv.ts @@ -1,5 +1,6 @@ import { eGcd } from './egcd.js' import { toZn } from './toZn.js' + /** * Modular inverse. * diff --git a/src/ts/modPow.ts b/src/ts/modPow.ts index 96ae152..4e067cc 100644 --- a/src/ts/modPow.ts +++ b/src/ts/modPow.ts @@ -1,18 +1,25 @@ import { abs } from './abs.js' +import { crt } from './crt.js' import { modInv } from './modInv.js' +import { PrimeFactorization, phi } from './phi.js' import { toZn } from './toZn.js' + +export type PrimePower = [number | bigint, number | bigint] // [p, k] is for p**k +export type PrimeFactor = number | bigint | PrimePower + /** - * Modular exponentiation b**e mod n. Currently using the right-to-left binary method + * 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 */ -export function modPow (b: number | bigint, e: number | bigint, n: number | bigint): bigint { +export function modPow (b: number | bigint, e: number | bigint, n: number | bigint, primeFactorization?: PrimeFactor[]): bigint { if (typeof b === 'number') b = BigInt(b) if (typeof e === 'number') e = BigInt(e) if (typeof n === 'number') n = BigInt(n) @@ -26,7 +33,11 @@ export function modPow (b: number | bigint, e: number | bigint, n: number | bigi b = toZn(b, n) if (e < 0n) { - return modInv(modPow(b, abs(e), n), n) + return modInv(modPow(b, abs(e), n, primeFactorization), n) + } + + if (primeFactorization !== undefined) { + return modPowWithFactorization(b, e, n, primePowerArguments(primeFactorization)) } let r = 1n @@ -39,3 +50,39 @@ export function modPow (b: number | bigint, e: number | bigint, n: number | bigi } return r } + +function primePowerArguments (primeFactors: PrimeFactor[]): PrimeFactorization { + interface PrimePowers { + [p: string]: { + p: bigint + k: bigint + } + } + const primePowers: PrimePowers = {} + primeFactors.forEach((primeFactor: PrimeFactor) => { + if (typeof primeFactor === 'bigint' || typeof primeFactor === 'number') { + const key = String(primeFactor) + if (primePowers[key] === undefined) { + primePowers[key] = { p: BigInt(primeFactor), k: 1n } + } else { + primePowers[key].k += 1n + } + } else { + const key = String(primeFactor[0]) + if (primePowers[key] === undefined) { + primePowers[key] = { p: BigInt(primeFactor[0]), k: BigInt(primeFactor[1]) } + } else { + primePowers[key].k += BigInt(primeFactor[1]) + } + } + }) + return Object.values(primePowers).map(val => [val.p, val.k]) +} + +function modPowWithFactorization (b: bigint, e: bigint, n: bigint, primeFactorization: PrimeFactorization): bigint { + const mods = primeFactorization.map(v => v[0] ** v[1]) + const phis = primeFactorization.map(v => phi([v])) + const remainders = phis.map((phi, i) => modPow(b, e % phi, mods[i])) + + return crt(remainders, mods, n) +} diff --git a/test/modPow.ts b/test/modPow.ts index b55188c..27eabfb 100644 --- a/test/modPow.ts +++ b/test/modPow.ts @@ -24,13 +24,58 @@ describe('modPow', function () { a: 2, b: BigInt(255), n: BigInt(64), - modPow: BigInt(0) + modPow: BigInt(0), + factorization: [ + [2n, 6n] as [bigint, bigint] + ] }, { a: BigInt(3), b: BigInt(3), n: BigInt(25), modPow: BigInt(2) + }, + { + a: 1245124521461246134613464612465425n, + b: 9861532432154028374523497086414586n, + n: 500153323344587826888856848415851710985056973082286918972465210560564286327935715658989361814629267526408365126549790626298674370641919299205366510873756645480988096218726721049169354944272728793562147809267541398194457197043260189n, + modPow: 240451691789770161942445790505417018856065097712648273113407316782091824158551945401793333941917448724323499865320019414055693250255681376010258044942735855039307823617978628203426153507803442305305788129411652227222626528677503357n, + factorization: [ + 218230499735828681265329912048785421189n, + 303663914757588658442322995331731552767n, + 330074629227155283615948126790169269393n, + 318474781297924758545194431666113118619n, + 258866136593300047022978927175555617677n, + 277352503791024309522752317490262967817n + ] + }, + { + a: 14, + b: 7, + n: 75, + modPow: (14n ** 7n) % 75n, + factorization: [5, 5, 3] + }, + { + a: 14, + b: 7, + n: 75, + modPow: (14n ** 7n) % 75n, + factorization: [ + [5, 2], + [3, 1] + ] as Array<[number, number]> + }, + { + a: 14, + b: 7, + n: 75, + modPow: (14n ** 7n) % 75n, + factorization: [ + [5, 1], + [5, 1], + [3, 1] + ] as Array<[number, number]> } ] const invalidInputs = [ @@ -49,6 +94,14 @@ describe('modPow', function () { chai.expect(String(ret)).to.equal(String(input.modPow)) }) }) + if (input.factorization !== undefined) { + describe(`modPow(${input.a}, ${input.b}, ${input.n}, ${input.factorization.toString()})`, function () { + it(`should return ${input.modPow}`, function () { + const ret = bma.modPow(input.a, input.b, input.n, input.factorization) + chai.expect(String(ret)).to.equal(String(input.modPow)) + }) + }) + } } for (const input of invalidInputs) { describe(`modPow(${input.a}, ${input.b}, ${input.n})`, function () { @@ -63,15 +116,37 @@ describe('modPow', function () { }) } describe('Time profiling', function () { - let iterations = 500 - it(`just testing ${iterations} iterations of a big modular exponentiation (1024 bits)`, function () { - const p = BigInt('103920301461718841589267304263845359224454055603847417021399996422142529929535423886894599506329362009085557636432288745748144369296043048325513558512136442971686130986388589421125262751724362880217790112013162815676017250234401214198365302142787009943498370856167174244675719638815809347261773472114842038647') - const b = BigInt('313632271690673451924314047671460131678794095260951233878123501752357966284491455239133687519908410656818506813151659324961829045286402303082891913186909806785080978448037486178337722667190743610785429936585699831407575170854873682955317589189564880931807976657385223632835801016017549762825562427694700595') - const e = BigInt('452149997592306202232720864363485824701879487303880767747217308770351197801836846325633986474037061753983278534192061455638289551714281047915315943771002615269860312318606105460307037327329178890486613832051027105330475852552183444938408408863970975090778239473049899109989825645608770309107015209564444316') + let iterations = 200 + it(`just testing ${iterations} iterations of a big modular exponentiation (2556 bits) without knowing the factorization`, function () { + const b = 14456431150320172221616509514915526986361238106327826551303073486525612767865296230128540157601034246266893020552680362383297675100669325175361571346279322237329539671666972989978592763343703141198972640627941866075477300010699834312750158094259287059018038648351844386887485449450696346016139524199689991349708808322654998848805208669420846568444495238595132694793197702398883664520354286998606227508937724093725751362231924270085297872354786607945787781132474291940577910417557559293025781300297297108502666688221522472289490235815670978276613741134646350434101590756987811531081642032408524942596500338402454466381n + const e = 6476828424489334540282736436237684965801863681796103123350476262449294411071194504043425154023126089205310946452545492503146985930350204469300515359582715304152166280054365341048395809786334314857324636363499307693460463510288529968621389225833525926438586030988343742064052508822378379640511991190252363284703683198952353035019752852304188032580325320976126425473699273404534699914473174622613565918567472049036606462965033376292343629368800907251671928637057211397168781968913665986137146419257679003630816671501426427417948524164164352320112674416922816719009895345189205426946805834621054179616261802871233808542n + const p = 14042712215688595888153548037889265603500445396639048834534593945467996508131090693365705725532399000992101105698944349047255173597667719370418259169482368508397450171314103850946590710597528264317201250415269575297721977669910571659769606054734401815045082525419212665804298903457270476082779587884970903510490346851467622773314340966549056833592925777140709340896303359906331395892064520612544700229681757412030739888382792194999476266900467607277786534152843408108882693507381781909441777014175765880808549111456404523289456415574592100070259890096499076724913855490255757168221008761519287520710678016476002003203122666993484494111951001896014648841958164118312595430383512299989338389906619375114947097244226374433271798549164684597345168487916487128962249635970759n while (iterations > 0) { bma.modPow(b, e, p) iterations-- } }) + let iterations2 = 200 + it(`just testing ${iterations2} iterations of a big modular exponentiation (2556 bits) knowing the factorization`, function () { + const b = 14456431150320172221616509514915526986361238106327826551303073486525612767865296230128540157601034246266893020552680362383297675100669325175361571346279322237329539671666972989978592763343703141198972640627941866075477300010699834312750158094259287059018038648351844386887485449450696346016139524199689991349708808322654998848805208669420846568444495238595132694793197702398883664520354286998606227508937724093725751362231924270085297872354786607945787781132474291940577910417557559293025781300297297108502666688221522472289490235815670978276613741134646350434101590756987811531081642032408524942596500338402454466381n + const e = 6476828424489334540282736436237684965801863681796103123350476262449294411071194504043425154023126089205310946452545492503146985930350204469300515359582715304152166280054365341048395809786334314857324636363499307693460463510288529968621389225833525926438586030988343742064052508822378379640511991190252363284703683198952353035019752852304188032580325320976126425473699273404534699914473174622613565918567472049036606462965033376292343629368800907251671928637057211397168781968913665986137146419257679003630816671501426427417948524164164352320112674416922816719009895345189205426946805834621054179616261802871233808542n + const p = 14042712215688595888153548037889265603500445396639048834534593945467996508131090693365705725532399000992101105698944349047255173597667719370418259169482368508397450171314103850946590710597528264317201250415269575297721977669910571659769606054734401815045082525419212665804298903457270476082779587884970903510490346851467622773314340966549056833592925777140709340896303359906331395892064520612544700229681757412030739888382792194999476266900467607277786534152843408108882693507381781909441777014175765880808549111456404523289456415574592100070259890096499076724913855490255757168221008761519287520710678016476002003203122666993484494111951001896014648841958164118312595430383512299989338389906619375114947097244226374433271798549164684597345168487916487128962249635970759n + const factorization = [ + 64735041287835073339645110378796758902638279101014381826528695387496122442691n, + 100608456040189246257906094489725850536673092825529567729728751391736301991369n, + 58992718408385655584411200892712190864864350334099743757220725378063820240657n, + 96562131825975924912838022675233698320760586729314385931723127363428962983247n, + 68620104844493133229164822823175832794894654493599547904820655831878232061531n, + 71474468886948151751742173259692288576445414562898468020644046548578552084431n, + 96793884673833556249816099345608529931050134280462961194018209385115828684189n, + 94085307601549784597508419912586171618182711224796241928810495401174923988119n, + 91841918562944515248478087657554520191420619060733607414018266296555587309041n, + 92269642318171922312931975258187595106742943586895754768486213552371747180589n + ] + while (iterations2 > 0) { + bma.modPow(b, e, p, factorization) + iterations2-- + } + }) }) })