-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentity.go
More file actions
38 lines (29 loc) · 935 Bytes
/
Copy pathidentity.go
File metadata and controls
38 lines (29 loc) · 935 Bytes
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
// SPDX-License-Identifier: AGPL-3.0-or-later
package runtime
import (
"crypto/ed25519"
"errors"
"github.com/pilot-protocol/common/coreapi"
"github.com/pilot-protocol/common/daemonapi"
)
// daemonIdentity adapts daemon's identity state to coreapi.Identity
// for plugin Deps. Methods that need the underlying *crypto.Identity
// (PublicKey, Sign) go through Daemon.Identity().
type daemonIdentity struct{ d daemonapi.Daemon }
func (i daemonIdentity) NodeID() uint32 { return i.d.NodeID() }
func (i daemonIdentity) Address() coreapi.Addr { return i.d.Addr() }
func (i daemonIdentity) PublicKey() ed25519.PublicKey {
id := i.d.Identity()
if id == nil {
return nil
}
return id.PublicKey
}
func (i daemonIdentity) Sign(msg []byte) ([]byte, error) {
id := i.d.Identity()
if id == nil {
return nil, errors.New("identity not initialized")
}
return id.Sign(msg), nil
}
var _ coreapi.Identity = daemonIdentity{}