Show the routing key prefix on each contact

Contacts now show the first path-hash-width bytes of their public key as
a monospace badge before the path label, so they can be matched to hops
in routing paths and told apart. The width follows the radio's path hash
size setting.
This commit is contained in:
zjs81 committed 2026-10-24 20:59:59 -07:00
1 parent 4c9705b3cb
commit c296597a2d
24 files changed
+253 -2

No files matched your search

+2
View File
@@ -3437,6 +3437,8 @@
"@repeater_prvKeyLengthError": {"placeholders": {"length": {"type": "int"}}},
"contacts_advertFailed": "Couldn't send advertisement",
"contacts_manageGroups": "Manage groups",
"contacts_keyPrefixSemantics": "Key prefix {prefix}",
"@contacts_keyPrefixSemantics": {"placeholders": {"prefix": {"type": "String"}}},
"community_shortId": "ID: {id}…",
"@community_shortId": {"placeholders": {"id": {"type": "String"}}},
"tcpSectionTitle": "TCP / IP",
+6
View File
@@ -10333,6 +10333,12 @@ abstract class AppLocalizations {
/// **'Manage groups'**
String get contacts_manageGroups;
/// No description provided for @contacts_keyPrefixSemantics.
///
/// In en, this message translates to:
/// **'Key prefix {prefix}'**
String contacts_keyPrefixSemantics(String prefix);
/// No description provided for @community_shortId.
///
/// In en, this message translates to:
+5
View File
@@ -6166,6 +6166,11 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get contacts_manageGroups => 'Управление на групи';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6181,6 +6181,11 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get contacts_manageGroups => 'Gruppen verwalten';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6080,6 +6080,11 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get contacts_manageGroups => 'Manage groups';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6169,6 +6169,11 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get contacts_manageGroups => 'Gestionar grupos';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6194,6 +6194,11 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get contacts_manageGroups => 'Gérer les groupes';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID : $id…';
+5
View File
@@ -6157,6 +6157,11 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get contacts_manageGroups => 'Csoportok kezelése';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6176,6 +6176,11 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get contacts_manageGroups => 'Gestisci gruppi';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -5878,6 +5878,11 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get contacts_manageGroups => 'グループを管理';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -5888,6 +5888,11 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get contacts_manageGroups => '그룹 관리';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6136,6 +6136,11 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get contacts_manageGroups => 'Groepen beheren';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6200,6 +6200,11 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get contacts_manageGroups => 'Zarządzaj grupami';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6165,6 +6165,11 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get contacts_manageGroups => 'Gerenciar grupos';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6186,6 +6186,11 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get contacts_manageGroups => 'Управление группами';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6148,6 +6148,11 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get contacts_manageGroups => 'Spravovať skupiny';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6150,6 +6150,11 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get contacts_manageGroups => 'Upravljaj skupine';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6116,6 +6116,11 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get contacts_manageGroups => 'Hantera grupper';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -6188,6 +6188,11 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get contacts_manageGroups => 'Керування групами';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID: $id…';
+5
View File
@@ -5744,6 +5744,11 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get contacts_manageGroups => '管理分组';
@override
String contacts_keyPrefixSemantics(String prefix) {
return 'Key prefix $prefix';
}
@override
String community_shortId(String id) {
return 'ID:$id…';
+11
View File
@@ -43,6 +43,17 @@ class Contact {
String get publicKeyHex => pubKeyToHex(publicKey);
/// Uppercase hex of the first [byteWidth] public-key bytes: the hash this
/// node appears as in routing paths.
String publicKeyPrefixHex(int byteWidth) {
final width = byteWidth.clamp(1, 3).toInt();
return publicKey
.take(width)
.map((b) => b.toRadixString(16).padLeft(2, '0'))
.join()
.toUpperCase();
}
/// Non-localized type label, intended for logs and non-UI exports
/// (e.g. GPX). For UI use the `typeLabel(l10n)` extension in
/// `lib/l10n/contact_localization.dart`.
+42 -1
View File
@@ -1884,9 +1884,13 @@ class _ContactTile extends StatelessWidget {
],
),
const SizedBox(height: 3),
// Path / subtitle row
// Key prefix + path / subtitle row
Row(
children: [
_KeyPrefixBadge(
prefix: contact.publicKeyPrefixHex(pathHashByteWidth),
),
const SizedBox(width: 8),
Expanded(
child: Text(
contact.pathLabel(
@@ -1953,6 +1957,43 @@ class _ContactTile extends StatelessWidget {
}
}
/// Mono pill showing the contact's routing hash (public-key prefix), so it can
/// be matched against hops in paths.
class _KeyPrefixBadge extends StatelessWidget {
final String prefix;
const _KeyPrefixBadge({required this.prefix});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return Semantics(
label: context.l10n.contacts_keyPrefixSemantics(
prefix.split('').join(' '),
),
excludeSemantics: true,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
decoration: BoxDecoration(
color: scheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(MeshRadii.xs),
border: Border.all(color: scheme.outline),
),
child: Text(
prefix,
maxLines: 1,
style: MeshTheme.mono(
fontSize: 13,
fontWeight: FontWeight.w700,
color: scheme.onSurface,
letterSpacing: 0.6,
),
),
),
);
}
}
/// Disposes [controller] when the dialog content unmounts, i.e. after the
/// route's exit animation, so the TextField never sees a disposed controller.
class _DisposeControllerOnUnmount extends StatefulWidget {
+33
View File
@@ -0,0 +1,33 @@
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_protocol.dart';
import 'package:meshcore_open/models/contact.dart';
Contact _contact(List<int> key) => Contact(
publicKey: Uint8List.fromList(key),
name: 'Node',
type: advTypeChat,
pathLength: -1,
path: Uint8List(0),
lastSeen: DateTime.fromMillisecondsSinceEpoch(0),
);
void main() {
final contact = _contact([0xA3, 0x0F, 0xB2, 0x44]);
test('formats the first pathHashByteWidth bytes as uppercase hex', () {
expect(contact.publicKeyPrefixHex(1), 'A3');
expect(contact.publicKeyPrefixHex(2), 'A30F');
expect(contact.publicKeyPrefixHex(3), 'A30FB2');
});
test('clamps width to the supported 1-3 range', () {
expect(contact.publicKeyPrefixHex(0), 'A3');
expect(contact.publicKeyPrefixHex(4), 'A30FB2');
});
test('handles keys shorter than the width', () {
expect(_contact([0x01]).publicKeyPrefixHex(3), '01');
});
}
+69 -1
View File
@@ -1 +1,69 @@
{}
{
"bg": [
"contacts_keyPrefixSemantics"
],
"de": [
"contacts_keyPrefixSemantics"
],
"es": [
"contacts_keyPrefixSemantics"
],
"fr": [
"contacts_keyPrefixSemantics"
],
"hu": [
"contacts_keyPrefixSemantics"
],
"it": [
"contacts_keyPrefixSemantics"
],
"ja": [
"contacts_keyPrefixSemantics"
],
"ko": [
"contacts_keyPrefixSemantics"
],
"nl": [
"contacts_keyPrefixSemantics"
],
"pl": [
"contacts_keyPrefixSemantics"
],
"pt": [
"contacts_keyPrefixSemantics"
],
"ru": [
"contacts_keyPrefixSemantics"
],
"sk": [
"contacts_keyPrefixSemantics"
],
"sl": [
"contacts_keyPrefixSemantics"
],
"sv": [
"contacts_keyPrefixSemantics"
],
"uk": [
"contacts_keyPrefixSemantics"
],
"zh": [
"contacts_keyPrefixSemantics"
]
}