js-IPFS 0.51.0 adds type definitions and removes SECIO

by Alex Potsides on 2020-10-29

πŸ”¦ Highlights

Type Defs! No more SECIO! Halve your install time!

js-IPFS@0.51.0 has taken off from the launchpad and is on route to your node_modules folder with TypeScript support, Custom DAG Formats and a new, lighter way to consume the module

πŸͺ Types

TypeScript has taken the JS world by storm, allowing developers to be alerted when the interface they are coding against is not what they expect and to enable vast amounts of useful tooling like accurate code completion and inline doc viewing.

There have been several community led efforts to provide type information for js-IPFS but since the project moves so quickly it’s an uphill struggle to keep compatibility with the changes that get landed in every release.

With js-IPFS@0.51.0 types are now a first-class citizen within the codebase. The project has not gone so far as to convert to TypeScript - we do not wish knowledge of TypeScript to become a prerequisite to contributing to js-IPFS development, instead all types are defined using JSDoc comments and are built and validated during development and Continuous Integration.

Going forward all new code will be required to have types so to help contributors with that aegir recently added stricter linting for JSDoc comments and we also added a typecheck github action to js-IPFS so any errors or missing types should be easy to spot in a PR.

SECIO Removal

The deprecated security transport SECIO has finally been removed in js-IPFS@0.51.0. It’s successor, Noise was first released with js-IPFS@0.47.0 and is now the default security transport used by libp2p.

go-IPFS@0.7.0 recently also removed SECIO support after introducing Noise in go-IPFS@0.6.0, which means js-IPFS@0.51.0 and go-IPFS@0.7.0 can only talk to other nodes running go-IPFS@0.6.0 or js-IPFS@0.47.0 or later.

If you are running IPFS nodes with a diverse range of versions you’ll want to upgrade them all to go-IPFS@0.6.0 or later and js-IPFS@0.47.0 at a minimum, otherwise you will start to lose connectivity with the rest of the network as SECIO ceases to be supported by peers.

πŸ“Œ Custom DAG Formats

At its heart IPFS is about files, which means UnixFS and in terms of IPLD Formats means dag-pb and ipld-raw.

IPFS gives you access to all the underlying components though, allowing you to use dag-cbor to connect your data structures together and have them accessible and distributable across the internet through libp2p.

But what if these codecs don’t meet your requirements, what if you want to develop a new codec or use less common ones like dag-jose?

We don’t bundle every available codec with the default js-IPFS install because some of them pull in large dependency trees which will unnecessarily slow down the install for people who aren’t going to use them.

Previously you’ve been able to use custom IPLD formats with ipfs-http-client and when running ipfs as an in-process node as part of your application, but now you can use them in a running daemon as well.

See the new custom-ipld-formats example in the js-IPFS repo for more information on how to set this up.

🍏 ipfs-core - a new lighter IPFS for application authors

When you npm install ipfs you get the core IPFS node as well as tools to run a daemon, an HTTP API server and a CLI. If you’re installing this globally to use on the command line to use with IPFS Desktop or just to have a node running on your network this is great as you want the extra tools to be able to communicate with your node.

These take time to install and use up hard drive space and if you are building an application on top of js-IPFS you don’t necessarily need them.

Now you can npm install ipfs-core to just get the parts of the IPFS stack you need to run an in-process node. This has roughly halved the install size of js-IPFS by not installing all those extra dependencies that you don’t need.

You can use the module in the same way you did before, all you need to do is change the dependency name/version and update the require name:

const IPFS = require('ipfs')

async function () {
  const node = await IPFS.create()

  node.add(...)

  await node.stop()
}

to this:

const IPFS = require('ipfs-core')

async function () {
  const node = await IPFS.create()

  node.add(...)

  await node.stop()
}

and you’re all set! This is the start of an attempt to make the codebase more modular and allow for swapping components out and maybe not pulling in everything all the time to enable power users to create a minimal node that only contains the functionality they require. Watch this space for more!

CORS is now disabled by default

Cross Origin Resource Sharing is a browser security measure to prevent unauthorized access to APIs by rogue JavaScript running on compromised sites on the web.

Versions of js-IPFS prior to 0.51.0 have a very permissive CORS setting allowing requests from anywhere which although makes developing against the API very simple it leaves a little to be desired in terms of security.

From 0.51.0 onwards CORS is disabled by default so if you plan on making requests against the HTTP RPC API you will need to add the relevant origin and methods you will be using to the node configuration before starting it.

See the CORS section of the README for the full lowdown.

✨New features

πŸ”¨ Breaking changes

πŸ•·οΈ Bug fixes

πŸ—ΊοΈ What’s next?

Check out the js-IPFS Project Roadmap which contains headline features organised in the order we hope them to land.

Only large features are called out in the roadmap, expect lots of small bugfix releases between the roadmapped items!

😍 Huge thank you to everyone that made this release possible

πŸ™ŒπŸ½ Want to contribute?

Would you like to contribute to the IPFS project and don’t know how? Well, there are a few places you can get started:

⁉️ Do you have questions?

The best place to ask your questions about IPFS, how it works, and what you can do with it is at discuss.ipfs.io. We are also available at the #ipfs channel on Freenode.

Comments