From 38e255414a7f050cd8df629764a416bf65ea37d3 Mon Sep 17 00:00:00 2001 From: Sterling Long Date: Tue, 11 Jul 2023 17:34:11 -0600 Subject: [PATCH] Updated tests, checked metamask with basic transaction and it is working, need to build a contract TX example --- CHANGELOG.md | 4 +- analysis_options.yaml | 4 + .../models/eth/ethereum_transaction.g.dart | 44 ++ .../solana/solana_sign_transaction.g.dart | 55 ++ example/dapp/lib/utils/crypto/chain_data.dart | 20 +- example/dapp/lib/utils/crypto/helpers.dart | 5 +- example/dapp/lib/utils/crypto/kadena.dart | 420 ++++++++-------- example/dapp/lib/utils/test_data.dart | 150 +++--- example/dapp/lib/widgets/session_widget.dart | 17 +- example/dapp/pubspec.yaml | 2 +- .../dependencies/chains/kadena_service.dart | 468 +++++++++--------- example/wallet/lib/main.dart | 13 +- .../models/eth/ethereum_transaction.g.dart | 44 ++ .../solana/solana_sign_transaction.g.dart | 55 ++ .../kadena_widgets/kadena_sign_widget.dart | 312 ++++++------ example/wallet/pubspec.yaml | 2 +- lib/apis/auth_api/auth_engine.dart | 2 +- lib/apis/sign_api/sign_engine.dart | 6 +- pubspec.yaml | 4 +- test/auth_api/auth_client_test.dart | 2 + test/auth_api/utils/engine_constants.dart | 1 + 21 files changed, 916 insertions(+), 714 deletions(-) create mode 100644 example/dapp/lib/models/eth/ethereum_transaction.g.dart create mode 100644 example/dapp/lib/models/solana/solana_sign_transaction.g.dart create mode 100644 example/wallet/lib/models/eth/ethereum_transaction.g.dart create mode 100644 example/wallet/lib/models/solana/solana_sign_transaction.g.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index fed53ee9..9ddad273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ ## 2.0.13 - Made message in json response nullable to resolve issues with rejection messages - +- Updated readme, added events to RequiredNamespace +- Swapped to `freezed` for all models +- Resolved issue with non-null resources for auth throwing errors ## 2.0.12 diff --git a/analysis_options.yaml b/analysis_options.yaml index 2e362727..2167d23d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -26,5 +26,9 @@ linter: prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule constant_identifier_names: false +analyzer: + errors: + invalid_annotation_target: ignore + # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/example/dapp/lib/models/eth/ethereum_transaction.g.dart b/example/dapp/lib/models/eth/ethereum_transaction.g.dart new file mode 100644 index 00000000..bcf198d0 --- /dev/null +++ b/example/dapp/lib/models/eth/ethereum_transaction.g.dart @@ -0,0 +1,44 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'ethereum_transaction.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +EthereumTransaction _$EthereumTransactionFromJson(Map json) => + EthereumTransaction( + from: json['from'] as String, + to: json['to'] as String, + value: json['value'] as String, + nonce: json['nonce'] as String?, + gasPrice: json['gasPrice'] as String?, + maxFeePerGas: json['maxFeePerGas'] as String?, + maxPriorityFeePerGas: json['maxPriorityFeePerGas'] as String?, + gas: json['gas'] as String?, + gasLimit: json['gasLimit'] as String?, + data: json['data'] as String?, + ); + +Map _$EthereumTransactionToJson(EthereumTransaction instance) { + final val = { + 'from': instance.from, + 'to': instance.to, + 'value': instance.value, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('nonce', instance.nonce); + writeNotNull('gasPrice', instance.gasPrice); + writeNotNull('maxFeePerGas', instance.maxFeePerGas); + writeNotNull('maxPriorityFeePerGas', instance.maxPriorityFeePerGas); + writeNotNull('gas', instance.gas); + writeNotNull('gasLimit', instance.gasLimit); + writeNotNull('data', instance.data); + return val; +} diff --git a/example/dapp/lib/models/solana/solana_sign_transaction.g.dart b/example/dapp/lib/models/solana/solana_sign_transaction.g.dart new file mode 100644 index 00000000..ada6a96d --- /dev/null +++ b/example/dapp/lib/models/solana/solana_sign_transaction.g.dart @@ -0,0 +1,55 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'solana_sign_transaction.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SolanaSignTransaction _$SolanaSignTransactionFromJson( + Map json) => + SolanaSignTransaction( + feePayer: json['feePayer'] as String, + recentBlockhash: json['recentBlockhash'] as String, + instructions: (json['instructions'] as List) + .map((e) => SolanaInstruction.fromJson(e as Map)) + .toList(), + ); + +Map _$SolanaSignTransactionToJson( + SolanaSignTransaction instance) => + { + 'feePayer': instance.feePayer, + 'recentBlockhash': instance.recentBlockhash, + 'instructions': instance.instructions, + }; + +SolanaInstruction _$SolanaInstructionFromJson(Map json) => + SolanaInstruction( + programId: json['programId'] as String, + keys: (json['keys'] as List) + .map((e) => SolanaKeyMetadata.fromJson(e as Map)) + .toList(), + data: json['data'] as String, + ); + +Map _$SolanaInstructionToJson(SolanaInstruction instance) => + { + 'programId': instance.programId, + 'keys': instance.keys, + 'data': instance.data, + }; + +SolanaKeyMetadata _$SolanaKeyMetadataFromJson(Map json) => + SolanaKeyMetadata( + pubkey: json['pubkey'] as String, + isSigner: json['isSigner'] as bool, + isWritable: json['isWritable'] as bool, + ); + +Map _$SolanaKeyMetadataToJson(SolanaKeyMetadata instance) => + { + 'pubkey': instance.pubkey, + 'isSigner': instance.isSigner, + 'isWritable': instance.isWritable, + }; diff --git a/example/dapp/lib/utils/crypto/chain_data.dart b/example/dapp/lib/utils/crypto/chain_data.dart index 66bde95c..5b775089 100644 --- a/example/dapp/lib/utils/crypto/chain_data.dart +++ b/example/dapp/lib/utils/crypto/chain_data.dart @@ -30,16 +30,16 @@ class ChainData { // "https://solana-api.projectserum.com", // ], // ), - ChainMetadata( - type: ChainType.kadena, - chainId: 'kadena:mainnet01', - name: 'Kadena', - logo: 'TODO', - color: Colors.purple.shade600, - rpc: [ - "https://api.testnet.chainweb.com", - ], - ), + // ChainMetadata( + // type: ChainType.kadena, + // chainId: 'kadena:mainnet01', + // name: 'Kadena', + // logo: 'TODO', + // color: Colors.purple.shade600, + // rpc: [ + // "https://api.testnet.chainweb.com", + // ], + // ), ]; static final List testChains = [ diff --git a/example/dapp/lib/utils/crypto/helpers.dart b/example/dapp/lib/utils/crypto/helpers.dart index 8656f77a..92829805 100644 --- a/example/dapp/lib/utils/crypto/helpers.dart +++ b/example/dapp/lib/utils/crypto/helpers.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:walletconnect_flutter_v2_dapp/models/chain_metadata.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/chain_data.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/eip155.dart'; -import 'package:walletconnect_flutter_v2_dapp/utils/crypto/kadena.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/solana_data.dart'; String getChainName(String chain) { @@ -32,7 +31,7 @@ List getChainMethods(ChainType value) { if (value == ChainType.solana) { return SolanaData.methods.values.toList(); } else if (value == ChainType.kadena) { - return Kadena.methods.values.toList(); + return EIP155.methods.values.toList(); //Kadena.methods.values.toList(); } else { return EIP155.methods.values.toList(); } @@ -42,7 +41,7 @@ List getChainEvents(ChainType value) { if (value == ChainType.solana) { return SolanaData.events.values.toList(); } else if (value == ChainType.kadena) { - return Kadena.events.values.toList(); + return EIP155.events.values.toList(); //Kadena.events.values.toList(); } else { return EIP155.events.values.toList(); } diff --git a/example/dapp/lib/utils/crypto/kadena.dart b/example/dapp/lib/utils/crypto/kadena.dart index c2d090eb..29db4344 100644 --- a/example/dapp/lib/utils/crypto/kadena.dart +++ b/example/dapp/lib/utils/crypto/kadena.dart @@ -1,225 +1,225 @@ -import 'dart:convert'; +// import 'dart:convert'; -import 'package:kadena_dart_sdk/kadena_dart_sdk.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; -import 'package:walletconnect_flutter_v2_dapp/utils/test_data.dart'; +// import 'package:kadena_dart_sdk/kadena_dart_sdk.dart'; +// import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; +// import 'package:walletconnect_flutter_v2_dapp/utils/test_data.dart'; -enum KadenaMethods { - sign, - quicksign, - kadenaSignV1, - kadenaQuicksignV1, - kadenaGetAccountsV1, -} +// enum KadenaMethods { +// sign, +// quicksign, +// kadenaSignV1, +// kadenaQuicksignV1, +// kadenaGetAccountsV1, +// } -enum KadenaEvents { - none, -} +// enum KadenaEvents { +// none, +// } -extension KadenaMethodsX on KadenaMethods { - String? get value => Kadena.methods[this]; -} +// extension KadenaMethodsX on KadenaMethods { +// String? get value => Kadena.methods[this]; +// } -extension KadenaMethodsStringX on String { - KadenaMethods? toKadenaMethod() { - final entries = Kadena.methods.entries.where( - (element) => element.value == this, - ); - return (entries.isNotEmpty) ? entries.first.key : null; - } -} +// extension KadenaMethodsStringX on String { +// KadenaMethods? toKadenaMethod() { +// final entries = Kadena.methods.entries.where( +// (element) => element.value == this, +// ); +// return (entries.isNotEmpty) ? entries.first.key : null; +// } +// } -extension KadenaEventsX on KadenaEvents { - String? get value => Kadena.events[this]; -} +// extension KadenaEventsX on KadenaEvents { +// String? get value => Kadena.events[this]; +// } -extension KadenaEventsStringX on String { - KadenaEvents? toKadenaEvent() { - final entries = Kadena.events.entries.where( - (element) => element.value == this, - ); - return (entries.isNotEmpty) ? entries.first.key : null; - } -} +// extension KadenaEventsStringX on String { +// KadenaEvents? toKadenaEvent() { +// final entries = Kadena.events.entries.where( +// (element) => element.value == this, +// ); +// return (entries.isNotEmpty) ? entries.first.key : null; +// } +// } -class Kadena { - static final Map methods = { - KadenaMethods.sign: 'kadena_sign', - KadenaMethods.quicksign: 'kadena_quicksign', - KadenaMethods.kadenaSignV1: 'kadena_sign_v1', - KadenaMethods.kadenaQuicksignV1: 'kadena_quicksign_v1', - KadenaMethods.kadenaGetAccountsV1: 'kadena_getAccounts_v1' - }; +// class Kadena { +// static final Map methods = { +// KadenaMethods.sign: 'kadena_sign', +// KadenaMethods.quicksign: 'kadena_quicksign', +// KadenaMethods.kadenaSignV1: 'kadena_sign_v1', +// KadenaMethods.kadenaQuicksignV1: 'kadena_quicksign_v1', +// KadenaMethods.kadenaGetAccountsV1: 'kadena_getAccounts_v1' +// }; - static final Map events = {}; +// static final Map events = {}; - static Future callMethod({ - required Web3App web3App, - required String topic, - required KadenaMethods method, - required String chainId, - required String address, - }) { - final String addressActual = - address.startsWith('k**') ? address.substring(3) : address; +// static Future callMethod({ +// required Web3App web3App, +// required String topic, +// required KadenaMethods method, +// required String chainId, +// required String address, +// }) { +// final String addressActual = +// address.startsWith('k**') ? address.substring(3) : address; - switch (method) { - case KadenaMethods.sign: - case KadenaMethods.kadenaSignV1: - return kadenaSignV1( - web3App: web3App, - method: method, - topic: topic, - chainId: chainId, - data: createSignRequest( - networkId: chainId.split(':')[1], - signingPubKey: addressActual, - sender: 'k:$addressActual', - caps: [ - DappCapp( - role: 'Test', - description: 'description', - cap: Capability( - name: 'coin.GAS', - ), - ), - DappCapp( - role: 'Test', - description: 'description', - cap: Capability( - name: 'coin.TRANSFER', - args: ['sender', 'receiver', 1.0], - ), - ), - ], - ), - ); - case KadenaMethods.quicksign: - case KadenaMethods.kadenaQuicksignV1: - return kadenaQuicksignV1( - web3App: web3App, - topic: topic, - chainId: chainId, - data: QuicksignRequest( - commandSigDatas: [ - CommandSigData( - cmd: jsonEncode( - createPactCommandPayload( - networkId: chainId.split(':')[1], - sender: 'k:$addressActual', - signerCaps: [ - SignerCapabilities( - pubKey: addressActual, - clist: [ - Capability( - name: 'coin.GAS', - ), - Capability( - name: 'coin.TRANSFER', - args: ['sender', 'receiver', 1.0], - ), - ], - ), - ], - ).toJson(), - ), - sigs: [ - QuicksignSigner( - pubKey: addressActual, - ), - ], - ), - CommandSigData( - cmd: jsonEncode( - createPactCommandPayload( - networkId: chainId.split(':')[1], - sender: 'k:$addressActual', - signerCaps: [ - SignerCapabilities( - pubKey: addressActual, - clist: [ - Capability( - name: 'coin.GAS', - ), - Capability( - name: 'coin.TRANSFER', - args: ['sender2', 'receiver2', 2.0], - ), - ], - ), - ], - ).toJson(), - ), - sigs: [ - QuicksignSigner( - pubKey: addressActual, - ), - ], - ), - ], - ), - ); +// switch (method) { +// case KadenaMethods.sign: +// case KadenaMethods.kadenaSignV1: +// return kadenaSignV1( +// web3App: web3App, +// method: method, +// topic: topic, +// chainId: chainId, +// data: createSignRequest( +// networkId: chainId.split(':')[1], +// signingPubKey: addressActual, +// sender: 'k:$addressActual', +// caps: [ +// DappCapp( +// role: 'Test', +// description: 'description', +// cap: Capability( +// name: 'coin.GAS', +// ), +// ), +// DappCapp( +// role: 'Test', +// description: 'description', +// cap: Capability( +// name: 'coin.TRANSFER', +// args: ['sender', 'receiver', 1.0], +// ), +// ), +// ], +// ), +// ); +// case KadenaMethods.quicksign: +// case KadenaMethods.kadenaQuicksignV1: +// return kadenaQuicksignV1( +// web3App: web3App, +// topic: topic, +// chainId: chainId, +// data: QuicksignRequest( +// commandSigDatas: [ +// CommandSigData( +// cmd: jsonEncode( +// createPactCommandPayload( +// networkId: chainId.split(':')[1], +// sender: 'k:$addressActual', +// signerCaps: [ +// SignerCapabilities( +// pubKey: addressActual, +// clist: [ +// Capability( +// name: 'coin.GAS', +// ), +// Capability( +// name: 'coin.TRANSFER', +// args: ['sender', 'receiver', 1.0], +// ), +// ], +// ), +// ], +// ).toJson(), +// ), +// sigs: [ +// QuicksignSigner( +// pubKey: addressActual, +// ), +// ], +// ), +// CommandSigData( +// cmd: jsonEncode( +// createPactCommandPayload( +// networkId: chainId.split(':')[1], +// sender: 'k:$addressActual', +// signerCaps: [ +// SignerCapabilities( +// pubKey: addressActual, +// clist: [ +// Capability( +// name: 'coin.GAS', +// ), +// Capability( +// name: 'coin.TRANSFER', +// args: ['sender2', 'receiver2', 2.0], +// ), +// ], +// ), +// ], +// ).toJson(), +// ), +// sigs: [ +// QuicksignSigner( +// pubKey: addressActual, +// ), +// ], +// ), +// ], +// ), +// ); - case KadenaMethods.kadenaGetAccountsV1: - return kadenaGetAccountsV1( - web3App: web3App, - topic: topic, - chainId: chainId, - data: createGetAccountsRequest(account: '$chainId:$addressActual'), - ); - } - } +// case KadenaMethods.kadenaGetAccountsV1: +// return kadenaGetAccountsV1( +// web3App: web3App, +// topic: topic, +// chainId: chainId, +// data: createGetAccountsRequest(account: '$chainId:$addressActual'), +// ); +// } +// } - static Future kadenaSignV1({ - required Web3App web3App, - required KadenaMethods method, - required String topic, - required String chainId, - required SignRequest data, - }) async { - // print(jsonEncode(data)); - final ret = await web3App.request( - topic: topic, - chainId: chainId, - request: SessionRequestParams( - method: methods[method]!, - params: data, - ), - ); - // print('ret: $ret'); - // print(ret.runtimeType); - return ret; - } +// static Future kadenaSignV1({ +// required Web3App web3App, +// required KadenaMethods method, +// required String topic, +// required String chainId, +// required SignRequest data, +// }) async { +// // print(jsonEncode(data)); +// final ret = await web3App.request( +// topic: topic, +// chainId: chainId, +// request: SessionRequestParams( +// method: methods[method]!, +// params: data, +// ), +// ); +// // print('ret: $ret'); +// // print(ret.runtimeType); +// return ret; +// } - static Future kadenaQuicksignV1({ - required Web3App web3App, - required String topic, - required String chainId, - required QuicksignRequest data, - }) async { - return await web3App.request( - topic: topic, - chainId: chainId, - request: SessionRequestParams( - method: methods[KadenaMethods.kadenaQuicksignV1]!, - params: data.toJson(), - ), - ); - } +// static Future kadenaQuicksignV1({ +// required Web3App web3App, +// required String topic, +// required String chainId, +// required QuicksignRequest data, +// }) async { +// return await web3App.request( +// topic: topic, +// chainId: chainId, +// request: SessionRequestParams( +// method: methods[KadenaMethods.kadenaQuicksignV1]!, +// params: data.toJson(), +// ), +// ); +// } - static Future kadenaGetAccountsV1({ - required Web3App web3App, - required String topic, - required String chainId, - required GetAccountsRequest data, - }) async { - return await web3App.request( - topic: topic, - chainId: chainId, - request: SessionRequestParams( - method: methods[KadenaMethods.kadenaGetAccountsV1]!, - params: data.toJson(), - ), - ); - } -} +// static Future kadenaGetAccountsV1({ +// required Web3App web3App, +// required String topic, +// required String chainId, +// required GetAccountsRequest data, +// }) async { +// return await web3App.request( +// topic: topic, +// chainId: chainId, +// request: SessionRequestParams( +// method: methods[KadenaMethods.kadenaGetAccountsV1]!, +// params: data.toJson(), +// ), +// ); +// } +// } diff --git a/example/dapp/lib/utils/test_data.dart b/example/dapp/lib/utils/test_data.dart index f177b9ba..ead87b98 100644 --- a/example/dapp/lib/utils/test_data.dart +++ b/example/dapp/lib/utils/test_data.dart @@ -1,7 +1,5 @@ import 'dart:convert'; -import 'package:kadena_dart_sdk/kadena_dart_sdk.dart'; - const String testSignData = 'Test sign data'; String testSignTypedData(String address) => jsonEncode( { @@ -40,80 +38,80 @@ const typedData = /// KADENA /// -SignRequest createSignRequest({ - required String networkId, - required String signingPubKey, - required String sender, - String code = '"hello"', - Map? data, - List caps = const [], - String chainId = '1', - int gasLimit = 2000, - double gasPrice = 1e-8, - int ttl = 600, -}) => - SignRequest( - code: code, - data: data ?? {}, - sender: sender, - networkId: networkId, - chainId: chainId, - gasLimit: gasLimit, - gasPrice: gasPrice, - signingPubKey: signingPubKey, - ttl: ttl, - caps: caps, - ); +// SignRequest createSignRequest({ +// required String networkId, +// required String signingPubKey, +// required String sender, +// String code = '"hello"', +// Map? data, +// List caps = const [], +// String chainId = '1', +// int gasLimit = 2000, +// double gasPrice = 1e-8, +// int ttl = 600, +// }) => +// SignRequest( +// code: code, +// data: data ?? {}, +// sender: sender, +// networkId: networkId, +// chainId: chainId, +// gasLimit: gasLimit, +// gasPrice: gasPrice, +// signingPubKey: signingPubKey, +// ttl: ttl, +// caps: caps, +// ); -PactCommandPayload createPactCommandPayload({ - required String networkId, - required String sender, - String code = '"hello"', - Map? data, - List signerCaps = const [], - String chainId = '1', - int gasLimit = 2000, - double gasPrice = 1e-8, - int ttl = 600, -}) => - PactCommandPayload( - networkId: networkId, - payload: CommandPayload( - exec: ExecMessage( - code: code, - data: data ?? {}, - ), - ), - signers: signerCaps, - meta: CommandMetadata( - chainId: chainId, - gasLimit: gasLimit, - gasPrice: gasPrice, - ttl: ttl, - sender: sender, - ), - ); +// PactCommandPayload createPactCommandPayload({ +// required String networkId, +// required String sender, +// String code = '"hello"', +// Map? data, +// List signerCaps = const [], +// String chainId = '1', +// int gasLimit = 2000, +// double gasPrice = 1e-8, +// int ttl = 600, +// }) => +// PactCommandPayload( +// networkId: networkId, +// payload: CommandPayload( +// exec: ExecMessage( +// code: code, +// data: data ?? {}, +// ), +// ), +// signers: signerCaps, +// meta: CommandMetadata( +// chainId: chainId, +// gasLimit: gasLimit, +// gasPrice: gasPrice, +// ttl: ttl, +// sender: sender, +// ), +// ); -QuicksignRequest createQuicksignRequest({ - required String cmd, - List sigs = const [], -}) => - QuicksignRequest( - commandSigDatas: [ - CommandSigData( - cmd: cmd, - sigs: sigs, - ), - ], - ); +// QuicksignRequest createQuicksignRequest({ +// required String cmd, +// List sigs = const [], +// }) => +// QuicksignRequest( +// commandSigDatas: [ +// CommandSigData( +// cmd: cmd, +// sigs: sigs, +// ), +// ], +// ); -GetAccountsRequest createGetAccountsRequest({ - required String account, -}) => - GetAccountsRequest( - accounts: [ - AccountRequest( - account: account, - ), - ], - ); +// GetAccountsRequest createGetAccountsRequest({ +// required String account, +// }) => +// GetAccountsRequest( +// accounts: [ +// AccountRequest( +// account: account, +// ), +// ], +// ); diff --git a/example/dapp/lib/widgets/session_widget.dart b/example/dapp/lib/widgets/session_widget.dart index 7b1530f9..ab3b7dd8 100644 --- a/example/dapp/lib/widgets/session_widget.dart +++ b/example/dapp/lib/widgets/session_widget.dart @@ -4,7 +4,6 @@ import 'package:walletconnect_flutter_v2_dapp/models/chain_metadata.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/eip155.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/helpers.dart'; -import 'package:walletconnect_flutter_v2_dapp/utils/crypto/kadena.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/string_constants.dart'; import 'package:walletconnect_flutter_v2_dapp/widgets/method_dialog.dart'; @@ -276,14 +275,14 @@ class SessionWidgetState extends State { chainId: chainMetadata.chainId, address: address.toLowerCase(), ); - case ChainType.kadena: - return Kadena.callMethod( - web3App: widget.web3App, - topic: widget.session.topic, - method: method.toKadenaMethod()!, - chainId: chainMetadata.chainId, - address: address.toLowerCase(), - ); + // case ChainType.kadena: + // return Kadena.callMethod( + // web3App: widget.web3App, + // topic: widget.session.topic, + // method: method.toKadenaMethod()!, + // chainId: chainMetadata.chainId, + // address: address.toLowerCase(), + // ); default: return Future.value(); } diff --git a/example/dapp/pubspec.yaml b/example/dapp/pubspec.yaml index a87475d0..17636ba0 100644 --- a/example/dapp/pubspec.yaml +++ b/example/dapp/pubspec.yaml @@ -40,7 +40,7 @@ dependencies: walletconnect_flutter_v2: path: ../.. fl_toast: ^3.1.0 - kadena_dart_sdk: ^2.0.0 + # kadena_dart_sdk: ^2.0.0 dev_dependencies: flutter_test: diff --git a/example/wallet/lib/dependencies/chains/kadena_service.dart b/example/wallet/lib/dependencies/chains/kadena_service.dart index a4436ff8..1394825f 100644 --- a/example/wallet/lib/dependencies/chains/kadena_service.dart +++ b/example/wallet/lib/dependencies/chains/kadena_service.dart @@ -1,265 +1,265 @@ -import 'dart:convert'; +// import 'dart:convert'; -import 'package:get_it/get_it.dart'; -import 'package:kadena_dart_sdk/kadena_dart_sdk.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; -import 'package:walletconnect_flutter_v2_wallet/dependencies/chains/i_chain.dart'; -import 'package:walletconnect_flutter_v2_wallet/dependencies/bottom_sheet/i_bottom_sheet_service.dart'; -import 'package:walletconnect_flutter_v2_wallet/dependencies/i_web3wallet_service.dart'; -import 'package:walletconnect_flutter_v2_wallet/dependencies/key_service/chain_key.dart'; -import 'package:walletconnect_flutter_v2_wallet/dependencies/key_service/i_key_service.dart'; -import 'package:walletconnect_flutter_v2_wallet/widgets/kadena_widgets/kadena_sign_widget.dart'; +// import 'package:get_it/get_it.dart'; +// import 'package:kadena_dart_sdk/kadena_dart_sdk.dart'; +// import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; +// import 'package:walletconnect_flutter_v2_wallet/dependencies/chains/i_chain.dart'; +// import 'package:walletconnect_flutter_v2_wallet/dependencies/bottom_sheet/i_bottom_sheet_service.dart'; +// import 'package:walletconnect_flutter_v2_wallet/dependencies/i_web3wallet_service.dart'; +// import 'package:walletconnect_flutter_v2_wallet/dependencies/key_service/chain_key.dart'; +// import 'package:walletconnect_flutter_v2_wallet/dependencies/key_service/i_key_service.dart'; +// import 'package:walletconnect_flutter_v2_wallet/widgets/kadena_widgets/kadena_sign_widget.dart'; -enum KadenaChainId { - testnet04, - mainnet01, - development, -} +// enum KadenaChainId { +// testnet04, +// mainnet01, +// development, +// } -extension KadenaChainIdX on KadenaChainId { - String get chain => '${KadenaService.namespace}:$name'; -} +// extension KadenaChainIdX on KadenaChainId { +// String get chain => '${KadenaService.namespace}:$name'; +// } -class KadenaService extends IChain { - static const namespace = 'kadena'; - static const kadenaSign = 'kadena_sign'; - static const kadenaQuicksign = 'kadena_quicksign'; - static const kadenaSignV1 = 'kadena_sign_v1'; - static const kadenaQuicksignV1 = 'kadena_quicksign_v1'; - static const kadenaGetAccountsV1 = 'kadena_getAccounts_v1'; +// class KadenaService extends IChain { +// static const namespace = 'kadena'; +// static const kadenaSign = 'kadena_sign'; +// static const kadenaQuicksign = 'kadena_quicksign'; +// static const kadenaSignV1 = 'kadena_sign_v1'; +// static const kadenaQuicksignV1 = 'kadena_quicksign_v1'; +// static const kadenaGetAccountsV1 = 'kadena_getAccounts_v1'; - final ISigningApi _signingApi = SigningApi(); - final IBottomSheetService _bottomSheetService = - GetIt.I(); - final IWeb3WalletService _web3WalletService = GetIt.I(); +// final ISigningApi _signingApi = SigningApi(); +// final IBottomSheetService _bottomSheetService = +// GetIt.I(); +// final IWeb3WalletService _web3WalletService = GetIt.I(); - final KadenaChainId reference; +// final KadenaChainId reference; - KadenaService({ - required this.reference, - }) { - final Web3Wallet wallet = _web3WalletService.getWeb3Wallet(); - for (final String event in getEvents()) { - wallet.registerEventEmitter(chainId: getChainId(), event: event); - } - wallet.registerRequestHandler( - chainId: getChainId(), - method: kadenaSign, - handler: signV1, - ); - wallet.registerRequestHandler( - chainId: getChainId(), - method: kadenaSignV1, - handler: signV1, - ); - wallet.registerRequestHandler( - chainId: getChainId(), - method: kadenaQuicksign, - handler: quicksignV1, - ); - wallet.registerRequestHandler( - chainId: getChainId(), - method: kadenaQuicksignV1, - handler: quicksignV1, - ); - wallet.registerRequestHandler( - chainId: getChainId(), - method: kadenaGetAccountsV1, - handler: getAccountsV1, - ); - } +// KadenaService({ +// required this.reference, +// }) { +// final Web3Wallet wallet = _web3WalletService.getWeb3Wallet(); +// for (final String event in getEvents()) { +// wallet.registerEventEmitter(chainId: getChainId(), event: event); +// } +// wallet.registerRequestHandler( +// chainId: getChainId(), +// method: kadenaSign, +// handler: signV1, +// ); +// wallet.registerRequestHandler( +// chainId: getChainId(), +// method: kadenaSignV1, +// handler: signV1, +// ); +// wallet.registerRequestHandler( +// chainId: getChainId(), +// method: kadenaQuicksign, +// handler: quicksignV1, +// ); +// wallet.registerRequestHandler( +// chainId: getChainId(), +// method: kadenaQuicksignV1, +// handler: quicksignV1, +// ); +// wallet.registerRequestHandler( +// chainId: getChainId(), +// method: kadenaGetAccountsV1, +// handler: getAccountsV1, +// ); +// } - @override - String getNamespace() { - return namespace; - } +// @override +// String getNamespace() { +// return namespace; +// } - @override - String getChainId() { - return reference.chain; - } +// @override +// String getChainId() { +// return reference.chain; +// } - @override - List getEvents() { - return ['kadena_transaction_updated']; - } +// @override +// List getEvents() { +// return ['kadena_transaction_updated']; +// } - Future signV1(String topic, dynamic parameters) async { - // print('received kadena sign request: $parameters'); - // Parse the request - late SignRequest signRequest; - try { - signRequest = _signingApi.parseSignRequest( - request: parameters, - ); - } catch (e) { - print(e); - rethrow; - } +// Future signV1(String topic, dynamic parameters) async { +// // print('received kadena sign request: $parameters'); +// // Parse the request +// late SignRequest signRequest; +// try { +// signRequest = _signingApi.parseSignRequest( +// request: parameters, +// ); +// } catch (e) { +// print(e); +// rethrow; +// } - // Get the keys for the kadena chain - final List keys = GetIt.I().getKeysForChain( - getChainId(), - ); +// // Get the keys for the kadena chain +// final List keys = GetIt.I().getKeysForChain( +// getChainId(), +// ); - final PactCommandPayload payload = _signingApi.constructPactCommandPayload( - request: signRequest, - signingPubKey: keys[0].publicKey, - ); +// final PactCommandPayload payload = _signingApi.constructPactCommandPayload( +// request: signRequest, +// signingPubKey: keys[0].publicKey, +// ); - // Show the sign widget - final List? approved = await _bottomSheetService.queueBottomSheet( - widget: KadenaSignWidget(payloads: [payload]), - ); +// // Show the sign widget +// final List? approved = await _bottomSheetService.queueBottomSheet( +// widget: KadenaSignWidget(payloads: [payload]), +// ); - // If the user approved, sign the request - if (approved != null && approved[0]) { - final SignResult signature = _signingApi.sign( - payload: payload, - keyPair: KadenaSignKeyPair( - privateKey: keys[0].privateKey, - publicKey: keys[0].publicKey, - ), - ); +// // If the user approved, sign the request +// if (approved != null && approved[0]) { +// final SignResult signature = _signingApi.sign( +// payload: payload, +// keyPair: KadenaSignKeyPair( +// privateKey: keys[0].privateKey, +// publicKey: keys[0].publicKey, +// ), +// ); - // Return the signature - // print(jsonEncode(signature)); - return signature; - } else { - throw Errors.getSdkError(Errors.USER_REJECTED_SIGN); - } - } +// // Return the signature +// // print(jsonEncode(signature)); +// return signature; +// } else { +// throw Errors.getSdkError(Errors.USER_REJECTED_SIGN); +// } +// } - Future quicksignV1(String topic, dynamic parameters) async { - // print('received kadena quicksign request: $parameters'); - // Parse the request - late QuicksignRequest quicksignRequest; - try { - quicksignRequest = _signingApi.parseQuicksignRequest( - request: parameters, - ); - } catch (e) { - print(e); - rethrow; - } +// Future quicksignV1(String topic, dynamic parameters) async { +// // print('received kadena quicksign request: $parameters'); +// // Parse the request +// late QuicksignRequest quicksignRequest; +// try { +// quicksignRequest = _signingApi.parseQuicksignRequest( +// request: parameters, +// ); +// } catch (e) { +// print(e); +// rethrow; +// } - // Show the sign widget - final List? approved = await _bottomSheetService.queueBottomSheet( - widget: KadenaSignWidget( - payloads: quicksignRequest.commandSigDatas - .map( - (e) => PactCommandPayload.fromJson( - jsonDecode(e.cmd), - ), - ) - .toList(), - ), - ); +// // Show the sign widget +// final List? approved = await _bottomSheetService.queueBottomSheet( +// widget: KadenaSignWidget( +// payloads: quicksignRequest.commandSigDatas +// .map( +// (e) => PactCommandPayload.fromJson( +// jsonDecode(e.cmd), +// ), +// ) +// .toList(), +// ), +// ); - // If the user approved, sign the request - // print('approved: $approved'); - if (approved != null) { - // Get the keys for the kadena chain - final List keys = GetIt.I().getKeysForChain( - getChainId(), - ); +// // If the user approved, sign the request +// // print('approved: $approved'); +// if (approved != null) { +// // Get the keys for the kadena chain +// final List keys = GetIt.I().getKeysForChain( +// getChainId(), +// ); - final List signatures = []; +// final List signatures = []; - // Loop through the requests and sign each one that is true - for (int i = 0; i < approved.length; i++) { - final bool isApproved = approved[i]; - final CommandSigData request = quicksignRequest.commandSigDatas[i]; - late QuicksignResponse signature; - if (isApproved) { - signature = _signingApi.quicksignSingleCommand( - commandSigData: request, - keyPairs: [ - KadenaSignKeyPair( - privateKey: keys[0].privateKey, - publicKey: keys[0].publicKey, - ) - ], - ); - } else { - signature = QuicksignResponse( - commandSigData: request, - outcome: QuicksignOutcome( - result: QuicksignOutcome.failure, - msg: 'User rejected sign', - ), - ); - } +// // Loop through the requests and sign each one that is true +// for (int i = 0; i < approved.length; i++) { +// final bool isApproved = approved[i]; +// final CommandSigData request = quicksignRequest.commandSigDatas[i]; +// late QuicksignResponse signature; +// if (isApproved) { +// signature = _signingApi.quicksignSingleCommand( +// commandSigData: request, +// keyPairs: [ +// KadenaSignKeyPair( +// privateKey: keys[0].privateKey, +// publicKey: keys[0].publicKey, +// ) +// ], +// ); +// } else { +// signature = QuicksignResponse( +// commandSigData: request, +// outcome: QuicksignOutcome( +// result: QuicksignOutcome.failure, +// msg: 'User rejected sign', +// ), +// ); +// } - signatures.add(signature); - } +// signatures.add(signature); +// } - final QuicksignResult result = QuicksignResult( - responses: signatures, - ); +// final QuicksignResult result = QuicksignResult( +// responses: signatures, +// ); - // Return the signature - // print('responding with: $result'); - return result; - } else { - throw Errors.getSdkError(Errors.USER_REJECTED_SIGN); - } - } +// // Return the signature +// // print('responding with: $result'); +// return result; +// } else { +// throw Errors.getSdkError(Errors.USER_REJECTED_SIGN); +// } +// } - Future getAccountsV1( - String topic, dynamic parameters) async { - // print('received kadena getAccounts request: $parameters'); - // Parse the request - late GetAccountsRequest getAccountsRequest; - try { - getAccountsRequest = GetAccountsRequest.fromJson(parameters); - } catch (e) { - print(e); - return GetAccountsResponse(accounts: []); - } +// Future getAccountsV1( +// String topic, dynamic parameters) async { +// // print('received kadena getAccounts request: $parameters'); +// // Parse the request +// late GetAccountsRequest getAccountsRequest; +// try { +// getAccountsRequest = GetAccountsRequest.fromJson(parameters); +// } catch (e) { +// print(e); +// return GetAccountsResponse(accounts: []); +// } - // Get the keys for the kadena chain - final List keys = GetIt.I().getKeysForChain( - getChainId(), - ); +// // Get the keys for the kadena chain +// final List keys = GetIt.I().getKeysForChain( +// getChainId(), +// ); - final List kadenaAccounts = []; +// final List kadenaAccounts = []; - kadenaAccounts.add( - KadenaAccount( - name: 'k:${keys[0].publicKey}', - contract: 'coin', - chains: ['1'], - ), - ); +// kadenaAccounts.add( +// KadenaAccount( +// name: 'k:${keys[0].publicKey}', +// contract: 'coin', +// chains: ['1'], +// ), +// ); - // Loop through the contracts of the request if it exists and add all accounts - if (getAccountsRequest.accounts.first.contracts != null) { - for (final String contract - in getAccountsRequest.accounts.first.contracts!) { - if (contract == 'coin') { - continue; - } +// // Loop through the contracts of the request if it exists and add all accounts +// if (getAccountsRequest.accounts.first.contracts != null) { +// for (final String contract +// in getAccountsRequest.accounts.first.contracts!) { +// if (contract == 'coin') { +// continue; +// } - kadenaAccounts.add( - KadenaAccount( - name: 'k:${keys[0].publicKey}', - contract: contract, - chains: ['1'], - ), - ); - } - } +// kadenaAccounts.add( +// KadenaAccount( +// name: 'k:${keys[0].publicKey}', +// contract: contract, +// chains: ['1'], +// ), +// ); +// } +// } - // Return the accounts - return GetAccountsResponse( - accounts: [ - AccountResponse( - account: '${getChainId()}${keys[0].publicKey}', - publicKey: keys[0].publicKey, - kadenaAccounts: kadenaAccounts, - ), - ], - ); - } -} +// // Return the accounts +// return GetAccountsResponse( +// accounts: [ +// AccountResponse( +// account: '${getChainId()}${keys[0].publicKey}', +// publicKey: keys[0].publicKey, +// kadenaAccounts: kadenaAccounts, +// ), +// ], +// ); +// } +// } diff --git a/example/wallet/lib/main.dart b/example/wallet/lib/main.dart index 66025d4f..9dc5ce25 100644 --- a/example/wallet/lib/main.dart +++ b/example/wallet/lib/main.dart @@ -4,7 +4,6 @@ import 'package:walletconnect_flutter_v2_wallet/dependencies/bottom_sheet/bottom import 'package:walletconnect_flutter_v2_wallet/dependencies/bottom_sheet/bottom_sheet_service.dart'; import 'package:walletconnect_flutter_v2_wallet/dependencies/chains/evm_service.dart'; import 'package:walletconnect_flutter_v2_wallet/dependencies/chains/i_chain.dart'; -import 'package:walletconnect_flutter_v2_wallet/dependencies/chains/kadena_service.dart'; import 'package:walletconnect_flutter_v2_wallet/dependencies/bottom_sheet/i_bottom_sheet_service.dart'; import 'package:walletconnect_flutter_v2_wallet/dependencies/i_web3wallet_service.dart'; import 'package:walletconnect_flutter_v2_wallet/dependencies/key_service/i_key_service.dart'; @@ -131,12 +130,12 @@ class _MyHomePageState extends State with GetItStateMixin { web3WalletService.create(); GetIt.I.registerSingleton(web3WalletService); - for (final cId in KadenaChainId.values) { - GetIt.I.registerSingleton( - KadenaService(reference: cId), - instanceName: cId.chain, - ); - } + // for (final cId in KadenaChainId.values) { + // GetIt.I.registerSingleton( + // KadenaService(reference: cId), + // instanceName: cId.chain, + // ); + // } for (final cId in EVMChainId.values) { GetIt.I.registerSingleton( diff --git a/example/wallet/lib/models/eth/ethereum_transaction.g.dart b/example/wallet/lib/models/eth/ethereum_transaction.g.dart new file mode 100644 index 00000000..bcf198d0 --- /dev/null +++ b/example/wallet/lib/models/eth/ethereum_transaction.g.dart @@ -0,0 +1,44 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'ethereum_transaction.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +EthereumTransaction _$EthereumTransactionFromJson(Map json) => + EthereumTransaction( + from: json['from'] as String, + to: json['to'] as String, + value: json['value'] as String, + nonce: json['nonce'] as String?, + gasPrice: json['gasPrice'] as String?, + maxFeePerGas: json['maxFeePerGas'] as String?, + maxPriorityFeePerGas: json['maxPriorityFeePerGas'] as String?, + gas: json['gas'] as String?, + gasLimit: json['gasLimit'] as String?, + data: json['data'] as String?, + ); + +Map _$EthereumTransactionToJson(EthereumTransaction instance) { + final val = { + 'from': instance.from, + 'to': instance.to, + 'value': instance.value, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('nonce', instance.nonce); + writeNotNull('gasPrice', instance.gasPrice); + writeNotNull('maxFeePerGas', instance.maxFeePerGas); + writeNotNull('maxPriorityFeePerGas', instance.maxPriorityFeePerGas); + writeNotNull('gas', instance.gas); + writeNotNull('gasLimit', instance.gasLimit); + writeNotNull('data', instance.data); + return val; +} diff --git a/example/wallet/lib/models/solana/solana_sign_transaction.g.dart b/example/wallet/lib/models/solana/solana_sign_transaction.g.dart new file mode 100644 index 00000000..ada6a96d --- /dev/null +++ b/example/wallet/lib/models/solana/solana_sign_transaction.g.dart @@ -0,0 +1,55 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'solana_sign_transaction.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SolanaSignTransaction _$SolanaSignTransactionFromJson( + Map json) => + SolanaSignTransaction( + feePayer: json['feePayer'] as String, + recentBlockhash: json['recentBlockhash'] as String, + instructions: (json['instructions'] as List) + .map((e) => SolanaInstruction.fromJson(e as Map)) + .toList(), + ); + +Map _$SolanaSignTransactionToJson( + SolanaSignTransaction instance) => + { + 'feePayer': instance.feePayer, + 'recentBlockhash': instance.recentBlockhash, + 'instructions': instance.instructions, + }; + +SolanaInstruction _$SolanaInstructionFromJson(Map json) => + SolanaInstruction( + programId: json['programId'] as String, + keys: (json['keys'] as List) + .map((e) => SolanaKeyMetadata.fromJson(e as Map)) + .toList(), + data: json['data'] as String, + ); + +Map _$SolanaInstructionToJson(SolanaInstruction instance) => + { + 'programId': instance.programId, + 'keys': instance.keys, + 'data': instance.data, + }; + +SolanaKeyMetadata _$SolanaKeyMetadataFromJson(Map json) => + SolanaKeyMetadata( + pubkey: json['pubkey'] as String, + isSigner: json['isSigner'] as bool, + isWritable: json['isWritable'] as bool, + ); + +Map _$SolanaKeyMetadataToJson(SolanaKeyMetadata instance) => + { + 'pubkey': instance.pubkey, + 'isSigner': instance.isSigner, + 'isWritable': instance.isWritable, + }; diff --git a/example/wallet/lib/widgets/kadena_widgets/kadena_sign_widget.dart b/example/wallet/lib/widgets/kadena_widgets/kadena_sign_widget.dart index 2455584b..35cde1c9 100644 --- a/example/wallet/lib/widgets/kadena_widgets/kadena_sign_widget.dart +++ b/example/wallet/lib/widgets/kadena_widgets/kadena_sign_widget.dart @@ -1,168 +1,168 @@ -import 'dart:convert'; +// import 'dart:convert'; -import 'package:flutter/material.dart'; -import 'package:kadena_dart_sdk/kadena_dart_sdk.dart'; -import 'package:walletconnect_flutter_v2_wallet/utils/constants.dart'; -import 'package:walletconnect_flutter_v2_wallet/widgets/wc_connection_widget/wc_connection_model.dart'; -import 'package:walletconnect_flutter_v2_wallet/widgets/wc_connection_widget/wc_connection_widget.dart'; -import 'package:walletconnect_flutter_v2_wallet/widgets/wc_request_widget.dart/wc_request_widget.dart'; +// import 'package:flutter/material.dart'; +// import 'package:kadena_dart_sdk/kadena_dart_sdk.dart'; +// import 'package:walletconnect_flutter_v2_wallet/utils/constants.dart'; +// import 'package:walletconnect_flutter_v2_wallet/widgets/wc_connection_widget/wc_connection_model.dart'; +// import 'package:walletconnect_flutter_v2_wallet/widgets/wc_connection_widget/wc_connection_widget.dart'; +// import 'package:walletconnect_flutter_v2_wallet/widgets/wc_request_widget.dart/wc_request_widget.dart'; -/// A widget that takes a list of PactCommandPayloads, and allows the user -/// to sign each one individually. If there is only one item in the list, -/// it doesn't show the number of transactions to be signed. Otherwise, it -/// shows the number of transactions to be signed at the top. -/// -/// This widget is used by the KadenaService to sign any kind of request. -/// -/// This widget is generally displayed using the [BottomSheetService]. -/// It returns a list of booleans. Each boolean represents whether the -/// user approved the transaction at the same index in the list of -/// PactCommandPayloads. -/// -/// For each PactCommandPayload to be signed, the widget itself -/// displays the code of the PactCommandPayload and the data. -/// It also shows each [Capability] that is included in the payload. -class KadenaSignWidget extends StatefulWidget { - const KadenaSignWidget({ - super.key, - required this.payloads, - }); +// /// A widget that takes a list of PactCommandPayloads, and allows the user +// /// to sign each one individually. If there is only one item in the list, +// /// it doesn't show the number of transactions to be signed. Otherwise, it +// /// shows the number of transactions to be signed at the top. +// /// +// /// This widget is used by the KadenaService to sign any kind of request. +// /// +// /// This widget is generally displayed using the [BottomSheetService]. +// /// It returns a list of booleans. Each boolean represents whether the +// /// user approved the transaction at the same index in the list of +// /// PactCommandPayloads. +// /// +// /// For each PactCommandPayload to be signed, the widget itself +// /// displays the code of the PactCommandPayload and the data. +// /// It also shows each [Capability] that is included in the payload. +// class KadenaSignWidget extends StatefulWidget { +// const KadenaSignWidget({ +// super.key, +// required this.payloads, +// }); - final List payloads; +// final List payloads; - @override - KadenaSignWidgetState createState() => KadenaSignWidgetState(); -} +// @override +// KadenaSignWidgetState createState() => KadenaSignWidgetState(); +// } -class KadenaSignWidgetState extends State { - int _currentIndex = 0; - final List _responses = []; +// class KadenaSignWidgetState extends State { +// int _currentIndex = 0; +// final List _responses = []; - @override - Widget build(BuildContext context) { - final List capsList = []; +// @override +// Widget build(BuildContext context) { +// final List capsList = []; - if (widget.payloads[_currentIndex].signers.isNotEmpty && - widget.payloads[_currentIndex].signers.first.clist != null) { - capsList.addAll( - widget.payloads[_currentIndex].signers.first.clist! - .map( - (e) => WCConnectionModel( - title: e.name, - elements: e.args - .map( - (e) => e.toString(), - ) - .toList(), - ), - ) - .toList(), - ); - } +// if (widget.payloads[_currentIndex].signers.isNotEmpty && +// widget.payloads[_currentIndex].signers.first.clist != null) { +// capsList.addAll( +// widget.payloads[_currentIndex].signers.first.clist! +// .map( +// (e) => WCConnectionModel( +// title: e.name, +// elements: e.args +// .map( +// (e) => e.toString(), +// ) +// .toList(), +// ), +// ) +// .toList(), +// ); +// } - final List signCounter = []; - if (widget.payloads.length > 1) { - signCounter.add( - Text( - '${_currentIndex + 1} of ${widget.payloads.length}', - style: StyleConstants.subtitleText, - ), - ); - signCounter.add( - const SizedBox( - height: StyleConstants.magic20, - ), - ); - } +// final List signCounter = []; +// if (widget.payloads.length > 1) { +// signCounter.add( +// Text( +// '${_currentIndex + 1} of ${widget.payloads.length}', +// style: StyleConstants.subtitleText, +// ), +// ); +// signCounter.add( +// const SizedBox( +// height: StyleConstants.magic20, +// ), +// ); +// } - return WCRequestWidget( - onAccept: () { - _responses.add(true); - _incrementIndex(); - }, - onReject: () { - _responses.add(false); - _incrementIndex(); - }, - child: Column( - children: [ - ...signCounter, - WCConnectionWidget( - title: 'Sign Transaction', - info: [ - WCConnectionModel( - title: 'Pact Command', - text: jsonEncode(widget.payloads[_currentIndex]), - ), - ...capsList, - ], - ), - ], - ), - ); - } +// return WCRequestWidget( +// onAccept: () { +// _responses.add(true); +// _incrementIndex(); +// }, +// onReject: () { +// _responses.add(false); +// _incrementIndex(); +// }, +// child: Column( +// children: [ +// ...signCounter, +// WCConnectionWidget( +// title: 'Sign Transaction', +// info: [ +// WCConnectionModel( +// title: 'Pact Command', +// text: jsonEncode(widget.payloads[_currentIndex]), +// ), +// ...capsList, +// ], +// ), +// ], +// ), +// ); +// } - // Widget _buildPactCommandPayload(PactCommandPayload payload) { - // return Column( - // children: [ - // Text( - // payload.payload.exec?.code ?? '', - // style: StyleConstants.bodyText, - // ), - // const SizedBox( - // height: StyleConstants.linear16, - // ), - // Text( - // (payload.payload.exec?.data ?? {}).toString(), - // style: StyleConstants.bodyText, - // ), - // const SizedBox( - // height: StyleConstants.linear16, - // ), - // const Text( - // 'Capabilities', - // style: StyleConstants.subtitleText, - // ), - // const SizedBox( - // height: StyleConstants.linear16, - // ), - // // Add the caps if they exist - // if (payload.signers[0].clist != null && - // payload.signers[0].clist!.isNotEmpty) - // ...payload.signers[0].clist!.map( - // (Capability sigCap) => _buildCapability(sigCap), - // ), - // ], - // ); - // } +// // Widget _buildPactCommandPayload(PactCommandPayload payload) { +// // return Column( +// // children: [ +// // Text( +// // payload.payload.exec?.code ?? '', +// // style: StyleConstants.bodyText, +// // ), +// // const SizedBox( +// // height: StyleConstants.linear16, +// // ), +// // Text( +// // (payload.payload.exec?.data ?? {}).toString(), +// // style: StyleConstants.bodyText, +// // ), +// // const SizedBox( +// // height: StyleConstants.linear16, +// // ), +// // const Text( +// // 'Capabilities', +// // style: StyleConstants.subtitleText, +// // ), +// // const SizedBox( +// // height: StyleConstants.linear16, +// // ), +// // // Add the caps if they exist +// // if (payload.signers[0].clist != null && +// // payload.signers[0].clist!.isNotEmpty) +// // ...payload.signers[0].clist!.map( +// // (Capability sigCap) => _buildCapability(sigCap), +// // ), +// // ], +// // ); +// // } - // Widget _buildCapability(Capability cap) { - // return Column( - // children: [ - // Text( - // cap.name, - // style: StyleConstants.bodyTextBold, - // ), - // const SizedBox( - // height: StyleConstants.linear16, - // ), - // ...cap.args.map( - // (e) => Text( - // e.toString(), - // style: StyleConstants.bodyText, - // ), - // ), - // ], - // ); - // } +// // Widget _buildCapability(Capability cap) { +// // return Column( +// // children: [ +// // Text( +// // cap.name, +// // style: StyleConstants.bodyTextBold, +// // ), +// // const SizedBox( +// // height: StyleConstants.linear16, +// // ), +// // ...cap.args.map( +// // (e) => Text( +// // e.toString(), +// // style: StyleConstants.bodyText, +// // ), +// // ), +// // ], +// // ); +// // } - void _incrementIndex() { - if (_currentIndex < widget.payloads.length - 1) { - setState(() { - _currentIndex++; - }); - } else { - Navigator.of(context).pop(_responses); - } - } -} +// void _incrementIndex() { +// if (_currentIndex < widget.payloads.length - 1) { +// setState(() { +// _currentIndex++; +// }); +// } else { +// Navigator.of(context).pop(_responses); +// } +// } +// } diff --git a/example/wallet/pubspec.yaml b/example/wallet/pubspec.yaml index 44eaa3a2..bcb4803d 100644 --- a/example/wallet/pubspec.yaml +++ b/example/wallet/pubspec.yaml @@ -41,7 +41,7 @@ dependencies: walletconnect_flutter_v2: path: ../.. fl_toast: ^3.1.0 - kadena_dart_sdk: ^2.0.4 + # kadena_dart_sdk: ^2.0.4 mobile_scanner: ^3.0.0 get_it: ^7.2.0 eth_sig_util: ^0.0.9 diff --git a/lib/apis/auth_api/auth_engine.dart b/lib/apis/auth_api/auth_engine.dart index 05a5f2dd..6cb25742 100644 --- a/lib/apis/auth_api/auth_engine.dart +++ b/lib/apis/auth_api/auth_engine.dart @@ -231,7 +231,7 @@ class AuthEngine implements IAuthEngine { final resp = AuthResponse( id: id, topic: responseTopic, - error: WalletConnectError( + error: const WalletConnectError( code: -1, message: 'Invalid signature', ), diff --git a/lib/apis/sign_api/sign_engine.dart b/lib/apis/sign_api/sign_engine.dart index 7f62554f..fab114fb 100644 --- a/lib/apis/sign_api/sign_engine.dart +++ b/lib/apis/sign_api/sign_engine.dart @@ -159,7 +159,7 @@ class SignEngine implements ISignEngine { relays: request.relays, proposer: request.proposer, requiredNamespaces: request.requiredNamespaces, - optionalNamespaces: request.optionalNamespaces ?? {}, + optionalNamespaces: request.optionalNamespaces, sessionProperties: request.sessionProperties, pairingTopic: pTopic, ); @@ -176,7 +176,7 @@ class SignEngine implements ISignEngine { selfPublicKey: publicKey, pairingTopic: pTopic, requiredNamespaces: request.requiredNamespaces, - optionalNamespaces: request.optionalNamespaces ?? {}, + optionalNamespaces: request.optionalNamespaces, sessionProperties: request.sessionProperties, completer: completer, ), @@ -935,7 +935,7 @@ class SignEngine implements ISignEngine { relays: proposeRequest.relays, proposer: proposeRequest.proposer, requiredNamespaces: proposeRequest.requiredNamespaces, - optionalNamespaces: proposeRequest.optionalNamespaces ?? {}, + optionalNamespaces: proposeRequest.optionalNamespaces, sessionProperties: proposeRequest.sessionProperties, pairingTopic: topic, generatedNamespaces: namespaces, diff --git a/pubspec.yaml b/pubspec.yaml index f71b1a6c..1ab434d1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: walletconnect_flutter_v2 description: WalletConnect v2 client made in dart for flutter. -version: 2.0.12 +version: 2.0.13 repository: https://github.com/WalletConnect/WalletConnectFlutterV2 environment: @@ -10,7 +10,7 @@ dependencies: flutter: sdk: flutter web_socket_channel: ^2.4.0 - http: ^0.13.5 + http: ^1.1.0 cryptography: ^2.0.5 convert: ^3.0.1 json_annotation: ^4.8.1 diff --git a/test/auth_api/auth_client_test.dart b/test/auth_api/auth_client_test.dart index 8d5d9051..66de971f 100644 --- a/test/auth_api/auth_client_test.dart +++ b/test/auth_api/auth_client_test.dart @@ -231,6 +231,8 @@ void runTests({ clientA.onAuthResponse.subscribe((AuthResponse? args) { counterA++; completerA.complete(); + + expect(args!.result, isNotNull); }); clientB.onAuthRequest.subscribe((AuthRequest? args) async { counterB++; diff --git a/test/auth_api/utils/engine_constants.dart b/test/auth_api/utils/engine_constants.dart index 648f0ce1..8422c010 100644 --- a/test/auth_api/utils/engine_constants.dart +++ b/test/auth_api/utils/engine_constants.dart @@ -33,6 +33,7 @@ final defaultRequestParams = AuthRequestParams( chainId: TEST_ETHEREUM_CHAIN, domain: 'localhost:3000', aud: TEST_AUD, + resources: ['test'], ); final testAuthRequestParamsValid = AuthRequestParams(