DidDocument.fromJson constructor
DidDocument.fromJson(
- dynamic jsonObject
Implementation
DidDocument.fromJson(dynamic jsonObject) {
var document = credentialToMap(jsonObject);
if (document.containsKey('@context')) {
context = document['@context'].cast<String>();
}
if (document.containsKey('id')) {
id = document['id'];
} else {
throw FormatException('id property needed in did document');
}
if (document.containsKey('alsoKnownAs')) {
alsoKnownAs = document['alsoKnownAs'].cast<String>();
}
controller = document['controller'];
if (controller != null) {
if (controller is! String || controller is! List) {
throw Exception('controller must be a String or a List');
}
}
if (document.containsKey('verificationMethod')) {
List tmp = document['verificationMethod'];
if (tmp.isNotEmpty) {
verificationMethod = [];
for (var v in tmp) {
verificationMethod!.add(VerificationMethod.fromJson(v));
}
}
}
if (document.containsKey('authentication')) {
List tmp = document['authentication'];
if (tmp.isNotEmpty) {
authentication = [];
for (var v in tmp) {
if (v is String) {
authentication!.add(v);
} else if (v is Map<String, dynamic>) {
authentication!.add(VerificationMethod.fromJson(v));
} else {
throw FormatException('unknown Datatype');
}
}
}
}
if (document.containsKey('keyAgreement')) {
List tmp = document['keyAgreement'];
if (tmp.isNotEmpty) {
keyAgreement = [];
for (var v in tmp) {
if (v is String) {
keyAgreement!.add(v);
} else if (v is Map<String, dynamic>) {
keyAgreement!.add(VerificationMethod.fromJson(v));
} else {
throw FormatException('unknown Datatype');
}
}
}
}
if (document.containsKey('assertionMethod')) {
List tmp = document['assertionMethod'];
if (tmp.isNotEmpty) {
assertionMethod = [];
for (var v in tmp) {
if (v is String) {
assertionMethod!.add(v);
} else if (v is Map<String, dynamic>) {
assertionMethod!.add(VerificationMethod.fromJson(v));
} else {
throw FormatException('unknown Datatype');
}
}
}
}
if (document.containsKey('capabilityInvocation')) {
List tmp = document['capabilityInvocation'];
if (tmp.isNotEmpty) {
capabilityInvocation = [];
for (var v in tmp) {
if (v is String) {
capabilityInvocation!.add(v);
} else if (v is Map<String, dynamic>) {
capabilityInvocation!.add(VerificationMethod.fromJson(v));
} else {
throw FormatException('unknown Datatype');
}
}
}
}
if (document.containsKey('capabilityDelegation')) {
List tmp = document['capabilityDelegation'];
if (tmp.isNotEmpty) {
capabilityDelegation = [];
for (var v in tmp) {
if (v is String) {
capabilityDelegation!.add(v);
} else if (v is Map<String, dynamic>) {
capabilityDelegation!.add(VerificationMethod.fromJson(v));
} else {
throw FormatException('unknown Datatype');
}
}
}
}
if (document.containsKey('service')) {
List tmp = document['service'];
if (tmp.isNotEmpty) {
service = [];
for (var v in tmp) {
service!.add(ServiceEndpoint.fromJson(v));
}
}
}
}