checkpoint

This commit is contained in:
Christien Rioux 2024-02-12 09:10:07 -05:00
parent a6ba08255b
commit 9dd17cb077
11 changed files with 80 additions and 85 deletions

View File

@ -74,9 +74,7 @@ class ChatComponent extends StatelessWidget {
); );
final editedName = conversation.contact.editedProfile.name; final editedName = conversation.contact.editedProfile.name;
final remoteUser = types.User( final remoteUser = types.User(
id: proto.TypedKeyProto.fromProto( id: conversation.contact.identityPublicKey.toVeilid().toString(),
conversation.contact.identityPublicKey)
.toString(),
firstName: editedName); firstName: editedName);
// Get the messages to display // Get the messages to display

View File

@ -91,14 +91,17 @@ class ActiveConversationMessagesCubit extends BlocMapCubit<TypedKey,
required proto.Conversation localConversation, required proto.Conversation localConversation,
required proto.Conversation remoteConversation}) async => required proto.Conversation remoteConversation}) async =>
add(() => MapEntry( add(() => MapEntry(
proto.TypedKeyProto.fromProto(contact.remoteConversationRecordKey), contact.remoteConversationRecordKey.toVeilid(),
MessagesCubit( MessagesCubit(
activeAccountInfo: _activeAccountInfo, activeAccountInfo: _activeAccountInfo,
remoteIdentityPublicKey: contact.identityPublicKey, remoteIdentityPublicKey: contact.identityPublicKey.toVeilid(),
localConversationRecordKey: contact.localConversationRecordKey, localConversationRecordKey:
remoteConversationRecordKey: contact.remoteConversationRecordKey, contact.localConversationRecordKey.toVeilid(),
localMessagesRecordKey: localConversation.messages, remoteConversationRecordKey:
remoteMessagesRecordKey: remoteConversation.messages))); contact.remoteConversationRecordKey.toVeilid(),
localMessagesRecordKey: localConversation.messages.toVeilid(),
remoteMessagesRecordKey:
remoteConversation.messages.toVeilid())));
//// ////

View File

