isSessionCompatible static method

bool isSessionCompatible({
  1. required SessionData session,
  2. required Map<String, RequiredNamespace> requiredNamespaces,
})

Implementation

static bool isSessionCompatible({
  required SessionData session,
  required Map<String, RequiredNamespace> requiredNamespaces,
}) {
  List<String> sessionKeys = session.namespaces.keys.toList();
  List<String> paramsKeys = requiredNamespaces.keys.toList();
  bool compatible = true;

  if (!isContainedIn(container: sessionKeys, contained: paramsKeys)) {
    return false;
  }

  for (var key in sessionKeys) {
    Namespace namespace = session.namespaces[key]!;
    RequiredNamespace requiredNamespace = requiredNamespaces[key]!;
    List<String> requiredNamespaceChains =
        NamespaceUtils.getChainsFromRequiredNamespace(
      nsOrChainId: key,
      requiredNamespace: requiredNamespace,
    );
    List<String> namespaceChains = NamespaceUtils.getChainIdsFromNamespace(
      nsOrChainId: key,
      namespace: namespace,
    );

    // Check the chains, methods and events for overlaps.
    // If any of them don't have it, we fail.
    final bool chainsOverlap = isContainedIn(
      container: namespaceChains,
      contained: requiredNamespaceChains,
    );
    final bool methodsOverlap = isContainedIn(
      container: namespace.methods,
      contained: requiredNamespaces[key]!.methods,
    );
    final bool eventsOverlap = isContainedIn(
      container: namespace.events,
      contained: requiredNamespaces[key]!.events,
    );

    if (!chainsOverlap || !methodsOverlap || !eventsOverlap) {
      compatible = false;
    }
  }

  return compatible;
}