marvinroger / nanocurrency-js

🔗 A toolkit for the Nano cryptocurrency, allowing you to derive keys, generate seeds, hashes, signatures, proofs of work and blocks.
https://marvinroger.github.io/nanocurrency-js
141 stars 31 forks source link

work() not working... #19

Closed vano21 closed 6 years ago

vano21 commented 6 years ago

I can't get work() to do its thing:

const pow = nanoCurrency.work(accountHash);

Outputs:

nanocurrency.esm.js:6 Uncaught (in promise) TypeError: checkHash is not a function at Object.work (http://localhost:3000/static/js/bundle.js:25491:182215)

This is in a react app.

marvinroger commented 6 years ago

I did not test the esm bundle, but the cjs and umd ones are working well. Can you provide a full reproduction script (with the imports)?

Also, what’s your module bundler? Webpack?

marvinroger commented 6 years ago

And, do you have the problem only with work ?

vano21 commented 6 years ago

These work: generateSeed() and deriveSecretKey()

These do not work: derivePublicKey(), deriveAddress() and work()

they produce a similar error (checkKey is not a function)

Looks like it has something to do with exporting from nano currency.esm.js - the problematic ones seem to be the ones being exported as an alias of checkSeed.

I am using a standard create-react-app generated project, this is basically the only imports:

import React from 'react'; import * as nanoCurrency from 'nanocurrency';

vano21 commented 6 years ago

Ok I just did this:

import * as nanoCurrency from '../node_modules/nanocurrency/dist/nanocurrency.cjs';

and it all works now.

The problem is with the esm one.

marvinroger commented 6 years ago

There must be a problem in either the Rollup bundling or the Babel transpiling. I implemented a workaround, not exporting aliases but actual wrapper functions. It feels cleaner anyway, so I am comfortable with that.

Can you test with 1.7.4?

vano21 commented 6 years ago

All ok now!

hashSendBlock, hashReceiveBlock and signBlock also all work.

marvinroger commented 6 years ago

Perfect! Thanks. 😉