Ceramic StreamID
This package contains Ceramic StreamID and CommitID implementation.
Implements Ceramic streamIDs as defined in ceramic spec and CIP,
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 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.
import { StreamID } from '@ceramicnetwork/streamid';
const streamid = new StreamID('tile', 'bagcqcerakszw2vsov...');
streamid.type;
streamid.typeName;
streamid.bytes;
streamid.cid;
streamid.toString();
streamid.toUrl();
You can also create StreamID instance from StreamID string or bytes.
const streamid = StreamID.fromString('k3y52l7mkcvtg023bt9txe...');
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.
import { CommitID } from '@ceramicnetwork/streamid';
const commitId = new CommitID('tile', 'bagcqcerakszw2vsov...', 'bagcqcerakszw2vsov...');
commitId.type;
commitId.typeName;
commitId.bytes;
commitId.cid;
commitId.commit;
commitId.toString();
commitId.toUrl();
To reference specific CID from StreamID
or to change commit reference in CommitID
, use atCommit
method:
commitId.atCommit('bagcqcerakszw2vsov...');
streamId.atCommit('bagcqcerakszw2vsov...');
CommitID
(StreamID
for compatibility also) can get you base StreamID
via #baseID
:
commitId.baseID;
streamId.baseID;
To parse an unknown input into proper CommitID or StreamID, you could use streamRef.from
:
import { streamRef } from '@ceramicnetwork/streamid';
const input = 'bagcqcerakszw2vsov...'
const streamIdOrCommitId = streamRef.from(input)
Development
Run tests:
npm test
Run linter:
npm run lint
Contributing
We are happy to accept small and large contributions. Make sure to check out the Ceramic specifications for details of how the protocol works.
License
MIT or Apache-2.0