github.com/Finschia/finschia-sdk@v0.48.1/crypto/keys/secp256k1/secp256k1_cgo.go (about)

     1  //go:build libsecp256k1_sdk
     2  // +build libsecp256k1_sdk
     3  
     4  package secp256k1
     5  
     6  import (
     7  	"github.com/Finschia/ostracon/crypto"
     8  
     9  	"github.com/Finschia/finschia-sdk/crypto/keys/secp256k1/internal/secp256k1"
    10  )
    11  
    12  // Sign creates an ECDSA signature on curve Secp256k1, using SHA256 on the msg.
    13  func (privKey *PrivKey) Sign(msg []byte) ([]byte, error) {
    14  	rsv, err := secp256k1.Sign(crypto.Sha256(msg), privKey.Key)
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  	// we do not need v  in r||s||v:
    19  	rs := rsv[:len(rsv)-1]
    20  	return rs, nil
    21  }
    22  
    23  // VerifySignature validates the signature.
    24  // The msg will be hashed prior to signature verification.
    25  func (pubKey *PubKey) VerifySignature(msg []byte, sigStr []byte) bool {
    26  	return secp256k1.VerifySignature(pubKey.Bytes(), crypto.Sha256(msg), sigStr)
    27  }