-
Notifications
You must be signed in to change notification settings - Fork 170
/
hasher.go
38 lines (33 loc) · 1015 Bytes
/
hasher.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
33
34
35
36
37
38
package utils
import (
"fmt"
"github.com/onflow/flow-go/crypto/hash"
"github.com/onflow/flow-go/fvm/crypto"
"github.com/onflow/flow-go/model/encoding"
)
// NewExecutionReceiptHasher generates and returns a hasher for signing
// and verification of execution receipts
func NewExecutionReceiptHasher() hash.Hasher {
h := crypto.NewBLSKMAC(encoding.ExecutionReceiptTag)
return h
}
// NewSPOCKHasher generates and returns a hasher for signing
// and verification of SPoCKs
func NewSPOCKHasher() hash.Hasher {
h := crypto.NewBLSKMAC(encoding.SPOCKTag)
return h
}
// NewHasher returns one of the hashers supported by Flow transactions.
func NewHasher(algo hash.HashingAlgorithm) (hash.Hasher, error) {
switch algo {
case hash.SHA2_256:
return hash.NewSHA2_256(), nil
case hash.SHA2_384:
return hash.NewSHA2_384(), nil
case hash.SHA3_256:
return hash.NewSHA3_256(), nil
case hash.SHA3_384:
return hash.NewSHA3_384(), nil
}
return nil, fmt.Errorf("not supported hashing algorithms: %d", algo)
}