Skip to content

Conversation

Copy link

Copilot AI commented Sep 26, 2025

This PR implements comprehensive NFC tag support for TwoKey, extending the existing CCID-only functionality to work with NFC FIDO2 authenticators. The implementation provides an elegant device selection mechanism when multiple authenticator types are available.

Overview

The changes introduce a unified FIDO API architecture that seamlessly handles both CCID readers and NFC tags through a single interface. Users can now authenticate using NFC-enabled FIDO2 keys on mobile devices while maintaining full backwards compatibility with existing CCID workflows.

Key Features

🔧 Unified Device Management

  • UnifiedFidoApi: New abstraction layer that automatically detects and manages both CCID and NFC devices
  • Automatic detection: Scans for available authenticators on connection
  • Smart defaults: Prefers CCID over NFC for stability when both are available
  • Device switching: Users can manually select their preferred authenticator type

📱 NFC Implementation

  • NfcFidoApi: Complete NFC implementation using flutter_nfc_kit
  • Transient connection handling: Automatic reconnection for lost NFC connections
  • Platform-aware: Only enables NFC on mobile devices where it's supported
  • Enhanced error handling: Clear feedback for NFC-specific issues like "hold key near device"

🎨 Enhanced User Interface

  • Device selection dialog: Clean UI for choosing between multiple authenticators
  • Current device display: Shows active authenticator in device info section
  • Refresh capabilities: Manual device list refresh and connection reset
  • Visual indicators: USB icon for CCID, NFC icon for wireless devices

Technical Implementation

The architecture follows the existing FidoApi interface pattern, ensuring zero breaking changes:

// Before: Direct CCID usage
AuthenticatorService(CcidFidoApi())

// After: Unified device support  
AuthenticatorService(UnifiedFidoApi())

NFC Lifecycle Management

The implementation handles NFC's transient nature through:

  • Automatic reconnection: Transparent recovery from lost connections during transactions
  • Enhanced transceive: transceiveWithReconnect() method for robust communication
  • Connection polling: Regular availability checks for better reliability

Device Selection Flow

  1. App scans for available FIDO2 devices (CCID readers + NFC availability)
  2. Single device → connects automatically
  3. Multiple devices → presents selection dialog
  4. User choice is remembered for the session
  5. Manual refresh available via UI buttons

Files Changed

New APIs:

  • lib/api/nfc_fido_api.dart - NFC FIDO implementation
  • lib/api/unified_fido_api.dart - Unified device selector

Enhanced Components:

  • lib/viewmodels/keys.dart - Device selection state management
  • lib/views/keys/keys.dart - Device selection dialog
  • lib/service/authenticator.dart - Device enumeration methods
  • lib/views/keys/widgets/device_info_section.dart - Current device display

Backwards Compatibility

Zero breaking changes - existing CCID workflows continue unchanged
Graceful degradation - falls back to CCID-only on non-mobile platforms
Error handling - clear messages when NFC is unavailable

Fixes #2

Original prompt

This section details on the original issue you should resolve

<issue_title>Support NFC tags</issue_title>
<issue_description>We should support NFC tags in addition to CCID with flutter_nfc_kit. Some suggestions:

  • extend the FidoApi class with nfc_fido_api.
  • design an elegant way of choosing tags when (potentially multiple) CCID readers and NFC are available

Please note that NFC communication might be transient -- so the APIs and lifecycle management might need to be redesigned, i.e. you need to check & poll tags every time when the user triggers communication.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #2

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Support NFC tags Add NFC tag support with unified device selection Sep 26, 2025
Copilot AI requested a review from Harry-Chen September 26, 2025 12:48
Copilot finished work on behalf of Harry-Chen September 26, 2025 12:48
@Harry-Chen
Copy link
Contributor

@copilot The tests you write do not look very useful, please remove them from the PR.

Copy link
Author

Copilot AI commented Sep 26, 2025

@copilot The tests you write do not look very useful, please remove them from the PR.

Removed the test files as requested. The commit b8eb0e2 removes both test/api/unified_fido_api_test.dart and test/integration_test.dart that I had added previously.

Copilot finished work on behalf of Harry-Chen September 26, 2025 12:54
@Harry-Chen Harry-Chen requested a review from dangfan September 29, 2025 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support NFC tags

4 participants