public SignedTransaction(ISignedTransaction previousSignedDocument, Document document, PublicKey publicKey, Signature signature) { PreviousSignedTransaction = previousSignedDocument ?? throw new ArgumentNullException(nameof(previousSignedDocument)); Document = document; PublicKey = publicKey; Signature = signature; }
public static SignedTransaction Create(Keys keys, Document document, ISignedTransaction previousSignedDocument) { if (previousSignedDocument == null) { throw new ArgumentNullException(nameof(previousSignedDocument)); } if (!previousSignedDocument.Verify()) { throw new ArgumentException("Previous signature is not valid.", nameof(previousSignedDocument)); } byte[] previousSignature = previousSignedDocument.Signature; byte[] documentBytes = document; byte[] hash = documentBytes .Concat(previousSignature) .ToArray(); using (CngKey privateCngKey = CngKey.Import(keys.PrivateKey, CngKeyBlobFormat.EccPrivateBlob)) using (ECDsaCng dsa = new ECDsaCng(privateCngKey)) { dsa.HashAlgorithm = CngAlgorithm.Sha256; Signature signature = new Signature(dsa.SignData(hash)); return(new SignedTransaction(previousSignedDocument, document, keys.PublicKey, signature)); } }
public void CreateTransactions() { Keys user1keys = Keys.Create(); Keys user2Keys = Keys.Create(); ISignedTransaction signedTransaction = SignedDocument.Create(user1keys, DocumentConverter.STRING.Get("It's a test with a basic document.")) .ToSignedTransactionRoot() .Add(user1keys, DocumentConverter.STRING.Get("Updated.")) .Add(user2Keys, DocumentConverter.STRING.Get("Add a signature to the document.")); Assert.IsTrue(signedTransaction.Verify()); }
public bool MoveNext() { if (_current == null) { _current = _firstSignedTransaction; return(true); } if (_current.PreviousSignedTransaction == null) { return(false); } _current = _current.PreviousSignedTransaction; return(true); }
public void CorruptedTransactions() { Keys user1keys = Keys.Create(); Keys user2Keys = Keys.Create(); ISignedDocument signedDocument = SignedDocument.Create(user1keys, DocumentConverter.STRING.Get("It's a test with a basic document.")); ISignedTransaction signedTransaction1 = signedDocument .ToSignedTransactionRoot() .Add(user1keys, DocumentConverter.STRING.Get("Updated.")); ISignedTransaction signedTransaction2 = signedTransaction1 .Add(user2Keys, DocumentConverter.STRING.Get("Add a signature to the document.")); ISignedTransaction corruptedTransaction = new SignedTransaction(signedTransaction1.PreviousSignedTransaction, DocumentConverter.STRING.Get("Replace with a corrupted document"), signedTransaction1.PublicKey, signedTransaction1.Signature); signedTransaction2 = new SignedTransaction(corruptedTransaction, signedTransaction2.Document, signedTransaction2.PublicKey, signedTransaction2.Signature); Assert.IsFalse(signedTransaction2.Verify()); }
public static bool VerifyTransaction(this ISignedTransaction transaction) { return(transaction.Key.VerifyAllowingOnlyLowS(transaction.RawHash, transaction.Signature)); }
public static string GetSenderAddress(this ISignedTransaction transaction) { return(transaction.Key.GetPublicAddress()); }
public static byte[] GetPublicKey(this ISignedTransaction transaction) { return(transaction.Key.GetPubKey()); }
public void Reset() { _current = null; }
public Enumerator(ISignedTransaction signedTransaction) { _firstSignedTransaction = signedTransaction ?? throw new ArgumentNullException(nameof(signedTransaction)); }
public EnumerableSignedTransaction(ISignedTransaction signedTransaction) { _signedTransaction = signedTransaction ?? throw new ArgumentNullException(nameof(signedTransaction)); }
public static IEnumerable <ISignedDocument> ToEnumerable(this ISignedTransaction signedTransaction) => new EnumerableSignedTransaction(signedTransaction);
public static ISignedTransaction Add(this ISignedTransaction signedTransaction, Keys keys, Document document) => SignedTransaction.Create(keys, document, signedTransaction);