github.com/kisexp/xdchain@v0.0.0-20211206025815-490d6b732aa7/consensus/istanbul/common/utils.go (about)

     1  package istanbulcommon
     2  
     3  import (
     4  	"github.com/kisexp/xdchain/common"
     5  	"github.com/kisexp/xdchain/crypto"
     6  )
     7  
     8  // GetSignatureAddress gets the signer address from the signature
     9  func GetSignatureAddress(data []byte, sig []byte) (common.Address, error) {
    10  	// 1. Keccak data
    11  	hashData := crypto.Keccak256(data)
    12  	// 2. Recover public key
    13  	pubkey, err := crypto.SigToPub(hashData, sig)
    14  	if err != nil {
    15  		return common.Address{}, err
    16  	}
    17  	return crypto.PubkeyToAddress(*pubkey), nil
    18  }