Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

CID

class CID<Data extends unknown = unknown, Format extends number = number, Alg extends number = number, Version extends API.Version = API.Version> implements [API.Link]<Data, Format, Alg, Version> {
constructor(
version: Version,
code: Format,
multihash: API.MultihashDigest<Alg>,
bytes: Uint8Array,
);
readonly /: Uint8Array;
get asCID(): CID<Data, Format, Alg, Version>;
get byteOffset(): number;
get byteLength(): number;
readonly bytes: Uint8Array;
readonly code: Format;
readonly multihash: API.MultihashDigest<Alg>;
readonly version: Version;
get [Symbol.toStringTag](): string;
 
equals(other: unknown): other is CID<Data, Format, Alg, Version>;
link(): CID<Data, Format, Alg, Version>;
toJSON(): {
code: Format;
version: Version;
hash: Uint8Array;
}
;
toString(base?: API.MultibaseEncoder<string> | undefined): string;
toV0(): CID<Data, API.DAG_PB, API.SHA_256, 0>;
toV1(): CID<Data, Format, Alg, 1>;
 
static asCID<Data_2 extends unknown, Format_2 extends number, Alg_2 extends number, Version_2 extends API.Version, U extends unknown>(input: U | API.Link<Data_2, Format_2, Alg_2, Version_2>): CID<Data_2, Format_2, Alg_2, Version_2> | null;
static create<Data_3 extends unknown, Format_3 extends number, Alg_3 extends number, Version_3 extends API.Version>(
version: Version_3,
code: Format_3,
digest: API.MultihashDigest<Alg_3>,
): CID<Data_3, Format_3, Alg_3, Version_3>;
static createV0<T extends unknown = unknown>(digest: API.MultihashDigest<SHA_256_CODE>): CID<T, 112, 18, 0>;
static createV1<Data_4 extends unknown, Code extends number, Alg_4 extends number>(code: Code, digest: API.MultihashDigest<Alg_4>): CID<Data_4, Code, Alg_4, 1>;
static decode<Data_5 extends unknown, Code_1 extends number, Alg_5 extends number, Ver extends API.Version>(bytes: API.ByteView<API.Link<Data_5, Code_1, Alg_5, Ver>>): CID<Data_5, Code_1, Alg_5, Ver>;
static decodeFirst<T_1 extends unknown, C extends number, A extends number, V extends API.Version>(bytes: API.ByteView<API.Link<T_1, C, A, V>>): [CID<T_1, C, A, V>, Uint8Array];
static equals<Data_1 extends unknown, Format_1 extends number, Alg_1 extends number, Version_1 extends API.Version>(self: API.Link<Data_1, Format_1, Alg_1, Version_1>, other: unknown): other is CID<any, number, number, API.Version>;
static inspectBytes<T_2 extends unknown, C_1 extends number, A_1 extends number, V_1 extends API.Version>(initialBytes: API.ByteView<API.Link<T_2, C_1, A_1, V_1>>): {
version: V_1;
codec: C_1;
multihashCode: A_1;
digestSize: number;
multihashSize: number;
size: number;
}
;
static parse<Prefix extends string, Data_6 extends unknown, Code_2 extends number, Alg_6 extends number, Ver_1 extends API.Version>(source: API.ToString<API.Link<Data_6, Code_2, Alg_6, Ver_1>, Prefix>, base?: API.MultibaseDecoder<Prefix> | undefined): CID<Data_6, Code_2, Alg_6, Ver_1>;
}

§Type Parameters

§
Data extends unknown = unknown
[src]
§
Format extends number = number
[src]
§
Alg extends number = number
[src]
§
Version extends API.Version = API.Version
[src]

§Implements

§
[API.Link]<Data, Format, Alg, Version>
[src]

§Constructors

§
new CID(version: Version, code: Format, multihash: API.MultihashDigest<Alg>, bytes: Uint8Array)
[src]
@param version
  • Version of the CID
@param code
@param multihash
  • (Multi)hash of the of the content.
@param bytes

§Properties

§
/: Uint8Array
[src]
§
asCID: CID<Data, Format, Alg, Version> readonly deprecated
[src]

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

@deprecated
§
byteOffset: number readonly
[src]
§
byteLength: number readonly
[src]
§
bytes: Uint8Array
[src]
§
code: Format
[src]
§
multihash: API.MultihashDigest<Alg>
[src]
§
version: Version
[src]
§
[Symbol.toStringTag]: string readonly
[src]

§Methods

§
equals(other: unknown): other is CID<Data, Format, Alg, Version>
[src]
@param other
@return
§
toJSON(): {
code: Format;
version: Version;
hash: Uint8Array;
}
[src]
§
toString(base?: API.MultibaseEncoder<string> | undefined): string
[src]
@return
§
toV0(): CID<Data, API.DAG_PB, API.SHA_256, 0>
[src]
@return
§
toV1(): CID<Data, Format, Alg, 1>
[src]
@return

§Static Methods

§
asCID<Data_2 extends unknown, Format_2 extends number, Alg_2 extends number, Version_2 extends API.Version, U extends unknown>(input: U | API.Link<Data_2, Format_2, Alg_2, Version_2>): CID<Data_2, Format_2, Alg_2, Version_2> | null
[src]

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 returs null.

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

@param input
@return
§
create<Data_3 extends unknown, Format_3 extends number, Alg_3 extends number, Version_3 extends API.Version>(version: Version_3, code: Format_3, digest: API.MultihashDigest<Alg_3>): CID<Data_3, Format_3, Alg_3, Version_3>
[src]
@param version
  • Version of the CID
@param code
@param digest
  • (Multi)hash of the of the content.
@return
§
createV0<T extends unknown = unknown>(digest: API.MultihashDigest<SHA_256_CODE>): CID<T, 112, 18, 0>
[src]

Simplified version of create for CIDv0.

@param digest
  • Multihash.
@return
§
createV1<Data_4 extends unknown, Code extends number, Alg_4 extends number>(code: Code, digest: API.MultihashDigest<Alg_4>): CID<Data_4, Code, Alg_4, 1>
[src]

Simplified version of create for CIDv1.

@param code
  • Content encoding format code.
@param digest
  • Miltihash of the content.
@return
§
decode<Data_5 extends unknown, Code_1 extends number, Alg_5 extends number, Ver extends API.Version>(bytes: API.ByteView<API.Link<Data_5, Code_1, Alg_5, Ver>>): CID<Data_5, Code_1, Alg_5, Ver>
[src]

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.

@param bytes
@return
§
decodeFirst<T_1 extends unknown, C extends number, A extends number, V extends API.Version>(bytes: API.ByteView<API.Link<T_1, C, A, V>>): [CID<T_1, C, A, V>, Uint8Array]
[src]

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.

@param bytes
@return
§
equals<Data_1 extends unknown, Format_1 extends number, Alg_1 extends number, Version_1 extends API.Version>(self: API.Link<Data_1, Format_1, Alg_1, Version_1>, other: unknown): other is CID<any, number, number, API.Version>
[src]
@param self
@param other
@return
§
inspectBytes<T_2 extends unknown, C_1 extends number, A_1 extends number, V_1 extends API.Version>(initialBytes: API.ByteView<API.Link<T_2, C_1, A_1, V_1>>): {
version: V_1;
codec: C_1;
multihashCode: A_1;
digestSize: number;
multihashSize: number;
size: number;
}
[src]

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.

@param initialBytes
@return
§
parse<Prefix extends string, Data_6 extends unknown, Code_2 extends number, Alg_6 extends number, Ver_1 extends API.Version>(source: API.ToString<API.Link<Data_6, Code_2, Alg_6, Ver_1>, Prefix>, base?: API.MultibaseDecoder<Prefix> | undefined): CID<Data_6, Code_2, Alg_6, Ver_1>
[src]

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).

@param source
@return