Skip to content

feat(sdk): host apps can prepare an identity's shielded account - #5967

Closed
QuantumExplorer wants to merge 4 commits into
v5.1-devfrom
claude/shielded-identity-account-hosts
Closed

QuantumExplorer wants to merge 4 commits into
v5.1-devfrom
claude/shielded-identity-account-hosts

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

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]) in shielded_sync.rs, next to the shielded bind.
    • It resolves the seed through the mnemonic resolver, the same way the bind does, and calls PlatformWallet::prepare_shielded_identity_address.
    • out_address is zeroed on entry and written only on success.
    • An unknown identity stays 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, is ErrorWalletOperation with 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 as ErrorWalletOperation, 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)

  • JNI 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.
    • It applies the checks bindShielded applies and counts as a native operation, so a shutdown waits for it.
    • It refreshes the local balance counters afterwards as a bind does, because the preparation can add an account to the bound set.
  • A README section for the call.

Example, a host that wants its contact requests to carry an address:

before: bindShielded(walletId, resolver, accounts: [0])
        sendContactRequest(...)            -> no encryptedShieldedAddress
after : bindShielded(walletId, resolver, accounts: [0])
        prepareShieldedIdentityAddress(walletId, identityId, resolver)
        sendContactRequest(...)            -> carries encryptedShieldedAddress

How Has This Been Tested?

New Rust tests in shielded_sync::identity_account_tests and runtime:

  • a bound wallet whose identity carries the seed's master key: the export returns the identity account's default address, the wallet reports the account as prepared, and the bound accounts are account 0 and the identity's account;
  • an unknown identity is refused with ErrorIdentityNotFound and the address stays zeroed;
  • a call from inside a runtime, which makes the native code panic, comes back as a retryable error with the address zeroed;
  • a second preparation returns the same address and leaves the bound accounts as they were;
  • a wallet whose shielded side is not bound is refused with ErrorWalletOperation and a zeroed address;
  • a null argument and an invalid manager handle leave the address zeroed;
  • catch_query_panic passes 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 crate
  • cargo check -p platform-wallet-ffi (without shielded), cargo check -p rs-unified-sdk-jni --tests, and cargo check -p rs-unified-sdk-jni --no-default-features
  • Kotlin: ./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:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw

thepastaclaw commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit ed17c18. Normal review starts when eligible; priority review starts as soon as a slot is available.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: critical by gpt-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); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-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; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-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.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 17, 2026
@QuantumExplorer

Copy link
Copy Markdown
Member Author

/self-reviewed

@github-actions

Copy link
Copy Markdown
Contributor

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.
Full checklist in the description.

@github-actions github-actions Bot added too-many-open-prs Beyond the author's 5 open PRs; waits for one to merge before a human is asked. and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 17, 2026
…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]>
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed too-many-open-prs Beyond the author's 5 open PRs; waits for one to merge before a human is asked. labels Nov 17, 2026
@QuantumExplorer
QuantumExplorer marked this pull request as draft November 17, 2026 17:18
@github-actions github-actions Bot removed the waiting-bots Waiting for the review bots to report on this head label Nov 17, 2026
…dentity-account-hosts

# Conflicts:
#	packages/rs-platform-wallet-ffi/src/shielded_sync.rs
@QuantumExplorer

Copy link
Copy Markdown
Member Author

Closing: these six files landed on v5.1-dev with #6094 (3b4117c), which had this branch merged in. Merging this branch into v5.1-dev now changes nothing.

🤖 Posted by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants