/
signaturek1.go
47 lines (39 loc) · 1.1 KB
/
signaturek1.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
40
41
42
43
44
45
46
47
package ecc
import (
"github.com/eoscanada/eos-go/btcsuite/btcd/btcec"
"github.com/eoscanada/eos-go/btcsuite/btcutil/base58"
)
type innerK1Signature struct {
}
// verify checks the signature against the pubKey. `hash` is a sha256
// hash of the payload to verify.
func (s *innerK1Signature) verify(content []byte, hash []byte, pubKey PublicKey) bool {
recoveredKey, _, err := btcec.RecoverCompact(btcec.S256(), content, hash)
if err != nil {
return false
}
key, err := pubKey.Key()
if err != nil {
return false
}
if recoveredKey.IsEqual(key) {
return true
}
return false
}
func (s *innerK1Signature) publicKey(content []byte, hash []byte) (out PublicKey, err error) {
recoveredKey, _, err := btcec.RecoverCompact(btcec.S256(), content, hash)
if err != nil {
return out, err
}
return PublicKey{
Curve: CurveK1,
Content: recoveredKey.SerializeCompressed(),
inner: &innerK1PublicKey{},
}, nil
}
func (s innerK1Signature) string(content []byte) string {
checksum := Ripemd160checksumHashCurve(content, CurveK1)
buf := append(content[:], checksum...)
return "SIG_K1_" + base58.Encode(buf)
}