Function grin_core::libtx::aggsig::sign_from_key_id

source ·
pub fn sign_from_key_id<K>(
    secp: &Secp256k1,
    k: &K,
    msg: &Message,
    value: u64,
    key_id: &Identifier,
    s_nonce: Option<&SecretKey>,
    blind_sum: Option<&PublicKey>
) -> Result<Signature, Error>
where K: Keychain,
Expand description

Creates a single-signer aggsig signature from a key id. Generally, this function is used to create transaction kernel signatures for coinbase outputs. Returns Ok(Signature) if the signature is valid, or a Signature ErrorKind otherwise

§Arguments

  • secp - A Secp256k1 Context initialized for Signing
  • k - The Keychain implementation being used
  • msg - The message to sign (fee|lockheight).
  • key_id - The keychain key id corresponding to the private key with which to sign the message
  • blind_sum - (Optional) The sum of all blinding factors in the transaction in the case of a coinbase transaction this will simply be the corresponding public key.

§Example

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

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 proof = proof::create(&keychain, &builder, value, &key_id, switch, commit, None).unwrap();
let output = Output::new(OutputFeatures::Coinbase, commit, proof);
let height = 20;
let over_commit = secp.commit_value(reward(fees)).unwrap();
let out_commit = output.commitment();
let features = KernelFeatures::HeightLocked{fee: 1.into(), lock_height: height};
let msg = features.kernel_sig_msg().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();