createChallenge method

Future<SecretChallenge> createChallenge(
  1. Session session, {
  2. required String verificationCode,
  3. required Transaction transaction,
})

Creates a new SecretChallenge from a verification code.

This method:

  1. Generates the hash of verificationCode
  2. Creates and inserts a SecretChallenge record

Returns the created SecretChallenge with its database ID.

The verificationCode should be generated by the caller and sent to the user via the appropriate channel (email, SMS, etc.).

Implementation

Future<SecretChallenge> createChallenge(
  final Session session, {
  required final String verificationCode,
  required final Transaction transaction,
}) async {
  final verificationCodeHash = await _hashUtil.createHashFromString(
    secret: verificationCode,
  );

  return SecretChallenge.db.insertRow(
    session,
    SecretChallenge(
      challengeCodeHash: verificationCodeHash,
    ),
    transaction: transaction,
  );
}