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

add debug statements that appear in js console #234

Draft
wants to merge 1 commit into
base: v0.3.6-release
Choose a base branch
from
Draft
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
30 changes: 16 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ opt-level = 3
[profile.release.package."rln-wasm"]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
debug = true

[profile.release.package."semaphore"]
codegen-units = 1
3 changes: 3 additions & 0 deletions rln/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ serde_json = "=1.0.96"
serde = { version = "=1.0.163", features = ["derive"] }

include_dir = "=0.7.3"
console_error_panic_hook = "0.1.7"
web-sys = { version = "0.3.69", features = ["console"] }


[dev-dependencies]
sled = "=0.34.7"
Expand Down
21 changes: 21 additions & 0 deletions rln/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,50 @@ pub fn serialize_witness(rln_witness: &RLNWitnessInput) -> Result<Vec<u8>> {
Ok(serialized)
}

extern crate web_sys;

pub fn deserialize_witness(serialized: &[u8]) -> Result<(RLNWitnessInput, usize)> {
let mut all_read: usize = 0;

let (identity_secret, read) = bytes_le_to_fr(&serialized[all_read..]);
all_read += read;
web_sys::console::log_1(&"Read identity secret".into());
web_sys::console::log_1(&identity_secret.to_string().into());
web_sys::console::log_1(&all_read.to_string().into());

let (path_elements, read) = bytes_le_to_vec_fr(&serialized[all_read..])?;
all_read += read;
web_sys::console::log_1(&"Read path elements".into());
web_sys::console::log_1(&format!("{:?}", path_elements).into());
web_sys::console::log_1(&all_read.to_string().into());

let (identity_path_index, read) = bytes_le_to_vec_u8(&serialized[all_read..])?;
all_read += read;
web_sys::console::log_1(&"Read identity path index".into());
web_sys::console::log_1(&format!("{:?}", identity_path_index).into());
web_sys::console::log_1(&all_read.to_string().into());

let (x, read) = bytes_le_to_fr(&serialized[all_read..]);
all_read += read;
web_sys::console::log_1(&"Read x".into());
web_sys::console::log_1(&x.to_string().into());
web_sys::console::log_1(&all_read.to_string().into());

let (epoch, read) = bytes_le_to_fr(&serialized[all_read..]);
all_read += read;
web_sys::console::log_1(&"Read epoch".into());
web_sys::console::log_1(&epoch.to_string().into());
web_sys::console::log_1(&all_read.to_string().into());

let (rln_identifier, read) = bytes_le_to_fr(&serialized[all_read..]);
all_read += read;
web_sys::console::log_1(&"Read rln identifier".into());
web_sys::console::log_1(&rln_identifier.to_string().into());
web_sys::console::log_1(&all_read.to_string().into());

// TODO: check rln_identifier against public::RLN_IDENTIFIER
if serialized.len() != all_read {
web_sys::console::log_1(&"serialized length is not equal to all_read".into());
return Err(Report::msg("serialized length is not equal to all_read"));
}

Expand Down
4 changes: 4 additions & 0 deletions rln/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use color_eyre::{Report, Result};
use num_bigint::BigInt;
use std::io::Cursor;
use utils::{ZerokitMerkleProof, ZerokitMerkleTree};
extern crate console_error_panic_hook;
use std::panic;


cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
Expand Down Expand Up @@ -1191,6 +1194,7 @@ impl RLN<'_> {
///
/// The function returns the corresponding JSON encoding of the input [`RLNWitnessInput`](crate::protocol::RLNWitnessInput) object.
pub fn get_rln_witness_json(&mut self, serialized_witness: &[u8]) -> Result<serde_json::Value> {
panic::set_hook(Box::new(console_error_panic_hook::hook));
let (rln_witness, _) = deserialize_witness(serialized_witness)?;
get_json_inputs(&rln_witness)
}
Expand Down
Loading