2021-04-28 16:10:44 -04:00
|
|
|
package pb
|
|
|
|
|
|
2023-04-04 14:01:44 -04:00
|
|
|
import (
|
2023-12-13 22:46:23 +08:00
|
|
|
"encoding/binary"
|
|
|
|
|
|
2023-04-04 14:01:44 -04:00
|
|
|
"github.com/waku-org/go-waku/waku/v2/hash"
|
|
|
|
|
)
|
2021-04-28 16:10:44 -04:00
|
|
|
|
2021-10-09 14:18:53 -04:00
|
|
|
// Hash calculates the hash of a waku message
|
2023-03-04 17:51:51 -04:00
|
|
|
func (msg *WakuMessage) Hash(pubsubTopic string) []byte {
|
2023-12-13 22:46:23 +08:00
|
|
|
return hash.SHA256([]byte(pubsubTopic), msg.Payload, []byte(msg.ContentTopic), msg.Meta, toBytes(msg.GetTimestamp()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func toBytes(i int64) []byte {
|
|
|
|
|
b := make([]byte, 8)
|
|
|
|
|
binary.BigEndian.PutUint64(b, uint64(i))
|
|
|
|
|
return b
|
2021-04-28 16:10:44 -04:00
|
|
|
}
|