-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (71 loc) · 2.52 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"crypto/sha256"
"fmt"
"io/ioutil"
"github.com/btcsuite/btcd/btcec"
"github.com/securepollingsystem/tallyspider/screed"
// "github.com/PuerktoBio/fetchbot"
)
func main() {
screedText := "I really like ice cream\n"
screedHash := sha256.Sum256([]byte(screedText))
regPkBytes := sha256.Sum256([]byte("This is Registrar key seed"))
pkBytes := sha256.Sum256([]byte("My key seed"))
privKey, pubKey := btcec.PrivKeyFromBytes(btcec.S256(), pkBytes[:])
regPrivKey, regPubKey := btcec.PrivKeyFromBytes(btcec.S256(), regPkBytes[:])
pubKeyHash := sha256.Sum256(pubKey.SerializeCompressed())
pubKeySig, err := regPrivKey.Sign(pubKeyHash[:])
if err != nil {
panic("Error from regPrivKey.Sign(pubKeyHash[:]) -- " + err.Error())
}
screedSig, err := privKey.Sign(screedHash[:])
if err != nil {
panic("Error from privKey.Sign(screedHash[:]) -- " + err.Error())
}
fmt.Println(len(screedSig.Serialize()))
fmt.Println(len(pubKey.SerializeCompressed()))
fmt.Println(len(pubKeySig.Serialize()))
fmt.Println(len(regPubKey.SerializeCompressed()))
screedObj := screed.NewScreed(screedText, *screedSig, *pubKey, *pubKeySig, *regPubKey)
dataForFile, err := screedObj.Serialize()
if err != nil {
panic("Error serializing screed: " + err.Error())
}
screedObj2, err := screed.DeserializeScreed(dataForFile)
if err != nil {
panic("Error from DeserializeScreed: " + err.Error())
}
screedObj2Str, err := screedObj2.Serialize()
if err != nil {
panic("Error serializing screedObj2: " + err.Error())
}
screedObj3, err := screed.DeserializeScreed(screedObj2Str)
if err != nil {
panic("Error from DeserializeScreed.Serialize: " + err.Error())
}
fmt.Println(screedObj)
fmt.Println(screedObj2)
fmt.Println(screedObj3)
err = ioutil.WriteFile("example_screed.txt", []byte(dataForFile), 0644)
if err != nil {
panic("Error writing example file: " + err.Error())
}
// screed, err := ioutil.ReadFile("example_screed.txt")
// check(err)
// signature, err := ioutil.ReadFile("example_screed.txt.sig")
// check(err)
// pubverifySignature(signature, screed)
// fmt.Printf("PubKey: %v")
// f := fetchbot.New(fetchbot.HandlerFunc(handler))
// queue := f.Start()
// queue.SendStringHead("http://google.com", "http://golang.org", "http://golang.org/doc")
// queue.Close()
}
// func handler(ctx *fetchbot.Context, res *http.Response, err error) {
// if err != nil {
// fmt.Printf("error: %s\n", err)
// return
// }
// fmt.Printf("[%d] %s %s\n", res.StatusCode, ctx.Cmd.Method(), ctx.Cmd.URL())
// }