Skip to main content

acta_maker_sdk/ws/managed/
signer.rs

1use std::sync::Arc;
2
3use crate::orders::SignerLike;
4use crate::signing::{AsyncSignerLike, SigningError, sign_verified};
5use crate::wire::encode_base58;
6use crate::ws::types::HelloData;
7
8use super::ManagedWsConfig;
9
10#[derive(Clone)]
11pub(crate) enum ChallengeSigning {
12    Local(Arc<dyn SignerLike + Send + Sync>),
13    Async(Arc<dyn AsyncSignerLike>),
14}
15
16impl ChallengeSigning {
17    pub(crate) async fn sign(&self, challenge: &str) -> Result<String, SigningError> {
18        match self {
19            Self::Local(signer) => Ok(signer.sign_message_base58(challenge.as_bytes())),
20            Self::Async(signer) => sign_verified(signer.as_ref(), challenge.as_bytes())
21                .await
22                .map(|signature| encode_base58(&signature)),
23        }
24    }
25}
26
27impl ManagedWsConfig {
28    /// Authenticate as maker owner `auth_pubkey`; the async `signer` must be its registered quote-signing key.
29    #[must_use]
30    pub fn new_async(
31        url: impl Into<String>,
32        hello: HelloData,
33        signer: Arc<dyn AsyncSignerLike>,
34        auth_pubkey: impl Into<crate::Address32>,
35    ) -> Self {
36        Self::new_with_signing(
37            url,
38            hello,
39            auth_pubkey.into(),
40            ChallengeSigning::Async(signer),
41        )
42    }
43}