dcid library

A Dart library for working with Content Identifiers (CIDs).

This library provides a CID class that allows for parsing, creating, and manipulating CIDs according to the CID specification. It supports both CIDv0 and CIDv1, and handles various multicodecs and multihashes.

Usage

import 'package:dart_cid/dcid.dart';
import 'dart:convert';
import 'dart:typed_data';

void main() {
  // Create a CIDv1 from data
  final data = utf8.encode('Hello World!');
  final cid = CID.fromData(CID.V1, 'dag-pb', Uint8List.fromList(data));
  print('Created CID: ${cid.toString()}'); // e.g., bafybeid7qoywk77r7rj3slobqfekdvs57qwuwh5d2z3sqsw52iabe3mqne

  // Parse an existing CID string
  final parsedCid = CID.fromString('QmWvQxTqbG2Z9HPJgG57jjwR154cKhbtJenbyYTWkjgF3e');
  print('Parsed CID version: ${parsedCid.version}');
  print('Parsed CID codec: ${parsedCid.codecName}');
}

See the CID class for more details on available methods and properties.

Classes

CID
Represents a Content Identifier (CID).
CodecInfo
CodecRegistry

Properties

codecCodeToName Map<int, String>
final
codecNameToCode Map<String, int>
final

Functions

decodeVarint(Uint8List bytes, [int offset = 0]) MapEntry<int, int>
Decodes a varint from the beginning of the bytes list. Returns a pair: the decoded integer and the number of bytes consumed. Throws FormatException if varint is malformed or incomplete.
encodeVarint(int number) Uint8List
Encodes an unsigned integer into varint bytes.