asmcrypto / asmcrypto.js

JavaScript Cryptographic Library with performance in mind.
MIT License
659 stars 182 forks source link

Canot use asmcrypto from NPM in NodeJS projects #114

Closed microshine closed 6 years ago

microshine commented 7 years ago

Current version of asmcrypto.js in npm is 0.0.11. When I use require("asmcrypto.js") I've got an error

TypeError: Cannot read property 'protocol' of undefined
    at C:\github\webcrypto-liner\node_modules\asmcrypto.js\asmcrypto.js:5:15020
    at Object.<anonymous> (C:\github\webcrypto-liner\node_modules\asmcrypto.js\asmcrypto.js:5:26797)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at repl:1:11

I can use the latest version of asmcrypto from GitHub.

Could you publish the latest version?

AZsoftAlanZheng commented 6 years ago

Hi, I have the same problem as you. I build the project by myself. but I got an error like this.

TypeError: Cannot read property 'now' of undefined
    at {PATH}/asmcrypto.js:8:29690
    ......

Could you tell me what is the js code you used to solve this problem?

ghost commented 6 years ago

Me too :-(

TypeError: Cannot read property 'protocol' of undefined
    at /home/pi/workspaces/pi_mesh_proxy/node_modules/asmcrypto.js/asmcrypto.js:5:15021
    at Object.<anonymous> (/home/pi/workspaces/pi_mesh_proxy/node_modules/asmcrypto.js/asmcrypto.js:5:26797)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/pi/workspaces/pi_mesh_proxy/aes_ccm_adapter.js:6:14)

Is there a solution to this? @microshine It sounds like you found a workaround.... if so, what was the magic solution?

AZsoftAlanZheng commented 6 years ago

It works~

(function ( exports, global ) {
……   
 })( {}, (typeof module !== 'undefined' && module.exports) ? global : this );
ghost commented 6 years ago

@AZsoftAlanZheng sorry, I don't understand your comment. Are you saying you changed some of the code? If so I'd appreciate you stating which js file and line you changed. A diff would be perfect. Thanks.

ghost commented 6 years ago

@AZsoftAlanZheng could you clarify your comment, please?

@vibornoff could you assist? I'm using asmcrypto in both a browser application OK and would very much like to use the same code in its node.js serverside counterpart. Thanks in anticipation.

vibornoff commented 6 years ago

@bluetooth-mdw, @AZsoftAlanZheng could you please provide a code snippet? I'm doint the next thing and all works fine:

$ node asmcrypto.js && echo "works fine"
works fine
helllamer commented 6 years ago

@vibornoff Please just release/publish current git version to npm.

https://www.npmjs.com/package/asmcrypto.js contains 2-year-old version with unfixed #105 (merged 1 year ago).

ghost commented 6 years ago

@vibornoff here's some very simple code:

var bleno = require('asmcrypto.js');

console.log("Hello World");
pi@raspberrypi:~/workspaces/asmtest $ node test.js
/home/pi/workspaces/asmtest/node_modules/asmcrypto.js/asmcrypto.js:5
if($a(a)||(a=new _a(a)),!this.sign)return a;if(!a.sign)return this;var b,c,d,e,f=this.bitLength,g=this.limbs,h=g.length,i=this.sign,j=a.bitLength,k=a.limbs,l=k.length,m=a.sign,n=new _a;b=(f>j?f:j)+(i*m>0?1:0),c=b+31>>5,Za.sreset();var o=Za.salloc(h<<2),p=Za.salloc(l<<2),q=Za.salloc(c<<2);return Za.z(q-o+(c<<2),0,o),Sc.set(g,o>>2),Sc.set(k,p>>2),i*m>0?(Za.add(o,h<<2,p,l<<2,q,c<<2),d=i):i>m?(e=Za.sub(o,h<<2,p,l<<2,q,c<<2),d=e?m:i):(e=Za.sub(p,l<<2,o,h<<2,q,c<<2),d=e?i:m),e&&Za.neg(q,c<<2,q,c<<2),0===Za.tst(q,c<<2)?Vc:(n.limbs=new Uint32Array(Sc.subarray(q>>2,(q>>2)+c)),n.bitLength=b,n.sign=d,n)}function ib(a){return $a(a)||(a=new _a(a)),this.add(a.negate())}function jb(a){if($a(a)||(a=new _a(a)),!this.sign||!a.sign)return Vc;var b,c,d=this.bitLength,e=this.limbs,f=e.length,g=a.bitLength,h=a.limbs,i=h.length,j=new _a;b=d+g,c=b+31>>5,Za.sreset();var k=Za.salloc(f<<2),l=Za.salloc(i<<2),m=Za.salloc(c<<2);return Za.z(m-k+(c<<2),0,k),Sc.set(e,k>>2

TypeError: Cannot read property 'protocol' of undefined
    at /home/pi/workspaces/asmtest/node_modules/asmcrypto.js/asmcrypto.js:5:15021
    at Object.<anonymous> (/home/pi/workspaces/asmtest/node_modules/asmcrypto.js/asmcrypto.js:5:26797)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/pi/workspaces/asmtest/test.js:1:75)
ghost commented 6 years ago

Also....

pi@raspberrypi:~/workspaces/asmtest $ node asmcrypto.js
module.js:538
    throw err;
    ^

Error: Cannot find module '/home/pi/workspaces/asmtest/asmcrypto.js'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
pi@raspberrypi:~/workspaces/asmtest $ ls -l node_modules/
total 4
drwxr-xr-x 4 pi pi 4096 Dec 14 12:48 asmcrypto.js
vibornoff commented 6 years ago

@bluetooth-mdw , just published v0.0.12, try again please

ghost commented 6 years ago

Thanks. I'm now getting the "'now' of undefined error" rather than "'protocol' of undefined":

pi@raspberrypi:~/workspaces/asmtest $ npm remove asmcrypto.js
npm WARN saveError ENOENT: no such file or directory, open '/home/pi/workspaces/asmtest/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/pi/workspaces/asmtest/package.json'
npm WARN asmtest No description
npm WARN asmtest No repository field.
npm WARN asmtest No README data
npm WARN asmtest No license field.

removed 1 package in 0.622s
pi@raspberrypi:~/workspaces/asmtest $ npm install asmcrypto.js
npm WARN saveError ENOENT: no such file or directory, open '/home/pi/workspaces/asmtest/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/pi/workspaces/asmtest/package.json'
npm WARN asmtest No description
npm WARN asmtest No repository field.
npm WARN asmtest No README data
npm WARN asmtest No license field.

+ asmcrypto.js@0.0.12
added 1 package in 2.213s
pi@raspberrypi:~/workspaces/asmtest $
pi@raspberrypi:~/workspaces/asmtest $
pi@raspberrypi:~/workspaces/asmtest $
pi@raspberrypi:~/workspaces/asmtest $ node test.js
/home/pi/workspaces/asmtest/node_modules/asmcrypto.js/asmcrypto.js:5
Za(a)||(a=new _a(a));var b=this.limbs,c=b.length,d=a.limbs,e=d.length,f=0;return this.sign<a.sign?-1:this.sign>a.sign?1:(Tc.set(b,0),Tc.set(d,c),f=Rc.cmp(0,c<<2,c<<2,e<<2),f*this.sign)}function hb(a){if(Za(a)||(a=new _a(a)),!this.sign)return a;if(!a.sign)return this;var b,c,d,e,f=this.bitLength,g=this.limbs,h=g.length,i=this.sign,j=a.bitLength,k=a.limbs,l=k.length,m=a.sign,n=new _a;b=(f>j?f:j)+(i*m>0?1:0),c=b+31>>5,Rc.sreset();var o=Rc.salloc(h<<2),p=Rc.salloc(l<<2),q=Rc.salloc(c<<2);return Rc.z(q-o+(c<<2),0,o),Tc.set(g,o>>2),Tc.set(k,p>>2),i*m>0?(Rc.add(o,h<<2,p,l<<2,q,c<<2),d=i):i>m?(e=Rc.sub(o,h<<2,p,l<<2,q,c<<2),d=e?m:i):(e=Rc.sub(p,l<<2,o,h<<2,q,c<<2),d=e?i:m),e&&Rc.neg(q,c<<2,q,c<<2),0===Rc.tst(q,c<<2)?Wc:(n.limbs=new Uint32Array(Tc.subarray(q>>2,(q>>2)+c)),n.bitLength=b,n.sign=d,n)}function ib(a){return Za(a)||(a=new _a(a)),this.add(a.negate())}function jb(a){if(Za(a)||(a=new _a(a)),!this.sign||!a.sign)return Wc;var b,c,d=this.bitLe

TypeError: Cannot read property 'now' of undefined
    at /home/pi/workspaces/asmtest/node_modules/asmcrypto.js/asmcrypto.js:5:25064
    at Object.<anonymous> (/home/pi/workspaces/asmtest/node_modules/asmcrypto.js/asmcrypto.js:5:27107)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/pi/workspaces/asmtest/test.js:1:75)
