Esempio n. 1
0
        public void TestVerifyingForMessagesMethodEquivalence()
        {
            var privateKey = _wrapper.GeneratePrivateKey();

            var message1 = new PublicEntry {Nonce = 123};
            var context = new SigningContext {NetworkType = NetworkType.Mainnet};

            var signature = _wrapper.Sign(privateKey, message1.ToByteArray(), context.ToByteArray());

            var expected = _wrapper.Verify(signature, message1.ToByteArray(), context.ToByteArray());
            var actual = _wrapper.Verify(signature, message1, context);

            actual.Should().Be(expected);
        }
        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();
        }
Esempio n. 3
0
        public void Hashes_messages()
        {
            var hashProvider = _container.Resolve <IHashProvider>();
            var entry        = new PublicEntry();

            var arrayHash   = hashProvider.ComputeMultiHash(entry.ToByteArray());
            var messageHash = hashProvider.ComputeMultiHash(entry);

            arrayHash.ToArray().Should().BeEquivalentTo(messageHash.ToArray());
        }
Esempio n. 4
0
        public void Hashes_messages_with_suffix()
        {
            var hashProvider = _container.Resolve <IHashProvider>();
            var entry        = new PublicEntry();

            var suffix = new byte[1];

            var arrayHash   = hashProvider.ComputeMultiHash(entry.ToByteArray().Concat(suffix).ToArray());
            var messageHash = hashProvider.ComputeMultiHash(entry, suffix);

            arrayHash.ToArray().Should().BeEquivalentTo(messageHash.ToArray());
        }
Esempio n. 5
0
        public void TestSigningForMessagesMethodEquivalence()
        {
            var privateKey = _wrapper.GeneratePrivateKey();

            var message1 = new PublicEntry {Nonce = 123};
            var message2 = new PublicEntry {Nonce = 34534908};

            var expected = _wrapper.Sign(privateKey, message1.ToByteArray(), message2.ToByteArray());
            var actual = _wrapper.Sign(privateKey, message1, message2);

            actual.SignatureBytes.Should().BeEquivalentTo(expected.SignatureBytes);
            actual.PublicKeyBytes.Should().BeEquivalentTo(expected.PublicKeyBytes);
        }
Esempio n. 6
0
        private static Signature GeneratePublicEntrySignature(PublicEntry publicEntry,
                                                              ICryptoContext cryptoContext,
                                                              IPrivateKey privateKey,
                                                              SigningContext context)
        {
            publicEntry.Signature = null;
            var signatureBytes = cryptoContext.Sign(privateKey, publicEntry.ToByteArray(),
                                                    context.ToByteArray()).SignatureBytes;

            return(new Signature
            {
                RawBytes = signatureBytes.ToByteString(),
                SigningContext = context
            });
        }
 public RawEntryWithSaltedAndHashedEntry(PublicEntry rawEntry, IEnumerable <byte> salt, IHashProvider hashProvider)
 {
     RawEntry             = rawEntry;
     SaltedAndHashedEntry = hashProvider.ComputeMultiHash(rawEntry.ToByteArray().Concat(salt)).ToArray();
 }