Skip to content

Commit

Permalink
Reintroduce Wallet.SignHash (ethereum#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-chrzan authored Feb 11, 2020
1 parent 6237993 commit 9fdfbd1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
8 changes: 8 additions & 0 deletions accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ type Wallet interface {
// the account in a keystore).
SignData(account Account, mimeType string, data []byte) ([]byte, error)

// SignHash is like SignData but doesn't hash the given data
//
// NOTE: DEPRACATED, use SignData for future releases.
// This is needed for backwards compatibility on a network where validators
// started on celo-blockchain 1.8. 1.9 removed the SignHash function,
// replacing it with SignData, which always hashes the input before signing.
SignHash(account Account, hash []byte) ([]byte, error)

// SignDataWithPassphrase is identical to SignData, but also takes a password
// NOTE: there's an chance that an erroneous call might mistake the two strings, and
// supply password in the mimetype field, or vice versa. Thus, an implementation
Expand Down
7 changes: 7 additions & 0 deletions accounts/external/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ func (api *ExternalSigner) SignData(account accounts.Account, mimeType string, d
return res, nil
}

// SignHash is not implemented for the external signer
//
// DEPRECATED, use SignData in future releases.
func (api *ExternalSigner) SignHash(account accounts.Account, hash []byte) ([]byte, error) {
panic("SignHash not implemented for the external signer")
}

func (api *ExternalSigner) SignText(account accounts.Account, text []byte) ([]byte, error) {
var res hexutil.Bytes
var signAddress = common.NewMixedcaseAddress(account.Address)
Expand Down
10 changes: 10 additions & 0 deletions accounts/keystore/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ func (w *keystoreWallet) SignData(account accounts.Account, mimeType string, dat
return w.signHash(account, crypto.Keccak256(data))
}

// SignHash implements accounts.Wallet, attempting to sign the given hash with
// the given account. If the wallet does not wrap this particular account, an
// error is returned to avoid account leakage (even though in theory we may be
// able to sign via our shared keystore backend).
//
// DEPRECATED, use SignData in future releases.
func (w *keystoreWallet) SignHash(account accounts.Account, hash []byte) ([]byte, error) {
return w.signHash(account, hash)
}

// SignDataWithPassphrase signs keccak256(data). The mimetype parameter describes the type of data being signed
func (w *keystoreWallet) SignDataWithPassphrase(account accounts.Account, passphrase, mimeType string, data []byte) ([]byte, error) {
// Make sure the requested account is contained within
Expand Down
10 changes: 10 additions & 0 deletions accounts/scwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,16 @@ func (w *Wallet) SignData(account accounts.Account, mimeType string, data []byte
return w.signHash(account, crypto.Keccak256(data))
}

// SignHash implements accounts.Wallet, attempting to sign the given hash with
// the given account. If the wallet does not wrap this particular account, an
// error is returned to avoid account leakage (even though in theory we may be
// able to sign via our shared keystore backend).
//
// DEPRECATED, use SignData in future releases.
func (w *Wallet) SignHash(account accounts.Account, hash []byte) ([]byte, error) {
return w.signHash(account, hash)
}

func (w *Wallet) signHash(account accounts.Account, hash []byte) ([]byte, error) {
w.lock.Lock()
defer w.lock.Unlock()
Expand Down
10 changes: 10 additions & 0 deletions accounts/usbwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,16 @@ func (w *wallet) SignData(account accounts.Account, mimeType string, data []byte
return w.signHash(account, crypto.Keccak256(data))
}

// SignHash implements accounts.Wallet, attempting to sign the given hash with
// the given account. If the wallet does not wrap this particular account, an
// error is returned to avoid account leakage (even though in theory we may be
// able to sign via our shared keystore backend).
//
// DEPRECATED, use SignData in future releases.
func (w *wallet) SignHash(account accounts.Account, hash []byte) ([]byte, error) {
return w.signHash(account, hash)
}

// SignDataWithPassphrase implements accounts.Wallet, attempting to sign the given
// data with the given account using passphrase as extra authentication.
// Since USB wallets don't rely on passphrases, these are silently ignored.
Expand Down
3 changes: 2 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,8 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
account := accounts.Account{Address: w.coinbase}
wallet, err := w.eth.AccountManager().Find(account)
if err == nil {
randomSeed, err = wallet.SignData(account, accounts.MimetypeTextPlain, randomSeedString)
// TODO: Use SignData instead
randomSeed, err = wallet.SignHash(account, common.BytesToHash(randomSeedString).Bytes())
}
if err != nil {
log.Error("Unable to create random seed", "err", err)
Expand Down

0 comments on commit 9fdfbd1

Please sign in to comment.