breez_sdk_spark/signer/
mod.rs

1use crate::SdkError;
2use bitcoin::bip32::DerivationPath;
3use bitcoin::hashes::{Hmac, sha256};
4use bitcoin::secp256k1::{self, Message, ecdsa::RecoverableSignature};
5
6#[macros::async_trait]
7pub trait BreezSigner: Send + Sync {
8    /// Returns the identity public key.
9    fn identity_public_key(&self) -> Result<secp256k1::PublicKey, SdkError>;
10
11    /// Signs a pre-hashed message using ECDSA at the given derivation path.
12    ///
13    /// The caller must create the Message from a 32-byte hash digest before calling this method.
14    async fn sign_ecdsa(
15        &self,
16        message: Message,
17        path: &DerivationPath,
18    ) -> Result<secp256k1::ecdsa::Signature, SdkError>;
19
20    /// Signs a pre-hashed message using recoverable ECDSA at the given derivation path.
21    ///
22    /// The caller must create the Message from a 32-byte hash digest before calling.
23    async fn sign_ecdsa_recoverable(
24        &self,
25        message: Message,
26        path: &DerivationPath,
27    ) -> Result<RecoverableSignature, SdkError>;
28
29    async fn encrypt_ecies(
30        &self,
31        message: &[u8],
32        path: &DerivationPath,
33    ) -> Result<Vec<u8>, SdkError>;
34
35    async fn decrypt_ecies(
36        &self,
37        message: &[u8],
38        path: &DerivationPath,
39    ) -> Result<Vec<u8>, SdkError>;
40
41    async fn sign_hash_schnorr(
42        &self,
43        hash: &[u8],
44        path: &DerivationPath,
45    ) -> Result<secp256k1::schnorr::Signature, SdkError>;
46
47    async fn derive_public_key(
48        &self,
49        path: &DerivationPath,
50    ) -> Result<secp256k1::PublicKey, SdkError>;
51
52    async fn generate_random_signing_commitment(
53        &self,
54    ) -> Result<spark_wallet::FrostSigningCommitmentsWithNonces, SdkError>;
55
56    async fn get_public_key_for_node(
57        &self,
58        id: &spark_wallet::TreeNodeId,
59    ) -> Result<secp256k1::PublicKey, SdkError>;
60
61    async fn generate_random_secret(&self) -> Result<spark_wallet::EncryptedSecret, SdkError>;
62
63    async fn static_deposit_secret_encrypted(
64        &self,
65        index: u32,
66    ) -> Result<spark_wallet::SecretSource, SdkError>;
67
68    async fn static_deposit_secret(&self, index: u32) -> Result<secp256k1::SecretKey, SdkError>;
69
70    async fn static_deposit_signing_key(
71        &self,
72        index: u32,
73    ) -> Result<secp256k1::PublicKey, SdkError>;
74
75    async fn subtract_secrets(
76        &self,
77        signing_key: &spark_wallet::SecretSource,
78        new_signing_key: &spark_wallet::SecretSource,
79    ) -> Result<spark_wallet::SecretSource, SdkError>;
80
81    async fn split_secret_with_proofs(
82        &self,
83        secret: &spark_wallet::SecretToSplit,
84        threshold: u32,
85        num_shares: usize,
86    ) -> Result<Vec<spark_wallet::VerifiableSecretShare>, SdkError>;
87
88    async fn encrypt_secret_for_receiver(
89        &self,
90        private_key: &spark_wallet::EncryptedSecret,
91        receiver_public_key: &secp256k1::PublicKey,
92    ) -> Result<Vec<u8>, SdkError>;
93
94    async fn public_key_from_secret(
95        &self,
96        private_key: &spark_wallet::SecretSource,
97    ) -> Result<secp256k1::PublicKey, SdkError>;
98
99    async fn sign_frost<'a>(
100        &self,
101        request: spark_wallet::SignFrostRequest<'a>,
102    ) -> Result<frost_secp256k1_tr::round2::SignatureShare, SdkError>;
103
104    async fn aggregate_frost<'a>(
105        &self,
106        request: spark_wallet::AggregateFrostRequest<'a>,
107    ) -> Result<frost_secp256k1_tr::Signature, SdkError>;
108
109    /// Computes HMAC-SHA256 using a key derived at the given path.
110    async fn hmac_sha256(
111        &self,
112        key_path: &DerivationPath,
113        input: &[u8],
114    ) -> Result<Hmac<sha256::Hash>, SdkError>;
115}
116
117// External signer support - private adapter
118mod adapter;
119mod default_external;
120
121// Public external signer API
122pub mod external;
123pub mod external_types;
124
125// Re-export only the external signer trait and types
126pub use external::ExternalSigner;
127pub use external_types::*;
128
129// Internal-only exports (used by adapter and builder)
130pub(crate) use adapter::ExternalSignerAdapter;
131pub(crate) use default_external::DefaultExternalSigner;
132pub mod breez;
133pub mod lnurl_auth;
134pub mod nostr;
135pub mod rtsync;
136pub mod spark;