ghost commented 6 years ago

@vibornoff Any news on this? I don't wish to pester you and I appreciate your hard work on this. I just need a sense of whether or not this is going to be resolved so I can consider my options. Thanks in anticipation.

helllamer commented 6 years ago

Feels like, this is a bug in Gruntfile.js: hardcoded grunt-concat options may break things in https://github.com/asmcrypto/asmcrypto.js/blob/master/Gruntfile.js#L476

LastZolex commented 6 years ago

Hi everybody,

I just started using asmcrypto.js today (version 0.0.12) to set up an easy example to evaluate it. And I stumble across exactly the same problem, locking me out of evaluating the lib at all, because it happens in the bootstrapping process (please see stacktrace below )

Any help will be appreciated though and thank you already in advance for any solution! ;-) Cheers LZ

asmcrypto.js:5 Uncaught TypeError: Cannot read property 'now' of undefined at asmcrypto.js:5 at Object.<anonymous> (asmcrypto.js:5) at __webpack_require__ (bootstrap bcc5cdf097a1e536e689:54) at Object.158 (key-cloak-rest-service.ts:11) at __webpack_require__ (bootstrap bcc5cdf097a1e536e689:54) at Object.48 (main.js:1262) at __webpack_require__ (bootstrap bcc5cdf097a1e536e689:54) at Object.209 (open-weather-map.ts:6) at __webpack_require__ (bootstrap bcc5cdf097a1e536e689:54) at Object.291 (main.js:1184)

alippai commented 6 years ago

We plan to fix this later this week. Thank you for your patience.

LastZolex commented 6 years ago

Thank you so much for the quick info!! Looking forward to your solution, but do not forget about having some fun during x-mas ;-)

Cheers LZ

ghost commented 6 years ago

That's great news, thank you @alippai :-)

ghost commented 6 years ago

Hi @alippai just wondering how this is progressing? Do you think this will be resolved for the start of next week?

Cheers M

alippai commented 6 years ago

Is it better with version 0.16.0?

ghost commented 6 years ago

Hi @alippai 0.16.0 looks very promising. My simple "Hello World" test no longer generates the errors reported here. I'll do some more substantial testing tomorrow. Fingers crossed.

Thanks a million for your work on this. Very much appreciated :-)

Martin

alippai commented 6 years ago

Be careful, it's a major change. A bunch of exported bundle formats are added to the npm package as well.

ghost commented 6 years ago

Presumably tests are passing though? All I need for my selfish purposes are AES_CCM.encrypt and AES_CCM.decrypt to be working....

alippai commented 6 years ago

The tests are passing in NodeJS 6, 8 and 9. I turned off SauceLabs as it didn't connect with the old setup.

ghost commented 6 years ago

Great, thank you. Sounds like it should be fine for my purposes. What I'm creating (for the Bluetooth SIG) is an education resource, not production code too.

ghost commented 6 years ago

@alippai Any chance you could publish with AES-CCM included? See https://github.com/asmcrypto/asmcrypto.js/issues/129 - I don't really understand the build process and am not sure what to do to enable AES-CCM. There's presumably a good reason it is not included by default but I wish it was easier to include it. If you can't publish to npm with AES-CCM enabled, would you mind patiently telling me what to do after npm install to enabled AES_CCM support please?

Thanks in anticipation

alippai commented 6 years ago

This should work now. Feel free to open a new ticket for platform specific problems (e.g. the Raspberry Pi installation error above).