refactor cubits to keep them alive, wip

This commit is contained in:
Christien Rioux 2024-06-17 23:38:30 -04:00
parent 360ba436f8
commit 3edf2ebb46
13 changed files with 550 additions and 158 deletions

View file

@ -1,10 +1,12 @@
import 'dart:convert';
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
import 'package:veilid_support/veilid_support.dart';
import 'unlocked_account_info.dart';
import '../account_manager.dart';
enum AccountInfoStatus {
noAccount,
accountInvalid,
accountLocked,
accountUnlocked,
@ -15,13 +17,49 @@ class AccountInfo extends Equatable {
const AccountInfo({
required this.status,
required this.active,
required this.unlockedAccountInfo,
required this.localAccount,
required this.userLogin,
});
final AccountInfoStatus status;
final bool active;
final UnlockedAccountInfo? unlockedAccountInfo;
final LocalAccount localAccount;
final UserLogin? userLogin;
@override
List<Object?> get props => [status, active, unlockedAccountInfo];
List<Object?> get props => [
status,
active,
localAccount,
userLogin,
];
}
extension AccountInfoExt on AccountInfo {
TypedKey get superIdentityRecordKey => localAccount.superIdentity.recordKey;
TypedKey get accountRecordKey =>
userLogin!.accountRecordInfo.accountRecord.recordKey;
TypedKey get identityTypedPublicKey =>
localAccount.superIdentity.currentInstance.typedPublicKey;
PublicKey get identityPublicKey =>
localAccount.superIdentity.currentInstance.publicKey;
SecretKey get identitySecretKey => userLogin!.identitySecret.value;
KeyPair get identityWriter =>
KeyPair(key: identityPublicKey, secret: identitySecretKey);
Future<VeilidCryptoSystem> get identityCryptoSystem =>
localAccount.superIdentity.currentInstance.cryptoSystem;
Future<VeilidCrypto> makeConversationCrypto(
TypedKey remoteIdentityPublicKey) async {
final identitySecret = userLogin!.identitySecret;
final cs = await Veilid.instance.getCryptoSystem(identitySecret.kind);
final sharedSecret = await cs.generateSharedSecret(
remoteIdentityPublicKey.value,
identitySecret.value,
utf8.encode('VeilidChat Conversation'));
final messagesCrypto = await VeilidCryptoPrivate.fromSharedSecret(
identitySecret.kind, sharedSecret);
return messagesCrypto;
}
}