Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/reown_sign/lib/utils/address_utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:wallet/wallet.dart' as wallet;

class AddressUtils {
static List<String> _getDidAddressSegments(String iss) {
return iss.split(':');
Expand Down Expand Up @@ -43,9 +45,19 @@ class AddressUtils {
}
}

final _evmAddress = RegExp(r'^(0x)?[0-9a-fA-F]{40}$');
Comment thread
o-mid marked this conversation as resolved.
Outdated

extension AddressUtilsExtension on String {
/// Checksums an EVM address per EIP-55. Non-EVM values are returned unchanged
/// so Solana / Bitcoin accounts are not forced through EthereumAddress.
String toEIP55() {
return this;
// return EthereumAddress.fromHex(this).hexEip55;
if (!_evmAddress.hasMatch(this)) {
return this;
}
try {
return wallet.EthereumAddress.fromHex(this).eip55With0x;
} catch (_) {
return this;
}
}
}
16 changes: 16 additions & 0 deletions packages/reown_sign/test/utils/address_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,21 @@ void main() {
TEST_ETHEREUM_CHAIN.split(':')[1],
);
});

test('toEIP55 checksums a lowercase EVM address', () {
expect(
'0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed'.toEIP55(),
'0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed',
);
});

test('toEIP55 keeps an already checksummed address', () {
expect(TEST_ADDRESS_EIP191.toEIP55(), TEST_ADDRESS_EIP191);
});

test('toEIP55 leaves non-EVM addresses unchanged', () {
const solana = '7EcDhSYGxXyscszYEp35KHN8vvw3svAuLKTzXwCFLtV';
expect(solana.toEIP55(), solana);
});
});
}
Loading