Show / Hide Table of Contents

Class Cid

Identifies some content, e.g. a Content ID.

Inheritance
Object
Cid
Implements
IEquatable<Cid>
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Namespace: Ipfs
Assembly: Ipfs.Core.dll
Syntax
[JsonConverter(typeof(Cid.CidJsonConverter))]
public class Cid : IEquatable<Cid>
Remarks

A Cid is a self-describing content-addressed identifier for distributed systems.

Initially, IPFS used a MultiHash as the CID and this is still supported as Version 0. Version 1 adds a self describing structure to the multi-hash, see the spec.

note

The Algorithm must be "sha2-256" for a version 0 CID.

Fields

| Improve this Doc View Source

DefaultContentType

The default ContentType.

Declaration
public const string DefaultContentType = "dag-pb"
Field Value
Type Description
String

Properties

| Improve this Doc View Source

ContentType

The content type or format of the data being addressed.

Declaration
public string ContentType { get; set; }
Property Value
Type Description
String

dag-pb, dag-cbor, eth-block, etc. Defaults to "dag-pb".

Remarks

Sets Version to 1, when setting a value that is not equal to "dag-pb".

See Also
MultiCodec
| Improve this Doc View Source

Encoding

The MultiBase encoding of the CID.

Declaration
public string Encoding { get; set; }
Property Value
Type Description
String

base58btc, base32, base64, etc. Defaults to DefaultAlgorithmName.

Remarks

Sets Version to 1, when setting a value that is not equal to "base58btc".

See Also
MultiBase
| Improve this Doc View Source

Hash

The cryptographic hash of the content being addressed.

Declaration
public MultiHash Hash { get; set; }
Property Value
Type Description
MultiHash

The MultiHash of the content being addressed.

Remarks

Sets Version to 1, when setting a hashing algorithm that is not equal to "sha2-256".

note

If the Algorithm equals identity, then the Digest is also the content. This is commonly referred to as 'CID inlining'.

| Improve this Doc View Source

Version

The version of the CID.

Declaration
public int Version { get; set; }
Property Value
Type Description
Int32

0 or 1.

Remarks

When the Version is 0 and the following properties are not matched, then the version is upgraded to version 1 when any of the properties is set.

  • ContentType equals "dag-pb"
  • Encoding equals "base58btc"
  • Hash algorithm name equals "sha2-256"

The default Encoding is "base32" when the Version is not zero.

Methods

| Improve this Doc View Source

Decode(String)

Converts the specified String to an equivalent Cid object.

Declaration
public static Cid Decode(string input)
Parameters
Type Name Description
String input

The Encode() string.

Returns
Type Description
Cid

A new Cid that is equivalent to input.

Exceptions
Type Condition
FormatException

When the input can not be decoded.

See Also
Encode()
| Improve this Doc View Source

Encode()

Converts the CID to its equivalent string representation.

Declaration
public string Encode()
Returns
Type Description
String

The string representation of the Cid.

Remarks

For Version 0, this is equalivalent to the ToBase58() of the Hash.

See Also
Decode(String)
| Improve this Doc View Source

Equals(Cid)

Declaration
public bool Equals(Cid that)
Parameters
Type Name Description
Cid that
Returns
Type Description
Boolean
| Improve this Doc View Source

Equals(Object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
Object obj
Returns
Type Description
Boolean
Overrides
Object.Equals(Object)
| Improve this Doc View Source

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
Int32
Overrides
Object.GetHashCode()
| Improve this Doc View Source

Read(CodedInputStream)

Reads the binary representation of the CID from the specified Google.Protobuf.CodedInputStream.

Declaration
public static Cid Read(CodedInputStream stream)
Parameters
Type Name Description
Google.Protobuf.CodedInputStream stream

The Google.Protobuf.CodedInputStream to read from.

Returns
Type Description
Cid

A new Cid.

| Improve this Doc View Source

Read(Byte[])

Reads the binary representation of the CID from the specified byte array.

Declaration
public static Cid Read(byte[] buffer)
Parameters
Type Name Description
Byte[] buffer

The souce of a CID.

Returns
Type Description
Cid

A new Cid.

Remarks

The buffer does NOT start with a varint length prefix.

| Improve this Doc View Source

Read(Stream)

Reads the binary representation of the CID from the specified Stream.

Declaration
public static Cid Read(Stream stream)
Parameters
Type Name Description
Stream stream

The Stream to read from.

Returns
Type Description
Cid

A new Cid.

| Improve this Doc View Source

ToArray()

Returns the binary representation of the CID as a byte array.

Declaration
public byte[] ToArray()
Returns
Type Description
Byte[]

A new buffer containing the CID.

Remarks

The buffer does NOT start with a varint length prefix.

| Improve this Doc View Source

ToString()

Returns the string representation of the CID in the general format.

Declaration
public override string ToString()
Returns
Type Description
String

e.g. "QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V"

Overrides
Object.ToString()
| Improve this Doc View Source

ToString(String)

Returns a string representation of the CID according to the provided format specifier.

Declaration
public string ToString(string format)
Parameters
Type Name Description
String format

A single format specifier that indicates how to format the value of the CID. Can be "G" or "L".

Returns
Type Description
String

The CID in the specified format.

Remarks

The "G" format specifier is the same as calling Encode().

Specifierreturn value
GQmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V
Lbase58btc cidv0 dag-pb sha2-256 Qm...

Exceptions
Type Condition
FormatException

format is not valid.

| Improve this Doc View Source

Write(CodedOutputStream)

Writes the binary representation of the CID to the specified Google.Protobuf.CodedOutputStream.

Declaration
public void Write(CodedOutputStream stream)
Parameters
Type Name Description
Google.Protobuf.CodedOutputStream stream

The Google.Protobuf.CodedOutputStream to write to.

| Improve this Doc View Source

Write(Stream)

Writes the binary representation of the CID to the specified Stream.

Declaration
public void Write(Stream stream)
Parameters
Type Name Description
Stream stream

The Stream to write to.

Operators

| Improve this Doc View Source

Equality(Cid, Cid)

Value equality.

Declaration
public static bool operator ==(Cid a, Cid b)
Parameters
Type Name Description
Cid a
Cid b
Returns
Type Description
Boolean
| Improve this Doc View Source

Implicit(Cid to String)

Implicit casting of a Cid to a String.

Declaration
public static implicit operator string (Cid id)
Parameters
Type Name Description
Cid id

A Cid.

Returns
Type Description
String

A new String.

Remarks

Equivalent to

Cid.Encode()

| Improve this Doc View Source

Implicit(MultiHash to Cid)

Implicit casting of a MultiHash to a Cid.

Declaration
public static implicit operator Cid(MultiHash hash)
Parameters
Type Name Description
MultiHash hash

A MultiHash.

Returns
Type Description
Cid

A new Cid based on the hash. A Version 0 CID is returned if the hash is "sha2-356"; otherwise Version 1.

| Improve this Doc View Source

Implicit(String to Cid)

Implicit casting of a String to a Cid.

Declaration
public static implicit operator Cid(string s)
Parameters
Type Name Description
String s

A string encoded Cid.

Returns
Type Description
Cid

A new Cid.

Remarks

Equivalent to

 Cid.Decode(s)

| Improve this Doc View Source

Inequality(Cid, Cid)

Value inequality.

Declaration
public static bool operator !=(Cid a, Cid b)
Parameters
Type Name Description
Cid a
Cid b
Returns
Type Description
Boolean

Implements

System.IEquatable<T>

See Also

https://github.com/ipld/cid
  • Improve this Doc
  • View Source
Back to top Generated by DocFX