-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrypto.go
39 lines (31 loc) · 930 Bytes
/
crypto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"encoding/hex"
"fmt"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/sirupsen/logrus"
)
func checkSignature(publickey, signature string, contents []byte) (bool, error) {
pk, err := hex.DecodeString(publickey)
if err != nil {
return false, fmt.Errorf("pubkey is invalid hex: %w", err)
}
pubkey, err := schnorr.ParsePubKey(pk)
if err != nil {
return false, fmt.Errorf("event has invalid pubkey '%s': %w", publickey, err)
}
s, err := hex.DecodeString(signature)
if err != nil {
return false, fmt.Errorf("signature is invalid hex: %w", err)
}
sig, err := schnorr.ParseSignature(s)
if err != nil {
return false, fmt.Errorf("failed to parse signature: %w", err)
}
logrus.WithFields(logrus.Fields{
"fileShasum": hex.EncodeToString(contents),
"pubkey": publickey,
"signature": signature,
}).Debug("checking signature")
return sig.Verify(contents, pubkey), nil
}