Skip to content

Commit

Permalink
Merge pull request #19 from 3box/fix/pub-export-jws
Browse files Browse the repository at this point in the history
chore: need to publicly export moved Jws and JwsBuilder for consumers
  • Loading branch information
dav1do authored Jun 24, 2024
2 parents a3299b3 + 65fefe9 commit 536203f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

0 comments on commit 536203f

Please sign in to comment.