Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
CluEleSsUK committed Jun 12, 2024
1 parent cd8ee94 commit bbdac2d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
26 changes: 17 additions & 9 deletions cli/internal/cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cmd

import (
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"os"

"github.com/randa-mu/ssv-dkg/cli"
"github.com/randa-mu/ssv-dkg/shared"
"github.com/randa-mu/ssv-dkg/shared/api"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -49,36 +50,43 @@ func Sign(cmd *cobra.Command, _ []string) {
shared.Exit(fmt.Sprintf("%v", err))
}

log.MaybeLog(fmt.Sprintf("✅ received signed deposit data! sessionID: %s", hex.EncodeToString(signingOutput.SessionID)))
path := cli.CreateFilename(stateDirectory, signingOutput)

log.MaybeLog(fmt.Sprintf("✅ received signed deposit data! stored state in %s", path))
log.Log(base64.StdEncoding.EncodeToString(signingOutput.GroupSignature))

path := cli.CreateFilename(stateDirectory, signingOutput)
bytes, err := cli.StoreStateIfNotExists(path, signingOutput)
if err != nil {
log.Log(fmt.Sprintf("⚠️ there was an error storing the state; you should store it somewhere for resharing. Error: %v", err))
log.Log(string(bytes))
}
}

func verifyAndGetArgs(cmd *cobra.Command) ([]string, []byte, error) {
func verifyAndGetArgs(cmd *cobra.Command) ([]string, api.UnsignedDepositData, error) {
// if the operator flag isn't passed, we consume operator addresses from stdin
operators, err := arrayOrReader(operatorFlag, cmd.InOrStdin())
if err != nil {
return nil, nil, errors.New("you must provider either the --operator flag or operators via stdin")
return nil, api.UnsignedDepositData{}, errors.New("you must provider either the --operator flag or operators via stdin")
}

if inputPathFlag == "" {
return nil, nil, errors.New("input path cannot be empty")
return nil, api.UnsignedDepositData{}, errors.New("input path cannot be empty")
}

// there is a default value, so this shouldn't really happen
if stateDirectory == "" {
return nil, nil, errors.New("you must provide a state directory")
return nil, api.UnsignedDepositData{}, errors.New("you must provide a state directory")
}

depositBytes, err := os.ReadFile(inputPathFlag)
if err != nil {
return nil, api.UnsignedDepositData{}, fmt.Errorf("error reading the deposit data file: %v", err)
}

depositData, err := os.ReadFile(inputPathFlag)
var depositData api.UnsignedDepositData
err = json.Unmarshal(depositBytes, &depositData)
if err != nil {
return nil, nil, fmt.Errorf("error reading the deposit data file: %v", err)
return nil, api.UnsignedDepositData{}, err
}

return operators, depositData, nil
Expand Down
22 changes: 21 additions & 1 deletion shared/api/cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
package api

import "github.com/randa-mu/ssv-dkg/shared/crypto"
import (
"math/big"

"github.com/randa-mu/ssv-dkg/shared/crypto"
)

type UnsignedDepositData struct {
WithdrawalCredentials []byte `json:"withdrawal_credentials"`
DepositDataRoot []byte `json:"deposit_data_root"`
DepositMessageRoot []byte `json:"deposit_message_root,omitempty"`
Amount big.Int `json:"amount,omitempty"`
ForkVersion string `json:"fork_version,omitempty"`
NetworkName string `json:"network_name,omitempty"`
DepositCLIVersion string `json:"deposit_cli_version,omitempty"`
}

type SignedDepositData struct {
UnsignedDepositData
PubKey []byte `json:"pubkey"`
Signature []byte `json:"signature"`
}

type SigningOutput struct {
SessionID []byte `json:"session_id"`
Expand Down

0 comments on commit bbdac2d

Please sign in to comment.