mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
clef, signer: minor changes from review
This commit is contained in:
parent
9b7ab978b0
commit
1b84db0169
3 changed files with 16 additions and 13 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
### 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.
|
||||
>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// 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) {
|
||||
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
|
||||
if block == nil {
|
||||
|
|
|
|||
|
|
@ -176,12 +176,12 @@ func (api *SignerAPI) SignData(ctx context.Context, contentType string, addr com
|
|||
// This method returns the mimetype for signing along with the request
|
||||
func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType string, addr common.MixedcaseAddress, data interface{}) (*SignDataRequest, bool, error) {
|
||||
var (
|
||||
req *SignDataRequest
|
||||
useLegacyV = true // Default to use V = 27 or 28, the legacy Ethereum format
|
||||
req *SignDataRequest
|
||||
useEthereumV = true // Default to use V = 27 or 28, the legacy Ethereum format
|
||||
)
|
||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||
if err != nil {
|
||||
return nil, useLegacyV, err
|
||||
return nil, useEthereumV, err
|
||||
}
|
||||
|
||||
switch mediaType {
|
||||
|
|
@ -189,7 +189,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
|
|||
// Data with an intended validator
|
||||
validatorData, err := UnmarshalValidatorData(data)
|
||||
if err != nil {
|
||||
return nil, useLegacyV, err
|
||||
return nil, useEthereumV, err
|
||||
}
|
||||
sighash, msg := SignTextValidator(validatorData)
|
||||
message := []*NameValueType{
|
||||
|
|
@ -204,15 +204,15 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
|
|||
// Clique is the Ethereum PoA standard
|
||||
stringData, ok := data.(string)
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, useLegacyV, err
|
||||
return nil, useEthereumV, err
|
||||
}
|
||||
header := &types.Header{}
|
||||
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
|
||||
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
|
||||
sighash, cliqueRlp, err := cliqueHeaderHashAndRlp(header)
|
||||
if err != nil {
|
||||
return nil, useLegacyV, err
|
||||
return nil, useEthereumV, err
|
||||
}
|
||||
message := []*NameValueType{
|
||||
{
|
||||
|
|
@ -234,17 +234,17 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
|
|||
},
|
||||
}
|
||||
// Clique uses V on the form 0 or 1
|
||||
useLegacyV = false
|
||||
useEthereumV = false
|
||||
req = &SignDataRequest{ContentType: mediaType, Rawdata: cliqueRlp, Message: message, Hash: sighash}
|
||||
default: // also case TextPlain.Mime:
|
||||
// Calculates an Ethereum ECDSA signature for:
|
||||
// hash = keccak256("\x19${byteVersion}Ethereum Signed Message:\n${message length}${message}")
|
||||
// We expect it to be a string
|
||||
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 {
|
||||
if textData, err := hexutil.Decode(stringData); err != nil {
|
||||
return nil, useLegacyV, err
|
||||
return nil, useEthereumV, err
|
||||
} else {
|
||||
sighash, msg := accounts.TextAndHash(textData)
|
||||
message := []*NameValueType{
|
||||
|
|
@ -260,7 +260,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
|
|||
}
|
||||
req.Address = addr
|
||||
req.Meta = MetadataFromContext(ctx)
|
||||
return req, useLegacyV, nil
|
||||
return req, useEthereumV, nil
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue