fix compilation issues

This commit is contained in:
Ivan Folgueira Bande 2026-01-25 23:21:37 +01:00
parent ff7345b541
commit 088cc0f11b
No known key found for this signature in database
GPG Key ID: 3C117481F89E24A7
2 changed files with 25 additions and 1 deletions

View File

@ -3,6 +3,9 @@ package common
import (
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"hash"
"sync"
@ -27,6 +30,27 @@ func ToMessageHash(b []byte) MessageHash {
return result
}
func ToMessageHashFromStringFormat(val string) (MessageHash, error) {
if len(val) == 0 {
return MessageHash{}, errors.New("empty message hash string not allowed")
}
if len(val) < 2 || val[:2] != "0x" {
return MessageHash{}, errors.New("string must start with 0x")
}
// Remove "0x" prefix for hex decoding
hexStr := val[2:]
// Verify the remaining string is valid hex
v, err := hex.DecodeString(hexStr)
if err != nil {
return MessageHash{}, fmt.Errorf("invalid hex string: %v", err)
}
return MessageHash(v), nil
}
var sha256Pool = sync.Pool{New: func() interface{} {
return sha256.New()
}}

View File

@ -1015,7 +1015,7 @@ func (n *WakuNode) RelayPublish(ctx context.Context, message *common.WakuMessage
wg.Wait()
if C.getRet(resp) == C.RET_OK {
msgHash := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
parsedMsgHash, err := common.ToMessageHash(msgHash)
parsedMsgHash, err := common.ToMessageHashFromStringFormat(msgHash)
if err != nil {
return common.MessageHash([32]byte{}), err
}