-
Notifications
You must be signed in to change notification settings - Fork 0
/
converters.go
44 lines (37 loc) · 1.06 KB
/
converters.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
package multisig
import (
"github.com/kalyan3104/k-core/core/check"
crypto "github.com/kalyan3104/k-crypto-core-go"
)
func convertBytesToPubKeys(pubKeys [][]byte, kg crypto.KeyGenerator) ([]crypto.PublicKey, error) {
if len(pubKeys) == 0 {
return nil, crypto.ErrNilPublicKeys
}
pk := make([]crypto.PublicKey, 0, len(pubKeys))
for _, pubKeyStr := range pubKeys {
pubKey, err := convertBytesToPubKey(pubKeyStr, kg)
if err != nil {
return nil, err
}
pk = append(pk, pubKey)
}
return pk, nil
}
func convertBytesToPubKey(pubKeyBytes []byte, kg crypto.KeyGenerator) (crypto.PublicKey, error) {
if len(pubKeyBytes) == 0 {
return nil, crypto.ErrEmptyPubKey
}
if check.IfNil(kg) {
return nil, crypto.ErrNilKeyGenerator
}
return kg.PublicKeyFromByteArray(pubKeyBytes)
}
func convertBytesToPrivateKey(privateKey []byte, kg crypto.KeyGenerator) (crypto.PrivateKey, error) {
if len(privateKey) == 0 {
return nil, crypto.ErrNilPrivateKey
}
if check.IfNil(kg) {
return nil, crypto.ErrNilKeyGenerator
}
return kg.PrivateKeyFromByteArray(privateKey)
}