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.7 to 2.5.0

dist/bigint-crypto-utils-latest.browser.min.js

2

dist/bigint-crypto-utils-latest.browser.mod.min.js

@@ -1,1 +0,1 @@

const _ZERO=BigInt(0),_ONE=BigInt(1),_TWO=BigInt(2);function abs(b){return b=BigInt(b),b>=_ZERO?b:-b}function bitLength(b){if(b=BigInt(b),b===_ONE)return 1;let c=1;do c++;while((b>>=_ONE)>_ONE);return c}function eGcd(c,d){if(c=BigInt(c),d=BigInt(d),c<=_ZERO|d<=_ZERO)return NaN;let e=_ZERO,f=_ONE,g=_ONE,h=_ZERO;for(;c!==_ZERO;){let a=d/c,b=d%c,i=e-g*a,j=f-h*a;d=c,c=b,e=g,f=h,g=i,h=j}return{b:d,x:e,y:f}}function gcd(c,d){if(c=abs(c),d=abs(d),c===_ZERO)return d;if(d===_ZERO)return c;let e=_ZERO;for(;!((c|d)&_ONE);)c>>=_ONE,d>>=_ONE,e++;for(;!(c&_ONE);)c>>=_ONE;do{for(;!(d&_ONE);)d>>=_ONE;if(c>d){let a=c;c=d,d=a}d-=c}while(d);return c<<e}async function isProbablyPrime(a,b=16){return"number"==typeof a&&(a=BigInt(a)),new Promise((c,d)=>{const e=new Worker(_isProbablyPrimeWorkerUrl());e.onmessage=a=>{e.terminate(),c(a.data.isPrime)},e.onmessageerror=a=>{d(a)},e.postMessage({rnd:a,iterations:b,id:0})})}function lcm(c,d){return c=BigInt(c),d=BigInt(d),c===_ZERO&&d===_ZERO?_ZERO:abs(c*d)/gcd(c,d)}function max(c,d){return c=BigInt(c),d=BigInt(d),c>=d?c:d}function min(c,d){return c=BigInt(c),d=BigInt(d),c>=d?d:c}function modInv(b,a){if(b==_ZERO|a<=_ZERO)return NaN;let c=eGcd(toZn(b,a),a);return c.b===_ONE?toZn(c.x,a):NaN}function modPow(a,c,d){if(d=BigInt(d),d===_ZERO)return NaN;if(d===_ONE)return _ZERO;if(a=toZn(a,d),c=BigInt(c),c<_ZERO)return modInv(modPow(a,abs(c),d),d);let f=_ONE;for(;0<c;)c%_TWO===_ONE&&(f=f*a%d),c/=_TWO,a=a**_TWO%d;return f}function prime(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);return new Promise(c=>{let d=[];const e=(e,f)=>{if(e.isPrime){for(let a=0;a<d.length;a++)d[a].terminate();for(;d.length;)d.pop();c(e.value)}else{let c=randBits(a,!0),d=fromBuffer(c);try{f.postMessage({rnd:d,iterations:b,id:e.id})}catch(a){}}};{let a=_isProbablyPrimeWorkerUrl();for(let b,c=0;c<self.navigator.hardwareConcurrency;c++)b=new Worker(a),b.onmessage=a=>e(a.data,b),d.push(b)}for(let e=0;e<d.length;e++){let c=randBits(a,!0),f=fromBuffer(c);d[e].postMessage({rnd:f,iterations:b,id:e})}})}function primeSync(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);let c=_ZERO;do c=fromBuffer(randBytesSync(a/8,!0));while(!_isProbablyPrime(c,b));return c}function randBetween(a,b=_ONE){if(a<=b)throw new Error("max must be > min");const c=a-b;let d,e=bitLength(c);do{let a=randBits(e);d=fromBuffer(a)}while(d>c);return d+b}function randBits(a,b=!1){var c=Math.ceil;if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);const d=c(a/8);let e=randBytesSync(d,!1);if(e[0]&=2**(a%8)-1,b){let b=a%8?2**(a%8-1):128;e[0]|=b}return e}function randBytes(a,b=!1){if(1>a)throw new RangeError(`byteLength MUST be > 0 and it is ${a}`);let c;return new Promise(function(d){c=new Uint8Array(a),self.crypto.getRandomValues(c),b&&(c[0]|=128),d(c)})}function randBytesSync(a,b=!1){if(1>a)throw new RangeError(`byteLength MUST be > 0 and it is ${a}`);let c;return c=new Uint8Array(a),self.crypto.getRandomValues(c),b&&(c[0]|=128),c}function toZn(b,c){return(c=BigInt(c),0>=c)?NaN:(b=BigInt(b)%c,0>b?b+c:b)}function fromBuffer(a){let b=_ZERO;for(let c of a.values()){let a=BigInt(c);b=(b<<BigInt(8))+a}return b}function _isProbablyPrimeWorkerUrl(){let a=`'use strict';const _ZERO = BigInt(0);const _ONE = BigInt(1);const _TWO = BigInt(2);const eGcd = ${eGcd.toString()};const modInv = ${modInv.toString()};const modPow = ${modPow.toString()};const toZn = ${toZn.toString()};const randBits = ${randBits.toString()};const randBytesSync = ${randBytesSync.toString()};const randBetween = ${randBetween.toString()};const isProbablyPrime = ${_isProbablyPrime.toString()};${bitLength.toString()}${fromBuffer.toString()}`;return a+=`onmessage = ${async function(a){const b=await isProbablyPrime(a.data.rnd,a.data.iterations);postMessage({isPrime:b,value:a.data.rnd,id:a.data.id})}.toString()};`,_workerUrl(a)}function _workerUrl(a){a=`(() => {${a}})()`;const b=new Blob([a],{type:"text/javascript"});return window.URL.createObjectURL(b)}function _isProbablyPrime(c,b=16){if(c===_TWO)return!0;if((c&_ONE)===_ZERO||c===_ONE)return!1;const e=[3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597];for(let a=0;a<e.length&&BigInt(e[a])<=c;a++){const b=BigInt(e[a]);if(c===b)return!0;if(c%b===_ZERO)return!1}let f=_ZERO,g=c-_ONE;for(;g%_TWO===_ZERO;)g/=_TWO,++f;let h=(c-_ONE)/_TWO**f;loop:do{let a=randBetween(c-_ONE,_TWO),b=modPow(a,h,c);if(b===_ONE||b===c-_ONE)continue;for(let a=1;a<f;a++){if(b=modPow(b,_TWO,c),b===c-_ONE)continue loop;if(b===_ONE)break}return!1}while(--b);return!0}export{abs,bitLength,eGcd,gcd,isProbablyPrime,lcm,max,min,modInv,modPow,prime,primeSync,randBetween,randBits,randBytes,randBytesSync,toZn};
const _ZERO=BigInt(0),_ONE=BigInt(1),_TWO=BigInt(2);function abs(a){return(a=BigInt(a))>=_ZERO?a:-a}function bitLength(a){if((a=BigInt(a))===_ONE)return 1;let bits=1;do{bits++}while((a>>=_ONE)>_ONE);return bits}function eGcd(a,b){if(a=BigInt(a),b=BigInt(b),a<=_ZERO|b<=_ZERO)return NaN;let x=_ZERO,y=_ONE,u=_ONE,v=_ZERO;for(;a!==_ZERO;){let q=b/a,r=b%a,m=x-u*q,n=y-v*q;b=a,a=r,x=u,y=v,u=m,v=n}return{b:b,x:x,y:y}}function gcd(a,b){if(a=abs(a),b=abs(b),a===_ZERO)return b;if(b===_ZERO)return a;let shift=_ZERO;for(;!((a|b)&_ONE);)a>>=_ONE,b>>=_ONE,shift++;for(;!(a&_ONE);)a>>=_ONE;do{for(;!(b&_ONE);)b>>=_ONE;if(a>b){let x=a;a=b,b=x}b-=a}while(b);return a<<shift}async function isProbablyPrime(w,iterations=16){return"number"==typeof w&&(w=BigInt(w)),new Promise((resolve,reject)=>{const worker=new Worker(_isProbablyPrimeWorkerUrl());worker.onmessage=event=>{worker.terminate(),resolve(event.data.isPrime)},worker.onmessageerror=event=>{reject(event)},worker.postMessage({rnd:w,iterations:iterations,id:0})})}function lcm(a,b){return a=BigInt(a),b=BigInt(b),a===_ZERO&&b===_ZERO?_ZERO:abs(a*b)/gcd(a,b)}function max(a,b){return(a=BigInt(a))>=(b=BigInt(b))?a:b}function min(a,b){return(a=BigInt(a))>=(b=BigInt(b))?b:a}function modInv(a,n){if(a==_ZERO|n<=_ZERO)return NaN;let egcd=eGcd(toZn(a,n),n);return egcd.b!==_ONE?NaN:toZn(egcd.x,n)}function modPow(b,e,n){if((n=BigInt(n))===_ZERO)return NaN;if(n===_ONE)return _ZERO;if(b=toZn(b,n),(e=BigInt(e))<_ZERO)return modInv(modPow(b,abs(e),n),n);let r=_ONE;for(;e>0;)e%_TWO===_ONE&&(r=r*b%n),e/=_TWO,b=b**_TWO%n;return r}function prime(bitLength,iterations=16){if(bitLength<1)throw new RangeError(`bitLength MUST be > 0 and it is ${bitLength}`);return new Promise(resolve=>{let workerList=[];const _onmessage=(msg,newWorker)=>{if(msg.isPrime){for(let j=0;j<workerList.length;j++)workerList[j].terminate();for(;workerList.length;)workerList.pop();resolve(msg.value)}else{let rnd=fromBuffer(randBits(bitLength,!0));try{newWorker.postMessage({rnd:rnd,iterations:iterations,id:msg.id})}catch(error){}}};{let workerURL=_isProbablyPrimeWorkerUrl();for(let i=0;i<self.navigator.hardwareConcurrency;i++){let newWorker=new Worker(workerURL);newWorker.onmessage=event=>_onmessage(event.data,newWorker),workerList.push(newWorker)}}for(let i=0;i<workerList.length;i++){let rnd=fromBuffer(randBits(bitLength,!0));workerList[i].postMessage({rnd:rnd,iterations:iterations,id:i})}})}function primeSync(bitLength,iterations=16){if(bitLength<1)throw new RangeError(`bitLength MUST be > 0 and it is ${bitLength}`);let rnd=_ZERO;do{rnd=fromBuffer(randBytesSync(bitLength/8,!0))}while(!_isProbablyPrime(rnd,iterations));return rnd}function randBetween(max,min=_ONE){if(max<=min)throw new Error("max must be > min");const interval=max-min;let rnd,bitLen=bitLength(interval);do{rnd=fromBuffer(randBits(bitLen))}while(rnd>interval);return rnd+min}function randBits(bitLength,forceLength=!1){if(bitLength<1)throw new RangeError(`bitLength MUST be > 0 and it is ${bitLength}`);let rndBytes=randBytesSync(Math.ceil(bitLength/8),!1);if(rndBytes[0]=rndBytes[0]&2**(bitLength%8)-1,forceLength){let mask=bitLength%8?2**(bitLength%8-1):128;rndBytes[0]=rndBytes[0]|mask}return rndBytes}function randBytes(byteLength,forceLength=!1){if(byteLength<1)throw new RangeError(`byteLength MUST be > 0 and it is ${byteLength}`);let buf;return new Promise((function(resolve){buf=new Uint8Array(byteLength),self.crypto.getRandomValues(buf),forceLength&&(buf[0]=128|buf[0]),resolve(buf)}))}function randBytesSync(byteLength,forceLength=!1){if(byteLength<1)throw new RangeError(`byteLength MUST be > 0 and it is ${byteLength}`);let buf;return buf=new Uint8Array(byteLength),self.crypto.getRandomValues(buf),forceLength&&(buf[0]=128|buf[0]),buf}function toZn(a,n){return(n=BigInt(n))<=0?NaN:(a=BigInt(a)%n)<0?a+n:a}function fromBuffer(buf){let ret=_ZERO;for(let i of buf.values()){let bi=BigInt(i);ret=(ret<<BigInt(8))+bi}return ret}function _isProbablyPrimeWorkerUrl(){let workerCode=`'use strict';const _ZERO = BigInt(0);const _ONE = BigInt(1);const _TWO = BigInt(2);const eGcd = ${eGcd.toString()};const modInv = ${modInv.toString()};const modPow = ${modPow.toString()};const toZn = ${toZn.toString()};const randBits = ${randBits.toString()};const randBytesSync = ${randBytesSync.toString()};const randBetween = ${randBetween.toString()};const isProbablyPrime = ${_isProbablyPrime.toString()};${bitLength.toString()}${fromBuffer.toString()}`;return workerCode+=`onmessage = ${async function(event){const isPrime=await isProbablyPrime(event.data.rnd,event.data.iterations);postMessage({isPrime:isPrime,value:event.data.rnd,id:event.data.id})}.toString()};`,function(workerCode){workerCode=`(() => {${workerCode}})()`;const _blob=new Blob([workerCode],{type:"text/javascript"});return window.URL.createObjectURL(_blob)}(workerCode)}function _isProbablyPrime(w,iterations=16){if(w===_TWO)return!0;if((w&_ONE)===_ZERO||w===_ONE)return!1;const firstPrimes=[3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597];for(let i=0;i<firstPrimes.length&&BigInt(firstPrimes[i])<=w;i++){const p=BigInt(firstPrimes[i]);if(w===p)return!0;if(w%p===_ZERO)return!1}let a=_ZERO,d=w-_ONE;for(;d%_TWO===_ZERO;)d/=_TWO,++a;let m=(w-_ONE)/_TWO**a;loop:do{let z=modPow(randBetween(w-_ONE,_TWO),m,w);if(z!==_ONE&&z!==w-_ONE){for(let j=1;j<a;j++){if(z=modPow(z,_TWO,w),z===w-_ONE)continue loop;if(z===_ONE)break}return!1}}while(--iterations);return!0}export{abs,bitLength,eGcd,gcd,isProbablyPrime,lcm,max,min,modInv,modPow,prime,primeSync,randBetween,randBits,randBytes,randBytesSync,toZn};
{
"name": "bigint-crypto-utils",
"version": "2.4.7",
"version": "2.5.0",
"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.",

@@ -42,2 +42,5 @@ "keywords": [

"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-multi-entry": "^3.0.0",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-replace": "^2.3.1",

@@ -49,9 +52,6 @@ "chai": ">=4.2.0",

"npm-run-all": "^4.1.5",
"rollup": "^1.32.0",
"rollup-plugin-babel-minify": "^9.1.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-multi-entry": ">=2.1.0",
"rollup-plugin-node-resolve": ">=5.2.0",
"rollup": "^2.0.6",
"rollup-plugin-terser": "^5.3.0",
"typescript": "^3.8.3"
}
}

@@ -1,169 +0,21 @@

/**
* 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
*/
export function abs(a: number | bigint): bigint;
/**
* Returns the bitlength of a number
*
* @param {number|bigint} a
* @returns {number} - the bit length
*/
export function bitLength(a: number | bigint): number;
/**
* @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).
*/
export function eGcd(a: number | bigint, b: number | bigint): egcdReturn;
/**
* 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
*/
export function gcd(a: number | bigint, b: number | bigint): bigint;
/**
* 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)
*
* @param {number|bigint} w An integer to be tested for primality
* @param {number} [iterations = 16] The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3
*
* @return {Promise} A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
*/
export function isProbablyPrime(w: number | bigint, iterations?: number): Promise<any>;
/**
* 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
*/
export function lcm(a: number | bigint, b: number | bigint): bigint;
/**
* 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
*/
export function max(a: number | bigint, b: number | bigint): bigint;
/**
* 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
*/
export function min(a: number | bigint, b: number | bigint): bigint;
/**
* 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
*/
export function modInv(a: number | bigint, n: number | bigint): bigint;
/**
* 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
*/
export function modPow(b: number | bigint, e: number | bigint, n: number | bigint): 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).
*
* @param {number} bitLength The required bit length for the generated prime
* @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test
*
* @returns {Promise} A promise that resolves to a bigint probable prime of bitLength bits.
*/
export function prime(bitLength: number, iterations?: number): Promise<any>;
/**
* 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.
*
* @param {number} bitLength The required bit length for the generated prime
* @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test
*
* @returns {bigint} A bigint probable prime of bitLength bits.
*/
export function primeSync(bitLength: number, iterations?: number): bigint;
/**
* Returns a cryptographically secure random integer between [min,max]
* @param {bigint} max Returned value will be <= max
* @param {bigint} [min = BigInt(1)] Returned value will be >= min
*
* @returns {bigint} A cryptographically secure random bigint between [min,max]
*/
export function randBetween(max: bigint, min?: bigint): bigint;
/**
* 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 {boolean} [forceLength = false] If we want to force the output to have a specific bit length. It basically forces the msb to be 1
*
* @returns {Buffer|Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bits
*/
export function randBits(bitLength: number, forceLength?: boolean): Uint8Array | Buffer;
/**
* Secure random bytes for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
*
* @param {number} byteLength The desired number of random bytes
* @param {boolean} [forceLength = false] If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*
* @returns {Promise} 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<any>;
/**
* Secure random bytes for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
*
* @param {number} byteLength The desired number of random bytes
* @param {boolean} [forceLength = false] If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*
* @returns {Buffer|Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bytes
*/
export function randBytesSync(byteLength: number, forceLength?: boolean): Uint8Array | Buffer;
/**
* 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
*/
export function toZn(a: number | bigint, n: number | bigint): bigint;
/**
* A triple (g, x, y), such that ax + by = g = gcd(a, b).
*/
export type egcdReturn = {
g: bigint;
export function abs(a: any): any;
export function bitLength(a: any): number;
export function eGcd(a: any, b: any): number | {
b: any;
x: bigint;
y: bigint;
};
export function gcd(a: any, b: any): any;
export function isProbablyPrime(w: any, iterations?: number): Promise<any>;
export function lcm(a: any, b: any): number | bigint;
export function max(a: any, b: any): any;
export function min(a: any, b: any): any;
export function modInv(a: any, n: any): any;
export function modPow(b: any, e: any, n: any): any;
export function prime(bitLength: any, iterations?: number): Promise<any>;
export function primeSync(bitLength: any, iterations?: number): bigint;
export function randBetween(max: any, min?: bigint): bigint;
export function randBits(bitLength: any, forceLength?: boolean): Uint8Array;
export function randBytes(byteLength: any, forceLength?: boolean): Promise<any>;
export function randBytesSync(byteLength: any, forceLength?: boolean): Uint8Array;
export function toZn(a: any, n: any): any;
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