diff --git a/src/extractor.rs b/src/extractor.rs index 2bcac36..7b563cb 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -7,6 +7,27 @@ use super::*; const PRAGMA: &str = "pragma circom 2.1.9;\n\n"; +#[derive(Debug, Deserialize)] +pub enum ValueType { + #[serde(rename = "string")] + String, + #[serde(rename = "number")] + Number, +} + +#[derive(Debug, Serialize, Deserialize)] +#[serde(untagged)] +pub enum Key { + String(String), + Num(i64), +} + +#[derive(Debug, Deserialize)] +pub struct Data { + keys: Vec, + value_type: ValueType, +} + fn extract_string(data: Data, circuit_buffer: &mut String) { *circuit_buffer += "template ExtractStringValue(DATA_BYTES, MAX_STACK_HEIGHT, "; for (i, key) in data.keys.iter().enumerate() { diff --git a/src/http_lock.rs b/src/http_lock.rs new file mode 100644 index 0000000..7bf2c24 --- /dev/null +++ b/src/http_lock.rs @@ -0,0 +1,34 @@ +use super::*; + +#[derive(Debug, Serialize, Deserialize)] +struct HttpData { + request: Request, + response: Response, +} + +#[derive(Debug, Serialize, Deserialize)] +struct Request { + method: String, + target: String, + version: String, + headers: Vec<(String, String)>, + #[serde(rename = "Host")] + host: String, +} + +#[derive(Debug, Serialize, Deserialize)] +struct Response { + version: String, + status: String, + headers: Vec<(String, serde_json::Value)>, +} + +// TODO: This needs to codegen a circuit now. +pub fn http_lock(args: HttpLockArgs) -> Result<(), Box> { + let data = std::fs::read(&args.lockfile)?; + let http_data: HttpData = serde_json::from_slice(&data)?; + + dbg!(http_data); + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 1b8a79b..2312c5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use std::{error::Error, path::PathBuf}; pub mod extractor; +pub mod http_lock; pub mod witness; #[derive(Parser, Debug)] @@ -16,6 +17,7 @@ pub struct Args { pub enum Command { Witness(WitnessArgs), Extractor(ExtractorArgs), + HttpLock(HttpLockArgs), } #[derive(Parser, Debug)] @@ -53,30 +55,21 @@ pub struct ExtractorArgs { output_filename: String, } -#[derive(Debug, Deserialize)] -enum ValueType { - #[serde(rename = "string")] - String, - #[serde(rename = "number")] - Number, -} - -#[derive(Debug, Serialize, Deserialize)] -#[serde(untagged)] -enum Key { - String(String), - Num(i64), -} +#[derive(Parser, Debug)] +pub struct HttpLockArgs { + /// Path to the JSON file + #[arg(long)] + lockfile: PathBuf, -#[derive(Debug, Deserialize)] -struct Data { - keys: Vec, - value_type: ValueType, + /// Output circuit file name + #[arg(long, default_value = "extractor")] + output_filename: String, } pub fn main() -> Result<(), Box> { match Args::parse().command { Command::Extractor(args) => extractor::extractor(args), Command::Witness(args) => witness::witness(args), + Command::HttpLock(args) => http_lock::http_lock(args), } }