public static Signature GenerateSignature(this PublicEntry publicEntry, ICryptoContext cryptoContext, IPrivateKey privateKey, SigningContext context) { return(GeneratePublicEntrySignature(publicEntry.Clone(), cryptoContext, privateKey, context)); }
private bool ValidateTransactionSignature(PublicEntry transaction) { if (transaction.Signature.RawBytes == ByteString.Empty) { _logger.Error("Transaction signature is null"); return(false); } var transactionSignature = _cryptoContext.GetSignatureFromBytes(transaction.Signature.RawBytes.ToByteArray(), transaction.SenderAddress.ToByteArray()); var signingContext = transaction.Signature.SigningContext.ToByteArray(); // we need to verify the signature matches the message, but transactionBroadcast contains the signature and original data, // passing message+sig will mean your verifying an incorrect message and always return false, so just null the sig. var transactionClone = transaction.Clone(); transactionClone.Signature = null; if (_cryptoContext.Verify(transactionSignature, transactionClone.ToByteArray(), signingContext)) { return(true); } _logger.Information( "Transaction Signature {signature} invalid.", transactionSignature); return(false); }
public static PublicEntry Sign(this PublicEntry publicEntry, ICryptoContext cryptoContext, IPrivateKey privateKey, SigningContext context) { var clone = publicEntry.Clone(); if (publicEntry.Signature?.RawBytes.Length == cryptoContext.SignatureLength) { Logger.Debug("The transaction was already signed, returning a clone."); return(clone); } clone.Signature = GeneratePublicEntrySignature(clone, cryptoContext, privateKey, context); return(clone); }