-
Notifications
You must be signed in to change notification settings - Fork 4
/
mpc_sign_data.go
54 lines (44 loc) · 2.1 KB
/
mpc_sign_data.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
package storemanmpc
import (
"github.com/wanchain/schnorr-mpc/log"
mpcprotocol "github.com/wanchain/schnorr-mpc/storeman/storemanmpc/protocol"
"github.com/wanchain/schnorr-mpc/storeman/storemanmpc/step"
)
//send create LockAccount from leader
func reqSignMpc(mpcID uint64, peers []mpcprotocol.PeerInfo, preSetValue ...MpcValue) (*MpcContext, error) {
result := createMpcBaseMpcResult()
result.InitializeValue(preSetValue...)
mpc := createMpcContext(mpcID, peers, result)
reqMpc := step.CreateRequestMpcStep(&mpc.peers, mpcprotocol.MpcSignLeader)
reqMpc.SetWaiting(mpcprotocol.MpcSchnrThr)
mpcReady := step.CreateMpcReadyStep(&mpc.peers)
return generateTxSignMpc(mpc, reqMpc, mpcReady)
}
//get message from leader and create Context
func ackSignMpc(mpcID uint64, peers []mpcprotocol.PeerInfo, preSetValue ...MpcValue) (*MpcContext, error) {
result := createMpcBaseMpcResult()
result.InitializeValue(preSetValue...)
mpc := createMpcContext(mpcID, peers, result)
ackMpc := step.CreateAckMpcStep(&mpc.peers, mpcprotocol.MpcSignPeer)
mpcReady := step.CreateGetMpcReadyStep(&mpc.peers)
return generateTxSignMpc(mpc, ackMpc, mpcReady)
}
func generateTxSignMpc(mpc *MpcContext, firstStep MpcStepFunc, readyStep MpcStepFunc) (*MpcContext, error) {
log.SyslogInfo("generateTxSignMpc begin")
accTypeStr := ""
skShare := step.CreateMpcRSKShareStep(mpcprotocol.MPCDegree, &mpc.peers)
// wait time out, in order for all node try best get most response, so each node can get the same poly value.
// It is not enough for node to wait only MPCDegree response, the reason is above.
RStep := step.CreateMpcRStep(&mpc.peers, accTypeStr)
RStep.SetWaiting(mpcprotocol.MpcSchnrThr)
SStep := step.CreateMpcSStep(&mpc.peers, []string{mpcprotocol.MpcPrivateShare}, []string{mpcprotocol.MpcS})
SStep.SetWaiting(mpcprotocol.MpcSchnrThr)
ackRSStep := step.CreateAckMpcRSStep(&mpc.peers, accTypeStr)
ackRSStep.SetWaiting(mpcprotocol.MpcSchnrThr)
mpc.setMpcStep(firstStep, readyStep, skShare, RStep, SStep, ackRSStep)
for stepId, stepItem := range mpc.MpcSteps {
stepItem.SetWaitAll(false)
stepItem.SetStepId(stepId)
}
return mpc, nil
}