MatrixSignableKey.fromJson constructor

MatrixSignableKey.fromJson(
  1. Map<String, Object?> json
)

Implementation

MatrixSignableKey.fromJson(Map<String, Object?> json)
    : _json = json,
      userId = json['user_id'] as String,
      keys = Map<String, String>.from(json['keys'] as Map<String, Object?>),
      // we need to manually copy to ensure that our map is Map<String, Map<String, String>>
      signatures = (() {
        final orig = json.tryGetMap<String, Object?>('signatures');
        final res = <String, Map<String, String>>{};
        for (final entry
            in (orig?.entries ?? <MapEntry<String, Object?>>[])) {
          final deviceSigs = entry.value;
          if (deviceSigs is Map<String, Object?>) {
            for (final nestedEntry in deviceSigs.entries) {
              final nestedValue = nestedEntry.value;
              if (nestedValue is String) {
                (res[entry.key] ??= <String, String>{})[nestedEntry.key] =
                    nestedValue;
              }
            }
          }
        }
        return res;
      }()),
      unsigned = json.tryGetMap<String, Object?>('unsigned')?.copy();