@ -23,8 +23,7 @@ class ChatListCubit extends DHTShortArrayCubit<proto.Chat> {
final accountRecordKey = final accountRecordKey =
activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey; activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey;
final chatListRecordKey = final chatListRecordKey = account.chatList.toVeilid();
proto.OwnedDHTRecordPointerProto.fromProto(account.chatList);
final dhtRecord = await DHTShortArray.openOwned(chatListRecordKey, final dhtRecord = await DHTShortArray.openOwned(chatListRecordKey,
parent: accountRecordKey); parent: accountRecordKey);

View File

@ -26,7 +26,7 @@ class ChatSingleContactItemWidget extends StatelessWidget {
final activeChatCubit = context.watch<ActiveChatCubit>(); final activeChatCubit = context.watch<ActiveChatCubit>();
final remoteConversationRecordKey = final remoteConversationRecordKey =
proto.TypedKeyProto.fromProto(_contact.remoteConversationRecordKey); _contact.remoteConversationRecordKey.toVeilid();
final selected = activeChatCubit.state == remoteConversationRecordKey; final selected = activeChatCubit.state == remoteConversationRecordKey;
return Container( return Container(

View File

@ -50,8 +50,7 @@ class ContactInvitationListCubit
activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey; activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey;
final contactInvitationListRecordKey = final contactInvitationListRecordKey =
proto.OwnedDHTRecordPointerProto.fromProto( account.contactInvitationRecords.toVeilid();
account.contactInvitationRecords);
final dhtRecord = await DHTShortArray.openOwned( final dhtRecord = await DHTShortArray.openOwned(
contactInvitationListRecordKey, contactInvitationListRecordKey,
@ -175,8 +174,7 @@ class ContactInvitationListCubit
} }
} }
await (await pool.openOwned( await (await pool.openOwned(
proto.OwnedDHTRecordPointerProto.fromProto( contactInvitationRecord.contactRequestInbox.toVeilid(),
contactInvitationRecord.contactRequestInbox),
parent: accountRecordKey)) parent: accountRecordKey))
.scope((contactRequestInbox) async { .scope((contactRequestInbox) async {
// Wipe out old invitation so it shows up as invalid // Wipe out old invitation so it shows up as invalid
@ -185,8 +183,7 @@ class ContactInvitationListCubit
}); });
if (!accepted) { if (!accepted) {
await (await pool.openRead( await (await pool.openRead(
proto.TypedKeyProto.fromProto( contactInvitationRecord.localConversationRecordKey.toVeilid(),
contactInvitationRecord.localConversationRecordKey),
parent: accountRecordKey)) parent: accountRecordKey))
.delete(); .delete();
} }
@ -205,7 +202,7 @@ class ContactInvitationListCubit
final contactInvitation = final contactInvitation =
proto.ContactInvitation.fromBuffer(contactInvitationBytes); proto.ContactInvitation.fromBuffer(contactInvitationBytes);
final contactRequestInboxKey = final contactRequestInboxKey =
proto.TypedKeyProto.fromProto(contactInvitation.contactRequestInboxKey); contactInvitation.contactRequestInboxKey.toVeilid();
ValidContactInvitation? out; ValidContactInvitation? out;
@ -216,7 +213,7 @@ class ContactInvitationListCubit
// If we're chatting to ourselves, // If we're chatting to ourselves,
// we are validating an invitation we have created // we are validating an invitation we have created
final isSelf = state.data!.value.indexWhere((cir) => final isSelf = state.data!.value.indexWhere((cir) =>
proto.TypedKeyProto.fromProto(cir.contactRequestInbox.recordKey) == cir.contactRequestInbox.recordKey.toVeilid() ==
contactRequestInboxKey) != contactRequestInboxKey) !=
-1; -1;
@ -246,21 +243,20 @@ class ContactInvitationListCubit
final contactRequestPrivate = final contactRequestPrivate =
proto.ContactRequestPrivate.fromBuffer(contactRequestPrivateBytes); proto.ContactRequestPrivate.fromBuffer(contactRequestPrivateBytes);
final contactIdentityMasterRecordKey = proto.TypedKeyProto.fromProto( final contactIdentityMasterRecordKey =
contactRequestPrivate.identityMasterRecordKey); contactRequestPrivate.identityMasterRecordKey.toVeilid();
// Fetch the account master // Fetch the account master
final contactIdentityMaster = await openIdentityMaster( final contactIdentityMaster = await openIdentityMaster(
identityMasterRecordKey: contactIdentityMasterRecordKey); identityMasterRecordKey: contactIdentityMasterRecordKey);
// Verify // Verify
final signature = proto.SignatureProto.fromProto( final signature = signedContactInvitation.identitySignature.toVeilid();
signedContactInvitation.identitySignature);
await cs.verify(contactIdentityMaster.identityPublicKey, await cs.verify(contactIdentityMaster.identityPublicKey,
contactInvitationBytes, signature); contactInvitationBytes, signature);
final writer = KeyPair( final writer = KeyPair(
key: proto.CryptoKeyProto.fromProto(contactRequestPrivate.writerKey), key: contactRequestPrivate.writerKey.toVeilid(),
secret: writerSecret); secret: writerSecret);
out = ValidContactInvitation( out = ValidContactInvitation(
@ -282,12 +278,10 @@ class ContactInvitationListCubit
final pool = DHTRecordPool.instance; final pool = DHTRecordPool.instance;
final accountRecordKey = _activeAccountInfo final accountRecordKey = _activeAccountInfo
.userLogin.accountRecordInfo.accountRecord.recordKey; .userLogin.accountRecordInfo.accountRecord.recordKey;
final writerKey = final writerKey = contactInvitationRecord.writerKey.toVeilid();
proto.CryptoKeyProto.fromProto(contactInvitationRecord.writerKey); final writerSecret = contactInvitationRecord.writerSecret.toVeilid();
final writerSecret = final recordKey =
proto.CryptoKeyProto.fromProto(contactInvitationRecord.writerSecret); contactInvitationRecord.contactRequestInbox.recordKey.toVeilid();
final recordKey = proto.TypedKeyProto.fromProto(
contactInvitationRecord.contactRequestInbox.recordKey);
final writer = TypedKeyPair( final writer = TypedKeyPair(
kind: recordKey.kind, key: writerKey, secret: writerSecret); kind: recordKey.kind, key: writerKey, secret: writerSecret);
final acceptReject = await (await pool.openRead(recordKey, final acceptReject = await (await pool.openRead(recordKey,
@ -307,8 +301,8 @@ class ContactInvitationListCubit
Uint8List.fromList(signedContactResponse.contactResponse); Uint8List.fromList(signedContactResponse.contactResponse);
final contactResponse = final contactResponse =
proto.ContactResponse.fromBuffer(contactResponseBytes); proto.ContactResponse.fromBuffer(contactResponseBytes);
final contactIdentityMasterRecordKey = proto.TypedKeyProto.fromProto( final contactIdentityMasterRecordKey =
contactResponse.identityMasterRecordKey); contactResponse.identityMasterRecordKey.toVeilid();
final cs = await pool.veilid.getCryptoSystem(recordKey.kind); final cs = await pool.veilid.getCryptoSystem(recordKey.kind);
// Fetch the remote contact's account master // Fetch the remote contact's account master
@ -316,8 +310,7 @@ class ContactInvitationListCubit
identityMasterRecordKey: contactIdentityMasterRecordKey); identityMasterRecordKey: contactIdentityMasterRecordKey);
// Verify // Verify
final signature = proto.SignatureProto.fromProto( final signature = signedContactResponse.identitySignature.toVeilid();
signedContactResponse.identitySignature);
await cs.verify(contactIdentityMaster.identityPublicKey, await cs.verify(contactIdentityMaster.identityPublicKey,
contactResponseBytes, signature); contactResponseBytes, signature);
@ -327,8 +320,8 @@ class ContactInvitationListCubit
} }
// Pull profile from remote conversation key // Pull profile from remote conversation key
final remoteConversationRecordKey = proto.TypedKeyProto.fromProto( final remoteConversationRecordKey =
contactResponse.remoteConversationRecordKey); contactResponse.remoteConversationRecordKey.toVeilid();
final conversation = ConversationCubit( final conversation = ConversationCubit(
activeAccountInfo: _activeAccountInfo, activeAccountInfo: _activeAccountInfo,
@ -345,8 +338,8 @@ class ContactInvitationListCubit
} }
// Complete the local conversation now that we have the remote profile // Complete the local conversation now that we have the remote profile
final localConversationRecordKey = proto.TypedKeyProto.fromProto( final localConversationRecordKey =
contactInvitationRecord.localConversationRecordKey); contactInvitationRecord.localConversationRecordKey.toVeilid();
return conversation.initLocalConversation( return conversation.initLocalConversation(
existingConversationRecordKey: localConversationRecordKey, existingConversationRecordKey: localConversationRecordKey,
profile: _account.profile, profile: _account.profile,

View File

@ -80,8 +80,8 @@ class ValidContactInvitation {
return AcceptedContact( return AcceptedContact(
remoteProfile: _contactRequestPrivate.profile, remoteProfile: _contactRequestPrivate.profile,
remoteIdentity: _contactIdentityMaster, remoteIdentity: _contactIdentityMaster,
remoteConversationRecordKey: proto.TypedKeyProto.fromProto( remoteConversationRecordKey:
_contactRequestPrivate.chatRecordKey), _contactRequestPrivate.chatRecordKey.toVeilid(),
localConversationRecordKey: localConversation.key, localConversationRecordKey: localConversation.key,
); );
}); });

View File

@ -24,8 +24,7 @@ class ContactListCubit extends DHTShortArrayCubit<proto.Contact> {
final accountRecordKey = final accountRecordKey =
activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey; activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey;
final contactListRecordKey = final contactListRecordKey = account.contactList.toVeilid();
proto.OwnedDHTRecordPointerProto.fromProto(account.contactList);
final dhtRecord = await DHTShortArray.openOwned(contactListRecordKey, final dhtRecord = await DHTShortArray.openOwned(contactListRecordKey,
parent: accountRecordKey); parent: accountRecordKey);
@ -63,10 +62,9 @@ class ContactListCubit extends DHTShortArrayCubit<proto.Contact> {
final pool = DHTRecordPool.instance; final pool = DHTRecordPool.instance;
final accountRecordKey = final accountRecordKey =
_activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey; _activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey;
final localConversationKey = final localConversationKey = contact.localConversationRecordKey.toVeilid();
proto.TypedKeyProto.fromProto(contact.localConversationRecordKey);
final remoteConversationKey = final remoteConversationKey =
proto.TypedKeyProto.fromProto(contact.remoteConversationRecordKey); contact.remoteConversationRecordKey.toVeilid();
// Remove Contact from account's list // Remove Contact from account's list
for (var i = 0; i < shortArray.length; i++) { for (var i = 0; i < shortArray.length; i++) {

View File

@ -25,7 +25,7 @@ class ContactItemWidget extends StatelessWidget {
final scale = theme.extension<ScaleScheme>()!; final scale = theme.extension<ScaleScheme>()!;
final remoteConversationKey = final remoteConversationKey =
proto.TypedKeyProto.fromProto(contact.remoteConversationRecordKey); contact.remoteConversationRecordKey.toVeilid();
return Container( return Container(
margin: const EdgeInsets.fromLTRB(0, 4, 0, 0), margin: const EdgeInsets.fromLTRB(0, 4, 0, 0),

View File

@ -17,9 +17,9 @@ extension OwnedDHTRecordPointerProto on OwnedDHTRecordPointer {
..owner = owner.toProto(); ..owner = owner.toProto();
return out; return out;
} }
}
static OwnedDHTRecordPointer fromProto(dhtproto.OwnedDHTRecordPointer p) =>
OwnedDHTRecordPointer( extension ProtoOwnedDHTRecordPointer on dhtproto.OwnedDHTRecordPointer {
recordKey: veilidproto.TypedKeyProto.fromProto(p.recordKey), OwnedDHTRecordPointer toVeilid() => OwnedDHTRecordPointer(
owner: veilidproto.KeyPairProto.fromProto(p.owner)); recordKey: recordKey.toVeilid(), owner: owner.toVeilid());
} }

View File

@ -241,8 +241,7 @@ class DHTShortArray {
/// Validate a new head record /// Validate a new head record
Future<void> _newHead(proto.DHTShortArray head) async { Future<void> _newHead(proto.DHTShortArray head) async {
// Get the set of new linked keys and validate it // Get the set of new linked keys and validate it
final linkedKeys = final linkedKeys = head.keys.map((p) => p.toVeilid()).toList();
head.keys.map<TypedKey>(proto.TypedKeyProto.fromProto).toList();
final index = head.index; final index = head.index;
final free = _validateHeadCacheData(linkedKeys, index); final free = _validateHeadCacheData(linkedKeys, index);

View File

@ -24,17 +24,19 @@ extension CryptoKeyProto on veilid.CryptoKey {
..u7 = b.getUint32(7 * 4); ..u7 = b.getUint32(7 * 4);
return out; return out;
} }
}
static veilid.CryptoKey fromProto(proto.CryptoKey p) { extension ProtoCryptoKey on proto.CryptoKey {
veilid.CryptoKey toVeilid() {
final b = ByteData(32) final b = ByteData(32)
..setUint32(0 * 4, p.u0) ..setUint32(0 * 4, u0)
..setUint32(1 * 4, p.u1) ..setUint32(1 * 4, u1)
..setUint32(2 * 4, p.u2) ..setUint32(2 * 4, u2)
..setUint32(3 * 4, p.u3) ..setUint32(3 * 4, u3)
..setUint32(4 * 4, p.u4) ..setUint32(4 * 4, u4)
..setUint32(5 * 4, p.u5) ..setUint32(5 * 4, u5)
..setUint32(6 * 4, p.u6) ..setUint32(6 * 4, u6)
..setUint32(7 * 4, p.u7); ..setUint32(7 * 4, u7);
return veilid.CryptoKey.fromBytes(Uint8List.view(b.buffer)); return veilid.CryptoKey.fromBytes(Uint8List.view(b.buffer));
} }
} }
@ -63,25 +65,27 @@ extension SignatureProto on veilid.Signature {
..u15 = b.getUint32(15 * 4); ..u15 = b.getUint32(15 * 4);
return out; return out;
} }
}
static veilid.Signature fromProto(proto.Signature p) { extension ProtoSignature on proto.Signature {
veilid.Signature toVeilid() {
final b = ByteData(64) final b = ByteData(64)
..setUint32(0 * 4, p.u0) ..setUint32(0 * 4, u0)
..setUint32(1 * 4, p.u1) ..setUint32(1 * 4, u1)
..setUint32(2 * 4, p.u2) ..setUint32(2 * 4, u2)
..setUint32(3 * 4, p.u3) ..setUint32(3 * 4, u3)
..setUint32(4 * 4, p.u4) ..setUint32(4 * 4, u4)
..setUint32(5 * 4, p.u5) ..setUint32(5 * 4, u5)
..setUint32(6 * 4, p.u6) ..setUint32(6 * 4, u6)
..setUint32(7 * 4, p.u7) ..setUint32(7 * 4, u7)
..setUint32(8 * 4, p.u8) ..setUint32(8 * 4, u8)
..setUint32(9 * 4, p.u9) ..setUint32(9 * 4, u9)
..setUint32(10 * 4, p.u10) ..setUint32(10 * 4, u10)
..setUint32(11 * 4, p.u11) ..setUint32(11 * 4, u11)
..setUint32(12 * 4, p.u12) ..setUint32(12 * 4, u12)
..setUint32(13 * 4, p.u13) ..setUint32(13 * 4, u13)
..setUint32(14 * 4, p.u14) ..setUint32(14 * 4, u14)
..setUint32(15 * 4, p.u15); ..setUint32(15 * 4, u15);
return veilid.Signature.fromBytes(Uint8List.view(b.buffer)); return veilid.Signature.fromBytes(Uint8List.view(b.buffer));
} }
} }
@ -128,7 +132,7 @@ extension TypedKeyProto on veilid.TypedKey {
extension ProtoTypedKey on proto.TypedKey { extension ProtoTypedKey on proto.TypedKey {
veilid.TypedKey toVeilid() => veilid.TypedKey toVeilid() =>
veilid.TypedKey(kind: kind, value: CryptoKeyProto.fromProto(value)); veilid.TypedKey(kind: kind, value: value.toVeilid());
} }
/// KeyPair protobuf marshaling /// KeyPair protobuf marshaling
@ -140,8 +144,9 @@ extension KeyPairProto on veilid.KeyPair {
..secret = secret.toProto(); ..secret = secret.toProto();
return out; return out;
} }
}
static veilid.KeyPair fromProto(proto.KeyPair p) => veilid.KeyPair(
key: CryptoKeyProto.fromProto(p.key), extension ProtoKeyPair on proto.KeyPair {
secret: CryptoKeyProto.fromProto(p.secret)); veilid.KeyPair toVeilid() =>
veilid.KeyPair(key: key.toVeilid(), secret: secret.toVeilid());
} }