diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index a25d0273..26c89cca 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -6560,11 +6560,13 @@ class MeshCoreConnector extends ChangeNotifier { if (path.isNotEmpty && path.length < hashWidth) { return; } + final pathStartIndex = path.isNotEmpty ? path.length - hashWidth : 0; + final publicKeyPrefixEnd = math.min(hashWidth, contact.publicKey.length).toInt(); final pubkeyPrefix = path.isNotEmpty - ? path.sublist(math.max(0, path.length - hashWidth)) + ? path.sublist(pathStartIndex) : contact.publicKey.sublist( 0, - math.min(hashWidth, contact.publicKey.length), + publicKeyPrefixEnd, ); final contactKeyHex = _resolveDirectRepeaterContactKeyHex( contact, diff --git a/lib/helpers/path_helper.dart b/lib/helpers/path_helper.dart index a622d3d5..935fa2bc 100644 --- a/lib/helpers/path_helper.dart +++ b/lib/helpers/path_helper.dart @@ -21,10 +21,10 @@ class PathHelper { ) { if (pathBytes.isEmpty) return const []; - final width = hashByteWidth.clamp(1, 4); + final width = hashByteWidth.clamp(1, 4).toInt(); final hops = []; for (int i = 0; i < pathBytes.length; i += width) { - final endIdx = (i + width).clamp(0, pathBytes.length); + final endIdx = (i + width).clamp(0, pathBytes.length).toInt(); final hopBytes = pathBytes.sublist(i, endIdx); if (hopBytes.isNotEmpty) { hops.add(Uint8List.fromList(hopBytes));