-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
146 lines (125 loc) · 3.39 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"crypto/sha256"
"encoding/hex"
//"log"
"os/exec"
//"runtime"
//"syscall"
//"flag"
"fmt"
"os"
//"github.com/whosthatguy/Quic/client"
//"github.com/whosthatguy/Quic/server"
//"github.com/quic-go/quic-go"
)
func main() {
if len(os.Args) < 2 {
fmt.Printf("Usage: go run . <server|client>")
return
}
switch os.Args[1] {
case "server":
StartServer()
return
case "client":
StartClient()
return
default:
fmt.Println("Invalid Choice: use 'server' or 'client'. ")
}
}
func openNewTerminal(command string) {
c := exec.Command("cmd.exe", "c", "start", "cmd.exe", "/k", command)
err := c.Run()
if err != nil {
fmt.Printf("cmd.Run() failed with %s\n ", err)
}
}
// // Step 1: Create participants and generate their keys
// participants := make([]*Participant, 0)
// names := []string{"Alice", "Bob", "Charlie"}
// for _, name := range names {
// privKey, pubKey, err := GenerateKeys()
// if err != nil {
// fmt.Println("Error generating keys:", err)
// return
// }
// participant := &Participant{
// Name: name,
// PrivateKey: privKey,
// PublicKey: *pubKey,
// }
// participants = append(participants, participant)
// }
// // Step 2: Each participant signs a message
// message := []byte("This is a multisig contract!")
// signatures := make([][]byte, 0)
// for _, participant := range participants {
// signature, err := signMessage(participant.PrivateKey, message)
// if err != nil {
// fmt.Println("Error signing message:", err)
// return
// }
// signatures = append(signatures, signature)
// }
// // Step 3: Build the Merkle tree from the signatures
// merkleRoot, tree := buildMerkleTree(signatures)
// // Display the Merkle root
// fmt.Println("Merkle Root:", merkleRoot)
// // For demonstration purposes, let's generate a Merkle proof for Alice's signature and then verify it
// aliceSignature := signatures[0]
// proof := generateMerkleProof(aliceSignature, tree)
// // Verify the Merkle proof
// isValid := verifyMerkleProof(proof, aliceSignature, merkleRoot)
// if isValid {
// fmt.Println("Merkle proof for Alice's signature is valid!")
// } else {
// fmt.Println("Merkle proof for Alice's signature is invalid!")
// }
//automat the process of creating server and client
//if len(os.Args) > 1{
// switch os.Args[1] {
// case "handleServerStream":
// handleServerStream()
// return
// case "handleClientStream":
// handleClientStream()
// return
// case "server":
// StartServer()
// return
// case "client":
// StartClient()
// }
// }
// for {
// fmt.Println("Select an option:")
// fmt.Println("1: Start server")
// fmt.Println("2: Start client")
// fmt.Println("3: Start both server and client")
// fmt.Println("4: Exit")
// var choice int
// _, err := fmt.Scanln(&choice)
// if err != nil {
// fmt.Println("Error reading choice", err)
// continue
// }
// switch choice {
// case 1:
// fmt.Println("Starting server in new Window: ")
// StartServer()
// case 2:
// fmt.Println("Starting client in new window: ")
// StartClient()
// case 3:
// fmt.Println("starting Server and Client in a new window : ")
// StartServer()
// StartClient()
// case 4:
// fmt.Println("Exiting Program: ")
// os.Exit(0)
// default:
// fmt.Println("Invalid choice")
// }
// }