acta-maker-sdk 0.8.0

Rust SDK for the Acta options RFQ venue on Solana: maker and vault-operator WebSocket clients, order signing, chain builders
Documentation
use std::sync::Arc;

use crate::orders::SignerLike;
use crate::signing::{AsyncSignerLike, SigningError, sign_verified};
use crate::wire::encode_base58;
use crate::ws::types::HelloData;

use super::ManagedWsConfig;

#[derive(Clone)]
pub(crate) enum ChallengeSigning {
    Local(Arc<dyn SignerLike + Send + Sync>),
    Async(Arc<dyn AsyncSignerLike>),
}

impl ChallengeSigning {
    pub(crate) async fn sign(&self, challenge: &str) -> Result<String, SigningError> {
        match self {
            Self::Local(signer) => Ok(signer.sign_message_base58(challenge.as_bytes())),
            Self::Async(signer) => sign_verified(signer.as_ref(), challenge.as_bytes())
                .await
                .map(|signature| encode_base58(&signature)),
        }
    }
}

impl ManagedWsConfig {
    /// Authenticate as maker owner `auth_pubkey`; the async `signer` must be its registered quote-signing key.
    #[must_use]
    pub fn new_async(
        url: impl Into<String>,
        hello: HelloData,
        signer: Arc<dyn AsyncSignerLike>,
        auth_pubkey: impl Into<crate::Address32>,
    ) -> Self {
        Self::new_with_signing(
            url,
            hello,
            auth_pubkey.into(),
            ChallengeSigning::Async(signer),
        )
    }
}