Skip to content

Commit

Permalink
Add bindings for threshold sig and upgraded wasmer
Browse files Browse the repository at this point in the history
Signed-off-by: lovesh <lovesh.bond@gmail.com>
  • Loading branch information
lovesh committed Jun 23, 2023
1 parent c7fa977 commit ddaf957
Show file tree
Hide file tree
Showing 22 changed files with 2,364 additions and 251 deletions.
461 changes: 308 additions & 153 deletions Cargo.lock

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "dock_crypto_wasm"
repository = "https://github.com/docknetwork/crypto-wasm"
version = "0.14.0"
version = "0.15.0"

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -20,18 +20,20 @@ js-sys = "0.3"
rand = { version = "0.7", features = ["wasm-bindgen"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0"}
serde-wasm-bindgen = "0.4.3"
wasm-bindgen = "= 0.2.84"
serde-wasm-bindgen = "0.4.5"
wasm-bindgen = "= 0.2.86"
dlmalloc = { version = "0.2.4", features = ["global"], optional = true }
bbs_plus = { version = "0.14.0", default-features = false }
vb_accumulator = { version = "0.14.0", default-features = false }
schnorr_pok = { version = "0.11.0", default-features = false }
proof_system = { version = "0.20.0", default-features = false }
coconut-crypto = { version = "0.3.0", default-features = false }
dock_crypto_utils = { version = "0.12.0", default-features = false }
saver = { version = "0.11.0", default-features = false }
legogroth16 = {version = "0.8.0", default-features = false, features = ["circom", "wasmer-js"] }
serde_with = { version = "1.10.0", default-features = false, features = ["macros"] }
bbs_plus = { version = "0.15.0", default-features = false }
vb_accumulator = { version = "0.16.0", default-features = false }
schnorr_pok = { version = "0.13.0", default-features = false }
proof_system = { version = "0.21.0", default-features = false }
coconut-crypto = { version = "0.4.0", default-features = false }
dock_crypto_utils = { version = "0.14.0", default-features = false }
saver = { version = "0.12.0", default-features = false }
legogroth16 = {version = "0.9.0", default-features = false, features = ["circom", "wasmer-js"] }
secret_sharing_and_dkg = { version = "0.6.0", default-features = false }
oblivious_transfer_protocols = { version = "0.2.0", default-features = false}

ark-ec = { version = "^0.4.0", default-features = false }
ark-ff = { version = "^0.4.0", default-features = false }
Expand All @@ -45,12 +47,7 @@ zeroize = { version = "1.6.0", features = ["derive"] }

[dev-dependencies]
wasm-bindgen-test = "0.3.33"

[dev-dependencies.web-sys]
version = "0.3"
features = [
'console'
]
web-sys = { version = "0.3", features = ["console"] }

[profile.dev]
opt-level = 1
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ The above primitives can be combined using the composite proof system. An exampl
different signatures and the message lists. Another example is proving knowledge of the signature and messages and certain message's presence (absence)
in an accumulator. Or the knowledge of 5 signatures and proving certain message is the same in the 5 message lists.

### DKG from FROST

### Threshold BBS+ and BBS

## Getting started

To use this package within your project simply run
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/crypto-wasm",
"version": "0.18.1",
"version": "0.19.0",
"author": "Dock.io",
"license": "Apache-2.0",
"private": false,
Expand Down
8 changes: 2 additions & 6 deletions src/bbs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::utils::{
fr_from_uint8_array, g1_affine_from_uint8_array, g1_affine_to_jsvalue,
g1_affine_to_uint8_array, get_seeded_rng, random_bytes, set_panic_hook,
g1_affine_to_uint8_array, get_seeded_rng, js_set_to_btree_set, random_bytes, set_panic_hook,
};

use bbs_plus::{proof::MessageOrBlinding, setup::MultiMessageSignatureParams};
Expand Down Expand Up @@ -235,11 +235,7 @@ pub fn bbs_initialize_proof_of_knowledge_of_signature(
// TODO: Avoid this hack of passing false, create separate method to parse
let mut blindings = encode_messages_as_js_map_to_fr_btreemap(&blindings, false)?;
let messages = encode_messages_as_js_array_to_fr_vec(&messages, encode_messages)?;
let revealed_indices: BTreeSet<usize> = revealed_indices
.values()
.into_iter()
.map(|i| serde_wasm_bindgen::from_value(i.unwrap()).unwrap())
.collect();
let revealed_indices = js_set_to_btree_set::<usize>(&revealed_indices);
let msg_iter = messages.iter().enumerate().map(|(idx, message)| {
if revealed_indices.contains(&idx) {
MessageOrBlinding::RevealMessage(message)
Expand Down
13 changes: 2 additions & 11 deletions src/bbs_plus.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::{
fr_from_uint8_array, g1_affine_from_uint8_array, g1_affine_to_jsvalue,
g1_affine_to_uint8_array, g2_affine_from_uint8_array, g2_affine_to_jsvalue,
g2_affine_to_uint8_array, get_seeded_rng, random_bytes, set_panic_hook,
g2_affine_to_uint8_array, get_seeded_rng, js_set_to_btree_set, random_bytes, set_panic_hook,
};

use bbs_plus::{proof::MessageOrBlinding, setup::MultiMessageSignatureParams};
Expand Down Expand Up @@ -338,7 +338,6 @@ pub fn bbs_plus_verify_g1(
encode_messages: bool,
) -> Result<JsValue, JsValue> {
set_panic_hook();
// let signature: SigG1 = serde_wasm_bindgen::from_value(signature)?;
let signature = obj_from_uint8array!(BBSPlusSigG1, signature, true);
let pk = obj_from_uint8array!(BBSPlusPublicKeyG2, public_key, false, "BBSPlusPublicKeyG2");
let params: BBSPlusSigParamsG1 = serde_wasm_bindgen::from_value(params)?;
Expand Down Expand Up @@ -410,10 +409,8 @@ pub fn bbs_plus_unblind_sig_g2(
blinding: js_sys::Uint8Array,
) -> Result<js_sys::Uint8Array, JsValue> {
set_panic_hook();
// let signature: SigG2 = serde_wasm_bindgen::from_value(blind_signature)?;
let signature = obj_from_uint8array!(BBSPlusSigG2, blind_signature, true);
let blinding = fr_from_uint8_array(blinding, true)?;
// serde_wasm_bindgen::to_value(&signature.unblind(&blinding).map_err(|e| JsValue::from(e)))
Ok(obj_to_uint8array!(
&signature.unblind(&blinding),
true,
Expand All @@ -431,7 +428,6 @@ pub fn bbs_plus_verify_g2(
) -> Result<JsValue, JsValue> {
set_panic_hook();

// let signature: SigG2 = serde_wasm_bindgen::from_value(signature)?;
let signature = obj_from_uint8array!(BBSPlusSigG2, signature, true);
let pk = obj_from_uint8array!(BBSPlusPublicKeyG1, public_key, false, "BBSPlusPublicKeyG1");
let params: BBSPlusSigParamsG2 = serde_wasm_bindgen::from_value(params)?;
Expand Down Expand Up @@ -467,11 +463,7 @@ pub fn bbs_plus_initialize_proof_of_knowledge_of_signature(
// TODO: Avoid this hack of passing false, create separate method to parse
let mut blindings = encode_messages_as_js_map_to_fr_btreemap(&blindings, false)?;
let messages = encode_messages_as_js_array_to_fr_vec(&messages, encode_messages)?;
let revealed_indices: BTreeSet<usize> = revealed_indices
.values()
.into_iter()
.map(|i| serde_wasm_bindgen::from_value(i.unwrap()).unwrap())
.collect();
let revealed_indices = js_set_to_btree_set::<usize>(&revealed_indices);
let msg_iter = messages.iter().enumerate().map(|(idx, message)| {
if revealed_indices.contains(&idx) {
MessageOrBlinding::RevealMessage(message)
Expand Down Expand Up @@ -500,7 +492,6 @@ pub fn bbs_plus_gen_proof(
let protocol: BBSPlusPoKOfSigProtocol = serde_wasm_bindgen::from_value(protocol)?;
let challenge = fr_from_uint8_array(challenge, false)?;
match protocol.gen_proof(&challenge) {
// Ok(proof) => Ok(serde_wasm_bindgen::to_value(&proof).map_err(|e| JsValue::from(e)).unwrap()),
Ok(proof) => Ok(obj_to_uint8array!(&proof, false, "BBS+ProofG1")),
Err(e) => Err(JsValue::from(&format!("{:?}", e))),
}
Expand Down
Loading

0 comments on commit ddaf957

Please sign in to comment.