Skip to content

Commit

Permalink
http lock example
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Aug 30, 2024
1 parent 7c74027 commit d0a22c0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
21 changes: 21 additions & 0 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Key>,
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() {
Expand Down
34 changes: 34 additions & 0 deletions src/http_lock.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Error>> {
let data = std::fs::read(&args.lockfile)?;
let http_data: HttpData = serde_json::from_slice(&data)?;

dbg!(http_data);

Ok(())
}
29 changes: 11 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -16,6 +17,7 @@ pub struct Args {
pub enum Command {
Witness(WitnessArgs),
Extractor(ExtractorArgs),
HttpLock(HttpLockArgs),
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -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<Key>,
value_type: ValueType,
/// Output circuit file name
#[arg(long, default_value = "extractor")]
output_filename: String,
}

pub fn main() -> Result<(), Box<dyn Error>> {
match Args::parse().command {
Command::Extractor(args) => extractor::extractor(args),
Command::Witness(args) => witness::witness(args),
Command::HttpLock(args) => http_lock::http_lock(args),
}
}

0 comments on commit d0a22c0

Please sign in to comment.