Load ethereum private key

Load an ethereum keystore when the node is started in coordinator mode.  The
private key corresponding to the forger address must be imported into the
keystore before running the node in coordinator mode.  You can see an examples
in `cli/node/load-sk-example.sh`.
This commit is contained in:
Eduard S
2020-12-29 17:21:45 +01:00
parent 88f924e9dd
commit 42791181a1
12 changed files with 253 additions and 56 deletions

View File

@@ -38,7 +38,8 @@ TokenHEZ = "0x5D94e3e7aeC542aB0F9129B9a7BAdeb5B3Ca0f77"
TokenHEZName = "Hermez Network Token"
[Coordinator]
ForgerAddress = "0x6BB84Cc84D4A34467aD12a2039A312f7029e2071"
# ForgerAddress = "0x05c23b938a85ab26A36E6314a0D02080E9ca6BeD" # Non-Boot Coordinator
ForgerAddress = "0xb4124ceb3451635dacedd11767f004d8a28c6ee7" # Boot Coordinator
ConfirmBlocks = 10
L1BatchTimeoutPerc = 0.6
ProofServerPollInterval = "1s"
@@ -60,7 +61,7 @@ Path = "/tmp/iden3-test/hermez/txselector"
Path = "/tmp/iden3-test/hermez/batchbuilder"
[[Coordinator.ServerProofs]]
URL = "http://localhost:3000"
URL = "http://localhost:3000/api"
[Coordinator.EthClient]
CallGasLimit = 300000
@@ -73,8 +74,13 @@ CheckLoopInterval = "500ms"
Attempts = 8
AttemptsDelay = "200ms"
[Coordinator.EthClient.Keystore]
Path = "/tmp/iden3-test/hermez/ethkeystore"
Password = "yourpasswordhere"
[Coordinator.API]
Coordinator = true
[Coordinator.Debug]
BatchPath = "/tmp/iden3-test/hermez/batchesdebug"
LightScrypt = true

7
cli/node/load-sk-example.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
# Non-Boot Coordinator
go run . --mode coord --cfg cfg.buidler.toml importkey --privatekey 0x30f5fddb34cd4166adb2c6003fa6b18f380fd2341376be42cf1c7937004ac7a3
# Boot Coordinator
go run . --mode coord --cfg cfg.buidler.toml importkey --privatekey 0xa8a54b2d8197bc0b19bb8a084031be71835580a01e70a45a13babd16c9bc1563

View File

@@ -4,7 +4,10 @@ import (
"fmt"
"os"
"os/signal"
"strings"
ethKeystore "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/crypto"
"github.com/hermeznetwork/hermez-node/config"
"github.com/hermeznetwork/hermez-node/log"
"github.com/hermeznetwork/hermez-node/node"
@@ -15,18 +18,41 @@ import (
const (
flagCfg = "cfg"
flagMode = "mode"
flagSK = "privatekey"
modeSync = "sync"
modeCoord = "coord"
)
func cmdInit(c *cli.Context) error {
log.Info("Init")
cfg, err := parseCli(c)
func cmdImportKey(c *cli.Context) error {
_cfg, err := parseCli(c)
if err != nil {
return tracerr.Wrap(fmt.Errorf("error parsing flags and config: %w", err))
}
if _cfg.mode != node.ModeCoordinator {
return tracerr.Wrap(fmt.Errorf("importkey must use mode coordinator"))
}
cfg := _cfg.node
scryptN := ethKeystore.StandardScryptN
scryptP := ethKeystore.StandardScryptP
if cfg.Coordinator.Debug.LightScrypt {
scryptN = ethKeystore.LightScryptN
scryptP = ethKeystore.LightScryptP
}
keyStore := ethKeystore.NewKeyStore(cfg.Coordinator.EthClient.Keystore.Path,
scryptN, scryptP)
hexKey := c.String(flagSK)
hexKey = strings.TrimPrefix(hexKey, "0x")
sk, err := crypto.HexToECDSA(hexKey)
if err != nil {
return tracerr.Wrap(err)
}
fmt.Println("TODO", cfg)
return tracerr.Wrap(err)
acc, err := keyStore.ImportECDSA(sk, cfg.Coordinator.EthClient.Keystore.Password)
if err != nil {
return tracerr.Wrap(err)
}
log.Infow("Imported private key", "addr", acc.Address.Hex())
return nil
}
func cmdRun(c *cli.Context) error {
@@ -122,10 +148,16 @@ func main() {
app.Commands = []*cli.Command{
{
Name: "init",
Name: "importkey",
Aliases: []string{},
Usage: "Initialize the hermez-node",
Action: cmdInit,
Usage: "Import ethereum private key",
Action: cmdImportKey,
Flags: []cli.Flag{
&cli.StringFlag{
Name: flagSK,
Usage: "ethereum `PRIVATE_KEY` in hex",
Required: true,
}},
},
{
Name: "run",