Skip to content

feat: decide which identity keys may be disabled in the wallet, not in the mobile apps - #5661

Draft
Claudius-Maginificent wants to merge 3 commits into
fix/platform-wallet-dip11-key-rulesfrom
fix/key-disable-gate-from-rust
Draft

Claudius-Maginificent wants to merge 3 commits into
fix/platform-wallet-dip11-key-rulesfrom
fix/key-disable-gate-from-rust

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #5644 — review and merge that first; this PR's base is its branch.

TL;DR

The Swift and Kotlin example apps decided on their own which identity keys may be disabled, and got it wrong in both directions. The wallet now decides it in Rust, with one function that both its identity-update calls and the apps' Disable Key button use.

User story

As a wallet user, I want the Disable Key button to be offered exactly when the wallet will actually let me disable that key, so that I am neither blocked from a safe change nor led into one the wallet then refuses.

Scenario

Actual behavior

  • The apps' KeyDisableGate counted enabled authentication keys by purpose. With a MASTER key and a HIGH key left, it offered to disable the only CRITICAL key; fix!: follow DIP-11 key rules when disabling keys and reading contact requests #5644's builder then refused the update with a generic error.
  • It refused to disable the only HIGH key even when a CRITICAL key stands in for it, which DIP-11 allows.
  • The last-transfer-key guard existed only in the apps: any other client of the wallet could disable the last transfer key and lose the ability to withdraw credits.

Expected behavior

  • Disable Key is offered exactly when an update that only disables that key would go through: another valid authentication key at the same level, or a stronger non-MASTER one, remains (DIP-11, as fix!: follow DIP-11 key rules when disabling keys and reading contact requests #5644 defines a valid key), and the identity keeps an enabled transfer key able to sign. An update that also adds a replacement key can pass where the verdict for a plain disable refuses.
  • A refusal says which rule applies: the security level, or the transfer key.
  • Every caller of the wallet's identity update gets the same refusals, before anything is fetched or signed.

Detailed discussion

Per the coding conventions, the FFI layers and the Swift and Kotlin SDKs marshal; they do not decide, and validation lives once.

  • Wallet policy (rs-platform-wallet). wallet::identity::state::key_disable::check_keys_can_be_disabled(identity, add_public_keys, disable_public_keys) is the single place this is decided. It applies dpp's DIP-11 predicate (fix!: follow DIP-11 key rules when disabling keys and reading contact requests #5644), then refuses disabling the last enabled TRANSFER key able to sign (CRITICAL level and a signing-capable key type per dpp's can_sign_state_transitions, HASH160 included): wallet policy, not a DIP rule or consensus (Platform accepts it), because without such a key the identity cannot withdraw or transfer credits. A TRANSFER key that cannot sign is neither counted nor protected. A key added in the same update counts as remaining. It returns KeyDisableRefusal::{LastAuthenticationKey(LastAuthenticationKeyError), LastEnabledKey(LastEnabledKeyError { key_id, purpose })}.
  • Signing-key selection is in feat(platform-wallet)!: expose protocol-14-aware signing-key selection #5588. The verdict counts an enabled key of a signing-capable type, including HASH160. The key picker that signs the update must match it by skipping disabled keys and accepting HASH160 keys, and feat(platform-wallet)!: expose protocol-14-aware signing-key selection #5588 delivers both. Until feat(platform-wallet)!: expose protocol-14-aware signing-key selection #5588 lands, a disabled key can still be picked, and a HASH160 MASTER key is not used for an identity update.
  • MASTER keys. Consensus refuses disabling a MASTER key without adding one in the same update, and adding one without disabling one, so the DIP-11 rule already refuses a plain disable of an identity's only MASTER key.
  • Cached identity. The verdict judges the wallet's cached identity, as the update does. Keys changed on another device are not seen until the cache is replaced; Platform then refuses the update on its revision.
  • No clock. The policy calls the DIP-11 predicate with no time, exactly as dpp's identity update builder does: an authentication key with any expiry does not count as remaining. That is stricter than DIP-11 and therefore compliant, and it means the verdict hosts show can never differ from what the update does.
  • Identity-update entry points. update_identity_with_external_signer and update_identity_with_signer call it before fetching a nonce or signing. The DIP-11 refusal keeps the shape the builder gives it, PlatformWalletError::Sdk(Protocol(LastAuthenticationKey)). The transfer refusal is the new PlatformWalletError::LastEnabledKey. FFI maps both to ErrorInvalidParameter. Refusing before the nonce fetch also means a refused update no longer leaves a gap in the locally cached nonce on these paths.
  • The verdict for hosts. IdentityWallet::check_keys_can_be_disabled(identity_id, disable_public_keys) runs the same function on the managed identity that the update is built from. It returns Result<Result<(), KeyDisableRefusal>, PlatformWalletError>: the inner result is the verdict, the outer one a wallet failure (wallet or identity not loaded).
  • FFI. platform_wallet_check_keys_can_be_disabled(wallet_handle, identity_id, ids, count, out_check) writes KeyDisableCheckFFI { refusal, refused_key_id, refused_security_level, refused_purpose }. refusal is 0 allowed, 1 last authentication key, 2 last enabled key. A refusal is a verdict with a success result; an error result means the wallet handle or identity is unknown, or a null key list came with a nonzero count (ErrorInvalidParameter).
  • JNI. TransactionsNative.checkKeysCanBeDisabled returns long[4] with the same fields. The int[] key-id reader is shared with updateIdentity; a failed read throws, and only a successful zero-length read means no keys.
  • SDKs. Swift ManagedPlatformWallet.checkKeysCanBeDisabled(identityId:keyIds:) and Kotlin IdentityUpdates.checkKeysCanBeDisabled(walletHandle, identityId, keyIds) return nothing or a KeyDisableRefusal: lastAuthenticationKey(keyId, securityLevel) or lastEnabledKey(keyId, purpose).
  • Example apps. KeyDisableGate.evaluate(target, ruleVerdict) keeps only the already-disabled display state and turns the verdict into copy. Its Evaluation shape (alreadyDisabled, allowed, forbidden(reason)) is unchanged. The views ask for the verdict whenever the key set changes or the wallet loads, and again right before submitting; a refusal at that point is shown. Kotlin reports an unknown native verdict value as a typed DashSdkError. Without a loaded wallet there is no verdict, and the button stays disabled with that reason. The purpose count, the blanket MASTER ban and the local transfer guard are gone.

How Has This Been Tested?

  • platform-wallet policy: should_refuse_disabling_the_last_enabled_transfer_key, should_allow_disabling_a_transfer_key_another_enabled_one_replaces (including one added in the same update), should_not_count_a_disabled_transfer_key_as_remaining (including disabling both at once), should_report_the_dip11_refusal_for_authentication_keys, should_allow_disabling_keys_of_other_purposes.
  • platform-wallet entry points and verdict: should_refuse_disabling_the_last_transfer_key_before_fetching_a_nonce (both entry points, mock SDK without expectations), should_judge_the_last_transfer_key_as_wallet_policy, should_judge_a_disable_against_the_managed_identity, should_not_count_an_expiring_key_like_the_builder (the verdict and update_identity_with_signer both refuse when the only stand-in key has an expiry), should_report_an_identity_the_wallet_does_not_hold. The existing DIP-11 refusal tests still pass for both entry points.
  • platform-wallet-ffi: should_report_the_wallets_verdict_for_its_identity (DIP-11 refusal, transfer refusal, allowed, unknown identity), should_refuse_a_null_out_pointer, last_enabled_key_refusal_maps_to_invalid_parameter.
  • platform-wallet last-key guard: should_not_count_a_transfer_key_that_cannot_sign_as_remaining, should_not_count_a_transfer_key_below_critical_as_remaining, should_allow_disabling_a_transfer_key_that_cannot_sign, should_count_a_hash160_transfer_key_as_remaining.
  • platform-wallet-ffi: should_refuse_a_null_key_list_with_a_nonzero_count.
  • rs-unified-sdk-jni, against a scripted JNI function table: should_throw_when_the_key_ids_cannot_be_read, should_not_give_a_verdict_when_the_key_ids_cannot_be_read, should_not_submit_an_update_when_its_disables_cannot_be_read, and the normal, zero-length, null and negative-id reads.
  • cargo nextest run -p platform-wallet -p platform-wallet-ffi -p rs-unified-sdk-jni: 2208 passed, 8 skipped.
  • cargo clippy -p platform-wallet -p platform-wallet-ffi -p rs-unified-sdk-jni --all-targets --features platform-wallet/shielded -- -D warnings is clean; cargo fmt --check is clean.
  • Swift KeyDisableGateTests rewritten around the verdict: already disabled wins, an allowed MASTER disable is allowed, each refusal is rendered naming its level or purpose, an unavailable verdict shows its reason.
  • Not built or run here: the Swift and Kotlin changes (no Xcode or Android toolchain on this host). They need build_ios.sh + SwiftExampleApp tests and the Kotlin app build before merge.

Breaking Changes

None for consensus. Rust API changes in platform-wallet:

  • IdentityWallet::update_identity_with_signer returns PlatformWalletError instead of dash_sdk::Error, like update_identity_with_external_signer; SDK errors arrive as PlatformWalletError::Sdk. It has no callers in this repository.
  • New variant PlatformWalletError::LastEnabledKey; exhaustive matches must handle it.
  • Both update entry points refuse disabling the last enabled TRANSFER key able to sign.

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

https://claude.ai/code/session_01WunYYjpfLux1ByK7fGF7SG

🤖 Co-authored by Claudius the Magnificent AI Agent

@coderabbitai

coderabbitai Bot commented Oct 29, 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

@thepastaclaw

thepastaclaw commented Oct 29, 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 c872b35. Normal review starts when eligible; priority review starts as soon as a slot is available.

@Claudius-Maginificent
Claudius-Maginificent marked this pull request as ready for review October 29, 2026 12:13

@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 Rust wallet policy is centralized and reused correctly, and CI reports the Kotlin build and review checks passing. However, the new TRANSFER guard can leave an identity with only a non-signable or insufficiently privileged transfer key, while the Swift views can permanently retain an unavailable verdict after wallet restoration; both can break the advertised disable-key flow.

🔴 2 blocking | 🟡 6 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Update the Swift disable-key test-plan policy description
packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156

The ID-12 row still describes the action as hidden or disabled for every master-level key and for the last enabled authentication key. The new wallet policy allows disabling a master key when another master remains, allows a stronger non-MASTER key to stand in for a weaker authentication level, and reports the affected security level rather than applying a blanket rule. Leaving this row unchanged makes the acceptance criteria contradict the implementation and rewritten gate tests.

source: gpt-6.1-sol (phase2-reviewer: general)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, cross-cutting change to wallet identity key-disable policy and identity-update signing paths, directly affecting key handling and authorization in check_keys_can_be_disabled and the identity update entry points.
  • 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. Verify each finding against the current code and only fix it if needed.

In `packages/rs-platform-wallet/src/wallet/identity/state/key_disable.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/state/key_disable.rs:74-79: Count only usable TRANSFER keys as remaining
  The last-TRANSFER check considers any enabled key with `Purpose::TRANSFER` to be a valid replacement, but transfer and withdrawal transitions require a CRITICAL transfer key, and identity-signed validation accepts only `ECDSA_SECP256K1`, `BLS12_381`, and `ECDSA_HASH160` key types. An identity with a usable CRITICAL transfer key plus an unusable HIGH-level or unsupported-type transfer key can therefore disable the usable key successfully and be left unable to transfer or withdraw credits. The guard should use the same security-level and key-type requirements as the operations it is intended to protect.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/KeyDetailView.swift`:
- [BLOCKING] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/KeyDetailView.swift:157-163: Restart the verdict check when the wallet becomes available
  This task is keyed only by `keySetVersion`, while `identityWallet` depends on the published `walletManager.wallets` collection. If the view appears while the wallet is still being restored, the task records `.unavailable`; inserting the wallet later recomputes the view but does not change the task id, so the verdict is not re-run and the Disable Key action remains unavailable until the key set or view identity changes. `KeysListView` has the same issue in its `.task(id: keySetVersion)` at lines 132-141, leaving swipe actions unavailable as well. Include wallet identity/availability or a wallet-manager generation in the task identity, or explicitly refresh when the manager's wallet collection changes.
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/KeyDetailView.swift:422-431: Show the refusal reason from the submit-time recheck
  After the fresh pre-submit verdict, `KeyDetailView` returns directly when the result is forbidden or unavailable, without setting `disableError`. A background update, sibling disable, wallet teardown, or transient verdict failure can therefore make a confirmed Disable Key tap appear to do nothing. `KeysListView.disableKey` has the same silent guard at lines 242-245. Surface the `KeyDisableGate` reason before returning so the refusal feedback promised by this PR remains available on races and failures.

In `packages/rs-unified-sdk-jni/src/transactions.rs`:
- [SUGGESTION] packages/rs-unified-sdk-jni/src/transactions.rs:146-161: Do not convert JNI key-array read failures into an empty list
  `read_key_ids` clears failures from both `get_array_length` and `get_int_array_region` and returns an empty vector. The new `checkKeysCanBeDisabled` path then passes `(null, 0)` to the wallet and can report that the requested disable is allowed even though the key IDs were not read. The shared helper also affects `updateIdentity`, where a failed read can turn an add-and-disable request into an add-only update. Only a successfully read zero-length array should represent no keys; JNI read failures must throw and return `None`.

