createAccount method
- String signupJwt, {
- String displayName = "User",
- String deviceName = "Device",
- SealdGeneratedPrivateKeys? privateKeys,
- Duration expireAfter = Duration.zero,
Creates a new Seald SDK Account for this Seald SDK instance. This function can only be called if the current SDK instance does not have an account yet.
signupJwt
- The JWT to allow this SDK instance to create an account.
displayName
- A name for the user to create. This is metadata, useful on the Seald Dashboard for recognizing this user. Defaults to "User".
deviceName
- A name for the device to create. This is metadata, useful on the Seald Dashboard for recognizing this device. Defaults to "Device".
privateKeys
- Optional. Pre-generated private keys, returned by a call to SealdSdk.generatePrivateKeysAsync.
expireAfter
- The duration during which the created device key will be valid without renewal. Optional, defaults to 5 years.
Returns a SealdAccountInfo instance containing the Seald ID of the newly created Seald user, the device ID, and the date at which the current device keys will expire.
Implementation
SealdAccountInfo createAccount(String signupJwt,
{String displayName = "User",
String deviceName = "Device",
SealdGeneratedPrivateKeys? privateKeys,
Duration expireAfter = Duration.zero}) {
if (_closed) {
throw SealdException(
code: "INSTANCE_CLOSED",
id: "FLUTTER_INSTANCE_CLOSED",
description: "Instance already closed.");
}
final Pointer<Pointer<NativeSealdAccountInfo>> result =
calloc<Pointer<NativeSealdAccountInfo>>();
final Pointer<Pointer<NativeSealdError>> err =
calloc<Pointer<NativeSealdError>>();
final Pointer<Utf8> nativeSignupJwt = signupJwt.toNativeUtf8();
final Pointer<Utf8> nativeDisplayName = displayName.toNativeUtf8();
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_CreateAccount(
_ptr.pointer(),
nativeDisplayName,
nativeDeviceName,
nativeSignupJwt,
expireAfter.inSeconds,
nativeEncryptionKey,
nativeSigningKey,
result,
err);
calloc.free(nativeSignupJwt);
calloc.free(nativeDisplayName);
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 = SealdAccountInfo._fromC(result.value);
calloc.free(result);
return res;
}
}