diff --git a/client/client.go b/client/client.go index 16588f53d2b2991025d34cc8ba06e14438aed858..1c9c3502a5dc46d661c654414c917257cc143e05 100644 --- a/client/client.go +++ b/client/client.go @@ -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 diff --git a/client/core/transaction_factory_util.go b/client/core/transaction_factory_util.go index 8463e8e64cc06cfea5a523214d2f8580ce28c6a7..01c2382618907eaaf8e7aa25903167ca0923d08b 100644 --- a/client/core/transaction_factory_util.go +++ b/client/core/transaction_factory_util.go @@ -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 } diff --git a/keys/key_client.go b/keys/key_client.go index 0372805a25c1ad3f7d5e8f00e3f88d7d779380de..44a60f1f5c9f94f0839ec58eb8e115f2d9ec1d1e 100644 --- a/keys/key_client.go +++ b/keys/key_client.go @@ -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 diff --git a/keys/mock/key_client_mock.go b/keys/mock/key_client_mock.go index 67b2ad9c11e6104873f62614378b8afa50210259..ef9cca8612a535011da62185af3e0a72fa8a5170 100644 --- a/keys/mock/key_client_mock.go +++ b/keys/mock/key_client_mock.go @@ -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) }