aboutsummaryrefslogtreecommitdiffstats
path: root/internal/ethapi/api.go
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 /internal/ethapi/api.go
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 'internal/ethapi/api.go')
-rw-r--r--internal/ethapi/api.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index b3fd4522a..4d5ef27da 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
+ "github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
@@ -1469,6 +1470,45 @@ func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (stri
return fmt.Sprintf("%x", encoded), nil
}
+// 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 {
+ return common.Address{}, fmt.Errorf("block #%d not found", number)
+ }
+ header := block.Header()
+ header.Extra = make([]byte, 32+65)
+ encoded := clique.CliqueRLP(header)
+
+ // Look up the wallet containing the requested signer
+ account := accounts.Account{Address: address}
+ wallet, err := api.b.AccountManager().Find(account)
+ if err != nil {
+ return common.Address{}, err
+ }
+
+ signature, err := wallet.SignData(account, accounts.MimetypeClique, encoded)
+ if err != nil {
+ return common.Address{}, err
+ }
+ sealHash := clique.SealHash(header).Bytes()
+ log.Info("test signing of clique block",
+ "Sealhash", fmt.Sprintf("%x", sealHash),
+ "signature", fmt.Sprintf("%x", signature))
+ pubkey, err := crypto.Ecrecover(sealHash, signature)
+ if err != nil {
+ return common.Address{}, err
+ }
+ var signer common.Address
+ copy(signer[:], crypto.Keccak256(pubkey[1:])[12:])
+
+ return signer, nil
+}
+
// PrintBlock retrieves a block and returns its pretty printed form.
func (api *PublicDebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) {
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))