solana_keychain/
traits.rs

1//! Core trait definitions for Solana signers
2
3use async_trait::async_trait;
4
5use crate::error::SignerError;
6use crate::sdk_adapter::{Pubkey, Signature, Transaction};
7
8pub type SignedTransaction = (String, Signature);
9
10/// Trait for signing Solana transactions
11///
12/// All signer implementations must implement this trait to provide
13/// a unified interface for transaction signing.
14#[async_trait]
15pub trait SolanaSigner: Send + Sync {
16    /// Get the public key of this signer
17    fn pubkey(&self) -> Pubkey;
18
19    /// Sign a Solana transaction
20    ///
21    /// # Arguments
22    ///
23    /// * `tx` - The transaction to sign (will be modified in place)
24    ///
25    /// # Returns
26    ///
27    /// The base64 encoded transaction and signature
28    async fn sign_transaction(
29        &self,
30        tx: &mut Transaction,
31    ) -> Result<SignedTransaction, SignerError>;
32
33    /// Sign an arbitrary message
34    ///
35    /// # Arguments
36    ///
37    /// * `message` - The message bytes to sign
38    ///
39    /// # Returns
40    ///
41    /// The signature produced by signing the message
42    async fn sign_message(&self, message: &[u8]) -> Result<Signature, SignerError>;
43
44    /// Partially sign a transaction and return it as a base64-encoded string
45    ///
46    /// This method signs the transaction and serializes it with `requireAllSignatures: false`,
47    /// making it suitable for multi-signature workflows where additional signatures will be
48    /// added later.
49    ///
50    /// # Arguments
51    ///
52    /// * `tx` - The transaction to sign (will be modified in place)
53    ///
54    /// # Returns
55    ///
56    /// Base64-encoded partially-signed transaction
57    async fn sign_partial_transaction(
58        &self,
59        tx: &mut Transaction,
60    ) -> Result<SignedTransaction, SignerError>;
61
62    /// Check if the signer is available and healthy
63    ///
64    /// # Returns
65    ///
66    /// `true` if the signer can be used, `false` otherwise
67    async fn is_available(&self) -> bool;
68}