Skip to content

Commit fadfcf9

Browse files
committed
docs: update migration guide and changelog for biometric authentication changes
1 parent 732f9d2 commit fadfcf9

File tree

4 files changed

+23
-102
lines changed

4 files changed

+23
-102
lines changed

CHANGELOG.md

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,8 @@ All notable changes to KSafe will be documented in this file.
2929
- `clearBiometricAuth(scope)` - Clear only a specific scope
3030

3131
### Changed
32-
- **Removed `useBiometrics` parameter** from all storage APIs (`get`, `put`, `getDirect`, `putDirect`)
33-
- Biometric verification is now a separate step you control explicitly
3432
- **iOS thread safety improvements** - Biometric callbacks now always execute on Main thread
3533

36-
### Migration from 1.2.x
37-
38-
#### Before (1.2.x)
39-
```kotlin
40-
// Biometrics tied to storage
41-
ksafe.put("key", value, useBiometrics = true)
42-
val data = ksafe.get("key", default, useBiometrics = true)
43-
```
44-
45-
#### After (1.3.0)
46-
```kotlin
47-
// Biometrics as a separate verification step
48-
ksafe.verifyBiometricDirect("Authenticate to save") { success ->
49-
if (success) {
50-
ksafe.putDirect("key", value)
51-
}
52-
}
53-
54-
// Or with suspend function
55-
if (ksafe.verifyBiometric("Authenticate to read")) {
56-
val data = ksafe.get("key", default)
57-
}
58-
59-
// With duration caching (60 seconds, scoped to ViewModel)
60-
ksafe.verifyBiometricDirect(
61-
reason = "Authenticate",
62-
authorizationDuration = BiometricAuthorizationDuration(
63-
duration = 60_000L,
64-
scope = viewModelScope.hashCode().toString()
65-
)
66-
) { success ->
67-
if (success) { /* ... */ }
68-
}
69-
```
70-
71-
### Benefits of New Architecture
72-
- **Full control** over when biometric prompts appear
73-
- **Reusable** - Same biometric helper protects any action
74-
- **Flexible caching** - Avoid prompt fatigue with duration caching
75-
- **Scoped invalidation** - Auth tied to ViewModel lifecycle or custom scopes
76-
- **Cleaner separation** - Storage and authentication are independent concerns
77-
7834
---
7935

8036
## [1.2.0] - 2025-01-15

README.md

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -929,44 +929,6 @@ The iOS test app demonstrates:
929929

930930
## Migration Guide
931931

932-
### From v1.2.x to v1.3.0
933-
934-
#### Biometric API Changes
935-
The `useBiometrics` parameter has been **removed** from all storage APIs. Biometric authentication is now a standalone helper.
936-
937-
**Before (1.2.x):**
938-
```kotlin
939-
// Biometrics tied to storage
940-
ksafe.put("key", value, useBiometrics = true)
941-
val data = ksafe.get("key", default, useBiometrics = true)
942-
```
943-
944-
**After (1.3.0):**
945-
```kotlin
946-
// Biometrics as a separate verification step
947-
ksafe.verifyBiometricDirect("Authenticate to save") { success ->
948-
if (success) {
949-
ksafe.putDirect("key", value)
950-
}
951-
}
952-
953-
// Or with suspend function
954-
if (ksafe.verifyBiometric("Authenticate to read")) {
955-
val data = ksafe.get("key", default)
956-
}
957-
958-
// With duration caching (60 seconds, scoped to ViewModel)
959-
ksafe.verifyBiometricDirect(
960-
reason = "Authenticate",
961-
authorizationDuration = BiometricAuthorizationDuration(
962-
duration = 60_000L,
963-
scope = viewModelScope.hashCode().toString()
964-
)
965-
) { success ->
966-
if (success) { /* ... */ }
967-
}
968-
```
969-
970932
### From v1.1.x to v1.2.0+
971933

972934
#### Binary Compatibility

ksafe/src/commonMain/kotlin/eu/anifantakis/lib/ksafe/KSafeConfig.kt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,42 @@ package eu.anifantakis.lib.ksafe
1414
*
1515
* // Custom key size
1616
* val ksafe128 = KSafe(context, config = KSafeConfig(keySize = 128))
17-
*
18-
* // Android: customize biometric auth validity duration
19-
* val androidSafe = KSafe(
20-
* context,
21-
* config = KSafeConfig(androidAuthValiditySeconds = 60)
22-
* )
2317
* ```
2418
*
25-
* ## Biometric Protection
19+
* ## Biometric Authentication
2620
*
27-
* Biometric protection is configured **per-value**, not at the KSafe instance level:
21+
* Biometric authentication is a **standalone helper** decoupled from storage operations.
22+
* Use `verifyBiometric()` or `verifyBiometricDirect()` to protect any action:
2823
*
2924
* ```kotlin
3025
* val ksafe = KSafe(context)
3126
*
32-
* // Per-value biometric protection
33-
* var authToken by ksafe(defaultValue = "", encrypted = true, useBiometrics = true) // 🔐 Protected
34-
* var theme by ksafe(defaultValue = "light", encrypted = false) // Not protected
35-
* ```
27+
* // Protect storage with biometrics
28+
* ksafe.verifyBiometricDirect("Authenticate to save") { success ->
29+
* if (success) {
30+
* ksafe.putDirect("authToken", token)
31+
* }
32+
* }
3633
*
37-
* Platform behavior when `useBiometrics = true`:
34+
* // With duration caching (60 seconds, scoped to ViewModel)
35+
* ksafe.verifyBiometricDirect(
36+
* reason = "Authenticate",
37+
* authorizationDuration = BiometricAuthorizationDuration(60_000L, viewModelScope.hashCode().toString())
38+
* ) { success ->
39+
* if (success) { /* ... */ }
40+
* }
41+
* ```
3842
*
3943
* | Platform | Behavior |
4044
* |----------|----------|
41-
* | **Android** | Time-bound: Key usable for N seconds after BiometricPrompt/device unlock |
42-
* | **iOS** | Per-access: Face ID / Touch ID / Passcode prompt on each key access |
43-
* | **JVM** | Ignored (no biometric hardware available) |
45+
* | **Android** | BiometricPrompt with fingerprint/face/device credential |
46+
* | **iOS** | Face ID / Touch ID / Passcode via LocalAuthentication |
47+
* | **JVM** | Always returns true (no biometric hardware available) |
4448
*
4549
* @property keySize The size of the AES key in bits. Supported values: 128, 256. Default is 256.
4650
* **Note:** 128-bit keys may offer marginally faster encryption on very old devices,
4751
* but 256-bit is strongly recommended for all modern devices (negligible performance difference).
48-
* @property androidAuthValiditySeconds **Android only.** Duration in seconds that biometric-protected
49-
* keys remain usable after authentication. Default is 30 seconds. Ignored on iOS/JVM.
52+
* @property androidAuthValiditySeconds Reserved for future use. Default is 30 seconds.
5053
*/
5154
data class KSafeConfig(
5255
val keySize: Int = 256,

ksafe/src/commonTest/kotlin/eu/anifantakis/lib/ksafe/KSafeConfigTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import kotlin.test.assertFalse
88
/**
99
* Tests for [KSafeConfig] validation and defaults.
1010
*
11-
* Note: Biometric protection is now configured per-value (via `useBiometrics` parameter),
12-
* not at the KSafeConfig level. See KSafe API for biometric usage.
11+
* Note: Biometric authentication is a standalone helper via `verifyBiometric()` and
12+
* `verifyBiometricDirect()`. See KSafe API for biometric usage.
1313
*/
1414
class KSafeConfigTest {
1515

0 commit comments

Comments
 (0)