Skip to content

Commit

Permalink
remove dag-jose functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
dbcfd committed Mar 23, 2023
1 parent a5eaa0d commit fc8f307
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 122 deletions.
31 changes: 0 additions & 31 deletions core/src/dag_jose.rs

This file was deleted.

90 changes: 0 additions & 90 deletions core/src/jws.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::dag_jose::{Encoded, EncodedSignature};
use crate::{Base64String, Base64UrlString, DidDocument, Jwk, MultiBase32String};
use cid::Cid;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -41,71 +40,6 @@ impl Jws {
}],
})
}

pub fn encode_dag_jose(self) -> anyhow::Result<Vec<u8>> {
let encoded: Encoded = self.try_into()?;
let v = serde_ipld_dagcbor::to_vec(&encoded)?;
Ok(v)
}
}

impl TryFrom<Encoded> for Jws {
type Error = anyhow::Error;

fn try_from(value: Encoded) -> Result<Self, Self::Error> {
if let Some(payload) = value.payload {
let link = Cid::try_from(payload.as_ref())?;
let signatures = value.signatures.unwrap_or_default();
let signatures: Result<Vec<_>, _> =
signatures.into_iter().map(JwsSignature::try_from).collect();
Ok(Self {
link: MultiBase32String::try_from_cid(&link)?,
payload: Base64UrlString::from(payload.as_ref()),
signatures: signatures?,
})
} else {
anyhow::bail!("Not a valid JOSE object")
}
}
}

impl TryInto<Encoded> for Jws {
type Error = anyhow::Error;

fn try_into(self) -> Result<Encoded, Self::Error> {
let sigs: Result<Vec<_>, _> = self.signatures.into_iter().map(|s| s.try_into()).collect();
Ok(Encoded {
payload: Some(self.payload.to_vec()?.into()),
signatures: Some(sigs?),
})
}
}

impl TryFrom<EncodedSignature> for JwsSignature {
type Error = anyhow::Error;

fn try_from(value: EncodedSignature) -> Result<Self, Self::Error> {
Ok(Self {
protected: value.protected.map(|v| Base64String::from(v.as_ref())),
signature: Base64UrlString::from(value.signature.as_ref()),
})
}
}

impl TryInto<EncodedSignature> for JwsSignature {
type Error = anyhow::Error;

fn try_into(self) -> Result<EncodedSignature, Self::Error> {
let protected = self
.protected
.map(|v| v.to_vec())
.transpose()?
.map(|v| v.into());
Ok(EncodedSignature {
protected,
signature: self.signature.to_vec()?.into(),
})
}
}

#[cfg(test)]
Expand All @@ -117,30 +51,6 @@ mod tests {
use ssi::did::Source;
use ssi::jwk::Params;

#[test]
fn should_roundtrip_dag_jose() {
let encoded_hex_str = "a2677061796c6f616458240171122089556551c3926679cc52c72e182a5619056a4727409ee93a26d05ad727ca11f46a7369676e61747572657381a26970726f7465637465644f7b22616c67223a224564445341227d697369676e61747572655840fbff49e4e65c979955b9196023534913373416a11bebfdb256c9146903ddb9c450e287be379ca70a5e7bc039b848fb66d4bd5b96dae986941e04e7968d55b505";
let obj_data = hex::decode(encoded_hex_str).unwrap();
let encoded: Encoded = serde_ipld_dagcbor::from_slice(&obj_data).unwrap();
let jws = Jws::try_from(encoded).unwrap();
assert_eq!(
jws.payload.as_ref(),
"AXESIIlVZVHDkmZ5zFLHLhgqVhkFakcnQJ7pOibQWtcnyhH0"
);
assert_eq!(
jws.link.as_ref(),
"bafyreiejkvsvdq4smz44yuwhfymcuvqzavveoj2at3utujwqlllspsqr6q"
);
assert_eq!(
jws.signatures[0].protected.as_ref().unwrap().as_ref(),
"eyJhbGciOiJFZERTQSJ9"
);
assert_eq!(jws.signatures[0].signature.as_ref(), "-_9J5OZcl5lVuRlgI1NJEzc0FqEb6_2yVskUaQPducRQ4oe-N5ynCl57wDm4SPtm1L1bltrphpQeBOeWjVW1BQ");
let rt_data = jws.encode_dag_jose().unwrap();
assert_eq!(rt_data, obj_data);
assert_eq!(&hex::encode(rt_data.as_slice()), encoded_hex_str);
}

#[tokio::test]
async fn should_produce_verifiable_signatures() {
let key = ssi::jwk::JWK::generate_ed25519().unwrap();
Expand Down
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod bytes;
mod dag_jose;
mod jwk;
mod jws;
mod stream_id;
Expand Down

0 comments on commit fc8f307

Please sign in to comment.