Problem with npm, @waves/[email protected] and secure-random.js

I need help with the JS module @waves/[email protected].

I installed as a dependency as:

npm install --save @waves/[email protected]

Then I imported on one of my projects (using typescript 3.2.4):

import { utils as wavesUtils } from '@waves/signature-generator';

Then I got next error when executing npm start:

ERROR in ./node_modules/@waves/signature-generator/dist/libs/secure-random.js
Module not found: Error: Can't resolve 'crypto' in '$project_folder/node_modules/@waves/signature-generator/dist/libs'

Checking that dependency I see that secure-random.js call require('crypto') but there is no crypto.js on the same folder (secure-random.js is defined on libs folder and crypto on utils folder.

Could you help with fix this issue please?

I was able to workaround this replicating same steps manually:

import { default as axlsign } from '@waves/signature-generator/libs/axlsign';
import { default as convert } from '@waves/signature-generator/dist/utils/convert';
import { concatUint8Arrays } from '@waves/signature-generator/dist/utils/concat';
import { default as base58 } from '@waves/signature-generator/dist/libs/base58';

...

  validateAuth(authPayload) {

    console.log("(login) validating auth", authPayload);

    let signature = authPayload.signature;
    let publicKey = authPayload.publicKey;
    let prefix = authPayload.prefix;
    let host = authPayload.host;
    let payload = this.loginPayload;

    let data = [prefix, host, payload]
        .map(d => convert.stringToByteArrayWithSize(d))
        .map(stringWithSize => Uint8Array.from(stringWithSize));

    let dataBytes = concatUint8Arrays(...data);
    let publicKeyBytes = base58.decode(publicKey);
    let signatureBytes = base58.decode(signature);

    //console.log("WavesGenerator", WavesGenerator);
    let validSignature = axlsign.verify(publicKeyBytes, dataBytes, signatureBytes);
    console.log("(login) validSignature?", validSignature);
  }

Hello, cverdes!
This problem is caused by your collector settings.
When building a project, the builder analyzes the code, finds ‘require’ calls in it, and tries to connect the appropriate dependencies, while ‘crypto’ is the native nodejs module. The collector does not find this module and gives an error. In the code, this place will never be called up in the browser, so you should configure the collector to skip ‘crypto’ and do not display any errors.

Let me know if you have mnore questions about this issue

I’m surprise with the answer to be honest but I understand what you mean, this is one of the reasons why I don’t really like JS, in Scala/Java you would use an Interface and the implementation will be resolved on runtime (avoiding this type of issues).

As I mentioned I workaround the problem replicating the source code, but is an effort I would like to avoid in the future using current library, so I’ll try your solution.

Could you put me an example of how to configure the collector to avoid crypto dependency?
Thanks in advance.