github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/local/me_nokey.go (about)

     1  package local
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/onflow/crypto"
     7  	"github.com/onflow/crypto/hash"
     8  
     9  	"github.com/onflow/flow-go/model/flow"
    10  	"github.com/onflow/flow-go/model/flow/filter"
    11  )
    12  
    13  type LocalNoKey struct {
    14  	me flow.IdentitySkeleton
    15  }
    16  
    17  func NewNoKey(id flow.IdentitySkeleton) (*LocalNoKey, error) {
    18  	l := &LocalNoKey{
    19  		me: id,
    20  	}
    21  	return l, nil
    22  }
    23  
    24  func (l *LocalNoKey) NodeID() flow.Identifier {
    25  	return l.me.NodeID
    26  }
    27  
    28  func (l *LocalNoKey) Address() string {
    29  	return l.me.Address
    30  }
    31  
    32  func (l *LocalNoKey) Sign(msg []byte, hasher hash.Hasher) (crypto.Signature, error) {
    33  	return nil, fmt.Errorf("no private key")
    34  }
    35  
    36  func (l *LocalNoKey) NotMeFilter() flow.IdentityFilter[flow.Identity] {
    37  	return filter.Not(filter.HasNodeID[flow.Identity](l.NodeID()))
    38  }
    39  
    40  // SignFunc provides a signature oracle that given a message, a hasher, and a signing function, it
    41  // generates and returns a signature over the message using the node's private key
    42  // as well as the input hasher by invoking the given signing function. The overall idea of this function
    43  // is to not expose the private key to the caller.
    44  func (l *LocalNoKey) SignFunc(data []byte, hasher hash.Hasher, f func(crypto.PrivateKey, []byte, hash.Hasher) (crypto.Signature,
    45  	error)) (crypto.Signature, error) {
    46  	return nil, fmt.Errorf("no private key to use for signing")
    47  }