VerifiableCredential.fromJson constructor
VerifiableCredential.fromJson(
- dynamic jsonObject
Implementation
VerifiableCredential.fromJson(dynamic jsonObject) {
var credential = credentialToMap(jsonObject);
if (credential.containsKey('@context')) {
context = credential['@context'];
} else {
throw FormatException(
'@context property is needed in verifiable credential');
}
if (credential.containsKey('type')) {
type = credential['type'].cast<String>();
} else {
throw FormatException('type property is needed in verifiable credential');
}
if (credential.containsKey('issuer')) {
issuer = credential['issuer'];
} else {
throw FormatException(
'issuer property is needed in verifiable credential');
}
if (credential.containsKey('credentialSubject')) {
{
credentialSubject = credential['credentialSubject'];
if (credentialSubject is! Map<String, dynamic>) {
if (credentialSubject is! List) {
throw FormatException(
'Credential subject property must be a Map or List (dart json Object)');
}
}
}
} else {
throw FormatException(
'credential subject property is needed in verifiable credential');
}
if (credential.containsKey('issuanceDate')) {
issuanceDate = DateTime.parse(credential['issuanceDate']);
} else {
throw FormatException(
'issuanceDate property is needed in verifiable credential');
}
id = credential['id'];
if (credential.containsKey('expirationDate')) {
expirationDate = DateTime.parse(credential['expirationDate']);
}
if (credential.containsKey('credentialStatus')) {
status = CredentialStatus.fromJson(credential['credentialStatus']);
}
if (credential.containsKey('proof')) {
proof = LinkedDataProof.fromJson(credential['proof']);
}
if (credential.containsKey('credentialSchema')) {
credentialSchema =
CredentialStatus.fromJson(credential['credentialSchema']);
}
_originalDoc = credential;
}