Code works on VSCode but not on toolbox plug in

Hi,

I need some custom code to generate a signature for an API authorisation , and the code works fine on VSCode under javascript, generated the correct signature when tested. However, the same code runs into error when I put them in the toolbox plugin, the error message is:

“Bug in custom code eval code@
eval@[native code]
@
at root (undefined:1:23)”

Anyone encountered similar issue before?

the javascript box is visible on page load.

The code:

function generateHmacSha1SignatureBase64(text, secretKey) {
  const hmac = crypto.createHmac('sha1', secretKey);
  hmac.update(text);
  const signature = hmac.digest('base64');
  return signature;
}

const textToSign = '2024-01-15 21:48:14[access key]GET/activity.json/[id]/availabilities?start=2024-01-15&end=2024-01-15&includeSoldOut=false';
const secretKey = '[secret key]';

const generatedSignatureBase64 = generateHmacSha1SignatureBase64(textToSign, secretKey);

bubble_fn_sig(generatedSignatureBase64)

Thank you!

You could try calling it from the browser window like this

if (window.crypto && window.crypto.subtle) {
console.log(“Web Crypto API is available.”);
} else {
console.error(“Web Crypto API is not available in this browser.”);
}

I end up using bubble’s inbuilt format text as to HMAC SHA1… which works. still have no idea why the code doesn’t run on toolbox’s server script though!