browser defaults to a not minified bundle
This commit is contained in:
parent
d7f49502f5
commit
4322e3a862
|
@ -11,7 +11,6 @@ const fs = require('fs')
|
|||
const pkgJson = require('../package.json')
|
||||
|
||||
const rootDir = path.join(__dirname, '..')
|
||||
const dstDir = path.join(rootDir, pkgJson.directories.dist)
|
||||
const srcDir = path.join(rootDir, 'src')
|
||||
|
||||
function camelise (str) {
|
||||
|
@ -40,20 +39,39 @@ const sourcemapOutputOptions = {
|
|||
}
|
||||
|
||||
module.exports = [
|
||||
{ // Browser ESM
|
||||
input: input,
|
||||
output: {
|
||||
file: path.join(rootDir, pkgJson.browser),
|
||||
format: 'es',
|
||||
...sourcemapOutputOptions
|
||||
},
|
||||
plugins: [
|
||||
replace({
|
||||
IS_BROWSER: true,
|
||||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
resolve({ // For the workers to properly load all the functions when minified (e.g. by webpack), bigint-mod-arith should be resolved
|
||||
browser: true,
|
||||
exportConditions: ['browser', 'module', 'import', 'default']
|
||||
})
|
||||
]
|
||||
},
|
||||
{ // Browser bundles
|
||||
input: input,
|
||||
output: [
|
||||
{
|
||||
file: path.join(dstDir, `bundles/${name}.iife.js`),
|
||||
file: path.join(rootDir, pkgJson.exports['./iife-browser-bundle']),
|
||||
format: 'iife',
|
||||
name: pkgCamelisedName
|
||||
},
|
||||
{
|
||||
file: path.join(dstDir, `bundles/${name}.esm.js`),
|
||||
file: path.join(rootDir, pkgJson.exports['./esm-browser-bundle']),
|
||||
format: 'es'
|
||||
},
|
||||
{
|
||||
file: path.join(dstDir, `bundles/${name}.umd.js`),
|
||||
file: path.join(rootDir, pkgJson.exports['./umd-browser-bundle']),
|
||||
format: 'umd',
|
||||
name: pkgCamelisedName
|
||||
}
|
||||
|
@ -110,6 +128,7 @@ module.exports = [
|
|||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
commonjs({ extensions: ['.js', '.ts'] }) // the ".ts" extension is required
|
||||
]
|
||||
],
|
||||
external
|
||||
}
|
||||
]
|
||||
|
|
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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -12,6 +12,6 @@
|
|||
* @returns A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
|
||||
*/
|
||||
export declare function isProbablyPrime(w: number | bigint, iterations?: number, disableWorkers?: boolean): Promise<boolean>;
|
||||
export declare function _isProbablyPrime(w: bigint, iterations?: number): boolean;
|
||||
export declare function _isProbablyPrime(w: bigint, iterations: number): boolean;
|
||||
export declare function _isProbablyPrimeWorkerUrl(): string;
|
||||
//# sourceMappingURL=isProbablyPrime.d.ts.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"isProbablyPrime.d.ts","sourceRoot":"","sources":["../../../../src/ts/isProbablyPrime.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,UAAU,GAAE,MAAW,EAAE,cAAc,GAAE,OAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAqD7H;AAED,wBAAgB,gBAAgB,CAAE,CAAC,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,OAAO,CA0T7E;AAED,wBAAgB,yBAAyB,IAAK,MAAM,CAkBnD"}
|
||||
{"version":3,"file":"isProbablyPrime.d.ts","sourceRoot":"","sources":["../../../../src/ts/isProbablyPrime.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,UAAU,GAAE,MAAW,EAAE,cAAc,GAAE,OAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAqD7H;AAED,wBAAgB,gBAAgB,CAAE,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CA0TxE;AAED,wBAAgB,yBAAyB,IAAK,MAAM,CAOnD"}
|
16
docs/API.md
16
docs/API.md
|
@ -135,7 +135,7 @@ w MUST be >= 0
|
|||
|
||||
A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
|
||||
|
||||
Defined in: [src/ts/isProbablyPrime.ts:21](https://github.com/juanelas/bigint-crypto-utils/blob/8580d40/src/ts/isProbablyPrime.ts#L21)
|
||||
Defined in: [src/ts/isProbablyPrime.ts:21](https://github.com/juanelas/bigint-crypto-utils/blob/d7f4950/src/ts/isProbablyPrime.ts#L21)
|
||||
|
||||
___
|
||||
|
||||
|
@ -275,7 +275,7 @@ bitLength MUST be > 0
|
|||
|
||||
A promise that resolves to a bigint probable prime of bitLength bits.
|
||||
|
||||
Defined in: [src/ts/prime.ts:21](https://github.com/juanelas/bigint-crypto-utils/blob/8580d40/src/ts/prime.ts#L21)
|
||||
Defined in: [src/ts/prime.ts:21](https://github.com/juanelas/bigint-crypto-utils/blob/d7f4950/src/ts/prime.ts#L21)
|
||||
|
||||
___
|
||||
|
||||
|
@ -300,7 +300,7 @@ bitLength MUST be > 0
|
|||
|
||||
A bigint probable prime of bitLength bits.
|
||||
|
||||
Defined in: [src/ts/prime.ts:100](https://github.com/juanelas/bigint-crypto-utils/blob/8580d40/src/ts/prime.ts#L100)
|
||||
Defined in: [src/ts/prime.ts:100](https://github.com/juanelas/bigint-crypto-utils/blob/d7f4950/src/ts/prime.ts#L100)
|
||||
|
||||
___
|
||||
|
||||
|
@ -324,7 +324,7 @@ Arguments MUST be: max > 0 && min >=0 && max > min
|
|||
|
||||
A cryptographically secure random bigint between [min,max]
|
||||
|
||||
Defined in: [src/ts/randBetween.ts:15](https://github.com/juanelas/bigint-crypto-utils/blob/8580d40/src/ts/randBetween.ts#L15)
|
||||
Defined in: [src/ts/randBetween.ts:15](https://github.com/juanelas/bigint-crypto-utils/blob/d7f4950/src/ts/randBetween.ts#L15)
|
||||
|
||||
___
|
||||
|
||||
|
@ -348,7 +348,7 @@ bitLength MUST be > 0
|
|||
|
||||
A Promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bits
|
||||
|
||||
Defined in: [src/ts/randBits.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/8580d40/src/ts/randBits.ts#L14)
|
||||
Defined in: [src/ts/randBits.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/d7f4950/src/ts/randBits.ts#L14)
|
||||
|
||||
___
|
||||
|
||||
|
@ -372,7 +372,7 @@ bitLength MUST be > 0
|
|||
|
||||
A Uint8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bits
|
||||
|
||||
Defined in: [src/ts/randBits.ts:45](https://github.com/juanelas/bigint-crypto-utils/blob/8580d40/src/ts/randBits.ts#L45)
|
||||
Defined in: [src/ts/randBits.ts:45](https://github.com/juanelas/bigint-crypto-utils/blob/d7f4950/src/ts/randBits.ts#L45)
|
||||
|
||||
___
|
||||
|
||||
|
@ -396,7 +396,7 @@ byteLength MUST be > 0
|
|||
|
||||
A promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bytes
|
||||
|
||||
Defined in: [src/ts/randBytes.ts:12](https://github.com/juanelas/bigint-crypto-utils/blob/8580d40/src/ts/randBytes.ts#L12)
|
||||
Defined in: [src/ts/randBytes.ts:12](https://github.com/juanelas/bigint-crypto-utils/blob/d7f4950/src/ts/randBytes.ts#L12)
|
||||
|
||||
___
|
||||
|
||||
|
@ -420,7 +420,7 @@ byteLength MUST be > 0
|
|||
|
||||
A UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bytes
|
||||
|
||||
Defined in: [src/ts/randBytes.ts:46](https://github.com/juanelas/bigint-crypto-utils/blob/8580d40/src/ts/randBytes.ts#L46)
|
||||
Defined in: [src/ts/randBytes.ts:46](https://github.com/juanelas/bigint-crypto-utils/blob/d7f4950/src/ts/randBytes.ts#L46)
|
||||
|
||||
___
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
},
|
||||
"types": "./dist/esm/types/index.d.ts",
|
||||
"main": "./dist/cjs/index.node.cjs",
|
||||
"browser": "./dist/bundles/bigint-crypto-utils.esm.js",
|
||||
"browser": "./dist/esm/index.browser.js",
|
||||
"module": "./dist/esm/index.node.js",
|
||||
"exports": {
|
||||
".": {
|
||||
|
@ -34,12 +34,12 @@
|
|||
"require": "./dist/cjs/index.node.cjs",
|
||||
"import": "./dist/esm/index.node.js"
|
||||
},
|
||||
"default": "./dist/bundles/bigint-crypto-utils.esm.js"
|
||||
"default": "./dist/esm/index.browser.js"
|
||||
},
|
||||
"./esm-browser-bundle": "./dist/bundles/bigint-crypto-utils.esm.js",
|
||||
"./iife-browser-bundle": "./dist/bundles/bigint-crypto-utils.iife.js",
|
||||
"./umd-browser-bundle": "./dist/bundles/bigint-crypto-utils.umd.js",
|
||||
"./types/": "./dist/esm/types/"
|
||||
"./types": "./dist/esm/types/index.d.ts"
|
||||
},
|
||||
"directories": {
|
||||
"build": "./build",
|
||||
|
|
|
@ -2,7 +2,7 @@ export function fromBuffer (buf: Uint8Array|Buffer): bigint {
|
|||
let ret = 0n
|
||||
for (const i of buf.values()) {
|
||||
const bi = BigInt(i)
|
||||
ret = (ret << BigInt(8)) + bi
|
||||
ret = (ret << 8n) + bi
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ export function isProbablyPrime (w: number|bigint, iterations: number = 16, disa
|
|||
}
|
||||
}
|
||||
|
||||
export function _isProbablyPrime (w: bigint, iterations: number = 16): boolean {
|
||||
export function _isProbablyPrime (w: bigint, iterations: number): boolean {
|
||||
/*
|
||||
PREFILTERING. Even values but 2 are not primes, so don't test.
|
||||
1 is not a prime and the M-R algorithm needs w>1.
|
||||
|
@ -393,18 +393,7 @@ export function _isProbablyPrimeWorkerUrl (): string {
|
|||
// Let's us first add all the required functions
|
||||
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 ${randBitsSync.name}=${randBitsSync.toString()};const ${randBytesSync.name}=${randBytesSync.toString()};const ${randBetween.name}=${randBetween.toString()};const ${isProbablyPrime.name}=${_isProbablyPrime.toString()};${bitLength.toString()};${fromBuffer.toString()};`
|
||||
|
||||
workerCode += `
|
||||
onmessage = async function (event) { // Let's start once we are called
|
||||
// event.data = {rnd: <bigint>, iterations: <number>}
|
||||
const isPrime = await ${isProbablyPrime.name}(event.data.rnd, event.data.iterations);
|
||||
const msg = {
|
||||
isPrime: isPrime,
|
||||
value: event.data.rnd,
|
||||
id: event.data.id
|
||||
};
|
||||
postMessage(msg);
|
||||
}
|
||||
`
|
||||
workerCode += `onmessage=async function(e){const m={isPrime:await ${isProbablyPrime.name}(e.data.rnd,e.data.iterations),value:e.data.rnd,id:e.data.id};postMessage(m);}`
|
||||
|
||||
return _workerUrl(workerCode)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue