cids
0.4.2

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 unkpkg.com under

SerializedCID

Parameters

  1. codec: string:  
  2. version: number:  
  3. multihash: Buffer:  

CID

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

static

CID.isCID

isCID(other: any): bool

Test if the given input is a CID.

Parameters

  1. other: any:  

Returns

bool

CID.validateCID

validateCID(other: any): void

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

Parameters

  1. other: any:  

Returns

void

instance

constructor

constructor(version: (string | Buffer), codec: [string], multihash: [Buffer])

Create a new CID.

The algorithm for argument input is roughly:

if (str)
  if (1st char is on multibase table) -> CID String
  else -> bs58 encoded multihash
else if (Buffer)
  if (0 or 1) -> CID
  else -> multihash
else if (Number)
  -> construct CID by parts

..if only JS had traits..

Parameters

  1. version: (string | Buffer):  
  2. codec: [string]:  
  3. multihash: [Buffer]:  

Example

new CID(<version>, <codec>, <multihash>)
new CID(<cidStr>)
new CID(<cid.buffer>)
new CID(<multihash>)
new CID(<bs58 encoded multihash>)

CID.prototype.codec

codec: string

CID.prototype.version

version: number

CID.prototype.multihash

multihash: Buffer

CID.prototype.buffer

buffer

The CID as a Buffer

Returns

CID.prototype.prefix

prefix

Get the prefix of the CID.

Returns

CID.prototype.toV0

toV0(): CID

Convert to a CID of version 0.

Returns

CID.prototype.toV1

toV1(): CID

Convert to a CID of version 1.

Returns

CID.prototype.toBaseEncodedString

toBaseEncodedString(base: [string]): string

Encode the CID into a string.

Parameters

  1. base: [string] (='base58btc'):  
    Base encoding to use.

Returns

CID.prototype.toJSON

toJSON(): SerializedCID

Serialize to a plain object.

CID.prototype.equals

equals(other: CID): bool

Compare equality with another CID.

Parameters

  1. other: CID:  

Returns

bool