Skip to content
Snippets Groups Projects
Unverified Commit f4b4e440 authored by Benjamin Bollen's avatar Benjamin Bollen
Browse files

keys: fixes build of tests for new simplified mock keys client

parent 7a3c97e9
No related branches found
No related tags found
No related merge requests found
...@@ -19,11 +19,12 @@ import ( ...@@ -19,11 +19,12 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
. "github.com/monax/eris-db/keys"
// NOTE: prior to building out /crypto, use // NOTE: prior to building out /crypto, use
// tendermint/go-crypto for the mock client // tendermint/go-crypto for the mock client
"github.com/tendermint/ed25519" "github.com/tendermint/ed25519"
"golang.org/x/crypto/ripemd160"
. "github.com/monax/eris-db/keys"
) )
//--------------------------------------------------------------------- //---------------------------------------------------------------------
...@@ -36,23 +37,31 @@ type MockKey struct { ...@@ -36,23 +37,31 @@ type MockKey struct {
PublicKey []byte PublicKey []byte
} }
func newMockKey() *MockKey { func newMockKey() (*MockKey, error) {
key := &MockKey{ key := &MockKey{
Address: make([]byte, 20), Address: make([]byte, 20),
PrivateKey: new([ed25519.PrivateKeySize]byte), PublicKey: make([]byte, ed25519.PublicKeySize),
Publickey: make([]byte, ed25519.PublicKeySize),
} }
// this is a mock key, so the entropy of the source is purely // this is a mock key, so the entropy of the source is purely
// for testing // for testing
publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader) publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, err
}
copy(key.PrivateKey[:], privateKey[:]) copy(key.PrivateKey[:], privateKey[:])
copy(key.Publickey[:], publicKey[:]) copy(key.PublicKey[:], publicKey[:])
return key
// prepend 0x01 for ed25519 public key
typedPublicKeyBytes := append([]byte{0x01}, key.PublicKey...)
hasher := ripemd160.New()
hasher.Write(typedPublicKeyBytes)
key.Address = hasher.Sum(nil)
return key, nil
} }
func (mockKey *MockKey) Sign(message []byte) ([]byte, error) { func (mockKey *MockKey) Sign(message []byte) ([]byte, error) {
signatureBytes := make([]byte, ed25519.SignatureSize) signatureBytes := make([]byte, ed25519.SignatureSize)
signature = ed25519.Sign(&mockKey.PrivateKey, message) signature := ed25519.Sign(&mockKey.PrivateKey, message)
copy(signatureBytes[:], signature[:]) copy(signatureBytes[:], signature[:])
return signatureBytes, nil return signatureBytes, nil
} }
......
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