brainworm2024 commited on
Commit
5970ba6
·
1 Parent(s): 6c9bf1e

Complete module fix: binary-only, restore proof, clean structure

Browse files
Files changed (3) hide show
  1. src/lib.rs +0 -8
  2. src/main.rs +5 -6
  3. src/proof.rs +14 -2
src/lib.rs DELETED
@@ -1,8 +0,0 @@
1
- pub mod handlers;
2
- pub mod inference;
3
- pub mod shield;
4
- pub mod web3;
5
- pub mod orchestrator;
6
- pub mod proof;
7
- pub mod api;
8
- pub mod federation;
 
 
 
 
 
 
 
 
 
src/main.rs CHANGED
@@ -5,7 +5,6 @@ use tracing_subscriber::EnvFilter;
5
 
6
  mod handlers;
7
  mod inference;
8
- mod lib;
9
  mod shield;
10
  mod web3;
11
  mod orchestrator;
@@ -13,7 +12,8 @@ mod proof;
13
  mod api;
14
  mod federation;
15
 
16
- use rustvital_amd::handlers;
 
17
 
18
  #[derive(Serialize)]
19
  struct StatusResponse {
@@ -29,9 +29,8 @@ async fn main() -> anyhow::Result<()> {
29
  .with_env_filter(EnvFilter::from_default_env().add_directive("rustvital_amd=debug".parse()?))
30
  .init();
31
 
32
- // Init zk-lite signing key (demo key; replace with env var in production)
33
- let demo_key = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
34
- proof::init_signing_key(demo_key);
35
 
36
  let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_string());
37
  let addr = format!("0.0.0.0:{}", port);
@@ -41,7 +40,7 @@ async fn main() -> anyhow::Result<()> {
41
  .route("/", get(serve_ui))
42
  .route("/health", get(|| async { "healthy" }))
43
  .route("/status", get(status))
44
- .route("/triage", post(handlers::triage::handle))
45
  .route("/triage/stream", get(api::stream::triage_stream))
46
  .route("/trigger-federated-tune", post(federation::trigger_tune))
47
  .route("/federation/round", get(federation::latest_round))
 
5
 
6
  mod handlers;
7
  mod inference;
 
8
  mod shield;
9
  mod web3;
10
  mod orchestrator;
 
12
  mod api;
13
  mod federation;
14
 
15
+ // use the handler directly from the crate root, not from a separate library
16
+ use handlers::triage;
17
 
18
  #[derive(Serialize)]
19
  struct StatusResponse {
 
29
  .with_env_filter(EnvFilter::from_default_env().add_directive("rustvital_amd=debug".parse()?))
30
  .init();
31
 
32
+ // Init zk-lite signing key
33
+ proof::init_signing_key("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
 
34
 
35
  let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_string());
36
  let addr = format!("0.0.0.0:{}", port);
 
40
  .route("/", get(serve_ui))
41
  .route("/health", get(|| async { "healthy" }))
42
  .route("/status", get(status))
43
+ .route("/triage", post(triage::handle))
44
  .route("/triage/stream", get(api::stream::triage_stream))
45
  .route("/trigger-federated-tune", post(federation::trigger_tune))
46
  .route("/federation/round", get(federation::latest_round))
src/proof.rs CHANGED
@@ -1,13 +1,25 @@
 
1
  use sha2::{Digest, Sha256};
2
  use crate::shield::redact::PiiMatch;
 
 
 
 
 
 
 
 
3
 
4
  pub fn generate_proof(original: &str, pii_map: &[PiiMatch]) -> String {
 
5
  let mut hasher = Sha256::new();
6
- hasher.update(original.as_bytes());
7
  for m in pii_map {
8
  hasher.update(m.entity_type.as_bytes());
9
  hasher.update(m.original.as_bytes());
10
  hasher.update(m.placeholder.as_bytes());
11
  }
12
- hex::encode(hasher.finalize())
 
 
13
  }
 
1
+ use k256::ecdsa::{SigningKey, Signature, signature::Signer};
2
  use sha2::{Digest, Sha256};
3
  use crate::shield::redact::PiiMatch;
4
+ use std::sync::OnceLock;
5
+
6
+ static SIGNING_KEY: OnceLock<SigningKey> = OnceLock::new();
7
+
8
+ pub fn init_signing_key(hex_key: &str) {
9
+ let key = SigningKey::from_slice(&hex::decode(hex_key).unwrap()).unwrap();
10
+ let _ = SIGNING_KEY.set(key);
11
+ }
12
 
13
  pub fn generate_proof(original: &str, pii_map: &[PiiMatch]) -> String {
14
+ let sk = SIGNING_KEY.get().expect("Signing key not initialised");
15
  let mut hasher = Sha256::new();
16
+ hasher.update(original);
17
  for m in pii_map {
18
  hasher.update(m.entity_type.as_bytes());
19
  hasher.update(m.original.as_bytes());
20
  hasher.update(m.placeholder.as_bytes());
21
  }
22
+ let digest = hasher.finalize();
23
+ let sig: Signature = sk.sign(&digest);
24
+ hex::encode(sig.to_bytes())
25
  }