Comparing version 5.0.0 to 6.0.0
@@ -0,1 +1,17 @@ | ||
# [6.0.0](https://github.com/ipfs/is-ipfs/compare/v5.0.0...v6.0.0) (2021-07-07) | ||
### chore | ||
* update to new multiformats ([#42](https://github.com/ipfs/is-ipfs/issues/42)) ([22bf9b7](https://github.com/ipfs/is-ipfs/commit/22bf9b7c88b6a9d6d9141f8565552557d9109ee8)) | ||
### BREAKING CHANGES | ||
* uses the CID class from the new multiformats module | ||
Co-authored-by: Marcin Rataj <lidel@lidel.org> | ||
# [5.0.0](https://github.com/ipfs/is-ipfs/compare/v4.0.0...v5.0.0) (2021-04-19) | ||
@@ -2,0 +18,0 @@ |
@@ -17,3 +17,3 @@ /** | ||
declare function isCID(hash: any): boolean; | ||
import CID = require("cids"); | ||
import { CID } from "multiformats/cid"; | ||
/** | ||
@@ -20,0 +20,0 @@ * @param {string | Uint8Array} url |
{ | ||
"name": "is-ipfs", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "A set of utilities to help identify IPFS resources on the web", | ||
@@ -44,8 +44,6 @@ "keywords": [ | ||
"dependencies": { | ||
"cids": "^1.1.6", | ||
"iso-url": "^1.1.3", | ||
"mafmt": "^9.0.0", | ||
"multiaddr": "^9.0.1", | ||
"multibase": "^4.0.2", | ||
"multihashes": "^4.0.2", | ||
"multiaddr": "^10.0.0", | ||
"multiformats": "^9.0.0", | ||
"uint8arrays": "^2.1.3" | ||
@@ -70,7 +68,7 @@ }, | ||
"Alan Shaw <alan.shaw@protocol.ai>", | ||
"Alex Potsides <alex@achingbrain.net>", | ||
"nginnever <ginneversource@gmail.com>", | ||
"Alex Potsides <alex@achingbrain.net>", | ||
"Hugo Dias <mail@hugodias.me>", | ||
"Henrique Dias <hacdias@gmail.com>" | ||
"Henrique Dias <hacdias@gmail.com>", | ||
"Hugo Dias <mail@hugodias.me>" | ||
] | ||
} |
'use strict' | ||
const multihash = require('multihashes') | ||
const multibase = require('multibase') | ||
const { base58btc } = require('multiformats/bases/base58') | ||
const { base32 } = require('multiformats/bases/base32') | ||
const Digest = require('multiformats/hashes/digest') | ||
const { Multiaddr } = require('multiaddr') | ||
const mafmt = require('mafmt') | ||
const CID = require('cids') | ||
const { CID } = require('multiformats/cid') | ||
const { URL } = require('iso-url') | ||
@@ -30,7 +31,8 @@ const uint8ArrayToString = require('uint8arrays/to-string') | ||
try { | ||
multihash.decode(multibase.decode('z' + formatted)) | ||
return true | ||
} catch (e) { | ||
Digest.decode(base58btc.decode('z' + formatted)) | ||
} catch { | ||
return false | ||
} | ||
return true | ||
} | ||
@@ -41,8 +43,10 @@ | ||
*/ | ||
function isMultibase (hash) { | ||
function isBase32EncodedMultibase (hash) { | ||
try { | ||
return multibase.isEncoded(hash) | ||
} catch (e) { | ||
base32.decode(hash) | ||
} catch { | ||
return false | ||
} | ||
return true | ||
} | ||
@@ -55,4 +59,11 @@ | ||
try { | ||
new CID(hash) // eslint-disable-line no-new | ||
return true | ||
if (typeof hash === 'string') { | ||
return Boolean(CID.parse(hash)) | ||
} | ||
if (hash instanceof Uint8Array) { | ||
return Boolean(CID.decode(hash)) | ||
} | ||
return Boolean(CID.asCID(hash)) // eslint-disable-line no-new | ||
} catch (e) { | ||
@@ -228,3 +239,3 @@ return false | ||
*/ | ||
base32cid: (cid) => (isMultibase(cid) === 'base32' && isCID(cid)), | ||
base32cid: (cid) => (isBase32EncodedMultibase(cid) && isCID(cid)), | ||
ipfsSubdomain, | ||
@@ -231,0 +242,0 @@ ipnsSubdomain, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
104044
5
8
587
0
+ Addedmultiformats@^9.0.0
+ Addedmultiaddr@10.0.1(transitive)
- Removedcids@^1.1.6
- Removedmultibase@^4.0.2
- Removedmultihashes@^4.0.2
Updatedmultiaddr@^10.0.0