Skip to content

feat(identity): add keys with spending limits and raise key limits - #1120

Draft
Claudius-Maginificent wants to merge 18 commits into
fix/protocol14-signing-key-selectionfrom
feat/identity-key-limits
Draft

Claudius-Maginificent wants to merge 18 commits into
fix/protocol14-signing-key-selectionfrom
feat/identity-key-limits

Conversation

@Claudius-Maginificent

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

Copy link
Copy Markdown
Collaborator

TL;DR: On networks running protocol 14, you can add an authentication key with a spending limit, an expiry, or both. Key Info shows how much of the limit is left and when the key expires. You can also raise a key's limits after confirming the exact change.

Stacked atop #1117.

User story

  • As a user handing a key to an app or a helper, I want to cap how much that key can ever spend and when it stops working, so that a leaked or forgotten key can do limited damage (IDN-022).
  • As a user whose limited key is running out, I want to add to its spending limit or extend its expiry without adding a new key (IDN-023).

Scenario

  1. On testnet, Priya opens Add Key for her identity and adds a HIGH authentication key with a 0.5 DASH spending limit that expires after 30 days.

  2. Key Info for that key shows the total limit, how much is left (read from Platform), and the expiry date. The keys list marks the key as Limited, and later as Expired.

  3. When the key runs low, Priya clicks Raise Limits, adds 0.25 DASH and 30 days, and confirms a summary of:

    • the resulting total limit and expiry;
    • the key that signs the change.

    The app sends exactly that. If the key's limits, or the key that would sign the change, changed in the meantime, nothing is sent and the screen asks her to review again.

On mainnet (protocol 13) the limit fields are shown disabled, with an explanation.

Detailed discussion

Adding a limited key

  • Where the fields are: Add Key offers "Spending Limit" and "Expires After (days)" for authentication keys below the master level.
  • Gate: the fields depend on the IdentityKeyLimits capability. It opens only once the network has proven it runs protocol 14.
  • Validation: model/identity_key_limits.rs holds the stateless validation. It refuses, before anything is sent:
    • a zero limit;
    • zero days;
    • an expiry more than 100 years away (a typo guard, not a Platform rule).
  • Backend checks: the backend task re-checks the same limits, the expiry bound included, together with the network's protocol version.
  • Keys without limits: a key added without limits, from a wallet or a private key, always goes out as a version 0 key. Upstream's with_limits makes a version 1 key even for no limits, which a protocol 13 network cannot decode.

Reading the remaining budget

  • Where it comes from: Platform tracks what is left of a key's budget; the key itself carries only the lifetime total. So Key Info asks Platform once per opened screen (IdentityTask::FetchKeyRemainingBudgets).
  • Read failures: if the read fails, Key Info still shows the total.
  • Mismatched answers: an answer for another key is ignored.
  • Before protocol 14: the query is refused.

Raising limits

  • What can be raised: a key's limits can only be raised, never lowered or added. An expiry is extended from its current date, or from today if the key has already expired. An expired key cannot be topped up without also extending its expiry.
  • The confirmation step: the confirmation builds a KeyLimitsRaise, and the backend sends exactly that raise (IdentityTask::RaiseKeyLimits).
    • If the key's limits moved meanwhile, the raise is refused rather than recomputed.
    • If the reviewed signing key changed, the user is asked for a new review. Another signer is never picked silently.
  • Signing key: the change is signed by the master key, or by a critical key with no limits and no contract bounds. Without either, the screen says which key to import, naming both conditions.
  • After a raise: the app stores the key as Platform now stores it, and the balance after the fee.
    • If the local save fails after the network accepted the raise, it is still reported as made (KeyLimitsRaisedButNotSaved), so the user does not retry.
    • If only the new balance cannot be read, the app says so (KeyLimitsRaisedButBalanceNotRefreshed).

Refusals

Platform's refusals for limited keys and for limit updates get dedicated messages:

  • expiry in the past;
  • a limit not raised;
  • a limit not set;
  • the signer has limits of its own;
  • limits not allowed on this key;
  • an update that raises nothing;
  • a disabled key.

Protocol 13 safety

Guard tests check two things at protocol 13:

  • a limited key is either refused or keeps its limits, and never goes out as an unlimited version 0 key;
  • a key added without limits goes out as version 0.

Scope

Contract-bound authentication keys (#1123) are not part of this PR.

Testing

  • Library tests and UI tests (kittest) pass, including the keys list markers (tests/kittest/keys_screen.rs).
  • cargo clippy --all-features --all-targets -- -D warnings and cargo fmt --all -- --check pass.
  • New tests cover:
    • limit validation, including the backend's expiry bound;
    • building and confirming a raise;
    • refusal of a changed signer or of moved limits;
    • storing the key and the balance after a raise;
    • "raised but not saved" reporting;
    • Key Info's budget read routing;
    • the capability gate;
    • the protocol 13 guard;
    • the refusal mappings.
  • No live network or GUI flows were run.

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q

lklimek and others added 4 commits October 24, 2026 19:36
On protocol 14 an authentication key below MASTER can carry a spending
limit, an expiry, or both. Limits are validated before anything is sent,
and only where the network has proven protocol 14 (IdentityKeyLimits
capability).

A key's remaining budget is read from Platform. A limits raise is sent
exactly as the user reviewed it: refused, not recomputed, when the key's
limits or the reviewed signer moved meanwhile. After a raise the key as
Platform stores it and the balance after the fee are saved; a raise the
network accepted is reported as made even if saving it locally fails.

A protocol 13 guard checks that a limited key never goes out as an
unlimited version 0 key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Map Platform's refusals of limited keys and limits updates (expiry in
the past, limit not raised, limit not set, signer with limits, limits
not allowed, disabled key) to dedicated TaskError variants with a
message that says what to do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Add Key offers a spending limit and an expiry for authentication keys
below MASTER, disabled with an explanation on networks without key
limits. Key Info shows the total limit, what is left of it, and the
expiry, and offers Raise Limits behind a confirmation of the resulting
limits and signing key. The keys list marks expired and limited keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
@coderabbitai

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

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

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

…efusals from the signing key branch

Merges 4452ae0 from fix/protocol14-signing-key-selection, which carries
74695e7 from chore/bump-platform-063589bf. The conflict in
src/backend_task/error.rs keeps both sides: the key limit refusals and the
moderation, gas sponsorship and distribution limit refusals each keep their
variants, match arms and test cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
lklimek and others added 9 commits October 25, 2026 10:59
The merge resolution kept the shared closing brace for the other guard
only; this restores it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Upstream's with_limits makes a version 1 key even when no limit is set,
and the identity update sends it as is, so a key added from a wallet
without limits went out in an encoding protocol 13 networks do not
decode. One helper now builds the key for both add paths and keeps a key
without limits at version 0, and the backend applies it to every key it
adds. The backend also refuses an expiry beyond the longest validity the
form allows, so every caller gets the same bound.

Also restores the Add Key doc comments the earlier merges dropped,
checks validity days in one place, and builds test identities from the
shared helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The key limits signer notice names both conditions a critical key must
meet, in one sentence shared by Key Info and the refusal. An update that
raises nothing gets its own message telling the user what to enter. Key
Info reads the live key through the shared lookup, and the spending
limit warning and IDN-024 again point at the remaining budget and the
key list markers this branch adds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…y limits branch

The protocol 13 transition tests go with the file the bump deleted; the
two key-limit cases there only checked the protocol 13 encoding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The Platform bump dropped DET's own protocol version copy, so the tests
have the SDK prove the version instead of setting it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The squash commit's tree equals #1114's final head, which this branch
already contains, so the tree is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…to the key limits branch

Conflicts:
- src/backend_task/dashpay/auto_accept_proof.rs: deleted by #1117 (contact
  QR codes now go through platform-wallet); this branch only carried
  #1117's earlier edit of it, so it stays deleted.
- src/backend_task/error.rs: this branch's key limits refusals and their
  test imports stay; the section header and test doc name key limits.
- src/context/feature_gate.rs: this branch's IdentityKeyLimits and
  v1.0-dev's NonTransferableTokens capability and gate both stay; the
  protocol 14 gate tests cover both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Next steps: the updated #1117 head is merged into this branch locally and verified (fmt, clippy, area tests); it will be pushed right after #1117. Once #1117 merges, this PR gets retargeted to v1.0-dev and goes through the normal review gate.

🤖 Co-authored by Claudius the Magnificent AI Agent

@Claudius-Maginificent Claudius-Maginificent added priority: low Low priority — nice to have priority: medium Medium priority and removed priority: low Low priority — nice to have priority: medium Medium priority labels Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: low Low priority — nice to have

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants