better dependencies

This commit is contained in:
juanelas 2020-04-08 00:21:02 +02:00
parent e7da55c352
commit 70a32d0286
15 changed files with 550 additions and 993 deletions

View File

@ -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.min.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.iife.js) or the [ES6 bundle module](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.mod.js) from GitHub.
## Usage examples
@ -29,11 +29,12 @@ Import your module as :
const bigintCryptoUtils = require('bigint-crypto-utils')
... // your code here
```
- JavaScript native project
- JavaScript native or TypeScript project
```javascript
import * as bigintCryptoUtils from 'bigint-crypto-utils'
... // your code here
```
> BigInt is [ES-2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you should set `lib` (and probably also `target` and `module`) to `esnext` in `tsconfig.json`.
- JavaScript native browser ES6 mod
```html
<script type="module">
@ -43,17 +44,17 @@ Import your module as :
```
- JavaScript native browser IIFE
```html
<script src="../../lib/index.browser.bundle.js"></script> <!-- Use you actual path to the browser bundle -->
<script>
... // your code here
</script>
<head>
...
<script src="../../lib/index.browser.bundle.js"></script> <!-- Use you actual path to the browser bundle -->
</head>
<body>
...
<script>
... // your code here
</script>
</body>
```
- TypeScript
```typescript
import * as bigintCryptoUtils from 'bigint-crypto-utils'
... // your code here
```
> BigInt is [ES-2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you should set `lib` (and probably also `target` and `module`) to `esnext` in `tsconfig.json`.
And you could use it like in the following:

View File

@ -8,7 +8,7 @@ const pkgJson = require('../package.json')
const rootDir = path.join(__dirname, '..')
const template = path.join(rootDir, pkgJson.directories.src, 'doc', 'readme-template.md')
const input = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.mod.js')
const input = path.join(rootDir, pkgJson.browser)
const source = fs.readFileSync(input, { encoding: 'UTF-8' }).replace(/([0-9]+)n([,\s\n)])/g, '$1$2')
const options = {

View File

@ -4,7 +4,7 @@ const path = require('path')
const pkgJson = require('../package.json')
const rootDir = path.join(__dirname, '..')
const jsFile = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.mod.js')
const jsFile = path.join(rootDir, pkgJson.browser)
const dtsFile = path.join(rootDir, pkgJson.types)
const compilerOptions = {

View File

@ -25,38 +25,17 @@ const pkgCamelisedName = camelise(pkgName)
const input = path.join(srcDir, 'js', 'index.js')
module.exports = [
{ // ESM native module
{ // Browser
input: input,
output: [
{
file: path.join(rootDir, pkgJson.browser),
format: 'esm'
}
],
plugins: [
replace({
'process.browser': true
})
],
external: ['bigint-mod-arith']
},
{ // Browser bundles
input: input,
output: [
{
file: path.join(dstDir, 'index.browser.bundle.js'),
format: 'iife',
name: pkgCamelisedName,
plugins: [
terser()
]
format: 'es'
},
{
file: path.join(dstDir, 'index.browser.bundle.min.mod.js'),
format: 'es',
plugins: [
terser()
]
file: path.join(dstDir, 'index.browser.bundle.iife.js'),
format: 'iife',
name: pkgCamelisedName
},
{
file: path.join(dstDir, 'index.browser.bundle.mod.js'),
@ -69,20 +48,26 @@ module.exports = [
}),
resolve({
browser: true
// ignore: ['index.browser.mod.js']
}),
terser({
exclude: ['index.browser.mod.js']
})
]
},
{ // Node
input: input,
plugins: [
replace({
'process.browser': false
})
],
output: {
file: path.join(dstDir, 'index.node.js'),
format: 'cjs'
},
external: ['bigint-mod-arith']
plugins: [
replace({
'process.browser': false
}),
resolve({
browser: true
})
]
}
]

View File

@ -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.min.mod.js')
const bundleFile = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.mod.js')
const testsJs = `
<script type="module">
import * as _pkg from '${path.relative(templatePath, bundleFile)}'

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

View File

@ -1,5 +1,213 @@
import { bitLength, eGcd, modInv, modPow, toZn } from 'bigint-mod-arith'
export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn } from 'bigint-mod-arith'
/**
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
*
* @param {number|bigint} a
*
* @returns {bigint} the absolute value of a
*/
function abs (a) {
a = BigInt(a)
return (a >= 0n) ? a : -a
}
/**
* Returns the bitlength of a number
*
* @param {number|bigint} a
* @returns {number} - the bit length
*/
function bitLength (a) {
a = BigInt(a)
if (a === 1n) { return 1 }
let bits = 1
do {
bits++
} while ((a >>= 1n) > 1n)
return bits
}
/**
* @typedef {Object} egcdReturn A triple (g, x, y), such that ax + by = g = gcd(a, b).
* @property {bigint} g
* @property {bigint} x
* @property {bigint} y
*/
/**
* 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).
*
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {egcdReturn} A triple (g, x, y), such that ax + by = g = gcd(a, b).
*/
function eGcd (a, b) {
a = BigInt(a)
b = BigInt(b)
if (a <= 0n | b <= 0n) { return NaN } // a and b MUST be positive
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 {
b: b,
x: x,
y: y
}
}
/**
* Greatest-common divisor of two integers based on the iterative binary algorithm.
*
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {bigint} The greatest common divisor of a and b
*/
function gcd (a, b) {
a = abs(a)
b = abs(b)
if (a === 0n) { return b } else if (b === 0n) { return a }
let shift = 0n
while (!((a | b) & 1n)) {
a >>= 1n
b >>= 1n
shift++
}
while (!(a & 1n)) a >>= 1n
do {
while (!(b & 1n)) b >>= 1n
if (a > b) {
const x = a
a = b
b = x
}
b -= a
} while (b)
// rescale
return a << shift
}
/**
* The least common multiple computed as abs(a*b)/gcd(a,b)
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {bigint} The least common multiple of a and b
*/
function lcm (a, b) {
a = BigInt(a)
b = BigInt(b)
if (a === 0n && b === 0n) { return 0n }
return abs(a * b) / gcd(a, b)
}
/**
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
*
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {bigint} maximum of numbers a and b
*/
function max (a, b) {
a = BigInt(a)
b = BigInt(b)
return (a >= b) ? a : b
}
/**
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
*
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {bigint} minimum of numbers a and b
*/
function min (a, b) {
a = BigInt(a)
b = BigInt(b)
return (a >= b) ? b : a
}
/**
* Modular inverse.
*
* @param {number|bigint} a The number to find an inverse for
* @param {number|bigint} n The modulo
*
* @returns {bigint} the inverse modulo n or NaN if it does not exist
*/
function modInv (a, n) {
const egcd = eGcd(toZn(a, n), n)
if (egcd.b !== 1n) {
return NaN // modular inverse does not exist
} else {
return toZn(egcd.x, n)
}
}
/**
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
*
* @param {number|bigint} b base
* @param {number|bigint} e exponent
* @param {number|bigint} n modulo
*
* @returns {bigint} b**e mod n
*/
function modPow (b, e, n) {
n = BigInt(n)
if (n === 0n) { return NaN } else if (n === 1n) { return 0n }
b = toZn(b, n)
e = BigInt(e)
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
}
/**
* Finds the smallest positive element that is congruent to a in modulo n
* @param {number|bigint} a An integer
* @param {number|bigint} n The modulo
*
* @returns {bigint} The smallest positive representation of a in modulo n
*/
function toZn (a, n) {
n = BigInt(n)
if (n <= 0) { return NaN }
a = BigInt(a) % n
return (a < 0) ? a + n : a
}
/**
* The test first tries if any of the first 250 small primes are a factor of the input number and then passes several
@ -611,4 +819,4 @@ function _isProbablyPrime (w, iterations = 16) {
return true
}
export { isProbablyPrime, prime, primeSync, randBetween, randBits, randBitsSync, randBytes, randBytesSync }
export { abs, bitLength, eGcd, gcd, isProbablyPrime, lcm, max, min, modInv, modPow, prime, primeSync, randBetween, randBits, randBitsSync, randBytes, randBytesSync, toZn }

View File

@ -2,7 +2,216 @@
Object.defineProperty(exports, '__esModule', { value: true })
var bigintModArith = require('bigint-mod-arith')
/**
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
*
* @param {number|bigint} a
*
* @returns {bigint} the absolute value of a
*/
function abs (a) {
a = BigInt(a)
return (a >= 0n) ? a : -a
}
/**
* Returns the bitlength of a number
*
* @param {number|bigint} a
* @returns {number} - the bit length
*/
function bitLength (a) {
a = BigInt(a)
if (a === 1n) { return 1 }
let bits = 1
do {
bits++
} while ((a >>= 1n) > 1n)
return bits
}
/**
* @typedef {Object} egcdReturn A triple (g, x, y), such that ax + by = g = gcd(a, b).
* @property {bigint} g
* @property {bigint} x
* @property {bigint} y
*/
/**
* 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).
*
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {egcdReturn} A triple (g, x, y), such that ax + by = g = gcd(a, b).
*/
function eGcd (a, b) {
a = BigInt(a)
b = BigInt(b)
if (a <= 0n | b <= 0n) { return NaN } // a and b MUST be positive
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 {
b: b,
x: x,
y: y
}
}
/**
* Greatest-common divisor of two integers based on the iterative binary algorithm.
*
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {bigint} The greatest common divisor of a and b
*/
function gcd (a, b) {
a = abs(a)
b = abs(b)
if (a === 0n) { return b } else if (b === 0n) { return a }
let shift = 0n
while (!((a | b) & 1n)) {
a >>= 1n
b >>= 1n
shift++
}
while (!(a & 1n)) a >>= 1n
do {
while (!(b & 1n)) b >>= 1n
if (a > b) {
const x = a
a = b
b = x
}
b -= a
} while (b)
// rescale
return a << shift
}
/**
* The least common multiple computed as abs(a*b)/gcd(a,b)
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {bigint} The least common multiple of a and b
*/
function lcm (a, b) {
a = BigInt(a)
b = BigInt(b)
if (a === 0n && b === 0n) { return 0n }
return abs(a * b) / gcd(a, b)
}
/**
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b
*
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {bigint} maximum of numbers a and b
*/
function max (a, b) {
a = BigInt(a)
b = BigInt(b)
return (a >= b) ? a : b
}
/**
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b
*
* @param {number|bigint} a
* @param {number|bigint} b
*
* @returns {bigint} minimum of numbers a and b
*/
function min (a, b) {
a = BigInt(a)
b = BigInt(b)
return (a >= b) ? b : a
}
/**
* Modular inverse.
*
* @param {number|bigint} a The number to find an inverse for
* @param {number|bigint} n The modulo
*
* @returns {bigint} the inverse modulo n or NaN if it does not exist
*/
function modInv (a, n) {
const egcd = eGcd(toZn(a, n), n)
if (egcd.b !== 1n) {
return NaN // modular inverse does not exist
} else {
return toZn(egcd.x, n)
}
}
/**
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
*
* @param {number|bigint} b base
* @param {number|bigint} e exponent
* @param {number|bigint} n modulo
*
* @returns {bigint} b**e mod n
*/
function modPow (b, e, n) {
n = BigInt(n)
if (n === 0n) { return NaN } else if (n === 1n) { return 0n }
b = toZn(b, n)
e = BigInt(e)
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
}
/**
* Finds the smallest positive element that is congruent to a in modulo n
* @param {number|bigint} a An integer
* @param {number|bigint} n The modulo
*
* @returns {bigint} The smallest positive representation of a in modulo n
*/
function toZn (a, n) {
n = BigInt(n)
if (n <= 0) { return NaN }
a = BigInt(a) % n
return (a < 0) ? a + n : a
}
/**
* The test first tries if any of the first 250 small primes are a factor of the input number and then passes several
@ -146,7 +355,7 @@ function primeSync (bitLength, iterations = 16) {
function randBetween (max, min = 1n) {
if (max <= min) throw new Error('max must be > min')
const interval = max - min
const bitLen = bigintModArith.bitLength(interval)
const bitLen = bitLength(interval)
let rnd
do {
const buf = randBitsSync(bitLen)
@ -589,11 +798,11 @@ function _isProbablyPrime (w, iterations = 16) {
do {
const b = randBetween(d, 2n)
let z = bigintModArith.modPow(b, m, w)
let z = modPow(b, m, w)
if (z === 1n || z === d) { continue }
let j = 1
while (j < a) {
z = bigintModArith.modPow(z, 2n, w)
z = modPow(z, 2n, w)
if (z === d) { break }
if (z === 1n) { return false }
j++
@ -638,67 +847,16 @@ if (_useWorkers) { // node.js with support for workers
}
}
Object.defineProperty(exports, 'abs', {
enumerable: true,
get: function () {
return bigintModArith.abs
}
})
Object.defineProperty(exports, 'bitLength', {
enumerable: true,
get: function () {
return bigintModArith.bitLength
}
})
Object.defineProperty(exports, 'eGcd', {
enumerable: true,
get: function () {
return bigintModArith.eGcd
}
})
Object.defineProperty(exports, 'gcd', {
enumerable: true,
get: function () {
return bigintModArith.gcd
}
})
Object.defineProperty(exports, 'lcm', {
enumerable: true,
get: function () {
return bigintModArith.lcm
}
})
Object.defineProperty(exports, 'max', {
enumerable: true,
get: function () {
return bigintModArith.max
}
})
Object.defineProperty(exports, 'min', {
enumerable: true,
get: function () {
return bigintModArith.min
}
})
Object.defineProperty(exports, 'modInv', {
enumerable: true,
get: function () {
return bigintModArith.modInv
}
})
Object.defineProperty(exports, 'modPow', {
enumerable: true,
get: function () {
return bigintModArith.modPow
}
})
Object.defineProperty(exports, 'toZn', {
enumerable: true,
get: function () {
return bigintModArith.toZn
}
})
exports.abs = abs
exports.bitLength = bitLength
exports.eGcd = eGcd
exports.gcd = gcd
exports.isProbablyPrime = isProbablyPrime
exports.lcm = lcm
exports.max = max
exports.min = min
exports.modInv = modInv
exports.modPow = modPow
exports.prime = prime
exports.primeSync = primeSync
exports.randBetween = randBetween
@ -706,3 +864,4 @@ exports.randBits = randBits
exports.randBitsSync = randBitsSync
exports.randBytes = randBytes
exports.randBytesSync = randBytesSync
exports.toZn = toZn

98
package-lock.json generated
View File

@ -14,9 +14,9 @@
}
},
"@babel/helper-validator-identifier": {
"version": "7.9.0",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.0.tgz",
"integrity": "sha512-6G8bQKjOh+of4PV/ThDm/rRqlU7+IGoJuofpagU5GlEl29Vv0RGqqt86ZGRV8ZuSOY3o+8yXl5y782SMcG7SHw==",
"version": "7.9.5",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.5.tgz",
"integrity": "sha512-/8arLKUFq882w4tWGj9JYzRpAlZgiWUJ+dtteNTDqrRBz9Iguck9Rn3ykuBDoUwh2TO4tSAJlrxDUOXWklJe4g==",
"dev": true
},
"@babel/highlight": {
@ -264,7 +264,8 @@
"bigint-mod-arith": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/bigint-mod-arith/-/bigint-mod-arith-2.0.4.tgz",
"integrity": "sha512-sQyEj0XMU4hai3G/+uLwohrGjfUn8rGVWAYnnlFrQhw8YjilptTyJrx7NMimKwQvYr2eXGWGDlYVL3wfE4GIRg=="
"integrity": "sha512-sQyEj0XMU4hai3G/+uLwohrGjfUn8rGVWAYnnlFrQhw8YjilptTyJrx7NMimKwQvYr2eXGWGDlYVL3wfE4GIRg==",
"dev": true
},
"binary-extensions": {
"version": "2.0.0",
@ -757,9 +758,9 @@
"dev": true
},
"entities": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz",
"integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-2.0.0.tgz",
"integrity": "sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==",
"dev": true
},
"error-ex": {
@ -876,6 +877,15 @@
"is-extglob": "^2.1.1"
}
},
"mkdirp": {
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"dev": true,
"requires": {
"minimist": "^1.2.5"
}
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
@ -1850,25 +1860,33 @@
}
},
"jsdoc": {
"version": "3.6.3",
"resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.3.tgz",
"integrity": "sha512-Yf1ZKA3r9nvtMWHO1kEuMZTlHOF8uoQ0vyo5eH7SQy5YeIiHM+B0DgKnn+X6y6KDYZcF7G2SPkKF+JORCXWE/A==",
"version": "3.6.4",
"resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.4.tgz",
"integrity": "sha512-3G9d37VHv7MFdheviDCjUfQoIjdv4TC5zTTf5G9VODLtOnVS6La1eoYBDlbWfsRT3/Xo+j2MIqki2EV12BZfwA==",
"dev": true,
"requires": {
"@babel/parser": "^7.4.4",
"bluebird": "^3.5.4",
"@babel/parser": "^7.9.4",
"bluebird": "^3.7.2",
"catharsis": "^0.8.11",
"escape-string-regexp": "^2.0.0",
"js2xmlparser": "^4.0.0",
"js2xmlparser": "^4.0.1",
"klaw": "^3.0.0",
"markdown-it": "^8.4.2",
"markdown-it-anchor": "^5.0.2",
"marked": "^0.7.0",
"mkdirp": "^0.5.1",
"markdown-it": "^10.0.0",
"markdown-it-anchor": "^5.2.7",
"marked": "^0.8.2",
"mkdirp": "^1.0.4",
"requizzle": "^0.2.3",
"strip-json-comments": "^3.0.1",
"strip-json-comments": "^3.1.0",
"taffydb": "2.6.2",
"underscore": "~1.9.1"
"underscore": "~1.10.2"
},
"dependencies": {
"marked": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/marked/-/marked-0.8.2.tgz",
"integrity": "sha512-EGwzEeCcLniFX51DhTpmTom+dSA/MG/OBUDjnWtHbEnjAH180VzUeAw+oE4+Zv+CoYBWyRlYOTR0N8SO9R1PVw==",
"dev": true
}
}
},
"jsdoc-api": {
@ -2082,13 +2100,13 @@
}
},
"markdown-it": {
"version": "8.4.2",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz",
"integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==",
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-10.0.0.tgz",
"integrity": "sha512-YWOP1j7UbDNz+TumYP1kpwnP0aEa711cJjrAQrzd0UXlbJfc5aAq0F/PZHjiioqDC1NKgvIMX+o+9Bk7yuM2dg==",
"dev": true,
"requires": {
"argparse": "^1.0.7",
"entities": "~1.1.1",
"entities": "~2.0.0",
"linkify-it": "^2.0.0",
"mdurl": "^1.0.1",
"uc.micro": "^1.0.5"
@ -2160,13 +2178,10 @@
"dev": true
},
"mkdirp": {
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"dev": true,
"requires": {
"minimist": "^1.2.5"
}
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true
},
"mkdirp2": {
"version": "1.0.4",
@ -2953,9 +2968,9 @@
}
},
"rollup": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.3.3.tgz",
"integrity": "sha512-uJ9VNWk80mb4wDCSfd1AyHoSc9TrWbkZtnO6wbsMTp9muSWkT26Dvc99MX1yGCOTvUN1Skw/KpFzKdUDuZKTXA==",
"version": "2.3.4",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.3.4.tgz",
"integrity": "sha512-8U9x54RCVhrUEV1zon4Pp8kokg1HM0fwzf5vkwe2/rOfyTClarx5e27kFlaoZ7ofJiazWkNQ+dgdG4HuZxkQ9A==",
"dev": true,
"requires": {
"fsevents": "~2.1.2"
@ -3501,9 +3516,9 @@
}
},
"underscore": {
"version": "1.9.2",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.2.tgz",
"integrity": "sha512-D39qtimx0c1fI3ya1Lnhk3E9nONswSKhnffBI0gME9C99fYOkNi04xs8K6pePLhvl1frbDemkaBQ5ikWllR2HQ==",
"version": "1.10.2",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.10.2.tgz",
"integrity": "sha512-N4P+Q/BuyuEKFJ43B9gYuOj4TQUHXX+j2FqguVOpjkssLUUrnJofCcBccJSCoeturDoZU6GorDTHSvUDlSQbTg==",
"dev": true
},
"uniq": {
@ -3641,6 +3656,17 @@
"dev": true,
"requires": {
"mkdirp": "^0.5.1"
},
"dependencies": {
"mkdirp": {
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"dev": true,
"requires": {
"minimist": "^1.2.5"
}
}
}
},
"xmlcreate": {

View File

@ -52,8 +52,8 @@
],
"ignore": [
"/test/browser/",
"/lib/index.browser.bundle.js",
"/lib/index.browser.bundle.min.mod.js"
"/lib/index.browser.bundle.iife.js",
"/lib/index.browser.bundle.mod.js"
]
},
"devDependencies": {
@ -61,17 +61,17 @@
"@rollup/plugin-multi-entry": "^3.0.0",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-replace": "^2.3.1",
"bigint-mod-arith": "^2.0.4",
"chai": "^4.2.0",
"jsdoc-to-markdown": "^5.0.3",
"mocha": "^7.1.1",
"npm-run-all": "^4.1.5",
"rollup": "^2.3.3",
"rollup": "^2.3.4",
"rollup-plugin-terser": "^5.3.0",
"standard": "^14.3.3",
"typescript": "^3.8.3"
},
"dependencies": {
"@types/node": "^13.11.0",
"bigint-mod-arith": "^2.0.4"
"@types/node": ">=10"
}
}

View File

@ -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.min.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.iife.js) or the [ES6 bundle module](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.mod.js) from GitHub.
## Usage examples
@ -29,11 +29,12 @@ Import your module as :
const bigintCryptoUtils = require('bigint-crypto-utils')
... // your code here
```
- JavaScript native project
- JavaScript native or TypeScript project
```javascript
import * as bigintCryptoUtils from 'bigint-crypto-utils'
... // your code here
```
> BigInt is [ES-2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you should set `lib` (and probably also `target` and `module`) to `esnext` in `tsconfig.json`.
- JavaScript native browser ES6 mod
```html
<script type="module">
@ -43,17 +44,17 @@ Import your module as :
```
- JavaScript native browser IIFE
```html
<script src="../../lib/index.browser.bundle.js"></script> <!-- Use you actual path to the browser bundle -->
<script>
... // your code here
</script>
<head>
...
<script src="../../lib/index.browser.bundle.js"></script> <!-- Use you actual path to the browser bundle -->
</head>
<body>
...
<script>
... // your code here
</script>
</body>
```
- TypeScript
```typescript
import * as bigintCryptoUtils from 'bigint-crypto-utils'
... // your code here
```
> BigInt is [ES-2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you should set `lib` (and probably also `target` and `module`) to `esnext` in `tsconfig.json`.
And you could use it like in the following:

View File

@ -13,7 +13,7 @@
<script>mocha.setup('bdd'); mocha.setup({ timeout: 90000 });</script>
<script type="module">
import * as _pkg from '../../../lib/index.browser.bundle.min.mod.js'
import * as _pkg from '../../../lib/index.browser.bundle.mod.js'
window._pkg = _pkg;
import './tests.js';
mocha.run();

View File

@ -10,7 +10,7 @@
<div id="syncPrime">result of primeSync() will show up here</div>
<div id="asyncPrime">result of prime() will show up here</div>
<script src="../../lib/index.browser.bundle.js"></script>
<script src="../../lib/index.browser.bundle.iife.js"></script>
<script>
(async () => {
document.getElementById(