github.com/koko1123/flow-go-1@v0.29.6/module/local/me_nokey.go (about)

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