2022-04-05 16:54:44 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate napi_derive;
|
|
|
|
|
2022-04-25 15:45:42 +02:00
|
|
|
mod biometric;
|
2022-04-05 16:54:44 +02:00
|
|
|
mod password;
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
pub mod passwords {
|
|
|
|
/// Fetch the stored password from the keychain.
|
|
|
|
#[napi]
|
|
|
|
pub async fn get_password(service: String, account: String) -> napi::Result<String> {
|
|
|
|
super::password::get_password(&service, &account)
|
|
|
|
.map_err(|e| napi::Error::from_reason(e.to_string()))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Fetch the stored password from the keychain that was stored with Keytar.
|
|
|
|
#[napi]
|
|
|
|
pub async fn get_password_keytar(service: String, account: String) -> napi::Result<String> {
|
|
|
|
super::password::get_password_keytar(&service, &account)
|
|
|
|
.map_err(|e| napi::Error::from_reason(e.to_string()))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Save the password to the keychain. Adds an entry if none exists otherwise updates the existing entry.
|
|
|
|
#[napi]
|
|
|
|
pub async fn set_password(
|
|
|
|
service: String,
|
|
|
|
account: String,
|
|
|
|
password: String,
|
|
|
|
) -> napi::Result<()> {
|
|
|
|
super::password::set_password(&service, &account, &password)
|
|
|
|
.map_err(|e| napi::Error::from_reason(e.to_string()))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Delete the stored password from the keychain.
|
|
|
|
#[napi]
|
|
|
|
pub async fn delete_password(service: String, account: String) -> napi::Result<()> {
|
|
|
|
super::password::delete_password(&service, &account)
|
|
|
|
.map_err(|e| napi::Error::from_reason(e.to_string()))
|
|
|
|
}
|
|
|
|
}
|
2022-04-25 15:45:42 +02:00
|
|
|
|
|
|
|
#[napi]
|
|
|
|
pub mod biometrics {
|
|
|
|
// Prompt for biometric confirmation
|
|
|
|
#[napi]
|
|
|
|
pub async fn prompt(
|
|
|
|
hwnd: napi::bindgen_prelude::Buffer,
|
|
|
|
message: String,
|
|
|
|
) -> napi::Result<bool> {
|
|
|
|
super::biometric::prompt(hwnd.into(), message)
|
|
|
|
.map_err(|e| napi::Error::from_reason(e.to_string()))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
pub async fn available() -> napi::Result<bool> {
|
|
|
|
super::biometric::available().map_err(|e| napi::Error::from_reason(e.to_string()))
|
|
|
|
}
|
|
|
|
}
|