@getanthill/datastore
Version:
Event-Sourced Datastore
78 lines (77 loc) • 2.91 kB
TypeScript
/**
* @credits https://github.com/s0l0ist/node-seal
*
* @see https://medium.com/@s0l0ist/homomorphic-encryption-for-web-apps-a3fa52e9f03d
* @see https://medium.com/@s0l0ist/homomorphic-encryption-for-web-apps-b615fb64d2a2
*/
import type { SEALLibrary } from 'node-seal/implementation/seal';
import type { CipherText } from 'node-seal/implementation/cipher-text';
import type { PlainText } from 'node-seal/implementation/plain-text';
import { Context } from 'node-seal/implementation/context';
import { SecretKey } from 'node-seal/implementation/secret-key';
import { PublicKey } from 'node-seal/implementation/public-key';
import { KeyGenerator } from 'node-seal/implementation/key-generator';
import { RelinKeys } from 'node-seal/implementation/relin-keys';
import { GaloisKeys } from 'node-seal/implementation/galois-keys';
import { Evaluator } from 'node-seal/implementation/evaluator';
interface Deletable {
delete: Function;
}
export interface FullyHomomorphicEncryptionClientConfig {
scheme?: 'bfv' | 'bgv' | 'ckks';
polyModulusDegree?: number;
bitSize?: number;
bitSizes?: Array<number>;
}
export default class FullyHomomorphicEncryptionClient {
private _config;
private _seal;
private _context;
private _keys;
private _evaluator;
/**
* @see https://github.com/s0l0ist/node-seal?tab=readme-ov-file#caveats
* Must have a `delete()` method
*/
private _instances;
/**
* Sample cipher instance to test the constructor equality
* @see computeFromAny()
*/
private _cipherSample;
private _encoder;
constructor(config: FullyHomomorphicEncryptionClientConfig);
/**
* @see https://github.com/s0l0ist/node-seal
*/
connect(): Promise<this | undefined>;
init(): Promise<this>;
disconnect(): Promise<this>;
clone(): Promise<FullyHomomorphicEncryptionClient>;
get seal(): SEALLibrary;
get context(): Context | null;
get keys(): {
secret: SecretKey;
public: PublicKey;
relin: RelinKeys;
galois: GaloisKeys;
} | null;
get scheme(): "bgv" | "bfv" | "ckks";
get bitSize(): number;
get bitSizes(): number[];
get polyModulusDegree(): number;
get evaluator(): Evaluator;
addInstance(instance: Deletable): void;
flushInstances(): void;
createKeys(_keyGenerator?: KeyGenerator): void;
encode(arr: Array<number>): void | PlainText;
createCypher(value: Array<number>): CipherText;
decode(plainText: PlainText): Array<number>;
fromCypher(cypher: CipherText): Array<number>;
computeFromAnyToCiphers(handler: Function, ...args: Array<any>): Promise<any>;
computeFromAny(handler: Function, ...args: Array<any>): Promise<any>;
compute(handler: Function, ..._args: Array<string>): Promise<any>;
compile(script: string): any;
relinearize(val: CipherText): void | CipherText;
}
export {};