github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/repo/config/identity.go (about)

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