threshold-elgamal 0.1.32 → 0.1.34
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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/utils/utils.d.ts +36 -0
- package/dist/utils/utils.js +32 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { generateParameters, encrypt, decrypt } from './elgamal';
|
|
2
2
|
import { generateKeys, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt } from './thresholdElgamal';
|
|
3
3
|
import type { EncryptedMessage, Parameters } from './types';
|
|
4
|
-
import { getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup } from './utils/utils';
|
|
5
|
-
export { generateParameters, encrypt, decrypt, generateKeys, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, };
|
|
4
|
+
import { getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, serializeEncryptedMessage, deserializeEncryptedMessage } from './utils/utils';
|
|
5
|
+
export { generateParameters, encrypt, decrypt, generateKeys, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, serializeEncryptedMessage, deserializeEncryptedMessage, };
|
|
6
6
|
export type { EncryptedMessage, Parameters };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { generateParameters, encrypt, decrypt } from "./elgamal.js";
|
|
2
2
|
import { generateKeys, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, } from "./thresholdElgamal.js";
|
|
3
|
-
import { getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, } from "./utils/utils.js";
|
|
4
|
-
export { generateParameters, encrypt, decrypt, generateKeys, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, };
|
|
3
|
+
import { getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, serializeEncryptedMessage, deserializeEncryptedMessage, } from "./utils/utils.js";
|
|
4
|
+
export { generateParameters, encrypt, decrypt, generateKeys, generateKeyShares, combinePublicKeys, createDecryptionShare, combineDecryptionShares, thresholdDecrypt, getRandomBigIntegerInRange, multiplyEncryptedValues, getGroup, serializeEncryptedMessage, deserializeEncryptedMessage, };
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -49,3 +49,39 @@ export declare const multiplyEncryptedValues: (value1: EncryptedMessage, value2:
|
|
|
49
49
|
* @returns {bigint[]} An array representing the polynomial coefficients `[a0, a1, ..., a_{threshold-1}]`.
|
|
50
50
|
*/
|
|
51
51
|
export declare const generatePolynomial: (threshold: number, prime: bigint) => bigint[];
|
|
52
|
+
/**
|
|
53
|
+
* Serializes an encrypted message into an object with string representations of its components.
|
|
54
|
+
* This function is useful for converting the bigint components of an encrypted message into
|
|
55
|
+
* strings, making them easier to store or transmit as JSON, for instance.
|
|
56
|
+
*
|
|
57
|
+
* @param {EncryptedMessage} message - The encrypted message to be serialized. It should have two bigint properties: `c1` and `c2`.
|
|
58
|
+
* @returns {{ c1: string; c2: string }} An object containing the `c1` and `c2` components of the message as strings.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // An example encrypted message
|
|
62
|
+
* const encryptedMessage = { c1: BigInt('1234567890123456789012345678901234567890'), c2: BigInt('0987654321098765432109876543210987654321') };
|
|
63
|
+
* const serializedMessage = serializeEncryptedMessage(encryptedMessage);
|
|
64
|
+
* console.log(serializedMessage); // Output: { c1: "1234567890123456789012345678901234567890", c2: "0987654321098765432109876543210987654321" }
|
|
65
|
+
*/
|
|
66
|
+
export declare const serializeEncryptedMessage: (message: EncryptedMessage) => {
|
|
67
|
+
c1: string;
|
|
68
|
+
c2: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Deserializes an object containing string representations of an encrypted message's components
|
|
72
|
+
* back into an `EncryptedMessage` with bigint components. This is useful for reconstructing
|
|
73
|
+
* encrypted messages from their stringified forms, such as when retrieving them from JSON data.
|
|
74
|
+
*
|
|
75
|
+
* @param {{ c1: string; c2: string }} message - An object containing the `c1` and `c2` components of the message as strings.
|
|
76
|
+
* @returns {EncryptedMessage} The deserialized encrypted message with `c1` and `c2` as bigints.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* // An example serialized message
|
|
80
|
+
* const serializedMessage = { c1: "1234567890123456789012345678901234567890", c2: "0987654321098765432109876543210987654321" };
|
|
81
|
+
* const encryptedMessage = deserializeEncryptedMessage(serializedMessage);
|
|
82
|
+
* console.log(encryptedMessage); // Output: { c1: 1234567890123456789012345678901234567890n, c2: 0987654321098765432109876543210987654321n }
|
|
83
|
+
*/
|
|
84
|
+
export declare const deserializeEncryptedMessage: (message: {
|
|
85
|
+
c1: string;
|
|
86
|
+
c2: string;
|
|
87
|
+
}) => EncryptedMessage;
|
package/dist/utils/utils.js
CHANGED
|
@@ -61,9 +61,9 @@ export const getRandomBigIntegerInRange = (min, max) => {
|
|
|
61
61
|
const bitsNeeded = range.toString(2).length;
|
|
62
62
|
// Generate a random bigint within the calculated bits
|
|
63
63
|
let num = randomBigint(bitsNeeded);
|
|
64
|
-
// Adjust the number to
|
|
64
|
+
// Adjust the number to the range
|
|
65
65
|
num = num % range;
|
|
66
|
-
// Add the minimum to align with
|
|
66
|
+
// Add the minimum to align with the desired range
|
|
67
67
|
return min + num;
|
|
68
68
|
};
|
|
69
69
|
/**
|
|
@@ -93,3 +93,33 @@ export const generatePolynomial = (threshold, prime) => {
|
|
|
93
93
|
}
|
|
94
94
|
return polynomial;
|
|
95
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Serializes an encrypted message into an object with string representations of its components.
|
|
98
|
+
* This function is useful for converting the bigint components of an encrypted message into
|
|
99
|
+
* strings, making them easier to store or transmit as JSON, for instance.
|
|
100
|
+
*
|
|
101
|
+
* @param {EncryptedMessage} message - The encrypted message to be serialized. It should have two bigint properties: `c1` and `c2`.
|
|
102
|
+
* @returns {{ c1: string; c2: string }} An object containing the `c1` and `c2` components of the message as strings.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // An example encrypted message
|
|
106
|
+
* const encryptedMessage = { c1: BigInt('1234567890123456789012345678901234567890'), c2: BigInt('0987654321098765432109876543210987654321') };
|
|
107
|
+
* const serializedMessage = serializeEncryptedMessage(encryptedMessage);
|
|
108
|
+
* console.log(serializedMessage); // Output: { c1: "1234567890123456789012345678901234567890", c2: "0987654321098765432109876543210987654321" }
|
|
109
|
+
*/
|
|
110
|
+
export const serializeEncryptedMessage = (message) => ({ c1: message.c1.toString(), c2: message.c2.toString() });
|
|
111
|
+
/**
|
|
112
|
+
* Deserializes an object containing string representations of an encrypted message's components
|
|
113
|
+
* back into an `EncryptedMessage` with bigint components. This is useful for reconstructing
|
|
114
|
+
* encrypted messages from their stringified forms, such as when retrieving them from JSON data.
|
|
115
|
+
*
|
|
116
|
+
* @param {{ c1: string; c2: string }} message - An object containing the `c1` and `c2` components of the message as strings.
|
|
117
|
+
* @returns {EncryptedMessage} The deserialized encrypted message with `c1` and `c2` as bigints.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* // An example serialized message
|
|
121
|
+
* const serializedMessage = { c1: "1234567890123456789012345678901234567890", c2: "0987654321098765432109876543210987654321" };
|
|
122
|
+
* const encryptedMessage = deserializeEncryptedMessage(serializedMessage);
|
|
123
|
+
* console.log(encryptedMessage); // Output: { c1: 1234567890123456789012345678901234567890n, c2: 0987654321098765432109876543210987654321n }
|
|
124
|
+
*/
|
|
125
|
+
export const deserializeEncryptedMessage = (message) => ({ c1: BigInt(message.c1), c2: BigInt(message.c2) });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "threshold-elgamal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.34",
|
|
4
4
|
"description": "Threshold ElGamal in TypeScript",
|
|
5
5
|
"author": "Piotr Piech <piotr@piech.dev>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"tsc": "tsc",
|
|
22
22
|
"prebuild": "npm run eslint && npm run tsc && npm run test && del-cli dist",
|
|
23
23
|
"build": "tsc --project tsconfig.build.json",
|
|
24
|
-
"build:skip": "tsc --project tsconfig.build.json",
|
|
24
|
+
"build:skip": "del-cli dist && tsc --project tsconfig.build.json",
|
|
25
25
|
"test": "vitest --watch=false --reporter=verbose",
|
|
26
26
|
"test:watch": "vitest --watch=true --reporter=verbose",
|
|
27
27
|
"pretypedoc": "del-cli 'docs/*' '!docs/_config.yml'",
|