mirror of https://github.com/certusone/dc4bc.git
wip
This commit is contained in:
parent
0528c779d7
commit
ee888aad2b
|
@ -107,6 +107,7 @@ func (am *Machine) reconstructThresholdSignature(o *client.Operation) error {
|
|||
}
|
||||
|
||||
response := client.ReconstructedSignature{
|
||||
SigningID: payload.SigningId,
|
||||
SrcPayload: payload.SrcPayload,
|
||||
Signature: reconstructedSignature,
|
||||
DKGRoundID: o.DKGIdentifier,
|
||||
|
|
|
@ -152,6 +152,7 @@ func (c *BaseClient) processSignature(message storage.Message) error {
|
|||
}
|
||||
|
||||
func (c *BaseClient) ProcessMessage(message storage.Message) error {
|
||||
// save broadcasted reconstructed signature
|
||||
if fsm.Event(message.Event) == types.SignatureReconstructed {
|
||||
if err := c.processSignature(message); err != nil {
|
||||
return fmt.Errorf("failed to process signature: %w", err)
|
||||
|
@ -161,6 +162,9 @@ func (c *BaseClient) ProcessMessage(message storage.Message) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// save signing data to the same storage as we save signatures
|
||||
// This allows easy to view signing data by CLI-command
|
||||
if fsm.Event(message.Event) == sipf.EventSigningStart {
|
||||
if err := c.processSignature(message); err != nil {
|
||||
return fmt.Errorf("failed to process signature: %w", err)
|
||||
|
|
|
@ -143,7 +143,7 @@ func RemoveContents(dir, mask string) error {
|
|||
|
||||
func TestFullFlow(t *testing.T) {
|
||||
_ = RemoveContents("/tmp", "dc4bc_*")
|
||||
//defer func() { _ = RemoveContents("/tmp", "dc4bc_*") }()
|
||||
defer func() { _ = RemoveContents("/tmp", "dc4bc_*") }()
|
||||
|
||||
var numNodes = 4
|
||||
var threshold = 2
|
||||
|
|
|
@ -363,6 +363,7 @@ func (c *BaseClient) proposeSignDataHandler(w http.ResponseWriter, r *http.Reque
|
|||
}
|
||||
|
||||
messageDataSign := requests.SigningProposalStartRequest{
|
||||
SigningID: uuid.New().String(),
|
||||
ParticipantId: participantID,
|
||||
SrcPayload: req["data"],
|
||||
CreatedAt: time.Now(),
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -340,11 +338,9 @@ func (s *LevelDBState) SaveSignature(signature types.ReconstructedSignature) err
|
|||
signatures = make(map[string][]types.ReconstructedSignature)
|
||||
}
|
||||
|
||||
dataHash := md5.Sum(signature.SrcPayload)
|
||||
dataHashString := hex.EncodeToString(dataHash[:])
|
||||
sig := signatures[dataHashString]
|
||||
sig := signatures[signature.SigningID]
|
||||
sig = append(sig, signature)
|
||||
signatures[dataHashString] = sig
|
||||
signatures[signature.SigningID] = sig
|
||||
|
||||
signaturesJSON, err := json.Marshal(signatures)
|
||||
if err != nil {
|
||||
|
|
|
@ -23,6 +23,7 @@ const (
|
|||
)
|
||||
|
||||
type ReconstructedSignature struct {
|
||||
SigningID string
|
||||
SrcPayload []byte
|
||||
Signature []byte
|
||||
Username string
|
||||
|
|
|
@ -121,7 +121,8 @@ func getOperationsCommand() *cobra.Command {
|
|||
return fmt.Errorf("failed to unmarshal operation payload")
|
||||
}
|
||||
msgHash := md5.Sum(payload.SrcPayload)
|
||||
fmt.Printf("Hash of the message to sign - %s\n", hex.EncodeToString(msgHash[:]))
|
||||
fmt.Printf("Hash of the data to sign - %s\n", hex.EncodeToString(msgHash[:]))
|
||||
fmt.Printf("Signing ID: %s\n", payload.SigningId)
|
||||
}
|
||||
fmt.Println("-----------------------------------------------------")
|
||||
}
|
||||
|
@ -165,8 +166,8 @@ func getSignaturesCommand() *cobra.Command {
|
|||
if signatures.ErrorMessage != "" {
|
||||
return fmt.Errorf("failed to get signatures: %s", signatures.ErrorMessage)
|
||||
}
|
||||
for dataHash, signature := range signatures.Result {
|
||||
fmt.Printf("Hash of the signing data: %s\n", dataHash)
|
||||
for sigID, signature := range signatures.Result {
|
||||
fmt.Printf("Signing ID: %s\n", sigID)
|
||||
for _, participantSig := range signature {
|
||||
fmt.Printf("\tDKG round ID: %s\n", participantSig.DKGRoundID)
|
||||
fmt.Printf("\tParticipant: %s\n", participantSig.Username)
|
||||
|
|
|
@ -182,8 +182,7 @@ func startClientCommand() *cobra.Command {
|
|||
log.Fatalf("Failed to init state client: %v", err)
|
||||
}
|
||||
|
||||
stg, err := storage.NewFileStorage("/tmp/dc4bc_storage")
|
||||
//stg, err := storage.NewKafkaStorage(ctx, cfg.StorageDBDSN, cfg.StorageTopic)
|
||||
stg, err := storage.NewKafkaStorage(ctx, cfg.StorageDBDSN, cfg.StorageTopic)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to init storage client: %v", err)
|
||||
}
|
||||
|
|
|
@ -897,6 +897,7 @@ func Test_SigningProposal_EventSigningStart(t *testing.T) {
|
|||
compareState(t, sif.StateSigningIdle, inState)
|
||||
|
||||
fsmResponse, testFSMDump[sif.StateSigningAwaitConfirmations], err = testFSMInstance.Do(sif.EventSigningStart, requests.SigningProposalStartRequest{
|
||||
SigningID: "test-signing-id",
|
||||
ParticipantId: 1,
|
||||
SrcPayload: []byte("message to sign"),
|
||||
CreatedAt: time.Now(),
|
||||
|
|
|
@ -60,12 +60,7 @@ func (m *SigningProposalFSM) actionStartSigningProposal(inEvent fsm.Event, args
|
|||
return
|
||||
}
|
||||
|
||||
m.payload.SigningProposalPayload.SigningId, err = generateSigningId()
|
||||
|
||||
if err != nil {
|
||||
err = errors.New("cannot generate {SigningId}")
|
||||
return
|
||||
}
|
||||
m.payload.SigningProposalPayload.SigningId = request.SigningID
|
||||
|
||||
m.payload.SigningProposalPayload.InitiatorId = request.ParticipantId
|
||||
m.payload.SigningProposalPayload.SrcPayload = request.SrcPayload
|
||||
|
|
|
@ -5,6 +5,7 @@ import "time"
|
|||
// States: "stage_signing_idle"
|
||||
// Events: "event_signing_start"
|
||||
type SigningProposalStartRequest struct {
|
||||
SigningID string
|
||||
ParticipantId int
|
||||
SrcPayload []byte
|
||||
CreatedAt time.Time
|
||||
|
|
Loading…
Reference in New Issue