-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpubkey.go
More file actions
43 lines (32 loc) · 771 Bytes
/
pubkey.go
File metadata and controls
43 lines (32 loc) · 771 Bytes
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
package key25519
import (
"crypto/ed25519"
"encoding/hex"
)
const PublicKeyLength int = ed25519.PublicKeySize
type PublicKey [PublicKeyLength]byte
func NewPubKeyFromEd25119PubKey(key ed25519.PublicKey) (PublicKey, error) {
return bytesToPubKey(key)
}
func (pk PublicKey) HexString() string {
return hex.EncodeToString(pk.Bytes())
}
func (pk PublicKey) VerifyMsg(originMsg, signMsg []byte) bool {
return ed25519.Verify(pk[:], originMsg, signMsg)
}
func (pk PublicKey) Bytes() []byte {
return pk[:]
}
func (pk *PublicKey) LoadFromBytes(d []byte) error {
bpk, err := bytesToPubKey(d)
if err != nil {
return err
}
*pk = bpk
return err
}
func bytesToPubKey(d []byte) (PublicKey, error) {
var pubKey PublicKey
copy(pubKey[:], d)
return pubKey, nil
}