spark_sdk/signer/traits/
ecdsa.rs

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