node.jsnetsuitesuitecommerce

Cant use Crypto in SuiteCommerce Advanced Service?


My SuiteScript Service MyService.Service.ss file is attempting to use the Node.js library Crypto but I get the error Error: No crypto when I run my service.

Does the Node.js version that SCA uses not have the Crypto library installed? Do I need to explicitly add Crypto as a dependency to distro.json? If so where? Do I need to install Crypto? If so, any advice how - I'm new to Node.js.

I am using pretty much standard Crypto functions, see below for the code that causes the problem:

function service (request)
{
    'use strict';

    var crypto = require('crypto'); // Error here

    var token = crypto.createHmac('md5', public_key)
               .update(private_key)
               .digest('hex');

    ...
}

Solution

  • Netsuite doesn't use the V8 engine so you are pretty much out of luck with crypto.

    I've used Paul Johnston's md5 package for hmac calc for years and it is fast enough and interoperates well. Name says MD5 but it includes SHA-1,256,512 as well.