wip, but full signature works

This commit is contained in:
programmer10110 2020-08-26 18:15:38 +03:00
parent 1cb71bc631
commit 2b219b3168
7 changed files with 99 additions and 6 deletions

View File

@ -191,6 +191,8 @@ func (am *AirgappedMachine) HandleOperation(operation client.Operation) (client.
err = am.handleStateDkgResponsesAwaitConfirmations(&operation)
case dkg_proposal_fsm.StateDkgMasterKeyAwaitConfirmations:
err = am.handleStateDkgMasterKeyAwaitConfirmations(&operation)
case signing_proposal_fsm.StateSigningAwaitConfirmations:
err = am.handleStateSigningAwaitConfirmations(&operation)
case signing_proposal_fsm.StateSigningAwaitPartialKeys:
err = am.handleStateSigningAwaitPartialSigns(&operation)
case signing_proposal_fsm.StateSigningPartialKeysCollected:

View File

@ -233,7 +233,7 @@ func TestAirgappedAllSteps(t *testing.T) {
runStep(tr, func(n *Node, wg *sync.WaitGroup) {
defer wg.Done()
payload := responses.SigningProposalParticipantInvitationsResponse{
payload := responses.SigningPartialSignsParticipantInvitationsResponse{
SrcPayload: msgToSign,
}

View File

@ -11,8 +11,7 @@ import (
"go.dedis.ch/kyber/v3/sign/tbls"
)
// commented because fsm is not ready
func (am *AirgappedMachine) handleStateSigningAwaitPartialSigns(o *client.Operation) error {
func (am *AirgappedMachine) handleStateSigningAwaitConfirmations(o *client.Operation) error {
var (
payload responses.SigningProposalParticipantInvitationsResponse
err error
@ -22,6 +21,35 @@ func (am *AirgappedMachine) handleStateSigningAwaitPartialSigns(o *client.Operat
return fmt.Errorf("failed to unmarshal payload: %w", err)
}
participantID, err := am.getParticipantID(o.DKGIdentifier)
if err != nil {
return fmt.Errorf("failed to get paricipant id: %w", err)
}
req := requests.SigningProposalParticipantRequest{
SigningId: payload.SigningId,
ParticipantId: participantID,
CreatedAt: o.CreatedAt,
}
reqBz, err := json.Marshal(req)
if err != nil {
return fmt.Errorf("failed to generate fsm request: %w", err)
}
o.Event = signing_proposal_fsm.EventConfirmSigningConfirmation
o.ResultMsgs = append(o.ResultMsgs, createMessage(*o, reqBz))
return nil
}
func (am *AirgappedMachine) handleStateSigningAwaitPartialSigns(o *client.Operation) error {
var (
payload responses.SigningPartialSignsParticipantInvitationsResponse
err error
)
if err = json.Unmarshal(o.Payload, &payload); err != nil {
return fmt.Errorf("failed to unmarshal payload: %w", err)
}
partialSign, err := am.createPartialSign(payload.SrcPayload, o.DKGIdentifier)
if err != nil {
return fmt.Errorf("failed to create partialSign for msg: %w", err)
@ -32,6 +60,7 @@ func (am *AirgappedMachine) handleStateSigningAwaitPartialSigns(o *client.Operat
return fmt.Errorf("failed to get paricipant id: %w", err)
}
req := requests.SigningProposalPartialKeyRequest{
SigningId: payload.SigningId,
ParticipantId: participantID,
PartialSign: partialSign,
CreatedAt: o.CreatedAt,

View File

@ -313,7 +313,7 @@ func (am *AirgappedMachine) handleStateDkgMasterKeyAwaitConfirmations(o *client.
o.Event = dkg_proposal_fsm.EventDKGMasterKeyConfirmationReceived
o.ResultMsgs = append(o.ResultMsgs, createMessage(*o, reqBz))
//fmt.Println(dkgInstance.ParticipantID, pubKey.String())
fmt.Println(dkgInstance.ParticipantID, pubKey.String())
return nil
}

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/depools/dc4bc/fsm/state_machines/signing_proposal_fsm"
"log"
"path/filepath"
"sync"
@ -182,6 +183,18 @@ func (c *Client) ProcessMessage(message storage.Message) error {
return fmt.Errorf("failed to Do operation in FSM: %w", err)
}
}
if resp.State == dpf.StateDkgMasterKeyCollected {
fsmInstance, err = state_machines.FromDump(fsmDump)
if err != nil {
return fmt.Errorf("failed get state_machines from dump: %w", err)
}
resp, fsmDump, err = fsmInstance.Do(signing_proposal_fsm.EventSigningInit, requests.DefaultRequest{
CreatedAt: time.Now(),
})
if err != nil {
return fmt.Errorf("failed to Do operation in FSM: %w", err)
}
}
var operation *types.Operation
switch resp.State {
@ -191,7 +204,10 @@ func (c *Client) ProcessMessage(message storage.Message) error {
dpf.StateDkgCommitsAwaitConfirmations,
dpf.StateDkgDealsAwaitConfirmations,
dpf.StateDkgResponsesAwaitConfirmations,
dpf.StateDkgMasterKeyAwaitConfirmations:
dpf.StateDkgMasterKeyAwaitConfirmations,
signing_proposal_fsm.StateSigningAwaitPartialKeys,
signing_proposal_fsm.StateSigningPartialKeysCollected,
signing_proposal_fsm.StateSigningAwaitConfirmations:
if resp.Data != nil {
bz, err := json.Marshal(resp.Data)
if err != nil {

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/depools/dc4bc/fsm/state_machines/signing_proposal_fsm"
"time"
"github.com/depools/dc4bc/fsm/fsm"
@ -85,6 +86,24 @@ func FSMRequestFromMessage(message storage.Message) (interface{}, error) {
return fmt.Errorf("failed to unmarshal fsm req: %v", err), nil
}
resolvedValue = req
case signing_proposal_fsm.EventSigningPartialKeyReceived:
var req requests.SigningProposalPartialKeyRequest
if err := json.Unmarshal(message.Data, &req); err != nil {
return fmt.Errorf("failed to unmarshal fsm req: %v", err), nil
}
resolvedValue = req
case signing_proposal_fsm.EventConfirmSigningConfirmation:
var req requests.SigningProposalParticipantRequest
if err := json.Unmarshal(message.Data, &req); err != nil {
return fmt.Errorf("failed to unmarshal fsm req: %v", err), nil
}
resolvedValue = req
case signing_proposal_fsm.EventSigningStart:
var req requests.SigningProposalStartRequest
if err := json.Unmarshal(message.Data, &req); err != nil {
return fmt.Errorf("failed to unmarshal fsm req: %v", err), nil
}
resolvedValue = req
default:
return nil, fmt.Errorf("invalid event: %s", message.Event)
}

29
main.go
View File

@ -7,6 +7,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
sif "github.com/depools/dc4bc/fsm/state_machines/signing_proposal_fsm"
_ "image/jpeg"
"log"
"sync"
@ -119,7 +120,7 @@ func main() {
participants = append(participants, &requests.SignatureProposalParticipantsEntry{
Addr: node.client.GetAddr(),
PubKey: node.client.GetPubKey(),
DkgPubKey: dkgPubKey, // TODO: Use a real one.
DkgPubKey: dkgPubKey,
})
}
messageData := requests.SignatureProposalParticipantsListRequest{
@ -146,6 +147,32 @@ func main() {
log.Fatalf("Failed to send %+v to storage: %v\n", message, err)
}
time.Sleep(10 * time.Second)
log.Println("Propose message to sign")
messageDataSign := requests.SigningProposalStartRequest{
ParticipantId: 0,
SrcPayload: []byte("message to sign"),
CreatedAt: time.Now(),
}
messageDataBz, err = json.Marshal(messageDataSign)
if err != nil {
log.Fatalf("failed to marshal SignatureProposalParticipantsListRequest: %v\n", err)
}
message = storage.Message{
ID: uuid.New().String(),
DkgRoundID: hex.EncodeToString(dkgRoundID[:]),
Event: string(sif.EventSigningStart),
Data: messageDataBz,
SenderAddr: nodes[0].client.GetAddr(),
}
message.Signature = ed25519.Sign(nodes[0].keyPair.Priv, message.Bytes())
if _, err := stg.Send(message); err != nil {
log.Fatalf("Failed to send %+v to storage: %v\n", message, err)
}
var wg = sync.WaitGroup{}
wg.Add(1)
wg.Wait()