Class CID<Data, Format, Alg, Version>

Represents an IPLD link to a specific data of type T.

Template: T

Logical type of the data being linked to.

Template: C

multicodec code corresponding to a codec linked data is encoded with

Template: A

multicodec code corresponding to the hashing algorithm of the CID

Type Parameters

  • Data = unknown
  • Format extends number = number
  • Alg extends number = number
  • Version extends Version = Version

    CID version

Implements

Accessors

  • get asCID(): this
  • Signalling cid.asCID === cid has been replaced with cid['/'] === cid.bytes please either use CID.asCID(cid) or switch to new signalling mechanism

    Returns this

    Deprecated

  • get byteLength(): number
  • Returns number

  • get byteOffset(): number
  • Returns number

Constructors

Methods

  • Returns this

  • Parameters

    Returns string

  • Returns CID<Data, 112, 18, 0>

  • Takes any input value and returns a CID instance if it was a CID otherwise returns null. If value is instanceof CID it will return value back. If value is not instance of this CID class, but is compatible CID it will return new instance of this CID class. Otherwise returns null.

    This allows two different incompatible versions of CID library to co-exist and interop as long as binary interface is compatible.

    Type Parameters

    • Data
    • Format extends number
    • Alg extends number
    • Version extends Version
    • U

    Parameters

    Returns null | CID<Data, Format, Alg, Version>

  • Simplified version of create for CIDv0.

    Type Parameters

    • T = unknown

    Parameters

    Returns CID<T, 112, 18, 0>

  • Simplified version of create for CIDv1.

    Type Parameters

    • Data
    • Code extends number
    • Alg extends number

    Parameters

    Returns CID<Data, Code, Alg, 1>

  • Decoded a CID from its binary representation. The byte array must contain only the CID with no additional bytes.

    An error will be thrown if the bytes provided do not contain a valid binary representation of a CID.

    Type Parameters

    • Data
    • Code extends number
    • Alg extends number
    • Version extends Version

    Parameters

    Returns CID<Data, Code, Alg, Version>

  • Decoded a CID from its binary representation at the beginning of a byte array.

    Returns an array with the first element containing the CID and the second element containing the remainder of the original byte array. The remainder will be a zero-length byte array if the provided bytes only contained a binary CID representation.

    Type Parameters

    • T
    • C extends number
    • A extends number
    • V extends Version

    Parameters

    Returns [CID<T, C, A, V>, Uint8Array]

  • Type Parameters

    • Data
    • Format extends number
    • Alg extends number
    • Version extends Version

    Parameters

    Returns other is CID<unknown, number, number, Version>

  • Inspect the initial bytes of a CID to determine its properties.

    Involves decoding up to 4 varints. Typically this will require only 4 to 6 bytes but for larger multicodec code values and larger multihash digest lengths these varints can be quite large. It is recommended that at least 10 bytes be made available in the initialBytes argument for a complete inspection.

    Type Parameters

    • T
    • C extends number
    • A extends number
    • V extends Version

    Parameters

    Returns {
        codec: C;
        digestSize: number;
        multihashCode: A;
        multihashSize: number;
        size: number;
        version: V;
    }

    • codec: C
    • digestSize: number
    • multihashCode: A
    • multihashSize: number
    • size: number
    • version: V
  • Takes cid in a string representation and creates an instance. If base decoder is not provided will use a default from the configuration. It will throw an error if encoding of the CID is not compatible with supplied (or a default decoder).

    Type Parameters

    • Prefix extends string
    • Data
    • Code extends number
    • Alg extends number
    • Version extends Version

    Parameters

    Returns CID<Data, Code, Alg, Version>

Properties

/: Uint8Array
[toStringTag]: "CID" = "CID"
bytes: Uint8Array
code: Format
multihash: MultihashDigest<Alg>
version: Version

Generated using TypeDoc