Skip to content

Commit d95fe57

Browse files
Merge pull request #55 from chamodanethra/feature/platform-support-windows
Refactor native communication and refactor example apps
2 parents 6b6d490 + ae209fb commit d95fe57

File tree

131 files changed

+14570
-4503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+14570
-4503
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
## [9.0.0] - 2025-12-18
2+
3+
* **Breaking**: Method signature changes:
4+
- `createKeys()` now takes `config`, `keyFormat`, `promptMessage` parameters
5+
- `createSignature()` now takes `payload`, `config`, `signatureFormat`, `keyFormat`, `promptMessage` parameters
6+
- `decrypt()` now takes `payload`, `payloadFormat`, `config`, `promptMessage` parameters
7+
8+
* Moved cross-platform parameters into unified config objects:
9+
- `signatureType`, `enforceBiometric`, `setInvalidatedByBiometricEnrollment`, `useDeviceCredentials` now in `CreateKeysConfig`
10+
- Each field is documented with which platform(s) it applies to
11+
12+
### Architecture - Type-safe Communication with Pigeon
13+
* **Breaking**: Migrated entire platform communication layer to [Pigeon](https://pub.dev/packages/pigeon).
14+
* **Breaking**: Replaced raw string/map returns with structured strongly-typed objects:
15+
- `KeyCreationResult`: Contains `publicKey`, `error`, and `code`.
16+
- `SignatureResult`: Contains `signature`, `publicKey`, `error`, and `code`.
17+
- `DecryptResult`: Contains `decryptedData`, `error`, and `code`.
18+
- `BiometricAvailability`: detailed availability status including enrolled biometric types and error reasons.
19+
* **Breaking**: Standardized `BiometricError` enum across all platforms.
20+
21+
### API Improvements
22+
* **Breaking**: `biometricAuthAvailable()` now returns a `BiometricAvailability` object instead of a raw string.
23+
* Removed legacy `signature_options.dart`, `decryption_options.dart` and old config classes.
24+
* Enhanced error handling with specific error codes (e.g., `userCanceled`, `notEnrolled`, `lockedOut`) instead of generic strings.
25+
* **New `getKeyInfo()` method**: Retrieve detailed information about existing biometric keys without creating a signature.
26+
- Returns `KeyInfo` object with: `exists`, `isValid`, `algorithm`, `keySize`, `isHybridMode`, `publicKey`, `decryptingPublicKey`.
27+
- Accepts `checkValidity` parameter to verify key hasn't been invalidated by biometric changes.
28+
- Accepts `keyFormat` parameter to specify output format (base64, pem, hex).
29+
* **New `KeyInfo` class**: Exported via Pigeon for type-safe key metadata.
30+
* `biometricKeyExists()` is now a convenience wrapper around `getKeyInfo()`.
31+
32+
### Improved
33+
* Cleaner, simpler API with fewer method parameters
34+
* Better documentation of platform-specific options
35+
* Updated all example projects to use new API
36+
137
## [8.5.0] - 2025-12-09
238

339
### Added - macOS Platform Support

EXAMPLES.md

Lines changed: 86 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -168,53 +168,112 @@ All examples demonstrate:
168168

169169
### Initialize Biometric Service
170170
```dart
171-
import 'package:biometric_signature/key_material.dart';
171+
import 'package:biometric_signature/biometric_signature.dart';
172172
173173
final biometric = BiometricSignature();
174174
175175
// Check availability
176-
final available = await biometric.biometricAuthAvailable();
176+
final availability = await biometric.biometricAuthAvailable();
177+
if (availability.canAuthenticate ?? false) {
178+
print('Biometrics available: ${availability.availableBiometrics}');
179+
}
177180
178-
// Create keys
181+
// Create keys (RSA by default)
179182
final keyResult = await biometric.createKeys(
180183
keyFormat: KeyFormat.pem,
181-
androidConfig: AndroidConfig(
182-
useDeviceCredentials: false,
183-
signatureType: AndroidSignatureType.RSA,
184-
),
185-
iosConfig: IosConfig(
186-
useDeviceCredentials: false,
187-
signatureType: IOSSignatureType.RSA,
184+
promptMessage: 'Authenticate to create keys',
185+
config: CreateKeysConfig(
186+
signatureType: SignatureType.rsa,
187+
useDeviceCredentials: true,
188+
setInvalidatedByBiometricEnrollment: true,
189+
enforceBiometric: true,
190+
enableDecryption: false, // Android only
188191
),
189192
);
190193
191-
final pemPublicKey = keyResult?.publicKey.asString();
194+
if (keyResult.code == BiometricError.success) {
195+
print('Public Key: ${keyResult.publicKey}');
196+
}
197+
```
198+
199+
### Get Key Info
200+
```dart
201+
// Check key existence with metadata
202+
final info = await biometric.getKeyInfo(
203+
checkValidity: true,
204+
keyFormat: KeyFormat.pem,
205+
);
206+
207+
if (info.exists && (info.isValid ?? true)) {
208+
print('Algorithm: ${info.algorithm}, Size: ${info.keySize} bits');
209+
print('Hybrid Mode: ${info.isHybridMode}');
210+
print('Public Key: ${info.publicKey}');
211+
}
192212
```
193213

194214
### Sign Data
195215
```dart
196-
final signatureResult = await biometric.createSignature(
197-
SignatureOptions(
198-
payload: 'data_to_sign',
199-
promptMessage: 'Authenticate to continue',
200-
keyFormat: KeyFormat.raw,
216+
final result = await biometric.createSignature(
217+
payload: 'data_to_sign',
218+
promptMessage: 'Authenticate to sign',
219+
signatureFormat: SignatureFormat.base64,
220+
keyFormat: KeyFormat.pem,
221+
config: CreateSignatureConfig(
222+
allowDeviceCredentials: true,
201223
),
202224
);
203225
204-
final signatureBase64 = signatureResult?.signature.toBase64();
226+
if (result.code == BiometricError.success) {
227+
print('Signature: ${result.signature}');
228+
}
229+
```
230+
231+
### Decrypt Data
232+
```dart
233+
final decryptResult = await biometric.decrypt(
234+
payload: encryptedBase64,
235+
payloadFormat: PayloadFormat.base64,
236+
promptMessage: 'Authenticate to decrypt',
237+
config: DecryptConfig(
238+
allowDeviceCredentials: false,
239+
),
240+
);
241+
242+
if (decryptResult.code == BiometricError.success) {
243+
print('Decrypted: ${decryptResult.decryptedData}');
244+
}
205245
```
206246

207247
### Error Handling
208248
```dart
209-
try {
210-
final signatureResult = await biometric.createSignature(options);
211-
final signatureHex = signatureResult?.signature.toHex();
212-
} on PlatformException catch (e) {
213-
if (e.code == 'AUTH_FAILED') {
214-
// Handle authentication failure
215-
} else if (e.code == 'CANCELLED') {
216-
// Handle user cancellation
217-
}
249+
final result = await biometric.createSignature(
250+
payload: 'data_to_sign',
251+
promptMessage: 'Authenticate',
252+
);
253+
254+
switch (result.code) {
255+
case BiometricError.success:
256+
print('Signed: ${result.signature}');
257+
break;
258+
case BiometricError.userCanceled:
259+
print('User cancelled authentication');
260+
break;
261+
case BiometricError.keyInvalidated:
262+
print('Key invalidated - re-enrollment required');
263+
break;
264+
case BiometricError.lockedOut:
265+
print('Too many attempts - locked out');
266+
break;
267+
default:
268+
print('Error: ${result.code} - ${result.error}');
269+
}
270+
```
271+
272+
### Delete Keys
273+
```dart
274+
final deleted = await biometric.deleteKeys();
275+
if (deleted) {
276+
print('All biometric keys removed');
218277
}
219278
```
220279

@@ -232,7 +291,7 @@ Found an issue or want to improve an example? Contributions are welcome!
232291

233292
1. Fork the repository
234293
2. Create your feature branch
235-
3. Test your changes on both platforms
294+
3. Test your changes on all platforms
236295
4. Submit a pull request
237296

238297
## 📄 License

0 commit comments

Comments
 (0)