some fixes in the README

This commit is contained in:
Juan Hernández Serrano 2021-08-06 10:10:32 +02:00
parent f11626d029
commit 519dcbc0fd
37 changed files with 543 additions and 861 deletions

View File

@ -45,9 +45,9 @@ 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/master/dist/bundles/bigint-crypto-utils.iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/dist/bundles/bigint-crypto-utils.esm.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/dist/bundles/bigint-crypto-utils.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/master/dist/bundles/iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/dist/bundles/esm.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/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/`.
An example of usage could be:
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):
```typescript
/* A BigInt with value 666 can be declared calling the bigint constructor as

View File

@ -23,9 +23,9 @@ async function typedoc () {
app.bootstrap({
// typedoc options here
entryPoints: ['src/index.ts'],
entryPoints: ['src/ts/index.ts'],
plugin: ['typedoc-plugin-markdown'],
includeVersion: true,
includeVersion: false,
entryDocument: 'API.md',
readme: 'none',
hideBreadcrumbs: true
@ -50,7 +50,7 @@ function getRepositoryData () {
return {
repoProvider,
repoUsername: repodata[1],
repoName: repodata[2]
repoName: repodata.slice(2).join('/')
}
} else return null
}
@ -98,6 +98,8 @@ let template = fs.readFileSync(templateFile, { encoding: 'UTF-8' })
if (repoProvider && repoProvider === 'github') {
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}/g, workflowBadget + '\n' + coverallsBadge)
} else {
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}/g, '')
}
const readmeFile = path.join(rootDir, 'README.md')

View File

@ -11,7 +11,8 @@ const fs = require('fs')
const pkgJson = require('../package.json')
const rootDir = path.join(__dirname, '..')
const srcDir = path.join(rootDir, 'src')
const dstDir = path.join(rootDir, pkgJson.directories.dist)
const srcDir = path.join(rootDir, 'src', 'ts')
function camelise (str) {
return str.replace(/-([a-z])/g,
@ -28,6 +29,7 @@ const input = path.join(srcDir, 'index.ts')
if (fs.existsSync(input) !== true) throw new Error('The entry point should be index.ts')
const tsBundleOptions = {
outDir: undefined, // ignore outDir in tsconfig.json
exclude: ['test/**/*', 'src/**/*.spec.ts', './build/typings/global-this-pkg.d.ts']
}
@ -39,39 +41,38 @@ const sourcemapOutputOptions = {
}
module.exports = [
{ // Browser ESM
{ // ESM for browsers
input: input,
output: {
file: path.join(rootDir, pkgJson.browser),
format: 'es',
...sourcemapOutputOptions
},
output: [
{
file: path.join(rootDir, pkgJson.exports['.'].default),
...sourcemapOutputOptions,
format: 'es'
}
],
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']
})
]
typescriptPlugin(tsBundleOptions)
],
external
},
{ // Browser bundles
input: input,
output: [
{
file: path.join(rootDir, pkgJson.exports['./iife-browser-bundle']),
file: path.join(dstDir, 'bundles/iife.js'),
format: 'iife',
name: pkgCamelisedName
},
{
file: path.join(rootDir, pkgJson.exports['./esm-browser-bundle']),
file: path.join(dstDir, 'bundles/esm.js'),
format: 'es'
},
{
file: path.join(rootDir, pkgJson.exports['./umd-browser-bundle']),
file: path.join(dstDir, 'bundles/umd.js'),
format: 'umd',
name: pkgCamelisedName
}
@ -92,8 +93,7 @@ module.exports = [
{ // Node ESM with declaration files
input: input,
output: {
dir: path.join(rootDir, path.dirname(pkgJson.exports['.'].node.import)),
entryFileNames: path.basename(pkgJson.exports['.'].node.import),
file: path.join(rootDir, pkgJson.exports['.'].node.import),
...sourcemapOutputOptions,
format: 'es'
},
@ -122,7 +122,7 @@ module.exports = [
format: 'cjs'
},
{
file: path.join(rootDir, pkgJson.exports['./node-js']),
file: path.join(rootDir, pkgJson.exports['.'].node.require).slice(0, -4) + '.js', // .js extension instead of .cjs for Node 10 support
...sourcemapOutputOptions,
format: 'cjs'
}
@ -134,7 +134,6 @@ module.exports = [
}),
typescriptPlugin(tsBundleOptions),
commonjs({ extensions: ['.js', '.ts'] }) // the ".ts" extension is required
],
external
]
}
]

