Skip to content

Commit

Permalink
Verify API implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Nov 3, 2023
1 parent 109deef commit 3199a12
Show file tree
Hide file tree
Showing 23 changed files with 968 additions and 279 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.9

- Added support for Verify API

## 2.1.8

- Minor changes.
Expand Down
2 changes: 1 addition & 1 deletion example/dapp/lib/pages/connect_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ConnectPageState extends State<ConnectPage> {
// Send off a connect
debugPrint('Creating connection and session');
final ConnectResponse res = await widget.web3App.connect(
requiredNamespaces: requiredNamespaces,
optionalNamespaces: requiredNamespaces,
);
// debugPrint('Connection created, connection response: ${res.uri}');

Expand Down
4 changes: 3 additions & 1 deletion example/wallet/lib/dependencies/web3wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Web3WalletService extends IWeb3WalletService {

@override
void create() {
// Create the web3wallet
// Create the web3wallet
_web3Wallet = Web3Wallet(
core: Core(
projectId: DartDefines.projectId,
Expand All @@ -49,6 +49,7 @@ class Web3WalletService extends IWeb3WalletService {
icons: [
'https://github.com/WalletConnect/Web3ModalFlutter/blob/master/assets/png/logo_wc.png'
],
// verifyUrl: 'https://your_verify_url.here',
),
);

Expand Down Expand Up @@ -137,6 +138,7 @@ class Web3WalletService extends IWeb3WalletService {
wallet: _web3Wallet!,
sessionProposal: WCSessionRequestModel(
request: args.params,
verifyContext: args.verifyContext,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:walletconnect_flutter_v2/apis/core/verify/models/verify_context.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
import 'package:walletconnect_flutter_v2_wallet/utils/constants.dart';
import 'package:walletconnect_flutter_v2_wallet/utils/namespace_model_builder.dart';
Expand Down Expand Up @@ -49,10 +50,8 @@ class WCConnectionRequestWidget extends StatelessWidget {
textAlign: TextAlign.center,
),
const SizedBox(height: StyleConstants.linear8),
Text(
metadata.metadata.url,
style: StyleConstants.bodyText,
textAlign: TextAlign.center,
VerifyContextWidget(
verifyContext: sessionProposal?.verifyContext,
),
const SizedBox(height: StyleConstants.linear8),
authRequest != null
Expand Down Expand Up @@ -109,3 +108,130 @@ class WCConnectionRequestWidget extends StatelessWidget {
// );
}
}

class VerifyContextWidget extends StatelessWidget {
const VerifyContextWidget({
super.key,
required this.verifyContext,
});
final VerifyContext? verifyContext;

@override
Widget build(BuildContext context) {
if (verifyContext == null) {
return const SizedBox.shrink();
}

if (verifyContext!.validation.scam) {
return VerifyBanner(
color: StyleConstants.errorColor,
origin: verifyContext!.origin,
title: 'Security risk',
text: 'This domain is flagged as unsafe by multiple security providers.'
' Leave immediately to protect your assets.',
);
}
if (verifyContext!.validation.invalid) {
return VerifyBanner(
color: StyleConstants.errorColor,
origin: verifyContext!.origin,
title: 'Domain mismatch',
text:
'This website has a domain that does not match the sender of this request.'
' Approving may lead to loss of funds.',
);
}
if (verifyContext!.validation.valid) {
return VerifyHeader(
iconColor: StyleConstants.successColor,
title: verifyContext!.origin,
);
}
return VerifyBanner(
color: Colors.orange,
origin: verifyContext!.origin,
title: 'Cannot verify',
text: 'This domain cannot be verified. '
'Check the request carefully before approving.',
);
}
}

class VerifyHeader extends StatelessWidget {
const VerifyHeader({
super.key,
required this.iconColor,
required this.title,
});
final Color iconColor;
final String title;

@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.shield_outlined,
color: iconColor,
),
const SizedBox(width: StyleConstants.linear8),
Text(
title,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
);
}
}

class VerifyBanner extends StatelessWidget {
const VerifyBanner({
super.key,
required this.origin,
required this.title,
required this.text,
required this.color,
});
final String origin, title, text;
final Color color;

@override
Widget build(BuildContext context) {
return Column(
children: [
Text(
origin,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
const SizedBox.square(dimension: 8.0),
Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: color,
borderRadius: const BorderRadius.all(Radius.circular(12.0)),
),
child: Column(
children: [
VerifyHeader(
iconColor: Colors.white,
title: title,
),
const SizedBox(height: 4.0),
Text(
text,
style: const TextStyle(color: Colors.white),
),
],
),
),
],
);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:walletconnect_flutter_v2/apis/core/verify/models/verify_context.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';

class WCSessionRequestModel {
// final List<String> accounts;
final ProposalData request;
final VerifyContext? verifyContext;

WCSessionRequestModel({
// required this.accounts,
required this.request,
this.verifyContext,
});
}
9 changes: 4 additions & 5 deletions lib/apis/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class Core implements ICore {
String get version => '2';

@override
String relayUrl = WalletConnectConstants.DEFAULT_RELAY_URL;
final String projectId;

@override
final String projectId;
String relayUrl = WalletConnectConstants.DEFAULT_RELAY_URL;

@override
final String pushUrl;
String pushUrl = WalletConnectConstants.DEFAULT_PUSH_URL;

@override
late ICrypto crypto;
Expand Down Expand Up @@ -76,8 +76,8 @@ class Core implements ICore {
late IStore<Map<String, dynamic>> storage;

Core({
this.relayUrl = WalletConnectConstants.DEFAULT_RELAY_URL,
required this.projectId,
this.relayUrl = WalletConnectConstants.DEFAULT_RELAY_URL,
this.pushUrl = WalletConnectConstants.DEFAULT_PUSH_URL,
bool memoryStore = false,
LogLevel logLevel = LogLevel.nothing,
Expand Down Expand Up @@ -169,7 +169,6 @@ class Core implements ICore {
await relayClient.init();
await expirer.init();
await pairing.init();
await verify.init();
heartbeat.init();
}
}
1 change: 1 addition & 0 deletions lib/apis/core/pairing/utils/pairing_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PairingMetadata with _$PairingMetadata {
required String description,
required String url,
required List<String> icons,
String? verifyUrl,
Redirect? redirect,
}) = _PairingMetadata;

Expand Down
25 changes: 23 additions & 2 deletions lib/apis/core/pairing/utils/pairing_models.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ mixin _$PairingMetadata {
String get description => throw _privateConstructorUsedError;
String get url => throw _privateConstructorUsedError;
List<String> get icons => throw _privateConstructorUsedError;
String? get verifyUrl => throw _privateConstructorUsedError;
Redirect? get redirect => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
Expand All @@ -283,6 +284,7 @@ abstract class $PairingMetadataCopyWith<$Res> {
String description,
String url,
List<String> icons,
String? verifyUrl,
Redirect? redirect});

$RedirectCopyWith<$Res>? get redirect;
Expand All @@ -305,6 +307,7 @@ class _$PairingMetadataCopyWithImpl<$Res, $Val extends PairingMetadata>
Object? description = null,
Object? url = null,
Object? icons = null,
Object? verifyUrl = freezed,
Object? redirect = freezed,
}) {
return _then(_value.copyWith(
Expand All @@ -324,6 +327,10 @@ class _$PairingMetadataCopyWithImpl<$Res, $Val extends PairingMetadata>
? _value.icons
: icons // ignore: cast_nullable_to_non_nullable
as List<String>,
verifyUrl: freezed == verifyUrl
? _value.verifyUrl
: verifyUrl // ignore: cast_nullable_to_non_nullable
as String?,
redirect: freezed == redirect
? _value.redirect
: redirect // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -357,6 +364,7 @@ abstract class _$$_PairingMetadataCopyWith<$Res>
String description,
String url,
List<String> icons,
String? verifyUrl,
Redirect? redirect});

@override
Expand All @@ -378,6 +386,7 @@ class __$$_PairingMetadataCopyWithImpl<$Res>
Object? description = null,
Object? url = null,
Object? icons = null,
Object? verifyUrl = freezed,
Object? redirect = freezed,
}) {
return _then(_$_PairingMetadata(
Expand All @@ -397,6 +406,10 @@ class __$$_PairingMetadataCopyWithImpl<$Res>
? _value._icons
: icons // ignore: cast_nullable_to_non_nullable
as List<String>,
verifyUrl: freezed == verifyUrl
? _value.verifyUrl
: verifyUrl // ignore: cast_nullable_to_non_nullable
as String?,
redirect: freezed == redirect
? _value.redirect
: redirect // ignore: cast_nullable_to_non_nullable
Expand All @@ -414,6 +427,7 @@ class _$_PairingMetadata implements _PairingMetadata {
required this.description,
required this.url,
required final List<String> icons,
this.verifyUrl,
this.redirect})
: _icons = icons;

Expand All @@ -434,12 +448,14 @@ class _$_PairingMetadata implements _PairingMetadata {
return EqualUnmodifiableListView(_icons);
}

@override
final String? verifyUrl;
@override
final Redirect? redirect;

@override
String toString() {
return 'PairingMetadata(name: $name, description: $description, url: $url, icons: $icons, redirect: $redirect)';
return 'PairingMetadata(name: $name, description: $description, url: $url, icons: $icons, verifyUrl: $verifyUrl, redirect: $redirect)';
}

@override
Expand All @@ -452,14 +468,16 @@ class _$_PairingMetadata implements _PairingMetadata {
other.description == description) &&
(identical(other.url, url) || other.url == url) &&
const DeepCollectionEquality().equals(other._icons, _icons) &&
(identical(other.verifyUrl, verifyUrl) ||
other.verifyUrl == verifyUrl) &&
(identical(other.redirect, redirect) ||
other.redirect == redirect));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, name, description, url,
const DeepCollectionEquality().hash(_icons), redirect);
const DeepCollectionEquality().hash(_icons), verifyUrl, redirect);

@JsonKey(ignore: true)
@override
Expand All @@ -481,6 +499,7 @@ abstract class _PairingMetadata implements PairingMetadata {
required final String description,
required final String url,
required final List<String> icons,
final String? verifyUrl,
final Redirect? redirect}) = _$_PairingMetadata;

factory _PairingMetadata.fromJson(Map<String, dynamic> json) =
Expand All @@ -495,6 +514,8 @@ abstract class _PairingMetadata implements PairingMetadata {
@override
List<String> get icons;
@override
String? get verifyUrl;
@override
Redirect? get redirect;
@override
@JsonKey(ignore: true)
Expand Down
2 changes: 2 additions & 0 deletions lib/apis/core/pairing/utils/pairing_models.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3199a12

Please sign in to comment.