refactor(trust): ego-centric trust replaces the global Duniter membership

The global membership rule (curated bootstrap referents + sigQty/stepMax
parameters) solved sybil-proof identity for a UBI — a problem this app
doesn't have — and its screen leaked graph jargon (npub roots, parameter
steppers). Trust is now computed from the user's own position only:
you vouch / vouched by people you know (distance <=2) / vouched by N.

- TrustCubit: drop networkMember tier, referents and params; keep the
  circle rule and the 365-day vouch expiry (renewable, self-pruning).
- Delete TrustReferents, WotSettings, TrustNetworkScreen and the bundled
  referents asset; unwire injector/bootstrap/app/chat.
- New 'Your people' screen (/your-people, from the profile): who you
  vouch for (revocable) and who vouches for you, names via ProfileCache.
- i18n: wot.* removed, yourPeople.* added (en/es/pt/ast); trust.member
  removed. Kind 30777 events on relays stay fully compatible — only the
  interpretation changes.
This commit is contained in:
vjrj 2026-07-11 13:03:20 +02:00
parent 4af90876f4
commit dc7b2eee27
25 changed files with 595 additions and 863 deletions

View file

@ -13,9 +13,7 @@ import '../services/message_store.dart';
import '../services/profile_cache.dart';
import '../services/social_connection.dart';
import '../services/social_service.dart';
import '../services/trust_referents.dart';
import '../services/unread_service.dart';
import '../services/wot_settings.dart';
import '../state/messages_cubit.dart';
import '../state/trust_cubit.dart';
import 'peer_avatar.dart';
@ -31,8 +29,6 @@ class ChatScreen extends StatefulWidget {
required this.peerPubkey,
this.messageStore,
this.profileCache,
this.trustReferents,
this.wotSettings,
super.key,
});
@ -49,10 +45,6 @@ class ChatScreen extends StatefulWidget {
/// Optional cache of peer display names; null in tests.
final ProfileCache? profileCache;
/// Web-of-trust bootstrap referents + parameters, for the membership verdict.
final TrustReferents? trustReferents;
final WotSettings? wotSettings;
@override
State<ChatScreen> createState() => _ChatScreenState();
}
@ -88,8 +80,6 @@ class _ChatScreenState extends State<ChatScreen> {
// connected / unreachable) null transports and the screen degrades.
final session = await widget.connection.session();
final cachedName = await widget.profileCache?.name(widget.peerPubkey);
final referents = await widget.trustReferents?.all() ?? const <String>{};
final wotParams = await widget.wotSettings?.params() ?? WotParams.duniter;
if (!mounted) return; // shared session is owned by the connection, not us
final self = widget.social.publicKeyHex;
final messages = MessagesCubit(
@ -102,8 +92,6 @@ class _ChatScreenState extends State<ChatScreen> {
session?.trust,
peerPubkey: widget.peerPubkey,
selfPubkey: self,
referents: referents,
params: wotParams,
);
unawaited(trust.load());
setState(() {
@ -323,10 +311,9 @@ class _TrustBanner extends StatelessWidget {
builder: (context, state) {
final cubit = context.read<TrustCubit>();
if (!cubit.isOnline || state.loading) return const SizedBox.shrink();
// Strongest applicable signal decides the badge (member > circle >
// vouched > unknown).
// Strongest applicable signal decides the badge (circle > vouched >
// unknown).
final (IconData icon, String label, bool strong) = switch (state.tier) {
TrustTier.networkMember => (Icons.verified, t.trust.member, true),
TrustTier.inYourCircle => (Icons.verified_user, t.trust.circle, true),
TrustTier.vouched => (
Icons.people_outline,

View file

@ -22,7 +22,7 @@ class ProfileScreen extends StatefulWidget {
required this.connection,
required this.profileStore,
required this.accounts,
this.trustNetworkEnabled = false,
this.yourPeopleEnabled = false,
super.key,
});
@ -33,8 +33,8 @@ class ProfileScreen extends StatefulWidget {
final ProfileStore profileStore;
final SocialAccountStore accounts;
/// Whether to offer the "Network of trust" entry (needs the WoT services).
final bool trustNetworkEnabled;
/// Whether to offer the "Your people" entry (needs the social layer).
final bool yourPeopleEnabled;
@override
State<ProfileScreen> createState() => _ProfileScreenState();
@ -210,16 +210,17 @@ class _ProfileScreenState extends State<ProfileScreen> {
onSwitch: (a) => _switchTo(a),
onNew: _newIdentity,
),
if (widget.trustNetworkEnabled) ...[
if (widget.yourPeopleEnabled) ...[
const SizedBox(height: 12),
const Divider(),
ListTile(
key: const Key('profile.trustNetwork'),
key: const Key('profile.yourPeople'),
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.hub_outlined, color: seedGreen),
title: Text(t.wot.open),
leading:
const Icon(Icons.people_alt_outlined, color: seedGreen),
title: Text(t.yourPeople.title),
trailing: const Icon(Icons.chevron_right, color: seedMuted),
onTap: () => context.push('/trust'),
onTap: () => context.push('/your-people'),
),
],
],

View file

@ -1,228 +0,0 @@
import 'package:commons_core/commons_core.dart';
import 'package:flutter/material.dart';
import '../i18n/strings.g.dart';
import '../services/profile_cache.dart' show shortPubkey;
import '../services/trust_referents.dart';
import '../services/wot_settings.dart';
import 'theme.dart';
/// Manage the web of trust: the bootstrap "roots" (Duniter seeds) membership is
/// measured from, and the advanced parameters (sigQty / stepMax / validity).
/// This is where a young network is seeded and tuned progressive disclosure,
/// reached from the profile.
class TrustNetworkScreen extends StatefulWidget {
const TrustNetworkScreen({
required this.referents,
required this.wotSettings,
super.key,
});
final TrustReferents referents;
final WotSettings wotSettings;
@override
State<TrustNetworkScreen> createState() => _TrustNetworkScreenState();
}
class _TrustNetworkScreenState extends State<TrustNetworkScreen> {
final _input = TextEditingController();
Set<String> _roots = {};
WotParams _params = WotParams.duniter;
bool _loading = true;
String? _error;
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
final roots = await widget.referents.userAdded();
final params = await widget.wotSettings.params();
if (!mounted) return;
setState(() {
_roots = roots;
_params = params;
_loading = false;
});
}
Future<void> _addRoot() async {
final t = context.t;
final messenger = ScaffoldMessenger.of(context);
try {
await widget.referents.add(_input.text);
_input.clear();
await _load();
messenger.showSnackBar(SnackBar(content: Text(t.wot.rootAdded)));
} on FormatException {
setState(() => _error = t.wot.rootInvalid);
}
}
Future<void> _removeRoot(String hex) async {
await widget.referents.remove(hex);
await _load();
}
Future<void> _saveParams(WotParams next) async {
await widget.wotSettings.save(next);
if (!mounted) return;
setState(() => _params = next);
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(context.t.wot.saved)));
}
@override
void dispose() {
_input.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final t = context.t;
return Scaffold(
appBar: AppBar(title: Text(t.wot.title)),
body: _loading
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(20),
children: [
Text(t.wot.help,
style: const TextStyle(color: seedMuted, fontSize: 13)),
const SizedBox(height: 20),
Text(t.wot.roots,
style: const TextStyle(
fontWeight: FontWeight.w600, color: seedOnSurface)),
const SizedBox(height: 4),
Text(t.wot.rootsHelp,
style: const TextStyle(color: seedMuted, fontSize: 12)),
const SizedBox(height: 8),
if (_roots.isEmpty)
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Text(t.wot.noRoots,
style:
const TextStyle(color: seedMuted, fontSize: 13)),
),
for (final hex in _roots)
ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.hub_outlined, color: seedGreen),
title: Text(shortPubkey(hex),
style: const TextStyle(
fontFamily: 'monospace', fontSize: 13)),
trailing: IconButton(
icon: const Icon(Icons.close, size: 20),
tooltip: t.wot.remove,
onPressed: () => _removeRoot(hex),
),
),
const SizedBox(height: 8),
TextField(
key: const Key('wot.rootInput'),
controller: _input,
onChanged: (_) {
if (_error != null) setState(() => _error = null);
},
decoration: InputDecoration(
labelText: t.wot.addRoot,
hintText: t.wot.rootHint,
errorText: _error,
suffixIcon: IconButton(
key: const Key('wot.addRoot'),
icon: const Icon(Icons.add),
onPressed: _addRoot,
),
),
),
const SizedBox(height: 12),
const Divider(),
ExpansionTile(
tilePadding: EdgeInsets.zero,
title: Text(t.wot.params),
subtitle: Text(t.wot.paramsHelp,
style: const TextStyle(fontSize: 12)),
children: [
_Stepper(
label: t.wot.sigQty,
value: _params.sigQty,
min: 1,
onChanged: (v) =>
_saveParams(_params.copyWith(sigQty: v)),
),
_Stepper(
label: t.wot.stepMax,
value: _params.stepMax,
min: 1,
onChanged: (v) =>
_saveParams(_params.copyWith(stepMax: v)),
),
_Stepper(
label: t.wot.validityDays,
value: _params.sigValidity.inDays,
min: 1,
step: 30,
onChanged: (v) => _saveParams(
_params.copyWith(sigValidity: Duration(days: v))),
),
const SizedBox(height: 8),
Align(
alignment: AlignmentDirectional.centerStart,
child: TextButton(
onPressed: () => _saveParams(WotParams.duniter),
child: Text(t.wot.reset),
),
),
],
),
],
),
);
}
}
/// A "- value +" row for an integer parameter, clamped to [min].
class _Stepper extends StatelessWidget {
const _Stepper({
required this.label,
required this.value,
required this.onChanged,
this.min = 0,
this.step = 1,
});
final String label;
final int value;
final int min;
final int step;
final ValueChanged<int> onChanged;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
Expanded(child: Text(label)),
IconButton(
icon: const Icon(Icons.remove_circle_outline),
onPressed:
value - step >= min ? () => onChanged(value - step) : null,
),
SizedBox(
width: 44,
child: Text('$value', textAlign: TextAlign.center),
),
IconButton(
icon: const Icon(Icons.add_circle_outline),
onPressed: () => onChanged(value + step),
),
],
),
);
}
}

