clef, signer: minor changes from review

This commit is contained in:
Martin Holst Swende 2019-02-12 10:53:41 +01:00
parent 9b7ab978b0
commit 1b84db0169
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
3 changed files with 16 additions and 13 deletions

View file

@ -2,7 +2,7 @@
### 3.2.0 ### 3.2.0
* Make `ShowError`, `OnApprovedTx`, `OnSignerStartup` be json-rpc [notification](https://www.jsonrpc.org/specification#notification): * Make `ShowError`, `OnApprovedTx`, `OnSignerStartup` be json-rpc [notifications](https://www.jsonrpc.org/specification#notification):
> A Notification is a Request object without an "id" member. A Request object that is a Notification signifies the Client's lack of interest in the corresponding Response object, and as such no Response object needs to be returned to the client. The Server MUST NOT reply to a Notification, including those that are within a batch request. > A Notification is a Request object without an "id" member. A Request object that is a Notification signifies the Client's lack of interest in the corresponding Response object, and as such no Response object needs to be returned to the client. The Server MUST NOT reply to a Notification, including those that are within a batch request.
> >

View file

@ -1484,6 +1484,9 @@ func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (stri
// TestSignCliqueBlock fetches the given block number, and attempts to sign it as a clique header with the // TestSignCliqueBlock fetches the given block number, and attempts to sign it as a clique header with the
// given address, returning the address of the recovered signature // given address, returning the address of the recovered signature
//
// This is a temporary method to debug the externalsigner integration,
// TODO: Remove this method when the integration is mature
func (api *PublicDebugAPI) TestSignCliqueBlock(ctx context.Context, address common.Address, number uint64) (common.Address, error) { func (api *PublicDebugAPI) TestSignCliqueBlock(ctx context.Context, address common.Address, number uint64) (common.Address, error) {
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
if block == nil { if block == nil {

View file

@ -177,11 +177,11 @@ func (api *SignerAPI) SignData(ctx context.Context, contentType string, addr com
func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType string, addr common.MixedcaseAddress, data interface{}) (*SignDataRequest, bool, error) { func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType string, addr common.MixedcaseAddress, data interface{}) (*SignDataRequest, bool, error) {
var ( var (
req *SignDataRequest req *SignDataRequest
useLegacyV = true // Default to use V = 27 or 28, the legacy Ethereum format useEthereumV = true // Default to use V = 27 or 28, the legacy Ethereum format
) )
mediaType, _, err := mime.ParseMediaType(contentType) mediaType, _, err := mime.ParseMediaType(contentType)
if err != nil { if err != nil {
return nil, useLegacyV, err return nil, useEthereumV, err
} }
switch mediaType { switch mediaType {
@ -189,7 +189,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
// Data with an intended validator // Data with an intended validator
validatorData, err := UnmarshalValidatorData(data) validatorData, err := UnmarshalValidatorData(data)
if err != nil { if err != nil {
return nil, useLegacyV, err return nil, useEthereumV, err
} }
sighash, msg := SignTextValidator(validatorData) sighash, msg := SignTextValidator(validatorData)
message := []*NameValueType{ message := []*NameValueType{
@ -204,15 +204,15 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
// Clique is the Ethereum PoA standard // Clique is the Ethereum PoA standard
stringData, ok := data.(string) stringData, ok := data.(string)
if !ok { if !ok {
return nil, useLegacyV, fmt.Errorf("input for %v must be an hex-encoded string", ApplicationClique.Mime) return nil, useEthereumV, fmt.Errorf("input for %v must be an hex-encoded string", ApplicationClique.Mime)
} }
cliqueData, err := hexutil.Decode(stringData) cliqueData, err := hexutil.Decode(stringData)
if err != nil { if err != nil {
return nil, useLegacyV, err return nil, useEthereumV, err
} }
header := &types.Header{} header := &types.Header{}
if err := rlp.DecodeBytes(cliqueData, header); err != nil { if err := rlp.DecodeBytes(cliqueData, header); err != nil {
return nil, useLegacyV, err return nil, useEthereumV, err
} }
// The incoming clique header is already truncated, sent to us with a extradata already shortened // The incoming clique header is already truncated, sent to us with a extradata already shortened
if len(header.Extra) < 65 { if len(header.Extra) < 65 {
@ -224,7 +224,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
// Get back the rlp data, encoded by us // Get back the rlp data, encoded by us
sighash, cliqueRlp, err := cliqueHeaderHashAndRlp(header) sighash, cliqueRlp, err := cliqueHeaderHashAndRlp(header)
if err != nil { if err != nil {
return nil, useLegacyV, err return nil, useEthereumV, err
} }
message := []*NameValueType{ message := []*NameValueType{
{ {
@ -234,17 +234,17 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
}, },
} }
// Clique uses V on the form 0 or 1 // Clique uses V on the form 0 or 1
useLegacyV = false useEthereumV = false
req = &SignDataRequest{ContentType: mediaType, Rawdata: cliqueRlp, Message: message, Hash: sighash} req = &SignDataRequest{ContentType: mediaType, Rawdata: cliqueRlp, Message: message, Hash: sighash}
default: // also case TextPlain.Mime: default: // also 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}")
// We expect it to be a string // We expect it to be a string
if stringData, ok := data.(string); !ok { if stringData, ok := data.(string); !ok {
return nil, useLegacyV, fmt.Errorf("input for text/plain must be an hex-encoded string") return nil, useEthereumV, fmt.Errorf("input for text/plain must be an hex-encoded string")
} else { } else {
if textData, err := hexutil.Decode(stringData); err != nil { if textData, err := hexutil.Decode(stringData); err != nil {
return nil, useLegacyV, err return nil, useEthereumV, err
} else { } else {
sighash, msg := accounts.TextAndHash(textData) sighash, msg := accounts.TextAndHash(textData)
message := []*NameValueType{ message := []*NameValueType{
@ -260,7 +260,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
} }
req.Address = addr req.Address = addr
req.Meta = MetadataFromContext(ctx) req.Meta = MetadataFromContext(ctx)
return req, useLegacyV, nil return req, useEthereumV, nil
} }