Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle coordinator key with keystore #139

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ build
config.toml
batches.json
users.json
genesis.json
genesis.json
.keystore
71 changes: 71 additions & 0 deletions cmd/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"fmt"
"io/ioutil"

"github.com/BOPR/config"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/console/prompt"
"github.com/spf13/cobra"
)

const (
defaultKeystorePath = ".keystore/"
)

func importCmd() *cobra.Command {
return &cobra.Command{
Use: "import",
Short: "Import keystore for operator",
RunE: func(cmd *cobra.Command, args []string) error {
keyfile := args[0]
passphrase, err := getPassPhrase("Unlock the keystore with the password", false)
if err != nil {
return err
}

keystoreBytes, err := ioutil.ReadFile(keyfile)
if err != nil {
return err
}

ks := keystore.NewKeyStore(defaultKeystorePath, keystore.StandardScryptN, keystore.StandardScryptP)

newPassphrase, err := getPassPhrase("Please give a new password", true)
if err != nil {
return err
}
acct, err := ks.Import(keystoreBytes, passphrase, newPassphrase)
if err != nil {
return err
}
fmt.Printf("Operator Address: {%x}\n", acct.Address)
cfg, err := config.ParseConfig()
cfg.KeystorePassphrase = newPassphrase
config.WriteConfigFile("./config.toml", &cfg)

return nil
},
}
}

func getPassPhrase(text string, confirmation bool) (string, error) {
if text != "" {
fmt.Println(text)
}
password, err := prompt.Stdin.PromptPassword("Password: ")
if err != nil {
return "", fmt.Errorf("Failed to read password: %v", err)
}
if confirmation {
confirm, err := prompt.Stdin.PromptPassword("Repeat password: ")
if err != nil {
return "", fmt.Errorf("Failed to read password confirmation: %v", err)
}
if password != confirm {
return "", fmt.Errorf("Passwords do not match")
}
}
return password, nil
}
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func main() {
}

rootCmd.AddCommand(initCmd())
rootCmd.AddCommand(importCmd())
rootCmd.AddCommand(configureGenesisCmd())
rootCmd.AddCommand(startCmd())
rootCmd.AddCommand(startRestServerCmd())
Expand Down
10 changes: 6 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ type Configuration struct {
MassMigration string `mapstructure:"mass_migration_address"`
Create2Transfer string `mapstructure:"create2transfer_address"`

OperatorKey string `mapstructure:"operator_key"`
OperatorAddress string `mapstructure:"operator_address"`
OperatorKey string `mapstructure:"operator_key"`
OperatorAddress string `mapstructure:"operator_address"`
KeystorePassphrase string `mapstructure:"keystore_passphrase"`

MaxTreeDepth uint64 `mapstructure:"max_tree_depth"`
MaxDepositSubtree uint64 `mapstructure:"max_deposit_subtree"`
Expand Down Expand Up @@ -94,8 +95,9 @@ func GetDefaultConfig() Configuration {
Create2Transfer: ethCmn.Address{}.String(),

// Default Account #0 from hardhat. DO NOT USE IN PRODUCTION
OperatorKey: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
OperatorAddress: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
OperatorKey: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
OperatorAddress: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
KeystorePassphrase: "",

MaxTreeDepth: 32,
MaxDepositSubtree: 1,
Expand Down
1 change: 1 addition & 0 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ max_commitments_per_batch = "{{ .MaxCommitmentsPerBatch }}"
#### Keystore #####
operator_key = "{{ .OperatorKey }}"
operator_address = "{{ .OperatorAddress }}"
keystore_passphrase = "{{ .KeystorePassphrase }}"

#### Syncer settings #####
confirmation_blocks = "{{ .ConfirmationBlocks }}"
Expand Down