github.com/datachainlab/burrow@v0.25.0/crypto/signature.go (about)

     1  package crypto
     2  
     3  import (
     4  	"fmt"
     5  
     6  	hex "github.com/tmthrgd/go-hex"
     7  	"golang.org/x/crypto/ed25519"
     8  )
     9  
    10  func SignatureFromBytes(bs []byte, curveType CurveType) (*Signature, error) {
    11  	switch curveType {
    12  	case CurveTypeEd25519:
    13  		if len(bs) != ed25519.SignatureSize {
    14  			return nil, fmt.Errorf("bytes passed have length %v by ed25519 signatures have %v bytes",
    15  				len(bs), ed25519.SignatureSize)
    16  		}
    17  	case CurveTypeSecp256k1:
    18  		// TODO: validate?
    19  	}
    20  
    21  	return &Signature{CurveType: curveType, Signature: bs}, nil
    22  }
    23  
    24  func (sig *Signature) RawBytes() []byte {
    25  	return sig.Signature
    26  }
    27  
    28  func (sig *Signature) String() string {
    29  	return hex.EncodeUpperToString(sig.Signature)
    30  }