Skip to content

Commit

Permalink
Bugfix: Transactions signing (#14)
Browse files Browse the repository at this point in the history
The previous transaction signing system used SIGN_MODE_AMINO_JSON, which is deprecated and no longer supported on the SEKAI side. This branch introduces a new way to sign transactions that use SIGN_MODE_DIRECT mode.

List of changes:
- imported "cryptography_utils" package which contains crypto-algorithms required to build and sign Cosmos transactions
- removed classes from "infra/dto/api_kira/broadcast/request/transaction/components" as they are included in the “cryptography_utils” package and are no longer needed on the miro side
- modified classes from "infra/dto/shared/messages" to extend "ProtobufAny" class from "cryptography_utils" package and define protobuf serialization for Cosmos messages
- replaced Uint8List private key in wallet.dart with ECPrivateKey from "cryptography_utils" package to simplify accessing private key for transaction signing
- removed signature_utils.dart and sign() method from tx_utils.dart, as now signing functionality is handled by the external package
- created new sign() method in unsigned_tx_model.dart, which calls proper signing method from "cryptography_utils" package
- removed Wallet.fromKeyfileData() constructor from wallet.dart as it wasn't used anywhere but needed improvement after changes
- adjusted tests and classes where updated classes were used
  • Loading branch information
dpajak99 authored Oct 17, 2024
1 parent a1bdd61 commit 52ae6b9
Show file tree
Hide file tree
Showing 62 changed files with 987 additions and 1,615 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#FVM sdk ignore
# Flutter Version Management
.fvm/flutter_sdk
.fvm/versions
.fvm/version
.fvm/release
.fvmrc

# Miscellaneous
*.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CreateWalletDrawerPageCubit extends Cubit<ACreateWalletDrawerPageState> {
emit(CreateWalletDrawerPageLoadingState());
await Future<void>.delayed(const Duration(milliseconds: 500));
Mnemonic mnemonic = Mnemonic.random();
Wallet wallet = Wallet.derive(mnemonic: mnemonic);
Wallet wallet = await Wallet.derive(mnemonic: mnemonic);

emit(CreateWalletDrawerPageLoadedState(mnemonic: mnemonic, wallet: wallet));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'package:miro/shared/models/transactions/signed_transaction_model.dart';
import 'package:miro/shared/models/transactions/unsigned_tx_model.dart';
import 'package:miro/shared/models/wallet/wallet.dart';
import 'package:miro/shared/utils/logger/app_logger.dart';
import 'package:miro/shared/utils/transactions/tx_utils.dart';

class TxProcessCubit<T extends AMsgFormModel> extends Cubit<ATxProcessState> {
final AuthCubit authCubit = globalLocator<AuthCubit>();
Expand Down Expand Up @@ -128,8 +127,6 @@ class TxProcessCubit<T extends AMsgFormModel> extends Cubit<ATxProcessState> {
if (wallet == null) {
throw Exception('Wallet cannot be null when signing transaction');
}
SignedTxModel signedTxModel = TxUtils.sign(unsignedTxModel: unsignedTxModel, wallet: wallet);
await Future<void>.delayed(const Duration(milliseconds: 100));
return signedTxModel;
return unsignedTxModel.sign(wallet);
}
}
6 changes: 3 additions & 3 deletions lib/infra/dto/api_kira/broadcast/request/broadcast_req.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:cryptography_utils/cryptography_utils.dart';
import 'package:equatable/equatable.dart';
import 'package:miro/infra/dto/api_kira/broadcast/request/transaction/tx.dart';

class BroadcastReq extends Equatable {
final Tx tx;
final CosmosTx tx;
final String mode;

const BroadcastReq({
Expand All @@ -12,7 +12,7 @@ class BroadcastReq extends Equatable {

Map<String, dynamic> toJson() {
return <String, dynamic>{
'tx': tx.toJson(),
'tx': tx.toProtoJson(),
'mode': mode,
};
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 52ae6b9

Please sign in to comment.