From f0888621172f8e0de093d093ff7c4b2d6ccaa647 Mon Sep 17 00:00:00 2001 From: storkandstars Date: Mon, 31 Jul 2023 15:55:40 +0200 Subject: [PATCH] updating for compatibility --- .DS_Store | Bin 0 -> 6148 bytes .idea/libraries/Dart_SDK.xml | 19 +++++++++ .idea/modules.xml | 8 ++++ .idea/workspace.xml | 36 ++++++++++++++++++ lib/.DS_Store | Bin 0 -> 6148 bytes .../helpers/wallet_connect_uri_convertor.dart | 23 +++++------ lib/src/wallet_connect_uri.dart | 11 ++++-- lib/src/wallet_connect_v1_uri.dart | 5 ++- lib/src/wallet_connect_v2_uri.dart | 5 ++- pubspec.yaml | 2 +- 10 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/libraries/Dart_SDK.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/workspace.xml create mode 100644 lib/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..86513d7dddf51c40dac04d0256a432e11043e775 GIT binary patch literal 6148 zcmeHKJ#Q015PfSq;*>Nl5FZl7HMEEnP{LuE7LXzugaomTg2CoO;!xj@;2)$18c-@I zKu`h=`~&^~H4<-Tm&$CN|@1A`4_CV{Y zbLZt@4Q>92SC&O!g}hTLbPt;mGuEEQUdugxe)E?WCf~BRM@0NMFZ{>I{{*`jb6sT> zaSgcCjIec_=zsir`Gsn5LFuQO + + + + + + + + + + + + + + + + + + \ 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 0000000000000000000000000000000000000000..01be2bc6c76dd65b8477270494ef8428b0bd565f GIT binary patch literal 6148 zcmeHKJx{|h5IxhXt;*7Yfdwf)fi7%_PzBKybzoqDwun|rn$iMd%unG5FtD&OG9ocD zGw?rnXIrWBr4C34p}Xq*lJnVqeo5?_h*a-(+$HJ|Q47vkZ=)zNu4gaUhK+0imF{Cf z%kZi@7{$@NkSzgGKot0E3h=kvpi5fd7sK=4?_0h;ii2Pn#zVwg{r&fkgQwTSV$OJN z&V1so6TJRVlO|vi(p>Y&F{wQkGh8mCj~XrUWJcMQ^`r>~w#FU%YcSipe%8+~^I4VWaybiA9ZLIj^;nmi<+;l|#eSv$_H4G+ra>u10Z~8{NEP7q!GkmU z788Sd=|G{60KhuJ+HkG+a-hcnpl>lThzLxXra;qF*&~KB%@Ox(o^LTRXquDKBcmTX zva%->rAJ5H)9IvqgHnnDqCi%Gnz`-p{(n?`{?9g&J5fLs_*V+3dN2rjn3COF3zOr$ u)`OqJ**GsTsGFd$+p)gjt#})*4Rs!00DX&zK}2BkM?lLUg(&c=3VZ_-8?pQV literal 0 HcmV?d00001 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