npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ipfs-uniform-resolve

v1.0.0

Published

Resolve IPFS paths to data in a well-documented, uniform fashion

Downloads

18

Readme

ipfs-uniform-resolve

Resolve CIDs into data using a well-defined method, that works across both UnixFS and "regular" node types.

import Resolve from "ipfs-uniform-resolve";

const resolver = Resolve(blockApi, nameApi);
const cid = await resolver.resolveIpns(ipnsCid);
const { value, block, cid: finalCid } = await resolver.resolve(cid, "/dir/file.json/key/0");

console.log(value);

Resolution Algorithm

Starting from a CID pointing at a block, and given a path, resolve(cid, path) will dereference the CID to the block, and then follow each path segment in the path, dereferencing CIDs along the way if necessary.

If resolve() hits a DAG-PB (UnixFS) node, path segments will be treated as UnixFS path segments, i.e. /foo will actually be node.Links[foo].

If resolve() hits a regular (non DAG-PB) block, path segments will correspond directly to object entries, i.e. /a/b/0 will be node.a.b[0].

CIDs in regular (non DAG-PB) block are detected if:

  • The node is a string, and CID.parse() succeeds
  • The node is an object, and CID.asCID() succeeds

CID in this case being the definition in the multiformats package.

CIDs will be automatically dereferenced, if needed.

API

The library default exports a factory function that returns the library instance:

Resolver(block, name, multidecoder)
  • block and name are object that implement the Block and Name API of the IPFS Core interface, respectively
  • multidecoder is an optional parameter to which you can either pass { decoders, hashers }, or a Multidecoder implementation.

The resulting object contains two functions:

async resolveIpns(cid: CID | string, timeout?: number): Promise<CID>

Resolves a CID as if it were an IPNS link until it resolves into a regular block CID. The function will throw if given an invalid CID, or if resolution otherwise fails.

const cid = await resolver.resolveIpns("ipfs.io");

async resolve(cid: CID, path: string = "/", options?)

Resolve an IPLD value starting from a CID, following a path. The algorithm with which it does this is defined here.

options is an object which affects the particular behaviour of the resolution:

  • options.followPb - Whether or not to follow path across DAG-PB nodes. Defaults to true
  • options.followIpld - Whether or not to follow path across non-DAG-PB (regular) nodes. Defaults to true

Will throw TypeError if the passed CID has a codec of libp2p-key (0x72). Currently, this is treated as only being used for IPNS. Please submit a bug report if you have a different use case.

Will throw DeadEndError if resolution can't move forward because of a missing object entry. The error contains cid, at, and remaining properties which point to which block/path the error happened.

const { value, cid, block } =  await resolver.resolve(cid, path, { followIpld: false });