aboutsummaryrefslogtreecommitdiffstats
path: root/core/types
diff options
context:
space:
mode:
Diffstat (limited to 'core/types')
-rw-r--r--core/types/transaction.go9
-rw-r--r--core/types/transaction_signing.go40
-rw-r--r--core/types/transaction_signing_test.go8
-rw-r--r--core/types/transaction_test.go2
4 files changed, 9 insertions, 50 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 87b54ab30..e610671d3 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -18,7 +18,6 @@ package types
import (
"container/heap"
- "crypto/ecdsa"
"encoding/json"
"errors"
"fmt"
@@ -293,14 +292,6 @@ func (tx *Transaction) AsMessage(s Signer) (Message, error) {
return msg, err
}
-// SignECDSA signs the transaction using the given signer and private key
-//
-// XXX This only makes for a nice API: NewTx(...).SignECDSA(signer, prv). Should
-// we keep this?
-func (tx *Transaction) SignECDSA(signer Signer, prv *ecdsa.PrivateKey) (*Transaction, error) {
- return signer.SignECDSA(tx, prv)
-}
-
// WithSignature returns a new transaction with the given signature.
// This signature needs to be formatted as described in the yellow paper (v+27).
func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, error) {
diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go
index 8952bd574..4ebc789a5 100644
--- a/core/types/transaction_signing.go
+++ b/core/types/transaction_signing.go
@@ -50,8 +50,8 @@ func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer {
return signer
}
-// SignECDSA signs the transaction using the given signer and private key
-func SignECDSA(s Signer, tx *Transaction, prv *ecdsa.PrivateKey) (*Transaction, error) {
+// SignTx signs the transaction using the given signer and private key
+func SignTx(tx *Transaction, s Signer, prv *ecdsa.PrivateKey) (*Transaction, error) {
h := s.Hash(tx)
sig, err := crypto.Sign(h[:], prv)
if err != nil {
@@ -96,9 +96,8 @@ type Signer interface {
Hash(tx *Transaction) common.Hash
// PubilcKey returns the public key derived from the signature
PublicKey(tx *Transaction) ([]byte, error)
- // SignECDSA signs the transaction with the given and returns a copy of the tx
- SignECDSA(tx *Transaction, prv *ecdsa.PrivateKey) (*Transaction, error)
- // WithSignature returns a copy of the transaction with the given signature
+ // WithSignature returns a copy of the transaction with the given signature.
+ // The signature must be encoded in [R || S || V] format where V is 0 or 1.
WithSignature(tx *Transaction, sig []byte) (*Transaction, error)
// Checks for equality on the signers
Equal(Signer) bool
@@ -124,10 +123,6 @@ func (s EIP155Signer) Equal(s2 Signer) bool {
return ok && eip155.chainId.Cmp(s.chainId) == 0
}
-func (s EIP155Signer) SignECDSA(tx *Transaction, prv *ecdsa.PrivateKey) (*Transaction, error) {
- return SignECDSA(s, tx, prv)
-}
-
func (s EIP155Signer) PublicKey(tx *Transaction) ([]byte, error) {
// if the transaction is not protected fall back to homestead signer
if !tx.Protected() {
@@ -193,15 +188,6 @@ func (s EIP155Signer) Hash(tx *Transaction) common.Hash {
})
}
-func (s EIP155Signer) SigECDSA(tx *Transaction, prv *ecdsa.PrivateKey) (*Transaction, error) {
- h := s.Hash(tx)
- sig, err := crypto.Sign(h[:], prv)
- if err != nil {
- return nil, err
- }
- return s.WithSignature(tx, sig)
-}
-
// HomesteadTransaction implements TransactionInterface using the
// homestead rules.
type HomesteadSigner struct{ FrontierSigner }
@@ -224,15 +210,6 @@ func (hs HomesteadSigner) WithSignature(tx *Transaction, sig []byte) (*Transacti
return cpy, nil
}
-func (hs HomesteadSigner) SignECDSA(tx *Transaction, prv *ecdsa.PrivateKey) (*Transaction, error) {
- h := hs.Hash(tx)
- sig, err := crypto.Sign(h[:], prv)
- if err != nil {
- return nil, err
- }
- return hs.WithSignature(tx, sig)
-}
-
func (hs HomesteadSigner) PublicKey(tx *Transaction) ([]byte, error) {
if tx.data.V.BitLen() > 8 {
return nil, ErrInvalidSig
@@ -280,15 +257,6 @@ func (fs FrontierSigner) WithSignature(tx *Transaction, sig []byte) (*Transactio
return cpy, nil
}
-func (fs FrontierSigner) SignECDSA(tx *Transaction, prv *ecdsa.PrivateKey) (*Transaction, error) {
- h := fs.Hash(tx)
- sig, err := crypto.Sign(h[:], prv)
- if err != nil {
- return nil, err
- }
- return fs.WithSignature(tx, sig)
-}
-
// Hash returns the hash to be sned by the sender.
// It does not uniquely identify the transaction.
func (fs FrontierSigner) Hash(tx *Transaction) common.Hash {
diff --git a/core/types/transaction_signing_test.go b/core/types/transaction_signing_test.go
index dc618e570..3216fcfad 100644
--- a/core/types/transaction_signing_test.go
+++ b/core/types/transaction_signing_test.go
@@ -30,7 +30,7 @@ func TestEIP155Signing(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey)
signer := NewEIP155Signer(big.NewInt(18))
- tx, err := NewTransaction(0, addr, new(big.Int), new(big.Int), new(big.Int), nil).SignECDSA(signer, key)
+ tx, err := SignTx(NewTransaction(0, addr, new(big.Int), new(big.Int), new(big.Int), nil), signer, key)
if err != nil {
t.Fatal(err)
}
@@ -49,7 +49,7 @@ func TestEIP155ChainId(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey)
signer := NewEIP155Signer(big.NewInt(18))
- tx, err := NewTransaction(0, addr, new(big.Int), new(big.Int), new(big.Int), nil).SignECDSA(signer, key)
+ tx, err := SignTx(NewTransaction(0, addr, new(big.Int), new(big.Int), new(big.Int), nil), signer, key)
if err != nil {
t.Fatal(err)
}
@@ -62,7 +62,7 @@ func TestEIP155ChainId(t *testing.T) {
}
tx = NewTransaction(0, addr, new(big.Int), new(big.Int), new(big.Int), nil)
- tx, err = tx.SignECDSA(HomesteadSigner{}, key)
+ tx, err = SignTx(tx, HomesteadSigner{}, key)
if err != nil {
t.Fatal(err)
}
@@ -121,7 +121,7 @@ func TestChainId(t *testing.T) {
tx := NewTransaction(0, common.Address{}, new(big.Int), new(big.Int), new(big.Int), nil)
var err error
- tx, err = tx.SignECDSA(NewEIP155Signer(big.NewInt(1)), key)
+ tx, err = SignTx(tx, NewEIP155Signer(big.NewInt(1)), key)
if err != nil {
t.Fatal(err)
}
diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go
index 4a38462e3..f52f80d34 100644
--- a/core/types/transaction_test.go
+++ b/core/types/transaction_test.go
@@ -138,7 +138,7 @@ func TestTransactionPriceNonceSort(t *testing.T) {
for start, key := range keys {
addr := crypto.PubkeyToAddress(key.PublicKey)
for i := 0; i < 25; i++ {
- tx, _ := NewTransaction(uint64(start+i), common.Address{}, big.NewInt(100), big.NewInt(100), big.NewInt(int64(start+i)), nil).SignECDSA(signer, key)
+ tx, _ := SignTx(NewTransaction(uint64(start+i), common.Address{}, big.NewInt(100), big.NewInt(100), big.NewInt(int64(start+i)), nil), signer, key)
groups[addr] = append(groups[addr], tx)
}
}