Skip to content
Open
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
207 changes: 110 additions & 97 deletions CredentialProvider/wasm/matcher-rs/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,154 +1,167 @@
use std::os::raw::{c_char, c_void};
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 ( disputes );
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#[repr(C)]
pub struct CallingAppInfo {
pub package_name: [u8; 256],
pub origin: [u8; 512],
}
//! Raw C foreign function interface (FFI) bindings imported from the host.

#[link(wasm_import_module = "credman")]
unsafe extern "C" {
pub fn AddEntry(
cred_id: i64,
icon: *const c_char,
icon_len: usize,
use std::os::raw::c_char;

extern "C" {
/// Adds a candidate entry to a set inside the matched presentation entry sets.
pub fn SetDelegationTypeForEntryInSet(
cred_id: *const c_char,
delegation_type: i32,
set_id: *const c_char,
set_index: i32,
);

/// Logs an informational message using the host environment's logger.
pub fn LogInfo(msg: *const c_char);

/// Logs a warning message using the host environment's logger.
pub fn LogWarning(msg: *const c_char);

/// Logs an error message using the host environment's logger.
pub fn LogError(msg: *const c_char);

/// Sets the status of the match result.
pub fn SetStatus(status: i32);

/// Sets the selection metadata JSON on the host environment's match result.
pub fn SetSelectionMetadata(metadata: *const c_char);

/// Sets the error message on the host environment's match result.
pub fn SetErrorMessage(error_message: *const c_char);

/// Adds a standard matched entry to the match result on the host environment.
pub fn AddStandardEntry(
provider_id: *const c_char,
entry_key: *const c_char,
title: *const c_char,
subtitle: *const c_char,
disclaimer: *const c_char,
warning: *const c_char,
metadata: *const c_char,
);
pub fn AddField(
cred_id: i64,
field_display_name: *const c_char,
field_display_value: *const c_char,
);
pub fn AddEntrySet(set_id: *const c_char, set_length: i32);
pub fn AddEntryToSet(
cred_id: *const c_char,
icon: *const c_char,
icon_len: usize,

/// Adds an inline issuance entry to the match result on the host environment.
pub fn AddInlineIssuanceEntry(
provider_id: *const c_char,
entry_key: *const c_char,
title: *const c_char,
subtitle: *const c_char,
disclaimer: *const c_char,
warning: *const c_char,
metadata: *const c_char,
set_id: *const c_char,
set_index: i32,
);
pub fn AddFieldToEntrySet(
cred_id: *const c_char,
field_display_name: *const c_char,
field_display_value: *const c_char,
set_id: *const c_char,
set_index: i32,
);
pub fn AddPaymentEntryToSet(

/// Creates a new entry set inside the matched presentation entry sets.
pub fn CreateEntrySet(set_id: *const c_char);

/// Adds a candidate entry to a set inside the matched presentation entry sets.
pub fn AddEntryToSet(
provider_id: *const c_char,
cred_id: *const c_char,
merchant_name: *const c_char,
payment_method_name: *const c_char,
payment_method_subtitle: *const c_char,
payment_method_icon: *const c_char,
payment_method_icon_len: usize,
transaction_amount: *const c_char,
bank_icon: *const c_char,
bank_icon_len: usize,
payment_provider_icon: *const c_char,
payment_provider_icon_len: usize,
entry_key: *const c_char,
title: *const c_char,
subtitle: *const c_char,
disclaimer: *const c_char,
warning: *const c_char,
metadata: *const c_char,
set_id: *const c_char,
set_index: i32,
);
pub fn AddPaymentEntryToSetV2(
cred_id: *const c_char,
merchant_name: *const c_char,
payment_method_name: *const c_char,
payment_method_subtitle: *const c_char,
payment_method_icon: *const c_char,
payment_method_icon_len: usize,
transaction_amount: *const c_char,
bank_icon: *const c_char,
bank_icon_len: usize,
payment_provider_icon: *const c_char,
payment_provider_icon_len: usize,
additional_info: *const c_char,
metadata: *const c_char,
set_id: *const c_char,
set_index: i32,

/// Self declares host package info display name and icon bytes.
pub fn SelfDeclarePackageInfo(
package_display_name: *const c_char,
package_icon_bytes: *const c_char,
package_icon_len: usize,
);

/// Adds string ID entry.
pub fn AddStringIdEntry(
cred_id: *const c_char,
icon: *const c_char,
icon_bytes: *const c_char,
icon_len: usize,
title: *const c_char,
subtitle: *const c_char,
disclaimer: *const c_char,
warning: *const c_char,
);

/// Adds issuance entry.
pub fn AddIssuanceEntry(
cred_id: *const c_char,
icon: *const c_char,
icon_bytes: *const c_char,
icon_len: usize,
title: *const c_char,
subtitle: *const c_char,
explainer: *const c_char,
metadata: *const c_char,
);
pub fn AddFieldForStringIdEntry(

/// Adds an entry set with set_id and total set_length.
pub fn AddEntrySet(set_id: *const c_char, set_length: i32);

/// Adds field name and value to a set.
pub fn AddFieldToEntrySet(
cred_id: *const c_char,
field_display_name: *const c_char,
field_display_value: *const c_char,
set_id: *const c_char,
set_index: i32,
);
pub fn GetRequestBuffer(buffer: *mut c_void);
pub fn GetRequestSize(size: *mut u32);
pub fn ReadCredentialsBuffer(buffer: *mut c_void, offset: usize, len: usize) -> usize;
pub fn GetCredentialsSize(size: *mut u32);
pub fn GetWasmVersion(version: *mut u32);
pub fn AddPaymentEntry(

/// Adds payment entry to set (V2).
pub fn AddPaymentEntryToSetV2(
cred_id: *const c_char,
merchant_name: *const c_char,
payment_method_name: *const c_char,
payment_method_subtitle: *const c_char,
payment_method_icon: *const c_char,
payment_method_icon_bytes: *const c_char,
payment_method_icon_len: usize,
transaction_amount: *const c_char,
bank_icon: *const c_char,
bank_icon_bytes: *const c_char,
bank_icon_len: usize,
payment_provider_icon: *const c_char,
payment_provider_icon_bytes: *const c_char,
payment_provider_icon_len: usize,
);
pub fn AddInlineIssuanceEntry(
cred_id: *const c_char,
icon: *const c_char,
icon_len: usize,
title: *const c_char,
subtitle: *const c_char,
);
pub fn SetAdditionalDisclaimerAndUrlForVerificationEntry(
cred_id: *const c_char,
secondary_disclaimer: *const c_char,
url_display_text: *const c_char,
url_value: *const c_char,
);
pub fn SetAdditionalDisclaimerAndUrlForVerificationEntryInCredentialSet(
cred_id: *const c_char,
secondary_disclaimer: *const c_char,
url_display_text: *const c_char,
url_value: *const c_char,
additional_info: *const c_char,
metadata: *const c_char,
set_id: *const c_char,
set_index: i32,
);
pub fn GetCallingAppInfo(info: *mut CallingAppInfo);
pub fn SelfDeclarePackageInfo(
package_display_name: *const c_char,
package_icon: *const c_char,
package_icon_len: usize,
);

/// Adds metadata display text to an entry set.
pub fn AddMetadataDisplayTextToEntrySet(
cred_id: *const c_char,
metadata_display_text: *const c_char,
set_id: *const c_char,
set_index: i32,
);
pub fn fd_write(fd: i32, iovs_ptr: *const c_void, iovs_len: i32, nwritten_ptr: *mut i32)
-> i32;

/// Gets request size in bytes.
pub fn GetRequestSize(size: *mut u32);

/// Fills request buffer.
pub fn GetRequestBuffer(buffer: *mut c_void);

/// Gets registered credentials size in bytes.
pub fn GetCredentialsSize(size: *mut u32);

/// Reads credentials buffer.
pub fn ReadCredentialsBuffer(buffer: *mut c_void, offset: usize, len: usize);

/// Gets WASM version.
pub fn GetWasmVersion(version: *mut u32);
}
68 changes: 67 additions & 1 deletion CredentialProvider/wasm/matcher-rs/src/credman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{ffi::CString, os::raw::c_void};
use crate::bindings::{
AddEntrySet, AddEntryToSet, AddFieldToEntrySet, AddInlineIssuanceEntry, AddIssuanceEntry,
AddMetadataDisplayTextToEntrySet, AddPaymentEntryToSetV2, AddStringIdEntry, GetCredentialsSize,
GetRequestBuffer, GetRequestSize, GetWasmVersion, ReadCredentialsBuffer,
GetRequestBuffer, GetRequestSize, GetWasmVersion, ReadCredentialsBuffer, SelfDeclarePackageInfo,
};

pub trait CredmanApi {
Expand Down Expand Up @@ -40,6 +40,14 @@ pub trait CredmanApi {
metadata: &str,
set_id: &str,
set_index: i32,
delegation_type: i32,
);
fn set_delegation_type_for_entry_in_set(
&mut self,
cred_id: &str,
delegation_type: i32,
set_id: &str,
set_index: i32,
);
fn add_field_to_entry_set(
&mut self,
Expand Down Expand Up @@ -78,6 +86,11 @@ pub trait CredmanApi {
set_id: &str,
set_index: i32,
);
fn self_declare_package_info(
&mut self,
package_display_name: &str,
package_icon: &[u8],
);
}

pub struct CredmanApiImpl;
Expand Down Expand Up @@ -233,6 +246,7 @@ impl CredmanApi for CredmanApiImpl {
metadata: &str,
set_id: &str,
set_index: i32,
delegation_type: i32,
) {
let cred_id_c = CString::new(cred_id).unwrap();
let title_c = if title.is_empty() {
Expand Down Expand Up @@ -284,6 +298,32 @@ impl CredmanApi for CredmanApiImpl {
set_id_c.as_ptr(),
set_index,
);
if delegation_type != 0 {
crate::bindings::SetDelegationTypeForEntryInSet(
cred_id_c.as_ptr(),
delegation_type,
set_id_c.as_ptr(),
set_index,
);
}
}
}
fn set_delegation_type_for_entry_in_set(
&mut self,
cred_id: &str,
delegation_type: i32,
set_id: &str,
set_index: i32,
) {
let cred_id_c = CString::new(cred_id).unwrap();
let set_id_c = CString::new(set_id).unwrap();
unsafe {
crate::bindings::SetDelegationTypeForEntryInSet(
cred_id_c.as_ptr(),
delegation_type,
set_id_c.as_ptr(),
set_index,
);
}
}
fn add_field_to_entry_set(
Expand Down Expand Up @@ -468,4 +508,30 @@ impl CredmanApi for CredmanApiImpl {
);
}
}
fn self_declare_package_info(
&mut self,
package_display_name: &str,
package_icon: &[u8],
) {
let package_display_name_c = if package_display_name.is_empty() {
None
} else {
Some(CString::new(package_display_name).unwrap())
};

let icon_bytes = if package_icon.is_empty() {
std::ptr::null()
} else {
package_icon.as_ptr()
} as *const std::os::raw::c_char;
let icon_length = package_icon.len();

unsafe {
SelfDeclarePackageInfo(
package_display_name_c.as_ref().map_or(std::ptr::null(), |c| c.as_ptr()),
icon_bytes,
icon_length,
);
}
}
}
Loading