grafana/k6 · error

invalid EC JWK key

Error message

invalid EC JWK key: %w

What it means

Returned by importECDSAJWK when the input parsed as JSON but failed the ecJWK semantic validation — e.g. `kty` is not "EC", or required coordinate fields (`x`, `y`) are missing/empty. The wrapped error identifies the first failed check. Distinct from a JSON syntax failure, which produces the 'failed to parse input' error instead.

Solutions

  1. Ensure the JWK has "kty":"EC" plus non-empty base64url-encoded "x" and "y" coordinates
  2. Include "d" only when importing a private key
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:228 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/0e0bf934ee8231ca. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/webcrypto/jwk.go:229

	exported.Set("x", base64URLEncode(x.Bytes()))
	exported.Set("y", base64URLEncode(y.Bytes()))

	if d != nil {
		exported.Set("d", encodeCurveBigInt(d, curveBits))
	}

	return exported, nil
}

func importECDSAJWK(_ EllipticCurveKind, jsonKeyData []byte) (any, CryptoKeyType, error) {
	var jwkKey ecJWK
	if err := json.Unmarshal(jsonKeyData, &jwkKey); err != nil {
		return nil, UnknownCryptoKeyType, fmt.Errorf("failed to parse input as EC JWK key: %w", err)
	}

	if err := jwkKey.validate(); err != nil {
		return nil, UnknownCryptoKeyType, fmt.Errorf("invalid EC JWK key: %w", err)
	}

	crv, err := pickEllipticCurve(jwkKey.Crv)
	if err != nil {
		return nil, UnknownCryptoKeyType, fmt.Errorf("failed to parse elliptic curve: %w", err)
	}

	x, err := base64URLDecode(jwkKey.X)
	if err != nil {
		return nil, UnknownCryptoKeyType, fmt.Errorf("failed to decode X coordinate: %w", err)
	}

	y, err := base64URLDecode(jwkKey.Y)
	if err != nil {
		return nil, UnknownCryptoKeyType, fmt.Errorf("failed to decode Y coordinate: %w", err)
	}

	pk := &ecdsa.PublicKey{

View on GitHub (pinned to 8d06114777)