2
votes

I'm getting "TypeError: Cannot read property 'sigBytes' of undefined" error when running a postman collection with a cryptojs pre-request script. The pre-request script computes a hmac-sha256 signature which is also part of parameters of the main API to be called.

Below is my script:

let mobile = pm.environment.get('mobileNumber');
let value = pm.environment.get('value');
let merchantId = pm.environment.get('merchantId');
let referenceNumber = pm.environment.get('referenceNumber');
let authCode = pm.environment.get('authCode');
let secretKey = pm.environment.get('secretKey');

let string = mobile + value + merchantId + referenceNumber + authCode;

pm.environment.set('string', string);

let hmac = CryptoJS.HmacSHA256(string, secretKey);

pm.environment.set('hmac', hmac);

signature = "hmac256-" + hmac;

pm.environment.set('signature', signature);

I already tried encoding the string and secretKey to UTF-8, base64stringify, JSON stringify but I'm getting errors still.

Here are sample values from each of the variables:

  • mobile - +639012345678
  • value - 100
  • merchantId - TEST_MERCHANT1
  • referenceNumber - TEST_MERCHANT1-000001
  • authCode - 000001
  • secretKey - a2c36909-c9cc-4ed3-9423-ec170e1eb6c2
1

1 Answers

1
votes

Looks like at least one of your environment variables isn't defined.

The error message is due to a bug in CryptoJS: https://github.com/brix/crypto-js/issues/85