isSessionCompatible function
Implementation
bool isSessionCompatible(
SessionStruct session,
ProposalRequiredNamespaces requiredNamespaces,
) {
final sessionKeys = session.namespaces.keys.toList();
final paramsKeys = requiredNamespaces.keys.toList();
bool compatible = true;
if (!hasOverlap(paramsKeys, sessionKeys)) return false;
sessionKeys.forEach((key) {
final sessionNamespace = session.namespaces[key]!;
final accounts = sessionNamespace.accounts;
final methods = sessionNamespace.methods;
final events = sessionNamespace.events;
final extension = sessionNamespace.extension;
final chains = getAccountsChains(accounts);
final requiredNamespace = requiredNamespaces[key]!;
if (!hasOverlap(requiredNamespace.chains, chains) ||
!hasOverlap(requiredNamespace.methods, methods) ||
!hasOverlap(requiredNamespace.events, events)) {
compatible = false;
}
if (compatible && extension != null) {
extension.forEach((extensionNamespace) {
final accounts = extensionNamespace.accounts;
final methods = extensionNamespace.methods;
final events = extensionNamespace.events;
final chains = getAccountsChains(accounts);
final overlap = requiredNamespace.extension?.any(
(ext) =>
hasOverlap(ext.chains, chains) &&
hasOverlap(ext.methods, methods) &&
hasOverlap(ext.events, events),
) ??
false;
if (!overlap) compatible = false;
});
}
});
return compatible;
}