-
Notifications
You must be signed in to change notification settings - Fork 106
/
api.go
39 lines (34 loc) · 886 Bytes
/
api.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
package cosi
import (
"errors"
"gopkg.in/dedis/cothority.v0/lib/dbg"
"gopkg.in/dedis/cothority.v0/lib/sda"
)
// Client is a structure to communicate with the CoSi
// service
type Client struct {
*sda.Client
}
// NewClient instantiates a new cosi.Client
func NewClient() *Client {
return &Client{Client: sda.NewClient(ServiceName)}
}
// SignMsg sends a CoSi sign request to the Cothority defined by the given
// EntityList
func (c *Client) SignMsg(el *sda.EntityList, msg []byte) (*SignatureResponse, error) {
serviceReq := &SignatureRequest{
EntityList: el,
Message: msg,
}
dst := el.List[0]
dbg.Lvl4("Sending message to", dst)
reply, err := c.Send(dst, serviceReq)
if e := sda.ErrMsg(reply, err); e != nil {
return nil, e
}
sr, ok := reply.Msg.(SignatureResponse)
if !ok {
return nil, errors.New("This is odd: couldn't cast reply.")
}
return &sr, nil
}