OutOfBandMessage.fromJson constructor

OutOfBandMessage.fromJson(
  1. dynamic jsonObject
)

Implementation

OutOfBandMessage.fromJson(super.jsonObject) : super.fromJson() {
  if (type != DidcommMessages.invitation) {
    throw Exception('Wrong message type');
  }
  if (from == null) throw FormatException('from property needed');
  if (typ != null && typ != DidcommMessageTyp.plain) {
    throw Exception(
        'Out of band Message is expected to be a Plaintext-message');
  }
  goalCode = body['goal_code'];
  goal = body['goal'];
  if (body.containsKey('accept')) {
    List acc = body['accept'];
    if (acc.isNotEmpty) {
      accept = [];
      for (String a in acc) {
        switch (a) {
          case 'didcomm/aip1':
            accept!.add(DidcommProfiles.aip1);
            break;
          case 'didcomm/aip2;env=rfc19':
            accept!.add(DidcommProfiles.rfc19);
            break;
          case 'didcomm/aip2;env=rfc587':
            accept!.add(DidcommProfiles.rfc587);
            break;
          case 'didcomm/v2':
            accept!.add(DidcommProfiles.v2);
            break;
          default:
            throw Exception('Unknown Profile');
        }
      }
    }
  }
}