grafana/k6 · error
failed to convert ECDH key to ECDSA key
Error message
failed to convert ECDH key to ECDSA key: %w
What it means
Returned by exportECJWK when exporting a key whose handle holds an *ecdh.PrivateKey: before serializing to JWK the ECDH key must be converted to its ECDSA form, and that conversion (convertECDHtoECDSAKey) failed — commonly because the ECDH key uses an unsupported curve (only P-256/P-384/P-521 convert) or its bytes are invalid.
Solutions
- Use one of the NIST curves P-256, P-384 or P-521 for ECDH keys you intend to export
- If the curve is X25519, export via raw format instead of jwk
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:188 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/8df931a744473bab.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:189
exported.Set("kty", JWKECKeyType)
var x, y, d *big.Int
var curveParams *elliptic.CurveParams
switch k := key.handle.(type) {
case *ecdsa.PrivateKey:
x = k.X
y = k.Y
d = k.D
curveParams = k.Params()
case *ecdsa.PublicKey:
x = k.X
y = k.Y
curveParams = k.Params()
case *ecdh.PrivateKey:
ecdsaKey, err := convertECDHtoECDSAKey(k)
if err != nil {
return nil, fmt.Errorf("failed to convert ECDH key to ECDSA key: %w", err)
}
x = ecdsaKey.X
y = ecdsaKey.Y
d = ecdsaKey.D
curveParams = ecdsaKey.Params()
case *ecdh.PublicKey:
ecdsaKey, err := convertPublicECDHtoECDSA(k)
if err != nil {
return nil, fmt.Errorf("failed to convert ECDH key to ECDSA key: %w", err)
}
x = ecdsaKey.X
y = ecdsaKey.Y
curveParams = ecdsaKey.Params()
default:
return nil, errors.New("key's handle isn't an ECDSA/ECDH public/private key")
}View on GitHub (pinned to 8d06114777)