Skip to content

Instantly share code, notes, and snippets.

@iamladi
Created March 9, 2023 06:16
Show Gist options
  • Select an option

  • Save iamladi/f040845cad45879255371466fc1ff7ac to your computer and use it in GitHub Desktop.

Select an option

Save iamladi/f040845cad45879255371466fc1ff7ac to your computer and use it in GitHub Desktop.
Verify transactions signatures and nonce
const signedTransactionSerialized =
credentials?.signedTransactionSerialized;
const pubkey = credentials?.pubkey;
const nonce = req.body?.csrfToken;
if (!(signedTransactionSerialized && pubkey && nonce)) {
throw new Error("Missing required credentials.");
}
const transaction = Transaction.from(
Buffer.from(signedTransactionSerialized, "hex")
);
if (!transaction.verifySignatures()) {
throw new Error("Incorrect signature.");
}
const txNonce = transaction.instructions[0].data.toString();
if (txNonce !== nonce) {
throw new Error("Invalid nonce.");
}
// Generate JWT token or whatever you need to for the user to get in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment