@atcute/cbor

2.2.0 • Public • Published

@atcute/cbor

lightweight DASL dCBOR42 (deterministic CBOR with tag 42) codec library for AT Protocol.

the specific profile being implemented is IPLD DAG-CBOR, with some additional notes to keep in mind:

  • undefined types are still forbidden, except for when they are in a map type, where fields will be omitted instead, which makes it easier to construct objects to then pass to the encoder.
  • byte and link types are represented by atproto's lex-json interfaces, but because these involve string codec and parsing, they are done lazily by BytesWrapper and CidLinkWrapper instances.
    • use fromBytes and fromCidLink to convert them to Uint8Array or CID interface respectively, without hitting the string conversion path.
    • use toBytes and toCidLink for the other direction.
  • integers can't exceed JavaScript's safe integer range, no bigint conversions will occur as they will be thrown instead if encountered.
import { encode } from '@atcute/cbor';

const record = {
	$type: 'app.bsky.feed.post',
	createdAt: '2024-08-18T03:18:24.000Z',
	langs: ['en'],
	text: 'hello world!',
};

const cbor = encode(record);
//    ^? Uint8Array(90) [ ... ]

Implementation based on the excellent microcbor library.

Readme

Keywords

Package Sidebar

Install

npm i @atcute/cbor

Weekly Downloads

499

Version

2.2.0

License

MIT

Unpacked Size

55.3 kB

Total Files

19

Last publish

Collaborators

  • externdefs