Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
//! UniFFI bindings for the iOS and Android apps.
use crate::crypto::argon2::Argon2Error;
use crate::crypto::{KeyChainError, SrpInputError};
use crate::crypto::srp::{SrpEphemeral, SrpError, SrpSession};
use crate::common::error::VaultError;
use crate::sqlite_host::{MemoryDatabase, SqlResult, SqlValue};
use crate::vault_items;
/// Filter credentials for autofill by the current URL/app and page title.
/// Input: `CredentialMatcherInput` JSON. Output: `CredentialMatcherOutput` JSON.
#[uniffi::export]
pub fn filter_credentials_json(input_json: String) -> Result<String, VaultError> {
crate::credential_matcher::filter_credentials_json(&input_json)
}
/// The domain of a URL or partial domain: no protocol, `www.` prefix, path, query or fragment.
#[uniffi::export]
pub fn extract_domain(url: String) -> String {
crate::credential_matcher::extract_domain(&url)
}
/// The root domain of a domain: `sub.example.co.uk` gives `example.co.uk`.
#[uniffi::export]
pub fn extract_root_domain(domain: String) -> String {
crate::credential_matcher::extract_root_domain(&domain)
}
/// Whether a page on `host` may use `rp_id` as its WebAuthn relying party id: the host or a parent that is not a public suffix.
#[uniffi::export]
pub fn is_rp_id_allowed_for_host(rp_id: String, host: String) -> bool {
crate::credential_matcher::is_rp_id_allowed_for_host(&rp_id, &host)
}
/// Whether `caller_origin` is listed in the `origins` of an rp id's `/.well-known/webauthn` file (WebAuthn related origins).
#[uniffi::export]
pub fn is_related_origin_allowed(caller_origin: String, origins: Vec<String>) -> bool {
crate::credential_matcher::is_related_origin_allowed(&caller_origin, &origins)
}
/// The favicon target for an item's URLs (in item order): the URL to fetch and the `Logos.Source` key, or None.
#[uniffi::export]
pub fn select_favicon_target(urls: Vec<String>) -> Option<crate::favicon::FaviconTarget> {
crate::favicon::select_favicon_target(&urls)
}
/// The `Logos.Source` key of a URL, or an empty string when no favicon can be fetched for it.
#[uniffi::export]
pub fn favicon_source_key(url: String) -> String {
crate::favicon::favicon_source_key(&url)
}
/// The RFC 6238 code for a Base32 secret at `unix_seconds`, or `None` for an unusable secret. Unknown parameters fall back to SHA1, 6 digits, 30 seconds.
#[uniffi::export]
pub fn generate_totp_code(secret: String, unix_seconds: i64, algorithm: String, digits: u32, period: u32) -> Option<String> {
crate::totp::generate_totp_code(&secret, unix_seconds, &algorithm, digits, period)
}
/// Generate a password or passphrase from `PasswordSettings` JSON; `Type` selects "basic" or "diceware" and an
/// optional 64-character hex `Seed` makes the output deterministic for UI previews.
#[uniffi::export]
pub fn generate_password(settings_json: String) -> Result<String, VaultError> {
crate::password_generator::generate_password(&settings_json)
}
/// List the language codes of all bundled Diceware wordlists (first is the default, English).
#[uniffi::export]
pub fn get_diceware_languages() -> Vec<String> {
crate::password_generator::available_languages()
}
/// Generate a random identity from `IdentityRequest` JSON; returns `Identity` JSON.
#[uniffi::export]
pub fn generate_identity(request_json: String) -> Result<String, VaultError> {
crate::identity_generator::generate_identity(&request_json)
}
/// Generate a username from name input JSON (`firstName`, `lastName`, `birthDate`).
#[uniffi::export]
pub fn generate_identity_username(input_json: String) -> Result<String, VaultError> {
crate::identity_generator::generate_username(&input_json)
}
/// Generate an email prefix from name input JSON (`firstName`, `lastName`, `birthDate`).
#[uniffi::export]
pub fn generate_identity_email_prefix(input_json: String) -> Result<String, VaultError> {
crate::identity_generator::generate_email_prefix(&input_json)
}
/// Generate a random alphanumeric email prefix that is not based on any identity.
#[uniffi::export]
pub fn generate_random_email_prefix(length: u32) -> String {
crate::identity_generator::generate_random_email_prefix(length)
}
/// Get the list of bundled identity dictionary language codes.
#[uniffi::export]
pub fn get_identity_languages() -> Vec<String> {
crate::identity_generator::available_languages()
}
/// Get the list of age range option values ("random" plus 5-year ranges).
#[uniffi::export]
pub fn get_identity_age_ranges() -> Vec<String> {
crate::identity_generator::available_age_ranges()
}
/// Parse a stored email source into its bodies and attachment metadata, as `ParsedEmail` JSON.
#[uniffi::export]
pub fn parse_email_source(source: Vec<u8>) -> Result<String, VaultError> {
crate::email_parser::parse_email_source_json(&source)
}
/// The raw RFC 822 bytes of a stored email source.
#[uniffi::export]
pub fn decode_email_source(source: Vec<u8>) -> Result<Vec<u8>, VaultError> {
crate::email_parser::decode_email_source(&source)
}
/// The decoded bytes of the attachment at `index`, with its separately fetched body when it is detached.
#[uniffi::export]
pub fn extract_email_attachment(source: Vec<u8>, index: u32, detached_body: Option<Vec<u8>>) -> Result<Vec<u8>, VaultError> {
crate::email_parser::extract_email_attachment(&source, index as usize, detached_body.as_deref())
}
/// The sha256 (lowercase hex) of an uploaded logo's bytes: the `Source` of a `custom` logo row, and
/// what [`vault_codec_logo_id_for`] then derives the row id from.
#[uniffi::export]
pub fn vault_codec_logo_content_hash(bytes: Vec<u8>) -> String {
crate::vault_codec::logo_content_hash(&bytes)
}
/// The `Logos.Id` to use for the logo `(kind, source)` inside the manifest with id `manifest_id`.
/// `kind` is 'favicon' (source = domain), 'builtin' (source = catalog key) or 'custom' (source = image content hash).
#[uniffi::export]
pub fn vault_codec_logo_id_for(manifest_id: String, kind: String, source: String) -> String {
crate::vault_codec::logo_id_for(&manifest_id, &kind, &source)
}
/// Derive a 32-byte key from a password and salt (UTF-8 bytes) with Argon2id under the `EncryptionSettings` JSON (required).
#[uniffi::export]
pub fn argon2_derive_key(password: String, salt: String, encryption_settings: String) -> Result<Vec<u8>, Argon2Error> {
let password = zeroize::Zeroizing::new(password);
let params = crate::crypto::argon2::Argon2Params::from_settings_json(&encryption_settings)?;
crate::crypto::argon2::argon2_derive_key(password.as_bytes(), salt.as_bytes(), params).map(|mut key| std::mem::take(&mut *key))
}
/// AES-256-GCM decrypt a base64 `IV | ciphertext | tag` string (no AAD) into UTF-8 with a base64 key. An empty ciphertext is an error.
#[uniffi::export]
pub fn symmetric_decrypt(base64_ciphertext: String, key_base64: String) -> Result<String, VaultError> {
crate::crypto::aes_gcm::decrypt_text(&base64_ciphertext, &key_base64, &[])
}
/// AES-256-GCM decrypt `IV | ciphertext | tag` bytes with a base64 key.
#[uniffi::export]
pub fn symmetric_decrypt_bytes(encrypted: Vec<u8>, key_base64: String) -> Result<Vec<u8>, VaultError> {
crate::crypto::aes_gcm::decrypt(&encrypted, &key_base64, &[])
}
/// AES-256-GCM encrypt bytes with a base64 key (random IV, no AAD) into `IV | ciphertext | tag` bytes.
#[uniffi::export]
pub fn symmetric_encrypt_bytes(plaintext: Vec<u8>, key_base64: String) -> Result<Vec<u8>, VaultError> {
crate::crypto::aes_gcm::encrypt(&plaintext, &key_base64, &[])
}
/// Encrypt the SQLite database bytes into the locally stored vault blob (base64) under the raw 32-byte VEK.
#[uniffi::export]
pub fn vault_blob_encrypt(sqlite_bytes: Vec<u8>, key: Vec<u8>) -> Result<String, VaultError> {
crate::crypto::vault_blob_encrypt(&sqlite_bytes, &zeroize::Zeroizing::new(crate::common::encoding::base64_encode(&key)))
}
/// Decrypt the locally stored vault blob (base64) into the SQLite database bytes under the raw 32-byte VEK.
#[uniffi::export]
pub fn vault_blob_decrypt(encrypted_blob: String, key: Vec<u8>) -> Result<Vec<u8>, VaultError> {
crate::crypto::vault_blob_decrypt(&encrypted_blob, &zeroize::Zeroizing::new(crate::common::encoding::base64_encode(&key)))
}
/// The fingerprint of the account's own signing key, derived from its private key encrypted with the Account Key.
#[uniffi::export]
pub fn account_signing_key_fingerprint(encrypted_signing_private_key: String, account_key: Vec<u8>) -> Result<String, VaultError> {
let account_key = zeroize::Zeroizing::new(crate::common::encoding::base64_encode(&account_key));
crate::crypto::account_signing_key_fingerprint(&encrypted_signing_private_key, &account_key)
}
/// Encrypt .avux bytes into an .avex file under the export password.
#[uniffi::export]
pub fn avex_encrypt(avux: Vec<u8>, password: String, exported_at: String, app_version: String) -> Result<Vec<u8>, VaultError> {
let (avux, password) = (zeroize::Zeroizing::new(avux), zeroize::Zeroizing::new(password));
crate::crypto::avex_encrypt(&avux, &password, &exported_at, &app_version)
}
/// A fresh random salt for a new PIN key.
#[uniffi::export]
pub fn pin_generate_salt() -> Vec<u8> {
crate::crypto::pin_generate_salt()
}
/// Encrypt `secret` with a key derived from the PIN and salt. Returns `IV | ciphertext | tag`.
#[uniffi::export]
pub fn pin_encrypt(pin: String, salt: Vec<u8>, secret: Vec<u8>) -> Result<Vec<u8>, VaultError> {
let (pin, secret) = (zeroize::Zeroizing::new(pin), zeroize::Zeroizing::new(secret));
crate::crypto::pin_encrypt(&pin, &salt, &secret)
}
/// Decrypt a key encrypted with the PIN. Fails for a wrong PIN.
#[uniffi::export]
pub fn pin_decrypt(pin: String, salt: Vec<u8>, encrypted: Vec<u8>) -> Result<Vec<u8>, VaultError> {
let pin = zeroize::Zeroizing::new(pin);
crate::crypto::pin_decrypt(&pin, &salt, &encrypted).map(|mut secret| std::mem::take(&mut *secret))
}
/// Whether a stored failed-attempt count means the PIN is locked.
#[uniffi::export]
pub fn pin_is_locked(failed_attempts: u32) -> bool {
crate::crypto::pin_is_locked(failed_attempts)
}
/// The counter state after one more failed PIN attempt on top of the stored count.
#[uniffi::export]
pub fn pin_register_failure(failed_attempts: u32) -> crate::crypto::PinFailure {
crate::crypto::pin_register_failure(failed_attempts)
}
/// Create a new account key hierarchy for the unlock key, as JSON.
#[uniffi::export]
pub fn create_account_key_hierarchy_json(unlock_key: Vec<u8>) -> Result<String, VaultError> {
let unlock_key = zeroize::Zeroizing::new(crate::common::encoding::base64_encode(&unlock_key));
let hierarchy = crate::crypto::create_account_key_hierarchy(&unlock_key)?;
Ok(serde_json::to_string(&hierarchy)?)
}
/// Re-encrypt the Account Key from the old to the new unlock key, as JSON; `null` when the old unlock key does not open it.
#[uniffi::export]
pub fn reencrypt_account_key_json(encrypted_account_key: String, old_unlock_key: Vec<u8>, new_unlock_key: Vec<u8>) -> Result<String, VaultError> {
use crate::common::encoding::base64_encode;
let old_unlock_key = zeroize::Zeroizing::new(base64_encode(&old_unlock_key));
let new_unlock_key = zeroize::Zeroizing::new(base64_encode(&new_unlock_key));
match crate::crypto::reencrypt_account_key(&encrypted_account_key, &old_unlock_key, &new_unlock_key) {
Ok(reencrypted) => Ok(serde_json::to_string(&reencrypted)?),
Err(KeyChainError::UnlockKeyRejected) => Ok("null".to_string()),
Err(e) => Err(VaultError::General(e.to_string())),
}
}
/// The SRP `password_hash` (uppercase hex) for an account's `encryptionType`, from the unlock key.
#[uniffi::export]
pub fn derive_srp_password_hash(unlock_key: Vec<u8>, encryption_type: String) -> Result<String, SrpInputError> {
crate::crypto::derive_srp_password_hash(&unlock_key, &encryption_type).map(|hash| hash.to_string())
}
/// The keys an opened chain gives.
#[derive(uniffi::Record)]
pub struct KeyChainKeys {
pub vault_encryption_key: Vec<u8>,
/// The Account Key: what the caller stores for later unlocks.
pub account_key: Vec<u8>,
/// The account private key (JWK), none when the account has no keypair or it does not open.
pub account_private_key: Option<String>,
}
impl KeyChainKeys {
fn from(opened: crate::crypto::key_chain::OpenedKeyChain) -> Result<Self, KeyChainError> {
let decode = |key: &str| crate::common::encoding::base64_decode(key).map_err(|e| KeyChainError::KeyChainUnreadable(e.to_string()));
Ok(KeyChainKeys {
vault_encryption_key: decode(&opened.vault_encryption_key)?,
account_key: decode(&opened.account_key)?,
account_private_key: opened.account_private_key.as_ref().map(|key| key.to_string()),
})
}
}
/// Open a key chain with the unlock key (the password's Argon2id output).
#[uniffi::export]
pub fn open_key_chain_with_unlock_key(unlock_key: Vec<u8>, encrypted_account_key: String, encrypted_vek: String, encrypted_account_private_key: Option<String>) -> Result<KeyChainKeys, KeyChainError> {
let unlock_key = zeroize::Zeroizing::new(crate::common::encoding::base64_encode(&unlock_key));
KeyChainKeys::from(crate::crypto::open_key_chain_with_unlock_key(&unlock_key, &encrypted_account_key, &encrypted_vek, encrypted_account_private_key.as_deref())?)
}
/// Open a key chain with the Account Key.
#[uniffi::export]
pub fn open_key_chain_with_account_key(account_key: Vec<u8>, encrypted_vek: String, encrypted_account_private_key: Option<String>) -> Result<KeyChainKeys, KeyChainError> {
let account_key = zeroize::Zeroizing::new(crate::common::encoding::base64_encode(&account_key));
KeyChainKeys::from(crate::crypto::open_key_chain_with_account_key(&account_key, &encrypted_vek, encrypted_account_private_key.as_deref())?)
}
/// A random 32-byte SRP salt as an uppercase hex string.
#[uniffi::export]
pub fn srp_generate_salt() -> String {
crate::crypto::srp::srp_generate_salt()
}
/// The SRP private key (x) as uppercase hex from the hex salt, the identity and the hex password hash.
#[uniffi::export]
pub fn srp_derive_private_key(salt: String, identity: String, password_hash: String) -> Result<String, SrpError> {
crate::crypto::srp::srp_derive_private_key(&salt, &identity, &password_hash)
}
/// The SRP verifier (v) as uppercase hex from the hex private key, for registration.
#[uniffi::export]
pub fn srp_derive_verifier(private_key: String) -> Result<String, SrpError> {
crate::crypto::srp::srp_derive_verifier(&private_key)
}
/// A client ephemeral pair: public (A) and secret (a) as uppercase hex.
#[uniffi::export]
pub fn srp_generate_ephemeral() -> SrpEphemeral {
crate::crypto::srp::srp_generate_ephemeral()
}
/// The client session (proof M1 and key K, uppercase hex) from the server's public ephemeral; hex inputs.
#[uniffi::export]
pub fn srp_derive_session(client_secret: String, server_public: String, salt: String, identity: String, private_key: String) -> Result<SrpSession, SrpError> {
crate::crypto::srp::srp_derive_session(&client_secret, &server_public, &salt, &identity, &private_key)
}
/// Whether the server's proof (M2) matches, which confirms it derived the same session key; hex inputs.
#[uniffi::export]
pub fn srp_verify_session(client_public: String, client_proof: String, session_key: String, server_proof: String) -> Result<bool, SrpError> {
crate::crypto::srp::srp_verify_session(&client_public, &client_proof, &session_key, &server_proof)
}
/// RSA-OAEP-256 decrypt base64 ciphertext with a JWK private key.
#[uniffi::export]
pub fn rsa_decrypt(base64_ciphertext: String, private_key_jwk: String) -> Result<Vec<u8>, VaultError> {
crate::crypto::rsa_oaep::decrypt(&base64_ciphertext, &private_key_jwk, &[])
}
/// Decrypt the shared manifest name encrypted into an invitation for this JWK private key.
#[uniffi::export]
pub fn decrypt_manifest_invitation_name(encrypted_name: String, manifest_id: String, private_key_jwk: String) -> Result<String, VaultError> {
crate::vault_sync::keys::decrypt_manifest_invitation_name(&encrypted_name, &manifest_id, &private_key_jwk)
}
/// RSA-OAEP-256 encrypt the Account Key for a mobile login request's JWK public key, as base64.
#[uniffi::export]
pub fn mobile_login_encrypt_account_key(account_key: Vec<u8>, public_key_jwk: String) -> Result<String, VaultError> {
crate::crypto::mobile_login_encrypt_account_key(&account_key, &public_key_jwk)
}
/// SHA-256 of a mobile login request's public key JWK string, unpadded base64url; the QR code carries it.
#[uniffi::export]
pub fn mobile_login_public_key_hash(public_key_jwk: String) -> String {
crate::crypto::mobile_login_public_key_hash(&public_key_jwk)
}
/// The verification code both devices show for a mobile login request's public key JWK string.
#[uniffi::export]
pub fn mobile_login_verification_code(public_key_jwk: String) -> String {
crate::crypto::mobile_login_verification_code(&public_key_jwk)
}
/// One engine operation. The host loops on `next_command` / `resume` until the command is `done`; see the
/// `vault_sync` module docs for the command and response shapes.
#[derive(uniffi::Object)]
pub struct VaultSyncSession {
inner: crate::vault_sync::SyncSession,
}
#[uniffi::export]
impl VaultSyncSession {
/// Start an operation from its `SyncRequest` JSON.
#[uniffi::constructor]
pub fn new(request_json: String) -> Result<std::sync::Arc<Self>, VaultError> {
Ok(std::sync::Arc::new(Self { inner: crate::vault_sync::SyncSession::new(&request_json)? }))
}
/// The next command for the host, as JSON.
pub fn next_command(&self) -> Result<String, VaultError> {
self.inner.next_command()
}
/// Take the raw bytes attached to the last command (the body of a binary `http` request), if any.
pub fn command_bytes(&self) -> Result<Option<Vec<u8>>, VaultError> {
self.inner.command_bytes()
}
/// Hand the host's response to the last command back, as JSON, with raw bytes for a `dbExport` or a binary `http` response.
pub fn resume(&self, response_json: String, bytes: Option<Vec<u8>>) -> Result<(), VaultError> {
self.inner.resume(&response_json, bytes)
}
}
/// An in-memory SQLite database the host reads and writes through.
#[derive(uniffi::Object)]
pub struct SqliteMemoryDatabase {
inner: MemoryDatabase,
}
#[uniffi::export]
impl SqliteMemoryDatabase {
/// Open a database from its SQLite file bytes.
#[uniffi::constructor]
pub fn from_bytes(bytes: Vec<u8>) -> Result<std::sync::Arc<Self>, VaultError> {
Ok(std::sync::Arc::new(Self { inner: MemoryDatabase::from_bytes(&bytes)? }))
}
/// Run a SQL script without parameters.
pub fn execute_batch(&self, sql: String) -> Result<(), VaultError> {
self.inner.execute_batch(&sql)
}
/// Run one query; `params_json` is a JSON array, the result a JSON array of row objects.
pub fn query(&self, sql: String, params_json: String) -> Result<String, VaultError> {
let params: Vec<serde_json::Value> = serde_json::from_str(¶ms_json)?;
Ok(serde_json::to_string(&self.inner.query(&sql, ¶ms)?)?)
}
/// Run statements (a JSON array of `{"sql", "params"}`) in one transaction.
pub fn exec(&self, statements_json: String) -> Result<(), VaultError> {
let statements: Vec<crate::sqlite_host::SqlStatement> = serde_json::from_str(&statements_json)?;
self.inner.exec(&statements)
}
/// Run one query with typed parameters; rows come back positionally under `columns`.
pub fn query_values(&self, sql: String, params: Vec<SqlValue>) -> Result<SqlResult, VaultError> {
self.inner.query_values(&sql, ¶ms)
}
/// Run one statement with typed parameters and return the number of rows it changed.
pub fn execute(&self, sql: String, params: Vec<SqlValue>) -> Result<u64, VaultError> {
self.inner.execute(&sql, ¶ms)
}
/// The database as SQLite file bytes.
pub fn export(&self) -> Result<Vec<u8>, VaultError> {
self.inner.export()
}
}
/// Item, passkey and usage-statistics operations on the open vault. Writes open no transaction of their own:
/// the host wraps each call in the transaction whose commit persists the vault.
#[uniffi::export]
impl SqliteMemoryDatabase {
/// Every active item (not deleted, trashed or archived) with its fields and folder path, newest first.
pub fn get_all_active_items(&self) -> Result<Vec<vault_items::VaultItem>, VaultError> {
self.inner.with_connection(vault_items::get_all_active_items)
}
/// The live TOTP codes of one item.
pub fn get_totp_codes_for_item(&self, item_id: String, manifest_id: String) -> Result<Vec<vault_items::VaultTotpCode>, VaultError> {
self.inner.with_connection(|conn| vault_items::get_totp_codes_for_item(conn, &item_id, &manifest_id))
}
/// Append one value to a system field of an item and return the rows inserted.
pub fn append_field_value(&self, item_id: String, manifest_id: String, field_key: String, value: String) -> Result<u64, VaultError> {
self.inner.with_connection(|conn| vault_items::append_field_value(conn, &item_id, &manifest_id, &field_key, &value))
}
/// The passkey with this credential id in any manifest.
pub fn get_passkey_by_id(&self, passkey_id: String) -> Result<Option<vault_items::VaultPasskeyWithItem>, VaultError> {
self.inner.with_connection(|conn| vault_items::get_passkey_by_id(conn, &passkey_id))
}
/// The passkey with this id inside one manifest.
pub fn get_passkey_in_manifest(&self, passkey_id: String, manifest_id: String) -> Result<Option<vault_items::VaultPasskeyWithItem>, VaultError> {
self.inner.with_connection(|conn| vault_items::get_passkey_in_manifest(conn, &passkey_id, &manifest_id))
}
/// The passkeys of one item, newest first.
pub fn get_passkeys_for_item(&self, item_id: String, manifest_id: String) -> Result<Vec<vault_items::VaultPasskey>, VaultError> {
self.inner.with_connection(|conn| vault_items::get_passkeys_for_item(conn, &item_id, &manifest_id))
}
/// The passkeys for a relying party, narrowed to an account when a user name or handle is given.
pub fn get_passkeys_for_rp_id(&self, rp_id: String, user_name: Option<String>, user_handle: Option<Vec<u8>>) -> Result<Vec<vault_items::VaultPasskeyWithItem>, VaultError> {
self.inner.with_connection(|conn| vault_items::get_passkeys_for_rp_id(conn, &rp_id, user_name.as_deref(), user_handle.as_deref()))
}
/// Every passkey whose item is live.
pub fn get_all_passkeys_with_items(&self) -> Result<Vec<vault_items::VaultPasskeyWithItem>, VaultError> {
self.inner.with_connection(vault_items::get_all_passkeys_with_items)
}
/// The Login items without a passkey that match a relying party, best match first.
pub fn get_items_without_passkey_for_rp_id(&self, rp_id: String, rp_name: Option<String>, user_name: Option<String>) -> Result<Vec<vault_items::PasskeyMergeCandidate>, VaultError> {
self.inner.with_connection(|conn| vault_items::get_items_without_passkey_for_rp_id(conn, &rp_id, rp_name.as_deref(), user_name.as_deref()))
}
/// Create a Login item in a manifest that holds a new passkey, with its URL, username and favicon.
#[allow(clippy::too_many_arguments)]
pub fn create_item_with_passkey(
&self,
manifest_id: String,
item_id: String,
item_name: String,
url: String,
user_name: Option<String>,
passkey: vault_items::NewPasskey,
logo: Option<Vec<u8>>,
) -> Result<(), VaultError> {
self.inner.with_connection(|conn| vault_items::create_item_with_passkey(conn, &manifest_id, &item_id, &item_name, &url, user_name.as_deref(), &passkey, logo.as_deref()))
}
/// Add a new passkey to an existing item, refreshing its favicon for `url`.
pub fn add_passkey_to_item(&self, item_id: String, manifest_id: String, passkey: vault_items::NewPasskey, url: String, logo: Option<Vec<u8>>) -> Result<(), VaultError> {
self.inner.with_connection(|conn| vault_items::add_passkey_to_item(conn, &item_id, &manifest_id, &passkey, &url, logo.as_deref()))
}
/// Replace a passkey with a new one on the same item and return the item id.
pub fn replace_passkey(&self, old_passkey_id: String, manifest_id: String, passkey: vault_items::NewPasskey, url: String, logo: Option<Vec<u8>>) -> Result<String, VaultError> {
self.inner.with_connection(|conn| vault_items::replace_passkey(conn, &old_passkey_id, &manifest_id, &passkey, &url, logo.as_deref()))
}
/// Record one use of an item by this device; false when the item does not exist.
pub fn record_item_use(&self, item_id: String, manifest_id: String, device_id: String, action: vault_items::ItemUsageAction) -> Result<bool, VaultError> {
self.inner.with_connection(|conn| vault_items::record_item_use(conn, &item_id, &manifest_id, &device_id, action))
}
}
/// The first passkey algorithm (COSE id) in the relying party's order that the authenticator supports; ES256 for an empty list.
#[uniffi::export]
pub fn passkey_pick_algorithm(requested: Vec<i64>) -> Result<i64, VaultError> {
crate::passkey::pick_algorithm(&requested)
}
/// Create a passkey: a fresh key pair, the "none" attestation object, and a PRF secret when `enable_prf` is set.
#[uniffi::export]
pub fn passkey_create(
credential_id: Vec<u8>,
rp_id: String,
algorithm: i64,
uv_performed: bool,
enable_prf: bool,
prf_inputs: Option<crate::passkey::PasskeyPrfInputs>,
) -> Result<crate::passkey::PasskeyCreation, VaultError> {
crate::passkey::create_passkey(&credential_id, &rp_id, algorithm, uv_performed, enable_prf, prf_inputs.as_ref(), None)
}
/// Sign a passkey assertion with a stored private key JWK.
#[uniffi::export]
pub fn passkey_get_assertion(
rp_id: String,
client_data_hash: Vec<u8>,
private_key_jwk: String,
uv_performed: bool,
prf_inputs: Option<crate::passkey::PasskeyPrfInputs>,
prf_secret: Option<Vec<u8>>,
) -> Result<crate::passkey::PasskeyAssertion, VaultError> {
crate::passkey::get_assertion(&rp_id, &client_data_hash, &private_key_jwk, uv_performed, prf_inputs.as_ref(), prf_secret.as_deref())
}
/// The 16 bytes of a passkey credential id from its GUID text.
#[uniffi::export]
pub fn passkey_guid_to_bytes(guid: String) -> Result<Vec<u8>, VaultError> {
crate::passkey::guid_to_bytes(&guid)
}
/// The lowercase GUID text of a 16-byte passkey credential id.
#[uniffi::export]
pub fn passkey_bytes_to_guid(bytes: Vec<u8>) -> Result<String, VaultError> {
crate::passkey::bytes_to_guid(&bytes)
}