I am trying to verify signature from the Sendgrid signed webhook. Current Sendgrid documentation only provides example in Golang to use ecdsa package.
They say that this can be achieved with Node crypto package but I don't have too much insight in crypto language.
Can anyone help me to parse the current Golang codebase to javascript?
// Golang Example
s := http.Request.Header.Get("X-Twilio-Email-Event-Webhook-Signature")
ts := http.Request.Header.Get("X-Twilio-Email-Event-Webhook-Timestamp")
signatureBytes, _ := base64.StdEncoding.DecodeString(s)
ecdsaSig := struct {
R *big.Int
S *big.Int
}
asn1.Unmarshal(signatureBytes, &ecdsaSig)
tsBytes := []byte(ts)
payload, _ := ioutil.ReadAll(http.Request.Body)
h := sha256.New()
h.Write(tsBytes)
h.Write(payload)
hashedPayload := h.Sum(nil)
ecdsa.Verify(publicKey, hashedPayload, ecdsaSig.R, ecdsaSig.S)