Created
March 9, 2023 06:16
-
-
Save martincik/f040845cad45879255371466fc1ff7ac to your computer and use it in GitHub Desktop.
Verify transactions signatures and nonce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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