CID.create constructor

CID.create(
  1. int version,
  2. String codecName,
  3. Uint8List multihash
)

Creates a CID instance from a version, codec name, and pre-computed multihash.

This is a lower-level constructor useful when you already have the multihash.

  • version: The CID version (CID.V0 or CID.V1).
  • codecName: The string name of the multicodec (e.g., "dag-pb", "raw").
  • multihash: The Uint8List containing the full multihash bytes.

Throws ArgumentError if the codecName is unknown or if parameters violate CID version constraints (e.g., CIDv0 with non-'dag-pb' codec).

Implementation

factory CID.create(int version, String codecName, Uint8List multihash) {
  final codecCode = codecNameToCode[codecName];
  if (codecCode == null) {
    throw ArgumentError('Unknown codec name: $codecName');
  }
  return CID(version, codecCode, multihash);
}