createGroup method

String createGroup({
  1. String groupName = "",
  2. required List<String> members,
  3. required List<String> admins,
  4. SealdGeneratedPrivateKeys? privateKeys,
})

Create a group and return the created group's ID. admins must also be members. admins must include yourself.

groupName - A name for the group. This is metadata, useful on the Seald Dashboard for recognizing this user. members - The Seald IDs of the members to add to the group. Must include yourself. admins - The Seald IDs of the members to also add as group admins. Must include yourself. privateKeys - Optional. Pre-generated private keys, returned by a call to SealdSdk.generatePrivateKeysAsync.

Returns the ID of the created group.

Implementation

String createGroup(
    {String groupName = "",
    required List<String> members,
    required List<String> admins,
    SealdGeneratedPrivateKeys? privateKeys}) {
  if (_closed) {
    throw SealdException(
        code: "INSTANCE_CLOSED",
        id: "FLUTTER_INSTANCE_CLOSED",
        description: "Instance already closed.");
  }
  final Pointer<Utf8> nativeGroupName = groupName.toNativeUtf8();
  final Pointer<NativeSealdStringArray> nativeMembers =
      _sealdStringArrayFromList(members);
  final Pointer<NativeSealdStringArray> nativeAdmins =
      _sealdStringArrayFromList(admins);
  final Pointer<Utf8> nativeEncryptionKey =
      privateKeys?.encryptionKey.toNativeUtf8() ?? nullptr;
  final Pointer<Utf8> nativeSigningKey =
      privateKeys?.signingKey.toNativeUtf8() ?? nullptr;
  final Pointer<Pointer<Utf8>> groupId = calloc<Pointer<Utf8>>();
  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();

  final int resultCode = _bindings.SealdSdk_CreateGroup(
      _ptr.pointer(),
      nativeGroupName,
      nativeMembers,
      nativeAdmins,
      nativeEncryptionKey,
      nativeSigningKey,
      groupId,
      err);

  calloc.free(nativeGroupName);
  _bindings.SealdStringArray_Free(nativeMembers);
  _bindings.SealdStringArray_Free(nativeAdmins);
  calloc.free(nativeEncryptionKey);
  calloc.free(nativeSigningKey);

  if (resultCode != 0) {
    throw SealdException._fromCPtr(err);
  } else {
    final String createdGroupId = groupId.value.toDartString();
    calloc.free(groupId.value);
    calloc.free(groupId);
    calloc.free(err);
    return createdGroupId;
  }
}