sjudson / paseto.js

PASETO: Platform-Agnostic Security Tokens
MIT License
271 stars 16 forks source link

Incompatibility with NodeJS 11 #6

Closed sloonz closed 5 years ago

sloonz commented 5 years ago

This code works fine with node 10.x, but throws an exception on node 11.x :

const Paseto = require('paseto.js');

async function main() {
  const key = new Paseto.PrivateKey.V2();
  await key.inject(Buffer.from('/W17oWlDaX7DxqublK5QN+2I/EbpSrzhy0/rvGGydpmlz3Utp1onJ6oYxlxH0ZOWr6PC4UAHqn7AWCwuEUr9EA==', 'base64'));
  await key.protocol().sign("hello world", key);
}

main().catch(console.log);

Exception :

TypeError [ERR_INVALID_ARG_TYPE]: The "byteLength" argument must be of type number. Received type undefined
    at validateNumber (internal/validators.js:130:11)
    at checkNumberType (internal/buffer.js:42:3)
    at boundsError (internal/buffer.js:47:5)
    at Buffer.writeIntLE (internal/buffer.js:687:3)
    at Object.pae (/opt/data/simon/tmp/digisthesia/smarketoo-api/node_modules/paseto.js/lib/utils.js:158:15)
    at sodium.ready.then (/opt/data/simon/tmp/digisthesia/smarketoo-api/node_modules/paseto.js/lib/protocol/V2.js:246:30)

Looks like the size must now be explicitly passed.

Replacing writeIntLE by wirteInt32LE in utils.js fixes the issue, with all tests still passing.

sjudson commented 5 years ago

Thanks, will try and find some time to get a fix up. It may take a few days, but I'm happy to merge a PR in the meantime.

sjudson commented 5 years ago

Release 0.1.3 up on npm with the fix. Thanks a lot for the report + PR.

x-077 commented 5 years ago

Hello @sjudson ,

As it's related to nodeJs 11, I have the following warning when installing with npm :

gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/extcrypto_addon/extcrypto/extcrypto.o
../extcrypto/extcrypto.cc:115:23: warning: 'Utf8Value' is deprecated: Use Isolate version [-Wdeprecated-declarations]
    String::Utf8Value ipem(pem);
                      ^
/Users/.../.node-gyp/11.13.0/include/node/v8.h:2991:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^
/Users/.../.node-gyp/11.13.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
1 warning generated.
  SOLINK_MODULE(target) Release/extcrypto_addon.node
gyp info ok 

node version :

$ node -v
v11.13.0

Just let me know if you prefer me to open a new issue.

Thanks.