keyfork/keyforkd/src/service.rs

66 lines
1.6 KiB
Rust
Raw Normal View History

2023-08-25 06:32:21 +00:00
use std::{future::Future, pin::Pin, task::Poll, sync::Arc};
use keyfork_mnemonic_util::Mnemonic;
use tower::Service;
use thiserror::Error;
use serde::{Serialize, Deserialize};
2023-08-25 06:32:21 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-08-25 06:32:21 +00:00
pub struct DerivablePath {
pub(crate) path: Vec<Vec<u8>>,
2023-08-25 06:32:21 +00:00
}
// TODO: move DerivablePath into a models crate for clients to produce?
/*
impl DerivablePath {
pub fn new(input: &[&[u8]]) -> DerivablePath {
DerivablePath {
path: input
.iter()
.map(|&word| {
// perform path validation
word.to_vec()
})
.collect(),
}
}
}
*/
#[derive(Clone, Debug)]
pub struct Keyforkd {
mnemonic: Arc<Mnemonic>,
}
// Currently, this can't be instantiated, therefore it is a never-type
#[derive(Debug, Error)]
pub enum DerivationError {
}
impl Keyforkd {
pub fn new(mnemonic: Mnemonic) -> Self {
Self { mnemonic: Arc::new(mnemonic) }
}
}
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![]) })
}
}