Détail du package

multiaddr

multiformats531.2kMITobsolète10.0.1

This module is deprecated, please upgrade to @multiformats/multiaddr

multiaddr implementation (binary + string representation of network addresses)

multiaddr, binary, string

readme

js-multiaddr

Dependency Status js-standard-style codecov

JavaScript implementation of multiaddr.

Lead Maintainer

Jacob Heun

Table of Contents

Background

What is multiaddr?

A standard way to represent addresses that

  • support any standard network protocol
  • are self-describing
  • have a binary packed format
  • have a nice string representation
  • encapsulate well

Install

NPM

npm i multiaddr

Browser: <script> Tag

Loading this module through a script tag will make the Multiaddr obj available in the global namespace.

<script src="https://unpkg.com/multiaddr/dist/index.min.js"></script>

Usage

// if we are coming from <= 8.x you can use the factory function 
const { multiaddr } = require('multiaddr')
const addr =  multiaddr("/ip4/127.0.0.1/udp/1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>

// or just the class directly
const { Multiaddr } = require('multiaddr')

const addr = new Multiaddr("/ip4/127.0.0.1/udp/1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>

addr.bytes
// <Uint8Array 04 7f 00 00 01 11 04 d2>

addr.toString()
// '/ip4/127.0.0.1/udp/1234'

addr.protos()
/* 
[
  {code: 4, name: 'ip4', size: 32},
  {code: 273, name: 'udp', size: 16}
]
*/

// gives you an object that is friendly with what Node.js core modules expect for addresses
addr.nodeAddress()
/*
{
  family: 4,
  port: 1234,
  address: "127.0.0.1"
}
*/

addr.encapsulate('/sctp/5678')
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>

API

https://multiformats.github.io/js-multiaddr/

Resolvers

multiaddr allows multiaddrs to be resolved when appropriate resolvers are provided. This module already has resolvers available, but you can also create your own. Resolvers should always be set in the same module that is calling multiaddr.resolve() to avoid conflicts if multiple versions of multiaddr are in your dependency tree. To provide multiaddr resolvers you can do:

const { Multiaddr } = require('multiaddr')
const resolvers = require('multiaddr/src/resolvers')

Multiaddr.resolvers.set('dnsaddr', resolvers.dnsaddrResolver)

The available resolvers are:

Name type Description
dnsaddrResolver dnsaddr dnsaddr resolution with TXT Records

A resolver receives a Multiaddr as a parameter and returns a Promise<Array<string>>.

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2016 Protocol Labs Inc.

changelog

10.0.1 (2021-08-19)

10.0.0 (2021-07-06)

chore

BREAKING CHANGES

  • uses the CID class from the new multiformats module

9.0.2 (2021-06-23)

9.0.1 (2021-04-08)

Bug Fixes

9.0.0 (2021-04-08)

Features

BREAKING CHANGES

  • entry point uses named exports
// before

const multiaddr = require('multiaddr')
multiaddr.resolvers
multiaddr.protocols

// after

const {multiaddr , Multiaddr, protocols, resolvers} = = require('multiaddr')
Multiaddr.resolvers
Multiaddr.protocols
  • Multiaddr is a normal class now
  • toOptions output changed to match node ```js // before multiaddr('/ip4/127.0.0.1/tcp/4001').toOptions() { family: 'ipv4', host: '127.0.0.1', transport: 'tcp', port: 4001 }

// after new Multiaddr('/ip4/127.0.0.1/tcp/4001').toOptions() { family: 4, host: '127.0.0.1', transport: 'tcp', port: 4001 }

- `fromNodeAddress` and `nodeAddress` inputs/outputs now match
```js
// before the family type was not the same between them
multiaddr('/ip4/127.0.0.1/tcp/4001').nodeAddress()
{family: 4, address: '127.0.0.1', port: '4001'}

multiaddr.fromNodeAddress({family: 'IPv4', address: '127.0.0.1', port: '4001'}, 'tcp')
<Multiaddr 047f000001060fa1 - /ip4/127.0.0.1/tcp/4001>

// after 
new Multiaddr('/ip4/127.0.0.1/tcp/4001').nodeAddress()
{family: 4, address: '127.0.0.1', port: 4001}

Multiaddr.fromNodeAddress({family: 4, address: '127.0.0.1', port: '4001'}, 'tcp')
<Multiaddr 047f000001060fa1 - /ip4/127.0.0.1/tcp/4001>

8.1.2 (2020-12-11)

Bug Fixes

  • tell bundlers to return false for node dns module (#163) (0ac20ba)

8.1.1 (2020-10-30)

Bug Fixes

8.1.0 (2020-10-29)

Features

8.0.0 (2020-08-07)

Bug Fixes

  • replace node buffers with uint8arrays (#140) (53398f5)

BREAKING CHANGES

    • Where node Buffers were returned, now Uint8Arrays are
  • The .buffer property has been renamed .bytes similar to cid@1.0.0

  • chore: downgrade aegir

7.5.0 (2020-06-25)

Features

  • add new memory protocol for testing and other simulation scenarios (bba22d2)

7.4.3 (2020-03-26)

7.4.2 (2020-03-18)

Bug Fixes

7.4.1 (2020-03-16)

Bug Fixes

  • use multibase, add buffer, remove ip dep (#113) (f245744)

7.4.0 (2020-02-28)

Bug Fixes

7.3.1 (2020-02-13)

Bug Fixes

7.3.0 (2020-02-06)

Features

7.2.1 (2019-11-11)

Bug Fixes

7.2.0 (2019-10-28)

Features

7.1.0 (2019-09-10)

Features

7.0.0 (2019-09-03)

Bug Fixes

  • make getPeerId resolve the last id (#95) (c32071d)
  • return ports as ints not strings (#87) (2a170c3)

6.1.0 (2019-06-05)

Features

6.0.6 (2019-03-04)

Bug Fixes

  • json round trip works as expected (#85) (1977874)

6.0.5 (2019-02-25)

Features

  • add unix protocol support and update protocol table (#84) (d4d3d9b)

6.0.4 (2019-01-25)

Features

6.0.3 (2019-01-08)

Bug Fixes

  • clean up repo and bundle size reduction (136315a)
  • increase bundle size limit (b7fc015)
  • remove unused deps (3d8cb42)
  • update max bundle size (116f227)

6.0.2 (2018-12-17)

Bug Fixes

  • make ipfs the default 421 proto name (#77) (bab6edb)

6.0.1 (2018-12-17)

Features

6.0.0 (2018-11-28)

Bug Fixes

Features

  • add support for quic addresses (9238d0d)

BREAKING CHANGES

  • The UDP code was changed in the multicodec table

The UDP code is now 273 instead of 17. For the full discussion of this change please see https://github.com/multiformats/multicodec/pull/16.

5.0.2 (2018-11-05)

5.0.1 (2018-11-05)

Features

  • add support for quic addresses (9238d0d)

5.0.0 (2018-04-24)

Features

  • Add support for multiaddr node with dns (5d6b93a)

4.0.0 (2018-04-05)

3.2.0 (2018-04-05)

Features

  • add ip validations to ip addr formats (#60) (70c138b)
  • use class-is module for type checks (b097af9)

3.1.0 (2018-03-23)

Bug Fixes

  • avoid constructor.name pattern (e386738)
  • use consistent /dnsaddr code (#59) (67fef56)

3.0.2 (2018-01-07)

Features

  • rename /dns to /dnsaddr to conform with go implementation (#50) (99a1aa4)

3.0.1 (2017-09-05)

Bug Fixes

  • Remove (s) in p2p-websockets-star (#46) (b6a613e)

3.0.0 (2017-09-03)

Features

2.3.0 (2017-03-28)

Features

  • don't throw on invalid b58 string in getPeerId (#43) (ec23f14)

2.2.3 (2017-03-27)

2.2.2 (2017-03-16)

2.2.1 (2017-02-09)

2.2.0 (2017-01-22)

2.1.3 (2017-01-16)

Features

2.1.1 (2016-11-17)

2.1.0 (2016-11-17)

2.0.3 (2016-09-07)

Features

2.0.2 (2016-05-21)

2.0.1 (2016-05-21)

2.0.0 (2016-05-17)

1.4.1 (2016-04-20)

Bug Fixes

  • handle variable sized protocols in protoCodes (1bce576)

1.4.0 (2016-04-19)

Features

  • Add support for ipfs addresses. (0f39678), closes #15

1.3.1 (2016-04-18)

1.3.0 (2016-03-12)

1.2.0 (2016-03-12)

1.1.3 (2016-03-11)

1.1.2 (2016-03-11)

1.1.1 (2015-11-06)

1.1.0 (2015-11-06)