Commit 342af92a authored by Chuck LeDuc Díaz's avatar Chuck LeDuc Díaz
Browse files

tk-120: fixing credentialStatus

parent 14e57d32
Pipeline #99013565 passed with stage
in 4 minutes and 18 seconds
......@@ -2,6 +2,7 @@
"cSpell.words": [
"Anytown",
"Jsonify",
"Keypair",
"Zenroom",
"bindgen",
"chrono",
......@@ -12,7 +13,9 @@
"mnumber",
"odel",
"redential",
"serializer",
"stdweb",
"unbased",
"vcdm",
"wasm"
]
......
[package]
name = "caelum-vcdm"
version = "0.1.3"
version = "0.2.0"
authors = ["Caelum-Labs <tomas@caelumlabs.com>"]
edition = "2018"
readme = "README.md"
......
## Prerequisites
- Clang >= 8.0
clear_on_drop library needs Clang >= 8.0, otherwise clang won't recognize the wasm32-unknown-unknown triple defined by this architecture.
clear_on_drop library needs Clang >= 8.0, otherwise clang won't recognize the wasm32-unknown-unknown triple defined by this architecture.
- Install clang 8.0 in Ubuntu/Debian:
```bash
......@@ -113,7 +113,7 @@ ley keys = vec![
241, 72, 72, 72, 195, 209, 12, 81,
];
// Creating Claim
let c: Claim = serde_json::from_str(r#"{"credentialStatus":{"id":"Hash: 0x8633385811f06e22d5f62eb958c8b1a72a6fbcf59c6f464f9d3b7d086355ab3d","type":"pending"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#).unwrap();
let c: Claim = serde_json::from_str(r#"{"credentialStatus":{"id":"https://lorena.caelumlabs.com/credentials","type":"CaelumEmailCredential","currentStatus":"pending","statusReason":"self-issued"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#).unwrap();
// Proof from claim (signature is created automatically)
let p: Proof = Proof::from_claim_and_keys(
......
......@@ -29,13 +29,17 @@ fn create_credential() -> VerifiableCredential {
fn create_claim() -> Claim {
// Creates Claim
return serde_json::from_str(r#"
{"credentialStatus":{"id":"Hash: 0x8633385811f06e22d5f62eb958c8b1a72a6fbcf59c6f464f9d3b7d086355ab3d",
"type":"pending"},"type":["VerifiableCredential","CaelumEmailCredential"],
return serde_json::from_str(
r#"
{"credentialStatus":{"id":"https://lorena.caelumlabs.com/credentials",
"type":"CaelumEmailCredential","currentStatus":"pending","statusReason":"self-issued"},
"type":["VerifiableCredential","CaelumEmailCredential"],
"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],
"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b",
"issuanceDate":"2019-10-16T14:07:41.657Z",
"issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#).unwrap();
"issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#,
)
.unwrap();
}
fn create_proof(keys: &[u8], c: &Claim) -> Proof {
......@@ -48,7 +52,7 @@ fn create_proof(keys: &[u8], c: &Claim) -> Proof {
* Is it a valid claim?
*/
fn is_valid_claim(v: VerifiableCredential) -> bool {
if v.claims.last().is_some() && v.proofs.last().is_some() {
if v.claims.last().is_some() && v.proofs.last().is_some() {
let c = v.claims.last().unwrap();
let p = v.proofs.last().unwrap();
......
......@@ -6,6 +6,10 @@ pub struct CredentialStatus {
pub id: String,
#[serde(rename(serialize = "type", deserialize = "type"))]
pub credential_status_type: String,
#[serde(rename(serialize = "currentStatus", deserialize = "currentStatus"))]
pub current_status: String,
#[serde(rename(serialize = "statusReason", deserialize = "statusReason"))]
pub status_reason: String,
}
impl Default for CredentialStatus {
......@@ -13,6 +17,8 @@ impl Default for CredentialStatus {
CredentialStatus {
id: "".to_string(),
credential_status_type: "".to_string(),
current_status: "".to_string(),
status_reason: "".to_string(),
}
}
}
......@@ -26,10 +32,17 @@ impl CredentialStatus {
serde_json::to_string(&self).unwrap()
}
pub fn new(id: String, status_type: String) -> Self {
pub fn new(
id: String,
status_type: String,
current_status: String,
status_reason: String,
) -> Self {
CredentialStatus {
id,
credential_status_type: status_type,
current_status,
status_reason,
}
}
}
......@@ -110,7 +110,9 @@ mod tests {
"id": "",
"credentialStatus": {
"id": "",
"type": ""
"type": "",
"currentStatus": "",
"statusReason": ""
},
"credentialSubject": [],
"issuer": "",
......@@ -133,24 +135,24 @@ mod tests {
];
// Create Claim
let claim: Claim = serde_json::from_str(r#"{"credentialStatus":{"id":"Hash: 0x8633385811f06e22d5f62eb958c8b1a72a6fbcf59c6f464f9d3b7d086355ab3d","type":"pending"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#).unwrap();
let claim: Claim = serde_json::from_str(r#"{"credentialStatus":{"id":"https://lorena.caelumlabs.com/credentials","type":"CaelumEmailCredential","currentStatus":"pending","statusReason":"self-issued"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#).unwrap();
// sign Claim
let signature_b64 = claim.sign(&keypair);
assert_eq!(
signature_b64,
"6g8bIdfh2UwcToe1yHUB81xuPWm0XLbaMltQrBTssrs31253s22Bp5OjGsirzOb68AwvBSPY5vtiLfoxzBS1Dg==".to_string()
"LAVMIj9X59o3TL0CtfEWbUT8nUBnHaUwYdE0wVGTlA6yoaBe+OF7yE3c8pLwbYwESYFYHjX7Zsd1/iy6csrSDA==".to_string()
);
// Keypair: [212, 109, 1, 120, 214, 102, 78, 169, 141, 239, 187, 76, 224, 61, 74, 250, 20, 4, 89, 89, 159, 113, 116, 168, 87, 79, 196, 25, 155, 87, 180, 134, 65, 189, 48, 58, 3, 235, 0, 194, 39, 238, 5, 140, 57, 222, 169, 56, 62, 89, 169, 66, 225, 253, 97, 6, 241, 72, 72, 72, 195, 209, 12, 81]
// claim: {"credentialStatus":{"id":"Hash: 0x8633385811f06e22d5f62eb958c8b1a72a6fbcf59c6f464f9d3b7d086355ab3d","type":"pending"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}
// claim: {"credentialStatus":{"id":"https://lorena.caelumlabs.com/credentials","type":"CaelumEmailCredential","currentStatus":"pending","statusReason":"self-issued"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}
// hash of claim: 80464a1d977d369f577d88710cd7f9d3c2278301c268eeab7b89888f68e84fb32d2896c72abc3a8dbaa4c295f66100ac6727916c73c2bea16e86bfcff4365591
// final signature: [20, 43, 243, 210, 195, 178, 255, 149, 243, 64, 46, 59, 46, 12, 150, 14, 239, 73, 70, 9, 111, 183, 100, 157, 65, 139, 90, 245, 89, 176, 44, 8, 230, 39, 111, 242, 163, 151, 161, 6, 169, 9, 123, 100, 180, 157, 60, 90, 160, 123, 167, 190, 253, 184, 20, 85, 19, 47, 178, 129, 105, 52, 216, 7]
}
#[test]
fn test_verify_claim() {
let c: Claim = serde_json::from_str(r#"{"credentialStatus":{"id":"Hash: 0x8633385811f06e22d5f62eb958c8b1a72a6fbcf59c6f464f9d3b7d086355ab3d","type":"pending"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#).unwrap();
let c: Claim = serde_json::from_str(r#"{"credentialStatus":{"id":"https://lorena.caelumlabs.com/credentials","type":"CaelumEmailCredential","currentStatus":"pending","statusReason":"self-issued"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#).unwrap();
let p: Proof = Proof::from_claim_and_keys(
&c,
&vec![
......
......@@ -740,8 +740,10 @@ impl VPresentation {
/// "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
/// "issuanceDate": "2010-01-01T19:73:24Z",
/// "credentialStatus": {
/// "id": "StatusID",
/// "type": "available"
/// "id": "http://example.com/credentialTypes",
/// "type": "PersonalInformation",
/// "currentStatus": "available",
/// "statusReason": "self-declared"
/// },
/// "credentialSubject": [{
/// "type": "did:example:abfab3f512ebc6c1c22de17ec77",
......@@ -865,8 +867,10 @@ impl VPresentation {
/// "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
/// "issuanceDate": "2010-01-01T19:73:24Z",
/// "credentialStatus": {
/// "id": "StatusID",
/// "type": "available"
/// "id": "http://example.com/credentialTypes",
/// "type": "PersonalInformation",
/// "currentStatus": "available",
/// "statusReason": "self-declared"
/// },
/// "credentialSubject": [{
/// "type": "did:example:abfab3f512ebc6c1c22de17ec77",
......@@ -983,8 +987,10 @@ impl VPresentation {
/// "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
/// "issuanceDate": "2010-01-01T19:73:24Z",
/// "credentialStatus": {
/// "id": "StatusID",
/// "type": "available"
/// "id": "http://example.com/credentialTypes",
/// "type": "PersonalInformation",
/// "currentStatus": "available",
/// "statusReason": "self-declared"
/// },
/// "credentialSubject": [{
/// "type": "did:example:abfab3f512ebc6c1c22de17ec77",
......@@ -1049,8 +1055,10 @@ impl VPresentation {
/// "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
/// "issuanceDate": "2010-01-01T19:73:24Z",
/// "credentialStatus": {
/// "id": "StatusID",
/// "type": "available"
/// "id": "http://example.com/credentialTypes",
/// "type": "PersonalInformation",
/// "currentStatus": "available",
/// "statusReason": "self-declared"
/// },
/// "credentialSubject": [{
/// "type": "did:example:abfab3f512ebc6c1c22de17ec77",
......@@ -1066,7 +1074,7 @@ impl VPresentation {
/// "signatureValue": "pY9...Cky6Ed = "
/// }]
/// }"#).unwrap());
/// console.log(vp.getVerifialbleCredential());
/// console.log(vp.getVerifiableCredential());
/// ```
/// The code above will print in console the following:
/// ```json
......@@ -1083,8 +1091,10 @@ impl VPresentation {
/// "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
/// "issuanceDate": "2010-01-01T19:73:24Z",
/// "credentialStatus": {
/// "id": "StatusID",
/// "type": "available"
/// "id": "http://example.com/credentialTypes",
/// "type": "PersonalInformation",
/// "currentStatus": "available",
/// "statusReason": "self-declared"
/// },
/// "credentialSubject": [{
/// "type": "did:example:abfab3f512ebc6c1c22de17ec77",
......@@ -1103,7 +1113,7 @@ impl VPresentation {
/// }
/// ```
///
#[wasm_bindgen(js_name = getVerifialbleCredential)]
#[wasm_bindgen(js_name = getVerifiableCredential)]
pub fn get_verifiable_credential(&self) -> JsValue {
let vp: VerifiablePresentation = self.ctx.into_serde().unwrap();
JsValue::from_serde(&vp.verifiable_credential).unwrap()
......
......@@ -82,12 +82,12 @@ mod tests {
194, 39, 238, 5, 140, 57, 222, 169, 56, 62, 89, 169, 66, 225, 253, 97, 6, 241, 72, 72,
72, 195, 209, 12, 81,
];
let claim: Claim = serde_json::from_str(r#"{"credentialStatus":{"id":"Hash: 0x8633385811f06e22d5f62eb958c8b1a72a6fbcf59c6f464f9d3b7d086355ab3d","type":"pending"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#).unwrap();
let claim: Claim = serde_json::from_str(r#"{"credentialStatus":{"id":"https://lorena.caelumlabs.com/credentials","type":"CaelumEmailCredential","currentStatus":"pending","statusReason":"self-issued"},"type":["VerifiableCredential","CaelumEmailCredential"],"credentialSubject":[{"email":"asd","last":"","type":"CaelumEmailCredential","first":""}],"id":"Hash: 0xa76745d559991b293036244416c6818b15d8debf6960151d4c6abf5b284fbb1b","issuanceDate":"2019-10-16T14:07:41.657Z","issuer":"did:lrn:caelum-email-verifier:ebfeb1276e12ec21f712ebc6f1c#k2"}"#).unwrap();
let a = Proof::from_claim_and_keys(&claim, &keys);
assert_eq!(
&a.signature_value,
"6g8bIdfh2UwcToe1yHUB81xuPWm0XLbaMltQrBTssrs31253s22Bp5OjGsirzOb68AwvBSPY5vtiLfoxzBS1Dg=="
"LAVMIj9X59o3TL0CtfEWbUT8nUBnHaUwYdE0wVGTlA6yoaBe+OF7yE3c8pLwbYwESYFYHjX7Zsd1/iy6csrSDA=="
);
assert_eq!(
&a.verification_method,
......
......@@ -88,7 +88,7 @@ impl VerifiableCredential {
/// id: "id_credential",
/// claims: [{
/// id: "",
/// credentialStatus: { id: "", type: "" },
/// credentialStatus: { id: "", type: "", "currentStatus": "", "statusReason": "" },
/// credentialSubject: [{
/// email: "example@example.com"
/// }],
......@@ -201,7 +201,9 @@ mod tests {
"id": "",
"credentialStatus": {
"id": "",
"type": ""
"type": "",
"currentStatus": "",
"statusReason": ""
},
"credentialSubject": [],
"issuer": "",
......
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