openzeppelin_relayer/services/signer/stellar/
mod.rs

1// openzeppelin-relayer/src/services/signer/stellar/mod.rs
2//! Stellar signer implementation (local keystore)
3
4mod local_signer;
5use async_trait::async_trait;
6use local_signer::*;
7
8use crate::{
9    domain::{SignDataRequest, SignDataResponse, SignTransactionResponse, SignTypedDataRequest},
10    models::{Address, NetworkTransactionData, SignerConfig, SignerRepoModel},
11    services::signer::{SignerError, SignerFactoryError},
12    services::Signer,
13};
14
15use super::DataSignerTrait;
16
17pub enum StellarSigner {
18    Local(LocalSigner),
19    Vault(LocalSigner),
20    VaultCloud(LocalSigner),
21}
22
23#[async_trait]
24impl Signer for StellarSigner {
25    async fn address(&self) -> Result<Address, SignerError> {
26        match self {
27            Self::Local(s) | Self::Vault(s) | Self::VaultCloud(s) => s.address().await,
28        }
29    }
30
31    async fn sign_transaction(
32        &self,
33        tx: NetworkTransactionData,
34    ) -> Result<SignTransactionResponse, SignerError> {
35        match self {
36            Self::Local(s) | Self::Vault(s) | Self::VaultCloud(s) => s.sign_transaction(tx).await,
37        }
38    }
39}
40
41pub struct StellarSignerFactory;
42
43impl StellarSignerFactory {
44    pub fn create_stellar_signer(m: &SignerRepoModel) -> Result<StellarSigner, SignerFactoryError> {
45        let signer = match m.config {
46            SignerConfig::Local(_)
47            | SignerConfig::Test(_)
48            | SignerConfig::Vault(_)
49            | SignerConfig::VaultCloud(_) => StellarSigner::Local(LocalSigner::new(m)?),
50            SignerConfig::AwsKms(_) => {
51                return Err(SignerFactoryError::UnsupportedType("AWS KMS".into()))
52            }
53            SignerConfig::VaultTransit(_) => {
54                return Err(SignerFactoryError::UnsupportedType("Vault Transit".into()))
55            }
56            SignerConfig::Turnkey(_) => {
57                return Err(SignerFactoryError::UnsupportedType("Turnkey".into()))
58            }
59            SignerConfig::GoogleCloudKms(_) => {
60                return Err(SignerFactoryError::UnsupportedType(
61                    "Google Cloud KMS".into(),
62                ))
63            }
64        };
65        Ok(signer)
66    }
67}