libp2p/cid

    Dark Mode
Search:
Group by:
  Source   Edit

This module implementes CID (Content IDentifier).

Types

Cid = object
  cidver*: CidVersion
  mcodec*: MultiCodec
  hpos*: int
  data*: VBuffer
  Source   Edit
CidError {.pure.} = enum
  Error, Incorrect, Unsupported, Overrun
  Source   Edit
CidVersion = enum
  CIDvIncorrect, CIDv0, CIDv1, CIDvReserved
  Source   Edit

Procs

proc `$`(cid: Cid): string {....raises: [], tags: [RootEffect].}
Return official string representation of content identifier cid.   Source   Edit
proc `==`(a: Cid; b: Cid): bool {....raises: [], tags: [].}
Compares content identifiers a and b, returns true if hashes are equal, false otherwise.   Source   Edit
proc base58(cid: Cid): string {....raises: [], tags: [].}
Get BASE58 encoded string representation of content identifier cid.   Source   Edit
proc contentType(cid: Cid): Result[MultiCodec, CidError] {....raises: [], tags: [].}
Returns content type part of CID   Source   Edit
proc hash(cid: Cid): Hash {.inline, ...raises: [], tags: [].}
  Source   Edit
proc hex(cid: Cid): string {....raises: [], tags: [].}
Get hexadecimal string representation of content identifier cid.   Source   Edit
proc init(ctype: typedesc[Cid]; version: CidVersion; content: MultiCodec;
          hash: MultiHash): Result[Cid, CidError] {....raises: [].}

Create new content identifier using content type content and MultiHash hash using version version.

To create CIDv0 you need to use: Cid.init(CIDv0, multiCodec("dag-pb"), MultiHash.digest("sha2-256", data))

All other encodings and hashes are not supported by CIDv0.

  Source   Edit
proc init[T: char | byte](ctype: typedesc[Cid]; data: openArray[T]): Result[Cid,
    CidError] {....raises: [].}
Create new content identifier using array of bytes or string data.   Source   Edit
proc mhash(cid: Cid): Result[MultiHash, CidError] {....raises: [], tags: [].}
Returns MultiHash part of CID.   Source   Edit
proc repr(cid: Cid): string {....raises: [], tags: [].}
Get string representation of content identifier cid.   Source   Edit
proc validate(ctype: typedesc[Cid]; data: openArray[byte]): bool {....raises: [].}
Returns true is data has valid binary CID representation.   Source   Edit
proc version(cid: Cid): CidVersion {....raises: [], tags: [].}
Returns CID version   Source   Edit
proc write(vb: var VBuffer; cid: Cid) {.inline, ...raises: [], tags: [].}
Write CID value cid to buffer vb.   Source   Edit

Templates

template orError(exp: untyped; err: untyped): untyped
  Source   Edit