forked from gtfierro/wave
-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.go
72 lines (66 loc) · 1.77 KB
/
log.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"encoding/pem"
"time"
"github.com/gogo/protobuf/proto"
"github.com/golang/glog"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"github.com/google/trillian"
"github.com/google/trillian/crypto/keyspb"
spb "github.com/google/trillian/crypto/sigpb"
_ "github.com/google/trillian/merkle/coniks"
"google.golang.org/grpc"
)
func mustMarshalAny(pb proto.Message) *any.Any {
value, err := ptypes.MarshalAny(pb)
if err != nil {
panic(err)
}
return value
}
var logconn *grpc.ClientConn
var OpLogTree *trillian.Tree
var logclient trillian.TrillianLogClient
var logId int64
func initlogs() {
pubk, _ := pem.Decode([]byte(PublicKey))
privk, _ := pem.Decode([]byte(PrivateKey))
OpLogTree = &trillian.Tree{
TreeId: TreeID_Op,
TreeState: trillian.TreeState_ACTIVE,
TreeType: trillian.TreeType_LOG,
HashStrategy: trillian.HashStrategy_RFC6962_SHA256,
HashAlgorithm: spb.DigitallySigned_SHA256,
SignatureAlgorithm: spb.DigitallySigned_ECDSA,
DisplayName: "OPERATIONS",
Description: "for WAVE",
PrivateKey: mustMarshalAny(&keyspb.PrivateKey{
Der: privk.Bytes,
}),
PublicKey: &keyspb.PublicKey{
Der: pubk.Bytes,
},
MaxRootDuration: ptypes.DurationProto(0 * time.Millisecond),
}
var err error
logconn, err = grpc.Dial(logServer, grpc.WithInsecure())
if err != nil {
glog.Fatal(err)
}
logclient = trillian.NewTrillianLogClient(logconn)
}
// func addToLog(value []byte) int64 {
// ctx := context.Background()
// llf := &trillian.LogLeaf{
// LeafValue: value,
// }
// resp, err := vlog.QueueLeaf(ctx, &trillian.QueueLeafRequest{
// LogId: logId,
// Leaf: llf,
// })
// if err != nil {
// panic(err)
// }
// return resp.QueuedLeaf.Leaf.LeafIndex
// }