Skip to content

Commit 5c9e0d0

Browse files
committed
Added signature verification to Transaction.Deserialize
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
1 parent bcb3144 commit 5c9e0d0

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/Solnet.Rpc/Models/Transaction.cs

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Chaos.NaCl;
12
using Solnet.Rpc.Builders;
23
using Solnet.Rpc.Utilities;
34
using Solnet.Wallet;
@@ -308,13 +309,35 @@ public static Transaction Populate(Message message, IList<byte[]> signatures = n
308309

309310
if (signatures != null)
310311
{
311-
for (int i = 0; i < signatures.Count; i++)
312+
int i = 0;
313+
foreach(byte[] signature in signatures)
312314
{
313-
tx.Signatures.Add(new SignaturePubKeyPair
315+
byte[] messageBytes = message.Serialize();
316+
bool validSig = Ed25519.Verify(signature, messageBytes, message.AccountKeys[i].KeyBytes);
317+
PublicKey signer = message.AccountKeys[i];
318+
if (!validSig)
314319
{
315-
PublicKey = message.AccountKeys[i],
316-
Signature = signatures[i]
317-
});
320+
foreach (var account in message.AccountKeys)
321+
{
322+
if (Ed25519.Verify(signature, messageBytes, account.KeyBytes))
323+
{
324+
validSig = true;
325+
signer = account;
326+
break;
327+
}
328+
}
329+
}
330+
331+
if (validSig)
332+
{
333+
tx.Signatures.Add(new SignaturePubKeyPair
334+
{
335+
PublicKey = signer,
336+
Signature = signature
337+
});
338+
}
339+
340+
i++;
318341
}
319342
}
320343

0 commit comments

Comments
 (0)