veilidchat/lib/account_manager/models/unlocked_account_info.dart

48 lines
1.6 KiB
Dart
Raw Normal View History

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 UnlockedAccountInfo {
const UnlockedAccountInfo({
2024-01-08 21:37:08 -05:00
required this.localAccount,
required this.userLogin,
});
//
2024-06-07 14:42:04 -04:00
TypedKey get superIdentityRecordKey => localAccount.superIdentity.recordKey;
2024-01-25 20:33:56 -05:00
TypedKey get accountRecordKey =>
userLogin.accountRecordInfo.accountRecord.recordKey;
2024-06-07 14:42:04 -04:00
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;
2024-01-08 21:37:08 -05:00
2024-05-25 22:46:43 -04:00
Future<VeilidCrypto> makeConversationCrypto(
2024-03-24 12:13:27 -04:00
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'));
2024-05-27 22:58:37 -04:00
final messagesCrypto = await VeilidCryptoPrivate.fromSharedSecret(
identitySecret.kind, sharedSecret);
2024-03-24 12:13:27 -04:00
return messagesCrypto;
}
2024-01-08 21:37:08 -05:00
//
final LocalAccount localAccount;
final UserLogin userLogin;
}