In `packages/rs-platform-wallet-ffi/src/identity_update.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/identity_update.rs:445-453: Reject a null disable-list pointer with a nonzero count
  The new C ABI treats a null `disable_public_key_ids` pointer as an empty list even when `disable_public_key_ids_count` is nonzero. A malformed caller therefore receives the verdict for disabling no keys, usually `allowed`, rather than an invalid-pointer error; the API no longer reports the wallet's answer for the caller's requested set. Reject the mismatched pointer/count combination before constructing the slice.

In `packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/identity/IdentityUpdates.kt`:
- [SUGGESTION] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/identity/IdentityUpdates.kt:289-300: Preserve a typed error for unknown native refusal discriminants
  The Kotlin wrapper decodes native security-level and purpose values with `entries.first`, and decodes unknown refusal kinds with `error(...)`. If the native library and Kotlin SDK become temporarily out of sync, callers receive `NoSuchElementException` or `IllegalStateException` outside the normal native-error mapping, unlike the Swift wrapper's explicit invalid-parameter handling. Validate the verdict length and use nullable discriminant lookups that raise the SDK's typed internal/invalid-parameter error.

In `packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156: Update the Swift disable-key test-plan policy description
  The ID-12 row still describes the action as hidden or disabled for every master-level key and for the last enabled authentication key. The new wallet policy allows disabling a master key when another master remains, allows a stronger non-MASTER key to stand in for a weaker authentication level, and reports the affected security level rather than applying a blanket rule. Leaving this row unchanged makes the acceptance criteria contradict the implementation and rewritten gate tests.

In `packages/rs-platform-wallet/src/wallet/identity/network/update.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/update.rs:66-75: Scope the verdict documentation to disable-only updates
  `IdentityWallet::check_keys_can_be_disabled` passes no added keys, while both update entry points can judge an update that adds replacement keys in the same transition. Consequently, the verdict can refuse a disable-only request that succeeds when a replacement is added atomically. The current documentation says the two always agree without stating this disable-only scope, which can mislead callers that use the verdict before an add-and-disable update. Clarify that the host verdict is for disabling the listed keys without additions.

@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.

Re-review — Final validation — Phase 1 + Phase 2

The wallet-owned key-disable policy and its Rust, FFI, JNI, Swift, and Kotlin integrations are generally consistent, and all eight prior findings were independently revalidated. One new blocking Swift API issue can terminate the host for malformed identity data; additional non-blocking issues remain in FFI pointer validation, detached-task lifetime/cancellation handling, and both example-app test plans. Several checks are still pending in CI.

🔴 1 blocking | 🟡 5 suggestion(s)

2 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Update the Swift disable-key test-plan policy description
packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156

The ID-12 row still describes the removed policy: it says the button is gated to match consensus and is hidden or disabled for every master-level key, the last enabled authentication key, and the last enabled transfer key. The current Rust verdict permits some MASTER disables, applies DIP-11's stronger-key behavior, and separately protects the last signable CRITICAL TRANSFER key as wallet policy. Update the row to describe the Rust verdict, its disable-only scope, refusal reasons, and the fact that an add-and-disable update may succeed with an atomically added replacement key.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer, security-auditor)

🟡 Suggestion: Update the Kotlin disable-key test-plan policy description
packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md:135

The ID-12 row only says the action is gated to match consensus. The Kotlin implementation now obtains a wallet-owned verdict covering DIP-11 and the last signable TRANSFER-key policy, including typed refusal reasons; it is not merely a consensus gate. Update the test plan so QA exercises the Rust verdict and its displayed refusal or unavailable states.

source: gpt-6.1-sol (phase2-reviewer: general)

1 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, intricate change to wallet identity key-disable policy and signing/update paths, directly affecting key handling and funds-transfer capability in rs-platform-wallet and its FFI boundaries.
  • 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. Verify each finding against the current code and only fix it if needed.

In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift:3813-3819: Return an error for malformed Swift identity IDs
  `Identifier` is a `Data` typealias, so callers can pass a value whose length is not 32 bytes. This new public method calls `withFFIBytes` without validating the length, and that helper executes `precondition(count == 32)`, terminating the Swift host instead of returning the `PlatformWalletError.invalidParameter` that the Rust FFI already supports. Add the same explicit length guard used by `refreshIdentityBalance` before calling `withFFIBytes`.
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift:3817-3822: Retain the Swift wallet while the detached verdict call uses its handle
  The method copies `self.handle` and the detached task captures only that integer. If the last `ManagedPlatformWallet` reference is released while the task is queued, `deinit` can destroy the Rust handle before the detached closure invokes the FFI function. The registry then reports an invalid-wallet error and the UI shows an unavailable verdict even though the operation had already started. Capture and retain `self` for the duration of the detached call, using the same `withExtendedLifetime(self)` pattern as `refreshIdentityBalance`.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Services/KeyDisableGate.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Services/KeyDisableGate.swift:38-58: Do not publish verdicts from cancelled Swift checks
  `ruleVerdict` catches every error and the wallet method runs its FFI work in a detached task. When either view's `.task(id:)` is cancelled because the wallet or key set changes, the detached operation can still complete and the cancelled task can return a normal verdict. The view then assigns that stale result after the newer task has started, temporarily displaying an action or refusal for obsolete wallet state. Check cancellation immediately before publishing `ruleVerdict` in `KeyDetailView` and `ruleVerdicts` in `KeysListView`, and avoid converting cancellation into an ordinary unavailable verdict that can overwrite newer state.

In `packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156: Update the Swift disable-key test-plan policy description
  The ID-12 row still describes the removed policy: it says the button is gated to match consensus and is hidden or disabled for every master-level key, the last enabled authentication key, and the last enabled transfer key. The current Rust verdict permits some MASTER disables, applies DIP-11's stronger-key behavior, and separately protects the last signable CRITICAL TRANSFER key as wallet policy. Update the row to describe the Rust verdict, its disable-only scope, refusal reasons, and the fact that an add-and-disable update may succeed with an atomically added replacement key.

In `packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md:135: Update the Kotlin disable-key test-plan policy description
  The ID-12 row only says the action is gated to match consensus. The Kotlin implementation now obtains a wallet-owned verdict covering DIP-11 and the last signable TRANSFER-key policy, including typed refusal reasons; it is not merely a consensus gate. Update the test plan so QA exercises the Rust verdict and its displayed refusal or unavailable states.

In `packages/rs-platform-wallet-ffi/src/identity_update.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/identity_update.rs:365-370: Reject a null disable-list pointer with a nonzero count in the update entry point
  (existing thread: https://github.com/dashpay/platform/pull/5661#discussion_r4415750453)
  The new verdict entry point rejects `disable_public_key_ids == null` with a nonzero count, but `platform_wallet_update_identity_with_signer` still treats that combination as an empty list. A malformed caller can therefore receive the verdict for disabling nothing and then submit an add-only update instead of receiving an invalid-parameter error. The update entry point should enforce the same pointer/count invariant as the verdict entry point so the two APIs agree on malformed input.

@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.

Re-review — Final validation — Phase 1 + Phase 2

One blocking mismatch remains in the managed identity-update path: the new verdict accepts signing-capable HASH160 master keys and excludes disabled keys, while the actual signer picker still accepts only ECDSA_SECP256K1 and allows disabled keys. This can present Disable Key as allowed and then fail before signing, or select a disabled master key. The Kotlin and Swift ID-12 test-plan rows also retain the old policy wording; the Kotlin build and test check is still queued, with no failed code checks reported.

🔴 1 blocking | 🟡 2 suggestion(s)

3 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: Align identity-update signing-key selection with the new disable verdict
packages/rs-platform-wallet/src/wallet/identity/network/update.rs:192-197

The managed update path still calls available_signing_key with only KeyType::ECDSA_SECP256K1 and allow_disabled = true. In contrast, the new verdict delegates to DPP's predicate, which explicitly treats ECDSA_HASH160 as signing-capable and the wallet policy excludes disabled keys. Therefore an otherwise-allowed disable on an identity whose usable MASTER key is HASH160 can be reported as allowed but then fail with No signable master key found before the nonce is fetched. The allow_disabled flag also permits the picker to select a disabled MASTER key when the signer can still access its private material, after which Platform rejects the signed update. Use the same usable-key selector as the verdict's eligibility rules, including all accepted key types and excluding disabled keys; the corrected selector in the referenced signing-key work provides the required behavior.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.1-sol (phase2-reviewer: general)

🟡 Suggestion: Update the Kotlin disable-key test-plan policy description
packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md:135

The ID-12 row still says the action is merely Gated to match consensus. The implementation now obtains a Rust wallet verdict combining DIP-11's level-aware authentication rule with the wallet's last usable CRITICAL TRANSFER-key rule; this is wallet policy rather than a generic consensus gate, and a disable-only verdict may refuse an update that succeeds when the same update adds a replacement key. Update the row so QA tests the Rust verdict and its refusal reasons instead of the removed local policy.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer)

🟡 Suggestion: Update the Swift disable-key test-plan policy description
packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156

