package shield
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
)
type WebhookData struct {
RequestID string `json:"RequestID"`
DeviceID string `json:"DeviceID"`
VisitorID string `json:"VisitorID"`
UserHID string `json:"UserHID"`
IP string `json:"IP"`
OS string `json:"OS"`
Country string `json:"Country"`
Score int `json:"Score"`
Details interface{} `json:"Details"`
LastRequestTime string `json:"LastRequestTime"`
}
func VerifyWebhook(data WebhookData, assing, secret string) bool {
b, err := json.Marshal(data)
if err != nil {
return false
}
mac := hmac.New(sha256.New, []byte(secret))
mac.Write(b)
expected := hex.EncodeToString(mac.Sum(nil))
return hmac.Equal([]byte(assing), []byte(expected))
}