# @ceramicnetwork/streamid

> Ceramic Stream Ids

Latest version **5.6.0** (published 2024-07-22) · (Apache-2.0 OR MIT) license · 0 weekly downloads

## Install

```sh
npm install @ceramicnetwork/streamid
pnpm add @ceramicnetwork/streamid
yarn add @ceramicnetwork/streamid
bun add @ceramicnetwork/streamid
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.6.0 |
| Published | 2024-07-22 |
| First published | 2021-04-19 |
| Weekly downloads | 0 |
| License | (Apache-2.0 OR MIT) |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 49.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Zach Ferland |
| Maintainers | dav1do, ceramic-velvetshark, cb3box, jpham2023, npm.3box, smrz2001, oed, paul_lecam, stbrody, ukstv |
| Keywords | ceramic, StreamId |

## Links

- npm: https://www.npmjs.com/package/@ceramicnetwork/streamid
- npm.io page: https://npm.io/package/@ceramicnetwork/streamid

## Dependencies (7)

- [cborg](https://npm.io/package/cborg.md) ^4.0.8
- [varint](https://npm.io/package/varint.md) ^6.0.0
- [mapmoize](https://npm.io/package/mapmoize.md) ^1.2.1
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^5.0.1
- [multiformats](https://npm.io/package/multiformats.md) ~13.1.3
- [@ipld/dag-cbor](https://npm.io/package/@ipld/dag-cbor.md) ^7.0.0
- [@stablelib/sha256](https://npm.io/package/@stablelib/sha256.md) ^1.0.1

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 5.6.0 (latest) — 2024-07-22
- 5.6.1-nightly.20251117002949.0 (nightly) — 2025-11-17
- 5.6.0-rc.0 (next) — 2024-07-22
- 2.9.0-hotfix.0 (hotfix) — 2022-12-23
- 5.6.1-nightly.20251116003123.0 — 2025-11-16
- 5.6.1-nightly.20251115002838.0 — 2025-11-15
- 5.6.1-nightly.20251114002950.0 — 2025-11-14
- 5.6.1-nightly.20251113002938.0 — 2025-11-13
- 5.6.1-nightly.20251112002933.0 — 2025-11-12
- 5.6.1-nightly.20251111002954.0 — 2025-11-11
- 5.6.1-nightly.20251110003201.0 — 2025-11-10
- 5.6.1-nightly.20251109003124.0 — 2025-11-09
- 5.6.1-nightly.20251108002716.0 — 2025-11-08
- 5.6.1-nightly.20251107002944.0 — 2025-11-07
- 5.6.1-nightly.20251106002909.0 — 2025-11-06
- … 755 more at https://npm.io/package/@ceramicnetwork/streamid/versions

## README

# Ceramic StreamID
![ceramicnetwork](https://circleci.com/gh/ceramicnetwork/js-ceramic.svg?style=shield)
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)
[![](https://img.shields.io/badge/Chat%20on-Discord-orange.svg?style=flat)](https://discord.gg/6VRZpGP)
[![Twitter](https://img.shields.io/twitter/follow/ceramicnetwork?label=Follow&style=social)](https://twitter.com/ceramicnetwork)

> This package contains Ceramic StreamID and CommitID implementation.

Implements Ceramic streamIDs as defined in ceramic spec and [CIP](https://github.com/ceramicnetwork/CIP/blob/master/CIPs/CIP-59/CIP-59.md),
represented as StreamID and CommitID for API clarity.

StreamID represents a reference to a stream as a whole, thus does not contain commit information.

CommitID represents a reference to a particular commit in the stream evolution.

```
<streamid> ::= <multibase-prefix><multicodec-streamid><type><genesis-cid-bytes>
```

or including StreamID commit

```
<streamid> ::= <multibase-prefix><multicodec-streamid><type><genesis-cid-bytes><commit-cid-bytes>
```

## Getting started

### Installation

```
$ npm install @ceramicnetwork/streamid
```

### Usage

See the [ceramic developer site](https://developers.ceramic.network/) for more details about how to use this package.


To reference a stream as a whole, use `StreamID`. You can create an instance from the parts. stream type string or integer and CID instance or string are required.

```typescript
import { StreamID } from '@ceramicnetwork/streamid';

const streamid = new StreamID('tile', 'bagcqcerakszw2vsov...');

streamid.type; // 0
streamid.typeName; // 'tile'
streamid.bytes; // Uint8Array(41) [ 206,   1,   0,   0,   1, 133,   1, ...]
streamid.cid; // CID('bagcqcerakszw2vsov...')
streamid.toString();
//k3y52l7mkcvtg023bt9txegccxe1bah8os3naw5asin3baf3l3t54atn0cuy98yws
streamid.toUrl();
//ceramic://k3y52l7mkcvtg023bt9txegccxe1bah8os3naw5asin3baf3l3t54atn0cuy98yws
```

You can also create StreamID instance from StreamID string or bytes.

```typescript
const streamid = StreamID.fromString('k3y52l7mkcvtg023bt9txe...');
```

```typescript
const streamid = StreamID.fromBytes(Uint8Array(41) [ 206,   1,   0,   0,   1, 133,   1, ...])
```

To reference particular point in a stream evolution, use `CommitID`.
In addition to stream type (string or integer) and genesis reference (CID instance or string),
one is expected to provide a reference to commit (CID instance or string). If you pass `0` or `'0'` (as string), `null`
or just omit the value, this would reference a genesis commit.

```typescript
import { CommitID } from '@ceramicnetwork/streamid';

const commitId = new CommitID('tile', 'bagcqcerakszw2vsov...', 'bagcqcerakszw2vsov...');

commitId.type; // 0
commitId.typeName; // 'tile'
commitId.bytes; // Uint8Array(41) [ 206,   1,   0,   0,   1, 133,   1, ...]
commitId.cid; // CID('bagcqcerakszw2vsov...')
commitId.commit; // CID('bagcqcerakszw2vsov...')

commitId.toString();
// k3y52l7mkcvtg023bt9txegccxe1bah8os3naw5asin3baf3l3t54atn0cuy98yws
commitId.toUrl();
// ceramic://k3y52l7mkcvtg023bt9txegccxe1bah8os3naw5asin3baf3l3t54atn0cuy98yws?version=k3y52l7mkcvt...
```

To reference specific CID from `StreamID` or to change commit reference in `CommitID`, use `atCommit` method:

```typescript
commitId.atCommit('bagcqcerakszw2vsov...'); // #=> new CommitID for the same stream
streamId.atCommit('bagcqcerakszw2vsov...'); // #=> new CommitID for the same stream
```

`CommitID` (`StreamID` for compatibility also) can get you base `StreamID` via `#baseID`:

```typescript
commitId.baseID; // #=> StreamID reference to the stream
streamId.baseID; // #=> new StreamID reference to the same stream, effectively a shallow clone.
```

To parse an unknown input into proper CommitID or StreamID, you could use `streamRef.from`:
```typescript
import { streamRef } from '@ceramicnetwork/streamid';
const input = 'bagcqcerakszw2vsov...' // could be instance of Uint8Array, StreamID, CommitID either; or in URL form
const streamIdOrCommitId = streamRef.from(input) // throws if can not properly parse it into CommitID or StreamID
```

## Development

Run tests:

```shell
npm test
```

Run linter:

```shell
npm run lint
```

## Contributing

We are happy to accept small and large contributions. Make sure to check out the [Ceramic specifications](https://github.com/ceramicnetwork/ceramic/blob/main/SPECIFICATION.md) for details of how the protocol works.

## License

MIT or Apache-2.0

---
_Source: https://npm.io/package/@ceramicnetwork/streamid · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
