Commit bc53322e authored by tizgafa's avatar tizgafa Committed by tizgafa
Browse files

TK-68: Add nonRevocationProof with zenroom structure #2

parent db8f36b9
Pipeline #94013938 passed with stage
in 4 minutes and 47 seconds
......@@ -111,6 +111,34 @@ impl VProof {
}
}
///
/// # WebAssembly gateway for ZenroomProofs
///
#[wasm_bindgen]
pub struct VNonRevocationProof {
ctx: JsValue,
}
#[wasm_bindgen]
impl VNonRevocationProof {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
let d = NonRevocationProof::default();
VNonRevocationProof { ctx: d.to_json() }
}
#[wasm_bindgen(js_name = fromJSON)]
pub fn from_json(json: JsValue) -> Self {
let vc: NonRevocationProof = json.into_serde().unwrap();
VNonRevocationProof { ctx: vc.to_json() }
}
#[wasm_bindgen(js_name = toJSON)]
pub fn to_json(&self) -> JsValue {
self.ctx.clone()
}
}
///
/// # WebAssembly gateway for Claims
///
......
......@@ -2,6 +2,52 @@ use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ZenroomSignature {
r: String,
s: String,
}
impl Default for ZenroomSignature {
fn default() -> Self {
ZenroomSignature {
r: "".to_string(),
s: "".to_string(),
}
}
}
impl ZenroomSignature {
pub fn to_str(&self) -> String {
serde_json::to_string(&self).unwrap()
}
pub fn from_json(json: JsValue) -> Self {
json.into_serde().unwrap()
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ZenroomProof {
draft: String,
signature: ZenroomSignature,
}
impl Default for ZenroomProof {
fn default() -> Self {
ZenroomProof {
draft: "".to_string(),
signature: ZenroomSignature::default(),
}
}
}
impl ZenroomProof {
pub fn to_str(&self) -> String {
serde_json::to_string(&self).unwrap()
}
pub fn from_json(json: JsValue) -> Self {
json.into_serde().unwrap()
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NonRevocationProof {
#[serde(rename(serialize = "type", deserialize = "type"))]
......@@ -11,6 +57,7 @@ pub struct NonRevocationProof {
pub verification_method: String,
#[serde(rename(serialize = "signatureValue", deserialize = "signatureValue"))]
pub signature_value: String,
pub zenroom: ZenroomProof,
}
impl Default for NonRevocationProof {
......@@ -20,6 +67,7 @@ impl Default for NonRevocationProof {
created: "".to_string(),
verification_method: "".to_string(),
signature_value: "".to_string(),
zenroom: ZenroomProof::default(),
}
}
}
......@@ -30,20 +78,73 @@ impl NonRevocationProof {
created: String,
verification_method: String,
signature_value: String,
zenroom: ZenroomProof,
) -> Self {
NonRevocationProof {
auth_type,
created,
verification_method,
signature_value,
zenroom,
}
}
pub fn from_json(json: JsValue) -> Self {
json.into_serde().unwrap()
}
pub fn to_str(&self) -> String {
serde_json::to_string(&self).unwrap()
}
pub fn from_json(json: JsValue) -> Self {
json.into_serde().unwrap()
pub fn to_json(&self) -> JsValue {
JsValue::from_serde(&self).unwrap()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_zenroom_signature() {
let nrp: ZenroomSignature = serde_json::from_str(r#"{
"r": "u64:HeYdIQ2QY3qdMVtZshqN-vOqeVnh1z6VC5LhkwizVadMONKrWPT08U8cN1hZeH-wQHY8_w4Xbwg",
"s": "u64:ExnZWn0keKZrTcICVIPrVdWzWiS7pu2aKdIuOt407NbPGaJJBhiPwxAT2speEBc7VtXEqhyPSjs"
}"#).unwrap();
println!("{:#?}", nrp)
}
#[test]
fn test_zenroom_proof() {
let nrp: ZenroomProof = serde_json::from_str(r#"{
"draft": "u64:W29iamVjdF9PYmplY3Rd",
"signature": {
"r": "u64:HeYdIQ2QY3qdMVtZshqN-vOqeVnh1z6VC5LhkwizVadMONKrWPT08U8cN1hZeH-wQHY8_w4Xbwg",
"s": "u64:ExnZWn0keKZrTcICVIPrVdWzWiS7pu2aKdIuOt407NbPGaJJBhiPwxAT2speEBc7VtXEqhyPSjs"
}
}"#).unwrap();
println!("{:#?}", nrp)
}
#[test]
fn test_non_revocation_proof() {
let nrp: NonRevocationProof = serde_json::from_str(
r#"{
"type": "",
"created": "",
"verificationMethod": "",
"signatureValue": "",
"zenroom": {
"draft": "",
"signature": {
"r": "",
"s": ""
}
}
}"#,
)
.unwrap();
println!("{:#?}", nrp)
}
}
......@@ -218,7 +218,14 @@ mod tests {
"type": "",
"created": "",
"verificationMethod": "",
"signatureValue": ""
"signatureValue": "",
"zenroom": {
"draft": "",
"signature": {
"r": "",
"s": ""
}
}
}]
}
"#;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment