iop-hydra-sdk 0.0.16

Hydraledger specific modules for the IOP Stack™ SDK
Documentation
use super::*;

pub trait HydraSigner {
    fn sign_hydra_transaction(&self, tx: &mut TransactionData) -> Result<()>;
}

impl HydraSigner for SecpPrivateKey {
    fn sign_hydra_transaction(&self, tx: &mut TransactionData) -> Result<()> {
        ensure!(
            tx.sender_public_key == self.public_key().to_string(),
            "Attempt to sign transaction with key different from tx.sender_public_key"
        );
        let bytes = tx.to_bytes(true, true, false)?;
        let signature = self.sign(&bytes);
        tx.signature = Some(hex::encode(signature.to_der()));
        tx.id = Some(tx.get_id()?);
        Ok(())
    }
}