Skip to content

Commit

Permalink
Revert #13 and use Sender instead of AsMessage
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez committed Jul 20, 2021
1 parent 518b14a commit 1365b41
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions hdwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (w *Wallet) SignHash(account accounts.Account, hash []byte) ([]byte, error)
}

// SignTxEIP155 implements accounts.Wallet, which allows the account to sign an ERC-20 transaction.
func (w *Wallet) SignTxEIP155(account accounts.Account, tx *types.Transaction, chainID, baseFee *big.Int) (*types.Transaction, error) {
func (w *Wallet) SignTxEIP155(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
w.stateLock.RLock() // Comms have own mutex, this is for the state fields
defer w.stateLock.RUnlock()

Expand All @@ -245,18 +245,18 @@ func (w *Wallet) SignTxEIP155(account accounts.Account, tx *types.Transaction, c
return nil, err
}

signer := types.NewEIP155Signer(chainID)
// Sign the transaction and verify the sender to avoid hardware fault surprises
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
signedTx, err := types.SignTx(tx, signer, privateKey)
if err != nil {
return nil, err
}

msg, err := signedTx.AsMessage(types.NewEIP155Signer(chainID), baseFee)
sender, err := types.Sender(signer, signedTx)
if err != nil {
return nil, err
}

sender := msg.From()
if sender != account.Address {
return nil, fmt.Errorf("signer mismatch: expected %s, got %s", account.Address.Hex(), sender.Hex())
}
Expand All @@ -265,7 +265,7 @@ func (w *Wallet) SignTxEIP155(account accounts.Account, tx *types.Transaction, c
}

// SignTx implements accounts.Wallet, which allows the account to sign an Ethereum transaction.
func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID, baseFee *big.Int) (*types.Transaction, error) {
func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
w.stateLock.RLock() // Comms have own mutex, this is for the state fields
defer w.stateLock.RUnlock()

Expand All @@ -280,18 +280,18 @@ func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID
return nil, err
}

signer := types.HomesteadSigner{}
// Sign the transaction and verify the sender to avoid hardware fault surprises
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, privateKey)
signedTx, err := types.SignTx(tx, signer, privateKey)
if err != nil {
return nil, err
}

msg, err := signedTx.AsMessage(types.HomesteadSigner{}, baseFee)
sender, err := types.Sender(signer, signedTx)
if err != nil {
return nil, err
}

sender := msg.From()
if sender != account.Address {
return nil, fmt.Errorf("signer mismatch: expected %s, got %s", account.Address.Hex(), sender.Hex())
}
Expand All @@ -308,8 +308,8 @@ func (w *Wallet) SignHashWithPassphrase(account accounts.Account, passphrase str

// SignTxWithPassphrase implements accounts.Wallet, attempting to sign the given
// transaction with the given account using passphrase as extra authentication.
func (w *Wallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID, baseFee *big.Int) (*types.Transaction, error) {
return w.SignTx(account, tx, baseFee, chainID)
func (w *Wallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
return w.SignTx(account, tx, chainID)
}

// PrivateKey returns the ECDSA private key of the account.
Expand Down

0 comments on commit 1365b41

Please sign in to comment.