retrieveIdentity method

SealdSsksTMRPluginRetrieveIdentityResponse retrieveIdentity(
  1. String sessionId,
  2. String authFactorType,
  3. String authFactorValue,
  4. Uint8List rawTMRSymKey, {
  5. String? challenge,
})

Retrieve the Seald account previously saved with saveIdentity.

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. challenge - The challenge sent by SSKS to the user's authentication method.

Returns a SealdSsksTMRPluginRetrieveIdentityResponse containing the retrieved identity.

Implementation

SealdSsksTMRPluginRetrieveIdentityResponse retrieveIdentity(String sessionId,
    String authFactorType, String authFactorValue, Uint8List rawTMRSymKey,
    {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<Utf8> nativeChallenge = challenge?.toNativeUtf8() ?? nullptr;

  final Pointer<Pointer<NativeSealdSsksTMRPluginRetrieveIdentityResponse>>
      result =
      calloc<Pointer<NativeSealdSsksTMRPluginRetrieveIdentityResponse>>();
  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();

  final int resultCode = _bindings.SealdSsksTMRPlugin_RetrieveIdentity(
      _ptr.pointer(),
      nativeSessionId,
      nativeAuthFactorType,
      nativeAuthFactorValue,
      nativeRawTMRSymKey,
      rawTMRSymKey.length,
      nativeChallenge,
      result,
      err);

  calloc.free(nativeSessionId);
  calloc.free(nativeAuthFactorType);
  calloc.free(nativeAuthFactorValue);
  calloc.free(nativeChallenge);
  calloc.free(nativeRawTMRSymKey);

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