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 remoteUser = types.User(
id: proto.TypedKeyProto.fromProto(
conversation.contact.identityPublicKey)
.toString(),
id: conversation.contact.identityPublicKey.toVeilid().toString(),
firstName: editedName);
// Get the messages to display

View File

@ -91,14 +91,17 @@ class ActiveConversationMessagesCubit extends BlocMapCubit<TypedKey,
required proto.Conversation localConversation,
required proto.Conversation remoteConversation}) async =>
add(() => MapEntry(
proto.TypedKeyProto.fromProto(contact.remoteConversationRecordKey),
contact.remoteConversationRecordKey.toVeilid(),
MessagesCubit(
activeAccountInfo: _activeAccountInfo,
remoteIdentityPublicKey: contact.identityPublicKey,
localConversationRecordKey: contact.localConversationRecordKey,
remoteConversationRecordKey: contact.remoteConversationRecordKey,
localMessagesRecordKey: localConversation.messages,
remoteMessagesRecordKey: remoteConversation.messages)));
remoteIdentityPublicKey: contact.identityPublicKey.toVeilid(),
localConversationRecordKey:
contact.localConversationRecordKey.toVeilid(),
remoteConversationRecordKey:
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 =
activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey;
final chatListRecordKey =
proto.OwnedDHTRecordPointerProto.fromProto(account.chatList);
final chatListRecordKey = account.chatList.toVeilid();
final dhtRecord = await DHTShortArray.openOwned(chatListRecordKey,
parent: accountRecordKey);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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