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(wasm): add missing push_u{512,1024,2048} #1475

Merged
merged 2 commits into from
Aug 19, 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
2 changes: 1 addition & 1 deletion tfhe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tfhe"
version = "0.8.0-alpha.2"
version = "0.8.0-alpha.3"
edition = "2021"
readme = "../README.md"
keywords = ["fully", "homomorphic", "encryption", "fhe", "cryptography"]
Expand Down
9 changes: 8 additions & 1 deletion tfhe/js_on_wasm_tests/test-hlapi-signed.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ test('hlapi_public_key_encrypt_decrypt_int256_small', (t) => {
});



//////////////////////////////////////////////////////////////////////////////
/// 32 bits compact
//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -423,12 +422,14 @@ test('hlapi_compact_ciphertext_list', (t) => {
let clear_i32 = -3284;
let clear_bool = true;
let clear_u256 = generateRandomBigInt(256);
let clear_u2048 = generateRandomBigInt(2048);

let builder = CompactCiphertextList.builder(publicKey);
builder.push_u2(clear_u2);
builder.push_i32(clear_i32);
builder.push_boolean(clear_bool);
builder.push_u256(clear_u256);
builder.push_u2048(clear_u2048);
let list = builder.build();

let serialized = list.safe_serialize(BigInt(10000000));
Expand All @@ -455,6 +456,12 @@ test('hlapi_compact_ciphertext_list', (t) => {
expander.get_uint256(3).decrypt(clientKey),
clear_u256,
);

assert.deepStrictEqual(
expander.get_uint2048(4).decrypt(clientKey),
clear_u2048,
);

});

test('hlapi_compact_ciphertext_list_with_proof', (t) => {
Expand Down
29 changes: 28 additions & 1 deletion tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,33 @@ impl CompactCiphertextListBuilder {
})
}

#[wasm_bindgen]
pub fn push_u512(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U512::try_from(value)?;
self.0.push(value);
Ok(())
})
}

#[wasm_bindgen]
pub fn push_u1024(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U1024::try_from(value)?;
self.0.push(value);
Ok(())
})
}

#[wasm_bindgen]
pub fn push_u2048(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U2048::try_from(value)?;
self.0.push(value);
Ok(())
})
}

#[wasm_bindgen]
pub fn push_i128(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
Expand Down Expand Up @@ -1018,7 +1045,7 @@ macro_rules! define_expander_get_method {
};
}
define_expander_get_method!(
unsigned: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128, 160, 256 }
unsigned: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128, 160, 256, 512, 1024, 2048 }
);
define_expander_get_method!(
signed: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128, 160, 256 }
Expand Down
Loading