IOTA Identity - Credentials
This crate contains types representing verifiable credentials and verifiable presentations as defined in the W3C Verifiable Credentials Data Model.
The IOTA Identity Framework Wiki provides an overview of verifiable credentials and demonstrates how they may be constructed using the building blocks from this crate.
Construction
This crate follows the builder pattern for the creation of Credentials and Presentations.
Example - Credential
Constructing a Credential using the CredentialBuilder.
use Credential;
use CredentialBuilder;
use Subject;
use Issuer;
use Url;
use Timestamp;
use json;
use Value;
// Construct a `Subject` from json
let json_subject: Value = json!;
let subject: Subject = from_value.unwrap;
// Construct an `Issuer` from json
let json_issuer: Value = json!;
let issuer: Issuer = from_value.unwrap;
let credential: Credential = default
.context
.id
.type_
.subject
.issuer
.issuance_date
.build
.unwrap;
Important
The generated Credential is not verifiable until it has been signed by the issuer's DID Document.
Example - Presentation
Constructing a Presentation using the PresentationBuilder.
use Credential;
use Presentation;
use PresentationBuilder;
use Url;
// Build a presentation for the given holder and iterator of credentials
Important
A Presentation is not verifiable until signed by the holder's DID Document. All Credentials contained in the presentation must also be signed by their respective issuers.
JSON Serialization
The Credential and Presentation types both implement the Serialize and Deserialize traits from the serde crate. Hence one can use the serde_json crate to obtain Credentials and Presentations from JSON.
Example
Deserializing a Presentation from JSON.
use Presentation;
use serde_json;
let presentation_json: &'static str = r#"{
"@context": "https://www.w3.org/2018/credentials/v1",
"id": "http://example.org/credentials/3732",
"type": "VerifiablePresentation",
"verifiableCredential": [
{
"@context": "https://www.w3.org/2018/credentials/v1",
"id": "https://example.edu/credentials/3732",
"type": [
"VerifiableCredential",
"UniversityDegreeCredential"
],
"credentialSubject": {
"id": "did:iota:4LCrrVYFQkYYn9VPejhebmMhNnCq24pYPao8yvVLwVje",
"GPA": "4.0",
"degree": {
"name": "Bachelor of Science and Arts",
"type": "BachelorDegree"
},
"name": "Alice"
},
"issuer": "did:iota:H3PBNPtLYkVaPpMQVz1R3LeT5zW1Hd6BXQmdtFptaGLR",
"issuanceDate": "2019-01-01T00:00:00Z",
"expirationDate": "2024-01-01T00:00:00Z",
"nonTransferable": true,
"proof": {
"type": "JcsEd25519Signature2020",
"verificationMethod": "did:iota:H3PBNPtLYkVaPpMQVz1R3LeT5zW1Hd6BXQmdtFptaGLR#sign-0",
"signatureValue": "5H2TSAG3cHnVEt7HZgg6aeYqmzKRQr9BTaP6mgHSE9uH9iLy7pK7TC2A5NHaiiFMGGaY3hJS5WUhfqCW3APxFhSP"
}
},
{
"@context": "https://www.w3.org/2018/credentials/v1",
"id": "https://example.edu/credentials/3732",
"type": [
"VerifiableCredential",
"UniversityDegreeCredential"
],
"credentialSubject": {
"id": "did:iota:b5DtNBzvJfz8jrX1FYYxgvHqvsoFofy1hxzPRMM5iH1",
"GPA": "4.0",
"degree": {
"name": "Bachelor of Science and Arts",
"type": "BachelorDegree"
},
"name": "Alice"
},
"issuer": "did:iota:7RD6LT5aSNuKMLJJYorGzhktpTG2TrxGSLmHnWW1Dbb",
"issuanceDate": "2020-01-01T00:00:00Z",
"expirationDate": "2023-01-01T00:00:00Z",
"proof": {
"type": "JcsEd25519Signature2020",
"verificationMethod": "did:iota:7RD6LT5aSNuKMLJJYorGzhktpTG2TrxGSLmHnWW1Dbb#sign-0",
"signatureValue": "4QYkkDLDCZxfa6mymhGTGvG4NRgzdx5Txst7dM6jtfDpBV3Mif8hWH93RzR2MoVCtMgZf3ed7qoZsqepWkp4x9oU"
}
}
],
"holder": "did:iota:4LCrrVYFQkYYn9VPejhebmMhNnCq24pYPao8yvVLwVje",
"proof": {
"type": "JcsEd25519Signature2020",
"verificationMethod": "did:iota:4LCrrVYFQkYYn9VPejhebmMhNnCq24pYPao8yvVLwVje#sign-0",
"signatureValue": "47YLi81cr8atfiyydTe4o989V8GBWZk6rVtvE5bAydhbd8HCK5c3wrNXRbBDAF8PDUBGGGqn8ZjA3jxGDFpQwGAW",
"challenge": "475a7984-1bb5-4c4c-a56f-822bccd46440"
}
}
"#;
let presentation: Presentation = from_str.unwrap;