grafana/k6 · error
invalid key type
Error message
invalid key type: %s
What it means
Returned by the symmetricJWK validator during JWK import (crypto.subtle.importKey with jwk format). The JSON parsed successfully but its `kty` (key type) field is anything other than "oct", which is the only key type accepted for symmetric (HMAC/AES) key import. The actual kty value is included in the message, revealing what kind of key was supplied instead.
Solutions
- Use a JWK with "kty": "oct" for symmetric key import
- For EC keys (kty EC) or RSA keys (kty RSA), pass the JWK to the appropriate algorithm import — k6 dispatches on the algorithm, so verify the algorithm name matches the key type
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:39 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/6dfc230d136afb44.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:40
// JsonWebKey represents a JSON Web Key (JsonWebKey) key.
type JsonWebKey map[string]any //nolint:revive // we name this type JsonWebKey to match the spec
// Set sets a key-value pair in the JWK.
func (jwk *JsonWebKey) Set(key string, value any) {
(*jwk)[key] = value
}
// symmetricJWK represents a symmetric JWK key.
// It is used to unmarshal symmetric keys from JWK format.
type symmetricJWK struct {
Kty string `json:"kty"`
K string `json:"k"`
}
func (jwk *symmetricJWK) validate() error {
if jwk.Kty != JWKOctKeyType {
return fmt.Errorf("invalid key type: %s", jwk.Kty)
}
if jwk.K == "" {
return errors.New("key (k) is required")
}
return nil
}
// extractSymmetricJWK extracts the symmetric key from a given JWK key (JSON data).
func extractSymmetricJWK(jsonKeyData []byte) ([]byte, error) {
sk := symmetricJWK{}
if err := json.Unmarshal(jsonKeyData, &sk); err != nil {
return nil, fmt.Errorf("failed to parse symmetric JWK: %w", err)
}
if err := sk.validate(); err != nil {
return nil, fmt.Errorf("invalid symmetric JWK: %w", err)View on GitHub (pinned to 8d06114777)