Skip to content
Merged
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
21 changes: 21 additions & 0 deletions wasm-attestation-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,24 @@ pub fn get_user_data(attestation_doc: &str) -> Result<Option<Vec<u8>>, JsValue>
))),
}
}

/// Given an attestation document, return the nonce if it exists
#[wasm_bindgen(js_name = getNonce)]
pub fn get_nonce(attestation_doc: &str) -> Result<Option<Vec<u8>>, JsValue> {
let decoded_ad = match BASE64_STANDARD.decode(attestation_doc.as_bytes()) {
Ok(ad) => ad,
Err(e) => {
return Err(JsValue::from_str(&format!(
"Failed to decode attestation document: {:?}",
e
)))
}
};
match decode_attestation_document(&decoded_ad) {
Ok((_, doc)) => Ok(doc.nonce.map(|buf| buf.to_vec())),
Err(e) => Err(JsValue::from_str(&format!(
"Failed to decode attestation document: {:?}",
e
))),
}
}