@ethersphere/swarm-cid
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Swarm CID

Dependency Status FOSSA Status standard-readme compliant js-standard-style

Utility library to convert Swarm hex references into Swarm CIDs and vice versa.

Warning: This project is in alpha state. There might (and most probably will) be changes in the future to its API and working. Also, no guarantees can be made about its stability, efficiency, and security at this stage.

Table of Contents

Install

> npm install @ethersphere/swarm-cid-js --save

Usage

import * as swarmCid from '@ethersphere/swarm-cid-js'

const someReference = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338'

const manifestCid = swarmCid.encodeReference(someReference, swarmCid.ReferenceType.MANIFEST)
// OR: swarmCid.encodeManifestReference(someReference)

console.log(manifestCid.toString())
// Prints base32 encoded CID string: bah5acgzazjrvpieogf6rl3cwb7xtjzgel6hrt4a4g4vkody5u4v7u7y2im4a

swarmCid.decodeFeedCid(manifestCid) // This will throw Error as it expects Manifest CID
console.log(swarmCid.decodeCid(manifestCid))
// Prints:
// {
//   type: 'manifest'
//   reference: 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338'
// }

API

There are generic functions, that encode/decode which does not throw when unexpected codec.

  • decodeCid
  • encodeReference

And there are type-related functions that check for correct codecs:

  • encodeFeedReference / decodeFeedCid
  • encodeManifestReference / decodeManifestCid

Encoding operations returns CID class! So if you want base32 encoded string then you have to call cid.toString()

Contribute

There are some ways you can make this module better:

  • Consult our open issues and take on one of them
  • Help our tests reach 100% coverage!
  • Join us in our Discord chat in the #develop-on-swarm channel if you have questions or want to give feedback

Maintainers

License

BSD-3-Clause

FOSSA Status

Readme

Keywords

Package Sidebar

Install

npm i @ethersphere/swarm-cid

Weekly Downloads

127

Version

0.1.0

License

BSD-3-Clause

Unpacked Size

15 kB

Total Files

5

Last publish

Collaborators

  • ethersphereowner
  • bee-worker