-
Notifications
You must be signed in to change notification settings - Fork 14
/
identity.go
34 lines (28 loc) · 969 Bytes
/
identity.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
package config
import (
"encoding/base64"
ic "github.com/libp2p/go-libp2p-core/crypto"
)
const IdentityTag = "Identity"
const PrivKeyTag = "PrivKey"
const MnemonicTag = "Mnemonic"
const PrivKeySelector = IdentityTag + "." + PrivKeyTag
const MnemonicSelector = IdentityTag + "." + MnemonicTag
// Identity tracks the configuration of the local node's identity.
type Identity struct {
PeerID string
PrivKey string `json:",omitempty"`
Mnemonic string `json:",omitempty"`
EncryptedMnemonic string `json:",omitempty"`
EncryptedPrivKey string `json:",omitempty"`
}
// DecodePrivateKey is a helper to decode the users PrivateKey
func (i *Identity) DecodePrivateKey(passphrase string) (ic.PrivKey, error) {
pkb, err := base64.StdEncoding.DecodeString(i.PrivKey)
if err != nil {
return nil, err
}
// currently storing key unencrypted. in the future we need to encrypt it.
// TODO(security)
return ic.UnmarshalPrivateKey(pkb)
}