Commit 182f7a82 authored by vicotor's avatar vicotor

update verify signature

parent 9f8cdabc
......@@ -80,8 +80,12 @@ func (wm *WorkerManager) computeTaskResult(worker *Worker, task *odysseus.TaskCo
paramHash := crypto.Keccak256Hash(task.TaskParam)
resultHash := crypto.Keccak256Hash(result.TaskResultBody)
dataHash := crypto.Keccak256Hash(utils.CombineBytes([]byte(result.TaskId), paramHash[:], resultHash[:]))
minerPubkey, _ := utils.HexToPubkey(worker.info.nodeInfo.MinerPubkey)
verified := ecdsa.VerifyASN1(minerPubkey, dataHash[:], result.MinerSignature)
signature := result.MinerSignature
if len(signature) == 65 {
signature = signature[:64]
}
verified := crypto.VerifySignature(utils.FromHex(worker.info.nodeInfo.MinerPubkey), dataHash[:], signature)
//verified := ecdsa.VerifyASN1(minerPubkey, dataHash[:], result.MinerSignature)
log.WithField("minerSignatureVerify", verified).Debug("miner signature verify")
if !verified {
// todo: handle signature verify failed
......
package utils
import (
"encoding/hex"
"strings"
)
func CombineBytes(b ...[]byte) []byte {
var result []byte
for _, v := range b {
......@@ -7,3 +12,11 @@ func CombineBytes(b ...[]byte) []byte {
}
return result
}
func FromHex(hexstr string) []byte {
if strings.HasPrefix(hexstr, "0x") {
hexstr = hexstr[2:]
}
d, _ := hex.DecodeString(hexstr)
return d
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment