Skip to content

Commit 74b708f

Browse files
authored
Merge pull request #146 from WalletConnect/chores/siwe_bug_fixes_and_enhancements
Bug fixes and enhancements for SIWE
2 parents d70b878 + 00bf60d commit 74b708f

15 files changed

Lines changed: 87 additions & 48 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 3.3.0-beta04
1+
## 3.3.0-beta05
22

33
- One-Click Auth + SIWE implementation
44
- Coinbase Wallet dependency update

example/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx1536M
22
android.useAndroidX=true
33
android.enableJetifier=true
44
versionName=3.3.0
5-
versionCode=65
5+
versionCode=66

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@
470470
CLANG_ENABLE_MODULES = YES;
471471
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
472472
CODE_SIGN_STYLE = Manual;
473-
CURRENT_PROJECT_VERSION = 65;
473+
CURRENT_PROJECT_VERSION = 66;
474474
DEVELOPMENT_TEAM = "";
475475
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
476476
ENABLE_BITCODE = NO;
@@ -496,7 +496,7 @@
496496
buildSettings = {
497497
BUNDLE_LOADER = "$(TEST_HOST)";
498498
CODE_SIGN_STYLE = Automatic;
499-
CURRENT_PROJECT_VERSION = 65;
499+
CURRENT_PROJECT_VERSION = 66;
500500
GENERATE_INFOPLIST_FILE = YES;
501501
MARKETING_VERSION = 1.0;
502502
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
@@ -514,7 +514,7 @@
514514
buildSettings = {
515515
BUNDLE_LOADER = "$(TEST_HOST)";
516516
CODE_SIGN_STYLE = Automatic;
517-
CURRENT_PROJECT_VERSION = 65;
517+
CURRENT_PROJECT_VERSION = 66;
518518
GENERATE_INFOPLIST_FILE = YES;
519519
MARKETING_VERSION = 1.0;
520520
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
@@ -530,7 +530,7 @@
530530
buildSettings = {
531531
BUNDLE_LOADER = "$(TEST_HOST)";
532532
CODE_SIGN_STYLE = Automatic;
533-
CURRENT_PROJECT_VERSION = 65;
533+
CURRENT_PROJECT_VERSION = 66;
534534
GENERATE_INFOPLIST_FILE = YES;
535535
MARKETING_VERSION = 1.0;
536536
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
@@ -655,7 +655,7 @@
655655
CLANG_ENABLE_MODULES = YES;
656656
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
657657
CODE_SIGN_STYLE = Manual;
658-
CURRENT_PROJECT_VERSION = 65;
658+
CURRENT_PROJECT_VERSION = 66;
659659
DEVELOPMENT_TEAM = "";
660660
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
661661
ENABLE_BITCODE = NO;
@@ -686,7 +686,7 @@
686686
CODE_SIGN_IDENTITY = "Apple Development";
687687
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
688688
CODE_SIGN_STYLE = Manual;
689-
CURRENT_PROJECT_VERSION = 65;
689+
CURRENT_PROJECT_VERSION = 66;
690690
DEVELOPMENT_TEAM = "";
691691
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
692692
ENABLE_BITCODE = NO;

example/ios/Runner/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</dict>
3737
</array>
3838
<key>CFBundleVersion</key>
39-
<string>65</string>
39+
<string>66</string>
4040
<key>ITSAppUsesNonExemptEncryption</key>
4141
<false/>
4242
<key>LSApplicationQueriesSchemes</key>

example/lib/home_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class _MyHomePageState extends State<MyHomePage> {
6868
} catch (error) {
6969
debugPrint('[SIWEConfig] getNonce error: $error');
7070
// Fallback patch for testing purposes in case SIWE backend has issues
71-
return AuthUtils.generateNonce();
71+
return AuthSignature.generateNonce();
7272
}
7373
},
7474
getMessageParams: () async {
@@ -86,7 +86,7 @@ class _MyHomePageState extends State<MyHomePage> {
8686
// Create SIWE message to be signed.
8787
// You can use our provided formatMessage() method of implement your own
8888
debugPrint('[SIWEConfig] createMessage()');
89-
return _w3mService.formatMessage(args);
89+
return AuthSignature.formatMessage(args);
9090
},
9191
verifyMessage: (SIWEVerifyMessageArgs args) async {
9292
// Implement your verifyMessage to authenticate the user after it.

example/pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,10 @@ packages:
10971097
dependency: transitive
10981098
description:
10991099
name: walletconnect_flutter_v2
1100-
sha256: "7f6f66038ce0f559c5661c21b6485f0abfe42354605a628c2fb571a02ec1386e"
1100+
sha256: "67582d34a3ceaf8253870d624112562e6e0af730bedc7954bd4df0099c277ee4"
11011101
url: "https://pub.dev"
11021102
source: hosted
1103-
version: "2.3.0-beta03"
1103+
version: "2.3.0-beta04"
11041104
watcher:
11051105
dependency: transitive
11061106
description:
@@ -1131,7 +1131,7 @@ packages:
11311131
path: ".."
11321132
relative: true
11331133
source: path
1134-
version: "3.3.0-beta04"
1134+
version: "3.3.0-beta05"
11351135
web_socket_channel:
11361136
dependency: transitive
11371137
description:

lib/services/coinbase_service/coinbase_service.dart

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:web3modal_flutter/services/coinbase_service/i_coinbase_service.d
77
import 'package:web3modal_flutter/services/coinbase_service/models/coinbase_data.dart';
88
import 'package:web3modal_flutter/services/coinbase_service/models/coinbase_events.dart';
99
import 'package:web3modal_flutter/services/explorer_service/explorer_service_singleton.dart';
10+
import 'package:web3modal_flutter/services/logger_service/logger_service_singleton.dart';
1011
import 'package:web3modal_flutter/web3modal_flutter.dart';
1112

1213
import 'package:coinbase_wallet_sdk/currency.dart';
@@ -122,12 +123,24 @@ class CoinbaseService implements ICoinbaseService {
122123
}
123124

124125
@override
125-
Future<String> get ownPublicKey async =>
126-
await CoinbaseWalletSDK.shared.ownPublicKey();
126+
Future<String> get ownPublicKey async {
127+
try {
128+
return await CoinbaseWalletSDK.shared.ownPublicKey();
129+
} catch (e) {
130+
loggerService.instance.e('[$runtimeType] ownPublicKey $e');
131+
return '';
132+
}
133+
}
127134

128135
@override
129-
Future<String> get peerPublicKey async =>
130-
await CoinbaseWalletSDK.shared.peerPublicKey();
136+
Future<String> get peerPublicKey async {
137+
try {
138+
return await CoinbaseWalletSDK.shared.peerPublicKey();
139+
} catch (e) {
140+
loggerService.instance.e('[$runtimeType] peerPublicKey $e');
141+
return '';
142+
}
143+
}
131144

132145
@override
133146
Future<void> getAccount() async {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'package:walletconnect_flutter_v2/apis/sign_api/models/auth/common_auth_models.dart';
2+
import 'package:walletconnect_flutter_v2/apis/sign_api/utils/auth/auth_signature.dart'
3+
as wcfv2;
4+
import 'package:walletconnect_flutter_v2/apis/sign_api/utils/auth/auth_utils.dart';
5+
import 'package:web3modal_flutter/services/siwe_service/models/w3m_siwe.dart';
6+
import 'package:web3modal_flutter/services/siwe_service/siwe_service_singleton.dart';
7+
8+
class AuthSignature {
9+
/// Given SIWECreateMessageArgs will format message according to EIP-4361 https://docs.login.xyz/general-information/siwe-overview/eip-4361
10+
static String formatMessage(SIWECreateMessageArgs params) {
11+
return siweService.instance!.formatMessage(
12+
params,
13+
);
14+
}
15+
16+
static String getAddressFromMessage(String message) {
17+
return wcfv2.AuthSignature.getAddressFromMessage(message);
18+
}
19+
20+
static String getChainIdFromMessage(String message) {
21+
return wcfv2.AuthSignature.getChainIdFromMessage(message);
22+
}
23+
24+
// verifies CACAO signature
25+
// Used by the wallet after formatting the message
26+
static Future<bool> verifySignature(
27+
String address,
28+
String message,
29+
CacaoSignature cacaoSignature,
30+
String chainId,
31+
String projectId,
32+
) async {
33+
return wcfv2.AuthSignature.verifySignature(
34+
address,
35+
message,
36+
cacaoSignature,
37+
chainId,
38+
projectId,
39+
);
40+
}
41+
42+
static String generateNonce() {
43+
return AuthUtils.generateNonce();
44+
}
45+
}

lib/services/w3m_service/i_w3m_service.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ abstract class IW3MService with ChangeNotifier {
111111

112112
Future<void> loadAccountData();
113113

114-
String formatMessage(SIWECreateMessageArgs params);
115-
116114
/// Disconnects the session and pairing, if any.
117115
/// If there is no session, this does nothing.
118116
Future<void> disconnect({bool disconnectAllSessions = true});

lib/services/w3m_service/w3m_service.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -721,13 +721,6 @@ class W3MService with ChangeNotifier implements IW3MService {
721721
}
722722
}
723723

724-
@override
725-
String formatMessage(SIWECreateMessageArgs params) {
726-
return siweService.instance!.formatMessage(
727-
params,
728-
);
729-
}
730-
731724
@override
732725
Future<void> buildConnectionUri() async {
733726
if (!_isConnected) {
@@ -1002,6 +995,7 @@ class W3MService with ChangeNotifier implements IW3MService {
1002995
List parameters = const [],
1003996
}) async {
1004997
try {
998+
// TODO use blockchain-api if possible.
1005999
return await _web3App.requestReadContract(
10061000
deployedContract: deployedContract,
10071001
functionName: functionName,

0 commit comments

Comments
 (0)