Intro

Installable via npm install --save cids, it can also be used directly in the browser.

Download

The source is available for download from GitHub. Alternatively, you can install using npm:

$ npm install --save cids

You can then require() cids as normal:

const cids = require('cids')

In the Browser

Cids should work in any ES2015 environment out of the box.

Usage:

<script type="text/javascript" src="index.js"></script>

The portable versions of cids, including index.js and index.min.js, are included in the /dist folder. Cids can also be found on unpkg.com under

SerializedCID

src/index.js
SerializedCID

Type: Object

Parameters
codec (string)
version (number)
multihash (Buffer)

The CID as a Buffer

buffer
Returns
Buffer:

Get the prefix of the CID.

prefix
Returns
Buffer:

Convert to a CID of version 0.

toV0(): CID
Returns
CID:

Convert to a CID of version 1.

toV1(): CID
Returns
CID:

toBaseEncodedString

src/index.js

Encode the CID into a string.

toBaseEncodedString(base: string): string
Parameters
base (string = this.multibaseName) Base encoding to use.
Returns
string:

CID(QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n)

toString(): String
Returns
String:

Serialize to a plain object.

toJSON(): SerializedCID
Returns
SerializedCID:

Compare equality with another CID.

equals(other: CID): bool
Parameters
other (CID)
Returns
bool:

validateCID

src/index.js

Test if the given input is a valid CID object. Throws if it is not.

validateCID(other: any): void
Parameters
other (any)
Returns
void:

Class representing a CID <mbase><version><mcodec><mhash> , as defined in ipld/cid.

new CID()
Static Members
isCID(other)
Instance Members
version
codec
multihash
multibaseName

checkCIDComponents

src/cid-util.js

Test if the given input is a valid CID object. Returns an error message if it is not. Returns undefined if it is a valid CID.

checkCIDComponents(other: any): string
Parameters
other (any)
Returns
string: