Skip to content

Commit

Permalink
Adding Basic Private Key Management (#671)
Browse files Browse the repository at this point in the history
* adding flags

* adding modified key utils

* adding more funcs

* more changes

* more changes

* documentation

* changes to node

* gazelle

* fixing bazel build

* gazelle

* adding tests

* more tests

* addressing terence's feedback

* adding geth header

* test

* changes

* fixedd it

* fixed marshalling

* adding more to tests

* gazelle

* adding more tests

* lint

* add cov

* cov

* fix imports
  • Loading branch information
Nishant Das committed Nov 8, 2018
1 parent 6476fb5 commit 37bc1c6
Show file tree
Hide file tree
Showing 23 changed files with 833 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ coverage:
project:
default:
target: auto
threshold: 1%
threshold: 1.5%
patch: no
changes: no

Expand Down
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,12 @@ go_repository(
importpath = "github.com/boltdb/bolt",
)

go_repository(
name = "com_github_pborman_uuid",
commit = "8b1b92947f46224e3b97bb1a3a5b0382be00d31e",
importpath = "github.com/pborman/uuid",
)

go_repository(
name = "com_github_libp2p_go_buffer_pool",
commit = "058210c5a0d042677367d923eb8a6dc072a15f7f",
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/blockchain/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"math/big"
"testing"

"github.com/prysmaticlabs/prysm/beacon-chain/casper"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/prysmaticlabs/prysm/beacon-chain/casper"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/casper/incentives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"math"
"testing"

"github.com/prysmaticlabs/prysm/shared/mathutil"

"github.com/prysmaticlabs/prysm/beacon-chain/params"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/mathutil"
)

func NewValidators() []*pb.ValidatorRecord {
Expand Down
2 changes: 2 additions & 0 deletions beacon-chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ VERSION:
cmd.EnableTracingFlag,
cmd.TracingEndpointFlag,
cmd.TraceSampleFractionFlag,
cmd.KeystorePasswordFlag,
cmd.KeystoreDirectoryFlag,
debug.PProfFlag,
debug.PProfAddrFlag,
debug.PProfPortFlag,
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/node/p2p_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package node

import (
"github.com/golang/protobuf/proto"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/prysmaticlabs/prysm/shared/p2p/adapter/tracer"
"github.com/urfave/cli"

pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)

var topicMappings = map[pb.Topic]proto.Message{
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/simulator/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"fmt"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"

"github.com/ethereum/go-ethereum/common"
"github.com/prysmaticlabs/prysm/beacon-chain/params"
"github.com/prysmaticlabs/prysm/beacon-chain/types"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
Expand Down
45 changes: 43 additions & 2 deletions shared/bls/bls.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,58 @@
// aggregating BLS signatures used by Ethereum Serenity.
package bls

import "fmt"
import (
"fmt"
"math/big"
)

// Signature used in the BLS signature scheme.
type Signature struct{}

// SecretKey used in the BLS scheme.
type SecretKey struct{}
type SecretKey struct {
K *big.Int
}

// PublicKey corresponding to secret key used in the BLS scheme.
type PublicKey struct{}

// PublicKey returns the corresponding public key for the
// Secret Key
func (s *SecretKey) PublicKey() (*PublicKey, error) {
return &PublicKey{}, nil
}

// BufferedSecretKey returns the secret key in a byte format.
func (s *SecretKey) BufferedSecretKey() []byte {
return s.K.Bytes()
}

// BufferedPublicKey returns the public key in a byte format.
func (p *PublicKey) BufferedPublicKey() []byte {
return []byte{}
}

// UnBufferSecretKey takes the byte representation of a secret key
// and sets it to a big int of the underlying secret key object.
func (s *SecretKey) UnBufferSecretKey(bufferedKey []byte) {
s.K = big.NewInt(0).SetBytes(bufferedKey)

}

// UnBufferPublicKey takes the byte representation of a public key
// and sets it to a big int of the underlying public key object.
func (p *PublicKey) UnBufferPublicKey(bufferedKey []byte) {

}

// GenerateKey generates a new secret key using a seed.
func GenerateKey(seed []byte) *SecretKey {
return &SecretKey{
K: big.NewInt(0).SetBytes(seed),
}
}

// Sign a message using a secret key - in a beacon/validator client,
// this key will come from and be unlocked from the account keystore.
func Sign(sec *SecretKey, msg []byte) (*Signature, error) {
Expand Down
7 changes: 7 additions & 0 deletions shared/bls/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ func TestSign(t *testing.T) {
}
}

func TestPublicKey(t *testing.T) {
sk := &SecretKey{}
if _, err := sk.PublicKey(); err != nil {
t.Errorf("Expected nil error, received %v", err)
}
}

func TestVerifySig(t *testing.T) {
pk := &PublicKey{}
msg := []byte{}
Expand Down
13 changes: 12 additions & 1 deletion shared/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
Name: "enable-tracing",
Usage: "Enable request tracing.",
}
// TracingEndpointFlag flag defines the http enpoint for serving traces to Jaeger.
// TracingEndpointFlag flag defines the http endpoint for serving traces to Jaeger.
TracingEndpointFlag = cli.StringFlag{
Name: "tracing-endpoint",
Usage: "Tracing endpoint defines where beacon chain traces are exposed to Jaeger.",
Expand All @@ -60,4 +60,15 @@ var (
Usage: "Indicate what fraction of p2p messages are sampled for tracing.",
Value: 0.20,
}
// KeystoreDirectoryFlag defines a flag to indicate where the keystore of the user
// is located.
KeystoreDirectoryFlag = DirectoryFlag{
Name: "keystore-dir",
Usage: "Keystore directory indicates which directory the keystore is located.",
}
// KeystorePasswordFlag defines the password that will unlock the keystore file.
KeystorePasswordFlag = cli.StringFlag{
Name: "keystore-password",
Usage: "Keystore password is used to unlock the keystore so that the users decrypted keys can be used.",
}
)
33 changes: 33 additions & 0 deletions shared/keystore/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"key.go",
"keystore.go",
"utils.go",
],
importpath = "github.com/prysmaticlabs/prysm/shared/keystore",
visibility = ["//visibility:public"],
deps = [
"//shared/bls:go_default_library",
"@com_github_ethereum_go_ethereum//common/math:go_default_library",
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
"@com_github_pborman_uuid//:go_default_library",
"@org_golang_x_crypto//pbkdf2:go_default_library",
"@org_golang_x_crypto//scrypt:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = [
"key_test.go",
"keystore_test.go",
],
embed = [":go_default_library"],
deps = [
"//shared/bls:go_default_library",
"@com_github_pborman_uuid//:go_default_library",
],
)
Loading

0 comments on commit 37bc1c6

Please sign in to comment.