mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-31 18:28:48 -04:00
update for api fixes
This commit is contained in:
parent
a1a6872e3f
commit
7a1fa6dfb8
5 changed files with 42 additions and 13 deletions
|
@ -209,7 +209,8 @@
|
|||
"protected_with_pin": "Contact invitation is protected with a PIN",
|
||||
"protected_with_password": "Contact invitation is protected with a password",
|
||||
"invalid_pin": "Invalid PIN",
|
||||
"invalid_password": "Invalid password"
|
||||
"invalid_password": "Invalid password",
|
||||
"invalid_identity": "Contact invitation is for an missing or unavailable identity"
|
||||
},
|
||||
"waiting_invitation": {
|
||||
"accepted": "Contact invitation accepted from {name}",
|
||||
|
|
|
@ -20,6 +20,13 @@ class ContactInviteInvalidKeyException implements Exception {
|
|||
final EncryptionKeyType type;
|
||||
}
|
||||
|
||||
class ContactInviteInvalidIdentityException implements Exception {
|
||||
const ContactInviteInvalidIdentityException(
|
||||
this.contactSuperIdentityRecordKey)
|
||||
: super();
|
||||
final TypedKey contactSuperIdentityRecordKey;
|
||||
}
|
||||
|
||||
typedef GetEncryptionKeyCallback = Future<SecretKey?> Function(
|
||||
VeilidCryptoSystem cs,
|
||||
EncryptionKeyType encryptionKeyType,
|
||||
|
@ -301,6 +308,10 @@ class ContactInvitationListCubit
|
|||
final contactSuperIdentity = await SuperIdentity.open(
|
||||
superRecordKey: contactSuperIdentityRecordKey)
|
||||
.withCancel(cancelRequest);
|
||||
if (contactSuperIdentity == null) {
|
||||
throw ContactInviteInvalidIdentityException(
|
||||
contactSuperIdentityRecordKey);
|
||||
}
|
||||
|
||||
// Verify
|
||||
final idcs = await contactSuperIdentity.currentInstance.cryptoSystem;
|
||||
|
|
|
@ -216,6 +216,17 @@ class InvitationDialogState extends State<InvitationDialog> {
|
|||
_isValidating = false;
|
||||
_validInvitation = validatedContactInvitation;
|
||||
});
|
||||
} on ContactInviteInvalidIdentityException catch (_) {
|
||||
if (mounted) {
|
||||
context
|
||||
.read<NotificationsCubit>()
|
||||
.error(text: translate('invitation_dialog.invalid_identity'));
|
||||
}
|
||||
setState(() {
|
||||
_isValidating = false;
|
||||
_validInvitation = null;
|
||||
widget.onValidationFailed();
|
||||
});
|
||||
} on ContactInviteInvalidKeyException catch (e) {
|
||||
String errorText;
|
||||
switch (e.type) {
|
||||
|
|
|
@ -226,7 +226,7 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
Future<Uint8List?> tryWriteBytes(Uint8List newValue,
|
||||
{int subkey = -1,
|
||||
VeilidCrypto? crypto,
|
||||
KeyPair? writer,
|
||||
SetDHTValueOptions? options,
|
||||
Output<int>? outSeqNum}) =>
|
||||
_wrapStats('tryWriteBytes', () async {
|
||||
subkey = subkeyOrDefault(subkey);
|
||||
|
@ -236,7 +236,9 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
// Set the new data if possible
|
||||
var newValueData = await _routingContext.setDHTValue(
|
||||
key, subkey, encryptedNewValue,
|
||||
writer: writer ?? _writer);
|
||||
options: SetDHTValueOptions(
|
||||
writer: options?.writer ?? _writer,
|
||||
allowOffline: options?.allowOffline));
|
||||
if (newValueData == null) {
|
||||
// A newer value wasn't found on the set, but we may get a newer value
|
||||
// when getting the value for the sequence number
|
||||
|
@ -292,7 +294,8 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
// Set the new data
|
||||
newValueData = await _routingContext.setDHTValue(
|
||||
key, subkey, encryptedNewValue,
|
||||
writer: writer ?? _writer);
|
||||
options: SetDHTValueOptions(
|
||||
writer: writer ?? _writer, allowOffline: false));
|
||||
|
||||
// Repeat if newer data on the network was found
|
||||
} while (newValueData != null);
|
||||
|
@ -351,7 +354,8 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
oldValue = await tryWriteBytes(updatedValue,
|
||||
subkey: subkey,
|
||||
crypto: crypto,
|
||||
writer: writer,
|
||||
options: SetDHTValueOptions(
|
||||
writer: writer ?? _writer, allowOffline: false),
|
||||
outSeqNum: outSeqNum);
|
||||
|
||||
// Repeat update if newer data on the network was found
|
||||
|
@ -362,12 +366,12 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
Future<T?> tryWriteJson<T>(T Function(dynamic) fromJson, T newValue,
|
||||
{int subkey = -1,
|
||||
VeilidCrypto? crypto,
|
||||
KeyPair? writer,
|
||||
SetDHTValueOptions? options,
|
||||
Output<int>? outSeqNum}) =>
|
||||
tryWriteBytes(jsonEncodeBytes(newValue),
|
||||
subkey: subkey,
|
||||
crypto: crypto,
|
||||
writer: writer,
|
||||
options: options,
|
||||
outSeqNum: outSeqNum)
|
||||
.then((out) {
|
||||
if (out == null) {
|
||||
|
@ -381,12 +385,12 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
T Function(List<int>) fromBuffer, T newValue,
|
||||
{int subkey = -1,
|
||||
VeilidCrypto? crypto,
|
||||
KeyPair? writer,
|
||||
SetDHTValueOptions? options,
|
||||
Output<int>? outSeqNum}) =>
|
||||
tryWriteBytes(newValue.writeToBuffer(),
|
||||
subkey: subkey,
|
||||
crypto: crypto,
|
||||
writer: writer,
|
||||
options: options,
|
||||
outSeqNum: outSeqNum)
|
||||
.then((out) {
|
||||
if (out == null) {
|
||||
|
|
|
@ -98,18 +98,20 @@ sealed class SuperIdentity with _$SuperIdentity {
|
|||
}
|
||||
|
||||
/// Opens an existing super identity, validates it, and returns it
|
||||
static Future<SuperIdentity> open({required TypedKey superRecordKey}) async {
|
||||
static Future<SuperIdentity?> open({required TypedKey superRecordKey}) async {
|
||||
final pool = DHTRecordPool.instance;
|
||||
|
||||
// SuperIdentity DHT record is public/unencrypted
|
||||
return (await pool.openRecordRead(superRecordKey,
|
||||
debugName: 'SuperIdentity::openSuperIdentity::SuperIdentityRecord'))
|
||||
.deleteScope((superRec) async {
|
||||
final superIdentity = (await superRec.getJson(SuperIdentity.fromJson,
|
||||
refreshMode: DHTRecordRefreshMode.network))!;
|
||||
final superIdentity = await superRec.getJson(SuperIdentity.fromJson,
|
||||
refreshMode: DHTRecordRefreshMode.network);
|
||||
if (superIdentity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
await superIdentity.validate(superRecordKey: superRecordKey);
|
||||
|
||||
return superIdentity;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue