Total Lines | 19 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package client |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | "crypto/hmac" |
||
6 | "crypto/sha256" |
||
7 | "encoding/hex" |
||
8 | ) |
||
9 | |||
10 | // WebhooksService is the used to verify the signature in webhook requests |
||
11 | type WebhooksService service |
||
12 | |||
13 | // Verify the signature in webhook requests |
||
14 | // https://docs.lemonsqueezy.com/api/webhooks#signing-requests |
||
15 | func (service *WebhooksService) Verify(_ context.Context, signature string, body []byte) bool { |
||
16 | key := []byte(service.client.signingSecret) |
||
17 | h := hmac.New(sha256.New, key) |
||
18 | h.Write(body) |
||
19 | return hex.EncodeToString(h.Sum(nil)) == signature |
||
20 | } |
||
21 |