import { createHash, createVerify } from 'crypto'
const isSignatureValid = async (receivedEventBody, signature) => {
// Fetch Rhino.fi webhook public key
const res = await fetch('https://api.rhino.fi/webhook/public-key')
const publicKeyBase64 = await res.json()
const publicKey = Buffer.from(publicKeyBase64, 'base64').toString()
// Hash the stringified event
const hash = createHash('sha256')
const hashedMessage = hash.update(
JSON.stringify(receivedEventBody),
)
// Verify the signature
const verify = createVerify('RSA-SHA256')
verify.update(hashedMessage.digest('hex'))
return verify.verify(publicKey, signature, 'hex')
}