PubKeyFromProto takes a protobuf Pubkey and transforms it to a crypto.Pubkey
(k cryptoproto.PublicKey)
| 47 | |
| 48 | // PubKeyFromProto takes a protobuf Pubkey and transforms it to a crypto.Pubkey |
| 49 | func 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 | } |
no outgoing calls
searching dependent graphs…