Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: need to publicly export moved Jws and JwsBuilder for consumers #19

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/jws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,34 @@ pub struct JwsBuilder<S> {
}

impl<S: Signer> JwsBuilder<S> {
/// Create a new JwsBuilder with a signer
pub fn new(signer: S) -> Self {
Self {
signer,
additional: BTreeMap::new(),
}
}

/// Add additional information to the JWS
pub fn with_additional(mut self, key: String, value: serde_json::Value) -> Self {
self.additional.insert(key, value);
self
}

/// Replace the additional information in the JWS
pub fn replace_additional(mut self, additional: BTreeMap<String, serde_json::Value>) -> Self {
self.additional = additional;
self
}

/// Build a JWS for a CID. This is used to define a link to other data.
pub fn build_for_cid(self, cid: &Cid) -> anyhow::Result<Jws> {
let cid_str = Base64UrlString::from_cid(cid);
let link = MultiBase32String::try_from(cid)?;
Jws::new(&self.signer, cid_str, Some(link), self.additional)
}

/// Build a JWS for with data as the payload.
pub fn build_for_data<T: Serialize>(self, input: &T) -> anyhow::Result<Jws> {
let input = serde_json::to_vec(input)?;
let input = Base64UrlString::from(input);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use ceramic_event::{
},
Base64String, Cid, MultiBase36String, StreamId, StreamIdType,
};
use jws::Jws;
use serde::Serialize;
use std::str::FromStr;

use crate::api::{ModelData, PARENT_STREAM_ID, SEP};
pub use ceramic_event;
pub use json_patch;
pub use jws::{Jws, JwsBuilder};
pub use model_definition::{
GetRootSchema, ModelAccountRelation, ModelDefinition, ModelRelationDefinition,
ModelViewDefinition,
Expand Down
Loading