How to use the is-ipfs.cid 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 ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-path.js View on Github external
function validIpnsPath (path, dnsLink) {
  if (IsIpfs.ipnsPath(path)) {
    // we may have false-positives here, so we do additional checks below
    const ipnsRoot = path.match(/^\/ipns\/([^/]+)/)[1]
    // console.log('==> IPNS root', ipnsRoot)
    // first check if root is a regular CID
    if (IsIpfs.cid(ipnsRoot)) {
      // console.log('==> IPNS is a valid CID', ipnsRoot)
      return true
    }
    // then see if there is an DNSLink entry for 'ipnsRoot' hostname
    // TODO: use dnslink cache only
    if (dnsLink.readAndCacheDnslink(ipnsRoot)) {
      // console.log('==> IPNS for FQDN with valid dnslink: ', ipnsRoot)
      return true
    }
  }
  return false
}
github ipfs / js-ipfs / src / core / runtime / dns-nodejs.js View on Github external
if (domain.startsWith('_dnslink.')) {
      // The supplied domain contains a _dnslink component
      // Check the non-_dnslink domain
      dnslinkRecord = await resolveDnslink(domain.replace('_dnslink.', ''))
    } else {
      // Check the _dnslink subdomain
      const _dnslinkDomain = `_dnslink.${domain}`
      // If this throws then we propagate the error
      dnslinkRecord = await resolveDnslink(_dnslinkDomain)
    }
  }

  const result = dnslinkRecord.replace('dnslink=', '')
  const domainOrCID = result.split('/')[2]
  const isIPFSCID = isIPFS.cid(domainOrCID)

  if (isIPFSCID || !depth) {
    return result
  }

  return recursiveResolveDnslink(domainOrCID, depth - 1)
}
github ipfs / js-ipfs / test / cli / resolve.js View on Github external
.then((out) => {
        b58Hash = out.split(' ')[1]
        expect(isIpfs.cid(b58Hash)).to.be.true()
        b64Hash = new CID(b58Hash).toV1().toBaseEncodedString('base64')
        return ipfs(`resolve /ipfs/${b58Hash} --cid-base=base64`)
      })
      .then((out) => {
github tableflip / ipld-explorer-cli / src / eval.js View on Github external
module.exports.evaluate = (ctx, cmd, cmdArgs) => {
  debug(cmd, cmdArgs)
  cmd = cmd || ''

  if (isIpfs.cid(cmd) || isIpfs.cid(cmd.split('/')[0])) {
    cmdArgs = [`/ipfs/${cmd}`]
    cmd = 'cd'
  } else if (isIpfs.path(cmd)) {
    cmdArgs = [cmd]
    cmd = 'cd'
  }

  if (!cmd) return
  if (!Commands[cmd]) throw new Error(`${cmd}: command not found`)

  return Commands[cmd](ctx, ...cmdArgs)
}
github tableflip / ipld-explorer-cli / src / lib / ipld / ipld.js View on Github external
get (path) {
    let cid

    if (CID.isCID(path)) {
      cid = path
      path = ''
    } else {
      const { cidOrFqdn, rest } = parsePath(path)

      if (!isIpfs.cid(cidOrFqdn)) {
        throw new Error(`invalid cid ${cidOrFqdn}`)
      }

      cid = new CID(cidOrFqdn)
      path = rest ? rest.slice(1) : ''
    }

    debug('get for', cid.toBaseEncodedString(), path)

    return new Promise((resolve, reject) => {
      this._ipld.get(cid, path, (err, res) => {
        if (err) return reject(err)
        resolve(res.value)
      })
    })
  }
github ipfs-shipyard / ipfs-webui / src / files / explore-form / FilesExploreForm.js View on Github external
onBrowse (evt) {
    evt.preventDefault()

    if (this.isValid) {
      let path = this.path

      if (isIPFS.cid(path)) {
        path = `/ipfs/${path}`
      }

      this.props.onBrowse(path)
      this.setState({ path: '' })
    }
  }
github PinataCloud / Pinata-SDK / src / commands / pinning / removePinFromIPFS.js View on Github external
export default function removePinFromIPFS(pinataApiKey, pinataSecretApiKey, ipfsPinHash) {
    validateApiKeys(pinataApiKey, pinataSecretApiKey);

    if (!ipfsPinHash) {
        throw new Error('ipfsPinHash value is required for removing a pin from Pinata');
    }
    if (!isIPFS.cid(ipfsPinHash)) {
        throw new Error(`${ipfsPinHash} is an invalid IPFS CID`);
    }

    const endpoint = `${baseUrl}/pinning/removePinFromIPFS`;
    const body = {
        ipfs_pin_hash: ipfsPinHash
    };

    return new Promise((resolve, reject) => {
        axios.post(
            endpoint,
            body,
            {
                withCredentials: true,
                headers: {
                    'pinata_api_key': pinataApiKey,

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