From 346518d44222315fafc2fb357e9316c584ec9b75 Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Sat, 10 Nov 2018 00:04:46 +0200 Subject: [PATCH] Added pretty print to data/typed UI --- signer/core/cliui.go | 2 +- signer/core/signed_data.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/signer/core/cliui.go b/signer/core/cliui.go index 1e5927b242..035d4f2016 100644 --- a/signer/core/cliui.go +++ b/signer/core/cliui.go @@ -164,7 +164,7 @@ func (ui *CommandlineUI) ApproveSignData(request *SignDataRequest) (SignDataResp fmt.Printf("-------- Sign data request--------------\n") fmt.Printf("Account: %s\n", request.Address.String()) - fmt.Printf("message: \n%q\n", request.Message) + fmt.Printf("message: \n%v\n", request.Message) fmt.Printf("raw data: \n%v\n", request.Rawdata) fmt.Printf("message hash: %v\n", request.Hash) fmt.Printf("-------------------------------------------\n") diff --git a/signer/core/signed_data.go b/signer/core/signed_data.go index 9566c80569..4bdc4b4ae6 100644 --- a/signer/core/signed_data.go +++ b/signer/core/signed_data.go @@ -19,6 +19,7 @@ package core import ( "bytes" "context" + "encoding/json" "errors" "fmt" "math/big" @@ -275,9 +276,12 @@ func (api *SignerAPI) SignTypedData(ctx context.Context, addr common.MixedcaseAd if err != nil { return nil, err } - msg := fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash)) - sighash := crypto.Keccak256([]byte(msg)) - req := &SignDataRequest{ContentType: DataTyped.Mime, Rawdata: typedData.Map(), Message: msg, Hash: sighash} + msg, err := json.MarshalIndent(typedData.Message, "", " ") + if err != nil { + return nil, err + } + sighash := crypto.Keccak256([]byte(fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash)))) + req := &SignDataRequest{ContentType: DataTyped.Mime, Rawdata: typedData, Message: string(msg), Hash: sighash} signature, err := api.Sign(ctx, addr, req) if err != nil { api.UI.ShowError(err.Error()) @@ -591,7 +595,7 @@ func (typedData *TypedData) IsValid() error { return nil } -// Map is a helper function to generate a map version of the typed data +// Map generates a map version of the typed data func (typedData *TypedData) Map() map[string]interface{} { dataMap := map[string]interface{}{ "types": typedData.Types, @@ -603,6 +607,11 @@ func (typedData *TypedData) Map() map[string]interface{} { return dataMap } +// PrettyPrint generates a pretty version of the typed data +func (typedData *TypedData) PrettyPrint() string { + return "" +} + // IsValid checks if the types object is conformant to the specs func (types *EIP712Types) IsValid() error { for typeKey, typeArr := range *types {