import { CID } from "multiformats"; import { Block } from "multiformats/block"; import type { API as BlockAPI } from "ipfs-core-types/block"; import type { API as NameAPI } from "ipfs-core-types/name"; import { Multidecoder } from "multiformat-multicodec"; import { BlockDecoder } from "multiformats/codecs/interface"; import { Hasher } from "multiformats/hashes/hasher"; /** * Factory function that takes in its dynamic dependencies and returns a library * object. * @param block The `block` API of an IPFS Core impl. Only needs to exist `block::get()` * @param name The `name` API of an IPFS Core impl. Only needs to exist `name::resolve()` * @param [multidecoder] Either an impl of the [Multidecoder]{@link Multidecoder} interface, or an object containing an array of `decoders` and `hashers` that will be added to the default Multidecoder. * @returns Library object */ export default function (block: Pick, name: Pick, multidecoder?: Multidecoder & { decoders: BlockDecoder[]; hashers: Hasher[]; }): { /** * Resolves a CID as if it were an IPNS link until it resolves into a regular block CID. * @param {CID | string} cid The CID which to resolve * @param {number} [timeout] Max timeout on the recursive query * @throws Will throw if `cid` is invalid, or resolution otherwise fails. */ resolveIpns(cid: CID | string, timeout?: number): Promise; /** * Resolve an IPLD value starting from a CID, following a path. * Will traverse DAG-PB (UnixFS) by treating path segments as UnixFS path segments (i.e. it will follow *files*, and not nodes). * * Will dereference CIDs in non-UnixFS nodes. * CIDs are detected if: * - The node is a string, and `CID.parse()` succeeds * - The node is an object, and `CID.asCID()` succeeds * @see CID.parse * @see CID.asCID * * @param {CID} cid Starting block CID * @param {string} [path] The path which to resolve. Defaults to `/` (doesn't move) * @param {Object} [options] Resolution configuration * @param {boolean} [options.followPb] Whether or not to follow path across DAG-PB nodes. Defaults to `true` * @param {boolean} [options.followIpld] Whether or not to follow path across non-DAG-PB (regular) nodes. Defaults to `true` * * @throws {TypeError} Passed CID has codec `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. * @throws {DeadEndError} Resolution can't move forward because of missing object entry */ resolve(cid: CID, path?: string, options?: { followPb?: boolean; followIpld?: boolean; }): Promise<{ value: T; cid: CID; block: Block; }>; };