From 0c5f8c078abca7dc5954e30f307495a5c41c5f6c Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 15 May 2019 21:26:07 +0200 Subject: [PATCH] accounts,signer: better support for EIP-191 intended validator (#19523) --- accounts/accounts.go | 2 +- signer/core/signed_data.go | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/accounts/accounts.go b/accounts/accounts.go index afeb412fe3..bf5190ad98 100644 --- a/accounts/accounts.go +++ b/accounts/accounts.go @@ -36,7 +36,7 @@ type Account struct { } const ( - MimetypeTextWithValidator = "text/validator" + MimetypeDataWithValidator = "data/validator" MimetypeTypedData = "data/typed" MimetypeClique = "application/x-clique-header" MimetypeTextPlain = "text/plain" diff --git a/signer/core/signed_data.go b/signer/core/signed_data.go index d264cbaa08..9dfd7b3f69 100644 --- a/signer/core/signed_data.go +++ b/signer/core/signed_data.go @@ -46,8 +46,8 @@ type SigFormat struct { } var ( - TextValidator = SigFormat{ - accounts.MimetypeTextWithValidator, + IntendedValidator = SigFormat{ + accounts.MimetypeDataWithValidator, 0x00, } DataTyped = SigFormat{ @@ -191,7 +191,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType } switch mediaType { - case TextValidator.Mime: + case IntendedValidator.Mime: // Data with an intended validator validatorData, err := UnmarshalValidatorData(data) if err != nil { @@ -200,9 +200,24 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType sighash, msg := SignTextValidator(validatorData) message := []*NameValueType{ { - Name: "message", - Typ: "text", - Value: msg, + Name: "This is a request to sign data intended for a particular validator (see EIP 191 version 0)", + Typ: "description", + Value: "", + }, + { + Name: "Intended validator address", + Typ: "address", + Value: validatorData.Address.String(), + }, + { + Name: "Application-specific data", + Typ: "hexdata", + Value: validatorData.Message, + }, + { + Name: "Full message for signing", + Typ: "hexdata", + Value: fmt.Sprintf("0x%x", msg), }, } req = &SignDataRequest{ContentType: mediaType, Rawdata: []byte(msg), Message: message, Hash: sighash} @@ -275,7 +290,6 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType // hash = keccak256("\x19\x00"${address}${data}). func SignTextValidator(validatorData ValidatorData) (hexutil.Bytes, string) { msg := fmt.Sprintf("\x19\x00%s%s", string(validatorData.Address.Bytes()), string(validatorData.Message)) - fmt.Printf("SignTextValidator:%s\n", msg) return crypto.Keccak256([]byte(msg)), msg }