grafana/k6 · error

failed to parse input as EC JWK key

Error message

failed to parse input as EC JWK key: %w

What it means

Returned by importECDSAJWK when the data passed to crypto.subtle.importKey with format 'jwk' and an EC algorithm is not valid JSON — json.Unmarshal of the bytes into the ecJWK struct failed. This is a pure deserialization failure: the input never reaches field validation.

Solutions

  1. Pass serialized JWK JSON, e.g. JSON.stringify({kty:'EC', crv:'P-256', x:'...', y:'...'})
  2. Verify the key string is not truncated or double-encoded (e.g. base64 of JSON)
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:224 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/8839862c397f31e1. Report an issue: GitHub.

Appendix: source

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

	}

	exported.Set("crv", curveParams.Name)
	curveBits := curveParams.BitSize

	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 {

View on GitHub (pinned to 8d06114777)