2021-04-28 20:10:44 +00:00
|
|
|
package pb
|
|
|
|
|
|
|
|
import (
|
2022-03-23 13:16:11 +00:00
|
|
|
"crypto/sha256"
|
|
|
|
|
2021-04-28 20:10:44 +00:00
|
|
|
proto "github.com/golang/protobuf/proto"
|
|
|
|
)
|
|
|
|
|
2021-10-09 18:18:53 +00:00
|
|
|
// Hash calculates the hash of a waku message
|
2021-04-28 20:10:44 +00:00
|
|
|
func (msg *WakuMessage) Hash() ([]byte, error) {
|
|
|
|
out, err := proto.Marshal(msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return Hash(out), nil
|
|
|
|
}
|
|
|
|
|
2022-03-23 13:16:11 +00:00
|
|
|
// Hash calculates a hash from a byte slice using sha2-256 for the hashing algorithm
|
2021-04-28 20:10:44 +00:00
|
|
|
func Hash(data []byte) []byte {
|
2022-03-23 13:16:11 +00:00
|
|
|
hash := sha256.Sum256(data)
|
|
|
|
return hash[:]
|
2021-04-28 20:10:44 +00:00
|
|
|
}
|