2024-03-24 12:13:27 -04:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2024-01-08 21:37:08 -05:00
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
import 'package:veilid_support/veilid_support.dart';
|
|
|
|
|
|
|
|
import 'local_account/local_account.dart';
|
|
|
|
import 'user_login/user_login.dart';
|
|
|
|
|
|
|
|
@immutable
|
|
|
|
class ActiveAccountInfo {
|
|
|
|
const ActiveAccountInfo({
|
|
|
|
required this.localAccount,
|
|
|
|
required this.userLogin,
|
|
|
|
required this.accountRecord,
|
|
|
|
});
|
|
|
|
//
|
|
|
|
|
2024-01-25 20:33:56 -05:00
|
|
|
TypedKey get accountRecordKey =>
|
|
|
|
userLogin.accountRecordInfo.accountRecord.recordKey;
|
|
|
|
|
|
|
|
KeyPair get conversationWriter {
|
2024-01-08 21:37:08 -05:00
|
|
|
final identityKey = localAccount.identityMaster.identityPublicKey;
|
|
|
|
final identitySecret = userLogin.identitySecret;
|
|
|
|
return KeyPair(key: identityKey, secret: identitySecret.value);
|
|
|
|
}
|
|
|
|
|
2024-03-24 12:13:27 -04:00
|
|
|
Future<DHTRecordCrypto> 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 DHTRecordCryptoPrivate.fromSecret(
|
|
|
|
identitySecret.kind, sharedSecret);
|
|
|
|
return messagesCrypto;
|
|
|
|
}
|
|
|
|
|
2024-01-08 21:37:08 -05:00
|
|
|
//
|
|
|
|
final LocalAccount localAccount;
|
|
|
|
final UserLogin userLogin;
|
|
|
|
final DHTRecord accountRecord;
|
|
|
|
}
|