How to use the is-ipfs.multihash function in is-ipfs

To help you get started, we’ve selected a few is-ipfs 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 cakenggt / ipfs-foundation-frontend / app / components / add-file-view.jsx View on Github external
handleAddClick: function () {
		// First check in db to see if name and hash are unique
		var file = {};
		file.name = this.state.name;
		file.description = this.state.description;
		file._id = this.state.hash;
		file.type = FILE;
		file.category = this.state.category;
		console.log(file);
		if (!file.name || !file.description) {
			this.setState({
				message: 'Files must have a name and a description'
			});
			return;
		}
		if (!multihash(file._id)) {
			this.setState({
				message: 'Not a valid multihash'
			});
			return;
		}
		searchNameOrHash(file.name, file._id)
		.then(result => {
			console.log('search result', result.length > 0);
			if (result.length === 0) {
				this.props.postFile(file, this.props.router);
			} else {
				this.setState({
					message: 'A file with this name or hash already exists on the server'
				});
			}
		});
github MichaelMure / Arbore / app / actions / shareList.js View on Github external
async function handleSharePush(dispatch, getState, payload) {
  const { from, hash } = payload

  const state: Store = getState()
  const contactList: ContactList = state.contactList
  const contact = contactList.findContactInDirectory(from)

  if(!contact) {
    console.log('Got a share notification from unknow contact ' + from)
    return
  }

  if(!isIpfs.multihash(hash)) {
    throw 'invalid hash'
  }

  // Send ACK
  const profile = getState().profile
  const data = protocol.shareAck(profile, hash)
  dispatch(pubsub.send(contact.sharesPubsubTopic, data))


  const shareList: ShareList = state.shareList
  const storedShare: ?Share = shareList.findByHash(hash)

  if(storedShare) {
    console.log('Got a share notification that we already knew: ' + storedShare.title)
    return
  }
github ipld / js-ipld / src / old-resolve.js View on Github external
function access (parts, obj, cb) {
    const isRoot = obj === null && (isIPFS.multihash(parts[0]) || isIPFS.ipfsPath('/' + parts.join('/')))
    const next = parts.shift()
    const isLink = obj && Object.keys(obj).length === 1 && obj[LINK_SYMBOL]
    const fetchLink = obj && (next ? !includes(Object.keys(obj), next) : true)

    if (!obj && !isRoot) {
      cb(new Error('No root object provided'))
    } else if (isLink && fetchLink) {
      // resolve links in objects with an / property
      const link = obj[LINK_SYMBOL]
      const linkParts = splitLink(link)
      let blockLink = ''

      if (linkParts[0] === 'ipfs') {
        // /ipfs/
        blockLink = linkParts[1]
        parts = linkParts.slice(2).concat(parts)
github ipld / js-ipld / src / old-resolve.js View on Github external
const isLink = obj && Object.keys(obj).length === 1 && obj[LINK_SYMBOL]
    const fetchLink = obj && (next ? !includes(Object.keys(obj), next) : true)

    if (!obj && !isRoot) {
      cb(new Error('No root object provided'))
    } else if (isLink && fetchLink) {
      // resolve links in objects with an / property
      const link = obj[LINK_SYMBOL]
      const linkParts = splitLink(link)
      let blockLink = ''

      if (linkParts[0] === 'ipfs') {
        // /ipfs/
        blockLink = linkParts[1]
        parts = linkParts.slice(2).concat(parts)
      } else if (isIPFS.multihash(linkParts[0])) {
        // /
        blockLink = linkParts[0]

        parts = linkParts.slice(1).concat(parts)
      } else {
        return cb(new Error(`Invalid link: "${link}"`))
      }

      service.get(blockLink, (err, block) => {
        if (err) {
          return cb(err)
        }
        if (next) {
          // Put back so it's resolved in the next node
          parts.unshift(next)
        }
github MichaelMure / Arbore / app / actions / contactResolver.js View on Github external
async function handleLookup(dispatch, getState, payload) {
  const { from, pubkey } = payload

  if(!isIpfs.multihash(from)) {
    return
  }

  if(!isIpfs.multihash(pubkey)) {
    return
  }

  console.log('Got a contact lookup query from ' + from + ' for ' + pubkey)

  const state: Store = getState()
  const profile = state.profile
  const contactList = state.contactList

  let reply = null

  const contact = contactList.findContactInPool(pubkey)
  if(contact) {
    reply = contact.publishObject()
  }
github ipfs / js-ipfs-http-client / src / utils / clean-multihash.js View on Github external
module.exports = function (multihash) {
  if (Buffer.isBuffer(multihash)) {
    multihash = bs58.encode(multihash)
  }
  if (CID.isCID(multihash)) {
    multihash = multihash.toBaseEncodedString()
  }
  if (typeof multihash !== 'string') {
    throw new Error('unexpected multihash type: ' + typeof multihash)
  }
  if (!isIPFS.multihash(multihash.split('/')[0])) {
    throw new Error('not valid multihash')
  }
  return multihash
}
github MichaelMure / Arbore / app / actions / contactResolver.js View on Github external
async function handleLookup(dispatch, getState, payload) {
  const { from, pubkey } = payload

  if(!isIpfs.multihash(from)) {
    return
  }

  if(!isIpfs.multihash(pubkey)) {
    return
  }

  console.log('Got a contact lookup query from ' + from + ' for ' + pubkey)

  const state: Store = getState()
  const profile = state.profile
  const contactList = state.contactList

  let reply = null

  const contact = contactList.findContactInPool(pubkey)
github MichaelMure / Arbore / app / models / IpfsDirectory.js View on Github external
static create(hash: string) {
    if(!isIpfs.multihash(hash)) {
      throw 'invalid hash'
    }

    return new this()
      .set(writable.hash, hash)
  }
github ipld / js-ipld / src / ipld-service.js View on Github external
function normalizeKey (key) {
  let res
  const isMhash = isIPFS.multihash(key)
  const isPath = isIPFS.path(key)

  if (!isMhash && !isPath) {
    return null
  }

  if (isMhash) {
    res = key
  } else if (isPath) {
    res = key.replace('/ipfs/', '')
  }

  if (typeof res === 'string') {
    return mh.fromB58String(res)
  }
github MichaelMure / Arbore / app / actions / shareList.js View on Github external
await Promise.all(shares.map(async (hash: string) => {
    if(!isIpfs.multihash(hash)) {
      throw 'invalid hash'
    }

    await handleNewShare(dispatch, contact, hash)
  }))

is-ipfs

A set of utilities to help identify IPFS resources on the web

Apache-2.0 OR MIT
Latest version published 3 months ago

Package Health Score

81 / 100
Full package analysis