Skip to content

feat(dpp): pick a usable withdrawal signing key in a new conversion generation #6383

Backlog

Description

@Claudius-Maginificent

TL;DR: dpp's credit-withdrawal constructor can pick a signing key that Platform will refuse, or give up when another usable key exists; fix it in a new conversion generation so shipped protocol versions keep their current behaviour.

User story

As a developer building withdrawals with dpp or the Rust SDK, I want automatic withdrawal-key selection to choose a key Platform accepts and the signer actually holds, to achieve withdrawals that succeed instead of being refused after they are signed and broadcast.

Scenario

Base flow

A client builds a credit withdrawal with IdentityCreditWithdrawalTransition::try_from_identity, passing an output script and letting dpp choose the signing key (for example PreferredKeyPurposeForSigningWithdrawal::OwnerPreferred).

Actual behavior

  • With an output script, OwnerPreferred picks the OWNER key. Platform refuses an OWNER-signed withdrawal that carries an output script (consensus error 10532, WithdrawalOutputScriptNotAllowedWhenSigningWithOwnerKeyError), so the transition is signed and sent only to be rejected.
  • For each purpose only the first key is considered. If the signer does not hold that key, a later key of the same purpose that it does hold is never tried.
  • Nothing refuses OWNER + output script before signing.

Expected behavior

  • OwnerPreferred with an output script tries a TRANSFER key first and keeps OWNER only as the fallback.
  • Each preference takes, per purpose, the first key the signer can sign with.
  • An OWNER key with an output script (explicit, OwnerOnly, or the fallback) is refused with 10532 before signing.
  • Protocol versions that select today's generation keep exactly today's behaviour.

Detailed discussion

try_from_identity dispatches on dpp.state_transition_conversion_versions.identity_to_identity_withdrawal_transition; generation 1 (identity_credit_withdrawal_transition/v1/v0_methods.rs) is selected from protocol version 3 onwards, so it is a shipped generation and must not change in place (book/src/contributing/coding-conventions.md, "Shipped generations are frozen unless the change cannot modify consensus").

Proposed approach:

  • Add conversion generation 2 with the behaviour above, plus a dispatcher arm in identity_credit_withdrawal_transition/methods/mod.rs.
  • Select it only from an unreleased protocol version's conversion table (a new DPP_STATE_TRANSITION_CONVERSION_VERSIONS_V3 named by that version), leaving the shipped tables untouched.
  • Reuse dpp's validate_withdrawal_output_script (added by feat(platform-wallet)!: expose protocol-14-aware signing-key selection #5588) for the pre-sign 10532 check.
  • Tests for both generations through the enum constructor: generation 1 pinned to today's selection, generation 2 to the new one (TRANSFER first with a script, signer-held key per purpose, 10532 refusals before the signer is asked to sign).

The platform wallet already refuses OWNER + output script in its own preflight (#5588), so this matters for direct dpp and Rust SDK callers.

Prior work

Attribution

🤖 Co-authored by Claudius the Magnificent AI Agent

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions