Skip to content

Commit

Permalink
Given selectors, return n-quad positions
Browse files Browse the repository at this point in the history
  • Loading branch information
thefireskater committed Jun 4, 2023
1 parent 3e31829 commit aaa0d85
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ssi-jws/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ pub fn verify_payload(
assert!(credential_subject_id != "", "credentialSubject node not found");

let mut first_claim_found = false;

i = 0;
while i < payload.messages.len() {
let m = payload.messages[i].as_str();
if m.starts_with(credential_subject_id) {
Expand All @@ -368,9 +370,11 @@ pub fn verify_payload(
assert!(first_claim_found, "No claims in derived credential");

for j in 0..message_hashes.len() {
//eprintln!("Checking hash for {}: ", payload.messages[i].as_str());
let revealed_hash = message_hashes[j];
let target_hash = SignatureMessage::hash(payload.messages[i].as_bytes());
if revealed_hash != target_hash {
//eprintln!("Hashes do not match");
return Err(Error::InvalidSignature);
}

Expand Down
11 changes: 11 additions & 0 deletions ssi-ldp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,17 @@ fn rename_blank_node_labels(orig: &Vec<String>) -> Vec<String> {
rewritten
}

pub async fn to_nquads(
document: &(dyn LinkedDataDocument + Sync),
context_loader: &mut ContextLoader,
) -> Result<Vec<String>, Error> {
let doc_dataset = document
.to_dataset_for_signing(None, context_loader)
.await?;
let doc_normalized = urdna2015::normalize(doc_dataset.quads().map(QuadRef::from)).into_nquads_vec();
Ok(doc_normalized)
}

async fn to_jws_payload_v2(
document: &(dyn LinkedDataDocument + Sync),
proof: &Proof,
Expand Down
1 change: 1 addition & 0 deletions ssi-ldp/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pub struct LinkedDataProofOptions {
#[serde(skip_serializing_if = "Option::is_none")]
/// The nonce of the proof.
pub nonce: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
/// Indices of disclosed messages
pub disclosed_message_indices: Option<Vec<usize>>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
22 changes: 22 additions & 0 deletions ssi-vc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ impl Credential {
resolver: &dyn DIDResolver,
context_loader: &mut ContextLoader,
) -> VerificationResult {
// this is the entrypoint called by didkit
let nonce = match options.as_ref() {
Some(ldp_options) => ldp_options.nonce.clone(),
None => None
Expand Down Expand Up @@ -1096,6 +1097,27 @@ impl Credential {
result.checks.push(Check::Status);
result
}

pub async fn get_nquad_positions(&self, selectors: &Vec<String>, context_loader: &mut ContextLoader) -> Result<Vec<u32>, Error> {
let nquads = ssi_ldp::to_nquads(self, context_loader).await?;
let mut positions = Vec::new();
let mut index: u32 = 2;
for nq in nquads.iter() {
let split: Vec<&str> = nq.split(" ").collect();
let middle = split[1];

for s in selectors.iter() {
let suffix = "/".to_owned() + s + ">";
if middle.ends_with(suffix.as_str()) {
positions.push(index);
break;
}
}

index += 1;
}
Ok(positions)
}
}

impl CheckableStatus {
Expand Down

0 comments on commit aaa0d85

Please sign in to comment.