Skip to content

Commit

Permalink
Added signature verification to Transaction.Deserialize
Browse files Browse the repository at this point in the history
Each signature is verified before adding it to the transaction object. It will attempt to find the owner of the signature if the initial verification fails
  • Loading branch information
BifrostTitan committed Sep 21, 2024
1 parent bcb3144 commit 5c9e0d0
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/Solnet.Rpc/Models/Transaction.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Chaos.NaCl;
using Solnet.Rpc.Builders;
using Solnet.Rpc.Utilities;
using Solnet.Wallet;
Expand Down Expand Up @@ -308,13 +309,35 @@ public static Transaction Populate(Message message, IList<byte[]> signatures = n

if (signatures != null)
{
for (int i = 0; i < signatures.Count; i++)
int i = 0;
foreach(byte[] signature in signatures)
{
tx.Signatures.Add(new SignaturePubKeyPair
byte[] messageBytes = message.Serialize();
bool validSig = Ed25519.Verify(signature, messageBytes, message.AccountKeys[i].KeyBytes);
PublicKey signer = message.AccountKeys[i];
if (!validSig)
{
PublicKey = message.AccountKeys[i],
Signature = signatures[i]
});
foreach (var account in message.AccountKeys)
{
if (Ed25519.Verify(signature, messageBytes, account.KeyBytes))
{
validSig = true;
signer = account;
break;
}
}
}

if (validSig)
{
tx.Signatures.Add(new SignaturePubKeyPair
{
PublicKey = signer,
Signature = signature
});
}

i++;
}
}

Expand Down

0 comments on commit 5c9e0d0

Please sign in to comment.