Skip to content

Commit

Permalink
fix writing profile and warn when coagulate without profile
Browse files Browse the repository at this point in the history
  • Loading branch information
LGro committed Feb 18, 2024
1 parent 2af15ae commit dbf2257
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
51 changes: 27 additions & 24 deletions lib/contact_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,33 @@ class ContactPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: _withSpacing([
Center(child: avatar(contact!.contact)),
Card(
child: Center(
child: (contact.sharingProfile == 'dont' ||
contact.sharingProfile == null)
? BlocConsumer<ProfileContactCubit, ProfileContactState>(
listener: (context, state) async {},
builder: (context, state) => TextButton(
onPressed: () async => {
context.read<PeerContactCubit>().shareWithPeer(
contact.contact.id,
// Profile probably comes in here fully
// constructed to allow filtering it inside
// depending on sharing preference
// TODO: Handle when no profile contact was set
state.profileContact!.toJson().toString())
},
child: const Text('Coagulate')))
: TextButton(
onPressed: () async => {
context
.read<PeerContactCubit>()
.unshareWithPeer(contact.contact.id)
},
child: const Text('Dissolve')))),
BlocConsumer<ProfileContactCubit, ProfileContactState>(
listener: (context, state) async {},
builder: (context, state) => (state.profileContact == null)
? const Card(
child: Text(
'Need to pick profile contact before coagulate.'))
: Card(
child: Center(
child: (contact.sharingProfile == 'dont' ||
contact.sharingProfile == null)
? TextButton(
onPressed: () async => {
context.read<PeerContactCubit>().shareWithPeer(
contact.contact.id,
// Profile probably comes in here fully
// constructed to allow filtering it inside
// depending on sharing preference
state.profileContact!.displayName)
},
child: const Text('Coagulate'))
: TextButton(
onPressed: () async => {
context
.read<PeerContactCubit>()
.unshareWithPeer(contact.contact.id)
},
child: const Text('Dissolve'))))),
_makeCard(
'ID',
[contact!.contact],
Expand Down
14 changes: 6 additions & 8 deletions lib/cubit/peer_contact_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ class PeerContactCubit extends HydratedCubit<PeerContactState> {
myRecord = MyDHTRecord(
key: myRecord.key,
writer: myRecord.writer,
// TODO: Generate proper secret from strong rng
// TODO: Double check if this is strong enough
psk: randomBytes(32).toString());
}

// TODO: Use the actual profile info
await updateDHTRecord(contact.myRecord!, profileJson);
await updateDHTRecord(myRecord, profileJson);

// TODO: Set sharing profile when feature available
state.contacts[contactId] =
Expand Down Expand Up @@ -119,12 +117,12 @@ Future<(String, String)> createDHTRecord() async {

Future<void> updateDHTRecord(MyDHTRecord myRecordInfo, String profile) async {
final _key = Typed<FixedEncodedString43>.fromString(myRecordInfo.key);
final writer = KeyPair.fromString(myRecordInfo.writer);
final pool = await DHTRecordPool.instance();
// TODO: Is the record crypto really needed when we do veilid independent psk enc?
final record = await pool.openRead(_key,
final record = await pool.openWrite(_key, writer,
// TODO: Is the record crypto really needed when we do veilid independent psk enc?
crypto: await DHTRecordCryptoPrivate.fromTypedKeyPair(
TypedKeyPair.fromKeyPair(
_key.kind, KeyPair.fromString(myRecordInfo.writer))));
TypedKeyPair.fromKeyPair(_key.kind, writer)));

final cs = await pool.veilid.bestCryptoSystem();
// TODO: Ensure via type that psk is available
Expand Down
1 change: 1 addition & 0 deletions lib/cubit/peer_contact_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MyDHTRecord {
Map<String, dynamic> toJson() => _$MyDHTRecordToJson(this);
}

// TODO: Add state to allow displaying loading while coagulating indicator
@JsonSerializable()
class PeerContact {
// TODO: Add constructor with everything, but remove sharing profile here to allow for default value
Expand Down

0 comments on commit dbf2257

Please sign in to comment.