updated usage instructions. updated deps

This commit is contained in:
juanelas 2020-11-12 12:04:13 +01:00
parent 98c552773b
commit ee20c7d313
12 changed files with 1191 additions and 1283 deletions

View File

@ -27,17 +27,22 @@ NPM installation defaults to the ES6 module for browsers and the CJS one for Nod
Import your module as : Import your module as :
- Node.js - Node.js
```javascript ```javascript
const bigintCryptoUtils = require('bigint-crypto-utils') const bigintCryptoUtils = require('bigint-crypto-utils')
... // your code here ... // your code here
``` ```
- JavaScript native or TypeScript project (including React and Angular JS)
- JavaScript native or TypeScript project (including React and Angular JS)
```javascript ```javascript
import * as bigintCryptoUtils from 'bigint-crypto-utils' import * as bigintCryptoUtils from 'bigint-crypto-utils'
... // your code here ... // your code here
``` ```
`bigint-crypto-utils` **CANNOT BE POLYFILLED** to suport older browsers. If you are using webpack/babel to create your production bundles, you should target only the most modern browsers. For instance, for **React** apps created with [`create-react-app`](https://create-react-app.dev/), you should edit your `package.json` and modify the `browserList` so that it only targets the latest browsers (supporting the latest features):
`bigint-crypto-utils` **CANNOT BE POLYFILLED** to suport older browsers. If you are using webpack/babel to create your production bundles, you should target only the most modern browsers. For instance, for **React** apps created with [`create-react-app`](https://create-react-app.dev/), you should edit your `package.json` and modify the `browserList` so that it only targets the latest browsers (play with the number of versions that do not need polyfilling):
```json ```json
"browserslist": { "browserslist": {
"production": [ "production": [
@ -52,20 +57,33 @@ Import your module as :
] ]
} }
``` ```
Also, notice that [BigInt implementation is quite recent](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you will probably need to set `lib`, `target` and/or `module` to `esnext` in your project's `tsconfig.json`.
- JavaScript native browser ES module Also, notice that [BigInt implementation is ES2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you will probably need to set `lib`, `target` and/or `module` to `es2020` in your project's `tsconfig.json`.
If you are using Angular, since this library uses node typings, you should also add them to the `angularCompilerOptions` in your `tsconfig.json`:
```json
"angularCompilerOptions": {
"types": ["node"]
...
}
```
- JavaScript native browser ES module
```html ```html
<script type="module"> <script type="module">
import * as bigintCryptoUtils from 'lib/index.browser.bundle.mod.js' // Use you actual path to the broser mod bundle import * as bigintCryptoUtils from 'index.browser.bundle.mod.js' // Use your actual path to the broser mod bundle that is in the lib directory
... // your code here ... // your code here
</script> </script>
``` ```
- JavaScript native browser IIFE
- JavaScript native browser IIFE
```html ```html
<head> <head>
... ...
<script src="../../lib/index.browser.bundle.iife.js"></script> <!-- Use you actual path to the browser bundle --> <script src="index.browser.bundle.iife.js"></script> <!-- Use your actual path to the browser iife bundle that is in the lib directory -->
</head> </head>
<body> <body>
... ...
@ -116,7 +134,6 @@ primeTesting()
You can find examples in the [examples folder of the repository](https://github.com/juanelas/bigint-crypto-utils/tree/master/examples). You can find examples in the [examples folder of the repository](https://github.com/juanelas/bigint-crypto-utils/tree/master/examples).
## API reference documentation ## API reference documentation
### Functions ### Functions

View File

@ -1,6 +1,6 @@
'use strict' 'use strict'
const resolve = require('@rollup/plugin-node-resolve') const resolve = require('@rollup/plugin-node-resolve').nodeResolve
const replace = require('@rollup/plugin-replace') const replace = require('@rollup/plugin-replace')
const { terser } = require('rollup-plugin-terser') const { terser } = require('rollup-plugin-terser')

View File

@ -1,6 +1,6 @@
'use strict' 'use strict'
const resolve = require('@rollup/plugin-node-resolve') const resolve = require('@rollup/plugin-node-resolve').nodeResolve
const replace = require('@rollup/plugin-replace') const replace = require('@rollup/plugin-replace')
const commonjs = require('@rollup/plugin-commonjs') const commonjs = require('@rollup/plugin-commonjs')
const multi = require('@rollup/plugin-multi-entry') const multi = require('@rollup/plugin-multi-entry')

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2340
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -64,21 +64,21 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^11.1.0", "@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-multi-entry": "^3.0.1", "@rollup/plugin-multi-entry": "^4.0.0",
"@rollup/plugin-node-resolve": "^7.1.3", "@rollup/plugin-node-resolve": "^10.0.0",
"@rollup/plugin-replace": "^2.3.3", "@rollup/plugin-replace": "^2.3.4",
"chai": "^4.2.0", "chai": "^4.2.0",
"jsdoc-to-markdown": "^5.0.3", "jsdoc-to-markdown": "^6.0.1",
"mocha": "^7.2.0", "mocha": "^8.2.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"rollup": "^2.28.1", "rollup": "^2.33.1",
"rollup-plugin-terser": "^5.3.1", "rollup-plugin-terser": "^7.0.2",
"standard": "^14.3.4", "standard": "^16.0.2",
"typescript": "^3.9.7" "typescript": "^3.9.7"
}, },
"dependencies": { "dependencies": {
"@types/node": "^14.11.2" "@types/node": ">=10.4"
} }
} }

View File

@ -26,17 +26,22 @@ NPM installation defaults to the ES6 module for browsers and the CJS one for Nod
Import your module as : Import your module as :
- Node.js - Node.js
```javascript ```javascript
const bigintCryptoUtils = require('bigint-crypto-utils') const bigintCryptoUtils = require('bigint-crypto-utils')
... // your code here ... // your code here
``` ```
- JavaScript native or TypeScript project (including React and Angular JS)
- JavaScript native or TypeScript project (including React and Angular JS)
```javascript ```javascript
import * as bigintCryptoUtils from 'bigint-crypto-utils' import * as bigintCryptoUtils from 'bigint-crypto-utils'
... // your code here ... // your code here
``` ```
`{{PKG_NAME}}` **CANNOT BE POLYFILLED** to suport older browsers. If you are using webpack/babel to create your production bundles, you should target only the most modern browsers. For instance, for **React** apps created with [`create-react-app`](https://create-react-app.dev/), you should edit your `package.json` and modify the `browserList` so that it only targets the latest browsers (supporting the latest features):
`{{PKG_NAME}}` **CANNOT BE POLYFILLED** to suport older browsers. If you are using webpack/babel to create your production bundles, you should target only the most modern browsers. For instance, for **React** apps created with [`create-react-app`](https://create-react-app.dev/), you should edit your `package.json` and modify the `browserList` so that it only targets the latest browsers (play with the number of versions that do not need polyfilling):
```json ```json
"browserslist": { "browserslist": {
"production": [ "production": [
@ -51,20 +56,33 @@ Import your module as :
] ]
} }
``` ```
Also, notice that [BigInt implementation is quite recent](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you will probably need to set `lib`, `target` and/or `module` to `esnext` in your project's `tsconfig.json`.
- JavaScript native browser ES module Also, notice that [BigInt implementation is ES2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you will probably need to set `lib`, `target` and/or `module` to `es2020` in your project's `tsconfig.json`.
If you are using Angular, since this library uses node typings, you should also add them to the `angularCompilerOptions` in your `tsconfig.json`:
```json
"angularCompilerOptions": {
"types": ["node"]
...
}
```
- JavaScript native browser ES module
```html ```html
<script type="module"> <script type="module">
import * as bigintCryptoUtils from 'lib/index.browser.bundle.mod.js' // Use you actual path to the broser mod bundle import * as bigintCryptoUtils from 'index.browser.bundle.mod.js' // Use your actual path to the broser mod bundle that is in the lib directory
... // your code here ... // your code here
</script> </script>
``` ```
- JavaScript native browser IIFE
- JavaScript native browser IIFE
```html ```html
<head> <head>
... ...
<script src="../../lib/index.browser.bundle.iife.js"></script> <!-- Use you actual path to the browser bundle --> <script src="index.browser.bundle.iife.js"></script> <!-- Use your actual path to the browser iife bundle that is in the lib directory -->
</head> </head>
<body> <body>
... ...
@ -115,7 +133,6 @@ primeTesting()
You can find examples in the [examples folder of the repository](https://github.com/juanelas/bigint-crypto-utils/tree/master/examples). You can find examples in the [examples folder of the repository](https://github.com/juanelas/bigint-crypto-utils/tree/master/examples).
## API reference documentation ## API reference documentation
{{>main}} {{>main}}

View File

@ -16,8 +16,8 @@ const inputs = [
bitLength: 2 bitLength: 2
}, },
{ {
value: BigInt(11592217955149597331), value: BigInt('11592217955149597331'),
abs: BigInt(11592217955149597331), abs: BigInt('11592217955149597331'),
bitLength: 64 bitLength: 64
} }
] ]

View File

@ -3,8 +3,8 @@
<head> <head>
<title>bigint-crypto-utils - Mocha Tests</title> <title>bigint-crypto-utils - Mocha Tests</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.1.2/mocha.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/8.2.1/mocha.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.1.2/mocha.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/8.2.1/mocha.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
</head> </head>

View File

@ -50,8 +50,8 @@ const inputs$1 = [
bitLength: 2 bitLength: 2
}, },
{ {
value: BigInt(11592217955149597331), value: BigInt('11592217955149597331'),
abs: BigInt(11592217955149597331), abs: BigInt('11592217955149597331'),
bitLength: 64 bitLength: 64
} }
]; ];

8
types/index.d.ts vendored
View File

@ -155,7 +155,7 @@ export function randBetween(max: bigint, min?: bigint): bigint;
* *
* @returns {Promise<Buffer | Uint8Array>} A Promise that resolves to a Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bits * @returns {Promise<Buffer | Uint8Array>} A Promise that resolves to a Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bits
*/ */
export function randBits(bitLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>; export function randBits(bitLength: number, forceLength?: boolean): Promise<Buffer | Uint8Array>;
/** /**
* Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues() * Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
* @param {number} bitLength The desired number of random bits * @param {number} bitLength The desired number of random bits
@ -165,7 +165,7 @@ export function randBits(bitLength: number, forceLength?: boolean): Promise<Uint
* *
* @returns {Buffer | Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bits * @returns {Buffer | Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bits
*/ */
export function randBitsSync(bitLength: number, forceLength?: boolean): Uint8Array | Buffer; export function randBitsSync(bitLength: number, forceLength?: boolean): Buffer | Uint8Array;
/** /**
* Secure random bytes for both node and browsers. Node version uses crypto.randomBytes() and browser one self.crypto.getRandomValues() * Secure random bytes for both node and browsers. Node version uses crypto.randomBytes() and browser one self.crypto.getRandomValues()
* *
@ -176,7 +176,7 @@ export function randBitsSync(bitLength: number, forceLength?: boolean): Uint8Arr
* *
* @returns {Promise<Buffer | Uint8Array>} A promise that resolves to a Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bytes * @returns {Promise<Buffer | Uint8Array>} A promise that resolves to a Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bytes
*/ */
export function randBytes(byteLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>; export function randBytes(byteLength: number, forceLength?: boolean): Promise<Buffer | Uint8Array>;
/** /**
* Secure random bytes for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues() * Secure random bytes for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
* *
@ -187,7 +187,7 @@ export function randBytes(byteLength: number, forceLength?: boolean): Promise<Ui
* *
* @returns {Buffer | Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bytes * @returns {Buffer | Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bytes
*/ */
export function randBytesSync(byteLength: number, forceLength?: boolean): Uint8Array | Buffer; export function randBytesSync(byteLength: number, forceLength?: boolean): Buffer | Uint8Array;
/** /**
* Finds the smallest positive element that is congruent to a in modulo n * Finds the smallest positive element that is congruent to a in modulo n
* @param {number|bigint} a An integer * @param {number|bigint} a An integer