All Projects → ipfs-shipyard → is-ipfs

ipfs-shipyard / is-ipfs

Licence: Unknown and 2 other licenses found Licenses found Unknown LICENSE Unknown LICENSE-APACHE MIT LICENSE-MIT
A set of utilities to help identify IPFS resources on the web

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to is-ipfs

sailplane-web
Collaborative p2p file sharing in the browser
Stars: ✭ 71 (-28.28%)
Mutual labels:  ipfs
estuary-www
https://estuary.tech
Stars: ✭ 32 (-67.68%)
Mutual labels:  ipfs
peer-id-generator
Vanity public key generator for use with IPFS and IPNS
Stars: ✭ 27 (-72.73%)
Mutual labels:  ipfs
ipfs-pubsub-chatroom
Simple IPFS Pubsub chatroom built on React
Stars: ✭ 45 (-54.55%)
Mutual labels:  ipfs
townhall
Deprecated: An early version of the Menlo framework
Stars: ✭ 21 (-78.79%)
Mutual labels:  ipfs
go-libp2p-http
HTTP on top of libp2p
Stars: ✭ 49 (-50.51%)
Mutual labels:  ipfs
ipgit
Inter Planetary Git
Stars: ✭ 62 (-37.37%)
Mutual labels:  ipfs
react-native-boilerplate
[DEPRECATED] A boilerplate app that shows creating, starting, and managing an IPFS peer using Textile's React Native SDK
Stars: ✭ 20 (-79.8%)
Mutual labels:  ipfs
dapps.earth
Source code for dapps.earth: IPFS and Swarm gateway
Stars: ✭ 12 (-87.88%)
Mutual labels:  ipfs
rust-ipfs-api
Rust language IPFS API implementation
Stars: ✭ 20 (-79.8%)
Mutual labels:  ipfs
django-ipfs-storage
IPFS storage backend for Django.
Stars: ✭ 26 (-73.74%)
Mutual labels:  ipfs
eth-plot
r/place inspired Dapp
Stars: ✭ 36 (-63.64%)
Mutual labels:  ipfs
gilfoyle
Distributed video encoding, hosting and streaming (WIP)
Stars: ✭ 73 (-26.26%)
Mutual labels:  ipfs
IPFS-Ethereum-Image
【IPFS + 区块链 系列】 入门篇 - IPFS + Ethereum (下篇)-ipfs + Ethereum 大图片存储
Stars: ✭ 57 (-42.42%)
Mutual labels:  ipfs
research
Shared learning of decentralized development.
Stars: ✭ 26 (-73.74%)
Mutual labels:  ipfs
nft-market-service
NFT Market service to mint tokens on IPFS
Stars: ✭ 76 (-23.23%)
Mutual labels:  ipfs
edgevpn
⛵ The immutable, decentralized, statically built p2p VPN without any central server and automatic discovery! Create decentralized introspectable tunnels over p2p with shared tokens
Stars: ✭ 223 (+125.25%)
Mutual labels:  ipfs
web3.storage
⁂ The simple file storage service for IPFS & Filecoin
Stars: ✭ 417 (+321.21%)
Mutual labels:  ipfs
creaton
Decentralized content sharing platform.
Stars: ✭ 38 (-61.62%)
Mutual labels:  ipfs
whitepaper
The Fission Technical Whitepaper
Stars: ✭ 15 (-84.85%)
Mutual labels:  ipfs

is-ipfs

codecov CI

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

Table of contents

Install

$ npm i is-ipfs

Usage

import * as isIPFS from 'is-ipfs'

isIPFS.multihash('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true
isIPFS.multihash('noop') // false

isIPFS.cid('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true (CIDv0)
isIPFS.cid('bafybeiasb5vpmaounyilfuxbd3lryvosl4yefqrfahsb2esg46q6tu6y5q') // true (CIDv1 in Base32)
isIPFS.cid('zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7') // true (CIDv1 in Base58btc)
isIPFS.cid('noop') // false

isIPFS.base32cid('bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va') // true
isIPFS.base32cid('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // false

isIPFS.url('https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true
isIPFS.url('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?filename=guardian.jpg') // true
isIPFS.url('https://ipfs.io/ipns/github.com') // true
isIPFS.url('https://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link') // true
isIPFS.url('http://en.wikipedia-on-ipfs.org.ipfs.localhost:8080') // true
isIPFS.url('https://github.com/ipfs/js-ipfs/blob/master/README.md') // false
isIPFS.url('https://google.com') // false

isIPFS.path('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true
isIPFS.path('/ipfs/QmbcBPAwCDxRMB1Qe7CRQmxdrTSkxKwM9y6rZw2FjGtbsb/?weird-filename=test.jpg') // true
isIPFS.path('/ipns/github.com') // true
isIPFS.path('/ipfs/js-ipfs/blob/master/README.md') // false

isIPFS.urlOrPath('https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true
isIPFS.urlOrPath('https://ipfs.io/ipns/github.com') // true
isIPFS.urlOrPath('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true
isIPFS.urlOrPath('/ipns/github.com') // true
isIPFS.urlOrPath('https://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link') // true
isIPFS.urlOrPath('https://google.com') // false

isIPFS.ipfsUrl('https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true
isIPFS.ipfsUrl('https://ipfs.io/ipfs/invalid-hash') // false

isIPFS.ipnsUrl('https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // false
isIPFS.ipnsUrl('https://ipfs.io/ipns/github.com') // true

isIPFS.ipfsPath('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true
isIPFS.ipfsPath('/ipfs/invalid-hash') // false

isIPFS.ipnsPath('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // false
isIPFS.ipnsPath('/ipns/github.com') // true

isIPFS.cidPath('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o/path/to/file') // true
isIPFS.cidPath('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o/') // true
isIPFS.cidPath('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // false
isIPFS.cidPath('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // false
isIPFS.cidPath('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o/file') // false

isIPFS.subdomain('http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link') // true
isIPFS.subdomain('http://bafybeiabc2xofh6tdi6vutusorpumwcikw3hf3st4ecjugo6j52f6xwc6q.ipns.dweb.link') // true
isIPFS.subdomain('http://www.bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link') // false
isIPFS.subdomain('http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.dweb.link') // false

isIPFS.ipfsSubdomain('http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link') // true
isIPFS.ipfsSubdomain('http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.dweb.link') // false

isIPFS.ipnsSubdomain('http://bafybeiabc2xofh6tdi6vutusorpumwcikw3hf3st4ecjugo6j52f6xwc6q.ipns.dweb.link') // true
isIPFS.ipnsSubdomain('http://bafybeiabc2xofh6tdi6vutusorpumwcikw3hf3st4ecjugo6j52f6xwc6q.dweb.link') // false
isIPFS.ipnsSubdomain('http://QmcNioXSC1bfJj1dcFErhUfyjFzoX2HodkRccsFFVJJvg8.ipns.dweb.link') // false
isIPFS.ipnsSubdomain('http://en.wikipedia-on-ipfs.org.ipns.localhost:8080') // true (assuming DNSLink)
isIPFS.ipnsSubdomain('http://en-wikipedia--on--ipfs-org.ipns.localhost:8080') // true (assuming inlined DNSLink)
isIPFS.ipnsSubdomain('http://hostname-without-tld-.ipns.dweb.link') // false (not a CID, invalid DNS label)

isIPFS.multiaddr('/ip4/127.0.0.1/udp/1234') // true
isIPFS.multiaddr('/ip4/127.0.0.1/udp/1234/http') // true
isIPFS.multiaddr('/ip6/::1/udp/1234') // true
isIPFS.multiaddr('ip6/::1/udp/1234') // false
isIPFS.multiaddr('/yoloinvalid/::1/udp/1234') // false

isIPFS.peerMultiaddr('/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4') // true
isIPFS.peerMultiaddr('/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4') // true (legacy notation)
isIPFS.peerMultiaddr('/ip4/127.0.0.1/tcp/1234/ws/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj') // true
isIPFS.peerMultiaddr('/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj') // true
isIPFS.peerMultiaddr('/dnsaddr/bootstrap.libp2p.io') // false (key missing, needs additional DNS lookup to tell if this is valid)
isIPFS.peerMultiaddr('/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN') // true (key present, ip and port can be resolved later)
isIPFS.peerMultiaddr('/ip4/127.0.0.1/udp/1234') // false (key missing)

API

A suite of util methods that provides efficient validation.

Detection of IPFS Paths and identifiers in URLs is a two-stage process:

  1. pathPattern/pathGatewayPattern/subdomainGatewayPattern regex is applied to quickly identify potential candidates
  2. proper CID validation is applied to remove false-positives

Content Identifiers

isIPFS.multihash(hash)

Returns true if the provided string or Uint8Array is a valid multihash or false otherwise.

isIPFS.cid(hash)

Returns true if the provided string, Uint8Array or CID object represents a valid CID or false otherwise.

isIPFS.base32cid(hash)

Returns true if the provided string is a valid CID in Base32 encoding or false otherwise.

URLs

isIPFS.url(url)

Returns true if the provided string is a valid IPFS or IPNS url or false otherwise.

isIPFS.ipfsUrl(url)

Returns true if the provided string is a valid IPFS url or false otherwise.

isIPFS.ipnsUrl(url)

Returns true if the provided string is a valid IPNS url or false otherwise.

Paths

Standalone validation of IPFS Paths: /ip(f|n)s/<cid>/..

isIPFS.path(path)

Returns true if the provided string is a valid IPFS or IPNS path or false otherwise.

isIPFS.urlOrPath(path)

Returns true if the provided string is a valid IPFS or IPNS url or path or false otherwise.

isIPFS.ipfsPath(path)

Returns true if the provided string is a valid IPFS path or false otherwise.

isIPFS.ipnsPath(path)

Returns true if the provided string is a valid IPNS path or false otherwise.

isIPFS.cidPath(path)

Returns true if the provided string is a valid "CID path" (IPFS path without /ipfs/ prefix) or false otherwise.

Subdomains

Validated subdomain convention: cidv1b32.ip(f|n)s.domain.tld

isIPFS.subdomain(url)

Returns true if the provided url string includes a valid IPFS, looks like IPNS/DNSLink subdomain or false otherwise.

isIPFS.ipfsSubdomain(url)

Returns true if the provided url string includes a valid IPFS subdomain (case-insensitive CIDv1) or false otherwise.

isIPFS.ipnsSubdomain(url)

Returns true if the provided url string looks like a valid IPNS subdomain (CIDv1 with libp2p-key multicodec or something that looks like a FQDN, for example en.wikipedia-on-ipfs.org.ipns.localhost:8080) or false otherwise.

Note: ipnsSubdomain method works in offline mode: it does not perform actual IPNS record lookup over DHT or other content routing method. It may return false-positives:

  • To ensure IPNS record exists, make a call to /api/v0/name/resolve?arg=<ipnsid>
  • To ensure DNSLink exists, make a call to /api/v0/dns?arg=<fqdn>

Multiaddrs

Below methods provide basic detection of multiaddrs: composable and future-proof network addresses.

Complex validation of multiaddr can be built using isIPFS.multiaddr and mafmt library.

isIPFS.multiaddr(addr)

Returns true if the provided string, Multiaddr or Uint8Array represents a valid multiaddr or false otherwise.

isIPFS.peerMultiaddr(addr)

Returns true if the provided string, Multiaddr or Uint8Array represents a valid libp2p peer multiaddr (matching P2P format from mafmt) or false otherwise.

License

Licensed under either of

Contribute

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].