tangle-network / tangle

Modular restaking infrastructure for developers, restakers, and operators.
https://www.tangle.tools/
GNU General Public License v3.0
51 stars 24 forks source link

Update ecdsa signature verification functions #626

Closed salman01zp closed 5 months ago

salman01zp commented 5 months ago

Summary of changes Changes introduced in this pull request:

Following are changes made to store result with original message on chain


pub fn verify_secp256k1_ecdsa_signature<T: Config>(
    msg: &[u8],  // Original message bytes
    signature: &[u8],
    expected_key: &[u8],
    derivation_path: &Option<BoundedVec<u8, T::MaxAdditionalParamsLen>>,
    chain_code: Option<[u8; 32]>
) -> DispatchResult {

    ...
    let signature = k256::ecdsa::Signature::from_slice(signature)
        .map_err(|_| Error::<T>::InvalidSignatureDeserialization)?;

    // Hash message here
    let message = keccak_256(msg);

    ensure!(
        verifying_key.verify_prehash(&message, &signature).map(|_| signature).is_ok(),
        Error::<T>::InvalidSignature
    );
}

Reference issue to close (if applicable)

Closes