{"id":15019400,"url":"https://github.com/juanelas/bigint-crypto-utils","last_synced_at":"2025-05-02T07:31:46.035Z","repository":{"id":34671212,"uuid":"182450241","full_name":"juanelas/bigint-crypto-utils","owner":"juanelas","description":"Utils for working with cryptography using native JS implementation of BigInt. It includes arbitrary precision modular arithmetics, cryptographically secure random numbers and strong probable prime generation/testing. It works with Node.js, and native JS, including React and Angular","archived":false,"fork":false,"pushed_at":"2023-07-18T20:19:34.000Z","size":21609,"stargazers_count":37,"open_issues_count":2,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-29T23:08:18.567Z","etag":null,"topics":["angu","arithmetics","bigint","biginteger","crypto","native-javascript","node","prime","prime-numbers","random","random-number-generators","react","type"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juanelas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-20T20:13:25.000Z","updated_at":"2024-06-01T21:10:17.000Z","dependencies_parsed_at":"2024-06-18T15:18:39.197Z","dependency_job_id":"ece0cfba-abaa-4a4b-af88-acffd5c0d106","html_url":"https://github.com/juanelas/bigint-crypto-utils","commit_stats":{"total_commits":254,"total_committers":5,"mean_commits":50.8,"dds":0.3031496062992126,"last_synced_commit":"7acfd37d61463d2dd4473c7086641daadf71872b"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanelas%2Fbigint-crypto-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanelas%2Fbigint-crypto-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanelas%2Fbigint-crypto-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanelas%2Fbigint-crypto-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juanelas","download_url":"https://codeload.github.com/juanelas/bigint-crypto-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224152666,"owners_count":17264743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angu","arithmetics","bigint","biginteger","crypto","native-javascript","node","prime","prime-numbers","random","random-number-generators","react","type"],"created_at":"2024-09-24T19:53:26.004Z","updated_at":"2024-11-12T16:02:50.882Z","avatar_url":"https://github.com/juanelas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Node.js CI](https://github.com/juanelas/bigint-crypto-utils/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/juanelas/bigint-crypto-utils/actions/workflows/build-and-test.yml)\n[![Coverage Status](https://coveralls.io/repos/github/juanelas/bigint-crypto-utils/badge.svg?branch=main)](https://coveralls.io/github/juanelas/bigint-crypto-utils?branch=main)\n\n# bigint-crypto-utils\n\nArbitrary precision modular arithmetic, cryptographically secure random numbers and strong probable prime generation/testing.\n\nIt relies on the native JS implementation of ([BigInt](https://tc39.es/ecma262/#sec-bigint-objects)). 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 (\u003e=10.4.0). The bundles can be imported directly by the browser or in Angular projects, React apps, Node.js, etc.\n\nSecure random numbers are generated using the native crypto implementation of the browsers ([Web Cryptography API](https://w3c.github.io/webcrypto/)) or [Node.js Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html). Strong probable prime generation and testing use Miller-Rabin primality tests and are automatically sped up using parallel workers both in browsers and Node.js.\n\n\u003e 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).\n\n## Usage\n\n`bigint-crypto-utils` can be imported to your project with `npm`:\n\n```console\nnpm install bigint-crypto-utils\n```\n\nThen either require (Node.js CJS):\n\n```javascript\nconst bigintCryptoUtils = require('bigint-crypto-utils')\n```\n\nor import (JavaScript ES module):\n\n```javascript\nimport * as bigintCryptoUtils from 'bigint-crypto-utils'\n```\n\nThe appropriate version for browser or node is automatically exported.\n\n\u003e `bigint-crypto-utils` uses [ES2020 BigInt](https://tc39.es/ecma262/#sec-bigint-objects), so take into account that:\n\u003e\n\u003e 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.\n\u003e 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`.\n\nYou can also download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/main/dist/bundle.iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/main/dist/bundle.esm.min.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/main/dist/bundle.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/`.\n\nAn example of usage could be (complete examples can be found in the [examples](https://github.com/juanelas/bigint-crypto-utils/tree/master/examples) directory):\n\n```typescript\n/* A BigInt with value 666 can be declared calling the bigint constructor as\nBigInt('666') or with the shorter 666n.\nNotice that you can also pass a number to the constructor, e.g. BigInt(666).\nHowever, it is not recommended since values over 2**53 - 1 won't be safe but\nno warning will be raised.\n*/\nconst a = BigInt('5')\nconst b = BigInt('2')\nconst n = 19n\n\nconsole.log(bigintCryptoUtils.modPow(a, b, n)) // prints 6\n\nconsole.log(bigintCryptoUtils.modInv(2n, 5n)) // prints 3\n\nconsole.log(bigintCryptoUtils.modInv(BigInt('3'), BigInt('5'))) // prints 2\n\nconsole.log(bigintCryptoUtils.randBetween(2n ** 256n)) // prints a cryptographically secure random number between 1 and 2**256 (both included).\n\nasync function primeTesting (): void {\n  // Let us print out a probable prime of 2048 bits\n  console.log(await bigintCryptoUtils.prime(2048))\n\n  // Testing if number is a probable prime (Miller-Rabin)\n  const number = 27n\n  const isPrime = await bigintCryptoUtils.isProbablyPrime(number)\n  if (isPrime === true) {\n    console.log(`${number} is prime`)\n  } else {\n    console.log(`${number} is composite`)\n  }\n}\n\nprimeTesting()\n\n```\n\n## API reference documentation\n\n[Check the API](./docs/API.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanelas%2Fbigint-crypto-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuanelas%2Fbigint-crypto-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanelas%2Fbigint-crypto-utils/lists"}