proto cleanup

This commit is contained in:
Christien Rioux 2023-09-26 18:46:02 -04:00
parent f951acd79a
commit a93c711d52
84 changed files with 2393 additions and 2087 deletions

View file

@ -1,7 +1,7 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../entities/local_account.dart';
import '../entities/proto.dart' as proto;
import '../proto/proto.dart' as proto;
import '../entities/user_login.dart';
import '../veilid_support/veilid_support.dart';

View file

@ -29,8 +29,6 @@ class _SystemHash {
}
}
typedef FetchAccountRef = AutoDisposeFutureProviderRef<AccountInfo>;
/// Get an account from the identity key and if it is logged in and we
/// have its secret available, return the account record contents
///
@ -95,10 +93,10 @@ class FetchAccountProvider extends AutoDisposeFutureProvider<AccountInfo> {
///
/// Copied from [fetchAccount].
FetchAccountProvider({
required this.accountMasterRecordKey,
}) : super.internal(
required Typed<FixedEncodedString43> accountMasterRecordKey,
}) : this._internal(
(ref) => fetchAccount(
ref,
ref as FetchAccountRef,
accountMasterRecordKey: accountMasterRecordKey,
),
from: fetchAccountProvider,
@ -110,10 +108,44 @@ class FetchAccountProvider extends AutoDisposeFutureProvider<AccountInfo> {
dependencies: FetchAccountFamily._dependencies,
allTransitiveDependencies:
FetchAccountFamily._allTransitiveDependencies,
accountMasterRecordKey: accountMasterRecordKey,
);
FetchAccountProvider._internal(
super._createNotifier, {
required super.name,
required super.dependencies,
required super.allTransitiveDependencies,
required super.debugGetCreateSourceHash,
required super.from,
required this.accountMasterRecordKey,
}) : super.internal();
final Typed<FixedEncodedString43> accountMasterRecordKey;
@override
Override overrideWith(
FutureOr<AccountInfo> Function(FetchAccountRef provider) create,
) {
return ProviderOverride(
origin: this,
override: FetchAccountProvider._internal(
(ref) => create(ref as FetchAccountRef),
from: from,
name: null,
dependencies: null,
allTransitiveDependencies: null,
debugGetCreateSourceHash: null,
accountMasterRecordKey: accountMasterRecordKey,
),
);
}
@override
AutoDisposeFutureProviderElement<AccountInfo> createElement() {
return _FetchAccountProviderElement(this);
}
@override
bool operator ==(Object other) {
return other is FetchAccountProvider &&
@ -129,6 +161,20 @@ class FetchAccountProvider extends AutoDisposeFutureProvider<AccountInfo> {
}
}
mixin FetchAccountRef on AutoDisposeFutureProviderRef<AccountInfo> {
/// The parameter `accountMasterRecordKey` of this provider.
Typed<FixedEncodedString43> get accountMasterRecordKey;
}
class _FetchAccountProviderElement
extends AutoDisposeFutureProviderElement<AccountInfo> with FetchAccountRef {
_FetchAccountProviderElement(super.provider);
@override
Typed<FixedEncodedString43> get accountMasterRecordKey =>
(origin as FetchAccountProvider).accountMasterRecordKey;
}
String _$fetchActiveAccountHash() =>
r'd074ab2c160bab41ed3dd979b7054603b7d5b2b1';
@ -149,4 +195,5 @@ final fetchActiveAccountProvider =
typedef FetchActiveAccountRef
= AutoDisposeFutureProviderRef<ActiveAccountInfo?>;
// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View file

@ -1,8 +1,8 @@
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../entities/proto.dart' as proto;
import '../entities/proto.dart' show Chat, ChatType;
import '../proto/proto.dart' as proto;
import '../proto/proto.dart' show Chat, ChatType;
import '../tools/tools.dart';
import '../veilid_support/veilid_support.dart';

View file

@ -23,4 +23,5 @@ final fetchChatListProvider = AutoDisposeFutureProvider<IList<Chat>?>.internal(
);
typedef FetchChatListRef = AutoDisposeFutureProviderRef<IList<Chat>?>;
// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View file

@ -3,9 +3,8 @@ import 'dart:convert';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../entities/identity.dart';
import '../entities/proto.dart' as proto;
import '../entities/proto.dart' show Contact;
import '../proto/proto.dart' as proto;
import '../proto/proto.dart' show Contact;
import '../veilid_support/veilid_support.dart';
import 'account.dart';

View file

@ -24,4 +24,5 @@ final fetchContactListProvider =
);
typedef FetchContactListRef = AutoDisposeFutureProviderRef<IList<Contact>?>;
// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View file

