veilidchat/lib/account_manager/models/account_info.dart

63 lines
1.9 KiB
Dart
Raw Normal View History

import 'dart:convert';
2024-06-15 23:29:15 -04:00
import 'package:equatable/equatable.dart';
2024-01-08 21:37:08 -05:00
import 'package:meta/meta.dart';
import 'package:veilid_support/veilid_support.dart';
2024-01-18 19:44:15 -05:00
import '../account_manager.dart';
2024-01-08 21:37:08 -05:00
enum AccountInfoStatus {
accountInvalid,
accountLocked,
2024-06-16 22:12:24 -04:00
accountUnlocked,
2024-01-08 21:37:08 -05:00
}
@immutable
2024-06-15 23:29:15 -04:00
class AccountInfo extends Equatable {
2024-01-08 21:37:08 -05:00
const AccountInfo({
required this.status,
required this.localAccount,
required this.userLogin,
2024-01-08 21:37:08 -05:00
});
final AccountInfoStatus status;
final LocalAccount localAccount;
final UserLogin? userLogin;
2024-06-15 23:29:15 -04:00
@override
List<Object?> get props => [
status,
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;
}
2024-01-08 21:37:08 -05:00
}