Socket
Socket
Sign inDemoInstall

cids

Package Overview
Dependencies
4
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

cids

CID Implementation in JavaScript


Version published
Weekly downloads
267K
decreased by-9.89%
Maintainers
3
Created
Weekly downloads
 

Package description

What is cids?

The 'cids' npm package is used for handling Content Identifiers (CIDs) in the context of IPFS (InterPlanetary File System). CIDs are a fundamental part of IPFS, allowing for unique identification of content based on its cryptographic hash. This package provides utilities for creating, parsing, and working with CIDs.

What are cids's main functionalities?

Creating a CID

This feature allows you to create a new CID instance. The constructor takes the version, codec, and multihash as parameters. The example demonstrates creating a CID of version 1 with the 'dag-pb' codec.

const CID = require('cids');
const cid = new CID(1, 'dag-pb', Buffer.from('1220...'));
console.log(cid.toString());

Parsing a CID

This feature allows you to parse an existing CID string. The example shows how to parse a CID and access its version property.

const CID = require('cids');
const cid = new CID('Qm...');
console.log(cid.version);

Converting CID to different formats

This feature allows you to convert a CID to different versions. The example demonstrates converting a CID to version 1 and then converting it to a string.

const CID = require('cids');
const cid = new CID('Qm...');
console.log(cid.toV1().toString());

Other packages similar to cids

Changelog

Source

0.5.8 (2019-03-14)

Performance Improvements

  • cache buffer form of CID when created (c7fc646)

<a name="0.5.7"></a>

Readme

Source

js-cid

Travis CI Coverage Status Dependency Status js-standard-style Greenkeeper badge

CID implementation in JavaScript.

Lead Maintainer

Volker Mische

Table of Contents

Install

In Node.js through npm

$ npm install --save cids

Browser: Browserify, Webpack, other bundlers

The code published to npm that gets loaded on require is in fact an ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.

const CID = require('cids')

In the Browser through <script> tag

Loading this module through a script tag will make the Cids obj available in the global namespace.

<script src="https://unpkg.com/cids/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/cids/dist/index.js"></script>
Gotchas

You will need to use Node.js Buffer API compatible, if you are running inside the browser, you can access it by multihash.Buffer or you can install Feross's Buffer.

Usage

Basic usage is quite simple.

const CID = require('cids')

const cid = new CID(1, 'dag-pb', multihash)

If you have a base encoded string for a multihash you can also create an instance from the encoded string.

const cid = new CID(base58Multihash)

API

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.

multihash must be a Buffer instance of a valid 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

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT

Keywords

FAQs

Last updated on 14 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc