spark_rust/signer/traits/ecdsa.rs
1use bitcoin::{
2 secp256k1::{ecdsa::Signature, PublicKey},
3 Network,
4};
5
6use crate::error::SparkSdkError;
7
8pub trait SparkSignerEcdsa {
9 /// Signs a message using the identity private key. The identity key is the first derived key from
10 /// the master seed (using child index 0).
11 ///
12 /// Accepts any type that can be treated as a slice of `u8` (e.g. Vec<u8>, &[u8], Arc<Vec<u8>>, etc.).
13 ///
14 /// # Arguments
15 /// * `message` - The message to sign. Must implement `AsRef<[u8]>`.
16 /// * `apply_hashing` - If true, the message will be hashed using SHA256 before signing. If false,
17 /// the message will be signed directly.
18 /// * `network` - The network to use for the signing key.
19 /// # Returns
20 /// The DER-serialized (non-compact) [`Signature`] of the message.
21 fn sign_message_ecdsa_with_identity_key<T: AsRef<[u8]>>(
22 &self,
23 message: T,
24 apply_hashing: bool,
25 network: Network,
26 ) -> Result<Signature, SparkSdkError>;
27
28 /// Signs a message using a provided public key.
29 ///
30 /// Accepts any type that can be treated as a slice of `u8` (e.g. Vec<u8>, &[u8], Arc<Vec<u8>>, etc.).
31 ///
32 /// # Arguments
33 /// * `message` - The message to sign. Must implement `AsRef<[u8]>`.
34 /// * `public_key_for_signing_key` - The public key for the signing key.
35 /// * `apply_hashing` - If true, the message will be hashed using SHA256 before signing. If false,
36 /// the message will be signed directly.
37 ///
38 /// # Returns
39 /// The DER-serialized (non-compact) [`Signature`] of the message.
40 fn sign_message_ecdsa_with_key<T: AsRef<[u8]>>(
41 &self,
42 message: T,
43 public_key_for_signing_key: &PublicKey,
44 apply_hashing: bool,
45 ) -> Result<Signature, SparkSdkError>;
46}