From c39d6ca753ef4b8e2b301487184503959586888f Mon Sep 17 00:00:00 2001 From: Arthur Meyre Date: Tue, 15 Nov 2022 10:02:11 +0100 Subject: [PATCH] feat(wasm): add boolean server key primitives --- tfhe/src/js_on_wasm_api/boolean.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tfhe/src/js_on_wasm_api/boolean.rs b/tfhe/src/js_on_wasm_api/boolean.rs index f3d37fd181..fbb5aa51c7 100644 --- a/tfhe/src/js_on_wasm_api/boolean.rs +++ b/tfhe/src/js_on_wasm_api/boolean.rs @@ -14,6 +14,9 @@ pub struct BooleanClientKey(pub(crate) crate::boolean::client_key::ClientKey); #[wasm_bindgen] pub struct BooleanPublicKey(pub(crate) crate::boolean::public_key::PublicKey); +#[wasm_bindgen] +pub struct BooleanServerKey(pub(crate) crate::boolean::server_key::ServerKey); + #[wasm_bindgen] pub struct Boolean {} @@ -118,6 +121,13 @@ impl Boolean { BooleanPublicKey(crate::boolean::public_key::PublicKey::new(&client_key.0)) } + #[wasm_bindgen] + pub fn new_server_key(client_key: &BooleanClientKey) -> BooleanServerKey { + set_hook(Box::new(console_error_panic_hook::hook)); + + BooleanServerKey(crate::boolean::server_key::ServerKey::new(&client_key.0)) + } + #[wasm_bindgen] pub fn encrypt(client_key: &BooleanClientKey, message: bool) -> BooleanCiphertext { set_hook(Box::new(console_error_panic_hook::hook)); @@ -192,4 +202,19 @@ impl Boolean { .map_err(|e| wasm_bindgen::JsError::new(format!("{:?}", e).as_str())) .map(BooleanPublicKey) } + + #[wasm_bindgen] + pub fn serialize_boolean_server_key(server_key: &BooleanServerKey) -> Result, JsError> { + set_hook(Box::new(console_error_panic_hook::hook)); + bincode::serialize(&server_key.0) + .map_err(|e| wasm_bindgen::JsError::new(format!("{:?}", e).as_str())) + } + + #[wasm_bindgen] + pub fn deserialize_boolean_server_key(buffer: &[u8]) -> Result { + set_hook(Box::new(console_error_panic_hook::hook)); + bincode::deserialize(buffer) + .map_err(|e| wasm_bindgen::JsError::new(format!("{:?}", e).as_str())) + .map(BooleanServerKey) + } }