-
Notifications
You must be signed in to change notification settings - Fork 669
/
server.go
45 lines (35 loc) · 910 Bytes
/
server.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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package gwarp
import (
"context"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
pb "github.com/ava-labs/avalanchego/proto/pb/warp"
)
var _ pb.SignerServer = (*Server)(nil)
type Server struct {
pb.UnsafeSignerServer
signer warp.Signer
}
func NewServer(signer warp.Signer) *Server {
return &Server{signer: signer}
}
func (s *Server) Sign(_ context.Context, unsignedMsg *pb.SignRequest) (*pb.SignResponse, error) {
sourceChainID, err := ids.ToID(unsignedMsg.SourceChainId)
if err != nil {
return nil, err
}
msg, err := warp.NewUnsignedMessage(
unsignedMsg.NetworkId,
sourceChainID,
unsignedMsg.Payload,
)
if err != nil {
return nil, err
}
sig, err := s.signer.Sign(msg)
return &pb.SignResponse{
Signature: sig,
}, err
}