diff --git a/CHANGELOG.md b/CHANGELOG.md index 838b82ec..74403e95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.3.0-beta04 +## 3.3.0-beta05 - One-Click Auth + SIWE implementation - Coinbase Wallet dependency update diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 5b366352..7c06f16b 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true versionName=3.3.0 -versionCode=65 +versionCode=66 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index fc4cb21b..34f67823 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -470,7 +470,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 65; + CURRENT_PROJECT_VERSION = 66; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22; ENABLE_BITCODE = NO; @@ -496,7 +496,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 65; + CURRENT_PROJECT_VERSION = 66; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests; @@ -514,7 +514,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 65; + CURRENT_PROJECT_VERSION = 66; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests; @@ -530,7 +530,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 65; + CURRENT_PROJECT_VERSION = 66; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests; @@ -655,7 +655,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 65; + CURRENT_PROJECT_VERSION = 66; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22; ENABLE_BITCODE = NO; @@ -686,7 +686,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 65; + CURRENT_PROJECT_VERSION = 66; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22; ENABLE_BITCODE = NO; diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index b6f6a39d..9565095f 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -36,7 +36,7 @@ CFBundleVersion - 65 + 66 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index bd9a4169..29135810 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -68,7 +68,7 @@ class _MyHomePageState extends State { } catch (error) { debugPrint('[SIWEConfig] getNonce error: $error'); // Fallback patch for testing purposes in case SIWE backend has issues - return AuthUtils.generateNonce(); + return AuthSignature.generateNonce(); } }, getMessageParams: () async { @@ -86,7 +86,7 @@ class _MyHomePageState extends State { // Create SIWE message to be signed. // You can use our provided formatMessage() method of implement your own debugPrint('[SIWEConfig] createMessage()'); - return _w3mService.formatMessage(args); + return AuthSignature.formatMessage(args); }, verifyMessage: (SIWEVerifyMessageArgs args) async { // Implement your verifyMessage to authenticate the user after it. diff --git a/example/pubspec.lock b/example/pubspec.lock index e7cdab56..d387e96f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1097,10 +1097,10 @@ packages: dependency: transitive description: name: walletconnect_flutter_v2 - sha256: "7f6f66038ce0f559c5661c21b6485f0abfe42354605a628c2fb571a02ec1386e" + sha256: "67582d34a3ceaf8253870d624112562e6e0af730bedc7954bd4df0099c277ee4" url: "https://pub.dev" source: hosted - version: "2.3.0-beta03" + version: "2.3.0-beta04" watcher: dependency: transitive description: @@ -1131,7 +1131,7 @@ packages: path: ".." relative: true source: path - version: "3.3.0-beta04" + version: "3.3.0-beta05" web_socket_channel: dependency: transitive description: diff --git a/lib/services/coinbase_service/coinbase_service.dart b/lib/services/coinbase_service/coinbase_service.dart index 2d53c50f..bd06665b 100644 --- a/lib/services/coinbase_service/coinbase_service.dart +++ b/lib/services/coinbase_service/coinbase_service.dart @@ -7,6 +7,7 @@ import 'package:web3modal_flutter/services/coinbase_service/i_coinbase_service.d import 'package:web3modal_flutter/services/coinbase_service/models/coinbase_data.dart'; import 'package:web3modal_flutter/services/coinbase_service/models/coinbase_events.dart'; import 'package:web3modal_flutter/services/explorer_service/explorer_service_singleton.dart'; +import 'package:web3modal_flutter/services/logger_service/logger_service_singleton.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; import 'package:coinbase_wallet_sdk/currency.dart'; @@ -122,12 +123,24 @@ class CoinbaseService implements ICoinbaseService { } @override - Future get ownPublicKey async => - await CoinbaseWalletSDK.shared.ownPublicKey(); + Future get ownPublicKey async { + try { + return await CoinbaseWalletSDK.shared.ownPublicKey(); + } catch (e) { + loggerService.instance.e('[$runtimeType] ownPublicKey $e'); + return ''; + } + } @override - Future get peerPublicKey async => - await CoinbaseWalletSDK.shared.peerPublicKey(); + Future get peerPublicKey async { + try { + return await CoinbaseWalletSDK.shared.peerPublicKey(); + } catch (e) { + loggerService.instance.e('[$runtimeType] peerPublicKey $e'); + return ''; + } + } @override Future getAccount() async { diff --git a/lib/services/siwe_service/utils/siwe_utils.dart b/lib/services/siwe_service/utils/siwe_utils.dart new file mode 100644 index 00000000..72aec9d8 --- /dev/null +++ b/lib/services/siwe_service/utils/siwe_utils.dart @@ -0,0 +1,45 @@ +import 'package:walletconnect_flutter_v2/apis/sign_api/models/auth/common_auth_models.dart'; +import 'package:walletconnect_flutter_v2/apis/sign_api/utils/auth/auth_signature.dart' + as wcfv2; +import 'package:walletconnect_flutter_v2/apis/sign_api/utils/auth/auth_utils.dart'; +import 'package:web3modal_flutter/services/siwe_service/models/w3m_siwe.dart'; +import 'package:web3modal_flutter/services/siwe_service/siwe_service_singleton.dart'; + +class AuthSignature { + /// Given SIWECreateMessageArgs will format message according to EIP-4361 https://docs.login.xyz/general-information/siwe-overview/eip-4361 + static String formatMessage(SIWECreateMessageArgs params) { + return siweService.instance!.formatMessage( + params, + ); + } + + static String getAddressFromMessage(String message) { + return wcfv2.AuthSignature.getAddressFromMessage(message); + } + + static String getChainIdFromMessage(String message) { + return wcfv2.AuthSignature.getChainIdFromMessage(message); + } + + // verifies CACAO signature + // Used by the wallet after formatting the message + static Future verifySignature( + String address, + String message, + CacaoSignature cacaoSignature, + String chainId, + String projectId, + ) async { + return wcfv2.AuthSignature.verifySignature( + address, + message, + cacaoSignature, + chainId, + projectId, + ); + } + + static String generateNonce() { + return AuthUtils.generateNonce(); + } +} diff --git a/lib/services/w3m_service/i_w3m_service.dart b/lib/services/w3m_service/i_w3m_service.dart index 352076f8..c49d16bb 100644 --- a/lib/services/w3m_service/i_w3m_service.dart +++ b/lib/services/w3m_service/i_w3m_service.dart @@ -111,8 +111,6 @@ abstract class IW3MService with ChangeNotifier { Future loadAccountData(); - String formatMessage(SIWECreateMessageArgs params); - /// Disconnects the session and pairing, if any. /// If there is no session, this does nothing. Future disconnect({bool disconnectAllSessions = true}); diff --git a/lib/services/w3m_service/w3m_service.dart b/lib/services/w3m_service/w3m_service.dart index 4d18537a..eb030f7f 100644 --- a/lib/services/w3m_service/w3m_service.dart +++ b/lib/services/w3m_service/w3m_service.dart @@ -721,13 +721,6 @@ class W3MService with ChangeNotifier implements IW3MService { } } - @override - String formatMessage(SIWECreateMessageArgs params) { - return siweService.instance!.formatMessage( - params, - ); - } - @override Future buildConnectionUri() async { if (!_isConnected) { @@ -1002,6 +995,7 @@ class W3MService with ChangeNotifier implements IW3MService { List parameters = const [], }) async { try { + // TODO use blockchain-api if possible. return await _web3App.requestReadContract( deployedContract: deployedContract, functionName: functionName, diff --git a/lib/version.dart b/lib/version.dart index 635a83cf..3212ce43 100644 --- a/lib/version.dart +++ b/lib/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '3.3.0-beta04'; +const packageVersion = '3.3.0-beta05'; diff --git a/lib/web3modal_flutter.dart b/lib/web3modal_flutter.dart index 02f49cfb..aad37a72 100644 --- a/lib/web3modal_flutter.dart +++ b/lib/web3modal_flutter.dart @@ -2,7 +2,8 @@ library web3modal_flutter; /// libraries -export 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; +export 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart' + hide AuthSignature; /// Models export 'models/w3m_chain_info.dart'; @@ -12,6 +13,7 @@ export 'services/siwe_service/models/w3m_siwe.dart'; /// Utils export 'utils/w3m_chains_presets.dart'; export 'utils/util.dart'; +export 'services/siwe_service/utils/siwe_utils.dart'; /// Theme export 'theme/w3m_theme.dart'; diff --git a/pubspec.lock b/pubspec.lock index e08d1a4c..28040cbc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1073,10 +1073,10 @@ packages: dependency: "direct main" description: name: walletconnect_flutter_v2 - sha256: "7f6f66038ce0f559c5661c21b6485f0abfe42354605a628c2fb571a02ec1386e" + sha256: "67582d34a3ceaf8253870d624112562e6e0af730bedc7954bd4df0099c277ee4" url: "https://pub.dev" source: hosted - version: "2.3.0-beta03" + version: "2.3.0-beta04" watcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5566c99e..70d859b3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: web3modal_flutter description: "WalletConnect Web3Modal: Simple, intuitive wallet login. With this drop-in UI SDK, enable any wallet's users to seamlessly log in to your app and enjoy a unified experience" -version: 3.3.0-beta04 +version: 3.3.0-beta05 repository: https://github.com/WalletConnect/Web3ModalFlutter environment: @@ -24,7 +24,7 @@ dependencies: shimmer: ^3.0.0 url_launcher: ^6.2.5 uuid: ^4.3.3 - walletconnect_flutter_v2: ^2.3.0-beta03 + walletconnect_flutter_v2: ^2.3.0-beta04 webview_flutter: ^4.7.0 webview_flutter_android: ^3.16.0 webview_flutter_wkwebview: ^3.13.0 diff --git a/test/mock_classes.mocks.dart b/test/mock_classes.mocks.dart index 8a780536..317be5b8 100644 --- a/test/mock_classes.mocks.dart +++ b/test/mock_classes.mocks.dart @@ -695,21 +695,6 @@ class MockW3MService extends _i1.Mock implements _i3.W3MService { returnValueForMissingStub: _i14.Future.value(), ) as _i14.Future); @override - String formatMessage(_i3.SIWECreateMessageArgs? params) => - (super.noSuchMethod( - Invocation.method( - #formatMessage, - [params], - ), - returnValue: _i13.dummyValue( - this, - Invocation.method( - #formatMessage, - [params], - ), - ), - ) as String); - @override _i14.Future buildConnectionUri() => (super.noSuchMethod( Invocation.method( #buildConnectionUri, @@ -1360,6 +1345,7 @@ class MockWeb3App extends _i1.Mock implements _i3.Web3App { required _i3.DeployedContract? deployedContract, required String? functionName, required String? rpcUrl, + _i3.EthereumAddress? sender, List? parameters = const [], }) => (super.noSuchMethod( @@ -1370,6 +1356,7 @@ class MockWeb3App extends _i1.Mock implements _i3.Web3App { #deployedContract: deployedContract, #functionName: functionName, #rpcUrl: rpcUrl, + #sender: sender, #parameters: parameters, }, ),