{"record":{"id":"486d1188b4acd711","repo":"grafana/k6","slug":"unsupported-algorithm-alg","errorCode":null,"errorMessage":"unsupported algorithm {alg}","messagePattern":"unsupported algorithm (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/elliptic_curve.go","lineNumber":486,"sourceCode":"\tif alg == ECDH {\n\t\tk, ok := handle.(*ecdh.PublicKey)\n\t\tif !ok {\n\t\t\treturn nil, NewError(OperationError, \"key data isn't a valid elliptic curve public key\")\n\t\t}\n\n\t\treturn k.Bytes(), nil\n\t}\n\n\tif alg == ECDSA {\n\t\tk, ok := handle.(*ecdsa.PublicKey)\n\t\tif !ok {\n\t\t\treturn nil, NewError(OperationError, \"key data isn't a valid elliptic curve public key\")\n\t\t}\n\n\t\treturn elliptic.Marshal(k.Curve, k.X, k.Y), nil //nolint:staticcheck // we need to use the Marshal function\n\t}\n\n\treturn nil, errors.New(\"unsupported algorithm \" + alg)\n}\n\n// ECDHKeyDeriveParams represents the object that should be passed as the algorithm parameter\n// into `SubtleCrypto.DeriveBits` or `SubtleCrypto.DeriveKey` when generating any elliptic-curve-based\n// key: that is, when the algorithm is identified as ECDH.\ntype ECDHKeyDeriveParams struct {\n\tAlgorithm\n\tPublic *CryptoKey\n}\n\nvar _ BitsDeriver = &ECDHKeyDeriveParams{}\n\nfunc newECDHKeyDeriveParams(rt *sobek.Runtime, normalized Algorithm, params sobek.Value) (*ECDHKeyDeriveParams, error) {\n\tvar publicKey *CryptoKey\n\n\tpcValue, err := traverseObject(rt, params, \"public\")\n\tif err != nil {\n\t\treturn nil, NewError(TypeError, \"algorithm does not contain a public key\")","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/webcrypto/elliptic_curve.go#L468-L504","documentation":"extractPublicKeyBytes (internal/js/modules/k6/webcrypto/elliptic_curve.go:467) serializes an elliptic-curve public key to raw bytes and handles exactly two algorithm names: ECDH (via ecdh.PublicKey.Bytes()) and ECDSA (via elliptic.Marshal). Any other algorithm name on an EC key when exporting in raw format returns \"unsupported algorithm <alg>\". It is called from exportECKey (elliptic_curve.go:432) during crypto.subtle.exportKey('raw', key).","triggerScenarios":"`crypto.subtle.exportKey('raw', ecKey)` where the key's algorithm normalized name is neither 'ECDH' nor 'ECDSA' — in practice only reachable with non-standard algorithm names on a key that still carries an EcKeyAlgorithm, since k6's normalization otherwise routes keys correctly.","commonSituations":"Rare/defensive: custom forks adding new EC algorithms, corrupted internal key state, or bugs in algorithm normalization. Stock k6 generates EC keys only as ECDH or ECDSA, so users essentially do not hit this.","solutions":["Verify the key was generated/imported with name 'ECDH' or 'ECDSA' and re-import it if unsure","Reproduce with a fresh generateKey/importKey call to rule out state corruption","If it persists on stock k6, report it at https://github.com/grafana/k6/issues with the script"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const name = key.algorithm.name;\nif (name !== 'ECDH' && name !== 'ECDSA') {\n  throw new Error(`cannot raw-export an EC key with algorithm ${name}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  raw = await crypto.subtle.exportKey('raw', key);\n} catch (e) {\n  if (String(e.message).includes('unsupported algorithm')) throw new Error(`key algorithm ${key.algorithm?.name} cannot be raw-exported as an EC key`);\n  throw e;\n}","preventionTips":["Only raw-export keys you generated/imported as ECDH or ECDSA in the same script run","Re-import keys from a canonical source instead of passing them through opaque layers","File a k6 issue if this fires on stock builds — it indicates internal state corruption"],"tags":["webcrypto","elliptic-curve","export","internal"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}