Skip to content
Snippets Groups Projects
Commit 3322a188 authored by Silas Davis's avatar Silas Davis Committed by GitHub
Browse files

Merge pull request #302 from benjaminbollen/patch_eris_client

client, keys: revert to use of string over []byte, fix stupid errors
parents 6d5c5420 de3755fd
No related branches found
No related tags found
No related merge requests found
......@@ -186,8 +186,7 @@ func (erisNodeClient *ErisNodeClient) GetName(name string) (owner []byte, data s
return nil, "", 0, err
}
// unwrap return results
owner = make([]byte, len(entryResult.Owner))
copy(owner, entryResult.Owner)
owner = entryResult.Owner
data = entryResult.Data
expirationBlock = entryResult.Expires
return
......
......@@ -38,7 +38,7 @@ import (
// tx has either one input or we default to the first one (ie for send/bond)
// TODO: better support for multisig and bonding
func signTx(keyClient keys.KeyClient, chainID string, tx_ txs.Tx) ([]byte, txs.Tx, error) {
signBytes := []byte(fmt.Sprintf("%X", acc.SignBytes(chainID, tx_)))
signBytesString := fmt.Sprintf("%X", acc.SignBytes(chainID, tx_))
var inputAddr []byte
var sigED crypto.SignatureEd25519
switch tx := tx_.(type) {
......@@ -67,7 +67,7 @@ func signTx(keyClient keys.KeyClient, chainID string, tx_ txs.Tx) ([]byte, txs.T
inputAddr = tx.Address
defer func(s *crypto.SignatureEd25519) { tx.Signature = *s }(&sigED)
}
sig, err := keyClient.Sign(signBytes, inputAddr)
sig, err := keyClient.Sign(signBytesString, inputAddr)
if err != nil {
return nil, nil, err
}
......
......@@ -17,13 +17,14 @@
package keys
import (
"fmt"
"encoding/hex"
)
type KeyClient interface {
// Sign needs to return the signature bytes for given message to sign
// and the address to sign it with.
Sign(signBytes []byte, signAddress []byte) (signature []byte, err error)
Sign(signBytesString string, signAddress []byte) (signature []byte, err error)
// PublicKey needs to return the public key associated with a given address
PublicKey(address []byte) (publicKey []byte, err error)
}
......@@ -46,11 +47,11 @@ func NewErisKeyClient(rpcString string) *ErisKeyClient {
// Eris-keys client Sign requests the signature from ErisKeysClient over rpc for the given
// bytes to be signed and the address to sign them with.
func (erisKeys *ErisKeyClient) Sign(signBytes []byte, signAddress []byte) (signature []byte, err error) {
func (erisKeys *ErisKeyClient) Sign(signBytesString string, signAddress []byte) (signature []byte, err error) {
args := map[string]string{
"msg": string(signBytes),
"hash": string(signBytes), // TODO:[ben] backwards compatibility
"addr": string(signAddress),
"msg": signBytesString,
"hash": signBytesString, // TODO:[ben] backwards compatibility
"addr": fmt.Sprintf("%X", signAddress),
}
sigS, err := RequestResponse(erisKeys.rpcString, "sign", args)
if err != nil {
......@@ -60,8 +61,7 @@ func (erisKeys *ErisKeyClient) Sign(signBytes []byte, signAddress []byte) (signa
if err != nil {
return
}
copy(signature[:], sigBytes)
return
return sigBytes, err
}
// Eris-keys client PublicKey requests the public key associated with an address from
......
......@@ -17,6 +17,7 @@
package mock
import (
"encoding/hex"
"fmt"
// for the mock of key server we explicitly import
......@@ -56,11 +57,15 @@ func (mock *MockKeyClient) NewKey() (address []byte) {
return key.Address
}
func (mock *MockKeyClient) Sign(signBytes []byte, signAddress []byte) (signature []byte, err error) {
func (mock *MockKeyClient) Sign(signBytesString string, signAddress []byte) (signature []byte, err error) {
key := mock.knownKeys[fmt.Sprintf("%X", signAddress)]
if key == nil {
return nil, fmt.Errorf("Unknown address (%X)", signAddress)
}
signBytes, err := hex.DecodeString(signBytesString)
if err != nil {
return nil, fmt.Errorf("Sign bytes string is invalid hex string: %s", err.Error())
}
return key.Sign(signBytes)
}
......
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