grafana/k6 · error
not implemented
Error message
not implemented
What it means
SubtleCrypto.wrapKey is declared but not implemented in k6's webcrypto module — the method body is a stub that always throws errors.New('not implemented') (internal/js/modules/k6/webcrypto/subtle_crypto.go:1044). Every call fails regardless of arguments; unlike most webcrypto errors it is not wrapped in a WebCrypto error type.
Solutions
- Replace wrapKey with exportKey + encrypt: const raw = await crypto.subtle.exportKey('raw', key); const wrapped = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, wrappingKey, raw)
- Track the grafana/xk6-webcrypto repository for a wrapKey implementation and upgrade k6 when it lands
- If AES-KW output must interoperate with another system, perform that wrapping outside the k6 script for now, since k6 does not expose AES-KW through this path
Example fix
// before
const wrapped = await crypto.subtle.wrapKey('raw', aesKey, wrappingKey, 'AES-KW');
// after (export + encrypt fallback)
const raw = await crypto.subtle.exportKey('raw', aesKey);
const iv = crypto.getRandomValues(new Uint8Array(12));
const wrapped = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, wrappingKey, raw); Defensive patterns
Strategy: fallback
Try / catch
async function wrapKeyCompat(format, key, wrappingKey, wrapAlgorithm) {
try {
return await crypto.subtle.wrapKey(format, key, wrappingKey, wrapAlgorithm);
} catch (err) {
if (String(err.message) !== 'not implemented') throw err;
// k6 has no wrapKey: export then encrypt
const raw = await crypto.subtle.exportKey(format, key);
return crypto.subtle.encrypt(wrapAlgorithm, wrappingKey, raw);
}
} Prevention
- Assume wrapKey is absent in k6 and write the exportKey+encrypt pattern up front
- Feature-check by try/catch on the first call, not by typeof — the stub exists as a function
- Keep wrapping algorithms AES-GCM/AES-CBC so the encrypt fallback matches what k6 supports
When it happens
Trigger: Any call to crypto.subtle.wrapKey(format, key, wrappingKey, wrapAlgorithm), e.g. wrapping an AES-GCM key with AES-KW as in browser code. The throw happens synchronously in the method, before argument processing.
Common situations: Porting browser or Node.js scripts that use AES-KW key wrapping; assuming k6's webcrypto covers the full SubtleCrypto surface; integration code that stores wrapped keys server-side.
Related errors
- coordinate Y is required
- data must be an ArrayBuffer, TypedArray, or DataView
- exponent (e) is required
- k6/experimental/webcrypto has been graduated and it's now…
- key derivation not implemented for algorithm
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/6d3b59fcf574c39b.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/subtle_crypto.go:1044
// The `key` parameter is the key to export, as a CryptoKey object.
// The `wrappingKey` parameter is the key to use to encrypt the exported key. The key **must** have
// the `wrapKey` usage flag set.
// The `wrapAlgorithm` parameter identifies the algorithm to use to encrypt the exported key, and should be one of:
// - an `SubtleCrypto.RSAOaepParams` object
// - an `SubtleCrypto.AesCtrParams` object
// - an `SubtleCrypto.AesCbcParams` object
// - an `SubtleCrypto.AesGcmParams` object
// - for the AES-KW algorithm, pass the string "AES-KW", or an object of the form `{ name: "AES-KW" }`
//
//nolint:revive // remove the nolint directive when the method is implemented
func (sc *SubtleCrypto) WrapKey(
format KeyFormat,
key sobek.Value,
wrappingKey sobek.Value,
wrapAlgorithm sobek.Value,
) (*sobek.Promise, error) {
// TODO: implementation
return nil, errors.New("not implemented")
}
// UnwrapKey "unwraps" a key.
//
// This means that it takes as its input a key that has been exported and then
// encrypted (also called "wrapped"). It decrypts the key and then imports it, returning
// a `CryptoKey` object that can be used in the Web Crypto API.
//
// As with `SubtleCrypto.ImportKey`, you specify the key's import format and other attributes
// of the key to import details such as whether it is extractable, and which operations it can be used for.
//
// But because `SubtleCrypto.UnwrapKey` also decrypts the key to be imported, you also need to pass
// in the key that must be used to decrypt it. This is sometimes called the "unwrapping key".
//
// The inverse of `SubtleCrypto.UnwrapKey` is `SubtleCrypto.WrapKey`: while `SubtleCrypto.UnwrapKey` is composed
// of decrypt + import, `Subtle.WrapKey` is composed of encrypt + export.
//
// It returns a Promise that fulfills with the unwrapped key as a CryptoKey object.View on GitHub (pinned to 01ffac6f24)