Repository navigation
feat(sdk): host apps can prepare an identity's shielded account - #5967
QuantumExplorer wants to merge 4 commits into
Conversation
The wallet prepares an identity's shielded account by proving the identity's slot with the seed (#5905), and a contact request carries the sender's per-contact shielded address only once that preparation stands (#5901, #5902). No host could ask for the preparation, so a request sent from iOS or Android never carried an address. platform_wallet_manager_prepare_shielded_identity_address resolves the seed through the mnemonic resolver, as the shielded bind does, and calls PlatformWallet::prepare_shielded_identity_address. It returns the account's default address, zeroes its output on entry and writes it only on success. A panic inside the call comes back as a retryable error (catch_query_panic): the call moves no funds. Swift and Kotlin wrap it on PlatformWalletManager, and JNI bridges it as FundingNative.prepareShieldedIdentityAddress. Taken from #5288, without its account index helpers and bound-account snapshot, which no host calls. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
🕓 Review not started yet because this PR is a draft.
Commit ed17c18. Normal review starts when eligible; priority review starts as soon as a slot is available. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The new export is correctly layered and protects output buffers and native lifetimes, but two API-contract issues remain. Non-identity preparation failures are flattened to ErrorUnknown instead of matching the existing shielded-operation mapping, and the documented panic-to-retry behavior cannot work in the iOS abort profiles. The CI snapshot has no failed code checks; several checks remain pending.
🟡 3 suggestion(s) | 💬 1 nitpick(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This is a substantial cross-platform FFI change that exposes seed-backed shielded-account preparation and therefore changes a key-handling surface across Rust, JNI/Kotlin, and Swift. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-platform-wallet-ffi/src/shielded_sync.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/shielded_sync.rs:575-585: Map preparation failures through the shielded-operation error helper
The new export converts every wallet error with `e.into()`. `IdentityNotFound` retains its dedicated code, but failures that this operation can actually return—such as `ShieldedNotBound` before binding, seed derivation failures, wallet removal, invalid identity data, and unset identity indexes—fall through the blanket conversion to `ErrorUnknown` (99). The neighboring `bind_shielded` path deliberately maps the same operational failures to `ErrorWalletOperation`, which gives hosts a consistent retryable error contract. Preserve the typed identity-not-found case, then route the remaining failures through `map_shielded_error`.
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/shielded_sync.rs:1890-1935: Exercise repeated preparation and the unbound error path
The new FFI tests cover one successful preparation and an unknown identity, but they do not call the export twice or invoke it after binding has been cleared or omitted. Those cases are part of the public contract documented for this export: repeated calls must remain idempotent, while an unbound wallet must produce the same retryable operational error as the bind path. A wrapper-level test for both paths would catch regressions in account merging and in the error mapping above.
In `packages/rs-platform-wallet-ffi/src/runtime.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/runtime.rs:107-115: Do not promise panic recovery for iOS abort-profile builds
`catch_query_panic` uses `catch_unwind`, but the workspace's `dev-ios` and `release-ios` profiles set `panic = "abort"` in `Cargo.toml` lines 86-98. In those builds, a panic from runtime resolution or the worker future terminates the iOS host before this helper can return `ErrorWalletOperation`, contrary to the export documentation and the stated retryable-error contract for Swift callers. Either use an unwind-capable iOS profile for this boundary, or explicitly scope the panic-recovery guarantee to profiles that unwind and document the abort behavior for Swift.
- [NITPICK] packages/rs-platform-wallet-ffi/src/runtime.rs:95-117: Keep shielded panic helpers with their shielded exports
`catch_query_panic` is specialized to the shielded identity-preparation operation and is only used from `shielded_sync.rs`, while the analogous spend and funding helpers live beside their exports in `shielded_send.rs`. Moving this helper next to the export would keep the generic runtime module independent of shielded-specific result semantics and keep the panic-mapping family together.
|
Bots are done — your move: post |
|
/self-reviewed |
|
Missing human approval. Automatic reviewer requests are paused and this PR is excluded from reviewers' queues. Merge, close, or draft another active PR by this author to free a review slot. Required human review can be satisfied without a slot; once all merge requirements are met, PR Hygiene passes. |
…s the bind does Every failure but an unknown identity reached the host as ErrorUnknown, including the ordinary one of a wallet whose shielded side is not bound yet. An unknown identity keeps its code and the rest goes through map_shielded_error, as the shielded bind's failures do: the two recovery codes stay typed and anything else is ErrorWalletOperation with the wallet's reason. The docs said a panic comes back as a retryable error. That holds only in builds that unwind. The iOS profiles abort on panic, and the docs now say so. catch_query_panic moves beside the export, its only user, so runtime.rs is as on v5.1-dev. Tests: a second preparation returns the same address and leaves the bound accounts as they were, and a wallet that is not bound is refused with ErrorWalletOperation and a zeroed address. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
…dentity-account-hosts # Conflicts: # packages/rs-platform-wallet-ffi/src/shielded_sync.rs
|
Closing: these six files landed on 🤖 Posted by Claude Code |
Basic explanation
What this does: iOS and Android apps can now ask the wallet to prepare an identity's private (shielded) account. Until now only Rust code could do that.
Value: Since #5901 and #5902 the wallet puts a per-contact shielded payment address into the contact requests it sends, but only after the sending identity's shielded account was prepared. No mobile app could trigger that step, so a contact request sent from a phone never carried an address. With this change it can.
Risks: Low. One new call on each platform, and nothing existing changes. The Swift wrapper was not compiled locally; CI's Swift build is its check. No example app calls it yet.
Issue being fixed or feature implemented
The wallet prepares an identity's shielded account by proving, with the seed, that the identity holds the slot the account belongs to (#5905). A contact request carries the sender's per-contact shielded address only once that preparation stands (#5901, #5902). The preparation had no export in the C interface, JNI, Swift or Kotlin.
This is taken from #5288, which carries the same export together with tip sending and profile addresses. It comes without #5288's account index helpers and bound-account snapshot: no host calls them.
What was done?
C interface (
packages/rs-platform-wallet-ffi)platform_wallet_manager_prepare_shielded_identity_address(handle, wallet_id, mnemonic_resolver, identity_id, out_address[43])inshielded_sync.rs, next to the shielded bind.PlatformWallet::prepare_shielded_identity_address.out_addressis zeroed on entry and written only on success.ErrorIdentityNotFound. Every other failure is reported as the shielded bind reports its own: the two recovery codes stay typed, and anything else, such as a wallet whose shielded side is not bound, isErrorWalletOperationwith the wallet's reason.catch_query_panic, beside the export: in builds that unwind (Android and the host tests) a panic inside the call comes back asErrorWalletOperation, which the host may retry. The iOS build profiles abort on panic, so there a panic ends the process.Android (
packages/rs-unified-sdk-jni,packages/kotlin-sdk)FundingNative.prepareShieldedIdentityAddress.PlatformWalletManager.prepareShieldedIdentityAddress(walletId, identityId): ByteArray, run behind the teardown gate with the manager's mnemonic resolver.iOS (
packages/swift-sdk)PlatformWalletManager.prepareShieldedIdentityAddress(walletId:identityId:resolver:) async throws -> Data.bindShieldedapplies and counts as a native operation, so a shutdown waits for it.Example, a host that wants its contact requests to carry an address:
How Has This Been Tested?
New Rust tests in
shielded_sync::identity_account_testsandruntime:ErrorIdentityNotFoundand the address stays zeroed;ErrorWalletOperationand a zeroed address;catch_query_panicpasses a normal result through and maps a panic.Run locally:
cargo test -p platform-wallet-ffi --features shielded --lib -- shielded_sync:: runtime::(24 passed)cargo clippy -p platform-wallet-ffi --features shielded --all-targets: no warnings in the cratecargo check -p platform-wallet-ffi(withoutshielded),cargo check -p rs-unified-sdk-jni --tests, andcargo check -p rs-unified-sdk-jni --no-default-features./gradlew :sdk:compileDebugKotlin(BUILD SUCCESSFUL)Not tested: the Swift wrapper was not compiled locally, the JNI function only compiles, and nothing was run on a device or in an example app.
Breaking Changes
None.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code