diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..86513d7 Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml new file mode 100644 index 0000000..525a4e4 --- /dev/null +++ b/.idea/libraries/Dart_SDK.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a7e88e8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..5b3388c --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000..01be2bc Binary files /dev/null and b/lib/.DS_Store differ diff --git a/lib/src/helpers/wallet_connect_uri_convertor.dart b/lib/src/helpers/wallet_connect_uri_convertor.dart index e6f5918..279bc41 100644 --- a/lib/src/helpers/wallet_connect_uri_convertor.dart +++ b/lib/src/helpers/wallet_connect_uri_convertor.dart @@ -4,14 +4,11 @@ class WalletConnectUriConvertor { static Uri? toUri(String uri) { if (uri.isEmpty) return null; - final u = Uri.tryParse( - uri.startsWith('wc:') ? uri.replaceFirst('wc:', 'wc://') : uri, - ); - + final u = Uri.tryParse(uri); if (u == null) return null; if ([ - u.host.isNotEmpty, + u.path.isNotEmpty, u.isScheme('wc'), ].contains(false)) return null; @@ -22,8 +19,10 @@ class WalletConnectUriConvertor { if (uri is WalletConnectV1Uri) { return Uri( scheme: uri.protocol, - userInfo: uri.topic, - host: uri.version.version.toString(), + path: [ + uri.topic, + uri.version.version.toString(), + ].join('@'), queryParameters: { 'bridge': uri.bridge, 'key': uri.key, @@ -34,12 +33,14 @@ class WalletConnectUriConvertor { if (uri is WalletConnectV2Uri) { return Uri( scheme: uri.protocol, - userInfo: uri.topic, - host: uri.version.version.toString(), + path: [ + uri.topic, + uri.version.version.toString(), + ].join('@'), queryParameters: { - 'relayProtocol': uri.relayProtocol, + 'relay-protocol': uri.relayProtocol, 'symKey': uri.symKey, - 'relayData': uri.relayData, + if (uri.relayData != null) 'relayData': uri.relayData, }, ).toString(); } diff --git a/lib/src/wallet_connect_uri.dart b/lib/src/wallet_connect_uri.dart index 0982519..d6eefa4 100644 --- a/lib/src/wallet_connect_uri.dart +++ b/lib/src/wallet_connect_uri.dart @@ -16,9 +16,12 @@ enum WalletConnectVersion { /// Parse [WalletConnectVersion] from [String] that contains version number static WalletConnectVersion parse(String value) { - final s = int.tryParse(value) ?? 0; - if (s > 0) return from(s); - return unknown; + try { + final v = value.contains('@') ? value.split('@').last : value; + return from(int.parse(v)); + } catch (_) { + return unknown; + } } /// Get [WalletConnectVersion] from [int] that contains version number @@ -74,7 +77,7 @@ abstract class WalletConnectUri { final u = WalletConnectUriConvertor.toUri(uri); if (u == null) throw const FormatException('Invalid WalletConnect URI'); - final v = WalletConnectVersion.parse(u.host); + final v = WalletConnectVersion.parse(u.path); if (v == WalletConnectVersion.v1) return WalletConnectV1Uri.parse(uri); if (v == WalletConnectVersion.v2) return WalletConnectV2Uri.parse(uri); diff --git a/lib/src/wallet_connect_v1_uri.dart b/lib/src/wallet_connect_v1_uri.dart index c265542..a37a437 100644 --- a/lib/src/wallet_connect_v1_uri.dart +++ b/lib/src/wallet_connect_v1_uri.dart @@ -16,12 +16,13 @@ class WalletConnectV1Uri extends WalletConnectUri { ); } + final topic = u.path.contains('@') ? u.path.split('@').first : u.path; final params = u.queryParameters; return WalletConnectV1Uri( protocol: u.scheme, - topic: u.userInfo, - version: WalletConnectVersion.parse(u.host), + topic: topic, + version: WalletConnectVersion.parse(u.path), bridge: params['bridge'] ?? '', key: params['key'] ?? '', ); diff --git a/lib/src/wallet_connect_v2_uri.dart b/lib/src/wallet_connect_v2_uri.dart index eac8023..2998915 100644 --- a/lib/src/wallet_connect_v2_uri.dart +++ b/lib/src/wallet_connect_v2_uri.dart @@ -16,12 +16,13 @@ class WalletConnectV2Uri extends WalletConnectUri { ); } + final topic = u.path.contains('@') ? u.path.split('@').first : u.path; final params = u.queryParameters; return WalletConnectV2Uri( protocol: u.scheme, - topic: u.userInfo, - version: WalletConnectVersion.parse(u.host), + topic: topic, + version: WalletConnectVersion.parse(u.path), relayProtocol: params['relay-protocol'] ?? '', symKey: params['symKey'] ?? '', relayData: params['relayData'], diff --git a/pubspec.yaml b/pubspec.yaml index 76cc381..6859218 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 0.1.0 repository: https://github.com/SimplioOfficial/wallet-connect-uri-validator.git environment: - sdk: '>=2.18.6 <3.0.0' + sdk: ">=3.0.0 <4.0.0" dev_dependencies: lints: ^2.0.0