Files
OpenMotion/lib/services/pin_store.dart
T
2026-09-21 18:03:21 -04:00

29 lines
935 B
Dart

import 'package:flutter_secure_storage/flutter_secure_storage.dart';
/// Remembers scooter PINs in platform secure storage (Android Keystore backed
/// storage, iOS Keychain), keyed by the BLE peripheral id.
///
/// The peripheral id is not a permanent scooter identity (see ScooterDevice).
/// Once the Apollo UID is read over AT+UID? this should key by that instead.
class PinStore {
PinStore([FlutterSecureStorage? storage])
: _storage = storage ?? const FlutterSecureStorage();
final FlutterSecureStorage _storage;
String _key(String deviceId) => 'pin:$deviceId';
Future<String?> read(String deviceId) async {
try {
return await _storage.read(key: _key(deviceId));
} catch (_) {
return null;
}
}
Future<void> save(String deviceId, String pin) =>
_storage.write(key: _key(deviceId), value: pin);
Future<void> forget(String deviceId) => _storage.delete(key: _key(deviceId));
}