{"record":{"id":"8812f040fc75ef74","repo":"grafana/k6","slug":"unsupported-algorithm-v","errorCode":null,"errorMessage":"unsupported algorithm: %v","messagePattern":"unsupported algorithm: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/jwk.go","lineNumber":108,"sourceCode":"}\n\nfunc extractAlg(inAlg any, keyLen int) (string, error) {\n\tswitch alg := inAlg.(type) {\n\tcase hasHash:\n\t\tv := alg.hash()\n\t\tif len(v) < 4 {\n\t\t\treturn \"\", errors.New(\"length of hash algorithm is less than 4: \" + v)\n\t\t}\n\t\treturn \"HS\" + v[4:], nil\n\tcase hasAlg:\n\t\tv := alg.alg()\n\t\tif len(v) < 4 {\n\t\t\treturn \"\", errors.New(\"length of named algorithm is less than 4: \" + v)\n\t\t}\n\n\t\treturn fmt.Sprintf(\"A%d%s\", (8 * keyLen), v[4:]), nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"unsupported algorithm: %v\", inAlg)\n\t}\n}\n\n// ecJWK represents an EC JWK key.\n// It is used to unmarshal ECDSA and ECDH keys to and from JWK format.\ntype ecJWK struct {\n\t// Key type\n\tKty string `json:\"kty\"`\n\t// Canonical Curve\n\tCrv string `json:\"crv\"`\n\t// X coordinate\n\tX string `json:\"x\"`\n\t// Y coordinate\n\tY string `json:\"y\"`\n\t// Private scalar\n\tD string `json:\"d\"`\n}\n","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/webcrypto/jwk.go#L90-L126","documentation":"Thrown inside k6 WebCrypto's JWK export path when a key's algorithm object implements neither the hasHash interface (HMAC-style, providing a hash name) nor hasAlg (AES-style, providing the algorithm name). extractAlg (internal/js/modules/k6/webcrypto/jwk.go:92-109) type-switches on inAlg and its default branch returns this error, printing the offending value with %v. Like 1117 it surfaces to scripts as 'failed to extract algorithm: unsupported algorithm: ...' from exportKey('jwk', ...).","triggerScenarios":"exportSymmetricJWK invoked with a key whose handle is a []byte but whose Algorithm is an unexpected Go type (e.g. an EC or RSA algorithm struct attached to a byte-slice handle) — a state normal API flows cannot produce; it indicates a mismatched/corrupted CryptoKey rather than a user-input error.","commonSituations":"Practically unseen in stock k6; would appear in forks/extensions that construct CryptoKey values manually or reuse the webcrypto package's internals with nonstandard algorithm types.","solutions":["Export the key as 'raw' instead of 'jwk' — the raw path does not consult extractAlg.","Recreate the key via generateKey/importKey so its algorithm object is one of the standard types.","If maintaining a k6 extension, ensure symmetric CryptoKeys get KeyAlgorithm values that implement hasAlg (AES) or hasHash (HMAC)."],"exampleFix":"// before\nconst jwk = await crypto.subtle.exportKey('jwk', key); // unsupported algorithm: ...\n\n// after\nconst raw = await crypto.subtle.exportKey('raw', key);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await crypto.subtle.exportKey('jwk', key);\n} catch (e) {\n  if (/unsupported algorithm/.test(e.message)) { await crypto.subtle.exportKey('raw', key); /* proceed with raw bytes */ } else throw e;\n}","preventionTips":["Treat this error as an internal invariant break — capture the key's algorithm and report it rather than patching around it blindly.","In extensions, always attach hasAlg/hasHash-compatible algorithm types to symmetric CryptoKeys."],"tags":["webcrypto","jwk","export-key","algorithm","internal"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}