spark_sdk/signer/traits/
mod.rs

1use crate::error::SparkSdkError;
2
3// Signer traits
4use crate::signer::traits::ecdsa::SparkSignerEcdsa;
5use crate::signer::traits::ecies::SparkSignerEcies;
6use crate::signer::traits::frost::SparkSignerFrost;
7use crate::signer::traits::frost_signing::SparkSignerFrostSigning;
8use crate::signer::traits::secp256k1::SparkSignerSecp256k1;
9use crate::signer::traits::shamir::SparkSignerShamir;
10
11use crate::SparkNetwork;
12
13use tonic::async_trait;
14use uuid::Uuid;
15
16pub mod ecdsa;
17pub mod ecies;
18pub mod frost;
19pub mod frost_signing;
20pub mod secp256k1;
21pub mod shamir;
22
23#[async_trait]
24pub trait SparkSigner:
25    SparkSignerShamir
26    + SparkSignerEcdsa
27    + SparkSignerEcies
28    + SparkSignerFrost
29    + SparkSignerSecp256k1
30    + SparkSignerFrostSigning
31{
32    /// The constructed signer type, wrapped in an Arc<parking_lot::RwLock<>>
33    type WrappedSigner: Sized;
34
35    /// Creates a new signer instance from a mnemonic (BIP-39).
36    ///
37    /// # Arguments
38    /// * `mnemonic` - The mnemonic to derive keys from
39    ///
40    /// # Returns
41    /// A new instance of Self
42    #[cfg(feature = "self-signing")]
43    async fn from_mnemonic(
44        mnemonic: &str,
45        network: SparkNetwork,
46    ) -> Result<Self::WrappedSigner, SparkSdkError>;
47
48    /// Creates a new signer instance from a seed.
49    ///
50    /// # Arguments
51    /// * `seed` - The seed bytes to derive keys from
52    ///
53    /// # Returns
54    /// A new instance of Self
55    #[cfg(feature = "self-signing")]
56    async fn from_master_seed(
57        master_seed: &[u8],
58        network: SparkNetwork,
59    ) -> Result<Self::WrappedSigner, SparkSdkError>;
60
61    /// Creates a new signer instance from a remote signer.
62    ///
63    /// # Returns
64    /// The remote signer returns the wallet public key as well as a user identifier for the wallet. The function constructs a new instance of Self using the public key.
65    #[cfg(not(feature = "self-signing"))]
66    async fn new_remote(
67        signer_url: &str,
68        wallet_id: &str,
69        user_public_key_hex: &str,
70    ) -> Result<Self::WrappedSigner, SparkSdkError>;
71
72    /// Derives a signing key from a leaf ID.
73    ///
74    /// # Arguments
75    /// * `leaf_id` - The leaf ID to derive the signing key from
76    ///
77    /// # Returns
78    /// The signing key as a 32-byte array of [`Vec<u8>`]
79    fn derive_signing_key_from_leaf(&self, leaf_id: Uuid) -> Result<Vec<u8>, SparkSdkError>;
80}