grafana/k6 · error

unable to convert ECDH public key to ECDSA public key, curve

Error message

unable to convert ECDH public key to ECDSA public key, curve: %s

What it means

Returned by convertPublicECDHtoECDSA when an ECDH public key on a known curve (P-256/P-384/P-521) cannot be unmarshalled into ECDSA point coordinates: elliptic.Unmarshal returns a nil x, meaning the key bytes do not encode a valid point on the stated curve. The curve name is included in the message. Encountered when exporting an ECDH key as JWK.

Solutions

  1. Regenerate or re-import the ECDH key — the raw public key bytes are likely corrupted or truncated
  2. Verify the key was generated on the curve claimed in its parameters
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/js/modules/k6/webcrypto/elliptic_curve.go:711 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/cfeaca086d7d0a3f. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/webcrypto/elliptic_curve.go:712

	}, nil
}

func convertPublicECDHtoECDSA(k *ecdh.PublicKey) (*ecdsa.PublicKey, error) {
	var crv elliptic.Curve
	switch k.Curve() {
	case ecdh.P256():
		crv = elliptic.P256()
	case ecdh.P384():
		crv = elliptic.P384()
	case ecdh.P521():
		crv = elliptic.P521()
	default:
		return nil, errors.New("curve not supported for converting to ECDSA key")
	}

	x, y := elliptic.Unmarshal(crv, k.Bytes()) //nolint:staticcheck // we need to use the Unmarshal function
	if x == nil {
		return nil, fmt.Errorf("unable to convert ECDH public key to ECDSA public key, curve: %s", crv.Params().Name)
	}

	return &ecdsa.PublicKey{
		Curve: crv,
		X:     x,
		Y:     y,
	}, nil
}

func ensureKeysUseSameCurve(k1, k2 CryptoKey) error {
	ecAlg1, ok1 := k1.Algorithm.(EcKeyAlgorithm)
	ecAlg2, ok2 := k2.Algorithm.(EcKeyAlgorithm)
	if !ok1 || !ok2 {
		return errors.New("keys are not valid elliptic curve keys")
	}

	if ecAlg1.NamedCurve != ecAlg2.NamedCurve {
		return errors.New("keys have different curves " + string(ecAlg1.NamedCurve) + " and " + string(ecAlg2.NamedCurve))

View on GitHub (pinned to 8d06114777)