grafana/k6 · error
failed to decode coefficient
Error message
failed to decode coefficient: %w
What it means
Returned by importRSAJWK when the private JWK's `qi` field (CRT coefficient, q^-1 mod p) fails base64url decoding. This is the last component decoded; all other fields were valid, but the coefficient string is not base64url so rsa.PrecomputedValues cannot be filled.
Solutions
- Encode qi as unpadded base64url, same byte length as p
- Export the JWK with a standard crypto library so qi matches the rest of the key
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:378 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/941cf24e1e28bee3.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:379
pBytes, err := base64URLDecode(jwk.P)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode first prime factor: %w", err)
}
qBytes, err := base64URLDecode(jwk.Q)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode second prime factor: %w", err)
}
dpBytes, err := base64URLDecode(jwk.Dp)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode first exponent: %w", err)
}
dqBytes, err := base64URLDecode(jwk.Dq)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode second exponent: %w", err)
}
qiBytes, err := base64URLDecode(jwk.Qi)
if err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to decode coefficient: %w", err)
}
privKey := &rsa.PrivateKey{
PublicKey: pubKey,
D: new(big.Int).SetBytes(dBytes),
Primes: []*big.Int{
new(big.Int).SetBytes(pBytes),
new(big.Int).SetBytes(qBytes),
},
Precomputed: rsa.PrecomputedValues{
Dp: new(big.Int).SetBytes(dpBytes),
Dq: new(big.Int).SetBytes(dqBytes),
Qinv: new(big.Int).SetBytes(qiBytes),
},
}
err = privKey.Validate()
if err != nil {View on GitHub (pinned to 8d06114777)