discord-interactions-js icon indicating copy to clipboard operation
discord-interactions-js copied to clipboard

Suggestion: Change verifyKey function to be pure JS friendly

Open solaris7x opened this issue 2 years ago • 2 comments

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

solaris7x avatar Mar 17 '22 16:03 solaris7x

Another alternative would be to use the SubtleCrypto.verify function.

alexanderl19 avatar May 24 '23 07:05 alexanderl19

👀 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

IanMitchell avatar Apr 16 '24 00:04 IanMitchell