Passed
Push — main ( e5c029...5d1870 )
by Acho
01:03
created

client.*WebhooksService.Verify   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 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