Socket
Socket
Sign inDemoInstall

multiaddr

Package Overview
Dependencies
Maintainers
2
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiaddr

multiaddr implementation (binary + string representation of network addresses)


Version published
Weekly downloads
71K
decreased by-15.72%
Maintainers
2
Weekly downloads
 
Created
Source

js-multiaddr

[ Build Status](https://travis-ci.org/diasdavid/js-multiaddr) Dependency Status js-standard-style

multiaddr implementation in JavaScript.

Usage

In Node.js through npm

$ npm install --save multiaddr
var multiaddr = require('multiaddr')

In the Browser through browserify

Same as in Node.js, you just have to browserify the code before serving it. See the browserify repo for how to do that.

In the Browser through <script> tag

Make the multiaddr.min.js available through your server and load it using a normal <script> tag, this will export the multiaddr on the window object, such that:

var multiaddr = window.multiaddr
Gotchas

You will need to use Node.js Buffer API compatible, if you are running inside the browser, you can access it by multiaddr.Buffer or you can install Feross's Buffer.

Example

Simple

var multiaddr = require('multiaddr')
var addr = multiaddr("/ip4/127.0.0.1/udp/1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>
addr.buffer
// <Buffer >
addr.toString()
// /ip4/127.0.0.1/udp/1234

// construct with Buffer
addr = multiaddr(addr.buffer)
// <Multiaddr /ip4/127.0.0.1/udp/1234>

Protocols

// get the multiaddr protocol codes
addr.protoCodes()
// [4, 6]

// get the multiaddr protocol string codes
addr.protoNames()
// ['ip4', 'tcp']

// get the multiaddr protocol description objects
addr.protos()
// [{code: 4, name: 'ip4', size: 32},
//  {code: 17, name: 'udp', size: 16}]

Other formats

// get a node friendly address object
addr.nodeAddress()
// {family: "IPv4", port:1234, address: "127.0.0.1"} - note no UDP :(
addr.fromNodeAddress({family: "IPv4", port:1234, address: "127.0.0.1"}, 'udp')
// /ip4/127.0.0.1/udp/1234

// handles the stupid string version too
addr = multiaddr.fromStupidString("udp4://127.0.0.1:1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>
addr.toStupidString(buf)
// udp4://127.0.0.1:1234

En/decapsulate

addr.encapsulate('/sctp/5678')
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
addr.decapsulate('/udp') // up to + inc last occurrence of this subaddr
// <Multiaddr /ip4/127.0.0.1>

Tunneling

Multiaddr allows expressing tunnels very nicely.

var printer = multiaddr('/ip4/192.168.0.13/tcp/80')
var proxy = multiaddr('/ip4/10.20.30.40/tcp/443')
var printerOverProxy = proxy.encapsulate(printer)
// <Multiaddr /ip4/10.20.30.40/tcp/443/ip4/192.168.0.13/tcp/80>

var proxyAgain = printerOverProxy.decapsulate('/ip4')
// <Multiaddr /ip4/10.20.30.40/tcp/443>

Keywords

FAQs

Package last updated on 06 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc