github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/abci/types/pubkey.go (about) 1 package types 2 3 import ( 4 fmt "fmt" 5 6 "github.com/badrootd/nibiru-cometbft/crypto/ed25519" 7 cryptoenc "github.com/badrootd/nibiru-cometbft/crypto/encoding" 8 "github.com/badrootd/nibiru-cometbft/crypto/secp256k1" 9 ) 10 11 func Ed25519ValidatorUpdate(pk []byte, power int64) ValidatorUpdate { 12 pke := ed25519.PubKey(pk) 13 14 pkp, err := cryptoenc.PubKeyToProto(pke) 15 if err != nil { 16 panic(err) 17 } 18 19 return ValidatorUpdate{ 20 // Address: 21 PubKey: pkp, 22 Power: power, 23 } 24 } 25 26 func UpdateValidator(pk []byte, power int64, keyType string) ValidatorUpdate { 27 switch keyType { 28 case "", ed25519.KeyType: 29 return Ed25519ValidatorUpdate(pk, power) 30 case secp256k1.KeyType: 31 pke := secp256k1.PubKey(pk) 32 pkp, err := cryptoenc.PubKeyToProto(pke) 33 if err != nil { 34 panic(err) 35 } 36 return ValidatorUpdate{ 37 // Address: 38 PubKey: pkp, 39 Power: power, 40 } 41 default: 42 panic(fmt.Sprintf("key type %s not supported", keyType)) 43 } 44 }