createSubIdentity method

SealdCreateSubIdentityResponse createSubIdentity({
  1. String deviceName = "",
  2. SealdGeneratedPrivateKeys? privateKeys,
  3. Duration expireAfter = const Duration(days: 5 * 365),
})

Creates a new sub-identity, or new device, for the current user account. After creating this new device, you will probably want to call massReencrypt, so that the newly created device will be able to decrypt SealdEncryptionSessions previously created for this account.

deviceName - An optional name for the device to create. This is metadata, useful on the Seald Dashboard for recognizing this device. Optional. privateKeys - Optional. Pre-generated private keys, returned by a call to SealdSdk.generatePrivateKeysAsync. expireAfter - The duration during which the device key for the device to create will be valid without renewal. Optional, defaults to 5 years.

Returns a SealdCreateSubIdentityResponse instance, containing the ID of the newly created device, and the identity export of the newly created sub-identity.

Implementation

SealdCreateSubIdentityResponse createSubIdentity(
    {String deviceName = "",
    SealdGeneratedPrivateKeys? privateKeys,
    Duration expireAfter = const Duration(days: 5 * 365)}) {
  if (_closed) {
    throw SealdException(
        code: "INSTANCE_CLOSED",
        id: "FLUTTER_INSTANCE_CLOSED",
        description: "Instance already closed.");
  }
  final Pointer<Pointer<NativeSealdCreateSubIdentityResponse>> result =
      calloc<Pointer<NativeSealdCreateSubIdentityResponse>>();
  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();
  final Pointer<Utf8> nativeDeviceName = deviceName.toNativeUtf8();
  final Pointer<Utf8> nativeEncryptionKey =
      privateKeys?.encryptionKey.toNativeUtf8() ?? nullptr;
  final Pointer<Utf8> nativeSigningKey =
      privateKeys?.signingKey.toNativeUtf8() ?? nullptr;

  final int resultCode = _bindings.SealdSdk_CreateSubIdentity(
      _ptr.pointer(),
      nativeDeviceName,
      expireAfter.inSeconds,
      nativeEncryptionKey,
      nativeSigningKey,
      result,
      err);

  calloc.free(nativeDeviceName);
  calloc.free(nativeEncryptionKey);
  calloc.free(nativeSigningKey);
  if (resultCode != 0) {
    calloc.free(result);
    throw SealdException._fromCPtr(err);
  } else {
    calloc.free(err);
    final res = SealdCreateSubIdentityResponse._fromC(result.value);
    calloc.free(result);
    return res;
  }
}