Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bigint-crypto-utils

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bigint-crypto-utils - npm Package Compare versions

Comparing version 2.4.2 to 2.4.3

8

package.json
{
"name": "bigint-crypto-utils",
"version": "2.4.2",
"version": "2.4.3",
"description": "Utils for working with cryptography using native JS (stage 3) implementation of BigInt. It includes arbitrary precision modular arithmetics, cryptographically secure random numbers and strong probable prime generation/testing.",

@@ -39,8 +39,8 @@ "keywords": [

"devDependencies": {
"@rollup/plugin-replace": "^2.2.1",
"@rollup/plugin-replace": "^2.3.1",
"chai": ">=4.2.0",
"eslint": "^6.5.1",
"eslint": "^6.8.0",
"jsdoc-to-markdown": "^5.0.3",
"mocha": "^6.2.1",
"rollup": "^1.27.13",
"rollup": "^1.31.1",
"rollup-plugin-babel-minify": "^9.1.0",

@@ -47,0 +47,0 @@ "rollup-plugin-commonjs": "^10.1.0",

# bigint-crypto-utils
Utils for working with cryptography using native JS (stage 3) implementation of BigInt. It includes some extra functions to work with modular arithmetics along with secure random numbers and a fast strong probable prime generator/tester (parallelised multi-threaded Miller-Rabin primality test). It can be used by any [Web Browser or webview supporting BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) and with Node.js (>=10.4.0). In the latter case, for multi-threaded primality tests, you should use Node.js v11 or newer or enable at runtime with `node --experimental-worker` with Node.js version >= 10.5.0 and < 11.
Utils for working with cryptography using native JS ([ECMA-262](https://tc39.es/ecma262/#sec-bigint-objects)) implementation of BigInt. It includes some extra functions to work with modular arithmetics along with secure random numbers and a fast strong probable prime generator/tester (parallelised multi-threaded Miller-Rabin primality test). It can be used by any [Web Browser or webview supporting BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) and with Node.js (>=10.4.0). In the latter case, for multi-threaded primality tests, you should use Node.js v11 or newer or enable at runtime with `node --experimental-worker` with Node.js version >= 10.5.0 and < 11.
_The operations supported on BigInts are not constant time. BigInt can be therefore **[unsuitable for use in cryptography](https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html).** Many platforms provide native support for cryptography, such as [Web Cryptography API](https://w3c.github.io/webcrypto/) or [Node.js Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html)._
> The operations supported on BigInts are not constant time. BigInt can be therefore **[unsuitable for use in cryptography](https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html).** Many platforms provide native support for cryptography, such as [Web Cryptography API](https://w3c.github.io/webcrypto/) or [Node.js Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html).
## Installation
bigint-crypto-utils is distributed for [web browsers and/or webviews supporting BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) as an ES6 module or an IIFE file; and for Node.js (>=10.4.0), as a CJS module.
bigint-crypto-utils can be imported to your project with `npm`:
```bash
npm install bigint-crypto-utils
```
NPM installation defaults to the ES6 module for browsers and the CJS one for Node.js.

@@ -18,7 +21,8 @@

## Usage example
## Usage examples
With node js:
### Node.js:
```javascript
const bigintCryptoUtils = require('bigint-crypto-utils');
const bigintCryptoUtils = require("bigint-crypto-utils");

@@ -31,11 +35,11 @@ /* Stage 3 BigInts with value 666 can be declared as BigInt('666')

*/
let a = BigInt('5');
let b = BigInt('2');
let n = BigInt('19');
let a = BigInt("5");
let b = BigInt("2");
let n = BigInt("19");
console.log(bigintCryptoUtils.modPow(a, b, n)); // prints 6
console.log(bigintCryptoUtils.modInv(BigInt('2'), BigInt('5'))); // prints 3
console.log(bigintCryptoUtils.modInv(BigInt("2"), BigInt("5"))); // prints 3
console.log(bigintCryptoUtils.modInv(BigInt('3'), BigInt('5'))); // prints 2
console.log(bigintCryptoUtils.modInv(BigInt("3"), BigInt("5"))); // prints 2

@@ -46,26 +50,28 @@ // Generation of a probable prime of 2048 bits

// Testing if a prime is a probable prime (Miller-Rabin)
if ( await bigintCryptoUtils.isProbablyPrime(prime) )
// code if is prime
if (await bigintCryptoUtils.isProbablyPrime(prime))
// code if is prime
// Get a cryptographically secure random number between 1 and 2**256 bits.
const rnd = bigintCryptoUtils.randBetween(BigInt(2) ** BigInt(256));
// Get a cryptographically secure random number between 1 and 2**256 bits.
const rnd = bigintCryptoUtils.randBetween(BigInt(2) ** BigInt(256));
```
From a browser, you can just load the module in a html page as:
### Javascript native from a browser
You can just load the module in a html page as:
```html
<script type="module">
import * as bigintCryptoUtils from 'bigint-utils-latest.browser.mod.min.js';
import * as bigintCryptoUtils from "bigint-utils-latest.browser.mod.min.js";
let a = BigInt('5');
let b = BigInt('2');
let n = BigInt('19');
let a = BigInt("5");
let b = BigInt("2");
let n = BigInt("19");
console.log(bigintCryptoUtils.modPow(a, b, n)); // prints 6
console.log(bigintCryptoUtils.modInv(BigInt('2'), BigInt('5'))); // prints 3
console.log(bigintCryptoUtils.modInv(BigInt("2"), BigInt("5"))); // prints 3
console.log(bigintCryptoUtils.modInv(BigInt('3'), BigInt('5'))); // prints 2
console.log(bigintCryptoUtils.modInv(BigInt("3"), BigInt("5"))); // prints 2
(async function () {
(async function() {
// Generation of a probable prime of 2018 bits

@@ -76,3 +82,3 @@ const p = await bigintCryptoUtils.prime(2048);

const isPrime = await bigintCryptoUtils.isProbablyPrime(p);
alert(p.toString() + '\nIs prime?\n' + isPrime);
alert(p.toString() + "\nIs prime?\n" + isPrime);

@@ -86,2 +92,6 @@ // Get a cryptographically secure random number between 1 and 2**256 bits.

### TypeScript
BigInt is currently [ECMA-262](https://tc39.es/ecma262/#sec-bigint-objects) and thus in order to use it with TypeScript you should set `lib` (and probably also `target` and `module`) to `esnext` in `tsconfig.json`.
# bigint-crypto-utils JS Doc

@@ -88,0 +98,0 @@

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

'use strict';
// For the browser test builder to work you MUST import them module in a variable that
// For the browser test builder to work you MUST import the module in a variable that
// is the camelised version of the package name.

@@ -5,0 +5,0 @@ const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc