Socket
Socket
Sign inDemoInstall

cids

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cids - npm Package Compare versions

Comparing version 0.5.3 to 0.5.4

18

CHANGELOG.md

@@ -0,1 +1,19 @@

<a name="0.5.4"></a>
## [0.5.4](https://github.com/ipld/js-cid/compare/v0.5.3...v0.5.4) (2018-09-24)
### Bug Fixes
* linter errors ([9f9359d](https://github.com/ipld/js-cid/commit/9f9359d))
* migrate to class-is for instance comparise, fixes [#53](https://github.com/ipld/js-cid/issues/53) ([6b6873b](https://github.com/ipld/js-cid/commit/6b6873b))
* remove direct access to codec lookup table ([4027108](https://github.com/ipld/js-cid/commit/4027108))
* use org/repo convention ([5805660](https://github.com/ipld/js-cid/commit/5805660))
### Features
* add toString function ([f47e68c](https://github.com/ipld/js-cid/commit/f47e68c))
<a name="0.5.3"></a>

@@ -2,0 +20,0 @@ ## [0.5.3](https://github.com/ipld/js-cid/compare/v0.5.2...v0.5.3) (2018-03-12)

21

package.json
{
"name": "cids",
"version": "0.5.3",
"version": "0.5.4",
"description": "CID Implementation in JavaScript",
"leadMaintainer": "Volker Mische <volker.mische@gmail.com>",
"main": "src/index.js",

@@ -19,3 +20,3 @@ "scripts": {

},
"pre-commit": [
"pre-push": [
"lint",

@@ -33,3 +34,2 @@ "test"

],
"author": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"license": "MIT",

@@ -40,12 +40,13 @@ "bugs": {

"dependencies": {
"multibase": "~0.4.0",
"multicodec": "~0.2.6",
"multihashes": "~0.4.13"
"class-is": "^1.1.0",
"multibase": "~0.5.0",
"multicodec": "~0.2.7",
"multihashes": "~0.4.14"
},
"devDependencies": {
"aegir": "^13.0.6",
"aegir": "^15.2.0",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"multihashing": "^0.3.2",
"multihashing-async": "^0.4.8",
"multihashing": "~0.3.2",
"multihashing-async": "~0.5.1",
"pre-commit": "^1.2.2"

@@ -58,5 +59,7 @@ },

"contributors": [
"Alan Shaw <alan@tableflip.io>",
"David Dias <daviddias.p@gmail.com>",
"Enrico Marino <enrico.marino@email.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Mikeal Rogers <mikeal.rogers@gmail.com>",
"Mitar <mitar.github@tnode.com>",

@@ -63,0 +66,0 @@ "Real Harry <sidewaybot@gmail.com>",

# js-cid
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-cid/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-cid?branch=master)
[![Travis CI](https://travis-ci.org/ipld/js-cid.svg?branch=master)](https://travis-ci.org/ipld/js-cid)
[![Circle CI](https://circleci.com/gh/ipld/js-cid.svg?style=svg)](https://circleci.com/gh/ipld/js-cid)
[![Dependency Status](https://david-dm.org/ipld/js-cid.svg?style=flat-square)](https://david-dm.org/ipld/js-cid)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
> [CID](https://github.com/ipld/cid) implementation in JavaScript.
## Lead Maintainer
[Volker Mische](https://github.com/vmx)
## Table of Contents
- [Install](#install)
- [In Node.js through npm](#in-nodejs-through-npm)
- [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
- [In the Browser through `<script>` tag](#in-the-browser-through-script-tag)
- [Gotchas](#gotchas)
- [Usage](#usage)

@@ -59,9 +55,14 @@ - [API](#api)

Basic usage is quite simple.
```js
const CID = require('cids')
// V1 CID
const cid = new CID(1, 'dag-pb', multihash)
```
// V0 CID
If you have a base encoded string for a multihash you can also create
an instance from the encoded string.
```js
const cid = new CID(base58Multihash)

@@ -72,4 +73,71 @@ ```

See https://ipld.github.io/js-cid
### CID.isCid(cid)
Returns true if object is a valid CID instance, false if not valid.
It's important to use this method rather than `instanceof` checks in
order to handle CID objects from different versions of this module.
### CID.validateCID(cid)
Validates the different components (version, codec, multihash) of the CID
instance. Returns true if valid, false if not valid.
### new CID(version, codec, multihash)
`version` must be either 0 or 1.
`codec` must be a string of a valid [registered codec](https://github.com/multiformats/multicodec/blob/master/table.csv).
`multihash` must be a `Buffer` instance of a valid [multihash](https://github.com/multiformats/multihash).
### new CID(baseEncodedString)
Additionally, you can instantiate an instance from a base encoded
string.
### new CID(Buffer)
Additionally, you can instantiate an instance from a buffer.
#### cid.codec
Property containing the codec string.
#### cid.version
Property containing the CID version integer.
#### cid.multihash
Property containing the multihash buffer.
#### cid.buffer
Property containing the full CID encoded as a `Buffer`.
#### cid.prefix
Proprety containing a buffer of the CID version, codec, and the prefix
section of the multihash.
#### cid.toV0()
Returns the CID encoded in version 0. Only works for `dag-pb` codecs.
Throws if codec is not `dag-pb`.
#### cid.toV1()
Returns the CID encoded in version 1.
#### cid.toBaseEncodedString(base='base58btc')
Returns a base encodec string of the CID. Defaults to `base58btc`.
#### cid.equals(cid)
Compare cid instance. Returns true if CID's are identical, false if
otherwise.
## Contribute

@@ -76,0 +144,0 @@

@@ -7,5 +7,5 @@ 'use strict'

const codecs = require('multicodec/src/base-table')
const codecVarints = require('multicodec/src/varint-table')
const multihash = require('multihashes')
const CIDUtil = require('./cid-util')
const withIs = require('class-is')

@@ -58,3 +58,3 @@ /**

constructor (version, codec, multihash) {
if (CID.isCID(version)) {
if (module.exports.isCID(version)) {
let cid = version

@@ -125,3 +125,3 @@ this.version = cid.version

Buffer.from('01', 'hex'),
Buffer.from(codecVarints[this.codec]),
multicodec.getCodeVarint(this.codec),
this.multihash

@@ -143,3 +143,3 @@ ])

Buffer.from(`0${this.version}`, 'hex'),
codecVarints[this.codec],
multicodec.getCodeVarint(this.codec),
multihash.prefix(this.multihash)

@@ -194,2 +194,6 @@ ])

toString (base) {
return this.toBaseEncodedString(base)
}
/**

@@ -221,12 +225,2 @@ * Serialize to a plain object.

/**
* Test if the given input is a CID.
*
* @param {any} other
* @returns {bool}
*/
static isCID (other) {
return !(CIDUtil.checkCIDComponents(other))
}
/**
* Test if the given input is a valid CID object.

@@ -248,2 +242,5 @@ * Throws if it is not.

module.exports = CID
module.exports = withIs(CID, {
className: 'CID',
symbolName: '@ipld/js-cid/CID'
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc