pub trait SparkSignerEcdsa {
// Required methods
fn sign_message_ecdsa_with_identity_key<T: AsRef<[u8]>>(
&self,
message: T,
apply_hashing: bool,
network: Network,
) -> Result<Signature, SparkSdkError>;
fn sign_message_ecdsa_with_key<T: AsRef<[u8]>>(
&self,
message: T,
public_key_for_signing_key: &PublicKey,
apply_hashing: bool,
) -> Result<Signature, SparkSdkError>;
}
Expand description
Trait for ECDSA signing operations in the Spark wallet.
This trait provides methods for creating ECDSA signatures using different keys in the wallet. ECDSA signatures are used for wallet authentication, identity verification, and operations that don’t require threshold signing with Spark Operators.
The trait supports signing with:
- The wallet’s identity key (derived at fixed path m/8797555’/account’/0’)
- Any key in the wallet identified by its public key
All signing methods can optionally apply SHA256 hashing to the message before signing, which is useful for ensuring consistent message format.
Required Methods§
Sourcefn sign_message_ecdsa_with_identity_key<T: AsRef<[u8]>>(
&self,
message: T,
apply_hashing: bool,
network: Network,
) -> Result<Signature, SparkSdkError>
fn sign_message_ecdsa_with_identity_key<T: AsRef<[u8]>>( &self, message: T, apply_hashing: bool, network: Network, ) -> Result<Signature, SparkSdkError>
Signs a message using the wallet’s identity private key.
The identity key is the first derived key from the master seed (using derivation path m/8797555’/account’/0’). This key is used for wallet authentication and identity verification with Spark Operators.
§Arguments
message
- The message to sign. Can be any type that implementsAsRef<[u8]>
, such asVec<u8>
,&[u8]
,String
, etc.apply_hashing
- If true, the message will be hashed using SHA256 before signing. If false, the message will be signed directly, which requires that the message already be 32 bytes.network
- The Bitcoin network to use, which affects the derivation path.
§Returns
Ok(Signature)
- The DER-serialized (non-compact) ECDSA signatureErr(SparkSdkError)
- If signing fails for any reason
§Example
// Sign a message with the identity key
let message = "Authenticate wallet";
let signature = signer.sign_message_ecdsa_with_identity_key(
message,
true, // Apply SHA256 hashing
Network::Bitcoin
)?;
Sourcefn sign_message_ecdsa_with_key<T: AsRef<[u8]>>(
&self,
message: T,
public_key_for_signing_key: &PublicKey,
apply_hashing: bool,
) -> Result<Signature, SparkSdkError>
fn sign_message_ecdsa_with_key<T: AsRef<[u8]>>( &self, message: T, public_key_for_signing_key: &PublicKey, apply_hashing: bool, ) -> Result<Signature, SparkSdkError>
Signs a message using a specified key in the wallet.
This method allows signing with any key in the wallet for which you have the public key. The signer implementation will locate the corresponding private key and use it for signing.
§Arguments
message
- The message to sign. Can be any type that implementsAsRef<[u8]>
, such asVec<u8>
,&[u8]
,String
, etc.public_key_for_signing_key
- The public key corresponding to the private key that should be used for signing. The signer must have access to this private key.apply_hashing
- If true, the message will be hashed using SHA256 before signing. If false, the message will be signed directly, which requires that the message already be 32 bytes.
§Returns
Ok(Signature)
- The DER-serialized (non-compact) ECDSA signatureErr(SparkSdkError)
- If signing fails, typically because the private key corresponding to the public key cannot be found
§Example
// Sign a message with a specific key
let message = "Custom message to sign";
let signature = signer.sign_message_ecdsa_with_key(
message,
&public_key,
true // Apply SHA256 hashing
)?;
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.