@dderevjanik/termux-api
Version:
This library allows you to interact with your Android device from Node.js using termux-api
45 lines (40 loc) • 1.1 kB
text/typescript
import { exec } from "child_process";
/**
* Represents the result of a fingerprint authentication attempt.
*/
export interface FingerprintAuthResult {
/**
* List of errors encountered during the authentication attempt.
* @example []
*/
errors: string[];
/**
* The number of failed authentication attempts.
* @example 0
*/
failed_attempts: number;
/**
* The result of the authentication attempt.
* @example "AUTH_RESULT_SUCCESS"
*/
auth_result: string;
}
/**
* Use fingerprint sensor on device to check for authentication.
*/
export async function fingerprint(): Promise<FingerprintAuthResult> {
return new Promise<FingerprintAuthResult>((resolve, reject) => {
const command = `termux-fingerprint`;
exec(command, (error, stdout, stderr) => {
if (error) {
return reject(`Error: ${error.message}`);
}
if (stderr) {
return reject(`Error: ${stderr}`);
}
const output = stdout.trim();
const authResult: FingerprintAuthResult = JSON.parse(output);
return resolve(authResult);
});
});
}