~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/zkwid

0
0
main
80 lines · 1.8 KB Raw History
mod did;
mod stage;

pub use did::document;
pub use stage::{run_stage, seed, stage_bytes};

use atproto_identity::key::{KeyData, KeyType, generate_key};
use reqwest::StatusCode;
use serde_json::Value;
use zkwid::lexicon::StrongRef;

#[derive(Clone)]
pub struct Host {
    pub did: String,
    pub base_url: String,
    pub signing_key: KeyData,
    pub n_url: String,
    pub n_did: String,
    pub http: reqwest::Client,
}

#[derive(Clone)]
pub struct Instance {
    pub key: KeyData,
    pub uri: String,
    pub n_url: String,
    pub n_did: String,
    pub http: reqwest::Client,
}

impl Host {
    pub fn new(
        did: &str,
        base_url: &str,
        n_url: &str,
        n_did: &str,
        http: reqwest::Client,
    ) -> anyhow::Result<Self> {
        Ok(Self {
            did: did.to_string(),
            base_url: base_url.to_string(),
            signing_key: generate_key(KeyType::K256Private)?,
            n_url: n_url.to_string(),
            n_did: n_did.to_string(),
            http,
        })
    }

    pub fn router(&self) -> axum::Router {
        did::router(self.did.clone(), self.signing_key.clone())
    }

    pub async fn challenge(&self, _repo: &str, _workload: &StrongRef) -> anyhow::Result<String> {
        todo!()
    }

    pub async fn create_key(
        &self,
        _repo: &str,
        _workload: &StrongRef,
        _stages: &[Vec<u8>],
        _instance: &str,
    ) -> anyhow::Result<Instance> {
        todo!()
    }

    pub async fn delete_key(&self, _uri: &str) -> anyhow::Result<()> {
        todo!()
    }
}

impl Instance {
    pub fn token(&self, _lxm: &str) -> anyhow::Result<String> {
        todo!()
    }

    pub async fn call(&self, _lxm: &str, _body: &Value) -> anyhow::Result<(StatusCode, Value)> {
        todo!()
    }
}