JSPM

@meproto/cbor

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q24304F
  • License Apache-2.0

CBOR encoding and decoding utilities for ME Protocol, DID:ME, and credential serialization.

Package Exports

  • @meproto/cbor

Readme

@meproto/cbor

npm version License Tests bundle size

Canonical DAG-CBOR encoder/decoder and CID helpers for the ME Protocol and did:me.

Implements a safe, deterministic subset of CBOR suitable for decentralized identity, verifiable credentials, content addressing, and protocol-level data structures.

  • ✔ Canonical, deterministic DAG-CBOR encoding
  • ✔ Strict decoder with type constraints
  • ✔ UTF-8 ordered map keys
  • ✔ No floats, no indefinite lengths
  • ✔ CIDv1 (dag-cbor / sha2-256) computation
  • ✔ Fully typed TypeScript API

Installation

pnpm add @meproto/cbor
# or
npm install @meproto/cbor
# or
yarn add @meproto/cbor

Usage

Encode canonical DAG-CBOR

import { encodeCanonical } from "@meproto/cbor";

const bytes = encodeCanonical({
  hello: "world",
  count: 42,
});

Decode canonical DAG-CBOR

import { decodeCanonical } from "@meproto/cbor";

const value = decodeCanonical(bytes);
// → { hello: "world", count: 42 }

CID helpers

Compute a CIDv1 (dag-cbor, sha2-256)

import { computeCidDagCbor } from "@meproto/cbor";

const cid = await computeCidDagCbor(bytes);
// → "bafyre..."

Verify a CID

import { verifyDagCborCid } from "@meproto/cbor";

const result = await verifyDagCborCid(cid, bytes);
// { ok: true, expected: "...", actual: "..." }

Validate CID syntax

import { isValidCidString } from "@meproto/cbor";

isValidCidString(cid);      // true
isValidCidString("nope");   // false

What is canonical DAG-CBOR?

ME Protocol uses a deterministic subset of CBOR with:

  • UTF-8 sorted map keys
  • No floats
  • No semantic tags
  • No indefinite-length items
  • Only major types 0–5 and null/true/false

This ensures stable hashing, CID derivation, and cryptographic integrity.


License

Apache-2.0 © 2025 ReallyMe LLC