@ -4,10 +4,9 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:fixnum/fixnum.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../entities/identity.dart';
import '../entities/local_account.dart';
import '../entities/proto.dart' as proto;
import '../entities/proto.dart'
import '../proto/proto.dart' as proto;
import '../proto/proto.dart'
show
ContactInvitation,
ContactInvitationRecord,
@ -16,7 +15,7 @@ import '../entities/proto.dart'
ContactResponse,
SignedContactInvitation,
SignedContactResponse;
import '../log/loggy.dart';
import '../log/log.dart';
import '../tools/tools.dart';
import '../veilid_support/veilid_support.dart';
import 'account.dart';
@ -60,13 +59,11 @@ Future<AcceptedOrRejectedContact?> checkAcceptRejectContact(
proto.CryptoKeyProto.fromProto(contactInvitationRecord.writerKey);
final writerSecret =
proto.CryptoKeyProto.fromProto(contactInvitationRecord.writerSecret);
final recordKey = proto.TypedKeyProto.fromProto(
contactInvitationRecord.contactRequestInbox.recordKey);
final writer = TypedKeyPair(
kind: contactInvitationRecord.contactRequestInbox.recordKey.kind,
key: writerKey,
secret: writerSecret);
final acceptReject = await (await pool.openRead(
proto.TypedKeyProto.fromProto(
contactInvitationRecord.contactRequestInbox.recordKey),
kind: recordKey.kind, key: writerKey, secret: writerSecret);
final acceptReject = await (await pool.openRead(recordKey,
crypto: await DHTRecordCryptoPrivate.fromTypedKeyPair(writer),
parent: accountRecordKey,
defaultSubkey: 1))
@ -83,8 +80,7 @@ Future<AcceptedOrRejectedContact?> checkAcceptRejectContact(
final contactResponse = ContactResponse.fromBuffer(contactResponseBytes);
final contactIdentityMasterRecordKey = proto.TypedKeyProto.fromProto(
contactResponse.identityMasterRecordKey);
final cs = await pool.veilid.getCryptoSystem(
contactInvitationRecord.contactRequestInbox.recordKey.kind);
final cs = await pool.veilid.getCryptoSystem(recordKey.kind);
// Fetch the remote contact's account master
final contactIdentityMaster = await openIdentityMaster(
@ -96,6 +92,11 @@ Future<AcceptedOrRejectedContact?> checkAcceptRejectContact(
await cs.verify(contactIdentityMaster.identityPublicKey,
contactResponseBytes, signature);
// Check for rejection
if (!contactResponse.accept) {
return AcceptedOrRejectedContact(acceptedContact: null);
}
// Pull profile from remote conversation key
final remoteConversationRecordKey = proto.TypedKeyProto.fromProto(
contactResponse.remoteConversationRecordKey);

View file

@ -26,4 +26,5 @@ final fetchContactInvitationRecordsProvider =
typedef FetchContactInvitationRecordsRef
= AutoDisposeFutureProviderRef<IList<ContactInvitationRecord>?>;
// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View file

@ -3,10 +3,11 @@ import 'dart:convert';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../entities/proto.dart' as proto;
import '../entities/proto.dart' show Conversation, Message;
import '../proto/proto.dart' as proto;
import '../proto/proto.dart' show Conversation, Message;
import '../log/loggy.dart';
import '../veilid_init.dart';
import '../veilid_support/veilid_support.dart';
import 'account.dart';
import 'chat.dart';
@ -332,6 +333,8 @@ class ActiveConversationMessages extends _$ActiveConversationMessages {
/// Get message for active converation
@override
FutureOr<IList<Message>?> build() async {
await eventualVeilid.future;
final activeChat = activeChatState.currentState;
if (activeChat == null) {
return null;

View file

@ -7,7 +7,7 @@ part of 'conversation.dart';
// **************************************************************************
String _$activeConversationMessagesHash() =>
r'd65cd8bf71122806320325e7f0e5f8e751d13b55';
r'1ec73644fd9b6c96c891487e3d027eb8834d25b6';
/// See also [ActiveConversationMessages].
@ProviderFor(ActiveConversationMessages)
@ -24,4 +24,5 @@ final activeConversationMessagesProvider = AutoDisposeAsyncNotifierProvider<
typedef _$ActiveConversationMessages
= AutoDisposeAsyncNotifier<IList<Message>?>;
// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View file

@ -4,13 +4,17 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../entities/entities.dart';
import '../proto/proto.dart' as proto;
import '../log/loggy.dart';
import '../tools/tools.dart';
import '../veilid_init.dart';
import '../veilid_support/veilid_support.dart';
import 'logins.dart';
part 'local_accounts.g.dart';
const String veilidChatAccountKey = 'com.veilid.veilidchat';
// Local account manager
@riverpod
class LocalAccounts extends _$LocalAccounts
@ -34,6 +38,7 @@ class LocalAccounts extends _$LocalAccounts
@override
FutureOr<IList<LocalAccount>> build() async {
try {
await eventualVeilid.future;
return await load();
} on Exception catch (e) {
log.error('Failed to load LocalAccounts table: $e');
@ -66,12 +71,34 @@ class LocalAccounts extends _$LocalAccounts
String encryptionKey = ''}) async {
final localAccounts = state.requireValue;
/////// Add account with profile to DHT
await identityMaster.newAccount(
identitySecret: identitySecret,
name: name,
title: title,
);
// Add account with profile to DHT
await identityMaster.addAccountToIdentity(
identitySecret: identitySecret,
accountKey: veilidChatAccountKey,
createAccountCallback: (parent) async {
// Make empty contact list
final contactList = await (await DHTShortArray.create(parent: parent))
.scope((r) async => r.record.ownedDHTRecordPointer);
// Make empty contact invitation record list
final contactInvitationRecords =
await (await DHTShortArray.create(parent: parent))
.scope((r) async => r.record.ownedDHTRecordPointer);
// Make empty chat record list
final chatRecords = await (await DHTShortArray.create(parent: parent))
.scope((r) async => r.record.ownedDHTRecordPointer);
// Make account object
final account = proto.Account()
..profile = (proto.Profile()
..name = name
..title = title)
..contactList = contactList.toProto()
..contactInvitationRecords = contactInvitationRecords.toProto()
..chatList = chatRecords.toProto();
return account;
});
// Encrypt identitySecret with key
final identitySecretBytes = await encryptSecretToBytes(

View file

@ -29,8 +29,6 @@ class _SystemHash {
}
}
typedef FetchLocalAccountRef = AutoDisposeFutureProviderRef<LocalAccount?>;
/// See also [fetchLocalAccount].
@ProviderFor(fetchLocalAccount)
const fetchLocalAccountProvider = FetchLocalAccountFamily();
@ -78,10 +76,10 @@ class FetchLocalAccountProvider
extends AutoDisposeFutureProvider<LocalAccount?> {
/// See also [fetchLocalAccount].
FetchLocalAccountProvider({
required this.accountMasterRecordKey,
}) : super.internal(
required Typed<FixedEncodedString43> accountMasterRecordKey,
}) : this._internal(
(ref) => fetchLocalAccount(
ref,
ref as FetchLocalAccountRef,
accountMasterRecordKey: accountMasterRecordKey,
),
from: fetchLocalAccountProvider,
@ -93,10 +91,44 @@ class FetchLocalAccountProvider
dependencies: FetchLocalAccountFamily._dependencies,
allTransitiveDependencies:
FetchLocalAccountFamily._allTransitiveDependencies,
accountMasterRecordKey: accountMasterRecordKey,
);
FetchLocalAccountProvider._internal(
super._createNotifier, {
required super.name,
required super.dependencies,
required super.allTransitiveDependencies,
required super.debugGetCreateSourceHash,
required super.from,
required this.accountMasterRecordKey,
}) : super.internal();
final Typed<FixedEncodedString43> accountMasterRecordKey;
@override
Override overrideWith(
FutureOr<LocalAccount?> Function(FetchLocalAccountRef provider) create,
) {
return ProviderOverride(
origin: this,
override: FetchLocalAccountProvider._internal(
(ref) => create(ref as FetchLocalAccountRef),
from: from,
name: null,
dependencies: null,
allTransitiveDependencies: null,
debugGetCreateSourceHash: null,
accountMasterRecordKey: accountMasterRecordKey,
),
);
}
@override
AutoDisposeFutureProviderElement<LocalAccount?> createElement() {
return _FetchLocalAccountProviderElement(this);
}
@override
bool operator ==(Object other) {
return other is FetchLocalAccountProvider &&
@ -112,7 +144,22 @@ class FetchLocalAccountProvider
}
}
String _$localAccountsHash() => r'3f532f7a6caf8e4eaa9f8636a632126a10b8b07f';
mixin FetchLocalAccountRef on AutoDisposeFutureProviderRef<LocalAccount?> {
/// The parameter `accountMasterRecordKey` of this provider.
Typed<FixedEncodedString43> get accountMasterRecordKey;
}
class _FetchLocalAccountProviderElement
extends AutoDisposeFutureProviderElement<LocalAccount?>
with FetchLocalAccountRef {
_FetchLocalAccountProviderElement(super.provider);
@override
Typed<FixedEncodedString43> get accountMasterRecordKey =>
(origin as FetchLocalAccountProvider).accountMasterRecordKey;
}
String _$localAccountsHash() => r'0ab9eca923cb9e15149f06d9edbb9de0cfed6790';
/// See also [LocalAccounts].
@ProviderFor(LocalAccounts)
@ -128,4 +175,5 @@ final localAccountsProvider = AutoDisposeAsyncNotifierProvider<LocalAccounts,
);
typedef _$LocalAccounts = AutoDisposeAsyncNotifier<IList<LocalAccount>>;
// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View file

@ -6,6 +6,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../entities/entities.dart';
import '../log/loggy.dart';
import '../tools/tools.dart';
import '../veilid_init.dart';
import '../veilid_support/veilid_support.dart';
import 'local_accounts.dart';
@ -31,6 +32,7 @@ class Logins extends _$Logins with AsyncTableDBBacked<ActiveLogins> {
@override
FutureOr<ActiveLogins> build() async {
try {
await eventualVeilid.future;
return await load();
} on Exception catch (e) {
log.error('Failed to load ActiveLogins table: $e');
@ -66,7 +68,7 @@ class Logins extends _$Logins with AsyncTableDBBacked<ActiveLogins> {
// Read the identity key to get the account keys
final accountRecordInfo = await identityMaster.readAccountFromIdentity(
identitySecret: identitySecret);
identitySecret: identitySecret, accountKey: veilidChatAccountKey);
// Add to user logins and select it
final current = state.requireValue;

View file

@ -29,8 +29,6 @@ class _SystemHash {
}
}
typedef FetchLoginRef = AutoDisposeFutureProviderRef<UserLogin?>;
/// See also [fetchLogin].
@ProviderFor(fetchLogin)
const fetchLoginProvider = FetchLoginFamily();
@ -77,10 +75,10 @@ class FetchLoginFamily extends Family<AsyncValue<UserLogin?>> {
class FetchLoginProvider extends AutoDisposeFutureProvider<UserLogin?> {
/// See also [fetchLogin].
FetchLoginProvider({
required this.accountMasterRecordKey,
}) : super.internal(
required Typed<FixedEncodedString43> accountMasterRecordKey,
}) : this._internal(
(ref) => fetchLogin(
ref,
ref as FetchLoginRef,
accountMasterRecordKey: accountMasterRecordKey,
),
from: fetchLoginProvider,
@ -92,10 +90,44 @@ class FetchLoginProvider extends AutoDisposeFutureProvider<UserLogin?> {
dependencies: FetchLoginFamily._dependencies,
allTransitiveDependencies:
FetchLoginFamily._allTransitiveDependencies,
accountMasterRecordKey: accountMasterRecordKey,
);
FetchLoginProvider._internal(
super._createNotifier, {
required super.name,
required super.dependencies,
required super.allTransitiveDependencies,
required super.debugGetCreateSourceHash,
required super.from,
required this.accountMasterRecordKey,
}) : super.internal();
final Typed<FixedEncodedString43> accountMasterRecordKey;
@override
Override overrideWith(
FutureOr<UserLogin?> Function(FetchLoginRef provider) create,
) {
return ProviderOverride(
origin: this,
override: FetchLoginProvider._internal(
(ref) => create(ref as FetchLoginRef),
from: from,
name: null,
dependencies: null,
allTransitiveDependencies: null,
debugGetCreateSourceHash: null,
accountMasterRecordKey: accountMasterRecordKey,
),
);
}
@override
AutoDisposeFutureProviderElement<UserLogin?> createElement() {
return _FetchLoginProviderElement(this);
}
@override
bool operator ==(Object other) {
return other is FetchLoginProvider &&
@ -111,7 +143,21 @@ class FetchLoginProvider extends AutoDisposeFutureProvider<UserLogin?> {
}
}
String _$loginsHash() => r'b07a2fe61a8662dbeb5f12d823d49d3645b2b944';
mixin FetchLoginRef on AutoDisposeFutureProviderRef<UserLogin?> {
/// The parameter `accountMasterRecordKey` of this provider.
Typed<FixedEncodedString43> get accountMasterRecordKey;
}
class _FetchLoginProviderElement
extends AutoDisposeFutureProviderElement<UserLogin?> with FetchLoginRef {
_FetchLoginProviderElement(super.provider);
@override
Typed<FixedEncodedString43> get accountMasterRecordKey =>
(origin as FetchLoginProvider).accountMasterRecordKey;
}
String _$loginsHash() => r'41c4630869b474c409b2fb3461dd2a56d9350c7f';
/// See also [Logins].
@ProviderFor(Logins)
@ -126,4 +172,5 @@ final loginsProvider =
);
typedef _$Logins = AutoDisposeAsyncNotifier<ActiveLogins>;
// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View file

@ -1,9 +0,0 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../veilid_support/veilid_support.dart';
part 'veilid_instance.g.dart';
// Expose the Veilid instance as a FutureProvider
@riverpod
FutureOr<Veilid> veilidInstance(VeilidInstanceRef ref) async =>
await eventualVeilid.future;

View file

@ -1,24 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'veilid_instance.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$veilidInstanceHash() => r'cca5cf288bafc4a051a1713e285f4c1d3ef4b680';
/// See also [veilidInstance].
@ProviderFor(veilidInstance)
final veilidInstanceProvider = AutoDisposeFutureProvider<Veilid>.internal(
veilidInstance,
name: r'veilidInstanceProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$veilidInstanceHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef VeilidInstanceRef = AutoDisposeFutureProviderRef<Veilid>;
// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions

View file

@ -22,4 +22,5 @@ final windowControlProvider =
);
typedef _$WindowControl = AutoDisposeAsyncNotifier<bool>;
// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member