UNPKG

@atcute/cid

Version:

lightweight DASL CID codec library for AT Protocol

33 lines (32 loc) 1.31 kB
export declare const CID_VERSION = 1; export declare const HASH_SHA256 = 18; export declare const CODEC_RAW = 85; export declare const CODEC_DCBOR = 113; /** * Represents a Content Identifier (CID), in particular, a limited subset of * CIDv1 as described by DASL specifications. * https://dasl.ing/cid.html */ export interface Cid { /** CID version, this is always `1` for CIDv1 */ version: number; /** Multicodec type for the data, can be `0x55` for raw data or `0x71` for DAG-CBOR */ codec: number; /** Digest contents */ digest: { /** Multicodec type for the digest, this is always `0x12` for SHA-256 */ codec: number; /** Raw hash bytes */ contents: Uint8Array; }; /** Raw CID bytes */ bytes: Uint8Array; } export declare const create: (codec: 85 | 113, data: Uint8Array) => Promise<Cid>; export declare const createEmpty: (codec: 85 | 113) => Cid; export declare const decodeFirst: (bytes: Uint8Array) => [decoded: Cid, remainder: Uint8Array]; export declare const decode: (bytes: Uint8Array) => Cid; export declare const fromString: (input: string) => Cid; export declare const toString: (cid: Cid) => string; export declare const fromBinary: (input: Uint8Array) => Cid; export declare const toBinary: (cid: Cid) => Uint8Array;