{"record":{"id":"6d3b59fcf574c39b","repo":"grafana/k6","slug":"not-implemented","errorCode":null,"errorMessage":"not implemented","messagePattern":"not implemented","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/subtle_crypto.go","lineNumber":1044,"sourceCode":"// The `key` parameter is the key to export, as a CryptoKey object.\n// The `wrappingKey` parameter is the key to use to encrypt the exported key. The key **must** have\n// the `wrapKey` usage flag set.\n// The `wrapAlgorithm` parameter identifies the algorithm to use to encrypt the exported key, and should be one of:\n//   - an `SubtleCrypto.RSAOaepParams` object\n//   - an `SubtleCrypto.AesCtrParams` object\n//   - an `SubtleCrypto.AesCbcParams` object\n//   - an `SubtleCrypto.AesGcmParams` object\n//   - for the AES-KW algorithm, pass the string \"AES-KW\", or an object of the form `{ name: \"AES-KW\" }`\n//\n//nolint:revive // remove the nolint directive when the method is implemented\nfunc (sc *SubtleCrypto) WrapKey(\n\tformat KeyFormat,\n\tkey sobek.Value,\n\twrappingKey sobek.Value,\n\twrapAlgorithm sobek.Value,\n) (*sobek.Promise, error) {\n\t// TODO: implementation\n\treturn nil, errors.New(\"not implemented\")\n}\n\n// UnwrapKey \"unwraps\" a key.\n//\n// This means that it takes as its input a key that has been exported and then\n// encrypted (also called \"wrapped\"). It decrypts the key and then imports it, returning\n// a `CryptoKey` object that can be used in the Web Crypto API.\n//\n// As with `SubtleCrypto.ImportKey`, you specify the key's import format and other attributes\n// of the key to import details such as whether it is extractable, and which operations it can be used for.\n//\n// But because `SubtleCrypto.UnwrapKey` also decrypts the key to be imported, you also need to pass\n// in the key that must be used to decrypt it. This is sometimes called the \"unwrapping key\".\n//\n// The inverse of `SubtleCrypto.UnwrapKey` is `SubtleCrypto.WrapKey`: while `SubtleCrypto.UnwrapKey` is composed\n// of decrypt + import, `Subtle.WrapKey` is composed of encrypt + export.\n//\n// It returns a Promise that fulfills with the unwrapped key as a CryptoKey object.","sourceCodeStart":1026,"sourceCodeEnd":1062,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/webcrypto/subtle_crypto.go#L1026-L1062","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst wrapped = await crypto.subtle.wrapKey('raw', aesKey, wrappingKey, 'AES-KW');\n\n// after (export + encrypt fallback)\nconst raw = await crypto.subtle.exportKey('raw', aesKey);\nconst iv = crypto.getRandomValues(new Uint8Array(12));\nconst wrapped = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, wrappingKey, raw);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"async function wrapKeyCompat(format, key, wrappingKey, wrapAlgorithm) {\n  try {\n    return await crypto.subtle.wrapKey(format, key, wrappingKey, wrapAlgorithm);\n  } catch (err) {\n    if (String(err.message) !== 'not implemented') throw err;\n    // k6 has no wrapKey: export then encrypt\n    const raw = await crypto.subtle.exportKey(format, key);\n    return crypto.subtle.encrypt(wrapAlgorithm, wrappingKey, raw);\n  }\n}","preventionTips":["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"],"tags":["webcrypto","wrapkey","not-implemented","stub","api-coverage"],"backgroundTag":"unsupported-crypto-operation","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}