better support for exports. fixed issue with workers with ESM version

This commit is contained in:
juanelas 2023-04-13 19:33:52 +02:00
parent 9ebe60d7ee
commit f4ea3d50cc
21 changed files with 308 additions and 1020 deletions

View File

@ -40,7 +40,7 @@ The appropriate version for browser or node is automatically exported.
> 1. If you experience issues using webpack/babel to create your production bundles, you may edit the supported browsers list and leave only [supported browsers and versions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility). The browsers list is usually located in your project's `package.json` or the `.browserslistrc` file.
> 2. In order to use `bigint-crypto-utils` with TypeScript you need to set `target`, and `lib` and `module` if in use, to `ES2020` in your project's `tsconfig.json`.
You can also download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/main/dist/bundles/iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/main/dist/bundles/esm.min.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/main/dist/bundles/umd.js) and manually add it to your project, or, if you have already installed `bigint-crypto-utils` in your project, just get the bundles from `node_modules/bigint-crypto-utils/dist/bundles/`.
You can also download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/main/dist/bundle.iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/main/dist/bundle.esm.min.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/main/dist/bundle.umd.js) and manually add it to your project, or, if you have already installed `bigint-crypto-utils` in your project, just get the bundles from `node_modules/bigint-crypto-utils/dist/bundles/`.
An example of usage could be (complete examples can be found in the [examples](https://github.com/juanelas/bigint-crypto-utils/tree/master/examples) directory):

View File

@ -2,7 +2,7 @@
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const minimatch = require('minimatch')
const minimatch = require('minimatch').minimatch
const rimraf = require('rimraf')
const runScript = require('../run-script.cjs')

View File

@ -1,4 +1,4 @@
import { mkdirSync, readFileSync, writeFileSync } from 'fs'
import { mkdirSync, writeFileSync } from 'fs'
import ts from 'typescript'
import { join, dirname, extname } from 'path'
import { sync } from 'rimraf'
@ -8,9 +8,7 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const { readJsonConfigFile, sys, parseJsonSourceFileConfigFileContent, createCompilerHost, createProgram } = ts
const rootDir = join(__dirname, '..')
const pkgJson = JSON.parse(readFileSync(join(rootDir, 'package.json')))
const srcFile = join(rootDir, 'src/ts/index.ts')
const outDir = dirname(join(rootDir, pkgJson.types))
const tsConfigPath = join(rootDir, 'tsconfig.json')
@ -20,31 +18,31 @@ const configFile = readJsonConfigFile(tsConfigPath, (file) => {
const tsConfig = parseJsonSourceFileConfigFileContent(configFile, sys, dirname(tsConfigPath))
const compilerOptions = {
...tsConfig.options,
declaration: true,
declarationMap: true,
emitDeclarationOnly: true,
outDir
}
const host = createCompilerHost(compilerOptions)
host.writeFile = (fileName, contents) => {
mkdirSync(dirname(fileName), { recursive: true })
writeFileSync(fileName, contents)
// we also write the .d.cts types
let fileName2 = ''
if (extname(fileName) === '.ts') {
fileName2 = fileName.slice(0, -2) + 'cts'
} else { // ext is .d.ts.map
fileName2 = fileName.slice(0, -6) + 'cts.map'
export const compile = (outDir) => {
const compilerOptions = {
...tsConfig.options,
declaration: true,
declarationMap: true,
emitDeclarationOnly: true,
outDir
}
const host = createCompilerHost(compilerOptions)
host.writeFile = (fileName, contents) => {
mkdirSync(dirname(fileName), { recursive: true })
writeFileSync(fileName, contents)
// we also write the .d.cts types
let fileName2 = ''
if (extname(fileName) === '.ts') {
fileName2 = fileName.slice(0, -2) + 'cts'
} else { // ext is .d.ts.map
fileName2 = fileName.slice(0, -6) + 'cts.map'
}
writeFileSync(fileName2, contents)
}
writeFileSync(fileName2, contents)
}
export const compile = () => {
// Clear the types dir
sync(outDir)
// Prepare and emit the d.ts files

View File

@ -1,17 +1,16 @@
'use strict'
import commonjs from '@rollup/plugin-commonjs'
import inject from '@rollup/plugin-inject'
import json from '@rollup/plugin-json'
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import typescriptPlugin from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import { dirname, join } from 'path'
import rollupPluginTs from '@rollup/plugin-typescript'
import { existsSync, readFileSync } from 'fs'
// import { browser, name as _name, exports } from '../package.json' assert { type: 'json' }
import { builtinModules } from 'module'
import { join } from 'path'
import dts from 'rollup-plugin-dts'
import { compile } from './rollup-plugin-dts.js'
import * as url from 'url'
@ -19,9 +18,11 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const rootDir = join(__dirname, '..')
const pkgJson = JSON.parse(readFileSync(join(rootDir, 'package.json')))
// const dstDir = join(rootDir, directories.dist)
const pkgJsonLock = JSON.parse(readFileSync(join(rootDir, 'package-lock.json')))
const srcDir = join(rootDir, 'src', 'ts')
const tsConfigPath = join(rootDir, 'tsconfig.json')
function camelise (str) {
return str.replace(/-([a-z])/g,
function (m, w) {
@ -29,6 +30,11 @@ function camelise (str) {
})
}
function isDevDependency (moduleName) {
const packageEntry = pkgJsonLock.packages['node_modules/' + moduleName]
return (packageEntry ?? {}).dev === true
}
const regex = /^(?:(?<scope>@.*?)\/)?(?<name>.*)/ // We are going to take only the package name part if there is a scope, e.g. @my-org/package-name
const { name } = pkgJson.name.match(regex).groups
const pkgCamelisedName = camelise(name)
@ -36,9 +42,9 @@ const pkgCamelisedName = camelise(name)
const input = join(srcDir, 'index.ts')
if (existsSync(input) !== true) throw new Error('The entry point should be index.ts')
const tsBundleOptions = {
tsconfig: join(rootDir, 'tsconfig.json'),
outDir: undefined, // ignore outDir in tsconfig.json
const tsPluginOptions = {
tsconfig: tsConfigPath,
outDir: undefined,
include: ['src/ts/**/*', 'build/typings/is-browser.d.ts'],
exclude: ['src/**/*.spec.ts']
}
@ -48,23 +54,47 @@ const sourcemapOutputOptions = {
sourcemapExcludeSources: true
}
function compileDts () {
function compileDts (outDir) {
return {
name: 'compile-dts',
closeBundle () {
compile()
compile(outDir)
}
}
}
function resolveOnly (module) { // if a dev dependency is imported we will resolve it so that the dist modules always work
const moduleNameMatch = module.match(/^(?:@[a-z0-9_-]+\/)?(?:node:)?[a-z0-9_-]+/)
if (moduleNameMatch === null || moduleNameMatch.length !== 1) {
return false
}
const moduleName = moduleNameMatch[0].replace(/^node:/, '')
// don't resolve if it is a native module
if (builtinModules.includes(moduleName)) {
return false
}
if (isDevDependency(moduleName)) {
console.warn(`\x1b[33m⚠ WARM: dev dependency \x1b[0m${module}\x1b[33m being bundled. Should it be a dependency instead?\x1b[0m`)
return true
}
return false
}
const tmpDeclarationsDir = join(rootDir, '.types')
export default [
{ // Browser ESM bundle
{ // Browser ESM
input,
output: [
{
file: join(rootDir, pkgJson.browser),
file: join(rootDir, pkgJson.exports['.'].default.default),
...sourcemapOutputOptions,
format: 'es'
format: 'es',
plugins: [
terser()
]
}
],
plugins: [
@ -73,14 +103,15 @@ export default [
_MODULE_TYPE: "'ESM'",
preventAssignment: true
}),
typescriptPlugin(tsBundleOptions),
rollupPluginTs(tsPluginOptions),
commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }),
json(),
resolve({
browser: true,
exportConditions: ['browser', 'default'],
mainFields: ['browser', 'module', 'main']
}),
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
json()
mainFields: ['browser', 'module', 'main'],
resolveOnly
})
]
},
{ // Browser bundles
@ -114,17 +145,13 @@ export default [
_MODULE_TYPE: "'BUNDLE'",
preventAssignment: true
}),
typescriptPlugin({
...tsBundleOptions,
rollupPluginTs({
...tsPluginOptions,
sourceMap: false
}),
resolve({
browser: true,
exportConditions: ['browser', 'default'],
mainFields: ['browser', 'module', 'main']
}),
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
json()
commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }),
json(),
resolve({ browser: true })
]
},
{ // Node CJS
@ -151,16 +178,16 @@ export default [
_MODULE_TYPE: "'CJS'",
preventAssignment: true
}),
rollupPluginTs(tsPluginOptions),
inject({
crypto: ['crypto', 'webcrypto']
}),
typescriptPlugin(tsBundleOptions),
commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }),
json(),
resolve({
browser: false,
exportConditions: ['require', 'node', 'module']
}),
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
json()
exportConditions: ['node'],
resolveOnly
})
]
},
{ // Node ESM and type declarations
@ -179,21 +206,37 @@ export default [
replace({
IS_BROWSER: false,
_MODULE_TYPE: "'ESM'",
__filename: `'${pkgJson.exports['.'].node.import.default}'`,
__dirname: `'${dirname(pkgJson.exports['.'].node.import.default)}'`,
__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']
}),
typescriptPlugin(tsBundleOptions),
commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }),
json(),
resolve({
browser: false,
exportConditions: ['node', 'import']
}),
compileDts(),
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
json()
exportConditions: ['node'],
resolveOnly
})
]
},
{
input: join(tmpDeclarationsDir, 'index.d.ts'),
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [
dts({
respectExternal: true
})
],
external: (module) => {
if (/^[./]/.test(module)) {
return false
}
return !resolveOnly(module)
}
}
]

