status-go/api/utils.go

28 lines
705 B
Go
Raw Normal View History

package api
import (
"fmt"
"github.com/ethereum/go-ethereum/crypto"
)
2018-06-27 08:11:45 +00:00
// RunAsync runs the specified function asynchronously.
2018-06-19 07:49:24 +00:00
func RunAsync(f func() error) <-chan error {
resp := make(chan error, 1)
go func() {
err := f()
resp <- err
close(resp)
}()
return resp
}
// HashMessage calculates the hash of a message to be safely signed by the keycard
// The hash is calulcated as
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
// This gives context to the signed message and prevents signing of transactions.
func HashMessage(data []byte) []byte {
msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data)
return crypto.Keccak256([]byte(msg))
}