This package contains Ceramic StreamID and CommitID implementation.
Implements Ceramic streamIDs as defined in ceramic spec and
CIP,
represented as [StreamId
] and [StreamId
] 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.
text
<streamid> ::= <multibase-prefix><multicodec-streamid><type><genesis-cid-bytes>
or including [StreamId
] commit
text
<streamid> ::= <multibase-prefix><multicodec-streamid><type><genesis-cid-bytes><commit-cid-bytes>
shell
$ cargo add streamid
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.
```rust use std::str::FromStr;
use cid::Cid; use streamid::*;
const CIDSTRING: &str = "bagcqcerakszw2vsovxznyp5gfnpdj4cqm2xiv76yd24wkjewhhykovorwo6a"; const STREAMID_STRING: &str = "kjzl6cwe1jw147dvq16zluojmraqvwdmbh61dx9e0c59i344lcrsgqfohexp60s";
let streamid = StreamId::fromstr(STREAMIDSTRING).unwrap();
asserteq!(streamid.streamtype(), StreamType::Tile); asserteq!(streamid.streamtype().tostring(), "tile"); asserteq!(streamid.cid().tostring(), CIDSTRING); asserteq!(streamid.tostring(), STREAMIDSTRING); asserteq!(streamid.tourl(), format!("ceramic://{STREAMID_STRING}")); ```
You can also create StreamId
instance from StreamId
string or bytes.
```rust use std::str::FromStr;
use streamid::*;
const STREAMIDSTRING: &str = "kjzl6cwe1jw147dvq16zluojmraqvwdmbh61dx9e0c59i344lcrsgqfohexp60s";
let streamid = StreamId::fromstr(STREAMIDSTRING).unwrap(); ```
```rust,no_run use streamid::*;
let streamid = StreamId::fromslice(vec![]).unwrap(); ```
To reference particular point in a stream evolution, use [CommitId
]. In
addition to stream type ([StreamType
]) and genesis reference ([Cid
]), one is
expected to provide a reference to commit ([Cid
]). If you pass [None
], this
would reference a genesis commit.
```rust use std::str::FromStr;
use streamid::*;
const BASECIDSTRING: &str = "bagcqcerakszw2vsovxznyp5gfnpdj4cqm2xiv76yd24wkjewhhykovorwo6a"; const COMMITCIDSTRING: &str = "bagjqcgzaday6dzalvmy5ady2m5a5legq5zrbsnlxfc2bfxej532ds7htpova"; const COMMITIDSTRING: &str = "k1dpgaqe3i64kjqcp801r3sn7ysi5i0k7nxvs7j351s7kewfzr3l7mdxnj7szwo4kr9mn2qki5nnj0cv836ythy1t1gya9s25cn1nexst3jxi5o3h6qprfyju";
let commitid = CommitId::fromstr(COMMITIDSTRING).unwrap();
asserteq!(commitid.streamtype(), StreamType::Tile); asserteq!(commitid.streamtype().tostring(), "tile"); asserteq!(commitid.cid().tostring(), BASECIDSTRING); asserteq!(commitid.commit().tostring(), COMMITCIDSTRING); asserteq!(commitid.tostring(), COMMITIDSTRING); asserteq!(commitid.tourl(), format!("ceramic://{COMMITID_STRING}")); ```
To reference specific CID from [StreamId
] or to change commit reference in
[CommitId
], use [StreamRefExt::at_commit
] method:
```rust,ignore use streamid::StreamRefExt;
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 [StreamRefExt::to_base_id
]:
```rust,ignore use streamid::StreamRefExt;
commitid.tobaseid(); // #=> StreamID reference to the stream streamid.tobaseid(); // #=> 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_str
:
```rust,ignore use std::str::FromStr;
use streamid::StreamRef;
let input = "bagcqcerakszw2vsov..."; let streamidorcommitid = StreamRef::from_str(input).unwrap(); ```
Run tests:
shell
cargo test
Run linter:
shell
cargo clippy
cargo fmt
We are happy to accept small and large contributions. Make sure to check out the Ceramic specifications for details of how the protocol works.
MIT or Apache-2.0