mirror of https://github.com/status-im/go-waku.git
fix: envelope hash should match messageIdFn hash (#220)
This commit is contained in:
parent
aa6d8c8b58
commit
15f3abec3a
|
@ -22,7 +22,7 @@ func TestEnvelope(t *testing.T) {
|
|||
hash := e.Hash()
|
||||
require.Equal(
|
||||
t,
|
||||
[]uint8([]byte{0x2d, 0x84, 0x3d, 0x43, 0x77, 0x14, 0x4, 0xad, 0x64, 0x9d, 0x90, 0xd6, 0x5c, 0xc7, 0x3d, 0x8f, 0x21, 0x49, 0xa, 0xf1, 0x9c, 0x83, 0x88, 0x76, 0x51, 0xba, 0x6f, 0x34, 0x14, 0x78, 0x93, 0xd2}),
|
||||
[]uint8([]byte{0xc7, 0xaf, 0xc3, 0xe9, 0x9, 0xd1, 0xc6, 0xb4, 0x81, 0xb3, 0xdf, 0x4f, 0x16, 0x1a, 0xe4, 0xc9, 0x9c, 0x8, 0x4e, 0x5, 0xe4, 0xeb, 0x5f, 0x9b, 0x58, 0xb5, 0xf4, 0xde, 0xe9, 0x73, 0x18, 0x7b}),
|
||||
hash,
|
||||
)
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package pb
|
||||
|
||||
import (
|
||||
gcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
"crypto/sha256"
|
||||
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
|
@ -15,7 +16,8 @@ func (msg *WakuMessage) Hash() ([]byte, error) {
|
|||
return Hash(out), nil
|
||||
}
|
||||
|
||||
// Hash calculates a hash from a byte slice using keccak256 for the hashing algorithm
|
||||
// Hash calculates a hash from a byte slice using sha2-256 for the hashing algorithm
|
||||
func Hash(data []byte) []byte {
|
||||
return gcrypto.Keccak256(data)
|
||||
hash := sha256.Sum256(data)
|
||||
return hash[:]
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func TestHash(t *testing.T) {
|
||||
expected := []byte{89, 47, 167, 67, 136, 159, 199, 249, 42, 194, 163, 123, 177, 245, 186, 29, 175, 42, 92, 132, 116, 28, 160, 224, 6, 29, 36, 58, 46, 103, 7, 186}
|
||||
expected := []byte{0xa5, 0x91, 0xa6, 0xd4, 0xb, 0xf4, 0x20, 0x40, 0x4a, 0x1, 0x17, 0x33, 0xcf, 0xb7, 0xb1, 0x90, 0xd6, 0x2c, 0x65, 0xbf, 0xb, 0xcd, 0xa3, 0x2b, 0x57, 0xb2, 0x77, 0xd9, 0xad, 0x9f, 0x14, 0x6e}
|
||||
result := Hash([]byte("Hello World"))
|
||||
require.Equal(t, expected, result)
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ func TestEnvelopeHash(t *testing.T) {
|
|||
msg.Timestamp = 123456789123456789
|
||||
msg.Version = 1
|
||||
|
||||
expected := []byte{82, 136, 166, 250, 14, 69, 211, 99, 19, 161, 139, 206, 179, 3, 117, 51, 112, 111, 203, 150, 207, 35, 104, 102, 21, 181, 114, 165, 77, 29, 190, 61}
|
||||
expected := []byte{0xf8, 0xa4, 0x70, 0x32, 0x76, 0xf2, 0x36, 0x99, 0x24, 0xc5, 0xfe, 0x36, 0xee, 0x3a, 0x96, 0xcb, 0xca, 0x45, 0x54, 0xed, 0xd3, 0x1a, 0x19, 0xb1, 0x68, 0xac, 0x49, 0xe9, 0x26, 0xed, 0xb6, 0xc6}
|
||||
result, err := msg.Hash()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, result)
|
||||
|
|
Loading…
Reference in New Issue