Skip to content

Commit

Permalink
Temporary work around for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
oeed committed Nov 8, 2021
1 parent ca38042 commit df6f818
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nzcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ p256 = {version = "0.9.0", features = ["ecdsa"]}
serde = {version = "~1", features = ["derive"]}
serde_bytes = "0.11.5"
serde_cbor = {version = "0.11.2", features = ["tags"]}
serde_json = "~1"
ssi = "0.3.0"
thiserror = "1"
uuid = {version = "0.8.2", features = ["serde"]}

[dev-dependencies]
hex = "0.4.3"
serde_json = "~1"
tokio = {version = "1.13.0", features = ["full"]}
41 changes: 35 additions & 6 deletions nzcp/src/decentralised_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,41 @@ impl<'a> DecentralizedIdentifier<'a> {
}

async fn resolve_document(&self) -> Result<Document, DecentralizedIdentifierError> {
let (metadata, document, _) = DIDWeb.resolve(&self.did(), &ResolutionInputMetadata::default()).await;
// TODO: horrifically disgusting temporary work around for https://github.com/vaxxnz/nzcp-rust/issues/1
let (metadata, doc_data, _) = DIDWeb
.resolve_representation(&self.did(), &ResolutionInputMetadata::default())
.await;
let doc_opt: Option<serde_json::Value> = if doc_data.is_empty() {
None
}
else {
match serde_json::from_slice(&doc_data) {
Ok(doc) => doc,
Err(err) => return Err(DecentralizedIdentifierError::ResolutionError(err.to_string())),
}
};

let document = doc_opt
.and_then(|mut doc_opt| {
if let Some(id) = doc_opt.get_mut("@context") {
match id {
serde_json::Value::String(id) => {
*id = String::from("https://www.w3.org/ns/did/v1");
Some(
serde_json::from_value(doc_opt)
.map_err(|err| DecentralizedIdentifierError::ResolutionError(err.to_string())),
)
}
_ => None,
}
}
else {
None
}
})
.transpose()?;

// let (metadata, document, _) = DIDWeb.resolve(&self.did(), &ResolutionInputMetadata::default()).await;

if let Some(error) = metadata.error {
Err(DecentralizedIdentifierError::ResolutionError(error))
Expand Down Expand Up @@ -162,8 +196,3 @@ impl<'a> DecentralizedIdentifier<'a> {
}
}
}

// pub struct PublicKey {
// pub x: Base64urlUInt,
// pub y: Base64urlUInt,
// }

0 comments on commit df6f818

Please sign in to comment.