saveIdentityFromPassword method

String saveIdentityFromPassword(
  1. String userId,
  2. String password,
  3. Uint8List identity
)

Save the given identity for the given userId, encrypted with the given password.

userId - The ID of the user. password - The password to encrypt the key. identity - The identity to save.

Returns the SSKS ID of the stored identity, which can be used by your backend to manage it.

Implementation

String saveIdentityFromPassword(
    String userId, String password, Uint8List identity) {
  final Pointer<Utf8> nativeUserId = userId.toNativeUtf8();
  final Pointer<Utf8> nativePassword = password.toNativeUtf8();
  // Dart FFI forces us to copy the data from Uint8List to a newly allocated Pointer<Uint8>
  final Pointer<Uint8> nativeIdentity = calloc<Uint8>(identity.length);
  final pointerListIdentity = nativeIdentity.asTypedList(identity.length);
  pointerListIdentity.setAll(0, identity);
  final Pointer<Pointer<Utf8>> result = calloc<Pointer<Utf8>>();
  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();

  final int resultCode =
      _bindings.SealdSsksPasswordPlugin_SaveIdentityFromPassword(
          _ptr.pointer(),
          nativeUserId,
          nativePassword,
          nativeIdentity,
          identity.length,
          result,
          err);

  calloc.free(nativeUserId);
  calloc.free(nativePassword);
  calloc.free(nativeIdentity);

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