2018-02-09 13:37:56 +00:00
|
|
|
package api
|
|
|
|
|
2019-03-21 10:48:47 +00:00
|
|
|
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 {
|
2018-02-09 13:37:56 +00:00
|
|
|
resp := make(chan error, 1)
|
|
|
|
go func() {
|
|
|
|
err := f()
|
|
|
|
resp <- err
|
|
|
|
close(resp)
|
|
|
|
}()
|
|
|
|
return resp
|
|
|
|
}
|
2019-03-21 10:48:47 +00:00
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|