View File

@ -1,7 +1,7 @@
const path = require('path')
const puppeteer = require('puppeteer')
const minimatch = require('minimatch')
const minimatch = require('minimatch').minimatch
const glob = require('glob')
const rootDir = path.join(__dirname, '../../..')
const pkgJson = require(path.join(rootDir, 'package.json'))

View File

@ -60,24 +60,20 @@ async function buildTests (testFiles) {
input: testFiles,
plugins: [
multi(),
replace({
'#pkg': `/${name}.esm.js`,
delimiters: ['', ''],
preventAssignment: true
}),
replace({
IS_BROWSER: true,
_MODULE_TYPE: "'ESM'",
preventAssignment: true
}),
typescriptPlugin(tsBundleOptions),
resolve({
browser: true,
exportConditions: ['browser', 'default'],
mainFields: ['browser', 'module', 'main']
}),
commonjs(),
json()
commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }),
json(),
resolve({ browser: true }),
replace({
'#pkg': `/${name}.esm.js`,
delimiters: ['', ''],
preventAssignment: true
})
],
external: [`/${name}.esm.js`]
}

View File

@ -1,147 +1,4 @@
function abs(a) {
return (a >= 0) ? a : -a;
}
function bitLength(a) {
if (typeof a === 'number')
a = BigInt(a);
if (a === 1n) {
return 1;
}
let bits = 1;
do {
bits++;
} while ((a >>= 1n) > 1n);
return bits;
}
function eGcd(a, b) {
if (typeof a === 'number')
a = BigInt(a);
if (typeof b === 'number')
b = BigInt(b);
if (a <= 0n || b <= 0n)
throw new RangeError('a and b MUST be > 0');
let x = 0n;
let y = 1n;
let u = 1n;
let v = 0n;
while (a !== 0n) {
const q = b / a;
const r = b % a;
const m = x - (u * q);
const n = y - (v * q);
b = a;
a = r;
x = u;
y = v;
u = m;
v = n;
}
return {
g: b,
x,
y
};
}
function gcd(a, b) {
let aAbs = (typeof a === 'number') ? BigInt(abs(a)) : abs(a);
let bAbs = (typeof b === 'number') ? BigInt(abs(b)) : abs(b);
if (aAbs === 0n) {
return bAbs;
}
else if (bAbs === 0n) {
return aAbs;
}
let shift = 0n;
while (((aAbs | bAbs) & 1n) === 0n) {
aAbs >>= 1n;
bAbs >>= 1n;
shift++;
}
while ((aAbs & 1n) === 0n)
aAbs >>= 1n;
do {
while ((bAbs & 1n) === 0n)
bAbs >>= 1n;
if (aAbs > bAbs) {
const x = aAbs;
aAbs = bAbs;
bAbs = x;
}
bAbs -= aAbs;
} while (bAbs !== 0n);
return aAbs << shift;
}
function lcm(a, b) {
if (typeof a === 'number')
a = BigInt(a);
if (typeof b === 'number')
b = BigInt(b);
if (a === 0n && b === 0n)
return BigInt(0);
return abs((a / gcd(a, b)) * b);
}
function max(a, b) {
return (a >= b) ? a : b;
}
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 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 modPow(b, e, n) {
if (typeof b === 'number')
b = BigInt(b);
if (typeof e === 'number')
e = BigInt(e);
if (typeof n === 'number')
n = BigInt(n);
if (n <= 0n) {
throw new RangeError('n must be > 0');
}
else if (n === 1n) {
return 0n;
}
b = toZn(b, n);
if (e < 0n) {
return modInv(modPow(b, abs(e), n), n);
}
let r = 1n;
while (e > 0) {
if ((e % 2n) === 1n) {
r = r * b % n;
}
e = e / 2n;
b = b ** 2n % n;
}
return r;
}
function n(n){return n>=0?n:-n}function t(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++;}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,e=1n,o=1n,u=0n;for(;0n!==n;){const i=t/n,f=t%n,g=r-o*i,b=e-u*i;t=n,n=f,r=o,e=u,o=g,u=b;}return {g:t,x:r,y:e}}function e(t,r){let e="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof r?BigInt(n(r)):n(r);if(0n===e)return o;if(0n===o)return e;let u=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,u++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){const n=e;e=o,o=n;}o-=e;}while(0n!==o);return e<<u}function o(t,r){return "number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),0n===t&&0n===r?BigInt(0):n(t/e(t,r)*r)}function u(n,t){return n>=t?n:t}function i(n,t){return n>=t?t:n}function f(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const r=n%t;return r<0n?r+t:r}function g(n,t){const e=r(f(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return f(e.x,t)}function b(t,r,e){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),"number"==typeof e&&(e=BigInt(e)),e<=0n)throw new RangeError("n must be > 0");if(1n===e)return 0n;if(t=f(t,e),r<0n)return g(b(t,n(r),e),e);let o=1n;for(;r>0;)r%2n===1n&&(o=o*t%e),r/=2n,t=t**2n%e;return o}
function fromBuffer(buf) {
let ret = 0n;
@ -233,7 +90,7 @@ function randBetween(max, min = 1n) {
if (max <= min)
throw new RangeError('Arguments MUST be: max > min');
const interval = max - min;
const bitLen = bitLength(interval);
const bitLen = t(interval);
let rnd;
do {
const buf = randBitsSync(bitLen);
@ -555,13 +412,13 @@ function _isProbablyPrime(w, iterations) {
}
const m = d / (2n ** a);
do {
const b = randBetween(d, 2n);
let z = modPow(b, m, w);
const b$1 = randBetween(d, 2n);
let z = b(b$1, m, w);
if (z === 1n || z === d)
continue;
let j = 1;
while (j < a) {
z = modPow(z, 2n, w);
z = b(z, 2n, w);
if (z === d)
break;
if (z === 1n)
@ -576,15 +433,15 @@ function _isProbablyPrime(w, iterations) {
function _isProbablyPrimeWorkerUrl() {
let workerCode = `
'use strict';
const ${eGcd.name} = ${eGcd.toString()};
const ${modInv.name} = ${modInv.toString()};
const ${modPow.name} = ${modPow.toString()};
const ${toZn.name} = ${toZn.toString()};
const ${r.name} = ${r.toString()};
const ${g.name} = ${g.toString()};
const ${b.name} = ${b.toString()};
const ${f.name} = ${f.toString()};
const ${randBitsSync.name} = ${randBitsSync.toString()};
const ${randBytesSync.name} = ${randBytesSync.toString()};
const ${randBetween.name} = ${randBetween.toString()};
const ${isProbablyPrime.name} = ${_isProbablyPrime.toString()};
${bitLength.toString()};
${t.toString()};
${fromBuffer.toString()};`;
workerCode += `
onmessage = async function(msg) {
@ -673,4 +530,4 @@ function primeSync(bitLength, iterations = 16) {
return rnd;
}
export { abs, bitLength, eGcd, gcd, isProbablyPrime, lcm, max, min, modInv, modPow, prime, primeSync, randBetween, randBits, randBitsSync, randBytes, randBytesSync, toZn };
export { n as abs, t as bitLength, r as eGcd, e as gcd, isProbablyPrime, o as lcm, u as max, i as min, g as modInv, b as modPow, prime, primeSync, randBetween, randBits, randBitsSync, randBytes, randBytesSync, f as toZn };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/index.browser.esm.js vendored Normal file

File diff suppressed because one or more lines are too long

40
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,40 @@
/// <reference types="node" />
declare function abs(a: number | bigint): number | bigint;
declare function bitLength(a: number | bigint): number;
interface Egcd {
g: bigint;
x: bigint;
y: bigint;
}
declare function eGcd(a: number | bigint, b: number | bigint): Egcd;
declare function gcd(a: number | bigint, b: number | bigint): bigint;
declare function lcm(a: number | bigint, b: number | bigint): bigint;
declare function max(a: number | bigint, b: number | bigint): number | bigint;
declare function min(a: number | bigint, b: number | bigint): number | 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 toZn(a: number | bigint, n: number | bigint): bigint;
declare function isProbablyPrime(w: number | bigint, iterations?: number, disableWorkers?: boolean): Promise<boolean>;
declare function prime(bitLength: number, iterations?: number): Promise<bigint>;
declare function primeSync(bitLength: number, iterations?: number): bigint;
declare function randBetween(max: bigint, min?: bigint): bigint;
declare function randBits(bitLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
declare function randBitsSync(bitLength: number, forceLength?: boolean): Uint8Array | Buffer;
declare function randBytes(byteLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
declare function randBytesSync(byteLength: number, forceLength?: boolean): Uint8Array | Buffer;
export { abs, bitLength, eGcd, gcd, isProbablyPrime, lcm, max, min, modInv, modPow, prime, primeSync, randBetween, randBits, randBitsSync, randBytes, randBytesSync, toZn };

2
dist/index.node.cjs vendored Normal file

File diff suppressed because one or more lines are too long

2
dist/index.node.esm.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -41,7 +41,7 @@
#### Defined in
node_modules/bigint-mod-arith/types/abs.d.ts:1
node_modules/bigint-mod-arith/dist/index.d.ts:1
___
@ -61,7 +61,7 @@ ___
#### Defined in
node_modules/bigint-mod-arith/types/bitLength.d.ts:1
node_modules/bigint-mod-arith/dist/index.d.ts:3
___
@ -82,7 +82,7 @@ ___
#### Defined in
node_modules/bigint-mod-arith/types/egcd.d.ts:6
node_modules/bigint-mod-arith/dist/index.d.ts:10
___
@ -103,7 +103,7 @@ ___
#### Defined in
node_modules/bigint-mod-arith/types/gcd.d.ts:1
node_modules/bigint-mod-arith/dist/index.d.ts:12
___
@ -134,7 +134,7 @@ A promise that resolves to a boolean that is either true (a probably prime numbe
#### Defined in
[src/ts/isProbablyPrime.ts:20](https://github.com/juanelas/bigint-crypto-utils/blob/8f2c2a5/src/ts/isProbablyPrime.ts#L20)
[src/ts/isProbablyPrime.ts:20](https://github.com/juanelas/bigint-crypto-utils/blob/9ebe60d/src/ts/isProbablyPrime.ts#L20)
___
@ -155,7 +155,7 @@ ___
#### Defined in
node_modules/bigint-mod-arith/types/lcm.d.ts:1
node_modules/bigint-mod-arith/dist/index.d.ts:14
___
@ -176,7 +176,7 @@ ___
#### Defined in
node_modules/bigint-mod-arith/types/max.d.ts:1
node_modules/bigint-mod-arith/dist/index.d.ts:16
___
@ -197,7 +197,7 @@ ___
#### Defined in
node_modules/bigint-mod-arith/types/min.d.ts:1
node_modules/bigint-mod-arith/dist/index.d.ts:18
___
@ -218,7 +218,7 @@ ___
#### Defined in
node_modules/bigint-mod-arith/types/modInv.d.ts:1
node_modules/bigint-mod-arith/dist/index.d.ts:20
___
@ -240,7 +240,7 @@ ___
#### Defined in
node_modules/bigint-mod-arith/types/modPow.d.ts:1
node_modules/bigint-mod-arith/dist/index.d.ts:22
___
@ -273,7 +273,7 @@ A promise that resolves to a bigint probable prime of bitLength bits.
#### Defined in
[src/ts/prime.ts:28](https://github.com/juanelas/bigint-crypto-utils/blob/8f2c2a5/src/ts/prime.ts#L28)
[src/ts/prime.ts:28](https://github.com/juanelas/bigint-crypto-utils/blob/9ebe60d/src/ts/prime.ts#L28)
___
@ -303,7 +303,7 @@ A bigint probable prime of bitLength bits.
#### Defined in
[src/ts/prime.ts:109](https://github.com/juanelas/bigint-crypto-utils/blob/8f2c2a5/src/ts/prime.ts#L109)
[src/ts/prime.ts:109](https://github.com/juanelas/bigint-crypto-utils/blob/9ebe60d/src/ts/prime.ts#L109)
___
@ -332,7 +332,7 @@ A cryptographically secure random bigint between [min,max]
#### Defined in
[src/ts/randBetween.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/8f2c2a5/src/ts/randBetween.ts#L14)
[src/ts/randBetween.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/9ebe60d/src/ts/randBetween.ts#L14)
___
@ -361,7 +361,7 @@ A Promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cry
#### Defined in
[src/ts/randBits.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/8f2c2a5/src/ts/randBits.ts#L13)
[src/ts/randBits.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/9ebe60d/src/ts/randBits.ts#L13)
___
@ -390,7 +390,7 @@ A Uint8Array/Buffer (Browser/Node.js) filled with cryptographically secure rando
#### Defined in
[src/ts/randBits.ts:43](https://github.com/juanelas/bigint-crypto-utils/blob/8f2c2a5/src/ts/randBits.ts#L43)
[src/ts/randBits.ts:43](https://github.com/juanelas/bigint-crypto-utils/blob/9ebe60d/src/ts/randBits.ts#L43)
___
@ -419,7 +419,7 @@ A promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cry
#### Defined in
[src/ts/randBytes.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/8f2c2a5/src/ts/randBytes.ts#L13)
[src/ts/randBytes.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/9ebe60d/src/ts/randBytes.ts#L13)
___
@ -449,7 +449,7 @@ A UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure rando
#### Defined in
[src/ts/randBytes.ts:54](https://github.com/juanelas/bigint-crypto-utils/blob/8f2c2a5/src/ts/randBytes.ts#L54)
[src/ts/randBytes.ts:54](https://github.com/juanelas/bigint-crypto-utils/blob/9ebe60d/src/ts/randBytes.ts#L54)
___
@ -470,4 +470,4 @@ ___
#### Defined in
node_modules/bigint-mod-arith/types/toZn.d.ts:1
node_modules/bigint-mod-arith/dist/index.d.ts:24

View File

@ -1,4 +1,4 @@
const bigintCryptoUtils = await import('../dist/esm/index.node.js')
import * as bigintCryptoUtils from '#pkg'
// const bigintCryptoUtils = require('bigint-crypto-utils')
/* A BigInt with value 666 can be declared calling the bigint constructor as

123
package-lock.json generated
View File

@ -8,9 +8,6 @@
"name": "bigint-crypto-utils",
"version": "3.2.1",
"license": "MIT",
"dependencies": {
"bigint-mod-arith": "^3.2.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-inject": "^5.0.3",
@ -22,18 +19,20 @@
"@rollup/plugin-typescript": "^11.1.0",
"@types/chai": "^4.2.22",
"@types/mocha": "^10.0.0",
"bigint-mod-arith": "^3.2.1",
"c8": "^7.12.0",
"chai": "^4.3.3",
"dotenv": "^16.0.3",
"glob": "^9.3.4",
"glob": "^10.0.0",
"json5": "^2.2.0",
"minimatch": "^8.0.3",
"minimatch": "^9.0.0",
"mocha": "^10.0.0",
"npm-run-all": "^4.1.5",
"pirates": "^4.0.1",
"puppeteer": "^19.1.2",
"rimraf": "^4.4.1",
"rimraf": "^5.0.0",
"rollup": "^3.20.2",
"rollup-plugin-dts": "^5.3.0",
"ts-standard": "^12.0.2",
"tslib": "^2.3.1",
"typedoc": "~0.23.0",
@ -398,9 +397,9 @@
}
},
"node_modules/@puppeteer/browsers": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-0.4.0.tgz",
"integrity": "sha512-3iB5pWn9Sr55PKKwqFWSWjLsTKCOEhKNI+uV3BZesgXuA3IhsX8I3hW0HI+3ksMIPkh2mVYzKSpvgq3oicjG2Q==",
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-0.4.1.tgz",
"integrity": "sha512-4IICvy1McAkT/HyNZHIs7sp8ngBX1dmO0TPQ+FWq9ATQMqI8p+Ulm5A3kS2wYDh5HDHHkYrrETOu6rlj64VuTw==",
"dev": true,
"dependencies": {
"debug": "4.3.4",
@ -469,9 +468,9 @@
}
},
"node_modules/@rollup/plugin-commonjs": {
"version": "24.0.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-24.0.1.tgz",
"integrity": "sha512-15LsiWRZk4eOGqvrJyu3z3DaBu5BhXIMeWnijSRvd8irrrg9SHpQ1pH+BUK4H6Z9wL9yOxZJMTLU+Au86XHxow==",
"version": "24.1.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-24.1.0.tgz",
"integrity": "sha512-eSL45hjhCWI0jCCXcNtLVqM5N1JlBGvlFfY0m6oOYnLCJ6N0qEXoZql4sY2MOUArzhH4SA/qBpTxvvZp2Sc+DQ==",
"dev": true,
"dependencies": {
"@rollup/pluginutils": "^5.0.1",
@ -1299,9 +1298,10 @@
]
},
"node_modules/bigint-mod-arith": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/bigint-mod-arith/-/bigint-mod-arith-3.2.0.tgz",
"integrity": "sha512-Khb+sLGLqbe/2NOLVMOpCSgsC3lz8r3VIRZGc41hccudLPnvks7RYZNOnGukQZV8scn5+bA6MABga3Ueq6z3+w==",
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/bigint-mod-arith/-/bigint-mod-arith-3.2.1.tgz",
"integrity": "sha512-roLlzeQ0okNjT8Ph9zL9Nvw85ucHSQkNndLRfAR2CVaYOEAMtbpIK3f6oJb3Jv/hg9mkrYaw/DknysTuvc8QhA==",
"dev": true,
"engines": {
"node": ">=10.4.0"
}
@ -2977,15 +2977,15 @@
}
},
"node_modules/glob": {
"version": "9.3.5",
"resolved": "https://registry.npmjs.org/glob/-/glob-9.3.5.tgz",
"integrity": "sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q==",
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-10.0.0.tgz",
"integrity": "sha512-zmp9ZDC6NpDNLujV2W2n+3lH+BafIVZ4/ct+Yj3BMZTH/+bgm/eVjHzeFLwxJrrIGgjjS2eiQLlpurHsNlEAtQ==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"minimatch": "^8.0.2",
"minipass": "^4.2.4",
"path-scurry": "^1.6.1"
"minimatch": "^9.0.0",
"minipass": "^5.0.0",
"path-scurry": "^1.6.4"
},
"engines": {
"node": ">=16 || 14 >=14.17"
@ -3988,9 +3988,9 @@
}
},
"node_modules/minimatch": {
"version": "8.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-8.0.4.tgz",
"integrity": "sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA==",
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.0.tgz",
"integrity": "sha512-0jJj8AvgKqWN05mrwuqi8QYKx1WmYSUoKSxu5Qhs9prezTz10sxAHGNZe9J9cqIJzta8DWsleh2KaVaLl6Ru2w==",
"dev": true,
"dependencies": {
"brace-expansion": "^2.0.1"
@ -4012,9 +4012,9 @@
}
},
"node_modules/minipass": {
"version": "4.2.7",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.7.tgz",
"integrity": "sha512-ScVIgqHcXRMyfflqHmEW0bm8z8rb5McHyOY3ewX9JBgZaR77G7nxq9L/mtV96/QbAAwtbCAHVVLzD1kkyfFQEw==",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz",
"integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==",
"dev": true,
"engines": {
"node": ">=8"
@ -4686,15 +4686,6 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/path-scurry/node_modules/minipass": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz",
"integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/path-type": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz",
@ -4926,27 +4917,27 @@
}
},
"node_modules/puppeteer": {
"version": "19.8.5",
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.8.5.tgz",
"integrity": "sha512-WSjouU7eux6cwBMEz4A7mDRVZWTQQTDXrb1R6AhKDdeEgpiBBkAzcAusPhILxiJOKj60rULZpWuCZ7HZIO6GTA==",
"version": "19.9.0",
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.9.0.tgz",
"integrity": "sha512-JDx8WwGlkdQYTaa3OMYDF+uFWimiwNnacg5FGEC5J6+VxDsLK30wHKU/Db2LqEhtAoIu4RwS+BRH4zRPlCsFpA==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
"@puppeteer/browsers": "0.4.0",
"@puppeteer/browsers": "0.4.1",
"cosmiconfig": "8.1.3",
"https-proxy-agent": "5.0.1",
"progress": "2.0.3",
"proxy-from-env": "1.1.0",
"puppeteer-core": "19.8.5"
"puppeteer-core": "19.9.0"
}
},
"node_modules/puppeteer-core": {
"version": "19.8.5",
"resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.8.5.tgz",
"integrity": "sha512-zoGhim/oBQbkND6h4Xz4X7l5DkWVH9wH7z0mVty5qa/c0P1Yad47t/npVtt2xS10BiQwzztWKx7Pa2nJ5yykdw==",
"version": "19.9.0",
"resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.9.0.tgz",
"integrity": "sha512-IJYfCE0oFpi5dTvNFqOwo8Dey6zzx7hANy7z6K2bjpCux9oPOSOIubq40awNhaHlfi8soYtgU4qabnzMXB7xBQ==",
"dev": true,
"dependencies": {
"@puppeteer/browsers": "0.4.0",
"@puppeteer/browsers": "0.4.1",
"chromium-bidi": "0.4.6",
"cross-fetch": "3.1.5",
"debug": "4.3.4",
@ -5132,12 +5123,12 @@
}
},
"node_modules/rimraf": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.4.1.tgz",
"integrity": "sha512-Gk8NlF062+T9CqNGn6h4tls3k6T1+/nXdOcSZVikNVtlRdYpA7wRJJMoXmuvOnLW844rPjdQ7JgXCYM6PPC/og==",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.0.tgz",
"integrity": "sha512-Jf9llaP+RvaEVS5nPShYFhtXIrb3LRKP281ib3So0KkeZKo2wIKyq0Re7TOSwanasA423PSr6CCIL4bP6T040g==",
"dev": true,
"dependencies": {
"glob": "^9.2.0"
"glob": "^10.0.0"
},
"bin": {
"rimraf": "dist/cjs/src/bin.js"
@ -5165,6 +5156,40 @@
"fsevents": "~2.3.2"
}
},
"node_modules/rollup-plugin-dts": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-5.3.0.tgz",
"integrity": "sha512-8FXp0ZkyZj1iU5klkIJYLjIq/YZSwBoERu33QBDxm/1yw5UU4txrEtcmMkrq+ZiKu3Q4qvPCNqc3ovX6rjqzbQ==",
"dev": true,
"dependencies": {
"magic-string": "^0.30.0"
},
"engines": {
"node": ">=v14"
},
"funding": {
"url": "https://github.com/sponsors/Swatinem"
},
"optionalDependencies": {
"@babel/code-frame": "^7.18.6"
},
"peerDependencies": {
"rollup": "^3.0.0",
"typescript": "^4.1 || ^5.0"
}
},
"node_modules/rollup-plugin-dts/node_modules/magic-string": {
"version": "0.30.0",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.0.tgz",
"integrity": "sha512-LA+31JYDJLs82r2ScLrlz1GjSgu66ZV518eyWT+S8VhyQn/JL0u9MeBOvQMGYiPk1DBiSN9DDMOcXvigJZaViQ==",
"dev": true,
"dependencies": {
"@jridgewell/sourcemap-codec": "^1.4.13"
},
"engines": {
"node": ">=12"
}
},
"node_modules/run-parallel": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",

View File

@ -25,46 +25,50 @@
"node": ">=14.0.0"
},
"type": "module",
"main": "./dist/cjs/index.node.cjs",
"types": "./types/index.d.cts",
"browser": "./dist/esm/index.browser.js",
"module": "./dist/esm/index.node.js",
"main": "./dist/index.node.cjs",
"browser": "./dist/index.browser.esm.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"node": {
"require": {
"default": "./dist/cjs/index.node.cjs",
"types": "./types/index.d.cts"
"module": {
"types": "./dist/index.d.ts",
"default": "./dist/index.node.esm.js"
},
"import": {
"default": "./dist/esm/index.node.js",
"types": "./types/index.d.ts"
"types": "./dist/index.d.ts",
"default": "./dist/index.node.esm.js"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.node.cjs"
}
},
"script": "./dist/bundle.iife.js",
"default": {
"default": "./dist/esm/index.browser.js",
"types": "./types/index.d.ts"
"types": "./dist/index.d.ts",
"default": "./dist/index.browser.esm.js"
}
},
"./esm-browser-bundle": "./dist/bundles/esm.min.js",
"./esm-browser-bundle-nomin": "./dist/bundles/esm.js",
"./iife-browser-bundle": "./dist/bundles/iife.js",
"./umd-browser-bundle": "./dist/bundles/umd.js",
"./types": "./types/index.d.cts"
"./esm-browser-bundle": "./dist/bundle.esm.min.js",
"./esm-browser-bundle-nomin": "./dist/bundle.esm.js",
"./iife-browser-bundle": "./dist/bundle.iife.js",
"./umd-browser-bundle": "./dist/bundle.umd.js",
"./types": "./dist/index.d.ts"
},
"imports": {
"#pkg": {
"require": {
"default": "./dist/cjs/index.node.cjs",
"types": "./types/index.d.cts"
"types": "./dist/index.d.ts",
"default": "./dist/index.node.cjs"
},
"import": {
"default": "./dist/esm/index.node.js",
"types": "./types/index.d.ts"
"types": "./dist/index.d.ts",
"default": "./dist/index.node.esm.js"
},
"default": {
"default": "./dist/esm/index.browser.js",
"types": "./types/index.d.ts"
"types": "./dist/esm/index.d.ts",
"default": "./dist/index.browser.esm.js"
}
}
},
@ -80,7 +84,8 @@
"scripts": {
"build": "run-s lint:src build:js lint:test docs",
"build:js": "rollup -c build/rollup.config.js",
"clean": "rimraf .mocha-ts coverage dist types docs",
"postbuild:js": "rimraf .types",
"clean": "rimraf .mocha-ts coverage dist .types docs",
"coverage": "c8 --clean --check-coverage --exclude \"{src/ts/**/*.spec.ts,test,test-vectors,build}\" --exclude-after-remap --reporter=text --reporter=lcov node ./build/bin/mocha-ts.cjs --commonjs ",
"docs": "node build/build.docs.cjs",
"git:add": "git add -A",
@ -141,25 +146,24 @@
"@rollup/plugin-typescript": "^11.1.0",
"@types/chai": "^4.2.22",
"@types/mocha": "^10.0.0",
"bigint-mod-arith": "^3.2.1",
"c8": "^7.12.0",
"chai": "^4.3.3",
"dotenv": "^16.0.3",
"glob": "^9.3.4",
"glob": "^10.0.0",
"json5": "^2.2.0",
"minimatch": "^8.0.3",
"minimatch": "^9.0.0",
"mocha": "^10.0.0",
"npm-run-all": "^4.1.5",
"pirates": "^4.0.1",
"puppeteer": "^19.1.2",
"rimraf": "^4.4.1",
"rimraf": "^5.0.0",
"rollup": "^3.20.2",
"rollup-plugin-dts": "^5.3.0",
"ts-standard": "^12.0.2",
"tslib": "^2.3.1",
"typedoc": "~0.23.0",
"typedoc-plugin-markdown": "~3.14.0",
"typescript": "^5.0.3"
},
"dependencies": {
"bigint-mod-arith": "^3.2.0"
}
}