/
keystore.go
53 lines (46 loc) · 994 Bytes
/
keystore.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
48
49
50
51
52
53
package types
import (
"encoding/json"
"fmt"
"github.com/filecoin-project/go-state-types/crypto"
)
// KeyType defines a type of a key
type KeyType string
func (kt *KeyType) UnmarshalJSON(bb []byte) error {
{
// first option, try unmarshaling as string
var s string
err := json.Unmarshal(bb, &s)
if err == nil {
*kt = KeyType(s)
return nil
}
}
{
var b byte
err := json.Unmarshal(bb, &b)
if err != nil {
return fmt.Errorf("could not unmarshal KeyType either as string nor integer: %w", err)
}
bst := crypto.SigType(b)
switch bst {
case crypto.SigTypeBLS:
*kt = KTBLS
case crypto.SigTypeSecp256k1:
*kt = KTSecp256k1
default:
return fmt.Errorf("unknown sigtype: %d", bst)
}
return nil
}
}
const (
KTBLS KeyType = "bls"
KTSecp256k1 KeyType = "secp256k1"
KTSecp256k1Ledger KeyType = "secp256k1-ledger"
)
// KeyInfo is used for storing keys in KeyStore
type KeyInfo struct {
Type KeyType
PrivateKey []byte
}