|
|
@ -8,7 +8,6 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
"github.com/ethereum/go-ethereum/crypto/secp256k1" |
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/logger" |
|
|
|
"github.com/ethereum/go-ethereum/logger" |
|
|
|
"github.com/ethereum/go-ethereum/logger/glog" |
|
|
|
"github.com/ethereum/go-ethereum/logger/glog" |
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
@ -93,9 +92,9 @@ func (self *Transaction) SetNonce(AccountNonce uint64) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (self *Transaction) From() (common.Address, error) { |
|
|
|
func (self *Transaction) From() (common.Address, error) { |
|
|
|
pubkey := self.PublicKey() |
|
|
|
pubkey, err := self.PublicKey() |
|
|
|
if len(pubkey) == 0 || pubkey[0] != 4 { |
|
|
|
if err != nil { |
|
|
|
return common.Address{}, errors.New("invalid public key") |
|
|
|
return common.Address{}, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var addr common.Address |
|
|
|
var addr common.Address |
|
|
@ -110,34 +109,34 @@ func (tx *Transaction) To() *common.Address { |
|
|
|
return tx.Recipient |
|
|
|
return tx.Recipient |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (tx *Transaction) Curve() (v byte, r []byte, s []byte) { |
|
|
|
func (tx *Transaction) GetSignatureValues() (v byte, r []byte, s []byte) { |
|
|
|
v = byte(tx.V) |
|
|
|
v = byte(tx.V) |
|
|
|
r = common.LeftPadBytes(tx.R.Bytes(), 32) |
|
|
|
r = common.LeftPadBytes(tx.R.Bytes(), 32) |
|
|
|
s = common.LeftPadBytes(tx.S.Bytes(), 32) |
|
|
|
s = common.LeftPadBytes(tx.S.Bytes(), 32) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (tx *Transaction) Signature(key []byte) []byte { |
|
|
|
func (tx *Transaction) PublicKey() ([]byte, error) { |
|
|
|
hash := tx.Hash() |
|
|
|
if !crypto.ValidateSignatureValues(tx.V, tx.R, tx.S) { |
|
|
|
sig, _ := secp256k1.Sign(hash[:], key) |
|
|
|
return nil, errors.New("invalid v, r, s values") |
|
|
|
return sig |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (tx *Transaction) PublicKey() []byte { |
|
|
|
|
|
|
|
hash := tx.Hash() |
|
|
|
hash := tx.Hash() |
|
|
|
v, r, s := tx.Curve() |
|
|
|
v, r, s := tx.GetSignatureValues() |
|
|
|
sig := append(r, s...) |
|
|
|
sig := append(r, s...) |
|
|
|
sig = append(sig, v-27) |
|
|
|
sig = append(sig, v-27) |
|
|
|
|
|
|
|
|
|
|
|
//pubkey := crypto.Ecrecover(append(hash[:], sig...))
|
|
|
|
|
|
|
|
//pubkey, _ := secp256k1.RecoverPubkey(hash[:], sig)
|
|
|
|
|
|
|
|
p, err := crypto.SigToPub(hash[:], sig) |
|
|
|
p, err := crypto.SigToPub(hash[:], sig) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
glog.V(logger.Error).Infof("Could not get pubkey from signature: ", err) |
|
|
|
glog.V(logger.Error).Infof("Could not get pubkey from signature: ", err) |
|
|
|
return nil |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pubkey := crypto.FromECDSAPub(p) |
|
|
|
pubkey := crypto.FromECDSAPub(p) |
|
|
|
return pubkey |
|
|
|
if len(pubkey) == 0 || pubkey[0] != 4 { |
|
|
|
|
|
|
|
return nil, errors.New("invalid public key") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pubkey, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (tx *Transaction) SetSignatureValues(sig []byte) error { |
|
|
|
func (tx *Transaction) SetSignatureValues(sig []byte) error { |
|
|
|