{"record":{"id":"5cd6abffe6010966","repo":"grafana/k6","slug":"failed-to-decode-d-w","errorCode":null,"errorMessage":"failed to decode D: %w","messagePattern":"failed to decode D: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/jwk.go","lineNumber":260,"sourceCode":"\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\n\t// if the key is a public key, return it\n\tif jwkKey.D == \"\" {\n\t\treturn pk, PublicCryptoKeyType, nil\n\t}\n\n\td, err := base64URLDecode(jwkKey.D)\n\tif err != nil {\n\t\treturn nil, UnknownCryptoKeyType, fmt.Errorf(\"failed to decode D: %w\", err)\n\t}\n\n\treturn &ecdsa.PrivateKey{\n\t\tPublicKey: *pk,\n\t\tD:         new(big.Int).SetBytes(d),\n\t}, PrivateCryptoKeyType, nil\n}\n\nfunc importECDHJWK(_ EllipticCurveKind, jsonKeyData []byte) (any, CryptoKeyType, error) {\n\t// first we do try to parse the key as ECDSA key\n\tkey, _, err := importECDSAJWK(EllipticCurveKindP256, jsonKeyData)\n\tif err != nil {\n\t\treturn nil, UnknownCryptoKeyType, fmt.Errorf(\"failed to parse input as ECDH key: %w\", err)\n\t}\n\n\tswitch key := key.(type) {\n\tcase *ecdsa.PrivateKey:\n\t\tecdhKey, err := key.ECDH()","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/webcrypto/jwk.go#L242-L278","documentation":"Returned by importECDSAJWK when the JWK contains a non-empty `d` field (marking it as a private key) whose base64url decoding fails. The public part (x, y) decoded fine, but the private scalar cannot be recovered, so the private ECDSA key cannot be assembled.","triggerScenarios":"Thrown at internal/js/modules/k6/webcrypto/jwk.go:259 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Encode d as unpadded base64url of the curve-sized big-endian private scalar","Strip the d field entirely when importing a public-only key"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}