diff --git a/cli/internal/cmd/sign.go b/cli/internal/cmd/sign.go index 5b045e0..e3d23e0 100644 --- a/cli/internal/cmd/sign.go +++ b/cli/internal/cmd/sign.go @@ -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" ) @@ -49,10 +50,11 @@ 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)) @@ -60,25 +62,31 @@ func Sign(cmd *cobra.Command, _ []string) { } } -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 diff --git a/shared/api/cli.go b/shared/api/cli.go index df0b112..2f16c13 100644 --- a/shared/api/cli.go +++ b/shared/api/cli.go @@ -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"`