Skip to content
Snippets Groups Projects
Commit e396bbbc authored by Ethan Buchman's avatar Ethan Buchman
Browse files

use eris-keys for validator signing

parent 998a01b2
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ func (this *consensus) State() (*ConsensusState, error) {
peerRoundStates := []string{}
for _, peer := range this.p2pSwitch.Peers().List() {
// TODO: clean this up?
peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState)
peerState := peer.Data.Get(types.PeerStateKey).(*cm.PeerState)
peerRoundState := peerState.GetRoundState()
peerRoundStateStr := peer.Key + ":" + string(wire.JSONBytes(peerRoundState))
peerRoundStates = append(peerRoundStates, peerRoundStateStr)
......
......@@ -3,15 +3,24 @@
package erisdb
import (
"encoding/hex"
"fmt"
"path"
"strings"
ep "github.com/eris-ltd/eris-db/erisdb/pipe"
"github.com/eris-ltd/eris-db/server"
"github.com/eris-ltd/mint-client/mintx/core"
"github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/log15"
acm "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/account"
. "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/common"
cfg "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/config"
tmcfg "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/config/tendermint"
"github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/node"
"github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/p2p"
ep "github.com/eris-ltd/eris-db/erisdb/pipe"
"github.com/eris-ltd/eris-db/server"
"path"
"github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/types"
)
const ERISDB_VERSION = "0.11.5"
......@@ -56,9 +65,28 @@ func ServeErisDB(workDir string) (*server.ServeProcess, error) {
tmConfig.Set("version", TENDERMINT_VERSION)
cfg.ApplyConfig(tmConfig) // Notify modules of new config
// load the priv validator
privVal := types.LoadPrivValidator(tmConfig.GetString("priv_validator_file"))
// possibly set the signer to use eris-keys
signerCfg := tmConfig.GetString("signer")
if !(signerCfg == "default" || signerCfg == "") {
spl := strings.Split(signerCfg, ":")
if len(spl) != 2 {
panic(`"signer" field in config.toml should be "default" or "ERIS_KEYS_HOST:ERIS_KEYS_PORT"`)
}
// TODO: if a privKey is found in the privVal, warn the user that we want to import it to eris-keys and delete it
host := signerCfg
addr := hex.EncodeToString(privVal.Address)
signer := NewErisSigner(host, addr)
privVal.SetSigner(signer)
}
// Set the node up.
nodeRd := make(chan struct{})
nd := node.NewNode()
nd := node.NewNode(privVal)
// Load the supporting objects.
pipe := ep.NewPipe(nd)
codec := &TCodec{}
......@@ -103,3 +131,25 @@ func startNode(nd *node.Node, ready chan struct{}, shutDown <-chan struct{}) {
<-shutDown
nd.Stop()
}
type ErisSigner struct {
Host string
Address string
SessionKey string
}
func NewErisSigner(host, address string) *ErisSigner {
if !strings.HasPrefix(host, "http://") {
host = fmt.Sprintf("http://%s", host)
}
return &ErisSigner{Host: host, Address: address}
}
func (es *ErisSigner) Sign(msg []byte) acm.SignatureEd25519 {
msgHex := hex.EncodeToString(msg)
sig, err := core.Sign(msgHex, es.Address, es.Host)
if err != nil {
panic(err)
}
return acm.SignatureEd25519(sig)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment