DidcommSignedMessage.fromJson constructor

DidcommSignedMessage.fromJson(
  1. dynamic jsonObject
)

Implementation

DidcommSignedMessage.fromJson(dynamic jsonObject) {
  var sig = credentialToMap(jsonObject);
  if (sig.containsKey('payload')) {
    _base64Payload = sig['payload'];
    var decodedPayload =
        utf8.decode(base64Decode(addPaddingToBase64(sig['payload'])));
    try {
      payload = DidcommSignedMessage.fromJson(decodedPayload);
    } catch (e) {
      try {
        payload = DidcommPlaintextMessage.fromJson(decodedPayload);
      } catch (e) {
        try {
          payload = DidcommEncryptedMessage.fromJson(decodedPayload);
        } catch (e) {
          throw Exception('Unknown message type');
        }
      }
    }
  } else {
    throw Exception('payload is needed in jws');
  }
  if (sig.containsKey('signatures')) {
    List tmp = sig['signatures'];
    if (tmp.isNotEmpty) {
      signatures = [];
      for (var s in tmp) {
        signatures!.add(SignatureObject.fromJson(s));
      }
    } else {
      throw Exception('Empty Signatures');
    }
  } else {
    throw Exception('signature property is needed in jws');
  }
}