import 'package:arbiter/features/connection/connection.dart'; import 'package:arbiter/proto/user_agent.pb.dart'; import 'package:protobuf/well_known_types/google/protobuf/empty.pb.dart'; Future> readClientWalletAccess( Connection connection, { required int clientId, }) async { final response = await connection.ask( UserAgentRequest(listWalletAccess: Empty()), ); if (!response.hasListWalletAccessResponse()) { throw Exception( 'Expected list wallet access response, got ${response.whichPayload()}', ); } return { for (final access in response.listWalletAccessResponse.accesses) if (access.clientId == clientId) access.walletId, }; } Future writeClientWalletAccess( Connection connection, { required int clientId, required Set walletIds, }) async { final current = await readClientWalletAccess(connection, clientId: clientId); final toGrant = walletIds.difference(current); final toRevoke = current.difference(walletIds); if (toGrant.isNotEmpty) { await connection.tell( UserAgentRequest( grantWalletAccess: SdkClientGrantWalletAccess( accesses: [ for (final walletId in toGrant) SdkClientWalletAccess(clientId: clientId, walletId: walletId), ], ), ), ); } if (toRevoke.isNotEmpty) { await connection.tell( UserAgentRequest( revokeWalletAccess: SdkClientRevokeWalletAccess( accesses: [ for (final walletId in toRevoke) SdkClientWalletAccess(clientId: clientId, walletId: walletId), ], ), ), ); } }