Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Getting js-ipfs to load in browser #509

Closed
nikuda opened this issue Oct 3, 2016 · 16 comments
Closed

Getting js-ipfs to load in browser #509

nikuda opened this issue Oct 3, 2016 · 16 comments

Comments

@nikuda
Copy link

nikuda commented Oct 3, 2016

Issues I've found (so far) that prevent js-ipfs from loading in the browser.

  1. package.json attribute main pointing to a non-existing path

    Fixed in Fixed path for module importing #508

  2. Use of fs.readFileSync with .proto files.

    Proposed solution No more fs.readFileSync and different hash functions js-ipfs-merkle-dag#50 would need to be applied to the following libraries:

    • ipfs-bitswap
    • ipfs-merkle-dag
    • ipfs-unixfs
    • libp2p-crypto
    • libp2p-identify
    • libp2p-secio
  3. node-forge library uses AMD modules which doesn't work with browserify

    Most severe of the issues, more detail:

    Affected libraries:

    • libp2p-crypto
    • libp2p-identify
    • libp2p-secio
@daviddias
Copy link
Member

daviddias commented Oct 3, 2016

Hi @nikuda thanks for digging deap into the roots of the problem, really nice sum up, looking forward to see you tinkering with the code too :D

1

Solved - #508

2

We are working on it, however there is one more change that needs to happen, which is changing libp2p-ipfs to libp2p-ipfs-browser, they offer the same API, but need to be replace for in browser used, this is currently achieved through the build process.

3

We are working on stop using node-forge, although we hoped it became CommonJS -- libp2p/js-peer-id#5 --

Follow - #485

@nikuda
Copy link
Author

nikuda commented Oct 3, 2016

Not a problem ☺️ @diasdavid

change that needs to happen, which is changing libp2p-ipfs to libp2p-ipfs-browser

Are there any issues/PRs open that relate to changes that need to happen here?

We are working on stop using node-forge

Have you considered any alternatives? Maybe native browser WebCrypto API could do the job? https://diafygi.github.io/webcrypto-examples/

These two libraries also look good. They both seem to be under 10Kb minified which is a lot better than node-forge 100Kb+. The size of js-ipfs is a bit of a concern, it's coming in at 500Kb+ minified for me.

@daviddias
Copy link
Member

change that needs to happen, which is changing libp2p-ipfs to libp2p-ipfs-browser
Are there any issues/PRs open that relate to changes that need to happen here?

That is just how it works, libp2p-ipfs is the libp2p build that has the transports for Node.js (TCP, WebSockets, UTP, libp2p-ipfs-browser is the build with the transports for Browser (WebRTC + WebSockets).

In the near future, Routing will be added (DHT) and that will behave interally different in the browser and in Node.js.

Have you considered any alternatives? Maybe native browser WebCrypto API could do the job? https://diafygi.github.io/webcrypto-examples/

If you go through #485, you'll see that is what we are doing :)

These two libraries also look good. They both seem to be under 10Kb minified which is a lot better than node-forge 100Kb+.

We have had some discussions (daviddias/webcrypto#1), but we ended up picking node-forge in the beginning because it had the primitives we needed.

@dignifiedquire
Copy link
Member

@nikuda all of this work is pretty much done, it was one of the things I have been working on in the last weeks, see #485 for a list of PRs that

  • do switch all crypto webcrypto in the browser where possible
  • remove the use of fs in the browser
  • use the browser field to map things like libp2p-ipfst o libp2p-ipfs-browser in an independent way

@nikuda
Copy link
Author

nikuda commented Oct 3, 2016

If you go through #485, you'll see that is what we are doing :)

Ah the ref to #485 was missing before. Thanks!

all of this work is pretty much done

Great! 🏆 It seems libp2p/js-libp2p-crypto#10 has been supplanted by libp2p/js-libp2p-crypto#12 which most of the other PRs rely on. I noticed that the PR has the backlog tag, is there anything I can help with it to get it merged in sooner?

@dignifiedquire
Copy link
Member

. I noticed that the PR has the backlog tag, is there anything I can help with it to get it merged in sooner?

The backlog currently just means that it is not part of a specific milestone. I am trying to get it merged as soon as possible, as it will be very painful to keep these PRs up to date across all the repos if too much happens.

If you want to help out, I've added a TODO list of things that need to be done at the top of #485. The current next step is to replace multihashing with multihashing-async on all PRs that depend on it.

@dignifiedquire
Copy link
Member

It seems libp2p/js-libp2p-crypto#10 has been supplanted by libp2p/js-libp2p-crypto#12 which most of the other PRs rely on.

Yes, just updated the reference.

@nikuda
Copy link
Author

nikuda commented Oct 3, 2016

The current next step is to replace multihashing with multihashing-async on all PRs that depend on it.

multihashing -> multihashing-async progress:

These seem to be the only libs from #485 that use multihashing.

@dignifiedquire
Copy link
Member

Thanks @nikuda, most of these pull it in as an indirect dependency. I just updated the issue with a better overview table of ALL THE PRs 😉

@daviddias
Copy link
Member

Hi @nikuda js-ipfs 0.18.0 has been released and it includes all of the changes of the async crypto PR #485 🎉

These should be all problems of the past, try it out :D

@nikuda
Copy link
Author

nikuda commented Nov 24, 2016

Good stuff @diasdavid! Will try it soon :)

@daviddias
Copy link
Member

also, check out the examples folder: https://github.com/ipfs/js-ipfs/tree/master/examples

@nikuda
Copy link
Author

nikuda commented Dec 3, 2016

All working @diasdavid. 👍

@nikuda
Copy link
Author

nikuda commented Dec 3, 2016

Spoke too soon.

In bundle-browserify example node.load() fails with an unhandled rejection. I'll open up a new issue when I have more info.

@nikuda
Copy link
Author

nikuda commented Dec 3, 2016

Fixed the issue in libp2p/js-libp2p-crypto#47.

Now the node in bundle-browserify example initialises successfully with a 'IPFS node is ready' message – although no peers seem to connect.

@daviddias
Copy link
Member

thank you @nikuda !! :)

MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this issue May 22, 2020
test: add test for add files to dir non sequentially
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants