| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "encoding/base64" |
| 5 | |
| 6 | ic "github.com/libp2p/go-libp2p/core/crypto" |
| 7 | ) |
| 8 | |
| 9 | const ( |
| 10 | IdentityTag = "Identity" |
| 11 | PrivKeyTag = "PrivKey" |
| 12 | PrivKeySelector = IdentityTag + "." + PrivKeyTag |
| 13 | ) |
| 14 | |
| 15 | // Identity tracks the configuration of the local node's identity. |
| 16 | type Identity struct { |
| 17 | PeerID string |
| 18 | PrivKey string `json:",omitempty"` |
| 19 | } |
| 20 | |
| 21 | // DecodePrivateKey is a helper to decode the users PrivateKey. |
| 22 | func (i *Identity) DecodePrivateKey(passphrase string) (ic.PrivKey, error) { |
| 23 | pkb, err := base64.StdEncoding.DecodeString(i.PrivKey) |
| 24 | if err != nil { |
| 25 | return nil, err |
| 26 | } |
| 27 | |
| 28 | // currently storing key unencrypted. in the future we need to encrypt it. |
| 29 | // TODO(security) |
| 30 | return ic.UnmarshalPrivateKey(pkb) |
| 31 | } |