VPRequestMessage.fromJson constructor

VPRequestMessage.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory VPRequestMessage.fromJson(Map<String, dynamic> json) {
  try {
    if (json.containsKey("type") && json["type"] != "VPReq") {
      throw Exception("Invalid type");
    }
    List<RequestVC> vcRequirements =
        (json["body"]["vcRequirements"] as List<dynamic>)
            .map<RequestVC>((vc) => RequestVC.fromJson(vc))
            .toList();

    return VPRequestMessage(
      id: json["id"],
      from: json["from"],
      to: (json["to"] as List<dynamic>)
          .map<String>((e) => e.toString())
          .toList(),
      createdTime: json.containsKey("createdTime") ? json["createdTime"] : 0,
      expiresTime: json.containsKey("expiresTime") ? json["expiresTime"] : 0,
      vcRequirements: vcRequirements,
      challenge: json["body"]["challenge"],
    );
  } catch (e) {
    print("Error in VPRequestMessage.fromJson: $e");
    rethrow;
  }
}