npm issue with secure-random.js #20
Comments
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);
} |
This code only for nodejs.
U run your app in browser or nodejs? |
I'm running an Angular project (browser only)... but the problem is at compile time. I don't get your example, the only thing I'm trying to do is to validate a signature before sending to the server, so the main point I need to cover is the next code: let validSignature = axlsign.verify(publicKeyBytes, dataBytes, signatureBytes); Original idea was to use the library: import { utils as wavesUtils } from '@waves/signature-generator';
wavesUtils.crypto.isValidSignature(bytes, sign, publicKey) I followed the next documentation: But when I import that library... I get the mentioned error. |
What the version of typescript u use? And give u tsconfig file please.
This look like no typescript error. |
Version of Typescript (I think I put on original post): As I said I use Angular, to reproduce the error I use the next code inside a service: import { utils as wavesUtils } from '@waves/signature-generator';
...
console.log("test waves", wavesUtils.crypto.isValidSignature(dataBytes, authPayload.signature, user.publicKey)); Then when I execute a $ ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2019-04-01T18:42:51.745Z
Hash: 97b437ba42fb91d6ff37
Time: 6550ms
chunk {main} main.js, main.js.map (main) 82.9 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 237 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 729 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.1 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 7.08 MB [initial] [rendered]
ERROR in ./node_modules/@waves/signature-generator/dist/libs/secure-random.js
Module not found: Error: Can't resolve 'crypto' in '/Users/cverdes/git/smart-trade-front/node_modules/@waves/signature-generator/dist/libs'
ℹ 「wdm」: Failed to compile. I understand is a compilation problem because secure-random is calling this: var crypto = require('crypto'); ... and there is no crypto lib on the same folder as signature-generator. tsconfig (renamed the extension to .txt, original is .json): Let me know if you need more information!! |
Hello, Carlos Verdes! Let me know if you have more questions about this issue |
It fails compiling with Node JS using Angular, could you give me a hint of how to solve the issue? Thanks for the answer in any case. |
This is not typescript error. This error with your angular build. |
@tsigel this error happen only when I add your dependency as I mentioned before and I show you which part of the code is failing. In any case I moved from Angular to another framework and now I'm using rollup.js to get my dependencies and found another error... a Circular dependency error. Is there any place I can chat with you @tsigel ?? |
U can use compiled file from path "@waves/signature-generator/dist/signature-generator.min.js" from package or give me link to ur repository with problem and i try to help u. |
How to reproduce.
Install on npm project as a dependency:
Import using typescript 3.2.4:
Execute
npm start
and get next error:Checking that dependency I see that
secure-random.js
callrequire('crypto')
but there is nocrypto.js
on the same folder (secure-random.js
is defined on libs folder andcrypto
on utils folder.Could you help with fix this issue please?
The text was updated successfully, but these errors were encountered: