[][src]Function grin_core::libtx::aggsig::verify_single_from_commit

pub fn verify_single_from_commit(
    secp: &Secp256k1,
    sig: &Signature,
    msg: &Message,
    commit: &Commitment
) -> Result<(), Error>

Simple verification a single signature from a commitment. The public key used to verify the signature is derived from the commit. Returns Ok(()) if the signature is valid, or a Signature ErrorKind otherwise

Arguments

  • secp - A Secp256k1 Context initialized for Verification
  • sig - The Signature to verify
  • msg - The message to sign (fee|lockheight).
  • commit - The commitment to verify. The actual public key used during verification is derived from this commit.

Example

use core::consensus::reward;
use core::libtx::{aggsig, proof};
use util::secp::key::{PublicKey, SecretKey};
use util::secp::{ContextFlag, Secp256k1};
use core::core::transaction::{kernel_sig_msg, KernelFeatures};
use core::core::{Output, OutputFeatures};
use keychain::{Keychain, ExtKeychain, SwitchCommitmentType};

// Create signature
let secp = Secp256k1::with_caps(ContextFlag::Commit);
let keychain = ExtKeychain::from_random_seed(false).unwrap();
let fees = 10_000;
let value = reward(fees);
let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
let switch = &SwitchCommitmentType::Regular;
let commit = keychain.commit(value, &key_id, switch).unwrap();
let builder = proof::ProofBuilder::new(&keychain);
let rproof = proof::create(&keychain, &builder, value, &key_id, switch, commit, None).unwrap();
let output = Output {
	features: OutputFeatures::Coinbase,
	commit: commit,
	proof: rproof,
};
let height = 20;
let over_commit = secp.commit_value(reward(fees)).unwrap();
let out_commit = output.commitment();
let msg = kernel_sig_msg(0, height, KernelFeatures::HeightLocked).unwrap();
let excess = secp.commit_sum(vec![out_commit], vec![over_commit]).unwrap();
let pubkey = excess.to_pubkey(&secp).unwrap();
let sig = aggsig::sign_from_key_id(&secp, &keychain, &msg, value, &key_id, None, Some(&pubkey)).unwrap();

// Verify the signature from the excess commit
let sig_verifies =
	aggsig::verify_single_from_commit(&keychain.secp(), &sig, &msg, &excess);
assert!(!sig_verifies.is_err());