github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/execution/utils/hasher.go (about)

     1  package utils
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/onflow/crypto/hash"
     7  
     8  	"github.com/onflow/flow-go/module/signature"
     9  )
    10  
    11  // NewExecutionReceiptHasher generates and returns a hasher for signing
    12  // and verification of execution receipts
    13  func NewExecutionReceiptHasher() hash.Hasher {
    14  	h := signature.NewBLSHasher(signature.ExecutionReceiptTag)
    15  	return h
    16  }
    17  
    18  // NewSPOCKHasher generates and returns a hasher for signing
    19  // and verification of SPoCKs
    20  func NewSPOCKHasher() hash.Hasher {
    21  	h := signature.NewBLSHasher(signature.SPOCKTag)
    22  	return h
    23  }
    24  
    25  // NewHasher returns one of the hashers supported by Flow transactions.
    26  func NewHasher(algo hash.HashingAlgorithm) (hash.Hasher, error) {
    27  	switch algo {
    28  	case hash.SHA2_256:
    29  		return hash.NewSHA2_256(), nil
    30  	case hash.SHA3_256:
    31  		return hash.NewSHA3_256(), nil
    32  	default:
    33  		return nil, fmt.Errorf("not supported hashing algorithms: %d", algo)
    34  	}
    35  }