grafana/k6 · error
coordinate Y is required
Error message
coordinate Y is required
What it means
Thrown when crypto.subtle.importKey receives a JWK with kty 'EC' that is missing the base64url-encoded 'y' coordinate of the public key point. RFC 7518 requires EC keys to carry 'crv', 'x', and 'y' (plus 'd' for private keys), and k6's ecJWK.validate() enforces each field in order before parsing (internal/js/modules/k6/webcrypto/jwk.go:140). The error rejects the promise returned by importKey.
Solutions
- Add the missing 'y' member as an unpadded base64url string sized for the curve (32 bytes for P-256, 48 for P-384, 66 for P-521)
- Regenerate the key pair and export the full JWK with crypto.subtle.exportKey('jwk', keyPair.publicKey) instead of hand-writing it
- Before calling importKey, check the parsed JWK contains kty, crv, x, y (and d for private keys) so the failure is caught with a clearer message
Example fix
// before
const jwk = { kty: 'EC', crv: 'P-256', x: 'SVqB...', d: 'Psv...' }; // missing y
const key = await crypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign']);
// after
const jwk = { kty: 'EC', crv: 'P-256', x: 'SVqB...', y: 'NjC7...', d: 'Psv...' };
const key = await crypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign']); Defensive patterns
Strategy: validation
Validate before calling
function assertEcJwkComplete(jwk) {
const missing = ['kty', 'crv', 'x', 'y'].filter((f) => !jwk || typeof jwk[f] !== 'string' || jwk[f] === '');
if (missing.length > 0) {
throw new Error(`EC JWK is missing required field(s): ${missing.join(', ')}`);
}
}
assertEcJwkComplete(jwk);
await crypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: jwk.crv }, true, ['sign']); Type guard
function isCompleteEcJwk(v) {
return !!v && v.kty === 'EC'
&& typeof v.crv === 'string' && v.crv !== ''
&& typeof v.x === 'string' && v.x !== ''
&& typeof v.y === 'string' && v.y !== '';
} Try / catch
try {
const key = await crypto.subtle.importKey('jwk', jwk, alg, true, usages);
} catch (err) {
if (/coordinate Y is required/.test(String(err))) {
throw new Error(`JWK missing y coordinate — regenerate it with exportKey('jwk'): ${JSON.stringify(jwk)}`);
}
throw err;
} Prevention
- Generate JWKs inside the script with crypto.subtle.exportKey rather than hand-writing them
- Validate kty/crv/x/y (and d for private keys) before importKey
- Remember JWK member names are lowercase and case-sensitive
When it happens
Trigger: Calling crypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-256' }, true, ['verify']) with a JWK that has kty: 'EC' and valid crv/x but no 'y' member (or y: ''). Only JWKs that already passed the kty, crv, and x checks reach this error.
Common situations: JWKs produced by another tool that omit public coordinates; a truncated JWK pasted into the script; a typo like uppercase 'Y' (JSON member names are lowercase and case-sensitive); building the JWK from raw hex coordinates without unpadded base64url-encoding them.
Related errors
- exponent (e) is required
- modulus (n) is required
- key derivation not implemented for algorithm
- data must be an ArrayBuffer, TypedArray, or DataView
- k6/experimental/webcrypto has been graduated and it's now…
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/92e819afee857b11.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:142
// Private scalar
D string `json:"d"`
}
func (jwk *ecJWK) validate() error {
if jwk.Kty != JWKECKeyType {
return fmt.Errorf("invalid key type: %s", jwk.Kty)
}
if jwk.Crv == "" {
return errors.New("curve is required")
}
if jwk.X == "" {
return errors.New("coordinate X is required")
}
if jwk.Y == "" {
return errors.New("coordinate Y is required")
}
return nil
}
// encodeCurveBigInt encodes the private scalar D of an ECDSA key with padding.
func encodeCurveBigInt(data *big.Int, curveBits int) string {
// Determine the expected byte length for the curve
byteLength := curveBits / 8
// Add one more byte if the bits are not a multiple of 8
if curveBits%8 != 0 {
byteLength++
}
dBytes := data.Bytes()
dPadded := padLeft(dBytes, byteLength) // Pad if necessary
return base64URLEncode(dPadded)View on GitHub (pinned to 8d06114777)