View File

@ -62,7 +62,8 @@ async function buildTests () {
exportConditions: ['browser', 'module', 'import', 'default']
}),
commonjs()
]
],
external: [pkgJson.name]
}
const bundle = await rollup.rollup(inputOptions)
const { output } = await bundle.generate({ format: 'esm' })
@ -79,7 +80,7 @@ class TestServer {
const tests = await buildTests()
this.server.on('request', function (req, res) {
if (req.url === `/${name}.esm.js`) {
fs.readFile(path.join(rootDir, pkgJson.directories.dist, `bundles/${name}.esm.js`), function (err, data) {
fs.readFile(path.join(rootDir, pkgJson.directories.dist, 'bundles/esm.js'), function (err, data) {
if (err) {
res.writeHead(404)
res.end(JSON.stringify(err))

View File

@ -28,7 +28,8 @@ module.exports = class TestsBuilder extends Builder {
const fileStr = fs.readFileSync(path, 'utf8')
const config = JSON5.parse(fileStr)
if (config.file) delete config.file
config.include = ['build/typings/**/*.ts', 'test/**/*.ts', 'src/**/*.spec.ts', 'node_modules/@types/**/*']
config.include.push('node_modules/**/*.d.ts')
config.compilerOptions.module = 'commonjs'
return JSON.stringify(config)
}
const configFile = ts.readJsonConfigFile(configPath, readFileAndMangle)
@ -68,7 +69,6 @@ module.exports = class TestsBuilder extends Builder {
...parsedTsConfig.options,
rootDir,
outDir: this.tempDir,
module: 'commonjs',
noEmit: false,
noResolve: true,
sourceMap: true

View File

@ -25,13 +25,21 @@ testBuilder.start() // This should be in exports.mochaGlobalSetup but mocha fail
exports.mochaHooks = {
beforeAll: [
async function () {
this.timeout('120000')
await Promise.all([rollupBuilder.ready(), testBuilder.ready()])
// Just in case our module had been modified. Reload it when the tests are repeated (for mocha watch mode).
delete require.cache[require.resolve(rootDir)]
global._pkg = require(rootDir)
},
async function () {
this.timeout('120000')
await Promise.all([rollupBuilder.ready(), testBuilder.ready()])
// And now reset any other transpiled module (just delete the cache so it is fully reloaded)
for (const key in require.cache) {
const relativePath = path.relative(rootDir, key)
if (relativePath.startsWith(`.mocha-ts${path.sep}`)) {
delete require.cache[key]
}
}
}
]
}

View File

@ -1,5 +1,7 @@
import * as _pkgModule from '../..'
export as namespace _pkg
declare global {
const _pkg: typeof _pkgModule
}
export as namespace _pkgTypes
export = _pkgModule

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,7 +0,0 @@
export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn } from 'bigint-mod-arith';
export { isProbablyPrime } from './ts/isProbablyPrime';
export { prime, primeSync } from './ts/prime';
export { randBetween } from './ts/randBetween';
export { randBits, randBitsSync } from './ts/randBits';
export { randBytes, randBytesSync } from './ts/randBytes';
//# sourceMappingURL=index.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEjG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}

View File

@ -1,3 +0,0 @@
/// <reference types="node" />
export declare function fromBuffer(buf: Uint8Array | Buffer): bigint;
//# sourceMappingURL=fromBuffer.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"fromBuffer.d.ts","sourceRoot":"","sources":["../../../../src/ts/fromBuffer.ts"],"names":[],"mappings":";AAAA,wBAAgB,UAAU,CAAE,GAAG,EAAE,UAAU,GAAC,MAAM,GAAG,MAAM,CAO1D"}

View File

@ -1,17 +0,0 @@
/**
* The test first tries if any of the first 250 small primes are a factor of the input number and then passes several
* iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)
*
* @param w - A positive integer to be tested for primality
* @param iterations - The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3
* @param disableWorkers - Disable the use of workers for the primality test
*
* @throws {RangeError}
* w MUST be >= 0
*
* @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 _isProbablyPrimeWorkerUrl(): string;
//# sourceMappingURL=isProbablyPrime.d.ts.map

View File

@ -1 +0,0 @@
{"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"}

View File

@ -1,30 +0,0 @@
/**
* A probably-prime (Miller-Rabin), cryptographically-secure, random-number generator.
* The browser version uses web workers to parallelise prime look up. Therefore, it does not lock the UI
* main process, and it can be much faster (if several cores or cpu are available).
* The node version can also use worker_threads if they are available (enabled by default with Node 11 and
* and can be enabled at runtime executing node --experimental-worker with node >=10.5.0).
*
* @param bitLength - The required bit length for the generated prime
* @param iterations - The number of iterations for the Miller-Rabin Probabilistic Primality Test
*
* @throws {RangeError}
* bitLength MUST be > 0
*
* @returns A promise that resolves to a bigint probable prime of bitLength bits.
*/
export declare function prime(bitLength: number, iterations?: number): Promise<bigint>;
/**
* A probably-prime (Miller-Rabin), cryptographically-secure, random-number generator.
* The sync version is NOT RECOMMENDED since it won't use workers and thus it'll be slower and may freeze thw window in browser's javascript. Please consider using prime() instead.
*
* @param bitLength - The required bit length for the generated prime
* @param iterations - The number of iterations for the Miller-Rabin Probabilistic Primality Test
*
* @throws {RangeError}
* bitLength MUST be > 0
*
* @returns A bigint probable prime of bitLength bits.
*/
export declare function primeSync(bitLength: number, iterations?: number): bigint;
//# sourceMappingURL=prime.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"prime.d.ts","sourceRoot":"","sources":["../../../../src/ts/prime.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAiElF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,CAO7E"}

View File

@ -1,12 +0,0 @@
/**
* Returns a cryptographically secure random integer between [min,max]. Both numbers must be >=0
* @param max Returned value will be <= max
* @param min Returned value will be >= min
*
* @throws {RangeError}
* Arguments MUST be: max > 0 && min >=0 && max > min
*
* @returns A cryptographically secure random bigint between [min,max]
*/
export declare function randBetween(max: bigint, min?: bigint): bigint;
//# sourceMappingURL=randBetween.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"randBetween.d.ts","sourceRoot":"","sources":["../../../../src/ts/randBetween.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAW,GAAG,MAAM,CAUlE"}

View File

@ -1,25 +0,0 @@
/// <reference types="node" />
/**
* Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
*
* @param bitLength - The desired number of random bits
* @param forceLength - If we want to force the output to have a specific bit length. It basically forces the msb to be 1
*
* @throws {RangeError}
* bitLength MUST be > 0
*
* @returns A Promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bits
*/
export declare function randBits(bitLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
/**
* Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
* @param bitLength - The desired number of random bits
* @param forceLength - If we want to force the output to have a specific bit length. It basically forces the msb to be 1
*
* @throws {RangeError}
* bitLength MUST be > 0
*
* @returns A Uint8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bits
*/
export declare function randBitsSync(bitLength: number, forceLength?: boolean): Uint8Array | Buffer;
//# sourceMappingURL=randBits.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"randBits.d.ts","sourceRoot":"","sources":["../../../../src/ts/randBits.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,GAAC,MAAM,CAAC,CAmBrG;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,UAAU,GAAC,MAAM,CAehG"}

View File

@ -1,26 +0,0 @@
/// <reference types="node" />
/**
* Secure random bytes for both node and browsers. Node version uses crypto.randomBytes() and browser one self.crypto.getRandomValues()
*
* @param byteLength - The desired number of random bytes
* @param forceLength - If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*
* @throws {RangeError}
* byteLength MUST be > 0
*
* @returns A promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bytes
*/
export declare function randBytes(byteLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
/**
* Secure random bytes for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
*
* @param byteLength - The desired number of random bytes
* @param forceLength - If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*
* @throws {RangeError}
* byteLength MUST be > 0
*
* @returns A UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bytes
*/
export declare function randBytesSync(byteLength: number, forceLength?: boolean): Uint8Array | Buffer;
//# sourceMappingURL=randBytes.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"randBytes.d.ts","sourceRoot":"","sources":["../../../../src/ts/randBytes.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAE,UAAU,EAAE,MAAM,EAAE,WAAW,UAAQ,GAAG,OAAO,CAAC,UAAU,GAAC,MAAM,CAAC,CAqB9F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAE,UAAU,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,UAAU,GAAC,MAAM,CAkBlG"}

View File

@ -1,14 +0,0 @@
export declare function _workerUrl(workerCode: string): string;
declare let _useWorkers: boolean;
export { _useWorkers };
export interface WorkerToMainMsg {
isPrime: boolean;
value: bigint;
id: number;
}
export interface MainToWorkerMsg {
rnd: bigint;
iterations: number;
id: number;
}
//# sourceMappingURL=workerUtils.d.ts.map

View File

@ -1 +0,0 @@
{"version":3,"file":"workerUtils.d.ts","sourceRoot":"","sources":["../../../../src/ts/workerUtils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,QAAA,IAAI,WAAW,SAAQ,CAAA;AAiBvB,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;IAClB,EAAE,EAAE,MAAM,CAAA;CACX"}

View File

@ -1,4 +1,4 @@
# bigint-crypto-utils - v3.0.16
# bigint-crypto-utils
## Table of contents
@ -153,7 +153,7 @@ A promise that resolves to a boolean that is either true (a probably prime numbe
#### Defined in
[src/ts/isProbablyPrime.ts:21](https://github.com/juanelas/bigint-crypto-utils/blob/54f0a8d/src/ts/isProbablyPrime.ts#L21)
[src/ts/isProbablyPrime.ts:21](https://github.com/juanelas/bigint-crypto-utils/blob/f11626d/src/ts/isProbablyPrime.ts#L21)
___
@ -317,7 +317,7 @@ 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/54f0a8d/src/ts/prime.ts#L21)
[src/ts/prime.ts:21](https://github.com/juanelas/bigint-crypto-utils/blob/f11626d/src/ts/prime.ts#L21)
___
@ -346,7 +346,7 @@ A bigint probable prime of bitLength bits.
#### Defined in
[src/ts/prime.ts:100](https://github.com/juanelas/bigint-crypto-utils/blob/54f0a8d/src/ts/prime.ts#L100)
[src/ts/prime.ts:100](https://github.com/juanelas/bigint-crypto-utils/blob/f11626d/src/ts/prime.ts#L100)
___
@ -374,7 +374,7 @@ A cryptographically secure random bigint between [min,max]
#### Defined in
[src/ts/randBetween.ts:15](https://github.com/juanelas/bigint-crypto-utils/blob/54f0a8d/src/ts/randBetween.ts#L15)
[src/ts/randBetween.ts:15](https://github.com/juanelas/bigint-crypto-utils/blob/f11626d/src/ts/randBetween.ts#L15)
___
@ -402,7 +402,7 @@ A Promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cry
#### Defined in
[src/ts/randBits.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/54f0a8d/src/ts/randBits.ts#L14)
[src/ts/randBits.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/f11626d/src/ts/randBits.ts#L14)
___
@ -430,7 +430,7 @@ A Uint8Array/Buffer (Browser/Node.js) filled with cryptographically secure rando
#### Defined in
[src/ts/randBits.ts:45](https://github.com/juanelas/bigint-crypto-utils/blob/54f0a8d/src/ts/randBits.ts#L45)
[src/ts/randBits.ts:45](https://github.com/juanelas/bigint-crypto-utils/blob/f11626d/src/ts/randBits.ts#L45)
___
@ -458,7 +458,7 @@ A promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cry
#### Defined in
[src/ts/randBytes.ts:12](https://github.com/juanelas/bigint-crypto-utils/blob/54f0a8d/src/ts/randBytes.ts#L12)
[src/ts/randBytes.ts:12](https://github.com/juanelas/bigint-crypto-utils/blob/f11626d/src/ts/randBytes.ts#L12)
___
@ -486,7 +486,7 @@ A UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure rando
#### Defined in
[src/ts/randBytes.ts:46](https://github.com/juanelas/bigint-crypto-utils/blob/54f0a8d/src/ts/randBytes.ts#L46)
[src/ts/randBytes.ts:46](https://github.com/juanelas/bigint-crypto-utils/blob/f11626d/src/ts/randBytes.ts#L46)
___

View File

@ -10,7 +10,7 @@
<div id="status">Still computing in background...</div>
<p>Look for the results in the JS console (Developer Tools)</p>
<script type="module">
import * as bigintCryptoUtils from '../dist/bundles/bigint-crypto-utils.esm.js'
import * as bigintCryptoUtils from '../dist/bundles/esm.js'
/* A BigInt with value 666 can be declared calling the bigint constructor as
BigInt('666') or with the shorter 666n.
Notice that you can also pass a number to the constructor, e.g. BigInt(666).

View File

@ -4,7 +4,7 @@
<head>
<title>bigint-crypto-utils</title>
<meta charset="UTF-8" />
<script src="../dist/bundles/bigint-crypto-utils.iife.js"></script>
<script src="../dist/bundles/iife.js"></script>
</head>
<body>

837
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -37,9 +37,9 @@
"default": "./dist/esm/index.browser.js"
},
"./node-js": "./dist/cjs/index.node.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",
"./esm-browser-bundle": "./dist/bundles/esm.js",
"./iife-browser-bundle": "./dist/bundles/iife.js",
"./umd-browser-bundle": "./dist/bundles/umd.js",
"./types": "./dist/esm/types/index.d.ts"
},
"directories": {
@ -53,17 +53,15 @@
"build": "run-s lint build:js docs test:browser coverage",
"build:js": "rollup -c build/rollup.config.js",
"clean": "rimraf .nyc_output .mocha-ts coverage dist docs",
"commitversion": "git commit -a -m \"v$npm_package_version\"",
"coverage": "nyc --check-coverage --exclude build --exclude '{src/**/*.spec.ts,test/**/*.ts}' --reporter=text --reporter=lcov node ./build/bin/mocha-ts.js --require build/testing/mocha/mocha-init.js '{src/**/*.spec.ts,test/**/*.ts}'",
"coverage": "nyc --check-coverage --exclude build --exclude '{src/ts/**/*.spec.ts,test/**/*.ts}' --reporter=text --reporter=lcov node ./build/bin/mocha-ts.js --require build/testing/mocha/mocha-init.js '{src/ts/**/*.spec.ts,test/**/*.ts}'",
"docs": "node build/build.docs.js",
"lint": "ts-standard --fix",
"mocha": "node ./build/bin/mocha-ts.js --require build/testing/mocha/mocha-init.js ",
"preversion": "npm run build",
"postversion": "run-s docs commitversion",
"test": "run-s test:browser test:node",
"test:browser": "node build/testing/browser/index.js",
"test:node": "npm run mocha -- '{src/**/*.spec.ts,test/**/*.ts}'",
"watch": "npm run mocha -- --watch '{src/**/*.spec.ts,test/**/*.ts}'"
"test:node": "npm run mocha -- '{src/ts/**/*.spec.ts,test/**/*.ts}'",
"watch": "npm run mocha -- --watch '{src/ts/**/*.spec.ts,test/**/*.ts}'"
},
"ts-standard": {
"env": [
@ -87,34 +85,30 @@
]
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-multi-entry": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@rollup/plugin-replace": "^2.4.1",
"@rollup/plugin-typescript": "^8.2.5",
"@types/chai": "^4.2.21",
"@types/mocha": "^8.2.3",
"@types/node": "^16.4.11",
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-multi-entry": "^4.0.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-replace": "^3.0.0",
"@rollup/plugin-typescript": "^8.2.0",
"@types/chai": "^4.2.14",
"@types/mocha": "^9.0.0",
"chai": "^4.3.3",
"glob": "^7.1.7",
"glob": "^7.1.6",
"json5": "^2.2.0",
"minimatch": "^3.0.4",
"mocha": "^8.4.0",
"mocha": "^9.0.3",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"pirates": "^4.0.1",
"puppeteer": "^8.0.0",
"puppeteer": "^10.1.0",
"rimraf": "^3.0.2",
"rollup": "^2.55.1",
"rollup": "^2.40.0",
"rollup-plugin-terser": "^7.0.2",
"ts-standard": "^10.0.0",
"tslib": "^2.3.0",
"tslib": "^2.1.0",
"typedoc": "^0.21.5",
"typedoc-plugin-markdown": "^3.10.4",
"typescript": "^4.3.5"
},
"peerDependencies": {
"@types/node": ">10.4"
"typedoc-plugin-markdown": "^3.6.0",
"typescript": "^4.2.2"
},
"dependencies": {
"bigint-mod-arith": "^3.0.0"

View File

@ -46,7 +46,7 @@ The appropriate version for browser or node is automatically exported.
You can also download the {{IIFE_BUNDLE}}, the {{ESM_BUNDLE}} or the {{UMD_BUNDLE}} and manually add it to your project, or, if you have already installed `{{PKG_NAME}}` in your project, just get the bundles from `node_modules/{{PKG_NAME}}/dist/bundles/`.
An example of usage could be:
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):
```typescript
/* A BigInt with value 666 can be declared calling the bigint constructor as

View File

@ -1,7 +0,0 @@
export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn } from 'bigint-mod-arith'
export { isProbablyPrime } from './ts/isProbablyPrime'
export { prime, primeSync } from './ts/prime'
export { randBetween } from './ts/randBetween'
export { randBits, randBitsSync } from './ts/randBits'
export { randBytes, randBytesSync } from './ts/randBytes'

7
src/ts/index.ts Normal file
View File

@ -0,0 +1,7 @@
export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn } from 'bigint-mod-arith'
export { isProbablyPrime } from './isProbablyPrime'
export { prime, primeSync } from './prime'
export { randBetween } from './randBetween'
export { randBits, randBitsSync } from './randBits'
export { randBytes, randBytesSync } from './randBytes'

View File

@ -1,10 +1,11 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"lib": [ "es2020", "DOM" , "WebWorker"], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": true, /* Report errors in .js files. */
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
// "lib": [ "es2020" ], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
"outDir": ".dst", /* If not set we cannot import .js files without a warning that is going to be overwritten. outDir is not going to be used in any case */
"checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'react', 'react-jsx', 'react-jsxdev', 'preserve' or 'react-native'. */
"strict": true, /* Enable all strict type-checking options. */
@ -35,5 +36,5 @@
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": ["src/**/*", "build/typings/**/*", "test/**/*"]
"include": ["src/ts/**/*", "build/typings/**/*", "test/**/*"]
}