How to use mafmt - 10 common examples

To help you get started, we’ve selected a few mafmt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs / is-ipfs / src / index.js View on Github external
function isPeerMultiaddr (input) {
  if (!isMultiaddr(input)) return false
  if (input instanceof Buffer) {
    // mafmt does not support Buffer input
    input = new Multiaddr(input)
  }
  return mafmt.IPFS.matches(input)
}
github libp2p / js-libp2p / src / circuit / listener.js View on Github external
addrs.forEach((addr) => {
      const peerMa = `/p2p-circuit/ipfs/${swarm._peerInfo.id.toB58String()}`
      if (addr.toString() === peerMa) {
        listenAddrs.push(multiaddr(peerMa))
        return
      }

      if (!mafmt.Circuit.matches(addr)) {
        if (addr.getPeerId()) {
          // by default we're reachable over any relay
          listenAddrs.push(multiaddr('/p2p-circuit').encapsulate(addr))
        } else {
          const ma = `${addr}/ipfs/${swarm._peerInfo.id.toB58String()}`
          listenAddrs.push(multiaddr('/p2p-circuit').encapsulate(ma))
        }
      } else {
        listenAddrs.push(addr.encapsulate(`/ipfs/${swarm._peerInfo.id.toB58String()}`))
      }
    })
github libp2p / js-libp2p-bootstrap / test / bootstrap.spec.js View on Github external
r.once('peer', (peer) => {
        const peerList = peer.multiaddrs.toArray()
        expect(peerList.length).to.eq(1)
        expect(mafmt.IPFS.matches(peerList[0].toString())).equals(true)
        resolve()
      })
    })
github libp2p / js-libp2p-bootstrap / src / index.js View on Github external
this._list.forEach(async (candidate) => {
      if (!mafmt.P2P.matches(candidate)) {
        return log.error('Invalid multiaddr')
      }

      const ma = multiaddr(candidate)

      const peerId = PeerId.createFromB58String(ma.getPeerId())

      try {
        const peerInfo = await PeerInfo.create(peerId)
        peerInfo.multiaddrs.add(ma)
        this.emit('peer', peerInfo)
      } catch (err) {
        log.error('Invalid bootstrap peer id', err)
      }
    })
  }
github ipfs / js-ipfs / src / cli / commands / swarm / peers.js View on Github external
result.forEach((item) => {
        let ma = multiaddr(item.addr.toString())
        if (!mafmt.IPFS.matches(ma)) {
          ma = ma.encapsulate('/ipfs/' + item.peer.toB58String())
        }
        const addr = ma.toString()
        argv.print(addr)
      })
    })())
github ipfs / js-ipfs / src / core / components / bootstrap.js View on Github external
'use strict'

const defaultConfig = require('../runtime/config-nodejs.js')
const isMultiaddr = require('mafmt').IPFS.matches
const callbackify = require('callbackify')

function isValidMultiaddr (ma) {
  try {
    return isMultiaddr(ma)
  } catch (err) {
    return false
  }
}

function invalidMultiaddrError (ma) {
  return new Error(`${ma} is not a valid Multiaddr`)
}

module.exports = function bootstrap (self) {
  return {
github ipfs / js-ipfs / src / core / config.js View on Github external
    'multiaddr-ipfs': v => mafmt.IPFS.matches(v) ? true : 'multiaddr IPFS invalid'
  }
github libp2p / js-libp2p / src / circuit / index.js View on Github external
return multiaddrs.filter((ma) => {
      return mafmt.Circuit.matches(ma)
    })
  }
github libp2p / js-libp2p / src / circuit / listener.js View on Github external
const p2pAddrs = addrs.filter((addr) => {
      return mafmt.Circuit.matches(addr) &&
        !addr.toString().includes(swarm._peerInfo.id.toB58String())
    })
github libp2p / js-libp2p-webrtc-star / src / webrtc-star / index.js View on Github external
return multiaddrs.filter((ma) => {
      return mafmt.WebRTCStar.matches(ma)
    })
  }

mafmt

A multiaddr validator

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis