Skip to content

Commit

Permalink
Use first key in the vault when doing eosc boot
Browse files Browse the repository at this point in the history
  • Loading branch information
abourget committed Jun 25, 2019
1 parent 9b7160b commit f1c6722
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
16 changes: 6 additions & 10 deletions bios/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func (b *BIOS) Boot() error {
}

func (b *BIOS) setEphemeralKeypair() error {
if b.EphemeralPrivateKey != nil {
b.logEphemeralKey("Using preset key")
return nil
}

if _, ok := b.BootSequence.Keys["ephemeral"]; ok {
cnt := b.BootSequence.Keys["ephemeral"]
privKey, err := ecc.NewPrivateKey(strings.TrimSpace(string(cnt)))
Expand All @@ -166,17 +171,7 @@ func (b *BIOS) setEphemeralKeypair() error {
b.EphemeralPublicKey = privKey.PublicKey()

b.logEphemeralKey("Using user provider custom ephemeral keys from boot sequence")
} else if _, ok := b.BootSequence.Keys["vault"]; ok {
cnt := b.BootSequence.Keys["vault"]
privKey, err := ecc.NewPrivateKey(strings.TrimSpace(string(cnt)))
if err != nil {
return fmt.Errorf("unable to correctly decode Vault's first public key %q: %s", cnt, err)
}

b.EphemeralPrivateKey = privKey
b.EphemeralPublicKey = privKey.PublicKey()

b.logEphemeralKey("Using first public key in Vault")
} else if b.ReuseGenesis {
genesisPrivateKey, err := readPrivKeyFromFile("genesis.key")
if err != nil {
Expand All @@ -187,6 +182,7 @@ func (b *BIOS) setEphemeralKeypair() error {
b.EphemeralPublicKey = genesisPrivateKey.PublicKey()

b.logEphemeralKey("REUSING previously generated ephemeral keys from genesis")

} else {
ephemeralPrivateKey, err := b.GenerateEphemeralPrivKey()
if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions eosc/cmd/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"path/filepath"

eos "github.com/eoscanada/eos-go"
"github.com/eoscanada/eosc/bios"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
Expand All @@ -12,15 +13,15 @@ import (
var bootCmd = &cobra.Command{
Use: "boot [boot_sequence.yaml]",
Short: "Boot a fresh network, using the now famous eos-bios.",
Long: `Boot a fresh network, using the now famous eos-bios.
Long: `Boot a fresh network, using the now famous eos-bios.
Use one of the boot sequences in https://github.com/eoscanada/eosc/tree/master/bootseqs
to setup a clean EOSIO blockchain, with the features you like.
Use a base config over there, run your node, create a new Vault and use it
to bootstrap your chain by running 'eosc boot'.
`,
Args: cobra.MaximumNArgs(1),
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
api := getAPI()
attachWallet(api)
Expand All @@ -40,6 +41,15 @@ to bootstrap your chain by running 'eosc boot'.

b.ReuseGenesis = viper.GetBool("boot-cmd-reuse-genesis")

keyBag, ok := api.Signer.(*eos.KeyBag)
if ok {
if len(keyBag.Keys) != 0 {
key := keyBag.Keys[0]
b.EphemeralPrivateKey = key
b.EphemeralPublicKey = key.PublicKey()
}
}

err := b.Boot()
errorCheck("failed eos-bios boot", err)
},
Expand Down

0 comments on commit f1c6722

Please sign in to comment.