[−][src]Function grin_core::libtx::aggsig::sign_from_key_id
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,
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 Signingk
- The Keychain implementation being usedmsg
- The message to sign (fee|lockheight).key_id
- The keychain key id corresponding to the private key with which to sign the messageblind_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::{kernel_sig_msg, KernelFeatures}; use core::core::{Output, OutputFeatures}; use keychain::{Keychain, ExtKeychain}; 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 commit = keychain.commit(value, &key_id).unwrap(); let rproof = proof::create(&keychain, value, &key_id, 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();