Skip to content

Commit

Permalink
feat(wasm): add boolean server key primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
IceTDrinker committed Nov 16, 2022
1 parent 1c8f385 commit c39d6ca
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tfhe/src/js_on_wasm_api/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<Vec<u8>, 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<BooleanServerKey, JsError> {
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)
}
}

0 comments on commit c39d6ca

Please sign in to comment.