mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/external, signer: implement remote signing of text, make accounts_sign take hexdata
This commit is contained in:
parent
656b1659eb
commit
af32f63c8e
2 changed files with 26 additions and 18 deletions
10
accounts/external/backend.go
vendored
10
accounts/external/backend.go
vendored
|
|
@ -160,7 +160,15 @@ func (api *ExternalSigner) SignData(account accounts.Account, mimeType string, d
|
|||
}
|
||||
|
||||
func (api *ExternalSigner) SignText(account accounts.Account, text []byte) ([]byte, error) {
|
||||
return api.signHash(account, accounts.TextHash(text))
|
||||
var res hexutil.Bytes
|
||||
var signAddress = common.NewMixedcaseAddress(account.Address)
|
||||
if err := api.client.Call(&res, "account_signData",
|
||||
accounts.MimetypeTextPlain,
|
||||
&signAddress, // Need to use the pointer here, because of how MarshalJSON is defined
|
||||
hexutil.Encode(text)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
|
||||
|
|
|
|||
|
|
@ -229,23 +229,23 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
|
|||
// Calculates an Ethereum ECDSA signature for:
|
||||
// hash = keccak256("\x19${byteVersion}Ethereum Signed Message:\n${message length}${message}")
|
||||
// We expect it to be a string
|
||||
stringData, ok := data.(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("input for text/plain must be a string")
|
||||
if stringData, ok := data.(string); !ok {
|
||||
return nil, fmt.Errorf("input for text/plain must be an hex-encoded string")
|
||||
} else {
|
||||
if textData, err := hexutil.Decode(stringData); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
sighash, msg := accounts.TextAndHash(textData)
|
||||
message := []*NameValueType{
|
||||
{
|
||||
Name: "message",
|
||||
Typ: "text/plain",
|
||||
Value: msg,
|
||||
},
|
||||
}
|
||||
req = &SignDataRequest{ContentType: mediaType, Rawdata: []byte(msg), Message: message, Hash: sighash}
|
||||
}
|
||||
}
|
||||
//plainData, err := hexutil.Decode(stringdata)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
sighash, msg := accounts.TextAndHash([]byte(stringData))
|
||||
message := []*NameValueType{
|
||||
{
|
||||
Name: "message",
|
||||
Typ: "text/plain",
|
||||
Value: msg,
|
||||
},
|
||||
}
|
||||
req = &SignDataRequest{ContentType: mediaType, Rawdata: []byte(msg), Message: message, Hash: sighash}
|
||||
}
|
||||
req.Address = addr
|
||||
req.Meta = MetadataFromContext(ctx)
|
||||
|
|
@ -722,7 +722,7 @@ func (nvt *NameValueType) Pprint(depth int) string {
|
|||
output.WriteString(sublevel)
|
||||
}
|
||||
} else {
|
||||
output.WriteString(fmt.Sprintf("%s\n", nvt.Value))
|
||||
output.WriteString(fmt.Sprintf("%q\n", nvt.Value))
|
||||
}
|
||||
return output.String()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue