-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.go
More file actions
113 lines (91 loc) · 2.51 KB
/
Copy pathinit.go
File metadata and controls
113 lines (91 loc) · 2.51 KB
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
package main
import (
"crypto/rand"
"math/big"
"os"
"strconv"
"github.com/btcsuite/btcd/btcec"
"github.com/coinbase/kryptology/pkg/core/curves"
"bip32_threshold_wallet/node"
"go.dedis.ch/dela/crypto"
"go.dedis.ch/dela/mino"
"go.dedis.ch/dela/mino/minogrpc"
"go.dedis.ch/dela/mino/router/tree"
"go.dedis.ch/kyber/v3"
)
// CollectiveAuthority is a fake implementation of the cosi.CollectiveAuthority
// interface.
type CollectiveAuthority struct {
crypto.CollectiveAuthority
addrs []mino.Address
pubkeys []kyber.Point
}
// NewAuthority returns a new collective authority of n members with new signers
// generated by g.
func NewAuthority(addrs []mino.Address, pubkeys []kyber.Point) CollectiveAuthority {
return CollectiveAuthority{
pubkeys: pubkeys,
addrs: addrs,
}
}
// leave the parameters here for future use
func getParams(msg *string, t, n *uint32) {
argCount := len(os.Args[1:])
if argCount > 0 {
*msg = os.Args[1]
}
if argCount > 1 {
val, _ := strconv.Atoi(os.Args[2])
*t = uint32(val)
}
if argCount > 2 {
val, _ := strconv.Atoi(os.Args[3])
*n = uint32(val)
}
}
// B10 generates big ints which might be needed for threshold ecdsa generation.
func B10(s string) *big.Int {
x, ok := new(big.Int).SetString(s, 10)
if !ok {
panic("Couldn't derive big.Int from string")
}
return x
}
func InitDevices(t int, n int) (CollectiveAuthority, []node.Device) {
minos := make([]mino.Mino, n)
devices := make([]node.Device, n)
addrs := make([]mino.Address, n)
for i := 0; i < n; i++ {
addr := minogrpc.ParseAddress("127.0.0.1", 0)
minogrpc, _ := minogrpc.NewMinogrpc(addr, nil, tree.NewRouter(minogrpc.NewAddressFactory()))
minos[i] = minogrpc
addrs[i] = minogrpc.GetAddress()
}
pubkeys := make([]kyber.Point, len(minos))
pubShares, privShares, pubkeyGlobal := node.GenSharedKey(uint32(t), uint32(n))
chaincode, _ := node.NewMasterChainCode()
index := uint32(0x0)
for i, mino := range minos {
for _, m := range minos {
mino.(*minogrpc.Minogrpc).GetCertificateStore().Store(m.GetAddress(),
m.(*minogrpc.Minogrpc).GetCertificateChain())
}
device, pubkey := node.NewDevice(
i,
pubShares[uint32(i)+1].Point,
privShares[uint32(i)+1].ShamirShare,
pubkeyGlobal,
index,
chaincode,
mino.(*minogrpc.Minogrpc),
)
pubkeys[i] = pubkey
devices[i] = device
}
Authority := NewAuthority(addrs, pubkeys)
field := curves.NewField(btcec.S256().Params().N)
rnd := rand.Reader
rho, _ := field.RandomElement(rnd)
devices[0].RandSk(*rho)
return Authority, devices
}