Skip to content

Commit

Permalink
refactor: remove multibase check
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Jul 23, 2018
1 parent 17f9292 commit 8e05326
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 80 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ const isIPFS = require('is-ipfs')
isIPFS.multihash('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true
isIPFS.multihash('noop') // false

isIPFS.multibase('bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va') // 'base32'
isIPFS.multibase('zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7') // 'base58btc'
isIPFS.multibase('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // false (no multibase prefix in CIDv0)
isIPFS.multibase('noop') // false

isIPFS.cid('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true (CIDv0)
isIPFS.cid('zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7') // true (CIDv1)
isIPFS.cid('noop') // false
Expand Down Expand Up @@ -83,6 +78,7 @@ isIPFS.ipfsPath('/ipfs/invalid-hash') // false
isIPFS.ipnsPath('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // false
isIPFS.ipnsPath('/ipns/github.com') // true

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
Expand Down Expand Up @@ -111,10 +107,6 @@ Detection of IPFS Paths and identifiers in URLs is a two-stage process:

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

### `isIPFS.multibase(cid)`

Returns a string with multibase name if the provided CID has `multibase` prefix or `false` otherwise.

### `isIPFS.cid(hash)`

Returns `true` if the provided string is a valid `CID` or `false` otherwise.
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"dependencies": {
"bs58": "4.0.1",
"cids": "0.5.3",
"multibase": "0.4.0",
"multihashes": "0.4.13"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ function convertToString (input) {

module.exports = {
multihash: isMultihash,
multibase: isMultibase,
cid: isCID,
base32cid: (cid) => (isMultibase(cid) === 'base32' && isCID(cid)),
ipfsSubdomain: (url) => isIpfs(url, fqdnPattern, fqdnProtocolMatch, fqdnHashMatch),
Expand Down
38 changes: 38 additions & 0 deletions test/test-cid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,41 @@ describe('ipfs cid', () => {
done()
})
})

describe('ipfs base32cid', () => {
it('isIPFS.base32cid should not match a valid CIDv0 (multihash in base58btc)', (done) => {
const actual = isIPFS.base32cid('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
expect(actual).to.equal(false)
done()
})

it('isIPFS.base32cid should not match a valid CIDv1 in base58btc', (done) => {
const actual = isIPFS.cid('zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7')
expect(actual).to.equal(true)
done()
})

it('isIPFS.base32cid should match a valid URL-safe CIDv1 in Base32', (done) => {
const actual = isIPFS.base32cid('bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va')
expect(actual).to.equal(true)
done()
})

it('isIPFS.base32cid should not match an invalid CID (with a typo)', (done) => {
const actual = isIPFS.base32cid('afybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va')
expect(actual).to.equal(false)
done()
})

it('isIPFS.base32cid should not match an invalid CID', (done) => {
const actual = isIPFS.base32cid('noop')
expect(actual).to.equal(false)
done()
})

it('isIPFS.base32cid should not match an invalid CID data type', (done) => {
const actual = isIPFS.base32cid(4)
expect(actual).to.equal(false)
done()
})
})
69 changes: 0 additions & 69 deletions test/test-multibase.spec.js

This file was deleted.

0 comments on commit 8e05326

Please sign in to comment.