From 5a4b3df42457b27d6571b015dc54391ada28a598 Mon Sep 17 00:00:00 2001 From: Ever Morales Date: Sun, 8 Nov 2026 21:56:45 -0600 Subject: [PATCH] Show AP2 spending permissions in the consent prompt. A request carrying AP2 `delegate` transaction data asks the person to let an agent spend for them later, unattended. The SDK's consent prompt would show only a heading for it. The wallet now registers the type together with the SDK's default renderer for it, on Android and iOS: the prompt shows the spending limits set large, then the merchant, the items, the expiry and the agent, and "View details" lists every mandate in full, as AP2 requires. `addUtopiaTypes()` leaves the type out, so `App` and the iOS `ViewModel` add it with `addDelegateTransactionType()`, and pass `walletTransactionDataRenderers`, which holds `DelegateTransactionRendererCompose` on Android and `DelegateTransactionRendererSwiftUi` on iOS, to `promptModelRequestConsent()`. This needs those renderers and `addDelegateTransactionType()`, which are not in a Multipaz release or snapshot yet. They are on the SDK branch feat/ap2-delegate-renderer, on top of feat/ap2-delegate-transaction-utopia. Test: ./gradlew :androidApp:testDebugUnitTest (38 tests, including WalletTransactionDataRenderersTest), :androidApp:assembleDebug and :androidApp:lintDebug, against that SDK branch published to mavenLocal as 0.103.0-SNAPSHOT. On iOS, the registration was type-checked with swiftc against the Multipaz framework built from that branch. The iOS app was not built: this host has Xcode 27.2, and Multipaz needs the iOS 27.3 SDK. Signed-off-by: Ever Morales Co-Authored-By: Claude Opus 5.5 --- .../java/org/multipaz/wallet/android/App.kt | 8 +++++++- .../WalletTransactionDataRenderers.kt | 16 ++++++++++++++++ .../WalletTransactionDataRenderersTest.kt | 19 +++++++++++++++++++ iosApp/iosApp/ViewModel.swift | 6 +++++- .../WalletTransactionDataRenderers.swift | 15 +++++++++++++++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 androidApp/src/main/java/org/multipaz/wallet/android/ui/presentment/WalletTransactionDataRenderers.kt create mode 100644 androidApp/src/test/java/org/multipaz/wallet/android/ui/presentment/WalletTransactionDataRenderersTest.kt create mode 100644 iosApp/iosApp/WalletTransactionDataRenderers.swift diff --git a/androidApp/src/main/java/org/multipaz/wallet/android/App.kt b/androidApp/src/main/java/org/multipaz/wallet/android/App.kt index 0ed267e..c1a3812 100644 --- a/androidApp/src/main/java/org/multipaz/wallet/android/App.kt +++ b/androidApp/src/main/java/org/multipaz/wallet/android/App.kt @@ -85,6 +85,7 @@ import org.multipaz.trustmanagement.TrustManager import org.multipaz.trustmanagement.TrustMetadata import org.multipaz.util.Logger import org.multipaz.util.Platform +import org.multipaz.utopia.knowntypes.addDelegateTransactionType import org.multipaz.utopia.knowntypes.addUtopiaTypes import org.multipaz.wallet.android.navigation.AppNavHost import org.multipaz.wallet.android.navigation.Destination @@ -93,6 +94,7 @@ import org.multipaz.wallet.android.navigation.ProvisioningNavHost import org.multipaz.wallet.android.navigation.VerificationShowResponseDestination import org.multipaz.wallet.android.navigation.WalletDestination import org.multipaz.wallet.android.ui.CommunicatingWithBackendDialog +import org.multipaz.wallet.android.ui.presentment.walletTransactionDataRenderers import org.multipaz.wallet.android.settings.SettingsModel import org.multipaz.wallet.client.WalletClient import org.multipaz.wallet.client.clearOnSignOut @@ -206,6 +208,9 @@ class App private constructor() { documentTypeRepository = DocumentTypeRepository() documentTypeRepository.addKnownTypes() documentTypeRepository.addUtopiaTypes() + // Not part of the utopia types: it is only registered alongside the renderer that shows + // the mandate (walletTransactionDataRenderers). + documentTypeRepository.addDelegateTransactionType() documentStore = buildDocumentStore(storage = storage, secureAreaRepository = secureAreaRepository) {} documentModel = DocumentModel.create( documentStore = documentStore, @@ -491,7 +496,8 @@ class App private constructor() { trustedRequesterIdentity = trustedRequesterIdentity, presentmentData = presentmentData, preselectedDocuments = preselectedDocuments, - onDocumentsInFocus = onDocumentsInFocus + onDocumentsInFocus = onDocumentsInFocus, + transactionDataRendererRepository = walletTransactionDataRenderers, ) } diff --git a/androidApp/src/main/java/org/multipaz/wallet/android/ui/presentment/WalletTransactionDataRenderers.kt b/androidApp/src/main/java/org/multipaz/wallet/android/ui/presentment/WalletTransactionDataRenderers.kt new file mode 100644 index 0000000..d69bbd8 --- /dev/null +++ b/androidApp/src/main/java/org/multipaz/wallet/android/ui/presentment/WalletTransactionDataRenderers.kt @@ -0,0 +1,16 @@ +package org.multipaz.wallet.android.ui.presentment + +import org.multipaz.compose.presentment.DelegateTransactionRendererCompose +import org.multipaz.prompt.TransactionDataRendererRepository +import org.multipaz.utopia.knowntypes.DelegateTransaction + +/** + * The wallet's renderers for transaction data in the consent prompt. + * + * A [DelegateTransaction] is drawn by the SDK's [DelegateTransactionRendererCompose], as a + * spending permission. Transaction types without a renderer here keep the consent prompt's + * built-in rendering. + */ +val walletTransactionDataRenderers = TransactionDataRendererRepository().apply { + addRenderer(DelegateTransaction.identifier, DelegateTransactionRendererCompose) +} diff --git a/androidApp/src/test/java/org/multipaz/wallet/android/ui/presentment/WalletTransactionDataRenderersTest.kt b/androidApp/src/test/java/org/multipaz/wallet/android/ui/presentment/WalletTransactionDataRenderersTest.kt new file mode 100644 index 0000000..90bd32b --- /dev/null +++ b/androidApp/src/test/java/org/multipaz/wallet/android/ui/presentment/WalletTransactionDataRenderersTest.kt @@ -0,0 +1,19 @@ +package org.multipaz.wallet.android.ui.presentment + +import org.junit.Assert.assertSame +import org.junit.Test +import org.multipaz.compose.presentment.DelegateTransactionRendererCompose +import org.multipaz.utopia.knowntypes.DelegateTransaction + +class WalletTransactionDataRenderersTest { + + // AP2 requires the signed Mandate Content to be shown, so `delegate` must not fall back to the + // consent prompt's built-in rendering, which shows only a heading for it. + @Test + fun delegateIsDrawnByTheSdkRenderer() { + assertSame( + DelegateTransactionRendererCompose, + walletTransactionDataRenderers.getRenderer(DelegateTransaction.identifier) + ) + } +} diff --git a/iosApp/iosApp/ViewModel.swift b/iosApp/iosApp/ViewModel.swift index 57086d2..b38b2ff 100644 --- a/iosApp/iosApp/ViewModel.swift +++ b/iosApp/iosApp/ViewModel.swift @@ -141,6 +141,9 @@ class ViewModel { documentTypeRepository = DocumentTypeRepository() documentTypeRepository.addKnownTypes(locale: currentLocale) documentTypeRepository.addUtopiaTypes(locale: currentLocale) + // Not part of the utopia types: it is only registered alongside the renderer that shows + // the mandate (walletTransactionDataRenderers). + documentTypeRepository.addDelegateTransactionType() documentStore = DocumentStore.Builder( storage: storage, secureAreaRepository: secureAreaRepository @@ -489,7 +492,8 @@ class ViewModel { preselectedDocuments: preselectedDocuments, onDocumentsInFocus: { documents in onDocumentsInFocus(documents) - } + }, + transactionDataRendererRepository: walletTransactionDataRenderers ) }, getFaceMatchingModeFn: { credential, requesterIdentities in diff --git a/iosApp/iosApp/WalletTransactionDataRenderers.swift b/iosApp/iosApp/WalletTransactionDataRenderers.swift new file mode 100644 index 0000000..7c8b06e --- /dev/null +++ b/iosApp/iosApp/WalletTransactionDataRenderers.swift @@ -0,0 +1,15 @@ +import Multipaz + +/// The wallet's renderers for transaction data in the consent prompt. +/// +/// A `DelegateTransaction` is drawn by the SDK's `DelegateTransactionRendererSwiftUi`, as a +/// spending permission. Transaction types without a renderer here keep the consent prompt's +/// built-in rendering. +let walletTransactionDataRenderers: TransactionDataRendererRepository = { + let repository = TransactionDataRendererRepository() + repository.addRenderer( + identifier: DelegateTransaction.shared.identifier, + renderer: DelegateTransactionRendererSwiftUi() + ) + return repository +}()