Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on using 'crypto' functions inside browserified NodeJS module #822

Closed
alexgo84 opened this issue Oct 25, 2018 · 1 comment
Closed

Comments

@alexgo84
Copy link

I am trying to generate an hmac from my payload and key. The following NodeJS code does this successfully:

var crypto = require('crypto')

function generateSignature(applicationKey, payload) {
    if (payload === undefined) {
        return ""
    }
    var strPayload = JSON.stringify(payload)
    var buffPayload = new Buffer(strPayload)

    var buffKey = new Buffer(applicationKey, 'hex')

    var hmac = crypto.createHmac('md5', buffKey);
    hmac.write(buffPayload);
    hmac.end()
    var signature = hmac.read().toString('hex')
    return signature
}

exports.generateSignature = generateSignature

In order to use this in my load test, I browserify this NodeJS file with:

browserify b.js --standalone sign > sign.js

Then, in my test I would require the browserified module:
var sign = require('./sign.js')
And call:

    var signature = sign.generateSignature(appKey, customerUpdatePayload)

However, when I run the JS file with k6, I get the following error:

TypeError: Value is not an object: undefined

referring to the browserified sign.js file.

This seems like a fairly common use case and I was wondering if I'm doing something wrong here?

Any advice would be very welcome. Thank you!

@alexgo84 alexgo84 changed the title Error on using 'crypt' functions inside browserified NodeJS module Error on using 'crypto' functions inside browserified NodeJS module Oct 25, 2018
@na-- na-- added the js-compat label Nov 9, 2018
@mstoykov
Copy link
Contributor

mstoykov commented Nov 6, 2020

importing nodejs "crypto" is not possible. Maybe in the future we will decide that instead of "k6/crypto" being a totally new implementation we are going to reimplement "crypto" from nodejs ... but this won't happen soon IMO.

If someone needs HMAC, k6 does support it I have even build awsv4 signing based on it.

I am closing this as I don't know what else could be done for this issue

@mstoykov mstoykov closed this as completed Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants