mirror of https://github.com/certusone/dc4bc.git
Merge branch 'feat/airgapped-client-tests' of github.com:depools/dc4bc into feat/airgapped-client-tests
This commit is contained in:
commit
41b3b97950
|
@ -1,45 +1,41 @@
|
|||
package airgapped
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
client "github.com/depools/dc4bc/client/types"
|
||||
"github.com/depools/dc4bc/fsm/state_machines/signing_proposal_fsm"
|
||||
"github.com/depools/dc4bc/fsm/types/requests"
|
||||
"github.com/depools/dc4bc/fsm/types/responses"
|
||||
"go.dedis.ch/kyber/v3/sign/bls"
|
||||
"go.dedis.ch/kyber/v3/sign/tbls"
|
||||
)
|
||||
|
||||
func (am *AirgappedMachine) handleStateSigningAwaitPartialKeys(o *client.Operation) error {
|
||||
var (
|
||||
payload responses.DKGProposalResponsesParticipantResponse
|
||||
err error
|
||||
)
|
||||
|
||||
if err = json.Unmarshal(o.Payload, &payload); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal payload: %w", err)
|
||||
}
|
||||
|
||||
partialSign, err := am.createPartialSign(nil, o.DKGIdentifier)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create partialSign for msg: %w", err)
|
||||
}
|
||||
|
||||
req := requests.SigningProposalPartialKeyRequest{
|
||||
ParticipantId: 0, // TODO: from where?
|
||||
PartialKey: partialSign,
|
||||
CreatedAt: o.CreatedAt,
|
||||
}
|
||||
reqBz, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to generate fsm request: %w", err)
|
||||
}
|
||||
|
||||
o.Result = reqBz
|
||||
o.Event = signing_proposal_fsm.EventSigningPartialKeyReceived
|
||||
return nil
|
||||
}
|
||||
// commented because fsm is not ready
|
||||
//func (am *AirgappedMachine) handleStateSigningAwaitPartialKeys(o *client.Operation) error {
|
||||
// var (
|
||||
// payload responses.DKGProposalResponsesParticipantResponse
|
||||
// err error
|
||||
// )
|
||||
//
|
||||
// if err = json.Unmarshal(o.Payload, &payload); err != nil {
|
||||
// return fmt.Errorf("failed to unmarshal payload: %w", err)
|
||||
// }
|
||||
//
|
||||
// partialSign, err := am.createPartialSign(nil, o.DKGIdentifier)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("failed to create partialSign for msg: %w", err)
|
||||
// }
|
||||
//
|
||||
// req := requests.SigningProposalPartialKeyRequest{
|
||||
// ParticipantId: 0, // TODO: from where?
|
||||
// PartialKey: partialSign,
|
||||
// CreatedAt: o.CreatedAt,
|
||||
// }
|
||||
// reqBz, err := json.Marshal(req)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("failed to generate fsm request: %w", err)
|
||||
// }
|
||||
//
|
||||
// o.Result = reqBz
|
||||
// o.Event = signing_proposal_fsm.EventSigningPartialKeyReceived
|
||||
// return nil
|
||||
//}
|
||||
|
||||
func (am *AirgappedMachine) createPartialSign(msg []byte, dkgIdentifier string) ([]byte, error) {
|
||||
blsKeyring, err := am.loadBLSKeyring(dkgIdentifier)
|
||||
|
|
|
@ -303,5 +303,8 @@ func (am *AirgappedMachine) handleStateDkgMasterKeyAwaitConfirmations(o *client.
|
|||
|
||||
o.Result = reqBz
|
||||
o.Event = dkg_proposal_fsm.EventDKGMasterKeyConfirmationReceived
|
||||
|
||||
fmt.Println(dkgInstance.ParticipantID, pubKey.String())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ type Client struct {
|
|||
keyStore KeyStore
|
||||
qrProcessor qr.Processor
|
||||
Airgapped *airgapped.AirgappedMachine
|
||||
stepBuf map[string]bool
|
||||
}
|
||||
|
||||
func NewClient(
|
||||
|
@ -72,7 +71,6 @@ func NewClient(
|
|||
keyStore: keyStore,
|
||||
qrProcessor: qrProcessor,
|
||||
Airgapped: airgappedMachine,
|
||||
stepBuf: make(map[string]bool),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -196,28 +194,27 @@ func (c *Client) ProcessMessage(message storage.Message) error {
|
|||
dpf.StateDkgDealsAwaitConfirmations,
|
||||
dpf.StateDkgResponsesAwaitConfirmations,
|
||||
dpf.StateDkgMasterKeyAwaitConfirmations:
|
||||
bz, err := json.Marshal(resp.Data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal FSM response: %w", err)
|
||||
}
|
||||
if resp.Data != nil {
|
||||
bz, err := json.Marshal(resp.Data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal FSM response: %w", err)
|
||||
}
|
||||
|
||||
operation = &types.Operation{
|
||||
ID: uuid.New().String(),
|
||||
Type: types.OperationType(resp.State),
|
||||
Payload: bz,
|
||||
DKGIdentifier: message.DkgRoundID,
|
||||
CreatedAt: time.Now(),
|
||||
operation = &types.Operation{
|
||||
ID: uuid.New().String(),
|
||||
Type: types.OperationType(resp.State),
|
||||
Payload: bz,
|
||||
DKGIdentifier: message.DkgRoundID,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
default:
|
||||
c.logger.Log("State %s does not require an operation", resp.State)
|
||||
}
|
||||
|
||||
if operation != nil {
|
||||
if _, ok := c.stepBuf[string(resp.State)]; !ok {
|
||||
if err := c.state.PutOperation(operation); err != nil {
|
||||
return fmt.Errorf("failed to PutOperation: %w", err)
|
||||
}
|
||||
c.stepBuf[string(resp.State)] = true
|
||||
if err := c.state.PutOperation(operation); err != nil {
|
||||
return fmt.Errorf("failed to PutOperation: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,7 +323,6 @@ func (c *Client) getFSMInstance(dkgRoundID string) (*state_machines.FSMInstance,
|
|||
}
|
||||
|
||||
if !ok {
|
||||
fmt.Println("Creating new state...")
|
||||
fsmInstance, err = state_machines.Create(dkgRoundID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create FSM instance: %w", err)
|
||||
|
|
Loading…
Reference in New Issue