{"record":{"id":"ef3c844da4ab4468","repo":"grafana/k6","slug":"failed-to-parse-elliptic-curve-w","errorCode":null,"errorMessage":"failed to parse elliptic curve: %w","messagePattern":"failed to parse elliptic curve: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/jwk.go","lineNumber":233,"sourceCode":"\t\texported.Set(\"d\", encodeCurveBigInt(d, curveBits))\n\t}\n\n\treturn exported, nil\n}\n\nfunc importECDSAJWK(_ EllipticCurveKind, jsonKeyData []byte) (any, CryptoKeyType, error) {\n\tvar jwkKey ecJWK\n\tif err := json.Unmarshal(jsonKeyData, &jwkKey); err != nil {\n\t\treturn nil, UnknownCryptoKeyType, fmt.Errorf(\"failed to parse input as EC JWK key: %w\", err)\n\t}\n\n\tif err := jwkKey.validate(); err != nil {\n\t\treturn nil, UnknownCryptoKeyType, fmt.Errorf(\"invalid EC JWK key: %w\", err)\n\t}\n\n\tcrv, err := pickEllipticCurve(jwkKey.Crv)\n\tif err != nil {\n\t\treturn nil, UnknownCryptoKeyType, fmt.Errorf(\"failed to parse elliptic curve: %w\", err)\n\t}\n\n\tx, err := base64URLDecode(jwkKey.X)\n\tif err != nil {\n\t\treturn nil, UnknownCryptoKeyType, fmt.Errorf(\"failed to decode X coordinate: %w\", err)\n\t}\n\n\ty, err := base64URLDecode(jwkKey.Y)\n\tif err != nil {\n\t\treturn nil, UnknownCryptoKeyType, fmt.Errorf(\"failed to decode Y coordinate: %w\", err)\n\t}\n\n\tpk := &ecdsa.PublicKey{\n\t\tCurve: crv,\n\t\tX:     new(big.Int).SetBytes(x),\n\t\tY:     new(big.Int).SetBytes(y),\n\t}\n","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/webcrypto/jwk.go#L215-L251","documentation":"importECDSAJWK maps the JWK's crv field to a Go elliptic.Curve via pickEllipticCurve, which accepts only the canonical names 'P-256', 'P-384' and 'P-521' (case-sensitive). This error means the crv string did not match any of them; the wrapped message includes the offending value ('invalid elliptic curve <crv>'). It surfaces from crypto.subtle.importKey('jwk', ...) for ECDSA.","triggerScenarios":"A crv of 'p-256' (lowercase), 'P256', 'prime256v1', 'secp256r1', 'P-224', 'Ed25519', or any non-canonical spelling; also a crv copied from a different curve family.","commonSituations":"JWKs converted from OpenSSL/JOSE libraries that emit SEC or ASN.1 curve names; hand-built JWKs; casing drift between systems; attempts to import curves k6 does not support (P-224, secp256k1, Ed25519).","solutions":["Use exactly 'P-256', 'P-384' or 'P-521' in the crv field","Map alternate names before import: secp256r1/prime256v1 -> P-256, secp384r1 -> P-384, secp521r1 -> P-521","For unsupported curves (P-224, secp256k1), switch to a supported curve or export/recreate the key","Keep namedCurve in the algorithm object consistent with the JWK's crv"],"exampleFix":"// before\nconst jwk = { kty: 'EC', crv: 'secp256r1', x, y };\n// after\nconst jwk = { kty: 'EC', crv: 'P-256', x, y };","handlingStrategy":"validation","validationCode":"const CANON = { 'P-256':1, 'P-384':1, 'P-521':1 };\nconst ALIAS = { secp256r1:'P-256', prime256v1:'P-256', secp384r1:'P-384', secp521r1:'P-521' };\nfunction normalizeCrv(crv) { return CANON[crv] ? crv : ALIAS[crv]; }\nconst crv = normalizeCrv(jwk.crv);\nif (!crv) throw new Error('unsupported crv: ' + jwk.crv);","typeGuard":"function isSupportedCrv(crv) {\n  return crv === 'P-256' || crv === 'P-384' || crv === 'P-521';\n}","tryCatchPattern":"try {\n  key = await crypto.subtle.importKey('jwk', jwk, alg, true, usages);\n} catch (e) {\n  if (e.message.includes('failed to parse elliptic curve')) {\n    throw new Error(`crv \"${jwk.crv}\" unsupported; use P-256/P-384/P-521`);\n  }\n  throw e;\n}","preventionTips":["Canonicalize curve names at the boundary where keys enter your system","Keep algorithm namedCurve and JWK crv in sync","Remember P-224, secp256k1 and Ed25519 are not supported by this importer"],"tags":["webcrypto","jwk","import","ecdsa","elliptic-curve","k6"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}