-
Notifications
You must be signed in to change notification settings - Fork 2
/
blind.go
82 lines (72 loc) · 1.87 KB
/
blind.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
package cli
import (
"crypto/rand"
"encoding/hex"
"fmt"
"io/ioutil"
"time"
"github.com/ethereum/go-ethereum/rlp"
"github.com/newtonproject/newchain-blind/blind"
"github.com/spf13/cobra"
)
func (cli *CLI) buildBlindCmd() *cobra.Command {
faucetCmd := &cobra.Command{
Use: "blind <pubkey>",
Short: "Blind 1NEW for address",
Args: cobra.MinimumNArgs(1),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
pub, err := blind.LoadPEMPublicKeyFile(args[0])
if err != nil {
fmt.Println(err)
return
}
c := 32
data := make([]byte, c)
_, err = rand.Read(data)
if err != nil {
fmt.Println(err)
return
}
cm := CashMessage{
Cash: 1,
Data: data,
}
cmb, err := rlp.EncodeToBytes(&cm)
if err != nil {
fmt.Println(err)
return
}
blinded, unblinder, err := blind.BlindCash(cmb, pub)
if err != nil {
fmt.Println(err)
return
}
n := time.Now().Format("20060102150405")
dataFile := fmt.Sprintf("%v.data", n)
blindedFile := fmt.Sprintf("%v.blinded", n)
unblinderFile := fmt.Sprintf("%v.unblinder", n)
if err := ioutil.WriteFile(dataFile, []byte(hex.EncodeToString(cmb)), 0644); err != nil {
fmt.Println(err)
return
}
if err := ioutil.WriteFile(blindedFile, []byte(hex.EncodeToString(blinded)), 0644); err != nil {
fmt.Println(err)
return
}
if err := ioutil.WriteFile(unblinderFile, []byte(hex.EncodeToString(unblinder)), 0644); err != nil {
fmt.Println(err)
return
}
fmt.Println("Data: ", dataFile)
fmt.Println("Blinded: ", blindedFile)
fmt.Println("Unblinder: ", unblinderFile)
fmt.Println("Send blinded file to bank")
},
}
return faucetCmd
}
type CashMessage struct {
Cash uint64 `json:"cash" gencodec:"required"`
Data []byte `json:"data" gencodec:"required"`
}