View file

@ -0,0 +1,240 @@
import 'dart:async';
import 'package:commons_core/commons_core.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../i18n/strings.g.dart';
import '../services/profile_cache.dart';
import '../services/social_connection.dart';
import '../services/social_service.dart';
import 'theme.dart';
/// "Your people": who you vouch for and who vouches for you, in human
/// language. Ego-centric by design no roots, no parameters, no graph talk.
/// Reached from the profile; rows open the 1:1 chat.
class YourPeopleScreen extends StatefulWidget {
const YourPeopleScreen({
required this.social,
required this.connection,
this.profileCache,
super.key,
});
final SocialService social;
/// The shared relay connection (one per identity), carrying trust.
final SocialConnection connection;
/// Optional cache of peer display names; null in tests.
final ProfileCache? profileCache;
@override
State<YourPeopleScreen> createState() => _YourPeopleScreenState();
}
class _YourPeopleScreenState extends State<YourPeopleScreen> {
TrustTransport? _transport;
bool _loading = true;
bool _busy = false;
List<String> _youVouchFor = const [];
List<String> _vouchForYou = const [];
final Map<String, String> _names = {};
@override
void initState() {
super.initState();
_init();
}
Future<void> _init() async {
final session = await widget.connection.session();
if (!mounted) return; // shared session is owned by the connection, not us
_transport = session?.trust;
await _load();
}
Future<void> _load() async {
final transport = _transport;
if (transport == null) {
if (mounted) setState(() => _loading = false);
return;
}
final self = widget.social.publicKeyHex;
final now = DateTime.now();
final certs = (await transport.allCertifications())
.where((c) => c.isValidAt(now))
.toList();
final given = [
for (final c in certs)
if (c.issuer == self) c.subject,
]..sort();
final received = [
for (final c in certs)
if (c.subject == self) c.issuer,
]..sort();
final cache = widget.profileCache;
if (cache != null) {
for (final peer in {...given, ...received}) {
final name = await cache.name(peer);
if (name != null) _names[peer] = name;
}
}
if (!mounted) return;
setState(() {
_youVouchFor = given;
_vouchForYou = received;
_loading = false;
});
}
Future<void> _revoke(String peer) async {
final t = context.t;
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(t.yourPeople.revokeConfirm),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: Text(t.common.cancel),
),
FilledButton(
onPressed: () => Navigator.pop(context, true),
child: Text(t.yourPeople.revoke),
),
],
),
);
final transport = _transport;
if (confirmed != true || transport == null || !mounted) return;
setState(() => _busy = true);
await transport.revoke(subjectPubkey: peer);
await _load();
if (mounted) setState(() => _busy = false);
}
@override
Widget build(BuildContext context) {
final t = context.t;
return Scaffold(
appBar: AppBar(title: Text(t.yourPeople.title)),
body: _loading
? const Center(child: CircularProgressIndicator())
: _transport == null
? Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Text(
t.yourPeople.offline,
textAlign: TextAlign.center,
style: const TextStyle(color: seedMuted, fontSize: 15),
),
),
)
: ListView(
padding: const EdgeInsets.symmetric(vertical: 8),
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
16, 8, 16, 8),
child: Text(
t.yourPeople.help,
style:
const TextStyle(color: seedMuted, fontSize: 14),
),
),
_SectionHeader(label: t.yourPeople.youVouchFor),
if (_youVouchFor.isEmpty)
_EmptyNote(text: t.yourPeople.youVouchForEmpty)
else
for (final peer in _youVouchFor)
_PersonTile(
key: Key('yourPeople.given.$peer'),
name: _names[peer] ?? shortPubkey(peer),
onOpen: () => context.push('/chat/$peer'),
trailing: TextButton(
onPressed: _busy ? null : () => _revoke(peer),
child: Text(t.yourPeople.revoke),
),
),
const SizedBox(height: 12),
_SectionHeader(label: t.yourPeople.vouchesForYou),
if (_vouchForYou.isEmpty)
_EmptyNote(text: t.yourPeople.vouchesForYouEmpty)
else
for (final peer in _vouchForYou)
_PersonTile(
key: Key('yourPeople.received.$peer'),
name: _names[peer] ?? shortPubkey(peer),
onOpen: () => context.push('/chat/$peer'),
),
],
),
);
}
}
class _SectionHeader extends StatelessWidget {
const _SectionHeader({required this.label});
final String label;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
child: Text(
label,
style: const TextStyle(
color: seedGreen,
fontSize: 13,
fontWeight: FontWeight.w600,
),
),
);
}
}
class _EmptyNote extends StatelessWidget {
const _EmptyNote({required this.text});
final String text;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),
child: Text(
text,
style: const TextStyle(color: seedMuted, fontSize: 14),
),
);
}
}
class _PersonTile extends StatelessWidget {
const _PersonTile({
required this.name,
required this.onOpen,
this.trailing,
super.key,
});
final String name;
final VoidCallback onOpen;
final Widget? trailing;
@override
Widget build(BuildContext context) {
return ListTile(
leading: const CircleAvatar(
backgroundColor: seedAvatar,
child: Icon(Icons.person, color: seedOnAvatar),
),
title: Text(name),
trailing: trailing,
onTap: onOpen,
);
}
}