diff --git a/Cargo.lock b/Cargo.lock index e27929f..a4928b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -312,7 +312,7 @@ checksum = "4d0f2d905ebd295e7effec65e5f6868d153936130ae718352771de3e7d03c75c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -409,7 +409,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -426,7 +426,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "syn-solidity", "tiny-keccak", ] @@ -444,7 +444,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.79", + "syn 2.0.87", "syn-solidity", ] @@ -856,7 +856,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -873,7 +873,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -901,7 +901,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -980,7 +980,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.79", + "syn 2.0.87", "which", ] @@ -1136,15 +1136,18 @@ dependencies = [ "alloy-primitives 0.8.9", "ark-serialize 0.4.2", "async-std", + "base64 0.22.1", "cid 0.8.6", "dotenv", "futures", "hex", "hyper 0.14.30", + "hyper-tls", "ipfs-api-backend-hyper", "rayon", "regex", "rs-car-ipfs", + "serde", "serde_json", "sha2", "signer-eigen", @@ -1467,7 +1470,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.1", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -1487,7 +1490,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "unicode-xid", ] @@ -1831,7 +1834,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2761,7 +2764,7 @@ checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2802,7 +2805,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2939,7 +2942,7 @@ checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3012,7 +3015,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3691,29 +3694,29 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.210" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", @@ -3833,7 +3836,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3887,7 +3890,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3909,9 +3912,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -3927,7 +3930,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -4008,7 +4011,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -4068,7 +4071,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -4206,7 +4209,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -4428,7 +4431,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -4462,7 +4465,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4702,7 +4705,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -4722,5 +4725,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] diff --git a/Cargo.toml b/Cargo.toml index e8848e3..6676855 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ async-std = { version = "1", features = ["attributes", "tokio1"] } advance_runner = {git = "https://github.com/zippiehq/cartesi-advance-runner", rev = "d56ca465282b258e6850fafb411926e90e9e7ff9"} hyper = { version = "0.14", features = ["full"] } hex = "0.4" -serde_json = "1.0.107" +serde_json = "1.0.132" regex = "1.11.0" dotenv = "0.15.0" @@ -21,8 +21,12 @@ futures = "0.3" cid = "0.8.6" alloy-primitives = "0.8.7" rayon = "1.10.0" +serde = "1.0.214" +base64 = "0.22.1" +hyper-tls = "0.6.0" [features] default = [] bls_signing = [ "signer-eigen", ] +nitro_attestation = [] diff --git a/src/main.rs b/src/main.rs index 14c57eb..dd5e0d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,14 +4,19 @@ use alloy_primitives::utils::{keccak256, Keccak256}; use alloy_primitives::B256; use async_std::channel::bounded; use async_std::fs::OpenOptions; +use base64::{prelude::BASE64_STANDARD, Engine}; use cid::Cid; use futures::TryStreamExt; +use hyper::body::to_bytes; use hyper::header::HeaderValue; use hyper::service::{make_service_fn, service_fn}; +use hyper::Method; use hyper::{Body, Client, Request, Response, Server, StatusCode}; +use hyper_tls::HttpsConnector; use ipfs_api_backend_hyper::IpfsApi; use regex::Regex; use rs_car_ipfs::single_file::read_single_file_seek; +use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fs::OpenOptions as StdOpenOptions; use std::io::Error; @@ -181,6 +186,21 @@ async fn main() { "outputs_callback_vector": *outputs_vector, "reports_callback_vector": *reports_vector, }); + + #[cfg(feature = "nitro_attestation")] + { + let data = hyper::body::to_bytes( + serde_json::to_string(&json_response).unwrap(), + ) + .await + .unwrap() + .to_vec(); + + let attestation_doc = get_attestation(data.clone()).await; + json_response["attestation_doc"] = + serde_json::from_slice(&attestation_doc).unwrap(); + } + #[cfg(feature = "bls_signing")] if signing_requested { let bls_private_key_str = std::env::var("BLS_PRIVATE_KEY") @@ -215,7 +235,6 @@ async fn main() { json_response["signature"] = serde_json::Value::String(signature_hex); } - let json_response = serde_json::to_string(&json_response).unwrap(); let response = Response::builder() @@ -447,6 +466,28 @@ async fn main() { println!("Server is listening on {}", addr); server.await.unwrap(); } + +async fn get_attestation>(user_data: T) -> Vec { + let client = Client::new(); + + let uri = "http://localhost:7777/v1/attestation".parse().unwrap(); + + let req_data = AttestationUserData { + user_data: BASE64_STANDARD.encode(user_data), + }; + + let mut req = Request::new(Body::from(serde_json::json!(req_data).to_string())); + + *req.uri_mut() = uri; + *req.method_mut() = Method::POST; + + let response = client.request(req).await.unwrap(); + to_bytes(response.into_body()).await.unwrap().to_vec() +} +#[derive(Debug, Serialize, Deserialize)] +struct AttestationUserData { + user_data: String, +} fn check_hash_format(hash: &str, error_message: &str) -> Result<(), Response> { let hash_regex = Regex::new(r"^[a-f0-9]{64}$").unwrap();