The ID-12 row still describes the removed app-side policy as hiding or disabling all MASTER-level keys, the last authentication key, and the last transfer key to match consensus. The implementation now delegates to Rust's disable-only verdict: DIP-11 is level-aware, another valid key can permit a MASTER disable, and the transfer guard applies specifically to an enabled CRITICAL signing-capable TRANSFER key. Replace the old wording so the test plan matches the wallet verdict and its refusal reasons.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This large, cross-language change modifies wallet identity key-disable policy and identity-update signing paths in key_disable::check_keys_can_be_disabled and update_identity_with_signer, directly affecting key handling and the ability to transfer or withdraw funds.
  • 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. Verify each finding against the current code and only fix it if needed.

In `packages/rs-platform-wallet/src/wallet/identity/network/update.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/update.rs:192-197: Align identity-update signing-key selection with the new disable verdict
  The managed update path still calls `available_signing_key` with only `KeyType::ECDSA_SECP256K1` and `allow_disabled = true`. In contrast, the new verdict delegates to DPP's predicate, which explicitly treats `ECDSA_HASH160` as signing-capable and the wallet policy excludes disabled keys. Therefore an otherwise-allowed disable on an identity whose usable MASTER key is HASH160 can be reported as allowed but then fail with `No signable master key found` before the nonce is fetched. The `allow_disabled` flag also permits the picker to select a disabled MASTER key when the signer can still access its private material, after which Platform rejects the signed update. Use the same usable-key selector as the verdict's eligibility rules, including all accepted key types and excluding disabled keys; the corrected selector in the referenced signing-key work provides the required behavior.

In `packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md:135: Update the Kotlin disable-key test-plan policy description
  The ID-12 row still says the action is merely `Gated to match consensus`. The implementation now obtains a Rust wallet verdict combining DIP-11's level-aware authentication rule with the wallet's last usable CRITICAL TRANSFER-key rule; this is wallet policy rather than a generic consensus gate, and a disable-only verdict may refuse an update that succeeds when the same update adds a replacement key. Update the row so QA tests the Rust verdict and its refusal reasons instead of the removed local policy.

