-
Notifications
You must be signed in to change notification settings - Fork 12
/
report.go
32 lines (27 loc) · 973 Bytes
/
report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package utils
import (
"crypto/sha256"
"encoding/binary"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)
// RawReportContext is a copy of evmutil.RawReportContext to avoid importing go-ethereum.
// github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil#RawReportContext
func RawReportContext(repctx types.ReportContext) [3][32]byte {
rawRepctx := [3][32]byte{}
copy(rawRepctx[0][:], repctx.ConfigDigest[:])
binary.BigEndian.PutUint32(rawRepctx[1][32-5:32-1], repctx.Epoch)
rawRepctx[1][31] = repctx.Round
rawRepctx[2] = repctx.ExtraHash
return rawRepctx
}
// HashReport returns a report digest using SHA256 hash.
func HashReport(ctx types.ReportContext, r types.Report) ([]byte, error) {
rawCtx := RawReportContext(ctx)
buf := sha256.New()
for _, v := range [][]byte{r[:], rawCtx[0][:], rawCtx[1][:], rawCtx[2][:]} {
if _, err := buf.Write(v); err != nil {
return []byte{}, err
}
}
return buf.Sum(nil), nil
}