OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

NotSupportedError - WebCrypto generateKey in k6

  • Thread starter Thread starter HapaxLegomenon
  • Start date Start date
H

HapaxLegomenon

Guest
I'm using the k6 JavaScript API to run tests, k6 is very limited when it comes to using libraries, so to do EC cryptography I'm using k6/experimental/webcrypto:

Code:
import { crypto } from "k6/experimental/webcrypto";

export function generateKeyPair() {
    crypto.subtle.generateKey(
        {
            name: "ECDSA",
            namedCurve: "P-256"
        },
        true,
        ["sign", "verify"],
    ).then((keypair) => {
        console.log(keypair)
    })
}

However when calling my function I get the following error:

ERRO[0009] Uncaught (in promise) NotSupportedError

Trying the same function in nodeJS with the @peculiar/webcrypto module yields no error:

Code:
const { Crypto } = require("@peculiar/webcrypto");

function keygenPerculiarCrypto(){
    const crypto = new Crypto();

    crypto.subtle.generateKey(
        {
            name: "ECDSA",
            namedCurve: "P-256"
        },
        true,
        ["sign", "verify"],
    ).then((keypair) => {
        console.log(keypair)
    })
}

Why does the k6 version not work whereas the node version does work?
Are there any alternatives for doing EC cryptography in k6 ?

<p>I'm using the k6 JavaScript API to run tests, k6 is very limited when it comes to using libraries, so to do EC cryptography I'm using <code>k6/experimental/webcrypto</code>:</p>
<pre><code>import { crypto } from "k6/experimental/webcrypto";

export function generateKeyPair() {
crypto.subtle.generateKey(
{
name: "ECDSA",
namedCurve: "P-256"
},
true,
["sign", "verify"],
).then((keypair) => {
console.log(keypair)
})
}
</code></pre>
<p>However when calling my function I get the following error:</p>
<p><code>ERRO[0009] Uncaught (in promise) NotSupportedError</code></p>
<p>Trying the same function in nodeJS with the @peculiar/webcrypto module yields no error:</p>
<pre><code>const { Crypto } = require("@peculiar/webcrypto");

function keygenPerculiarCrypto(){
const crypto = new Crypto();

crypto.subtle.generateKey(
{
name: "ECDSA",
namedCurve: "P-256"
},
true,
["sign", "verify"],
).then((keypair) => {
console.log(keypair)
})
}
</code></pre>
<p>Why does the k6 version not work whereas the node version does work?<br />
Are there any alternatives for doing EC cryptography in k6 ?</p>
 

Latest posts

Top