{"record":{"id":"92e819afee857b11","repo":"grafana/k6","slug":"coordinate-y-is-required","errorCode":null,"errorMessage":"coordinate Y is required","messagePattern":"coordinate Y is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/jwk.go","lineNumber":142,"sourceCode":"\t// Private scalar\n\tD string `json:\"d\"`\n}\n\nfunc (jwk *ecJWK) validate() error {\n\tif jwk.Kty != JWKECKeyType {\n\t\treturn fmt.Errorf(\"invalid key type: %s\", jwk.Kty)\n\t}\n\n\tif jwk.Crv == \"\" {\n\t\treturn errors.New(\"curve is required\")\n\t}\n\n\tif jwk.X == \"\" {\n\t\treturn errors.New(\"coordinate X is required\")\n\t}\n\n\tif jwk.Y == \"\" {\n\t\treturn errors.New(\"coordinate Y is required\")\n\t}\n\n\treturn nil\n}\n\n// encodeCurveBigInt encodes the private scalar D of an ECDSA key with padding.\nfunc encodeCurveBigInt(data *big.Int, curveBits int) string {\n\t// Determine the expected byte length for the curve\n\tbyteLength := curveBits / 8\n\t// Add one more byte if the bits are not a multiple of 8\n\tif curveBits%8 != 0 {\n\t\tbyteLength++\n\t}\n\n\tdBytes := data.Bytes()\n\tdPadded := padLeft(dBytes, byteLength) // Pad if necessary\n\n\treturn base64URLEncode(dPadded)","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/webcrypto/jwk.go#L124-L160","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst jwk = { kty: 'EC', crv: 'P-256', x: 'SVqB...', d: 'Psv...' }; // missing y\nconst key = await crypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign']);\n\n// after\nconst jwk = { kty: 'EC', crv: 'P-256', x: 'SVqB...', y: 'NjC7...', d: 'Psv...' };\nconst key = await crypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign']);","handlingStrategy":"validation","validationCode":"function assertEcJwkComplete(jwk) {\n  const missing = ['kty', 'crv', 'x', 'y'].filter((f) => !jwk || typeof jwk[f] !== 'string' || jwk[f] === '');\n  if (missing.length > 0) {\n    throw new Error(`EC JWK is missing required field(s): ${missing.join(', ')}`);\n  }\n}\n\nassertEcJwkComplete(jwk);\nawait crypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: jwk.crv }, true, ['sign']);","typeGuard":"function isCompleteEcJwk(v) {\n  return !!v && v.kty === 'EC'\n    && typeof v.crv === 'string' && v.crv !== ''\n    && typeof v.x === 'string' && v.x !== ''\n    && typeof v.y === 'string' && v.y !== '';\n}","tryCatchPattern":"try {\n  const key = await crypto.subtle.importKey('jwk', jwk, alg, true, usages);\n} catch (err) {\n  if (/coordinate Y is required/.test(String(err))) {\n    throw new Error(`JWK missing y coordinate — regenerate it with exportKey('jwk'): ${JSON.stringify(jwk)}`);\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["webcrypto","jwk","ecdsa","ecdh","importkey","key-validation"],"backgroundTag":"jwk-validation-failed","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}