From 4a14ff6abb05a47bebc42b5134b9e4a9b7221267 Mon Sep 17 00:00:00 2001 From: Stefan Liu Date: Wed, 29 Jun 2022 16:21:56 +0800 Subject: [PATCH] Add SignHash stub in wallet --- wallet/key.go | 12 ++++++++++-- wallet/wallet.go | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/wallet/key.go b/wallet/key.go index df74202..c3fe370 100644 --- a/wallet/key.go +++ b/wallet/key.go @@ -23,11 +23,11 @@ import ( "fmt" "math/big" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" ) type KeyProvider struct { @@ -66,3 +66,11 @@ func (p *KeyProvider) Save(path, passphrase string) (error) { _, err := ks.ImportECDSA(p.priv, passphrase) return err } + +func (p *KeyProvider) SignHash(account accounts.Account, hash []byte) (sig []byte, err error) { + if !bytes.Equal(account.Address.Bytes(), p.Address.Bytes()) { + return nil, fmt.Errorf("unexpected account unmatch %s, %s", account.Address.String(), p.Address.String()) + } + return crypto.Sign(hash, p.priv) +} + diff --git a/wallet/wallet.go b/wallet/wallet.go index 1927624..6421293 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -83,6 +83,7 @@ type Provider interface { SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) Init(accounts.Account) error Accounts() []accounts.Account + SignHash(accounts.Account,[]byte) ([]byte, error) } func New(config *Config, sdk *eth.SDK) *Wallet {