Skip to content

Commit

Permalink
Fix test and fmt
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 24, 2024
1 parent 830e6d4 commit 358535a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 24 deletions.
9 changes: 7 additions & 2 deletions src/accumulator/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{utils::{fr_to_jsvalue, random_bytes, set_panic_hook}, Fr, G1Affine};
use crate::{
utils::{fr_to_jsvalue, random_bytes, set_panic_hook},
Fr, G1Affine,
};
use ark_bls12_381::Bls12_381;
use ark_serialize::CanonicalDeserialize;
use blake2::Blake2b512;
Expand Down Expand Up @@ -27,7 +30,9 @@ pub fn generate_accumulator_params(label: Option<Vec<u8>>) -> Result<js_sys::Uin

/// Generate accumulator parameters for keyed-verification. Pass the `label` argument to generate parameters deterministically.
#[wasm_bindgen(js_name = generateAccumulatorParamsForKeyedVerification)]
pub fn generate_accumulator_params_for_keyed_verification(label: Option<Vec<u8>>) -> Result<js_sys::Uint8Array, JsValue> {
pub fn generate_accumulator_params_for_keyed_verification(
label: Option<Vec<u8>>,
) -> Result<js_sys::Uint8Array, JsValue> {
set_panic_hook();
let label = label.unwrap_or_else(random_bytes);
let params = AccumSetupParamsKV::new::<Blake2b512>(&label);
Expand Down
84 changes: 68 additions & 16 deletions src/keyed_proof.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
accumulator::common::AccumSk,
accumulator::common::{AccumPkKV, AccumSetupParamsKV, AccumSk},
bddt16_kvac::{BDDT16MACParams, BDDT16MACPublicKeyG1, BDDT16MACSecretKey},
common::VerifyResponse,
composite_proof_system::Proof,
Expand All @@ -16,18 +16,20 @@ use kvac::bddt_2016::keyed_proof::{
use proof_system::prelude::StatementProof;
use vb_accumulator::{
kb_universal_accumulator::proofs_keyed_verification::{
KBUniversalAccumulatorKeyedMembershipProof as KBUniMemKp, KBUniversalAccumulatorProofOfValidityOfKeyedMembershipProof as KBUniMemPvkp,
KBUniversalAccumulatorKeyedMembershipProof as KBUniMemKp,
KBUniversalAccumulatorKeyedNonMembershipProof as KBUniNonMemKp,
KBUniversalAccumulatorProofOfInvalidityOfKeyedMembershipProof as KBUniMemPivkp,
KBUniversalAccumulatorKeyedNonMembershipProof as KBUniNonMemKp, KBUniversalAccumulatorProofOfValidityOfKeyedNonMembershipProof as KBUniNonMemPvkp,
KBUniversalAccumulatorProofOfInvalidityOfKeyedNonMembershipProof as KBUniNonMemPivkp
KBUniversalAccumulatorProofOfInvalidityOfKeyedNonMembershipProof as KBUniNonMemPivkp,
KBUniversalAccumulatorProofOfValidityOfKeyedMembershipProof as KBUniMemPvkp,
KBUniversalAccumulatorProofOfValidityOfKeyedNonMembershipProof as KBUniNonMemPvkp,
},
proofs_keyed_verification::{
KeyedMembershipProof as VBMemKp, ProofOfValidityOfKeyedMembershipProof as VbMemPvkp, ProofOfInvalidityOfKeyedMembershipProof as VbMemPivkp
KeyedMembershipProof as VBMemKp, ProofOfInvalidityOfKeyedMembershipProof as VbMemPivkp,
ProofOfValidityOfKeyedMembershipProof as VbMemPvkp,
},
};
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
use zeroize::Zeroize;
use crate::accumulator::common::{AccumPkKV, AccumSetupParamsKV};

#[wasm_bindgen(js_name = getAllKeyedSubproofsFromProof)]
pub fn get_all_keyed_subproofs_from_proof(proof: Uint8Array) -> Result<js_sys::Map, JsValue> {
Expand Down Expand Up @@ -233,7 +235,12 @@ pub fn verify_proof_of_validity_of_vb_accum_membership_keyed_proof(
false,
"ProofOfValidityOfVBAccumMembershipKeyedProof"
);
let keyed_proof = obj_from_uint8array!(VBMemKp<G1Affine>, keyed_proof, false, "VBMembershipKeyedProof");
let keyed_proof = obj_from_uint8array!(
VBMemKp<G1Affine>,
keyed_proof,
false,
"VBMembershipKeyedProof"
);
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
to_verify_response!(proof_of_validity.verify::<Blake2b512>(&keyed_proof, &pk, &params))
Expand Down Expand Up @@ -276,7 +283,12 @@ pub fn verify_proof_of_invalidity_of_vb_accum_membership_keyed_proof(
false,
"ProofOfInvalidityOfVBAccumMembershipKeyedProof"
);
let keyed_proof = obj_from_uint8array!(VBMemKp<G1Affine>, keyed_proof, false, "VBMembershipKeyedProof");
let keyed_proof = obj_from_uint8array!(
VBMemKp<G1Affine>,
keyed_proof,
false,
"VBMembershipKeyedProof"
);
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
to_verify_response!(proof_of_invalidity.verify::<Blake2b512>(&keyed_proof, &pk, &params))
Expand Down Expand Up @@ -306,7 +318,12 @@ pub fn proof_of_validity_of_kb_uni_accum_membership_keyed_proof(
params: Uint8Array,
) -> Result<Uint8Array, JsValue> {
set_panic_hook();
let proof = obj_from_uint8array!(KBUniMemKp<G1Affine>, proof, false, "KBUniMembershipKeyedProof");
let proof = obj_from_uint8array!(
KBUniMemKp<G1Affine>,
proof,
false,
"KBUniMembershipKeyedProof"
);
let sk = obj_from_uint8array!(AccumSk, secret_key, true, "VBAccumulatorSk");
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
Expand All @@ -333,7 +350,12 @@ pub fn verify_proof_of_validity_of_kb_uni_accum_membership_keyed_proof(
false,
"ProofOfValidityOfKBUniAccumMembershipKeyedProof"
);
let keyed_proof = obj_from_uint8array!(KBUniMemKp<G1Affine>, keyed_proof, false, "KBUniMembershipKeyedProof");
let keyed_proof = obj_from_uint8array!(
KBUniMemKp<G1Affine>,
keyed_proof,
false,
"KBUniMembershipKeyedProof"
);
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
to_verify_response!(proof_of_validity.verify::<Blake2b512>(&keyed_proof, &pk, &params))
Expand All @@ -347,7 +369,12 @@ pub fn proof_of_invalidity_of_kb_uni_accum_membership_keyed_proof(
params: Uint8Array,
) -> Result<Uint8Array, JsValue> {
set_panic_hook();
let proof = obj_from_uint8array!(KBUniMemKp<G1Affine>, proof, false, "KBUniMembershipKeyedProof");
let proof = obj_from_uint8array!(
KBUniMemKp<G1Affine>,
proof,
false,
"KBUniMembershipKeyedProof"
);
let sk = obj_from_uint8array!(AccumSk, secret_key, true, "VBAccumulatorSk");
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
Expand Down Expand Up @@ -376,7 +403,12 @@ pub fn verify_proof_of_invalidity_of_kb_uni_accum_membership_keyed_proof(
false,
"ProofOfInvalidityOfKBUniAccumMembershipKeyedProof"
);
let keyed_proof = obj_from_uint8array!(KBUniMemKp<G1Affine>, keyed_proof, false, "KBUniMembershipKeyedProof");
let keyed_proof = obj_from_uint8array!(
KBUniMemKp<G1Affine>,
keyed_proof,
false,
"KBUniMembershipKeyedProof"
);
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
to_verify_response!(proof_of_invalidity.verify::<Blake2b512>(&keyed_proof, &pk, &params))
Expand Down Expand Up @@ -406,7 +438,12 @@ pub fn proof_of_validity_of_kb_uni_accum_non_membership_keyed_proof(
params: Uint8Array,
) -> Result<Uint8Array, JsValue> {
set_panic_hook();
let proof = obj_from_uint8array!(KBUniNonMemKp<G1Affine>, proof, false, "KBUniNonMembershipKeyedProof");
let proof = obj_from_uint8array!(
KBUniNonMemKp<G1Affine>,
proof,
false,
"KBUniNonMembershipKeyedProof"
);
let sk = obj_from_uint8array!(AccumSk, secret_key, true, "VBAccumulatorSk");
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
Expand All @@ -433,7 +470,12 @@ pub fn verify_proof_of_validity_of_kb_uni_accum_non_membership_keyed_proof(
false,
"ProofOfValidityOfKBUniAccumNonMembershipKeyedProof"
);
let keyed_proof = obj_from_uint8array!(KBUniNonMemKp<G1Affine>, keyed_proof, false, "KBUniNonMembershipKeyedProof");
let keyed_proof = obj_from_uint8array!(
KBUniNonMemKp<G1Affine>,
keyed_proof,
false,
"KBUniNonMembershipKeyedProof"
);
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
to_verify_response!(proof_of_validity.verify::<Blake2b512>(&keyed_proof, &pk, &params))
Expand All @@ -447,7 +489,12 @@ pub fn proof_of_invalidity_of_kb_uni_accum_non_membership_keyed_proof(
params: Uint8Array,
) -> Result<Uint8Array, JsValue> {
set_panic_hook();
let proof = obj_from_uint8array!(KBUniNonMemKp<G1Affine>, proof, false, "KBUniNonMembershipKeyedProof");
let proof = obj_from_uint8array!(
KBUniNonMemKp<G1Affine>,
proof,
false,
"KBUniNonMembershipKeyedProof"
);
let sk = obj_from_uint8array!(AccumSk, secret_key, true, "VBAccumulatorSk");
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
Expand Down Expand Up @@ -476,7 +523,12 @@ pub fn verify_proof_of_invalidity_of_kb_uni_accum_non_membership_keyed_proof(
false,
"ProofOfInvalidityOfKBUniAccumNonMembershipKeyedProof"
);
let keyed_proof = obj_from_uint8array!(KBUniNonMemKp<G1Affine>, keyed_proof, false, "KBUniNonMembershipKeyedProof");
let keyed_proof = obj_from_uint8array!(
KBUniNonMemKp<G1Affine>,
keyed_proof,
false,
"KBUniNonMembershipKeyedProof"
);
let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1");
let params = obj_from_uint8array!(AccumSetupParamsKV, params, false);
to_verify_response!(proof_of_invalidity.verify::<Blake2b512>(&keyed_proof, &pk, &params))
Expand Down
7 changes: 4 additions & 3 deletions src/threshold_sig/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{
bbs_plus::BBSPlusSigParamsG1,
threshold_sig::{KAPPA, SALT_SIZE, STATISTICAL_SECURITY_PARAMETER},
utils::{
encode_messages_as_js_array_to_fr_vec_in_constant_time, fr_from_uint8_array, get_seeded_rng,
js_array_to_iter, js_set_to_btree_set, set_panic_hook,
encode_messages_as_js_array_to_fr_vec_in_constant_time, fr_from_uint8_array,
get_seeded_rng, js_array_to_iter, js_set_to_btree_set, set_panic_hook,
},
Fr,
};
Expand Down Expand Up @@ -109,7 +109,8 @@ macro_rules! create_signature_share {
($messages: ident, $index_in_output: ident, $phase1_output: ident, $phase2_output: ident, $params: ident, $encode_messages: ident, $params_type: ident, $phase1_output_type: ident, $share_type: ident, $sig_name: expr) => {{
set_panic_hook();
let params: $params_type = serde_wasm_bindgen::from_value($params)?;
let messages = encode_messages_as_js_array_to_fr_vec_in_constant_time(&$messages, $encode_messages)?;
let messages =
encode_messages_as_js_array_to_fr_vec_in_constant_time(&$messages, $encode_messages)?;
let phase1_output = obj_from_uint8array!($phase1_output_type<Fr>, $phase1_output, true);
let phase2_output = obj_from_uint8array!(Phase2Output<Fr>, $phase2_output, true);
let share = $share_type::new(
Expand Down
9 changes: 6 additions & 3 deletions tests/js/thresholdBbsPlusAndBbs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ import {
thresholdBbsPhase2ReceiveMessage1,
thresholdBbsPhase2ReceiveMessage2,
thresholdBbsPhase2Finish,
thresholdBbsCreateSignatureShare, thresholdBbsAggregateSignatureShares
thresholdBbsCreateSignatureShare,
thresholdBbsAggregateSignatureShares,
bbsPlusVerifyG1ConstantTime,
bbsVerifyConstantTime
} from "../../lib";

import {doFrostDKG, stringToBytes} from "./util";
Expand Down Expand Up @@ -257,11 +260,11 @@ describe("For threshold BBS+ and BBS", () => {

it("create a threshold BBS+ signature", () => {
const protocolId = stringToBytes("test BBS+");
checkThresholdSig(protocolId, paramsBbsPlus, thresholdPubkeyBbsPlus, secretKeysBbsPlus, thresholdBbsPlusStartPhase1, thresholdBbsPlusPhase1ProcessCommitments, thresholdBbsPlusPhase1GetSharesForOther, thresholdBbsPlusPhase1ProcessShares, thresholdBbsPlusPhase1Finish, thresholdBbsPlusPhase2Start, thresholdBbsPlusPhase2ReceiveMessage1, thresholdBbsPlusPhase2ReceiveMessage2, thresholdBbsPlusPhase2Finish, thresholdBbsPlusCreateSignatureShare, thresholdBbsPlusAggregateSignatureShares, bbsPlusVerifyG1)
checkThresholdSig(protocolId, paramsBbsPlus, thresholdPubkeyBbsPlus, secretKeysBbsPlus, thresholdBbsPlusStartPhase1, thresholdBbsPlusPhase1ProcessCommitments, thresholdBbsPlusPhase1GetSharesForOther, thresholdBbsPlusPhase1ProcessShares, thresholdBbsPlusPhase1Finish, thresholdBbsPlusPhase2Start, thresholdBbsPlusPhase2ReceiveMessage1, thresholdBbsPlusPhase2ReceiveMessage2, thresholdBbsPlusPhase2Finish, thresholdBbsPlusCreateSignatureShare, thresholdBbsPlusAggregateSignatureShares, bbsPlusVerifyG1ConstantTime)
})

it("create a threshold BBS signature", () => {
const protocolId = stringToBytes("test BBS");
checkThresholdSig(protocolId, paramsBbs, thresholdPubkeyBbs, secretKeysBbs, thresholdBbsStartPhase1, thresholdBbsPhase1ProcessCommitments, thresholdBbsPhase1GetSharesForOther, thresholdBbsPhase1ProcessShares, thresholdBbsPhase1Finish, thresholdBbsPhase2Start, thresholdBbsPhase2ReceiveMessage1, thresholdBbsPhase2ReceiveMessage2, thresholdBbsPhase2Finish, thresholdBbsCreateSignatureShare, thresholdBbsAggregateSignatureShares, bbsVerify)
checkThresholdSig(protocolId, paramsBbs, thresholdPubkeyBbs, secretKeysBbs, thresholdBbsStartPhase1, thresholdBbsPhase1ProcessCommitments, thresholdBbsPhase1GetSharesForOther, thresholdBbsPhase1ProcessShares, thresholdBbsPhase1Finish, thresholdBbsPhase2Start, thresholdBbsPhase2ReceiveMessage1, thresholdBbsPhase2ReceiveMessage2, thresholdBbsPhase2Finish, thresholdBbsCreateSignatureShare, thresholdBbsAggregateSignatureShares, bbsVerifyConstantTime)
})
})

0 comments on commit 358535a

Please sign in to comment.