MCPcopy Create free account
hub / github.com/tendermint/tendermint / PubKeyFromProto

Function PubKeyFromProto

crypto/encoding/codec.go:49–78  ·  view source on GitHub ↗

PubKeyFromProto takes a protobuf Pubkey and transforms it to a crypto.Pubkey

(k cryptoproto.PublicKey)

Source from the content-addressed store, hash-verified

47
48// PubKeyFromProto takes a protobuf Pubkey and transforms it to a crypto.Pubkey
49func PubKeyFromProto(k cryptoproto.PublicKey) (crypto.PubKey, error) {
50 switch k := k.Sum.(type) {
51 case *cryptoproto.PublicKey_Ed25519:
52 if len(k.Ed25519) != ed25519.PubKeySize {
53 return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d",
54 len(k.Ed25519), ed25519.PubKeySize)
55 }
56 pk := make(ed25519.PubKey, ed25519.PubKeySize)
57 copy(pk, k.Ed25519)
58 return pk, nil
59 case *cryptoproto.PublicKey_Secp256K1:
60 if len(k.Secp256K1) != secp256k1.PubKeySize {
61 return nil, fmt.Errorf("invalid size for PubKeySecp256k1. Got %d, expected %d",
62 len(k.Secp256K1), secp256k1.PubKeySize)
63 }
64 pk := make(secp256k1.PubKey, secp256k1.PubKeySize)
65 copy(pk, k.Secp256K1)
66 return pk, nil
67 case *cryptoproto.PublicKey_Sr25519:
68 if len(k.Sr25519) != sr25519.PubKeySize {
69 return nil, fmt.Errorf("invalid size for PubKeySr25519. Got %d, expected %d",
70 len(k.Sr25519), sr25519.PubKeySize)
71 }
72 pk := make(sr25519.PubKey, sr25519.PubKeySize)
73 copy(pk, k.Sr25519)
74 return pk, nil
75 default:
76 return nil, fmt.Errorf("fromproto: key type %v is not supported", k)
77 }
78}

Callers 12

MakeValSetChangeTxFunction · 0.92
updateValidatorMethod · 0.92
MarshalJSONMethod · 0.92
ValidatorFromProtoFunction · 0.92
testABCIPubKeyFunction · 0.92
ValidatorUpdatesMethod · 0.92
GetPubKeyMethod · 0.92
shareAuthSignatureFunction · 0.92
GetPubKeyMethod · 0.92
validateValidatorUpdatesFunction · 0.92
shareAuthSignatureFunction · 0.92

Calls

no outgoing calls

Tested by 2

testABCIPubKeyFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…