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

+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');
});
}