decode method

  1. @override
Future<String?> decode(
  1. String topic,
  2. String encoded, {
  3. DecodeOptions? options,
})
override

Implementation

@override
Future<String?> decode(
  String topic,
  String encoded, {
  DecodeOptions? options,
}) async {
  _checkInitialized();

  final EncodingValidation params = utils.validateDecoding(
    encoded,
    receiverPublicKey: options?.receiverPublicKey,
  );

  if (utils.isTypeTwoEnvelope(params)) {
    return utils.decodeTypeTwoEnvelope(message: encoded);
  }

  if (utils.isTypeOneEnvelope(params)) {
    final String selfPublicKey = params.receiverPublicKey!;
    final String peerPublicKey = params.senderPublicKey!;
    topic = await generateSharedKey(selfPublicKey, peerPublicKey);
  }
  final String? symKey = _getSymKey(topic);
  if (symKey == null) {
    return null;
  }

  final String message = await utils.decrypt(symKey, encoded);

  return message;
}