spark_rust/signer/traits/
ecies.rs

1use bitcoin::{
2    secp256k1::{PublicKey, SecretKey},
3    Network,
4};
5
6use crate::error::SparkSdkError;
7
8pub trait SparkSignerEcies {
9    /// Encrypts a secret key using the ECIES algorithm.
10    ///
11    /// # Arguments
12    /// * `receiver_public_key` - The [`PublicKey`] with which to encrypt the secret key.
13    /// * `pubkey_for_sk_to_encrypt` - The [`PublicKey`] corresponding to the [`SecretKey`] to encrypt.
14    ///
15    /// # Returns
16    /// The encrypted [`SecretKey`] as a vector of bytes.
17    fn encrypt_secret_key_with_ecies(
18        &self,
19        receiver_public_key: &PublicKey,
20        pubkey_for_sk_to_encrypt: &PublicKey,
21    ) -> Result<Vec<u8>, SparkSdkError>;
22
23    /// Decrypts a secret key using the ECIES algorithm.
24    ///
25    /// # Arguments
26    /// * `ciphertext` - The ciphertext to decrypt (implements `AsRef<[u8]>`)
27    /// * `network` - The network to use for the decryption key.
28    ///
29    /// # Returns
30    /// The decrypted [`SecretKey`].
31    fn decrypt_secret_key_with_ecies<T>(
32        &self,
33        ciphertext: T,
34        network: Network,
35    ) -> Result<SecretKey, SparkSdkError>
36    where
37        T: AsRef<[u8]>;
38}