-
Notifications
You must be signed in to change notification settings - Fork 178
/
me_nokey.go
47 lines (37 loc) · 1.29 KB
/
me_nokey.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
39
40
41
42
43
44
45
46
47
package local
import (
"fmt"
"github.com/onflow/crypto"
"github.com/onflow/crypto/hash"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/filter"
)
type LocalNoKey struct {
me flow.IdentitySkeleton
}
func NewNoKey(id flow.IdentitySkeleton) (*LocalNoKey, error) {
l := &LocalNoKey{
me: id,
}
return l, nil
}
func (l *LocalNoKey) NodeID() flow.Identifier {
return l.me.NodeID
}
func (l *LocalNoKey) Address() string {
return l.me.Address
}
func (l *LocalNoKey) Sign(msg []byte, hasher hash.Hasher) (crypto.Signature, error) {
return nil, fmt.Errorf("no private key")
}
func (l *LocalNoKey) NotMeFilter() flow.IdentityFilter[flow.Identity] {
return filter.Not(filter.HasNodeID[flow.Identity](l.NodeID()))
}
// SignFunc provides a signature oracle that given a message, a hasher, and a signing function, it
// generates and returns a signature over the message using the node's private key
// as well as the input hasher by invoking the given signing function. The overall idea of this function
// is to not expose the private key to the caller.
func (l *LocalNoKey) SignFunc(data []byte, hasher hash.Hasher, f func(crypto.PrivateKey, []byte, hash.Hasher) (crypto.Signature,
error)) (crypto.Signature, error) {
return nil, fmt.Errorf("no private key to use for signing")
}