Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper to check biometrics support #1

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/KeychainLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,11 @@ func _getPassword(context: LAContext, service: String, completion: @escaping (Re
completion(.failure(.cannotRetrieve("Failed to retrieve data from keychain")))
}
}

@_cdecl("isBiometricsSupported")
public func isBiometricsSupported() -> Bool {
let context = LAContext()
return context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)

return false
}
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ export const getPassword = async (params: GetPasswordParams): Promise<string> =>

return secretResult;
};

export const isBiometricsSupported = (): boolean => {
const biometricsSupported = lib.func('isBiometricsSupported', 'bool', []);

return biometricsSupported() as boolean;
};
5 changes: 5 additions & 0 deletions tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as keychain from '../src';

if (!keychain.isBiometricsSupported()) {
console.error(`Keychain is not supported on this platform`);
process.exit(1);
}

console.log(`Adding to keychain...`);

const isSuccess2 = keychain.setPassword({
Expand Down
Loading