diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2016-05-04 15:54:19 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2016-05-04 15:54:19 -0400 |
| commit | 7943430749a22e6f26aa16ca2c48e97e9277998f (patch) | |
| tree | 51a4d95e987d60f1b2936d5a5da9f5040efdf835 /verify.go | |
| download | pos-7943430749a22e6f26aa16ca2c48e97e9277998f.tar.gz | |
Initial commit
Diffstat (limited to 'verify.go')
| -rw-r--r-- | verify.go | 22 |
1 files changed, 22 insertions, 0 deletions
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 +} |
