snarkyjs-elgamal
Version:
This repository implements Elgmal, a partial homomorphic encryption scheme originally described by [Taher Elgamal in 1985](https://caislab.kaist.ac.kr/lecture/2010/spring/cs548/basic/B02.pdf). This implementation includes the original version of Elgamal,
79 lines (78 loc) • 1.69 kB
TypeScript
import { Group, PublicKey, PrivateKey, Field } from 'snarkyjs';
export { ElGamalECC, ElGamalFF, Cipher };
/**
* ElGamal over an elliptic curve.
*/
declare class ElGamalECC {
private static G;
static encrypt(msg: Group, y: PublicKey): {
c: Group;
d: Group;
};
static decrypt({ c, d }: {
c: Group;
d: Group;
}, priv: PrivateKey): Group;
}
declare const Cipher_base: (new (value: {
c1: Field;
c2: Field;
}) => {
c1: Field;
c2: Field;
}) & {
_isStruct: true;
} & import("snarkyjs/dist/node/snarky.js").ProvablePure<{
c1: Field;
c2: Field;
}> & {
toInput: (x: {
c1: Field;
c2: Field;
}) => {
fields?: Field[] | undefined;
packed?: [Field, number][] | undefined;
};
toJSON: (x: {
c1: Field;
c2: Field;
}) => {
c1: string;
c2: string;
};
fromJSON: (x: {
c1: string;
c2: string;
}) => {
c1: Field;
c2: Field;
};
};
declare class Cipher extends Cipher_base {
mul(c2: Cipher): Cipher;
}
/**
* ElGamal over a finite field.
*/
declare class ElGamalFF {
static G: Field;
/**
* Generate a key pair used for encrypting and decrypting.
*/
static generateKeys(): {
pk: Field;
sk: Field;
};
/**
* Encrypts a Field element, with a public key `h`.
* @param m Message
* @param h Public key
*/
static encrypt(m: Field, h: Field): Cipher;
/**
* Decrypts a cipher text, with a private key `x`.
* @param m Message
* @param h Public key
*/
static decrypt({ c1, c2 }: Cipher, x: Field): Field;
}