keyfork/keyforkd/src/service.rs

45 lines
1.1 KiB
Rust
Raw Normal View History

2023-08-25 09:28:47 +00:00
use std::{future::Future, pin::Pin, sync::Arc, task::Poll};
2023-08-25 06:32:21 +00:00
2023-08-25 09:27:16 +00:00
use keyfork_derive_util::DerivablePath;
2023-08-25 09:28:47 +00:00
use keyfork_mnemonic_util::Mnemonic;
2023-08-25 06:32:21 +00:00
use thiserror::Error;
2023-08-25 09:28:47 +00:00
use tower::Service;
2023-08-25 06:32:21 +00:00
#[derive(Clone, Debug)]
pub struct Keyforkd {
mnemonic: Arc<Mnemonic>,
}
// Currently, this can't be instantiated, therefore it is a never-type
#[derive(Debug, Error)]
2023-08-25 09:28:47 +00:00
pub enum DerivationError {}
2023-08-25 06:32:21 +00:00
impl Keyforkd {
pub fn new(mnemonic: Mnemonic) -> Self {
2023-08-25 09:28:47 +00:00
Self {
mnemonic: Arc::new(mnemonic),
}
2023-08-25 06:32:21 +00:00
}
}
impl Service<DerivablePath> for Keyforkd {
type Response = Vec<u8>;
type Error = DerivationError;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(
&mut self,
_cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))]
fn call(&mut self, req: DerivablePath) -> Self::Future {
dbg!(&req, &self.mnemonic);
Box::pin(async { Ok(vec![]) })
}
}