Git Product home page Git Product logo

Comments (8)

mpetrunic avatar mpetrunic commented on June 19, 2024 1

@tynes
I debug this a lot, good thing it's not related to electron. It's jest that's causing this, apparently, moduleRegistry inside jest (they have custom loader because of mocking and stubbing) stores empty object({}) if module require throws. So in our tests in jest with electron rebuilded bcrypto, loading of sha256 throws with module did not self-register. and all other native modules load successfully because require('./bindings') returns "{}" instead of throwing.

Would you be willing to accept PR where all native modules have instead of

const assert = require('bsert');
const binding = require('./binding').random;

this

const assert = require('bsert');
const binding = require('./binding').random;

assert(binding);

?
Which prevents during requiring binding to be undefined and it would throw causing bcrypto to fallback on js or node version.

from bcrypto.

mpetrunic avatar mpetrunic commented on June 19, 2024 1

Bug is releated to jest and how it handles require calls. Aparently if require trows, jest will same empty object to modules cache and return it on all subsequent calls. Havent found solution yet

from bcrypto.

braydonf avatar braydonf commented on June 19, 2024 1

A lot has changed including the removal of OpenSSL as a dependency.

OpenSSL is still used, however is via the existing Node.js crypto API for example aes and random. Also sha{256,384,512}, hash160 and hash256 use OpenSSL via libtorsion, except on electron (which has a fallback).

from bcrypto.

mpetrunic avatar mpetrunic commented on June 19, 2024

This is when pbkdf2 native is invoked on electron rebuilded bcrypto:

backend.load is not a function
      at derive (node_modules/@nodefactory/bls-keystore/node_modules/bcrypto/lib/native/pbkdf2.js:35:11)

from bcrypto.

tynes avatar tynes commented on June 19, 2024

@mpetrunic Have you seen this issue? #27

At runtime, NODE_ENV can be set as js and that might fix the problem. The require of the module looks like this:

bcrypto/lib/pbkdf2.js

Lines 9 to 16 in 1d257bb

try {
module.exports = require('./native/pbkdf2');
} catch (e) {
if (process.env.NODE_BACKEND === 'js')
module.exports = require('./js/pbkdf2');
else
module.exports = require('./node/pbkdf2');
}

There is also pbkdf2-browser.js.
https://github.com/bcoin-org/bcrypto/blob/master/lib/pbkdf2-browser.js

from bcrypto.

mpetrunic avatar mpetrunic commented on June 19, 2024

Well code never reaches catch clause. It successfully requires native module and fails to execute function there. /node/pbkdf2 works perfectly so that means it would work if native throws exception,

from bcrypto.

alexbarnsley avatar alexbarnsley commented on June 19, 2024

Is there any update on this? I also get the same error during jest as @mpetrunic described. Thanks

from bcrypto.

tynes avatar tynes commented on June 19, 2024

@alexbarnsley @mpetrunic Have you tried the latest version of bcrypto? A lot has changed including the removal of OpenSSL as a dependency.

from bcrypto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.