How can npm modules be used inside K6 scripts

I need to use http-signature and jssha npm modules inside my K6 test script in order to sign the request as mentioned in the below link

Is there a way I can use these npm modules inside my k6 tests?


Hi @vinzy,

tl;dr: sorry, not in your case

Generally depending on the library you are using you might be able to use the things that I wrote here in part 2 .

Looking at the code for http-signature … it uses crypto … which as far as I know neither webpack nor browserify polyfill or at least they don’t polyfll it for the custom crypto library k6 has. Looking at the code you have a slim chance of being able to rewrite it with our crypto library (generally not a lot of work, awsv4 signature that I rewrote), but then it has dependencies from other libraries that use it. This is not not only going to be a rabbit hole, but given that you need to use private keys and such I am pretty sure you will need to use the undocumented (and unsupported) x509 module. And on a second look at the module code you will need to merge this PR, which (if I remember correctly) was one of the reasons we decided to stop making up our own crypto library.

Instead we shelved it until we fix some architectural things in k6 (still underway) and come back and decide which exact other already established crypto js API are we going to implement. This has been backlogged for a while and honestly it’s unlikely to be picked up (it’s just a lot of work and it will require some things still not in k6) until next year. Hopefully in the early parts of next year, but … again no promises :).

All of the above steps are in no way guarantees that you will be able to make it work as well … it might just turn out that you need another small piece so …
And you will need to have a custom build of k6 with … not small amount of changes to be honest…

So, sorry but given the usage of crypto it’s going to be very unlikely