github.com/number571/tendermint@v0.34.11-gost/abci/types/pubkey.go (about)

     1  package types
     2  
     3  import (
     4  	fmt "fmt"
     5  
     6  	gkeys "github.com/number571/go-cryptopro/gost_r_34_10_2012"
     7  	cryptoenc "github.com/number571/tendermint/crypto/encoding"
     8  	"github.com/number571/tendermint/crypto/gost256"
     9  	"github.com/number571/tendermint/crypto/gost512"
    10  )
    11  
    12  func Gost512ValidatorUpdate(pk []byte, power int64) ValidatorUpdate {
    13  	pkx, err := gkeys.LoadPubKey(pk)
    14  	if err != nil {
    15  		return ValidatorUpdate{}
    16  	}
    17  	pke := gost512.PubKey(pkx.(gkeys.PubKey512))
    18  
    19  	pkp, err := cryptoenc.PubKeyToProto(pke)
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  
    24  	return ValidatorUpdate{
    25  		PubKey: pkp,
    26  		Power:  power,
    27  	}
    28  }
    29  
    30  func UpdateValidator(pk []byte, power int64, keyType string) ValidatorUpdate {
    31  	switch keyType {
    32  	case "", gost512.KeyType:
    33  		return Gost512ValidatorUpdate(pk, power)
    34  	case gost256.KeyType:
    35  		pke := gost256.PubKey(pk)
    36  		pkp, err := cryptoenc.PubKeyToProto(pke)
    37  		if err != nil {
    38  			panic(err)
    39  		}
    40  		return ValidatorUpdate{
    41  			PubKey: pkp,
    42  			Power:  power,
    43  		}
    44  	default:
    45  		panic(fmt.Sprintf("key type %s not supported", keyType))
    46  	}
    47  }