2019-07-22 12:17:27 +03:00
|
|
|
// Copyright 2019 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
//
|
2019-07-22 12:17:27 +03:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2019-07-22 12:17:27 +03:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-07-22 12:17:27 +03:00
|
|
|
// GNU Lesser General Public License for more details.
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
//
|
2019-07-22 12:17:27 +03:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
|
|
|
|
package external
|
|
|
|
|
|
|
|
import (
|
2023-05-25 20:25:58 +08:00
|
|
|
"errors"
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
"fmt"
|
|
|
|
"math/big"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
|
|
|
"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/event"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2021-07-29 16:06:44 +02:00
|
|
|
"github.com/ethereum/go-ethereum/signer/core/apitypes"
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type ExternalBackend struct {
|
|
|
|
signers []accounts.Wallet
|
|
|
|
}
|
|
|
|
|
|
|
|
func (eb *ExternalBackend) Wallets() []accounts.Wallet {
|
|
|
|
return eb.signers
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewExternalBackend(endpoint string) (*ExternalBackend, error) {
|
|
|
|
signer, err := NewExternalSigner(endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &ExternalBackend{
|
|
|
|
signers: []accounts.Wallet{signer},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (eb *ExternalBackend) Subscribe(sink chan<- accounts.WalletEvent) event.Subscription {
|
|
|
|
return event.NewSubscription(func(quit <-chan struct{}) error {
|
|
|
|
<-quit
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExternalSigner provides an API to interact with an external signer (clef)
|
|
|
|
// It proxies request to the external signer while forwarding relevant
|
|
|
|
// request headers
|
|
|
|
type ExternalSigner struct {
|
|
|
|
client *rpc.Client
|
|
|
|
endpoint string
|
|
|
|
status string
|
|
|
|
cacheMu sync.RWMutex
|
|
|
|
cache []accounts.Account
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewExternalSigner(endpoint string) (*ExternalSigner, error) {
|
|
|
|
client, err := rpc.Dial(endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
extsigner := &ExternalSigner{
|
|
|
|
client: client,
|
|
|
|
endpoint: endpoint,
|
|
|
|
}
|
|
|
|
// Check if reachable
|
|
|
|
version, err := extsigner.pingVersion()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
extsigner.status = fmt.Sprintf("ok [version=%v]", version)
|
|
|
|
return extsigner, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) URL() accounts.URL {
|
|
|
|
return accounts.URL{
|
|
|
|
Scheme: "extapi",
|
|
|
|
Path: api.endpoint,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) Status() (string, error) {
|
|
|
|
return api.status, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) Open(passphrase string) error {
|
2023-05-25 20:25:58 +08:00
|
|
|
return errors.New("operation not supported on external signers")
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) Close() error {
|
2023-05-25 20:25:58 +08:00
|
|
|
return errors.New("operation not supported on external signers")
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) Accounts() []accounts.Account {
|
|
|
|
var accnts []accounts.Account
|
|
|
|
res, err := api.listAccounts()
|
|
|
|
if err != nil {
|
|
|
|
log.Error("account listing failed", "error", err)
|
|
|
|
return accnts
|
|
|
|
}
|
|
|
|
for _, addr := range res {
|
|
|
|
accnts = append(accnts, accounts.Account{
|
|
|
|
URL: accounts.URL{
|
|
|
|
Scheme: "extapi",
|
|
|
|
Path: api.endpoint,
|
|
|
|
},
|
|
|
|
Address: addr,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
api.cacheMu.Lock()
|
|
|
|
api.cache = accnts
|
|
|
|
api.cacheMu.Unlock()
|
|
|
|
return accnts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) Contains(account accounts.Account) bool {
|
|
|
|
api.cacheMu.RLock()
|
|
|
|
defer api.cacheMu.RUnlock()
|
2020-04-30 18:57:06 +02:00
|
|
|
if api.cache == nil {
|
|
|
|
// If we haven't already fetched the accounts, it's time to do so now
|
|
|
|
api.cacheMu.RUnlock()
|
|
|
|
api.Accounts()
|
|
|
|
api.cacheMu.RLock()
|
|
|
|
}
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
for _, a := range api.cache {
|
|
|
|
if a.Address == account.Address && (account.URL == (accounts.URL{}) || account.URL == api.URL()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) Derive(path accounts.DerivationPath, pin bool) (accounts.Account, error) {
|
2023-05-25 20:25:58 +08:00
|
|
|
return accounts.Account{}, errors.New("operation not supported on external signers")
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
2019-04-10 13:09:08 +03:00
|
|
|
func (api *ExternalSigner) SelfDerive(bases []accounts.DerivationPath, chain ethereum.ChainStateReader) {
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
log.Error("operation SelfDerive not supported on external signers")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2019-02-12 14:00:02 +01:00
|
|
|
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
|
|
|
|
}
|
2020-05-25 16:21:28 +08:00
|
|
|
// If V is on 27/28-form, convert to 0/1 for Clique
|
2019-02-12 14:00:02 +01:00
|
|
|
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
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) SignText(account accounts.Account, text []byte) ([]byte, error) {
|
2020-05-01 13:52:41 +02:00
|
|
|
var signature hexutil.Bytes
|
2019-02-12 14:00:02 +01:00
|
|
|
var signAddress = common.NewMixedcaseAddress(account.Address)
|
2020-05-01 13:52:41 +02:00
|
|
|
if err := api.client.Call(&signature, "account_signData",
|
2019-02-12 14:00:02 +01:00
|
|
|
accounts.MimetypeTextPlain,
|
|
|
|
&signAddress, // Need to use the pointer here, because of how MarshalJSON is defined
|
|
|
|
hexutil.Encode(text)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-01 13:52:41 +02:00
|
|
|
if signature[64] == 27 || signature[64] == 28 {
|
|
|
|
// If clef is used as a backend, it may already have transformed
|
|
|
|
// the signature to ethereum-type signature.
|
|
|
|
signature[64] -= 27 // Transform V from Ethereum-legacy to 0/1
|
|
|
|
}
|
|
|
|
return signature, nil
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
2020-07-10 17:33:31 +08:00
|
|
|
// signTransactionResult represents the signinig result returned by clef.
|
|
|
|
type signTransactionResult struct {
|
|
|
|
Raw hexutil.Bytes `json:"raw"`
|
|
|
|
Tx *types.Transaction `json:"tx"`
|
|
|
|
}
|
|
|
|
|
2021-08-13 15:39:51 +03:00
|
|
|
// SignTx sends the transaction to the external signer.
|
|
|
|
// If chainID is nil, or tx.ChainID is zero, the chain ID will be assigned
|
|
|
|
// by the external signer. For non-legacy transactions, the chain ID of the
|
|
|
|
// transaction overrides the chainID parameter.
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
|
|
|
|
data := hexutil.Bytes(tx.Data())
|
2019-07-04 03:54:59 +08:00
|
|
|
var to *common.MixedcaseAddress
|
|
|
|
if tx.To() != nil {
|
|
|
|
t := common.NewMixedcaseAddress(*tx.To())
|
|
|
|
to = &t
|
|
|
|
}
|
2021-07-29 16:06:44 +02:00
|
|
|
args := &apitypes.SendTxArgs{
|
2021-06-09 13:48:47 +02:00
|
|
|
Data: &data,
|
|
|
|
Nonce: hexutil.Uint64(tx.Nonce()),
|
|
|
|
Value: hexutil.Big(*tx.Value()),
|
|
|
|
Gas: hexutil.Uint64(tx.Gas()),
|
|
|
|
To: to,
|
|
|
|
From: common.NewMixedcaseAddress(account.Address),
|
|
|
|
}
|
accounts/external, internal/ethapi: fixes for London tx signing (#23274)
Ticket #23273 found a flaw where we were unable to sign legacy-transactions
using the external signer, even if we're still on non-london network. That's
fixed in this PR.
Additionally, I found that even when supplying all parameters, it was impossible
to sign a london-transaction on an unsynched node. It's a pretty common usecase
that someone wants to sign a transaction using an unsynced 'vanilla' node,
providing all necessary data. Our setDefaults, however, insisted on checking the
current block against the config. This PR therefore adds a case, so that if both
MaxPriorityFeePerGas and MaxFeePerGas are provided, we accept them as given.
OBS This PR fixes a regression -- on current master, we are unable to sign a
london-transaction unless the node is synched, which may break scenarios where
geth (or clef) is used as a cold wallet.
Fixes #23273
2021-07-29 14:00:06 +02:00
|
|
|
switch tx.Type() {
|
|
|
|
case types.LegacyTxType, types.AccessListTxType:
|
|
|
|
args.GasPrice = (*hexutil.Big)(tx.GasPrice())
|
|
|
|
case types.DynamicFeeTxType:
|
2021-06-09 13:48:47 +02:00
|
|
|
args.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap())
|
|
|
|
args.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap())
|
accounts/external, internal/ethapi: fixes for London tx signing (#23274)
Ticket #23273 found a flaw where we were unable to sign legacy-transactions
using the external signer, even if we're still on non-london network. That's
fixed in this PR.
Additionally, I found that even when supplying all parameters, it was impossible
to sign a london-transaction on an unsynched node. It's a pretty common usecase
that someone wants to sign a transaction using an unsynced 'vanilla' node,
providing all necessary data. Our setDefaults, however, insisted on checking the
current block against the config. This PR therefore adds a case, so that if both
MaxPriorityFeePerGas and MaxFeePerGas are provided, we accept them as given.
OBS This PR fixes a regression -- on current master, we are unable to sign a
london-transaction unless the node is synched, which may break scenarios where
geth (or clef) is used as a cold wallet.
Fixes #23273
2021-07-29 14:00:06 +02:00
|
|
|
default:
|
2021-08-13 15:39:51 +03:00
|
|
|
return nil, fmt.Errorf("unsupported tx type %d", tx.Type())
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
}
|
2021-04-21 13:03:33 +02:00
|
|
|
// We should request the default chain id that we're operating with
|
|
|
|
// (the chain we're executing on)
|
2021-08-13 15:39:51 +03:00
|
|
|
if chainID != nil && chainID.Sign() != 0 {
|
2021-04-21 13:03:33 +02:00
|
|
|
args.ChainID = (*hexutil.Big)(chainID)
|
|
|
|
}
|
2021-05-17 15:13:22 +02:00
|
|
|
if tx.Type() != types.LegacyTxType {
|
|
|
|
// However, if the user asked for a particular chain id, then we should
|
|
|
|
// use that instead.
|
2021-08-13 15:39:51 +03:00
|
|
|
if tx.ChainId().Sign() != 0 {
|
2021-05-17 15:13:22 +02:00
|
|
|
args.ChainID = (*hexutil.Big)(tx.ChainId())
|
|
|
|
}
|
2021-04-21 13:03:33 +02:00
|
|
|
accessList := tx.AccessList()
|
|
|
|
args.AccessList = &accessList
|
|
|
|
}
|
2020-07-10 17:33:31 +08:00
|
|
|
var res signTransactionResult
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
if err := api.client.Call(&res, "account_signTransaction", args); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return res.Tx, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) SignTextWithPassphrase(account accounts.Account, passphrase string, text []byte) ([]byte, error) {
|
2023-05-25 20:25:58 +08:00
|
|
|
return []byte{}, errors.New("password-operations not supported on external signers")
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
|
2023-05-25 20:25:58 +08:00
|
|
|
return nil, errors.New("password-operations not supported on external signers")
|
signer, clef: implement EIP191/712 (#17789)
* Named functions and defined a basic EIP191 content type list
* Written basic content type functions
* Added ecRecover method in the clef api
* Updated the extapi changelog and addded indications in the README
* Changed the version of the external API
* Added tests for 0x45
* Implementing UnmarshalJSON() for TypedData
* Working on TypedData
* Solved the auditlog issue
* Changed method to signTypedData
* Changed mimes and implemented the 'encodeType' function for EIP-712
* Polished docstrings, ran goimports and swapped fmt.Errorf with errors.New where possible
* Drafted recursive encodeData
* Ran goimports and gofmt
* Drafted first version of EIP-712, including tests
* Temporarily switched to using common.Address in tests
* Drafted text/validator and and rewritten []byte as hexutil.Bytes
* Solved stringified address encoding issue
* Changed the property type required by signData from bytes to interface{}
* Fixed bugs in 'data/typed' signs
* Brought legal warning back after temporarily disabling it for development
* Added example RPC calls for account_signData and account_signTypedData
* Named functions and defined a basic EIP191 content type list
* Written basic content type functions
* Added ecRecover method in the clef api
* Updated the extapi changelog and addded indications in the README
* Added tests for 0x45
* Implementing UnmarshalJSON() for TypedData
* Working on TypedData
* Solved the auditlog issue
* Changed method to signTypedData
* Changed mimes and implemented the 'encodeType' function for EIP-712
* Polished docstrings, ran goimports and swapped fmt.Errorf with errors.New where possible
* Drafted recursive encodeData
* Ran goimports and gofmt
* Drafted first version of EIP-712, including tests
* Temporarily switched to using common.Address in tests
* Drafted text/validator and and rewritten []byte as hexutil.Bytes
* Solved stringified address encoding issue
* Changed the property type required by signData from bytes to interface{}
* Fixed bugs in 'data/typed' signs
* Brought legal warning back after temporarily disabling it for development
* Added example RPC calls for account_signData and account_signTypedData
* Polished and fixed PR
* Polished and fixed PR
* Solved malformed data panics and also wrote tests
* Solved malformed data panics and also wrote tests
* Added alphabetical sorting to type dependencies
* Added alphabetical sorting to type dependencies
* Added pretty print to data/typed UI
* Added pretty print to data/typed UI
* signer: more tests for typed data
* signer: more tests for typed data
* Fixed TestMalformedData4 errors and renamed IsValid to Validate
* Fixed TestMalformedData4 errors and renamed IsValid to Validate
* Fixed more new failing tests and deanonymised some functions
* Fixed more new failing tests and deanonymised some functions
* Added types to EIP712 output in cliui
* Added types to EIP712 output in cliui
* Fixed regexp issues
* Fixed regexp issues
* Added pseudo-failing test
* Added pseudo-failing test
* Fixed false positive test
* Fixed false positive test
* Added PrettyPrint method
* Added PrettyPrint method
* signer: refactor formatting and UI
* signer: make ui use new message format for signing
* Fixed breaking changes
* Fixed rules_test failing test
* Added extra regexp for reference types
* signer: more hard types
* Fixed failing test, formatted files
* signer: use golang/x keccak
* Fixed goimports error
* clef, signer: address some review concerns
* Implemented latest recommendations
* Fixed comments and uintint256 issue
* accounts, signer: fix mimetypes, add interface to sign data with passphrase
* signer, accounts: remove duplicated code, pass hash preimages to signing
* signer: prevent panic in type assertions, make cliui print rawdata as quotable-safe
* signer: linter fixes, remove deprecated crypto dependency
* accounts: fix goimport
2019-02-06 07:30:49 +00:00
|
|
|
}
|
|
|
|
func (api *ExternalSigner) SignDataWithPassphrase(account accounts.Account, passphrase, mimeType string, data []byte) ([]byte, error) {
|
2023-05-25 20:25:58 +08:00
|
|
|
return nil, errors.New("password-operations not supported on external signers")
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 11:23:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) listAccounts() ([]common.Address, error) {
|
|
|
|
var res []common.Address
|
|
|
|
if err := api.client.Call(&res, "account_list"); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *ExternalSigner) pingVersion() (string, error) {
|
|
|
|
var v string
|
|
|
|
if err := api.client.Call(&v, "account_version"); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return v, nil
|
|
|
|
}
|