0

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');

    ...
}
sazr
  • 24,984
  • 66
  • 194
  • 362

1 Answers1

1

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.

bknights
  • 14,408
  • 2
  • 18
  • 31
  • Thanks :). I did some research and it looks like SCA/NetSuite backend uses Rhino not Node.js. Is that correct? Or maybe Rhino is built partially off Rhino? – sazr Feb 22 '17 at 22:01
  • Rhino was what they were using last time some of their stack traces leaked through. I imagine that's still the case since they operate on a Java stack. You can't get at any of the rhino functionality though. – bknights Feb 22 '17 at 22:15
  • damn :P I was hoping Rhino has a cryptographic function I could use. I'm probably going to use the node package js-sha256 and install it as a `third_parties` module in my SCA website (and include it in `distro.json`). Hopefully I can pull in that libary that way and use it. – sazr Feb 22 '17 at 23:50