Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add proven ciphertext #95

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import { createRequire } from 'node:module';

import json from '@rollup/plugin-json';
import url from '@rollup/plugin-url';
import { wasm } from '@rollup/plugin-wasm';
import typescript from '@rollup/plugin-typescript';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import nodePolyfills from 'rollup-plugin-polyfill-node';

const require = createRequire(import.meta.url);

const nodePlugins = [
copy({
targets: [
{
src: './src/kms/node/*',
dest: 'lib/kms/node',
},
{
src: './src/kms/node/kms_lib_bg.wasm',
dest: 'lib/',
},
],
}),
json(),
wasm(),
commonjs(),
typescript({
Expand All @@ -31,19 +21,13 @@ const nodePlugins = [
];

const webPlugins = [
copy({
targets: [
{
src: './src/kms/web/*',
dest: 'lib/kms/web',
},
],
}),
json(),
url(),
nodePolyfills(),
replace({
preventAssignment: true,
'node-tfhe': 'tfhe',
'kms/node': 'kms/web',
'node-tkms': 'tkms',
}),
typescript({
tsconfig: './tsconfig.rollup.json',
Expand All @@ -56,7 +40,7 @@ const webPlugins = [
commonjs(),
resolve({
browser: true,
resolveOnly: ['tfhe'],
resolveOnly: ['tfhe', 'tkms'],
extensions: ['.js', '.ts', '.wasm'],
}),
];
Expand All @@ -71,6 +55,16 @@ export default [
},
plugins: [...webPlugins],
},
{
input:
'./node_modules/tfhe/snippets/wasm-bindgen-rayon-3e04391371ad0a8e/src/workerHelpers.worker.js',
output: {
file: 'lib/workerHelpers.worker.js',
name: 'fhevm',
format: 'es',
},
plugins: [...webPlugins],
},
{
input: 'src/node.ts',
output: {
Expand Down
8 changes: 3 additions & 5 deletions config/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ const web = {
'node-tfhe': 'tfhe/tfhe',
},
fallback: {
'tfhe_bg.wasm': require.resolve('tfhe/tfhe_bg.wasm'),
'node-tfhe': require.resolve('tfhe/tfhe'),
'kms_lib_bg.wasm': require.resolve('../src/kms/web/kms_lib_bg.wasm'),
'tfhe_bg.wasm': require.resolve('tfhe/tfhe_bg.wasm'),
'node-tkms': require.resolve('tkms/kms_lib'),
'kms_lib_bg.wasm': require.resolve('tkms/kms_lib_bg.wasm'),
buffer: require.resolve('buffer/'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
Expand All @@ -72,9 +73,6 @@ const web = {
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
],
};

Expand Down
58 changes: 58 additions & 0 deletions generateKeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env node

import {
TfheCompactPublicKey,
TfheConfigBuilder,
TfheClientKey,
ShortintParameters,
ShortintParametersName,
CompactPkeCrs,
ShortintCompactPublicKeyEncryptionParameters,
ShortintCompactPublicKeyEncryptionParametersName,
} from 'node-tfhe';

import fs from 'fs';

const createTfheKeypair = () => {
const block_params = new ShortintParameters(
ShortintParametersName.PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS,
);
const casting_params = new ShortintCompactPublicKeyEncryptionParameters(
ShortintCompactPublicKeyEncryptionParametersName.SHORTINT_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64,
);
const config = TfheConfigBuilder.default()
.use_custom_parameters(block_params)
.use_dedicated_compact_public_key_parameters(casting_params)
.build();
let clientKey = TfheClientKey.generate(config);
let publicKey = TfheCompactPublicKey.new(clientKey);
fs.writeFileSync('src/test/keys/publicKey.bin', publicKey.serialize());
fs.writeFileSync('src/test/keys/privateKey.bin', clientKey.serialize());
const crs0 = CompactPkeCrs.from_config(config, 4 * 32);
fs.writeFileSync(
'src/test/keys/crs128.bin',
crs0.public_params().serialize(),
);
const crs1 = CompactPkeCrs.from_config(config, 4 * 64);
fs.writeFileSync(
'src/test/keys/crs256.bin',
crs1.public_params().serialize(),
);
const crs2 = CompactPkeCrs.from_config(config, 4 * 128);
fs.writeFileSync(
'src/test/keys/crs512.bin',
crs2.public_params().serialize(),
);
const crs3 = CompactPkeCrs.from_config(config, 4 * 256);
fs.writeFileSync(
'src/test/keys/crs1024.bin',
crs3.public_params().serialize(),
);
const crs4 = CompactPkeCrs.from_config(config, 4 * 512);
fs.writeFileSync(
'src/test/keys/crs2048.bin',
crs4.public_params().serialize(),
);
};

createTfheKeypair();
1 change: 1 addition & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
'!src/node.ts',
'!src/web.ts',
],
setupFiles: ['./setupJest.cjs'],
testRegex: '\\.test\\.tsx?$',
coverageReporters: ['lcov', 'text-summary', 'json'],
transformIgnorePatterns: ['/node_modules/'],
Expand Down
Loading
Loading