1 package keyfunc 2 3 import ( 4 "crypto/ed25519" 5 "fmt" 6 ) 7 8 const ( 9 // ktyEC is the key type (kty) in the JWT header for EdDSA. 10 ktyOKP = "OKP" 11 ) 12 13 // EdDSA parses a jsonWebKey and turns it into a EdDSA public key. 14 func (j *jsonWebKey) EdDSA() (publicKey ed25519.PublicKey, err error) { 15 if j.X == "" { 16 return nil, fmt.Errorf("%w: %s", ErrMissingAssets, ktyOKP) 17 } 18 19 // Decode the public key from Base64. 20 // 21 // According to RFC 8037, this is from Base64 URL bytes. 22 // https://datatracker.ietf.org/doc/html/rfc8037#appendix-A.2 23 publicBytes, err := base64urlTrailingPadding(j.X) 24 if err != nil { 25 return nil, err 26 } 27 28 return publicBytes, nil 29 } 30