0.1.0 • Published 3 years ago
@ethersphere/swarm-cid v0.1.0
Swarm CID
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
0.1.0
3 years ago