From 7943430749a22e6f26aa16ca2c48e97e9277998f Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Wed, 4 May 2016 15:54:19 -0400 Subject: Initial commit --- verify.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 verify.go (limited to 'verify.go') diff --git a/verify.go b/verify.go new file mode 100644 index 0000000..74c89b6 --- /dev/null +++ b/verify.go @@ -0,0 +1,22 @@ +package main + +import "golang.org/x/crypto/sha3" + +// Verify the merkle proof for a given node id +func verify(id int64, proof [][]byte) []byte { + h := sha3.New256() + buf := proof[0] + for _, hash := range proof[1:] { + h.Reset() + if id&1 == 0 { + h.Write(hash) + h.Write(buf) + } else { + h.Write(buf) + h.Write(hash) + } + buf = h.Sum(buf[:0]) + id = (id - 1) >> 1 + } + return buf +} -- cgit v1.2.3-70-g09d2