createGroupTMRTemporaryKey method

SealdGroupTMRTemporaryKey createGroupTMRTemporaryKey(
  1. String groupId,
  2. String authFactorType,
  3. String authFactorValue,
  4. Uint8List rawOverEncryptionKey, {
  5. bool isAdmin = false,
})

Create a group TMR temporary key, and returns the created SealdGroupTMRTemporaryKey instance.

groupId The Id of the group for which to create a TMR key. authFactorType The type of authentication factor. Can be "EM" or "SMS". authFactorValue The value of authentication factor. rawOverEncryptionKey The raw encryption key to use. This MUST be a cryptographically random buffer of 64 bytes. isAdmin Should this TMR temporary key give the group admin status. Returns a SealdGroupTMRTemporaryKey instance.

Implementation

SealdGroupTMRTemporaryKey createGroupTMRTemporaryKey(
    String groupId,
    String authFactorType,
    String authFactorValue,
    Uint8List rawOverEncryptionKey,
    {bool isAdmin = false}) {
  if (_closed) {
    throw SealdException(
        code: "INSTANCE_CLOSED",
        id: "FLUTTER_INSTANCE_CLOSED",
        description: "Instance already closed.");
  }
  final Pointer<Utf8> nativeGroupId = groupId.toNativeUtf8();
  final Pointer<Utf8> nativeAuthFactorType = authFactorType.toNativeUtf8();
  final Pointer<Utf8> nativeAuthFactorValue = authFactorValue.toNativeUtf8();
  final int isAdminInt = isAdmin ? 1 : 0;
  // Dart FFI forces us to copy the data from Uint8List to a newly allocated Pointer<Uint8>
  final Pointer<Uint8> nativeRawOverEncryptionKey =
      calloc<Uint8>(rawOverEncryptionKey.length);
  final pointerListRawOverEncryptionKey =
      nativeRawOverEncryptionKey.asTypedList(rawOverEncryptionKey.length);
  pointerListRawOverEncryptionKey.setAll(0, rawOverEncryptionKey);

  final Pointer<Pointer<NativeSealdGroupTMRTemporaryKey>> result =
      calloc<Pointer<NativeSealdGroupTMRTemporaryKey>>();
  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();

  final int resultCode = _bindings.SealdSdk_CreateGroupTMRTemporaryKey(
      _ptr.pointer(),
      nativeGroupId,
      nativeAuthFactorType,
      nativeAuthFactorValue,
      isAdminInt,
      nativeRawOverEncryptionKey,
      rawOverEncryptionKey.length,
      result,
      err);

  calloc.free(nativeGroupId);
  calloc.free(nativeAuthFactorType);
  calloc.free(nativeAuthFactorValue);
  calloc.free(nativeRawOverEncryptionKey);

  if (resultCode != 0) {
    calloc.free(result);
    throw SealdException._fromCPtr(err);
  } else {
    final SealdGroupTMRTemporaryKey gTMRtempKey =
        SealdGroupTMRTemporaryKey._fromC(result.value);
    calloc.free(result);
    calloc.free(err);
    return gTMRtempKey;
  }
}