package api import ( "fmt" "github.com/ethereum/go-ethereum/crypto" ) // RunAsync runs the specified function asynchronously. 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)) }