diff --git a/README.md b/README.md index 1f25376..413cf24 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ npm install bigint-crypto-utils NPM installation defaults to the ES6 module for browsers and the CJS one for Node.js. -For web browsers, you can also directly download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.js) or the [ES6 bundle module](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.mod.js) from GitHub. +For web browsers, you can also directly download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.js) or the [ES6 bundle module](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.min.mod.js) from GitHub. ## Usage examples @@ -96,6 +96,77 @@ primeTesting() ## API reference documentation +### Functions + +
+
abs(a)bigint
+

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

+
+
bitLength(a)number
+

Returns the bitlength of a number

+
+
eGcd(a, b)egcdReturn
+

An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm. +Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).

+
+
gcd(a, b)bigint
+

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

+
+
lcm(a, b)bigint
+

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

+
+
max(a, b)bigint
+

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

+
+
min(a, b)bigint
+

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

+
+
modInv(a, n)bigint
+

Modular inverse.

+
+
modPow(b, e, n)bigint
+

Modular exponentiation b**e mod n. Currently using the right-to-left binary method

+
+
toZn(a, n)bigint
+

Finds the smallest positive element that is congruent to a in modulo n

+
+
isProbablyPrime(w, [iterations])Promise.<boolean>
+

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)

+
+
prime(bitLength, [iterations])Promise.<bigint>
+

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).

+
+
primeSync(bitLength, [iterations])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.

+
+
randBetween(max, [min])bigint
+

Returns a cryptographically secure random integer between [min,max]

+
+
randBits(bitLength, [forceLength])Buffer | Uint8Array
+

Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()

+
+
randBytes(byteLength, [forceLength])Promise.<(Buffer|Uint8Array)>
+

Secure random bytes for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()

+
+
randBytesSync(byteLength, [forceLength])Buffer | Uint8Array
+

Secure random bytes for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()

+
+
+ +### Typedefs + +
+
egcdReturn : Object
+

A triple (g, x, y), such that ax + by = g = gcd(a, b).

+
+
+ ### abs(a) ⇒ bigint diff --git a/build/build.docs.js b/build/build.docs.js index c71462b..09264e5 100644 --- a/build/build.docs.js +++ b/build/build.docs.js @@ -14,8 +14,8 @@ const source = fs.readFileSync(input, { encoding: 'UTF-8' }).replace(/([0-9]+)n( const options = { source, // we need to use this instead of files in order to avoid issues with esnext features template: fs.readFileSync(template, { encoding: 'UTF-8' }), - 'heading-depth': 3, // The initial heading depth. For example, with a value of 2 the top-level markdown headings look like "## The heading" - 'global-index-format': 'none' // none, grouped, table, dl. + 'heading-depth': 3 // The initial heading depth. For example, with a value of 2 the top-level markdown headings look like "## The heading" + // 'global-index-format': 'none' // none, grouped, table, dl. } jsdoc2md.clear().then(() => { diff --git a/build/build.dts.js b/build/build.dts.js index bedea02..b1ea3dc 100644 --- a/build/build.dts.js +++ b/build/build.dts.js @@ -4,7 +4,7 @@ const path = require('path') const pkgJson = require('../package.json') const rootDir = path.join(__dirname, '..') -const jsFile = path.join(rootDir, pkgJson.browser) +const jsFile = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.mod.js') const dtsFile = path.join(rootDir, pkgJson.types) const compilerOptions = { diff --git a/build/rollup.tests.config.js b/build/rollup.tests.config.js index b5da420..3fc0b03 100644 --- a/build/rollup.tests.config.js +++ b/build/rollup.tests.config.js @@ -21,7 +21,7 @@ const dstDir = path.join(rootDir, pkgJson.directories.test, 'browser') const dstFileName = path.join(dstDir, 'index.html') const template = fs.readFileSync(templatePath, 'utf-8') -const bundleFile = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.mod.js') +const bundleFile = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.min.mod.js') const testsJs = `