npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mutable-webtorrent

v1.3.1

Published

Create / Load / Seed mutable webtorrents (BEP 46)

Downloads

106

Readme

mutable-webtorrent (WIP)

Create / Load / Seed mutable webtorrents (BEP 46)

Based on the proof of concept for BEP 46 https://github.com/lmatteis/dmt/

About

BitTorrent is widespread and is used all over the place for sharing files without having to rely on centralized third parties. Even though it's great for sharing content, it doesn't provide a method for updating that content. Luckily, BitTorrent is a constantly evolving spec, and there was a push to provide a mechanism to support this use case in 2016. This library implements the "Updating Torrents Via DHT Mutable Items" proposal on top of WebTorrent.

Essentially, you create a public/secret keypair using ed25519. Then, you create a torrent and note it's infoHash, an identifier calculated based on the torrent contents. Then, you sign the infohash with your secret key, and publish a value to the DHT under the sha1 hash of your public key. Only you are able to publish changes to this key because it's automatically validated by nodes in the DHT.

Then, you create a magnet link which points to your public key instead of the infohash of the torrent and share it somewhere. Then, if somebody wants to download your content, they'll take the hash of your public key, look up values in the DHT, then verify that those values got signed by your secret key, and get the infohash of the torrent. From there they use the usual peer discovery methods for other magnet links.

What this gives you is the ability to share a torrent, and update where it points to over time. My goal with this is to enable people to create websites and other types of archives that can be used as a peer to peer alternative to the HTTP-based web.

Example

const MutableWebTorrent = require('mutable-webtorrent')

const client = new MutableWebTorrent()

const { publicKey, secretKey } = client.createKeypair()

console.log('Created Keypair: Public [ ', publicKey, '] Secret [ ', secretKey, ']')

client.on('torrent', (torrent) => {
  const { infoHash, files } = torrent

  console.log('Created torrent', infoHash, files.map(({ path }) => path))

  console.log('Publishing torrent')

  client.publish(publicKey, secretKey, infoHash, (err, { magnetURI, sequence }) => {
    if (err) throw err
    console.log('Published torrent', magnetURI, '- Version', sequence)


    client.resolve(publicKey, (err, res) => {
      if (err) throw err

      console.log('Resolved latest version:', res)

      republish()
    })

    function republish() {
      console.log('Republishing version to the DHT')
      client.republish(publicKey, () => {
        setTimeout(republish, 6000)
      })
    }
  })
})

console.log('Preparing to seed', __dirname)

client.seed(__dirname, {
  name: 'example'
})

API

Extends the WebTorrent API with the following:

  • add(magnetURI, callback) now takes magnet URIs using the new uri:btpk: scheme for resolving mutable torrents. It also adds a publicKey buffer to torrents loaded from a mutable magnet link.
  • resolve(publicKeyString, callback) resolves a public key to an object with the latest infoHash it's pointing to as well as the sequence number.
  • publish(publicKeyString, secretKeyString, infohash, [options], callback) publishes your latest version information on the DHT. The options can include the sequence you wish to publish at. Note that nodes in the DHT will ignore any sequences older than what they currently have. It results in an object with the infoHash, magnetURI, and sequence number for the published torrent. Check out how BEP 44 works for details.
  • republish(publicKey, callback) republishes the current version for a given public key. This doesn't require the private key since it takes whatever is currently on the DHT. This is how you seed the version data in the DHT.
  • createKeypair() returns an object with a publicKey and secretKey pair that can be used for publishing content.