-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Add encrypt and decrypt methods
- Loading branch information
Showing
12 changed files
with
794 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
lib/infrastructure/rpc/decrypt_payloads/command_handler.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:aewallet/domain/rpc/commands/command.dart'; | ||
import 'package:aewallet/infrastructure/rpc/dto/request_origin.dart'; | ||
import 'package:aewallet/infrastructure/rpc/dto/rpc_command_handler.dart'; | ||
import 'package:archethic_wallet_client/archethic_wallet_client.dart' as awc; | ||
|
||
class RPCDecryptPayloadsCommandHandler extends RPCCommandHandler< | ||
awc.DecryptPayloadRequest, awc.DecryptPayloadsResult> { | ||
RPCDecryptPayloadsCommandHandler() : super(); | ||
|
||
@override | ||
RPCCommand<awc.DecryptPayloadRequest> commandToModel( | ||
awc.Request dto, | ||
) { | ||
final rpcDecryptPayloadCommandDataList = <awc.DecryptPayloadRequestData>[]; | ||
final payloads = dto.payload['payloads']; | ||
for (final Map<String, dynamic> payload in payloads) { | ||
final payloadDecoded = payload['payload'] ?? ''; | ||
final isHexa = payload['isHexa'] ?? false; | ||
final rpcDecryptTransactionCommandData = awc.DecryptPayloadRequestData( | ||
payload: payloadDecoded, | ||
isHexa: isHexa, | ||
); | ||
rpcDecryptPayloadCommandDataList.add(rpcDecryptTransactionCommandData); | ||
} | ||
|
||
return RPCCommand( | ||
origin: dto.origin.toModel, | ||
data: awc.DecryptPayloadRequest( | ||
serviceName: dto.payload['serviceName'], | ||
pathSuffix: dto.payload['pathSuffix'], | ||
description: dto.payload['description'] ?? {}, | ||
payloads: rpcDecryptPayloadCommandDataList, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Map<String, dynamic> resultFromModel( | ||
awc.DecryptPayloadsResult model, | ||
) => | ||
model.toJson(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lib/infrastructure/rpc/encrypt_payloads/command_handler.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:aewallet/domain/rpc/commands/command.dart'; | ||
import 'package:aewallet/infrastructure/rpc/dto/request_origin.dart'; | ||
import 'package:aewallet/infrastructure/rpc/dto/rpc_command_handler.dart'; | ||
import 'package:archethic_wallet_client/archethic_wallet_client.dart' as awc; | ||
|
||
class RPCEncryptPayloadsCommandHandler extends RPCCommandHandler< | ||
awc.EncryptPayloadRequest, awc.EncryptPayloadsResult> { | ||
RPCEncryptPayloadsCommandHandler() : super(); | ||
|
||
@override | ||
RPCCommand<awc.EncryptPayloadRequest> commandToModel( | ||
awc.Request dto, | ||
) { | ||
final rpcEncryptPayloadCommandDataList = <awc.EncryptPayloadRequestData>[]; | ||
final payloads = dto.payload['payloads']; | ||
for (final Map<String, dynamic> payload in payloads) { | ||
final payloadDecoded = payload['payload'] ?? ''; | ||
final isHexa = payload['isHexa'] ?? false; | ||
final rpcEncryptTransactionCommandData = awc.EncryptPayloadRequestData( | ||
payload: payloadDecoded, | ||
isHexa: isHexa, | ||
); | ||
rpcEncryptPayloadCommandDataList.add(rpcEncryptTransactionCommandData); | ||
} | ||
|
||
return RPCCommand( | ||
origin: dto.origin.toModel, | ||
data: awc.EncryptPayloadRequest( | ||
serviceName: dto.payload['serviceName'], | ||
pathSuffix: dto.payload['pathSuffix'], | ||
payloads: rpcEncryptPayloadCommandDataList, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Map<String, dynamic> resultFromModel( | ||
awc.EncryptPayloadsResult model, | ||
) => | ||
model.toJson(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
lib/ui/views/rpc_command_receiver/decrypt_payload/bloc/provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:aewallet/domain/rpc/commands/command.dart'; | ||
import 'package:archethic_wallet_client/archethic_wallet_client.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'provider.freezed.dart'; | ||
|
||
@freezed | ||
class DecryptPayloadsConfirmationFormState | ||
with _$DecryptPayloadsConfirmationFormState { | ||
const factory DecryptPayloadsConfirmationFormState({ | ||
required RPCCommand<DecryptPayloadRequest> decryptTransactionCommand, | ||
}) = _DecryptPayloadsConfirmationFormState; | ||
const DecryptPayloadsConfirmationFormState._(); | ||
} | ||
|
||
class DecryptPayloadsConfirmationFormNotifiers | ||
extends AutoDisposeFamilyAsyncNotifier<DecryptPayloadsConfirmationFormState, | ||
RPCCommand<DecryptPayloadRequest>> { | ||
@override | ||
Future<DecryptPayloadsConfirmationFormState> build( | ||
RPCCommand<DecryptPayloadRequest> arg, | ||
) async { | ||
return DecryptPayloadsConfirmationFormState( | ||
decryptTransactionCommand: arg, | ||
); | ||
} | ||
} | ||
|
||
class DecryptPayloadsConfirmationProviders { | ||
static final form = AsyncNotifierProvider.autoDispose.family< | ||
DecryptPayloadsConfirmationFormNotifiers, | ||
DecryptPayloadsConfirmationFormState, | ||
RPCCommand<DecryptPayloadRequest>>( | ||
DecryptPayloadsConfirmationFormNotifiers.new, | ||
); | ||
} |
183 changes: 183 additions & 0 deletions
183
lib/ui/views/rpc_command_receiver/decrypt_payload/bloc/provider.freezed.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
// coverage:ignore-file | ||
// GENERATED CODE - DO NOT MODIFY BY HAND | ||
// ignore_for_file: type=lint | ||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark | ||
|
||
part of 'provider.dart'; | ||
|
||
// ************************************************************************** | ||
// FreezedGenerator | ||
// ************************************************************************** | ||
|
||
T _$identity<T>(T value) => value; | ||
|
||
final _privateConstructorUsedError = UnsupportedError( | ||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); | ||
|
||
/// @nodoc | ||
mixin _$DecryptPayloadsConfirmationFormState { | ||
RPCCommand<DecryptPayloadRequest> get decryptTransactionCommand => | ||
throw _privateConstructorUsedError; | ||
|
||
/// Create a copy of DecryptPayloadsConfirmationFormState | ||
/// with the given fields replaced by the non-null parameter values. | ||
@JsonKey(includeFromJson: false, includeToJson: false) | ||
$DecryptPayloadsConfirmationFormStateCopyWith< | ||
DecryptPayloadsConfirmationFormState> | ||
get copyWith => throw _privateConstructorUsedError; | ||
} | ||
|
||
/// @nodoc | ||
abstract class $DecryptPayloadsConfirmationFormStateCopyWith<$Res> { | ||
factory $DecryptPayloadsConfirmationFormStateCopyWith( | ||
DecryptPayloadsConfirmationFormState value, | ||
$Res Function(DecryptPayloadsConfirmationFormState) then) = | ||
_$DecryptPayloadsConfirmationFormStateCopyWithImpl<$Res, | ||
DecryptPayloadsConfirmationFormState>; | ||
@useResult | ||
$Res call({RPCCommand<DecryptPayloadRequest> decryptTransactionCommand}); | ||
|
||
$RPCCommandCopyWith<DecryptPayloadRequest, $Res> | ||
get decryptTransactionCommand; | ||
} | ||
|
||
/// @nodoc | ||
class _$DecryptPayloadsConfirmationFormStateCopyWithImpl<$Res, | ||
$Val extends DecryptPayloadsConfirmationFormState> | ||
implements $DecryptPayloadsConfirmationFormStateCopyWith<$Res> { | ||
_$DecryptPayloadsConfirmationFormStateCopyWithImpl(this._value, this._then); | ||
|
||
// ignore: unused_field | ||
final $Val _value; | ||
// ignore: unused_field | ||
final $Res Function($Val) _then; | ||
|
||
/// Create a copy of DecryptPayloadsConfirmationFormState | ||
/// with the given fields replaced by the non-null parameter values. | ||
@pragma('vm:prefer-inline') | ||
@override | ||
$Res call({ | ||
Object? decryptTransactionCommand = null, | ||
}) { | ||
return _then(_value.copyWith( | ||
decryptTransactionCommand: null == decryptTransactionCommand | ||
? _value.decryptTransactionCommand | ||
: decryptTransactionCommand // ignore: cast_nullable_to_non_nullable | ||
as RPCCommand<DecryptPayloadRequest>, | ||
) as $Val); | ||
} | ||
|
||
/// Create a copy of DecryptPayloadsConfirmationFormState | ||
/// with the given fields replaced by the non-null parameter values. | ||
@override | ||
@pragma('vm:prefer-inline') | ||
$RPCCommandCopyWith<DecryptPayloadRequest, $Res> | ||
get decryptTransactionCommand { | ||
return $RPCCommandCopyWith<DecryptPayloadRequest, $Res>( | ||
_value.decryptTransactionCommand, (value) { | ||
return _then(_value.copyWith(decryptTransactionCommand: value) as $Val); | ||
}); | ||
} | ||
} | ||
|
||
/// @nodoc | ||
abstract class _$$DecryptPayloadsConfirmationFormStateImplCopyWith<$Res> | ||
implements $DecryptPayloadsConfirmationFormStateCopyWith<$Res> { | ||
factory _$$DecryptPayloadsConfirmationFormStateImplCopyWith( | ||
_$DecryptPayloadsConfirmationFormStateImpl value, | ||
$Res Function(_$DecryptPayloadsConfirmationFormStateImpl) then) = | ||
__$$DecryptPayloadsConfirmationFormStateImplCopyWithImpl<$Res>; | ||
@override | ||
@useResult | ||
$Res call({RPCCommand<DecryptPayloadRequest> decryptTransactionCommand}); | ||
|
||
@override | ||
$RPCCommandCopyWith<DecryptPayloadRequest, $Res> | ||
get decryptTransactionCommand; | ||
} | ||
|
||
/// @nodoc | ||
class __$$DecryptPayloadsConfirmationFormStateImplCopyWithImpl<$Res> | ||
extends _$DecryptPayloadsConfirmationFormStateCopyWithImpl<$Res, | ||
_$DecryptPayloadsConfirmationFormStateImpl> | ||
implements _$$DecryptPayloadsConfirmationFormStateImplCopyWith<$Res> { | ||
__$$DecryptPayloadsConfirmationFormStateImplCopyWithImpl( | ||
_$DecryptPayloadsConfirmationFormStateImpl _value, | ||
$Res Function(_$DecryptPayloadsConfirmationFormStateImpl) _then) | ||
: super(_value, _then); | ||
|
||
/// Create a copy of DecryptPayloadsConfirmationFormState | ||
/// with the given fields replaced by the non-null parameter values. | ||
@pragma('vm:prefer-inline') | ||
@override | ||
$Res call({ | ||
Object? decryptTransactionCommand = null, | ||
}) { | ||
return _then(_$DecryptPayloadsConfirmationFormStateImpl( | ||
decryptTransactionCommand: null == decryptTransactionCommand | ||
? _value.decryptTransactionCommand | ||
: decryptTransactionCommand // ignore: cast_nullable_to_non_nullable | ||
as RPCCommand<DecryptPayloadRequest>, | ||
)); | ||
} | ||
} | ||
|
||
/// @nodoc | ||
class _$DecryptPayloadsConfirmationFormStateImpl | ||
extends _DecryptPayloadsConfirmationFormState { | ||
const _$DecryptPayloadsConfirmationFormStateImpl( | ||
{required this.decryptTransactionCommand}) | ||
: super._(); | ||
|
||
@override | ||
final RPCCommand<DecryptPayloadRequest> decryptTransactionCommand; | ||
|
||
@override | ||
String toString() { | ||
return 'DecryptPayloadsConfirmationFormState(decryptTransactionCommand: $decryptTransactionCommand)'; | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
return identical(this, other) || | ||
(other.runtimeType == runtimeType && | ||
other is _$DecryptPayloadsConfirmationFormStateImpl && | ||
(identical(other.decryptTransactionCommand, | ||
decryptTransactionCommand) || | ||
other.decryptTransactionCommand == decryptTransactionCommand)); | ||
} | ||
|
||
@override | ||
int get hashCode => Object.hash(runtimeType, decryptTransactionCommand); | ||
|
||
/// Create a copy of DecryptPayloadsConfirmationFormState | ||
/// with the given fields replaced by the non-null parameter values. | ||
@JsonKey(includeFromJson: false, includeToJson: false) | ||
@override | ||
@pragma('vm:prefer-inline') | ||
_$$DecryptPayloadsConfirmationFormStateImplCopyWith< | ||
_$DecryptPayloadsConfirmationFormStateImpl> | ||
get copyWith => __$$DecryptPayloadsConfirmationFormStateImplCopyWithImpl< | ||
_$DecryptPayloadsConfirmationFormStateImpl>(this, _$identity); | ||
} | ||
|
||
abstract class _DecryptPayloadsConfirmationFormState | ||
extends DecryptPayloadsConfirmationFormState { | ||
const factory _DecryptPayloadsConfirmationFormState( | ||
{required final RPCCommand<DecryptPayloadRequest> | ||
decryptTransactionCommand}) = | ||
_$DecryptPayloadsConfirmationFormStateImpl; | ||
const _DecryptPayloadsConfirmationFormState._() : super._(); | ||
|
||
@override | ||
RPCCommand<DecryptPayloadRequest> get decryptTransactionCommand; | ||
|
||
/// Create a copy of DecryptPayloadsConfirmationFormState | ||
/// with the given fields replaced by the non-null parameter values. | ||
@override | ||
@JsonKey(includeFromJson: false, includeToJson: false) | ||
_$$DecryptPayloadsConfirmationFormStateImplCopyWith< | ||
_$DecryptPayloadsConfirmationFormStateImpl> | ||
get copyWith => throw _privateConstructorUsedError; | ||
} |
Oops, something went wrong.