grafana/k6 · error
exponent (e) is required
Error message
exponent (e) is required
What it means
Thrown when crypto.subtle.importKey receives a JWK with kty 'RSA' that is missing the 'e' (public exponent) member. rsaJWK.validate() checks n first, then e (internal/js/modules/k6/webcrypto/jwk.go:317), so this error means the modulus was present but the exponent was not. The importKey promise rejects with this message.
Solutions
- Add the 'e' member as unpadded base64url — for the standard exponent 65537 that is 'AQAB'
- Re-export the JWK with crypto.subtle.exportKey('jwk', key) so no field is lost
- Validate that both n and e are present before importKey
Example fix
// before
const jwk = { kty: 'RSA', n: 'vHkg...' };
const key = await crypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['encrypt']);
// after
const jwk = { kty: 'RSA', n: 'vHkg...', e: 'AQAB' };
const key = await crypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['encrypt']); Defensive patterns
Strategy: validation
Validate before calling
if (!jwk || typeof jwk.e !== 'string' || jwk.e === '') {
throw new Error(`RSA JWK needs a public exponent (e), e.g. 'AQAB' for 65537`);
}
await crypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['encrypt']); Type guard
function hasRsaExponent(v) {
return !!v && v.kty === 'RSA' && typeof v.e === 'string' && v.e !== '';
} Try / catch
try {
const key = await crypto.subtle.importKey('jwk', jwk, alg, true, usages);
} catch (err) {
if (/exponent \(e\) is required/.test(String(err))) {
throw new Error(`RSA JWK missing exponent — for 65537 use e: 'AQAB'`);
}
throw err;
} Prevention
- Use 'AQAB' (65537) as the default exponent when constructing JWKs
- Beware near-miss field names: 'E', 'exp', 'exponent' are all wrong
- Round-trip keys through exportKey/importKey to prove the JWK is complete
When it happens
Trigger: Calling crypto.subtle.importKey('jwk', { kty: 'RSA', n: '...' }, { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, true, ['verify']) — the JWK has a modulus but no e member.
Common situations: Hand-editing a JWK and dropping the exponent; JSON with 'E' uppercase or 'exp' (a JWT-claims name) instead of 'e'; a JWK round-tripped through code that renamed or stripped short fields.
Related errors
- modulus (n) is required
- coordinate Y is required
- public exponent is even
- public exponent too large
- public exponent too small
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/46d37c8512658a70.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:318
D string `json:"d,omitempty"` // Private exponent
P string `json:"p,omitempty"` // First prime factor
Q string `json:"q,omitempty"` // Second prime factor
Dp string `json:"dp,omitempty"` // Exponent1
Dq string `json:"dq,omitempty"` // Exponent2
Qi string `json:"qi,omitempty"` // Coefficient
}
func (jwk *rsaJWK) validate() error {
if jwk.Kty != "RSA" {
return fmt.Errorf("invalid key type: %s", jwk.Kty)
}
if jwk.N == "" {
return errors.New("modulus (n) is required")
}
if jwk.E == "" {
return errors.New("exponent (e) is required")
}
// TODO: consider validating the other fields in future
return nil
}
func importRSAJWK(jsonKeyData []byte) (any, CryptoKeyType, int, error) {
var jwk rsaJWK
if err := json.Unmarshal(jsonKeyData, &jwk); err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("failed to parse input as RSA JWK key: %w", err)
}
if err := jwk.validate(); err != nil {
return nil, UnknownCryptoKeyType, 0, fmt.Errorf("invalid RSA JWK key: %w", err)
}
// decode the various key components
nBytes, err := base64URLDecode(jwk.N)View on GitHub (pinned to 8d06114777)