diff --git a/packages/core-dart/.dart_tool/package_config.json b/packages/core-dart/.dart_tool/package_config.json index e22317e..206f948 100644 --- a/packages/core-dart/.dart_tool/package_config.json +++ b/packages/core-dart/.dart_tool/package_config.json @@ -298,7 +298,7 @@ ], "generator": "pub", "generatorVersion": "3.9.2", - "flutterRoot": "file:///C:/Users/TCE%20HUB/fvm/versions/3.35.7", + "flutterRoot": "file:///C:/Users/TCE%20HUB/fvm/default", "flutterVersion": "3.35.7", "pubCache": "file:///C:/Users/TCE%20HUB/AppData/Local/Pub/Cache" } diff --git a/packages/core-dart/.dart_tool/test/incremental_kernel.Ly9AZGFydD0zLjA= b/packages/core-dart/.dart_tool/test/incremental_kernel.Ly9AZGFydD0zLjA= index dbc620a..2f881d8 100644 Binary files a/packages/core-dart/.dart_tool/test/incremental_kernel.Ly9AZGFydD0zLjA= and b/packages/core-dart/.dart_tool/test/incremental_kernel.Ly9AZGFydD0zLjA= differ diff --git a/packages/core-dart/lib/src/address/stellar_address.dart b/packages/core-dart/lib/src/address/stellar_address.dart index f37501f..f951e67 100644 --- a/packages/core-dart/lib/src/address/stellar_address.dart +++ b/packages/core-dart/lib/src/address/stellar_address.dart @@ -1,8 +1,8 @@ import 'package:meta/meta.dart'; -import '../address/codes.dart'; import '../muxed/decode.dart'; -import '../address/detect.dart'; import '../exceptions.dart'; +import 'codes.dart'; +import 'detect.dart'; /// An immutable representation of a Stellar Address. @immutable @@ -65,8 +65,8 @@ class StellarAddress { return StellarAddress._( kind: AddressKind.m, raw: address, - baseG: decoded['baseG'] as String?, - muxedId: decoded['id'] as BigInt?, + baseG: decoded.baseG, + muxedId: decoded.id, ); } catch (error) { throw StellarAddressException( diff --git a/packages/core-dart/lib/src/muxed/decode.dart b/packages/core-dart/lib/src/muxed/decode.dart index 99f8672..d24b74b 100644 --- a/packages/core-dart/lib/src/muxed/decode.dart +++ b/packages/core-dart/lib/src/muxed/decode.dart @@ -1,10 +1,20 @@ import 'dart:typed_data'; import '../util/strkey.dart'; import 'decoded_muxed_address.dart'; +import '../exceptions.dart'; class MuxedDecoder { static DecodedMuxedAddress decodeMuxedString(String mAddress) { final decoded = StrKeyUtil.decodeBase32(mAddress); + + if (decoded.length != 43) { + throw const StellarAddressException('Invalid muxed address length'); + } + + if (decoded[0] != 0x60) { + throw const StellarAddressException('Invalid muxed address prefix'); + } + // Payload starts at index 1 (skip version byte 0x60) // 32 bytes pubkey + 8 bytes ID = 40 bytes final pubkey = decoded.sublist(1, 33); diff --git a/packages/core-dart/lib/src/routing/extract.dart b/packages/core-dart/lib/src/routing/extract.dart index 098a387..219c190 100644 --- a/packages/core-dart/lib/src/routing/extract.dart +++ b/packages/core-dart/lib/src/routing/extract.dart @@ -51,8 +51,8 @@ RoutingResult extractRouting(RoutingInput input) { if (parsed.kind == AddressKind.m) { final warnings = List.from(parsed.warnings); final decoded = MuxedDecoder.decodeMuxedString(parsed.address); - final baseG = decoded['baseG'] as String; - final muxedId = (decoded['id'] as BigInt).toString(); + final baseG = decoded.baseG; + final muxedId = decoded.id.toString(); if (input.memoType == 'none') { return RoutingResult( diff --git a/packages/core-dart/test/debug_decode.dart b/packages/core-dart/test/debug_decode.dart new file mode 100644 index 0000000..36dec62 --- /dev/null +++ b/packages/core-dart/test/debug_decode.dart @@ -0,0 +1,12 @@ +import 'package:stellar_address_kit/stellar_address_kit.dart'; + +void main() { + const baseG = 'GAYCUYT553C5LHVE2XPW5GMEJT4BXGM7AHMJWLAPZP53KJO7EIQADRSI'; + try { + print('Testing decode on G address...'); + final result = MuxedAddress.decode(baseG); + print('Result: $result'); + } catch (e) { + print('Caught expected error: $e'); + } +} diff --git a/packages/core-dart/test/muxed_round_trip_test.dart b/packages/core-dart/test/muxed_round_trip_test.dart index 30d505f..72c9ff7 100644 --- a/packages/core-dart/test/muxed_round_trip_test.dart +++ b/packages/core-dart/test/muxed_round_trip_test.dart @@ -11,7 +11,7 @@ BigInt _randomUint64(Random rng) { // Build 64 random bits from two 32-bit values. final hi = BigInt.from(rng.nextInt(1 << 32)); final lo = BigInt.from(rng.nextInt(1 << 32)); - return (hi << 32) | lo; + return (hi << 32) + lo; } void main() { @@ -20,7 +20,7 @@ void main() { // Feature: muxed-decode-typed-dto, Property 1: Construction preserves field values // For any baseG string and BigInt id, DecodedMuxedAddress(baseG, id).baseG == baseG and .id == id group('Property 1: Construction preserves field values', () { - test('field values are preserved across $\_iterations random instances', () { + test('field values are preserved across $_iterations random instances', () { for (var i = 0; i < _iterations; i++) { final id = _randomUint64(rng); final dto = DecodedMuxedAddress(baseG: _baseG, id: id); @@ -43,7 +43,7 @@ void main() { // Feature: muxed-decode-typed-dto, Property 2: Equality and hashCode consistency // For any two DecodedMuxedAddress instances, == and hashCode are consistent with field equality group('Property 2: Equality and hashCode consistency', () { - test('equal instances have equal hashCode across $\_iterations pairs', () { + test('equal instances have equal hashCode across $_iterations pairs', () { for (var i = 0; i < _iterations; i++) { final id = _randomUint64(rng); final a = DecodedMuxedAddress(baseG: _baseG, id: id); @@ -68,7 +68,7 @@ void main() { // Feature: muxed-decode-typed-dto, Property 3: toString contains both fields // For any DecodedMuxedAddress, toString() contains baseG and id group('Property 3: toString contains both fields', () { - test('toString contains baseG and id across $\_iterations instances', () { + test('toString contains baseG and id across $_iterations instances', () { for (var i = 0; i < _iterations; i++) { final id = _randomUint64(rng); final dto = DecodedMuxedAddress(baseG: _baseG, id: id); @@ -84,7 +84,7 @@ void main() { // Feature: muxed-decode-typed-dto, Property 4: Round-trip encode → decode → encode // For any valid baseG and uint64 id, encode then decode then re-encode is identity group('Property 4: Round-trip encode → decode → encode', () { - test('round-trip preserves baseG and id across $\_iterations random ids', + test('round-trip preserves baseG and id across $_iterations random ids', () { for (var i = 0; i < _iterations; i++) { final id = _randomUint64(rng);