Example #1
0
        TransactionValidator_ValidateTransactionSignature_returns_false_for_invalid_transaction_signature_verification()
        {
            var subbedLogger    = Substitute.For <ILogger>();
            var signatureResult = Substitute.For <ISignature>();
            var subbedContext   = new FakeContext(signatureResult, false);

            signatureResult.SignatureBytes.Returns(new byte[64]);

            var privateKey = Substitute.For <IPrivateKey>();

            // raw un-signed tx message
            var validTransaction = new PublicEntry
            {
                SenderAddress = privateKey.GetPublicKey().Bytes.ToByteString()
            };

            var txSig = new Signature
            {
                RawBytes = new byte[64]
                           .ToByteString(), //random bytes that are not of a signed TransactionBroadcast Object
                SigningContext = new SigningContext
                {
                    NetworkType   = NetworkType.Devnet,
                    SignatureType = SignatureType.TransactionPublic
                }
            };

            var transactionValidator = new TransactionValidator(subbedLogger, subbedContext);

            validTransaction.Signature = txSig;

            var result = transactionValidator.ValidateTransaction(validTransaction);

            result.Should().BeFalse();
        }
Example #2
0
        TransactionValidator_ValidateTransactionSignature_returns_true_for_valid_transaction_signature_verification()
        {
            var subbedLogger    = Substitute.For <ILogger>();
            var signatureResult = Substitute.For <ISignature>();
            var subbedContext   = new FakeContext(signatureResult, true);

            signatureResult.SignatureBytes.Returns(new byte[64]);

            var transactionValidator = new TransactionValidator(subbedLogger, subbedContext);
            var privateKey           = Substitute.For <IPrivateKey>();

            var validTransaction = new PublicEntry
            {
                SenderAddress = privateKey.GetPublicKey().Bytes.ToByteString()
            };

            var signature = new Signature
            {
                // sign an actual TransactionBroadcast object
                RawBytes = subbedContext.Sign(privateKey, validTransaction, new SigningContext())
                           .SignatureBytes.ToByteString(),
                SigningContext = new SigningContext
                {
                    NetworkType   = NetworkType.Devnet,
                    SignatureType = SignatureType.TransactionPublic
                }
            };

            validTransaction.Signature = signature;

            var result = transactionValidator.ValidateTransaction(validTransaction);

            result.Should().BeTrue();
        }
        public void ValidateTransactionSignature_will_pass_with_valid_transaction_signature()
        {
            var subbedLogger         = Substitute.For <ILogger>();
            var cryptoContext        = new FfiWrapper();
            var transactionValidator = new TransactionValidator(subbedLogger, cryptoContext);

            // build a valid transaction
            var privateKey = cryptoContext.GeneratePrivateKey();

            var validTransaction = new PublicEntry
            {
                SenderAddress = privateKey.GetPublicKey().Bytes.ToByteString()
            };

            var signingContext = new SigningContext
            {
                NetworkType   = NetworkType.Devnet,
                SignatureType = SignatureType.TransactionPublic
            };

            var signature = new Signature
            {
                // sign an actual TransactionBroadcast object
                RawBytes = cryptoContext.Sign(privateKey, validTransaction.ToByteArray(), signingContext.ToByteArray())
                           .SignatureBytes.ToByteString(),
                SigningContext = signingContext
            };

            validTransaction.Signature = signature;

            var result = transactionValidator.ValidateTransaction(validTransaction);

            result.Should().BeTrue();
        }
Example #4
0
        public void TransactionValidator_ValidateTransactionSignature_returns_false_when_signature_is_null()
        {
            var subbedLogger  = Substitute.For <ILogger>();
            var subbedContext = Substitute.For <ICryptoContext>();

            var transactionValidator = new TransactionValidator(subbedLogger, subbedContext);

            var invalidSignature   = new Signature();
            var invalidTransaction = new PublicEntry {
                Signature = invalidSignature
            };

            var result = transactionValidator.ValidateTransaction(invalidTransaction);

            result.Should().BeFalse();
        }
Example #5
0
        public void TestValidateTransactions()
        {
            TransactionValidator validator = new TransactionValidator();
            string dataString = "String";

            byte[]            data       = Serializer.ToHexString(dataString);
            var               message    = "Peace!!!!";
            AccountKeyBuilder keyBuilder = new AccountKeyBuilder();
            Account           newAcc;

            using (var hasher = SHA256.Create())
            {
                newAcc = new Account()
                {
                    Key      = keyBuilder.CreateAccKey(),
                    Login    = message,
                    Password = new HexString(hasher.ComputeHash
                                                 (Serializer.ToBinaryArray("212121"))),
                    Role = UserRole.Admin
                };
            }
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    stream    = new MemoryStream();

            formatter.Serialize(stream, newAcc);
            Record record = new Record(1, "New acc " + newAcc.Login,
                                       new HexString(stream.ToArray()), TypeData.Account);

            Record records = new Record(1, message, new HexString(data), TypeData.Host);

            var jArray = JArray.FromObject(new List <Record>()
            {
                records
            });
            // string privkey = new ECKeyValidator().CreateKeys().ToXmlString(true);
            string pubkey = new ECKeyValidator().RSA.ToXmlString(false);

            validator.ValidateTransaction(record, pubkey).Wait();
        }