createAttestation method Null safety

Future<String?> createAttestation(
  1. String address
)

Implementation

Future<String?> createAttestation(String address) async {
  try {
    final options = GetAssertionOptions.fromJson(jsonDecode(getAssertionJson));
    // Only allow credentials currently in the state with a matching username
    // The requesting server should be doing this and sending which credentials
    // they are expecting you to try to verify.
    options.allowCredentialDescriptorList = _credentials
        .where((e) => e.address == address)
        .map((e) => PublicKeyCredentialDescriptor(type: PublicKeyCredentialType.publicKey, id: e.attestation.getCredentialId()))
        .toList();

    // User not found
    if (options.allowCredentialDescriptorList!.isEmpty) {
      throw AuthenticatorException('Username not found');
    }

    final assertion = await _auth.getAssertion(options);
    final credentialId = base64.encode(assertion.selectedCredentialId);
    return credentialId;
  } on AuthenticatorException catch (e) {
    if (kDebugMode) {
      print(e);
    }
    return null;
  }
}