aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/accounts.go
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2019-02-05 18:23:57 +0800
committerGitHub <noreply@github.com>2019-02-05 18:23:57 +0800
commit43e8efe8955b8bb1fab7bfced33a6302fb69e48e (patch)
tree3db96494c913b31be950f5580bf49a82141b9255 /accounts/accounts.go
parent520024dfd689d264807b7fe1fc28deba51d6ab20 (diff)
downloadgo-tangerine-43e8efe8955b8bb1fab7bfced33a6302fb69e48e.tar
go-tangerine-43e8efe8955b8bb1fab7bfced33a6302fb69e48e.tar.gz
go-tangerine-43e8efe8955b8bb1fab7bfced33a6302fb69e48e.tar.bz2
go-tangerine-43e8efe8955b8bb1fab7bfced33a6302fb69e48e.tar.lz
go-tangerine-43e8efe8955b8bb1fab7bfced33a6302fb69e48e.tar.xz
go-tangerine-43e8efe8955b8bb1fab7bfced33a6302fb69e48e.tar.zst
go-tangerine-43e8efe8955b8bb1fab7bfced33a6302fb69e48e.zip
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
Diffstat (limited to 'accounts/accounts.go')
-rw-r--r--accounts/accounts.go35
1 files changed, 31 insertions, 4 deletions
diff --git a/accounts/accounts.go b/accounts/accounts.go
index cb1eae281..11232b19a 100644
--- a/accounts/accounts.go
+++ b/accounts/accounts.go
@@ -18,12 +18,14 @@
package accounts
import (
+ "fmt"
"math/big"
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
+ "golang.org/x/crypto/sha3"
)
// Account represents an Ethereum account located at a specific location defined
@@ -87,8 +89,20 @@ type Wallet interface {
// chain state reader.
SelfDerive(base DerivationPath, chain ethereum.ChainStateReader)
- // SignHash requests the wallet to sign the given hash.
+ // SignData requests the wallet to sign the hash of the given data
+ // It looks up the account specified either solely via its address contained within,
+ // or optionally with the aid of any location metadata from the embedded URL field.
//
+ // If the wallet requires additional authentication to sign the request (e.g.
+ // a password to decrypt the account, or a PIN code o verify the transaction),
+ // an AuthNeededError instance will be returned, containing infos for the user
+ // about which fields or actions are needed. The user may retry by providing
+ // the needed details via SignHashWithPassphrase, or by other means (e.g. unlock
+ // the account in a keystore).
+ SignData(account Account, mimeType string, data []byte) ([]byte, error)
+
+ // Signtext requests the wallet to sign the hash of a given piece of data, prefixed
+ // by the Ethereum prefix scheme
// It looks up the account specified either solely via its address contained within,
// or optionally with the aid of any location metadata from the embedded URL field.
//
@@ -98,7 +112,7 @@ type Wallet interface {
// about which fields or actions are needed. The user may retry by providing
// the needed details via SignHashWithPassphrase, or by other means (e.g. unlock
// the account in a keystore).
- SignHash(account Account, hash []byte) ([]byte, error)
+ SignText(account Account, text []byte) ([]byte, error)
// SignTx requests the wallet to sign the given transaction.
//
@@ -113,12 +127,12 @@ type Wallet interface {
// the account in a keystore).
SignTx(account Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
- // SignHashWithPassphrase requests the wallet to sign the given hash with the
+ // SignTextWithPassphrase requests the wallet to sign the given text with the
// given passphrase as extra authentication information.
//
// It looks up the account specified either solely via its address contained within,
// or optionally with the aid of any location metadata from the embedded URL field.
- SignHashWithPassphrase(account Account, passphrase string, hash []byte) ([]byte, error)
+ SignTextWithPassphrase(account Account, passphrase string, hash []byte) ([]byte, error)
// SignTxWithPassphrase requests the wallet to sign the given transaction, with the
// given passphrase as extra authentication information.
@@ -148,6 +162,19 @@ type Backend interface {
Subscribe(sink chan<- WalletEvent) event.Subscription
}
+// TextHash is a helper function that calculates a hash for the given message that can be
+// safely used to calculate a signature from.
+//
+// The hash is calulcated as
+// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
+//
+// This gives context to the signed message and prevents signing of transactions.
+func TextHash(data []byte) []byte {
+ hash := sha3.NewLegacyKeccak256()
+ fmt.Fprintf(hash, "\x19Ethereum Signed Message:\n%d%s", len(data), data)
+ return hash.Sum(nil)
+}
+
// WalletEventType represents the different event types that can be fired by
// the wallet subscription subsystem.
type WalletEventType int