saveIdentity method
Save the Seald account to SSKS.
sessionId
- The user's session ID.
authFactorType
- The type of authentication factor. Can be "EM" or "SMS".
authFactorValue
- The value of authentication factor.
rawTMRSymKey
- The raw encryption key used to encrypt / decrypt the stored identity keys. This MUST be a cryptographically random buffer of 64 bytes.
identity
- The identity to save.
challenge
- The challenge sent by SSKS to the user's authentication method.
Returns a SealdSsksTMRPluginSaveIdentityResponse containing the SSKS ID of the stored identity.
Implementation
SealdSsksTMRPluginSaveIdentityResponse saveIdentity(
String sessionId,
String authFactorType,
String authFactorValue,
Uint8List rawTMRSymKey,
Uint8List identity,
{String? challenge}) {
final Pointer<Utf8> nativeSessionId = sessionId.toNativeUtf8();
final Pointer<Utf8> nativeAuthFactorType = authFactorType.toNativeUtf8();
final Pointer<Utf8> nativeAuthFactorValue = authFactorValue.toNativeUtf8();
// Dart FFI forces us to copy the data from Uint8List to a newly allocated Pointer<Uint8>
final Pointer<Uint8> nativeRawTMRSymKey =
calloc<Uint8>(rawTMRSymKey.length);
final pointerListRawTMRSymKey =
nativeRawTMRSymKey.asTypedList(rawTMRSymKey.length);
pointerListRawTMRSymKey.setAll(0, rawTMRSymKey);
final Pointer<Uint8> nativeIdentity = calloc<Uint8>(identity.length);
final pointerListIdentity = nativeIdentity.asTypedList(identity.length);
pointerListIdentity.setAll(0, identity);
final Pointer<Utf8> nativeChallenge = challenge?.toNativeUtf8() ?? nullptr;
final Pointer<Pointer<NativeSealdSsksTMRPluginSaveIdentityResponse>>
result =
calloc<Pointer<NativeSealdSsksTMRPluginSaveIdentityResponse>>();
final Pointer<Pointer<NativeSealdError>> err =
calloc<Pointer<NativeSealdError>>();
final int resultCode = _bindings.SealdSsksTMRPlugin_SaveIdentity(
_ptr.pointer(),
nativeSessionId,
nativeAuthFactorType,
nativeAuthFactorValue,
nativeRawTMRSymKey,
rawTMRSymKey.length,
nativeIdentity,
identity.length,
nativeChallenge,
result,
err);
calloc.free(nativeSessionId);
calloc.free(nativeAuthFactorType);
calloc.free(nativeAuthFactorValue);
calloc.free(nativeChallenge);
calloc.free(nativeRawTMRSymKey);
calloc.free(nativeIdentity);
if (resultCode != 0) {
calloc.free(result);
throw SealdException._fromCPtr(err);
} else {
final SealdSsksTMRPluginSaveIdentityResponse res =
SealdSsksTMRPluginSaveIdentityResponse._fromC(result.value);
calloc.free(result);
calloc.free(err);
return res;
}
}