Skip to content

Commit

Permalink
Secured messaging models and methods (#79)
Browse files Browse the repository at this point in the history
* New Tests for Secured instant messenger

* add mixin to manage Messenger methods

* new global test

* version 3.2.0 tag

* organization

* add TransactionSenderInterface

* update visibility

* fix class

* fix error

* add pubspec.lock in gitignore

* MessengerUtil.getMessages returns messages.

* Add MessengerUtil.buildMessageSendTransaction.

* MessengerUtil.sendMessage returns the new transaction address.

* Messenger : renamed parameters.

* Fix tests

* add informations

* fix request

* Encode SC content

* Change param endpoint -> apiservice

* Add genesisPublicKey in message

* fix genesisPubKey research

* minor change

* change method to avoid sync call

* 🐛 remove exception hiding on createNewSc.

* ⚡ add pagination to Messenger readMessages.

* 🐛 readMessages keeps messages order.

* ✨ Notifications management utils

* update lints

* add getMessageGroup method (WIP)

* add getGroupMessage method

* ✨ Add localizations to notifications.

* 🚨 Fix lints.

* Updates following PR's review

* update changelog 3.2.0

---------

Co-authored-by: Chralu <[email protected]>
  • Loading branch information
redDwarf03 and Chralu authored Jul 18, 2023
1 parent a901a82 commit df9abd3
Show file tree
Hide file tree
Showing 30 changed files with 4,736 additions and 767 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ ios/Flutter/Release.xcconfig
ios/Flutter/Debug.xcconfig
macos/Flutter/Flutter-Debug.xcconfig
macos/Flutter/Flutter-Release.xcconfig
pubspec.lock
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

#### Version 3.2.0
* Add utility methods to handle message exchange mechanisms within the context of messaging.
* Add a transaction utility method to handle confirmations when a transaction is sent to the blockchain.
* Add logs activation property on Service classes

#### Version 3.1.1 (2023-05-22)
* Fix getStorageNoncePublicKey method

Expand Down
6 changes: 2 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# packages, and plugins designed to encourage good coding practices.
analyzer:
exclude:
- '**/*.freezed.dart'
- '**/*.g.dart'
- "**/*.freezed.dart"
- "**/*.g.dart"

language:
strict-casts: true
Expand Down Expand Up @@ -127,7 +127,6 @@ linter:
- prefer_const_literals_to_create_immutables
- prefer_constructors_over_static_methods
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
Expand Down Expand Up @@ -205,6 +204,5 @@ linter:
- use_to_and_as_if_applicable
- valid_regexps
- void_checks

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
12 changes: 12 additions & 0 deletions lib/archethic_lib_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export 'src/model/keychain.dart';
export 'src/model/ledger.dart';
export 'src/model/ledger_operations.dart';
export 'src/model/location.dart';
export 'src/model/messaging/ae_group_message.dart';
export 'src/model/messaging/ae_message.dart';
export 'src/model/messaging/transaction_content_messaging.dart';
export 'src/model/node.dart';
export 'src/model/on_chain_wallet_data.dart';
export 'src/model/oracle_chain/oracle_uco_price.dart';
Expand All @@ -35,6 +38,7 @@ export 'src/model/transaction.dart';
export 'src/model/transaction_fee.dart';
export 'src/model/transaction_input.dart';
export 'src/model/transaction_movement.dart';
export 'src/model/transaction_notification.dart';
export 'src/model/transaction_status.dart';
export 'src/model/uco.dart';
export 'src/model/uco_ledger.dart';
Expand All @@ -44,6 +48,14 @@ export 'src/model/validation_stamp.dart';
export 'src/services/address_service.dart';
export 'src/services/api_service.dart';
export 'src/services/oracle_service.dart';
export 'src/utils/confirmations/archethic_transaction_sender.dart';
export 'src/utils/confirmations/phoenix_link.dart';
export 'src/utils/confirmations/transaction_event.dart';
export 'src/utils/confirmations/transaction_remote.dart';
export 'src/utils/confirmations/transaction_sender.dart';
export 'src/utils/crypto.dart';
export 'src/utils/messenger_util.dart';
export 'src/utils/notification_util.dart';
export 'src/utils/transaction_util.dart';
export 'src/utils/utils.dart';
export 'src/utils/wallet_encoder.dart';
2 changes: 1 addition & 1 deletion lib/crypto_keys/src/asymmetric_operator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

part of '../crypto_keys.dart';

abstract class _AsymmetricOperator<T extends Key> implements Operator<T> {
abstract mixin class _AsymmetricOperator<T extends Key> implements Operator<T> {
static pc.ECDomainParameters createCurveParameters(Identifier curve) {
var name = curve.name.split('/').last;
switch (name) {
Expand Down
6 changes: 3 additions & 3 deletions lib/crypto_keys/src/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
part of '../crypto_keys.dart';

/// A cryptographic key
abstract class Key {
abstract mixin class Key {
/// Creates an [Encrypter] using this key and the specified algorithm
Encrypter createEncrypter(Identifier algorithm) {
if (this is SymmetricKey) {
Expand All @@ -15,7 +15,7 @@ abstract class Key {
}

/// A cryptographic public key
abstract class PublicKey implements Key {
abstract mixin class PublicKey implements Key {
/// Creates a signature [Verifier] using this key and the specified algorithm
Verifier createVerifier(Identifier algorithm) {
if (this is SymmetricKey) {
Expand All @@ -27,7 +27,7 @@ abstract class PublicKey implements Key {
}

/// A cryptographic private key
abstract class PrivateKey implements Key {
abstract mixin class PrivateKey implements Key {
/// Creates a [Signer] using this key and the specified algorithm.
Signer createSigner(Identifier algorithm) {
if (this is SymmetricKey) {
Expand Down
20 changes: 20 additions & 0 deletions lib/src/model/messaging/ae_group_message.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:freezed_annotation/freezed_annotation.dart';

part 'ae_group_message.freezed.dart';
part 'ae_group_message.g.dart';

@freezed
class AEGroupMessage with _$AEGroupMessage {
const factory AEGroupMessage({
@Default('') final String groupName,
@Default('') final String address,
@Default([]) final List<String> usersPubKey,
@Default([]) final List<String> adminPublicKey,
@Default(0) final int timestampLastUpdate,
}) = _AEGroupMessage;
const AEGroupMessage._();

factory AEGroupMessage.fromJson(Map<String, dynamic> json) =>
_$AEGroupMessageFromJson(json);
}
266 changes: 266 additions & 0 deletions lib/src/model/messaging/ae_group_message.freezed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
// 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 'ae_group_message.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#custom-getters-and-methods');

AEGroupMessage _$AEGroupMessageFromJson(Map<String, dynamic> json) {
return _AEGroupMessage.fromJson(json);
}

/// @nodoc
mixin _$AEGroupMessage {
String get groupName => throw _privateConstructorUsedError;
String get address => throw _privateConstructorUsedError;
List<String> get usersPubKey => throw _privateConstructorUsedError;
List<String> get adminPublicKey => throw _privateConstructorUsedError;
int get timestampLastUpdate => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$AEGroupMessageCopyWith<AEGroupMessage> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $AEGroupMessageCopyWith<$Res> {
factory $AEGroupMessageCopyWith(
AEGroupMessage value, $Res Function(AEGroupMessage) then) =
_$AEGroupMessageCopyWithImpl<$Res, AEGroupMessage>;
@useResult
$Res call(
{String groupName,
String address,
List<String> usersPubKey,
List<String> adminPublicKey,
int timestampLastUpdate});
}

/// @nodoc
class _$AEGroupMessageCopyWithImpl<$Res, $Val extends AEGroupMessage>
implements $AEGroupMessageCopyWith<$Res> {
_$AEGroupMessageCopyWithImpl(this._value, this._then);

// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;

@pragma('vm:prefer-inline')
@override
$Res call({
Object? groupName = null,
Object? address = null,
Object? usersPubKey = null,
Object? adminPublicKey = null,
Object? timestampLastUpdate = null,
}) {
return _then(_value.copyWith(
groupName: null == groupName
? _value.groupName
: groupName // ignore: cast_nullable_to_non_nullable
as String,
address: null == address
? _value.address
: address // ignore: cast_nullable_to_non_nullable
as String,
usersPubKey: null == usersPubKey
? _value.usersPubKey
: usersPubKey // ignore: cast_nullable_to_non_nullable
as List<String>,
adminPublicKey: null == adminPublicKey
? _value.adminPublicKey
: adminPublicKey // ignore: cast_nullable_to_non_nullable
as List<String>,
timestampLastUpdate: null == timestampLastUpdate
? _value.timestampLastUpdate
: timestampLastUpdate // ignore: cast_nullable_to_non_nullable
as int,
) as $Val);
}
}

/// @nodoc
abstract class _$$_AEGroupMessageCopyWith<$Res>
implements $AEGroupMessageCopyWith<$Res> {
factory _$$_AEGroupMessageCopyWith(
_$_AEGroupMessage value, $Res Function(_$_AEGroupMessage) then) =
__$$_AEGroupMessageCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{String groupName,
String address,
List<String> usersPubKey,
List<String> adminPublicKey,
int timestampLastUpdate});
}

/// @nodoc
class __$$_AEGroupMessageCopyWithImpl<$Res>
extends _$AEGroupMessageCopyWithImpl<$Res, _$_AEGroupMessage>
implements _$$_AEGroupMessageCopyWith<$Res> {
__$$_AEGroupMessageCopyWithImpl(
_$_AEGroupMessage _value, $Res Function(_$_AEGroupMessage) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? groupName = null,
Object? address = null,
Object? usersPubKey = null,
Object? adminPublicKey = null,
Object? timestampLastUpdate = null,
}) {
return _then(_$_AEGroupMessage(
groupName: null == groupName
? _value.groupName
: groupName // ignore: cast_nullable_to_non_nullable
as String,
address: null == address
? _value.address
: address // ignore: cast_nullable_to_non_nullable
as String,
usersPubKey: null == usersPubKey
? _value._usersPubKey
: usersPubKey // ignore: cast_nullable_to_non_nullable
as List<String>,
adminPublicKey: null == adminPublicKey
? _value._adminPublicKey
: adminPublicKey // ignore: cast_nullable_to_non_nullable
as List<String>,
timestampLastUpdate: null == timestampLastUpdate
? _value.timestampLastUpdate
: timestampLastUpdate // ignore: cast_nullable_to_non_nullable
as int,
));
}
}

/// @nodoc
@JsonSerializable()
class _$_AEGroupMessage extends _AEGroupMessage {
const _$_AEGroupMessage(
{this.groupName = '',
this.address = '',
final List<String> usersPubKey = const [],
final List<String> adminPublicKey = const [],
this.timestampLastUpdate = 0})
: _usersPubKey = usersPubKey,
_adminPublicKey = adminPublicKey,
super._();

factory _$_AEGroupMessage.fromJson(Map<String, dynamic> json) =>
_$$_AEGroupMessageFromJson(json);

@override
@JsonKey()
final String groupName;
@override
@JsonKey()
final String address;
final List<String> _usersPubKey;
@override
@JsonKey()
List<String> get usersPubKey {
if (_usersPubKey is EqualUnmodifiableListView) return _usersPubKey;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_usersPubKey);
}

final List<String> _adminPublicKey;
@override
@JsonKey()
List<String> get adminPublicKey {
if (_adminPublicKey is EqualUnmodifiableListView) return _adminPublicKey;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_adminPublicKey);
}

@override
@JsonKey()
final int timestampLastUpdate;

@override
String toString() {
return 'AEGroupMessage(groupName: $groupName, address: $address, usersPubKey: $usersPubKey, adminPublicKey: $adminPublicKey, timestampLastUpdate: $timestampLastUpdate)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_AEGroupMessage &&
(identical(other.groupName, groupName) ||
other.groupName == groupName) &&
(identical(other.address, address) || other.address == address) &&
const DeepCollectionEquality()
.equals(other._usersPubKey, _usersPubKey) &&
const DeepCollectionEquality()
.equals(other._adminPublicKey, _adminPublicKey) &&
(identical(other.timestampLastUpdate, timestampLastUpdate) ||
other.timestampLastUpdate == timestampLastUpdate));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(
runtimeType,
groupName,
address,
const DeepCollectionEquality().hash(_usersPubKey),
const DeepCollectionEquality().hash(_adminPublicKey),
timestampLastUpdate);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_AEGroupMessageCopyWith<_$_AEGroupMessage> get copyWith =>
__$$_AEGroupMessageCopyWithImpl<_$_AEGroupMessage>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$_AEGroupMessageToJson(
this,
);
}
}

abstract class _AEGroupMessage extends AEGroupMessage {
const factory _AEGroupMessage(
{final String groupName,
final String address,
final List<String> usersPubKey,
final List<String> adminPublicKey,
final int timestampLastUpdate}) = _$_AEGroupMessage;
const _AEGroupMessage._() : super._();

factory _AEGroupMessage.fromJson(Map<String, dynamic> json) =
_$_AEGroupMessage.fromJson;

@override
String get groupName;
@override
String get address;
@override
List<String> get usersPubKey;
@override
List<String> get adminPublicKey;
@override
int get timestampLastUpdate;
@override
@JsonKey(ignore: true)
_$$_AEGroupMessageCopyWith<_$_AEGroupMessage> get copyWith =>
throw _privateConstructorUsedError;
}
Loading

0 comments on commit df9abd3

Please sign in to comment.