Skip to content
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
java-version: 17

- name: Setup Android SDK + NDK
uses: android-actions/setup-android@v3
uses: android-actions/setup-android@v4

- name: Install Android NDK
run: sdkmanager "ndk;27.0.12077973"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-kotlin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
java-version: 17

- name: Setup Android SDK + NDK
uses: android-actions/setup-android@v3
uses: android-actions/setup-android@v4
- run: sdkmanager "ndk;27.0.12077973"

- name: Install cargo-ndk
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-react-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
java-version: 17

- name: Setup Android SDK + pinned NDK 27.0.12077973 (parity with release-kotlin.yml)
uses: android-actions/setup-android@v3
uses: android-actions/setup-android@v4
- run: sdkmanager "ndk;$ANDROID_NDK_VERSION"

- name: Wire ANDROID_NDK_HOME + install cargo-ndk
Expand Down
49 changes: 48 additions & 1 deletion crates/clear-signing/src/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,25 @@ fn render_typed_fields<'a>(
{
continue;
}
// Each element of a calldata array is its own nested call.
if matches!(format.as_ref(), Some(FieldFormat::Calldata)) {
let entry = render_typed_calldata_field(
descriptor,
message,
&val,
item_params.as_ref(),
label,
container,
data_provider,
descriptors,
depth,
warnings,
nested_fallback,
)
.await?;
entries.push(entry);
continue;
}
let formatted = format_typed_value(
descriptor,
&val,
Expand Down Expand Up @@ -2072,7 +2091,8 @@ async fn format_typed_value(
return Ok(format!("{} #{}", name, token_id));
}
}
Ok(format!("#{}", token_id))
// ERC-7730 `nftName` falls back to the raw token ID.
Ok(token_id)
}
FieldFormat::Calldata => {
// Should not reach here — calldata is intercepted in render_typed_fields
Expand Down Expand Up @@ -2203,6 +2223,33 @@ async fn resolve_and_format_typed_interpolation(
) -> Result<String, Error> {
let field = resolve_interpolation_field_spec(fields, excluded, path)?;

// One element of an array field (`x.[2].y` for `x.[].y`): format that
// element like field rendering does (parity with the calldata path).
if let Some(i) = field.element_index {
let element_path = field.path.replacen(".[]", &format!(".[{i}]"), 1);
let value =
resolve_typed_path_in_context(message, &element_path, container)?.ok_or_else(|| {
Error::Descriptor(format!(
"interpolatedIntent path '{}' could not be resolved from typed data",
path
))
})?;
let item_params = crate::engine::index_array_params(field.params, i);
let mut warnings = Vec::new();
return format_typed_value(
descriptor,
&Some(value),
field.format,
item_params.as_ref(),
container,
message,
None,
data_provider,
&mut warnings,
)
.await;
}

// Array-iteration paths (`.[]`) format each element like field rendering and
// join with " and " (parity with the calldata path).
if let Some((base, rest)) = crate::engine::split_array_iter_path(field.path) {
Expand Down
105 changes: 94 additions & 11 deletions crates/clear-signing/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,20 @@ fn render_fields<'a>(
{
continue;
}
// Each element of a calldata array is its own nested call.
if matches!(format.as_ref(), Some(FieldFormat::Calldata)) {
let entry = render_calldata_field(
ctx,
&val,
item_params.as_ref(),
label,
warnings,
nested_fallback,
)
.await?;
entries.push(entry);
continue;
}
let formatted = format_value(
ctx,
&val,
Expand Down Expand Up @@ -736,18 +750,25 @@ pub(crate) fn expand_display_fields(
DisplayField::Reference {
reference,
path,
label: ref_label,
params: ref_params,
encryption: ref_encryption,
visible,
} => {
if let Some(resolved) = resolve_reference(descriptor, reference) {
let merged = merge_ref_with_definition(
let mut merged = merge_ref_with_definition(
resolved,
path,
ref_params,
ref_encryption,
visible,
);
// The reference label overrides the definition label.
if let (Some(ref_label), DisplayField::Simple { label, .. }) =
(ref_label, &mut merged)
{
label.clone_from(ref_label);
}
expanded.extend(expand_display_fields(descriptor, &[merged], warnings));
} else {
warnings.push(render_warning(
Expand Down Expand Up @@ -836,12 +857,14 @@ pub fn prepend_scope_path(field: &DisplayField, scope: &str) -> DisplayField {
DisplayField::Reference {
reference,
path,
label,
params,
encryption,
visible,
} => DisplayField::Reference {
reference: reference.clone(),
path: Some(prepend_path(scope, path.as_deref())),
label: label.clone(),
params: params.as_ref().map(|p| prepend_params(scope, p)),
encryption: encryption.clone(),
visible: visible.clone(),
Expand Down Expand Up @@ -1177,20 +1200,32 @@ pub(crate) fn split_array_iter_path(path: &str) -> Option<(&str, &str)> {
Some((base, rest))
}

/// Scope the element-relative `tokenPath` to the array element being rendered
/// by rewriting its first `.[]` to a concrete index, so `tokenPath`
/// Scope the element-relative path params to the array element being
/// rendered by rewriting their first `.[]` to a concrete index, so `tokenPath`
/// `details.[].token` resolves to `details.[index].token` for element `index`.
/// No-op when `tokenPath` is absent or has no `.[]`. Only `tokenPath` is
/// rewritten; other element-relative path params (`calleePath`, `amountPath`,
/// `spenderPath`) are not scoped here. Shared by the calldata and EIP-712 flat
/// array-iteration paths (field rendering + interpolation).
/// Applies to `tokenPath`, `chainIdPath`, `selectorPath`, `calleePath`,
/// `amountPath`, `spenderPath` and `collectionPath`. A path without `.[]`
/// stays unchanged. Shared by the calldata and EIP-712 flat array-iteration
/// paths (field rendering + interpolation).
pub(crate) fn index_array_params(
params: Option<&FormatParams>,
index: usize,
) -> Option<FormatParams> {
let mut params = params.cloned()?;
if let Some(token_path) = params.token_path.as_ref() {
params.token_path = Some(token_path.replacen(".[]", &format!(".[{index}]"), 1));
let indexed = format!(".[{index}]");
for path in [
&mut params.token_path,
&mut params.chain_id_path,
&mut params.selector_path,
&mut params.callee_path,
&mut params.amount_path,
&mut params.spender_path,
&mut params.collection_path,
]
.into_iter()
.flatten()
{
*path = path.replacen(".[]", &indexed, 1);
}
Some(params)
}
Expand Down Expand Up @@ -2394,7 +2429,8 @@ fn resolve_map(ctx: &RenderContext<'_>, map_ref: &str, val: &ArgumentValue) -> O
lookup_map_entry(ctx.descriptor, map_ref, &key)
}

/// Format an NFT name: "{collection_name} #{token_id}" or "#{token_id}" fallback.
/// Format an NFT name: "{collection_name} #{token_id}", or the raw token ID
/// when the collection is not found (ERC-7730 `nftName` fallback).
async fn format_nft_name(
ctx: &RenderContext<'_>,
val: &ArgumentValue,
Expand Down Expand Up @@ -2450,7 +2486,7 @@ async fn format_nft_name(
label, collection_addr
),
));
Ok(format!("#{}", token_id))
Ok(token_id)
}
}

Expand Down Expand Up @@ -2554,6 +2590,31 @@ async fn resolve_and_format_for_interpolation(
) -> Result<String, Error> {
let field = resolve_interpolation_field_spec(fields, excluded, path)?;

// One element of an array field (`x.[2].y` for `x.[].y`): format that
// element like field rendering does.
if let Some(i) = field.element_index {
let element_path = field.path.replacen(".[]", &format!(".[{i}]"), 1);
let value = resolve_path(ctx.decoded, &element_path).ok_or_else(|| {
Error::Descriptor(format!(
"interpolatedIntent path '{}' could not be resolved from calldata",
path
))
})?;
let item_params = index_array_params(field.params, i);
let mut warnings = RenderDiagnostics::new();
return format_value(
ctx,
&Some(value),
field.format,
item_params.as_ref(),
field.path,
field.label,
field.separator,
&mut warnings,
)
.await;
}

// Array-iteration paths (`.[]`) format each element like field rendering and
// join with " and "; a scalar `resolve_path` returns None for `.[]`, which
// would otherwise drop the whole interpolatedIntent.
Expand Down Expand Up @@ -2631,6 +2692,28 @@ mod tests {
enums
}

#[test]
fn test_index_array_params_scopes_all_element_paths() {
let params: FormatParams = serde_json::from_value(serde_json::json!({
"tokenPath": "items.[].token",
"calleePath": "calls.[].target",
"amountPath": "calls.[].value",
"spenderPath": "calls.[].spender",
"selectorPath": "calls.[].selector",
"chainIdPath": "calls.[].chainId",
"collectionPath": "collections.[]"
}))
.unwrap();
let indexed = index_array_params(Some(&params), 2).unwrap();
assert_eq!(indexed.token_path.as_deref(), Some("items.[2].token"));
assert_eq!(indexed.callee_path.as_deref(), Some("calls.[2].target"));
assert_eq!(indexed.amount_path.as_deref(), Some("calls.[2].value"));
assert_eq!(indexed.spender_path.as_deref(), Some("calls.[2].spender"));
assert_eq!(indexed.selector_path.as_deref(), Some("calls.[2].selector"));
assert_eq!(indexed.chain_id_path.as_deref(), Some("calls.[2].chainId"));
assert_eq!(indexed.collection_path.as_deref(), Some("collections.[2]"));
}

#[test]
fn enum_lookup_matches_bool_keys_case_insensitively() {
let params = FormatParams {
Expand Down
1 change: 1 addition & 0 deletions crates/clear-signing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod encryption;
pub mod engine;
pub mod error;
pub mod merge;
mod native_currencies;
pub mod outcome;
mod path;
pub mod provider;
Expand Down
Loading
Loading