grafana/k6 · error
unsupported algorithm: %v
Error message
unsupported algorithm: %v
What it means
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', ...).
Source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:108
}
func extractAlg(inAlg any, keyLen int) (string, error) {
switch alg := inAlg.(type) {
case hasHash:
v := alg.hash()
if len(v) < 4 {
return "", errors.New("length of hash algorithm is less than 4: " + v)
}
return "HS" + v[4:], nil
case hasAlg:
v := alg.alg()
if len(v) < 4 {
return "", errors.New("length of named algorithm is less than 4: " + v)
}
return fmt.Sprintf("A%d%s", (8 * keyLen), v[4:]), nil
default:
return "", fmt.Errorf("unsupported algorithm: %v", inAlg)
}
}
// ecJWK represents an EC JWK key.
// It is used to unmarshal ECDSA and ECDH keys to and from JWK format.
type ecJWK struct {
// Key type
Kty string `json:"kty"`
// Canonical Curve
Crv string `json:"crv"`
// X coordinate
X string `json:"x"`
// Y coordinate
Y string `json:"y"`
// Private scalar
D string `json:"d"`
}
View on GitHub (pinned to 93accf6570)
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).
Example fix
// before
const jwk = await crypto.subtle.exportKey('jwk', key); // unsupported algorithm: ...
// after
const raw = await crypto.subtle.exportKey('raw', key); Defensive patterns
Strategy: fallback
Try / catch
try {
await crypto.subtle.exportKey('jwk', key);
} catch (e) {
if (/unsupported algorithm/.test(e.message)) { await crypto.subtle.exportKey('raw', key); /* proceed with raw bytes */ } else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to extract algorithm: %w
- curve not supported for converting to ECDSA key
- invalid block size
- unsupported algorithm {alg}
- key (k) is required
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/8812f040fc75ef74.
Report an issue: GitHub.