aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/external
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2019-02-12 21:00:02 +0800
committerGitHub <noreply@github.com>2019-02-12 21:00:02 +0800
commit75d292bcf673e1b10ac883f8767d092d2f45fd9a (patch)
tree072e2ddae84bfae2e1f0a72e8aeaa9dc82c6d937 /accounts/external
parentedf976ee8e7e1561cf11cbdc5a0c5edb497dda34 (diff)
downloadgo-tangerine-75d292bcf673e1b10ac883f8767d092d2f45fd9a.tar
go-tangerine-75d292bcf673e1b10ac883f8767d092d2f45fd9a.tar.gz
go-tangerine-75d292bcf673e1b10ac883f8767d092d2f45fd9a.tar.bz2
go-tangerine-75d292bcf673e1b10ac883f8767d092d2f45fd9a.tar.lz
go-tangerine-75d292bcf673e1b10ac883f8767d092d2f45fd9a.tar.xz
go-tangerine-75d292bcf673e1b10ac883f8767d092d2f45fd9a.tar.zst
go-tangerine-75d292bcf673e1b10ac883f8767d092d2f45fd9a.zip
clef: external signing fixes + signing data (#19003)
* signer/clef: make use of json-rpc notification * signer: tidy up output of OnApprovedTx * accounts/external, signer: implement remote signing of text, make accounts_sign take hexdata * clef: added basic testscript * signer, external, api: add clique signing test to debug rpc, fix clique signing in clef * signer: fix clique interoperability between geth and clef * clef: rename networkid switch to chainid * clef: enable chainid flag * clef, signer: minor changes from review * clef: more tests for signer
Diffstat (limited to 'accounts/external')
-rw-r--r--accounts/external/backend.go39
1 files changed, 22 insertions, 17 deletions
diff --git a/accounts/external/backend.go b/accounts/external/backend.go
index 3b8d50f1b..21a313b66 100644
--- a/accounts/external/backend.go
+++ b/accounts/external/backend.go
@@ -26,7 +26,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
@@ -154,13 +153,31 @@ func (api *ExternalSigner) signHash(account accounts.Account, hash []byte) ([]by
// SignData signs keccak256(data). The mimetype parameter describes the type of data being signed
func (api *ExternalSigner) SignData(account accounts.Account, mimeType string, data []byte) ([]byte, error) {
- // TODO! Replace this with a call to clef SignData with correct mime-type for Clique, once we
- // have that in place
- return api.signHash(account, crypto.Keccak256(data))
+ var res hexutil.Bytes
+ var signAddress = common.NewMixedcaseAddress(account.Address)
+ if err := api.client.Call(&res, "account_signData",
+ mimeType,
+ &signAddress, // Need to use the pointer here, because of how MarshalJSON is defined
+ hexutil.Encode(data)); err != nil {
+ return nil, err
+ }
+ // If V is on 27/28-form, convert to to 0/1 for Clique
+ if mimeType == accounts.MimetypeClique && (res[64] == 27 || res[64] == 28) {
+ res[64] -= 27 // Transform V from 27/28 to 0/1 for Clique use
+ }
+ return res, nil
}
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) {
@@ -202,18 +219,6 @@ func (api *ExternalSigner) listAccounts() ([]common.Address, error) {
return res, nil
}
-func (api *ExternalSigner) signCliqueBlock(a common.Address, rlpBlock hexutil.Bytes) (hexutil.Bytes, error) {
- var sig hexutil.Bytes
- if err := api.client.Call(&sig, "account_signData", core.ApplicationClique.Mime, a, rlpBlock); err != nil {
- return nil, err
- }
- if sig[64] != 27 && sig[64] != 28 {
- return nil, fmt.Errorf("invalid Ethereum signature (V is not 27 or 28)")
- }
- sig[64] -= 27 // Transform V from 27/28 to 0/1 for Clique use
- return sig, nil
-}
-
func (api *ExternalSigner) pingVersion() (string, error) {
var v string
if err := api.client.Call(&v, "account_version"); err != nil {