discord-interactions-js
discord-interactions-js copied to clipboard
Suggestion: Change verifyKey function to be pure JS friendly
Hello, The current implementation of verify key function has Buffer as typeof accepted input which are NodeJS specific and require heavy polyfills for pure JS (serverless/service-workers)
We can instead use
import * as ed from "@noble/ed25519"
const verifyKey = async (
signature: string,
timestamp: string,
body: string,
clientPublicKey: string
) => {
const message = new TextEncoder().encode(timestamp + body)
const isVerified = await ed.verify(signature, message, clientPublicKey)
return isVerified
}
export default verifyKey
Cons:
- change the argument types
- dependent library
Pros:
- now can be used in service-workers or pure JS environment
Another alternative would be to use the SubtleCrypto.verify
function.
👀 would love to see an update as well. I've published discord-verify
which could be used here for incredible performance benefits and better cross platform compatibility