mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
signer: make ui use new message format for signing
This commit is contained in:
parent
5f45cdc9fb
commit
c182e18fb3
3 changed files with 37 additions and 10 deletions
|
|
@ -176,7 +176,8 @@ type (
|
||||||
ContentType string `json:"content_type"`
|
ContentType string `json:"content_type"`
|
||||||
Address common.MixedcaseAddress `json:"address"`
|
Address common.MixedcaseAddress `json:"address"`
|
||||||
Rawdata interface{} `json:"raw_data"`
|
Rawdata interface{} `json:"raw_data"`
|
||||||
Message string `json:"message"`
|
//Message string `json:"message"`
|
||||||
|
Message []*NameValueType `json:"message"`
|
||||||
Hash hexutil.Bytes `json:"hash"`
|
Hash hexutil.Bytes `json:"hash"`
|
||||||
Meta Metadata `json:"meta"`
|
Meta Metadata `json:"meta"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,11 @@ func (ui *CommandlineUI) ApproveSignData(request *SignDataRequest) (SignDataResp
|
||||||
|
|
||||||
fmt.Printf("-------- Sign data request--------------\n")
|
fmt.Printf("-------- Sign data request--------------\n")
|
||||||
fmt.Printf("Account: %s\n", request.Address.String())
|
fmt.Printf("Account: %s\n", request.Address.String())
|
||||||
fmt.Printf("message: \n%v\n", request.Message)
|
fmt.Printf("message:\n")
|
||||||
|
for _, nvt := range request.Message {
|
||||||
|
fmt.Printf("%v\n", nvt.Pprint(1))
|
||||||
|
}
|
||||||
|
//fmt.Printf("message: \n%v\n", request.Message)
|
||||||
fmt.Printf("raw data: \n%v\n", request.Rawdata)
|
fmt.Printf("raw data: \n%v\n", request.Rawdata)
|
||||||
fmt.Printf("message hash: %v\n", request.Hash)
|
fmt.Printf("message hash: %v\n", request.Hash)
|
||||||
fmt.Printf("-------------------------------------------\n")
|
fmt.Printf("-------------------------------------------\n")
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,14 @@ func (api *SignerAPI) determineSignatureFormat(contentType string, addr common.M
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sighash, msg := SignTextValidator(validatorData)
|
sighash, msg := SignTextValidator(validatorData)
|
||||||
req = &SignDataRequest{ContentType: mediaType, Rawdata: validatorData, Message: msg, Hash: sighash}
|
message := []*NameValueType{
|
||||||
|
&NameValueType{
|
||||||
|
Name: "message",
|
||||||
|
Typ: "text",
|
||||||
|
Value: msg,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
req = &SignDataRequest{ContentType: mediaType, Rawdata: validatorData, Message: message, Hash: sighash}
|
||||||
case ApplicationClique.Mime:
|
case ApplicationClique.Mime:
|
||||||
// Clique is the Ethereum PoA standard
|
// Clique is the Ethereum PoA standard
|
||||||
cliqueData, err := hexutil.Decode(data.(string))
|
cliqueData, err := hexutil.Decode(data.(string))
|
||||||
|
|
@ -183,8 +190,14 @@ func (api *SignerAPI) determineSignatureFormat(contentType string, addr common.M
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
msg := fmt.Sprintf("clique block %d [0x%x]", header.Number, header.Hash())
|
message := []*NameValueType{
|
||||||
req = &SignDataRequest{ContentType: mediaType, Rawdata: cliqueData, Message: msg, Hash: sighash}
|
&NameValueType{
|
||||||
|
Name: "Clique block",
|
||||||
|
Typ: "clique",
|
||||||
|
Value: fmt.Sprintf("clique block %d [0x%x]", header.Number, header.Hash()),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
req = &SignDataRequest{ContentType: mediaType, Rawdata: cliqueData, Message: message, Hash: sighash}
|
||||||
case TextPlain.Mime:
|
case TextPlain.Mime:
|
||||||
// Calculates an Ethereum ECDSA signature for:
|
// Calculates an Ethereum ECDSA signature for:
|
||||||
// hash = keccak256("\x19${byteVersion}Ethereum Signed Message:\n${message length}${message}")
|
// hash = keccak256("\x19${byteVersion}Ethereum Signed Message:\n${message length}${message}")
|
||||||
|
|
@ -193,7 +206,15 @@ func (api *SignerAPI) determineSignatureFormat(contentType string, addr common.M
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sighash, msg := SignTextPlain(plainData)
|
sighash, msg := SignTextPlain(plainData)
|
||||||
req = &SignDataRequest{ContentType: mediaType, Rawdata: plainData, Message: msg, Hash: sighash}
|
message := []*NameValueType{
|
||||||
|
&NameValueType{
|
||||||
|
Name: "message",
|
||||||
|
Typ: "text/plain",
|
||||||
|
Value: msg,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
req = &SignDataRequest{ContentType: mediaType, Rawdata: plainData, Message: message, Hash: sighash}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("content type '%s' not implemented for signing", contentType)
|
return nil, fmt.Errorf("content type '%s' not implemented for signing", contentType)
|
||||||
}
|
}
|
||||||
|
|
@ -270,8 +291,9 @@ func (api *SignerAPI) SignTypedData(ctx context.Context, addr common.MixedcaseAd
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sighash := crypto.Keccak256([]byte(fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash))))
|
sighash := crypto.Keccak256([]byte(fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash))))
|
||||||
output := typedData.PrettyPrint()
|
//output := typedData.PrettyPrint()
|
||||||
req := &SignDataRequest{ContentType: DataTyped.Mime, Rawdata: typedData.Map(), Message: output, Hash: sighash}
|
message := typedData.Format()
|
||||||
|
req := &SignDataRequest{ContentType: DataTyped.Mime, Rawdata: typedData.Map(), Message: message, Hash: sighash}
|
||||||
signature, err := api.Sign(ctx, addr, req)
|
signature, err := api.Sign(ctx, addr, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.UI.ShowError(err.Error())
|
api.UI.ShowError(err.Error())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue