/// Sign a message using a secp256k1 private key
///
/// # Arguments
/// * `msg` is the message to be signed
/// * `sk` is the private key
/// # Errors
/// * `InvalidArgument` if signature generation failed
/// * `MalformedSecretKey` if the private key seems to be invalid
/// * `MalformedSignature` if OpenSSL generated an invalid ECDSA signature
/// # Returns
/// The generated signature
Sign a message using a secp256k1 private key
Sign a message using a secp256k1 private key
pub fn sign(msg: &[u8], sk: &types::SecretKeyBytes) -> CryptoResult<types::SignatureBytes> {
    let signing_key = EcKey::private_key_from_der(sk.0.expose_secret()).map_err(|_| {
        CryptoError::MalformedSecretKey {
            algorithm: AlgorithmId::EcdsaSecp256k1,
            internal_error: "OpenSSL error".to_string(), // don't leak sensitive information
        }
    })?;
    let secp256k1_sig =
        EcdsaSig::sign(msg, &signing_key).map_err(|e| CryptoError::InvalidArgument {
            message: format!("ECDSA signing failed with error {}", e),
        })?;
    let sig_bytes = secp256k1_sig_to_bytes(secp256k1_sig)?;
    Ok(types::SignatureBytes(sig_bytes))
}
pub fn sign ( msg : & [ u8 ] , sk : & types :: SecretKeyBytes ) -> CryptoResult < types :: SignatureBytes > { let signing_key = EcKey :: private_key_from_der ( sk . 0 . expose_secret ( ) ) . map_err ( | _ | { CryptoError :: MalformedSecretKey { algorithm : AlgorithmId :: EcdsaSecp256k1 , internal_error : " " . to_string ( ) , // don't leak sensitive information } } ) ? ; let secp256k1_sig = EcdsaSig :: sign ( msg , & signing_key ) . map_err ( | e | CryptoError :: InvalidArgument { message : format ! ( " " e ) , } ) ? ; let sig_bytes = secp256k1_sig_to_bytes ( secp256k1_sig ) ? ; Ok ( types :: SignatureBytes ( sig_bytes ) ) }
Sign a message using a secp256k1 private key
Sign a message using a secp256k1 private key
The generated signature
The generated signature
msg
&[u8]
sk
&types::SecretKeyBytes
errors
`InvalidArgument` if signature generation failed
`MalformedSecretKey` if the private key seems to be invalid
`MalformedSignature` if OpenSSL generated an invalid ECDSA signature
` InvalidArgument ` if signature generation failed ` MalformedSecretKey ` if the private key seems to be invalid ` MalformedSignature ` if OpenSSL generated an invalid ECDSA signature