In `packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156: Update the Swift disable-key test-plan policy description
  The ID-12 row still describes the removed app-side policy as hiding or disabling all MASTER-level keys, the last authentication key, and the last transfer key to match consensus. The implementation now delegates to Rust's disable-only verdict: DIP-11 is level-aware, another valid key can permit a MASTER disable, and the transfer guard applies specifically to an enabled CRITICAL signing-capable TRANSFER key. Replace the old wording so the test plan matches the wallet verdict and its refusal reasons.

@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.

Re-review — Final validation — Phase 1 + Phase 2

The Swift verdict task remains keyed only by wallet presence, so replacing an already-loaded wallet manager can leave both key views displaying a verdict computed against the old wallet. The two test plans still document the superseded policy, and the C update export accepts a malformed counted-null disable list unlike the new verdict export. The signer-selection mismatch is real but is explicitly tracked for #5588 and is intentionally deferred; CI code checks are still pending with no reported failure.

🔴 1 blocking | 🟡 3 suggestion(s)

2 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Update the Swift disable-key test-plan policy description
packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156

ID-12 still says the button is gated to match consensus and is disabled for all master-level keys, the last enabled authentication key, and the last enabled transfer key. The current UI delegates to the Rust wallet verdict: it applies DPP's DIP-11 signing predicate, does not impose a blanket MASTER ban, and separately protects the last usable TRANSFER key as wallet policy. Update this row to describe the Rust disable-only verdict and its structured refusal reasons.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.1-sol (phase2-reviewer: general, rust-quality, security-auditor)

🟡 Suggestion: Update the Kotlin disable-key test-plan policy description
packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md:135

ID-12 still describes the action only as gated to match consensus. The Kotlin UI now receives the Rust wallet's disable-only verdict through JNI, including DPP's DIP-11 authentication-key rule and the wallet-owned last usable TRANSFER-key safeguard. Update the row so it identifies the verdict source and the refusal behavior instead of misclassifying wallet policy as consensus.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.1-sol (phase2-reviewer: general, rust-quality, security-auditor)

Still open from earlier rounds (2)

  • 🔴 Blocking: Restart the verdict check when the wallet becomes available — packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/KeyDetailView.swift:52-55 (thread)
  • 🟡 Suggestion: Reject a null disable list with a nonzero count in the update export too — packages/rs-platform-wallet-ffi/src/identity_update.rs:365-370 (thread)
Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large cross-language change to identity key-disable policy and signing/update entry points, directly affecting key handling and the wallet's ability to transfer or withdraw funds in key_disable::check_keys_can_be_disabled and identity update functions.
  • 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/swift-sdk/SwiftExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156: Update the Swift disable-key test-plan policy description
  ID-12 still says the button is gated to match consensus and is disabled for all master-level keys, the last enabled authentication key, and the last enabled transfer key. The current UI delegates to the Rust wallet verdict: it applies DPP's DIP-11 signing predicate, does not impose a blanket MASTER ban, and separately protects the last usable TRANSFER key as wallet policy. Update this row to describe the Rust disable-only verdict and its structured refusal reasons.

In `packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md:135: Update the Kotlin disable-key test-plan policy description
  ID-12 still describes the action only as gated to match consensus. The Kotlin UI now receives the Rust wallet's disable-only verdict through JNI, including DPP's DIP-11 authentication-key rule and the wallet-owned last usable TRANSFER-key safeguard. Update the row so it identifies the verdict source and the refusal behavior instead of misclassifying wallet policy as consensus.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/KeyDetailView.swift`:
- [BLOCKING] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/KeyDetailView.swift:52-55: Restart the verdict check when the wallet becomes available
  (carried; thread: https://github.com/dashpay/platform/pull/5661#discussion_r4415750435)

In `packages/rs-platform-wallet-ffi/src/identity_update.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/identity_update.rs:365-370: Reject a null disable list with a nonzero count in the update export too
  (carried; thread: https://github.com/dashpay/platform/pull/5661#discussion_r4415750453)

@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.

Re-review — Final validation — Phase 2 only (queue backlog)

New on this head: On the rebased head, the mobile apps use the Rust wallet’s cached disable verdict, while managed submission refreshes the identity and rechecks the policy before reserving a nonce. The wallet now uses the base branch’s same-level DIP-11 replacement rule without changing consensus. Rust workspace tests and the Swift and Kotlin SDK build-and-test checks passed; the review check is still pending.

🟡 3 suggestion(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.

2 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Update the Kotlin disable-key test-plan policy description
Impact: An Android tester following ID-12 can mistake a correct refusal to disable the last usable TRANSFER key for a test failure because Platform itself does not enforce that restriction.
packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md:135

ID-12 tells QA to expect the screen to match consensus, but the screen displays the Rust wallet’s disable-only verdict. State that the wallet checks for a valid same-level authentication replacement and separately refuses to disable the last enabled, signing-capable CRITICAL TRANSFER key. Use the latter as a concrete case where QA should expect a refusal before signing, not a rejection from Platform.

source: gpt-6.2-astra (phase2-reviewer: general, ffi-engineer, rust-quality, security-auditor)

🟡 Suggestion: Update the Swift disable-key test-plan policy description
Impact: An iOS tester following ID-12 can wrongly expect Disable Key to be available for the only HIGH authentication key when a CRITICAL key remains.
packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156

ID-12 still describes the removed app-side MASTER ban and a count of authentication keys across levels as a consensus gate. The detail and swipe actions now use the Rust wallet verdict: a CRITICAL key does not replace the only HIGH key, and the last usable TRANSFER key is protected by wallet policy. Describe those expected results and keep the separate read-only display case for keys that are already disabled.

source: gpt-6.2-astra (phase2-reviewer: general, ffi-engineer, rust-quality, security-auditor)

Follow-up candidates (optional) (2)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: A removed wallet handle can return the replacement wallet’s disable verdict
Impact: A Rust caller that retains an IdentityWallet after restoring the same wallet can get an allowed preview for an identity that the old handle cannot update.
packages/rs-platform-wallet/src/wallet/identity/network/update.rs:90-94

The old handle can report an allowed disable from a wallet it no longer represents. This lookup uses only the wallet ID, so after a same-ID restore it reads the replacement generation if that generation holds the identity. On the rebased head, managed submission refreshes before checking the policy, and that refresh rejects the old generation with WalletNotFound when it folds the fetched identity. Use the existing generation-aware read helper so the preview also rejects the old handle.

        let info = self.current_wallet_info(&wm)?;

source: gpt-6.2-astra (phase2-reviewer: general)

🟡 Suggestion: The last-HIGH refusal says signing would stop even when a CRITICAL key can still sign
Impact: Swift and Kotlin example-app users with one valid HIGH key and an unrestricted CRITICAL authentication key see the correct refusal but are incorrectly told they would lose the ability to sign operations requiring HIGH.
packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Services/KeyDisableGate.swift:85-86

Disabling the HIGH key would not, by itself, prevent the identity from signing a document operation that requires HIGH: that operation accepts a CRITICAL key too. The rebased DPP predicate refuses the disable because DIP-11 requires a replacement at the same level, not because the CRITICAL key cannot sign. Explain that requirement and the remedy in both apps; the same claim appears in KeyDisableGate.kt:100–102. Update the PR description’s stronger-key example to match the rebased rule as well.

        case .lastAuthenticationKey(_, let securityLevel):
            return "DIP-11 requires another valid authentication key at the \(securityLevel.name) level. Add one before disabling this key (Add Key)."

source: gpt-6.2-astra (phase2-reviewer: general)

Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — This large cross-language change alters wallet key handling in check_keys_can_be_disabled, which now governs whether both identity-update entry points allow disabling authentication and transfer signing keys.
  • Phase 1 reviewers: not run (skipped for throughput: 11 PRs queued, above the 10 limit)
  • New since the last final review (f2f0896f): 2 suggestion(s) on unchanged code listed as follow-up candidates
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); 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/src/wallet/identity/network/update.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/update.rs:1169-1172: The last-TRANSFER test passes even if submission checks the pre-refresh key set
  Impact: A regression that evaluates the cached key set instead of the refreshed one would go undetected when another device has disabled the only replacement TRANSFER key.
  The test cannot distinguish a refusal based on fresh Platform state from the same refusal based on stale cache data. The rebased managed update now refreshes before applying wallet policy, but `manager_holding` serves a clone of the same identity it caches. Add a case with two enabled TRANSFER keys in the cache and a newer fetched revision in which the other key is disabled. Assert that the cached preview allows disabling the target and that managed submission returns `LastEnabledKey` for that target without a nonce or broadcast expectation.

In `packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md:135: Update the Kotlin disable-key test-plan policy description
  Impact: An Android tester following ID-12 can mistake a correct refusal to disable the last usable TRANSFER key for a test failure because Platform itself does not enforce that restriction.
  ID-12 tells QA to expect the screen to match consensus, but the screen displays the Rust wallet’s disable-only verdict. State that the wallet checks for a valid same-level authentication replacement and separately refuses to disable the last enabled, signing-capable CRITICAL TRANSFER key. Use the latter as a concrete case where QA should expect a refusal before signing, not a rejection from Platform.

In `packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:156: Update the Swift disable-key test-plan policy description
  Impact: An iOS tester following ID-12 can wrongly expect Disable Key to be available for the only HIGH authentication key when a CRITICAL key remains.
  ID-12 still describes the removed app-side MASTER ban and a count of authentication keys across levels as a consensus gate. The detail and swipe actions now use the Rust wallet verdict: a CRITICAL key does not replace the only HIGH key, and the last usable TRANSFER key is protected by wallet policy. Describe those expected results and keep the separate read-only display case for keys that are already disabled.

Comment on lines +1169 to +1172
sdk.mock()
.expect_fetch(identity.id(), Some(identity.clone()))
.await
.expect("identity expectation");

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.

🟡 Suggestion: The last-TRANSFER test passes even if submission checks the pre-refresh key set
Impact: A regression that evaluates the cached key set instead of the refreshed one would go undetected when another device has disabled the only replacement TRANSFER key.

The test cannot distinguish a refusal based on fresh Platform state from the same refusal based on stale cache data. The rebased managed update now refreshes before applying wallet policy, but manager_holding serves a clone of the same identity it caches. Add a case with two enabled TRANSFER keys in the cache and a newer fetched revision in which the other key is disabled. Assert that the cached preview allows disabling the target and that managed submission returns LastEnabledKey for that target without a nonce or broadcast expectation.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

@lklimek
lklimek force-pushed the fix/key-disable-gate-from-rust branch from 088e5d3 to 4c3b35a Compare November 24, 2026 12:13
@Claudius-Maginificent
Claudius-Maginificent marked this pull request as draft November 24, 2026 12:16
@Claudius-Maginificent Claudius-Maginificent added the priority: medium Medium priority label Nov 24, 2026
@lklimek
lklimek removed this pull request from stack #6214 December 2, 2026 08:25
@lklimek
lklimek added this pull request to stack #6451 December 2, 2026 08:25
lklimek and others added 3 commits December 2, 2026 16:09
…n the mobile apps

Preserve the final PR scope, including merge resolutions, on the updated native stack.

Co-Authored-By: Codex <[email protected]>
dpp's check_keys_can_be_disabled now takes the platform version, so the
wallet's check takes it last and passes the SDK's version. The parent's error
matches list every variant: LastEnabledKey is refused before a nonce or a
signature, so it is NotSent, not retryable and no asset-lock resume refusal,
like InvalidParameter, the code FFI maps it to.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lklimek
lklimek force-pushed the fix/key-disable-gate-from-rust branch from 4c3b35a to c872b35 Compare December 3, 2026 07:11

This branch has not been deployed

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

Labels

priority: medium Medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants