threshold-elgamal 0.1.21 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/elgamal.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { modPow, modInv } from 'bigint-mod-arith';
2
- import { getRandomBigIntegerInRange, getGroup } from './utils';
2
+ import { getRandomBigIntegerInRange, getGroup } from "./utils/utils.js";
3
3
  /**
4
4
  * Generates the parameters for the ElGamal encryption, including the prime, generator,
5
5
  * and key pair (public and private keys).
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { generateParameters, encrypt, decrypt } from './elgamal';
2
2
  import { generateSingleKeyShare, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt } from './thresholdElgamal';
3
3
  import type { EncryptedMessage, Parameters, KeyPair, PartyKeyPair } from './types';
4
- import { getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup } from './utils';
4
+ import { getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup } from './utils/utils';
5
5
  export { generateParameters, encrypt, decrypt, generateSingleKeyShare, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, };
6
6
  export type { EncryptedMessage, Parameters, KeyPair, PartyKeyPair };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { generateParameters, encrypt, decrypt } from './elgamal';
2
- import { generateSingleKeyShare, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, } from './thresholdElgamal';
3
- import { getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, } from './utils';
1
+ import { generateParameters, encrypt, decrypt } from "./elgamal.js";
2
+ import { generateSingleKeyShare, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, } from "./thresholdElgamal.js";
3
+ import { getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, } from "./utils/utils.js";
4
4
  export { generateParameters, encrypt, decrypt, generateSingleKeyShare, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, };
@@ -1,5 +1,5 @@
1
1
  import { modPow, modInv } from 'bigint-mod-arith';
2
- import { generatePolynomial, getGroup } from './utils';
2
+ import { generatePolynomial, getGroup } from "./utils/utils.js";
3
3
  /**
4
4
  * Evaluates a polynomial at a given point using modular arithmetic.
5
5
  *
@@ -1,4 +1,4 @@
1
- import type { PartyKeyPair } from './types';
1
+ import type { PartyKeyPair } from '../types';
2
2
  export declare const getRandomScore: (min?: number, max?: number) => number;
3
3
  export declare const thresholdSetup: (partiesCount: number, threshold: number, primeBits?: 2048 | 3072 | 4096) => {
4
4
  keyShares: PartyKeyPair[];
@@ -1,7 +1,7 @@
1
1
  import { expect } from 'vitest';
2
- import { encrypt } from './elgamal';
3
- import { generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, } from './thresholdElgamal';
4
- import { multiplyEncryptedValues, getGroup } from './utils';
2
+ import { encrypt } from "../elgamal.js";
3
+ import { generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, } from "../thresholdElgamal.js";
4
+ import { multiplyEncryptedValues, getGroup } from "./utils.js";
5
5
  export const getRandomScore = (min = 1, max = 10) => Math.floor(Math.random() * (max - min + 1)) + min;
6
6
  export const thresholdSetup = (partiesCount, threshold, primeBits = 2048) => {
7
7
  const { prime, generator } = getGroup(primeBits);
@@ -1,4 +1,20 @@
1
- import type { EncryptedMessage } from './types';
1
+ import type { EncryptedMessage } from '../types';
2
+ /**
3
+ * Generates a random BigInt of exactly the specified number of bits.
4
+ * The function calculates the required number of hexadecimal digits to represent
5
+ * the given number of bits. It ensures the most significant bit is always set,
6
+ * guaranteeing the BigInt has the exact bit length specified. The remaining
7
+ * bits are filled with random values to complete the desired bit length.
8
+ *
9
+ * @param {number} bits The exact bit length for the generated BigInt.
10
+ * @returns {bigint} A random BigInt of exactly the specified bit length.
11
+ *
12
+ * @example
13
+ * // Generates a random BigInt of exactly 128 bits
14
+ * const randomBigInt = generateRandomBigIntFromBits(128);
15
+ * console.log(randomBigInt);
16
+ */
17
+ export declare const randomBigint: (bits: number) => bigint;
2
18
  /**
3
19
  * Retrieves the group parameters for a given prime bit length.
4
20
  *
@@ -1,5 +1,36 @@
1
- import randomBigint from 'random-bigint';
2
- import { GROUPS } from './constants';
1
+ import { GROUPS } from "../constants.js";
2
+ /**
3
+ * Generates a random BigInt of exactly the specified number of bits.
4
+ * The function calculates the required number of hexadecimal digits to represent
5
+ * the given number of bits. It ensures the most significant bit is always set,
6
+ * guaranteeing the BigInt has the exact bit length specified. The remaining
7
+ * bits are filled with random values to complete the desired bit length.
8
+ *
9
+ * @param {number} bits The exact bit length for the generated BigInt.
10
+ * @returns {bigint} A random BigInt of exactly the specified bit length.
11
+ *
12
+ * @example
13
+ * // Generates a random BigInt of exactly 128 bits
14
+ * const randomBigInt = generateRandomBigIntFromBits(128);
15
+ * console.log(randomBigInt);
16
+ */
17
+ export const randomBigint = (bits) => {
18
+ // Ensure bits is positive and greater than zero to avoid infinite loop
19
+ if (bits <= 0) {
20
+ throw new RangeError('Bit length must be greater than 0');
21
+ }
22
+ // Calculate the number of hexadecimal digits needed
23
+ const hexDigits = Math.ceil(bits / 4);
24
+ // The first hex digit must be between 8 and F (inclusive) to ensure the MSB is set
25
+ const firstDigit = (8 + Math.floor(Math.random() * 8)).toString(16);
26
+ // Generate the remaining hex digits randomly
27
+ const remainingDigits = Array(hexDigits - 1)
28
+ .fill(0)
29
+ .map(() => Math.floor(Math.random() * 16).toString(16))
30
+ .join('');
31
+ // Combine, convert to BigInt, and return
32
+ return BigInt(`0x${firstDigit}${remainingDigits}`);
33
+ };
3
34
  /**
4
35
  * Retrieves the group parameters for a given prime bit length.
5
36
  *
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "threshold-elgamal",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
+ "description": "Threshold ElGamal in TypeScript",
4
5
  "author": "Piotr Piech <piotr@piech.dev>",
5
6
  "license": "MIT",
6
- "description": "Threshold ElGamal in TypeScript",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "repository": {
@@ -15,6 +15,7 @@
15
15
  },
16
16
  "homepage": "https://tenemo.github.io/threshold-elgamal/",
17
17
  "scripts": {
18
+ "prepare": "ts-patch install -s",
18
19
  "eslint": "eslint . -c eslint.config.js",
19
20
  "eslint:fix": "eslint . --fix -c eslint.config.js",
20
21
  "tsc": "tsc",
@@ -28,10 +29,9 @@
28
29
  "prepublish:public": "npm run build && npm run typedoc && git add . && git commit && git push origin && npm version patch",
29
30
  "publish:public": "npm publish --access public"
30
31
  },
31
- "engines": {
32
- "node": ">=20.11.0"
32
+ "dependencies": {
33
+ "bigint-mod-arith": "^3.3.1"
33
34
  },
34
- "type": "module",
35
35
  "devDependencies": {
36
36
  "@eslint/eslintrc": "^3.0.2",
37
37
  "@eslint/js": "^8.57.0",
@@ -52,16 +52,18 @@
52
52
  "globals": "^15.0.0",
53
53
  "prettier": "^3.2.5",
54
54
  "prettier-eslint": "^16.3.0",
55
+ "ts-patch": "^3.1.2",
55
56
  "tsx": "^4.7.2",
56
57
  "typedoc": "^0.25.13",
57
58
  "typedoc-plugin-markdown": "^3.17.1",
58
59
  "typescript": "^5.4.4",
60
+ "typescript-transformer-esm": "^1.1.0",
59
61
  "vitest": "^1.4.0"
60
62
  },
61
- "dependencies": {
62
- "bigint-mod-arith": "^3.3.1",
63
- "random-bigint": "^0.0.1"
63
+ "engines": {
64
+ "node": ">=20.11.0"
64
65
  },
66
+ "type": "module",
65
67
  "keywords": [
66
68
  "cryptography",
67
69
  "security",