Skip to content

Commit

Permalink
Add SignHash stub in wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
devfans committed Jun 29, 2022
1 parent f5ae35e commit 4a14ff6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions wallet/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

1 change: 1 addition & 0 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4a14ff6

Please sign in to comment.