Skip to content

feat(platform)!: identity public key references (refersTo identityPublicKey) - #4397

Merged
QuantumExplorer merged 1 commit into
v4.2-devfrom
feat/identity-public-key-references
Aug 13, 2026
Merged

feat(platform)!: identity public key references (refersTo identityPublicKey)#4397
QuantumExplorer merged 1 commit into
v4.2-devfrom
feat/identity-public-key-references

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Follows #2993 (refersTo for identities, contracts, tokens) and #4390 (permanent documents). This adds the next reference target that structurally cannot dangle: a specific public key of an identity — identity keys can be disabled but never removed.

What was done?

Extends refersTo with an identityPublicKey target. The reference property's value holds the identity id; the declaration names a sibling property of the same document type whose value carries the key id:

"toUserId": {
  "type": "array",
  "byteArray": true,
  "minItems": 32,
  "maxItems": 32,
  "contentMediaType": "application/x.dash.dpp.identifier",
  "position": 0,
  "refersTo": {
    "type": "identityPublicKey",
    "keyIdProperty": "toKeyIndex"
  }
},
"toKeyIndex": {
  "type": "integer",
  "position": 1
}

This two-property shape matches how DashPay's contactRequest already pairs toUserId with recipientKeyIndex, so per-document key selection works naturally.

Semantics

  • Write time (document create, and replace on changed fields via the existing machinery): the key id is read from the declared sibling property, and the identity's key is fetched with a specific-key request (billed as one key-by-id lookup, the same way signature validation fetches keys). The key must exist and must not be disabled — writing a fresh reference to a dead key is almost certainly a mistake. A key disabled later does not invalidate previously written documents; since keys are never removed, an accepted reference can never dangle.
  • Contract registration (the create/update declaration validation introduced in feat(platform)!: permanent document references (refersTo permanentDocument) #4390): the declared keyIdProperty must exist in the same document type and be an integer. The u32 key-id range is enforced at write time by the integer read.

Changes

  • DocumentPropertyReferenceTarget gains IdentityPublicKey { key_id_property } (appended — the enum is consensus-serialized inside errors and @append_only).
  • Meta-schema v3 (still editable until the PV14 release ships): refersTo.type admits identityPublicKey; keyIdProperty (dotted property-path shape, ≤256 chars) is required for it and rejected for every other target. The per-target conditionals are now an allOf of if/then/else blocks.
  • Parse (apply_property_reference_v0): new arm; missing/oversized keyIdProperty is a hard parse error.
  • Write-time validation (document_reference_validation v0, amended in place — PV14 is unreleased): resolves the key id from document data (ReferencedKeyIdPropertyInvalidError when unset or out of range), bills RetrieveIdentityInfo::one_key(), fetches via fetch_identity_keys::<OptionalSingleIdentityPublicKeyOutcome> with IdentityKeysRequest::new_specific_key_query, then checks is_disabled().
  • Registration validation (data_contract_reference_validation v0, amended in place — also PV14-new): keyIdProperty must resolve to an integer property of the declaring document type.
  • New state errors (appended, discriminants pinned): ReferencedIdentityKeyNotFoundError (40123 — a missing identity and a missing key are indistinguishable in the key tree and resolve to the same failure), ReferencedIdentityKeyDisabledError (40124), ReferencedKeyIdPropertyInvalidError (40125, shared by registration and write time).
  • wasm-dpp: the three errors exposed via generic_consensus_error!.

How Has This Been Tested?

  • 2 parse tests, 4 meta-schema tests (accept; missing keyIdProperty; keyIdProperty on other targets; malformed values).
  • 5 drive-abci document-write tests (fixture registered via setup_contract): key exists (success), key missing, identity missing, key disabled (the helper disables the test identity's master key in state), key-id property unset.
  • 3 drive-abci contract-registration tests: valid declaration registers; undefined keyIdProperty and non-integer keyIdProperty are rejected at create.
  • Full suites: dpp 3899 pass, drive-abci reference tests 39 pass, --all-targets checks clean on dpp/drive/drive-abci/dash-sdk/wasm-dpp, clippy clean, fmt applied.

Breaking Changes

Consensus-breaking for the in-development protocol version 14 only (extends the PV14 meta-schema v3 grammar and reference validation; pre-PV14 behavior is untouched).

Checklist:

  • I have performed a self-review of my own code
  • 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

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

…licKey)

Extends refersTo with an identityPublicKey target: the property value
holds the referenced identity's id and the declaration names a sibling
integer property of the same document type (keyIdProperty) whose value
carries the key id.

Identity keys can be disabled but never removed, so an existing
reference can never dangle; at write time the key must exist and must
not be disabled (a key disabled later does not invalidate old
documents). The billed existence check goes through
fetch_identity_keys with a specific-key request, billed as one key
lookup, matching how signature validation fetches keys.

Contract registration (the create/update reference validation from the
permanentDocument work) checks that the declared keyIdProperty exists
in the same document type and is an integer.

New state errors: ReferencedIdentityKeyNotFoundError (40123, also
covers a missing identity), ReferencedIdentityKeyDisabledError (40124)
and ReferencedKeyIdPropertyInvalidError (40125), discriminants pinned.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@QuantumExplorer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 9 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f586f544-5dd3-48fc-bdf7-0fe2e03b5a48

📥 Commits

Reviewing files that changed from the base of the PR and between 0cb4bad and f963dd8.

📒 Files selected for processing (20)
  • packages/rs-dpp/schema/meta_schemas/document/v3/document-meta.json
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs
  • packages/rs-dpp/src/errors/consensus/codes.rs
  • packages/rs-dpp/src/errors/consensus/state/document/mod.rs
  • packages/rs-dpp/src/errors/consensus/state/document/referenced_identity_key_disabled_error.rs
  • packages/rs-dpp/src/errors/consensus/state/document/referenced_identity_key_not_found_error.rs
  • packages/rs-dpp/src/errors/consensus/state/document/referenced_key_id_property_invalid_error.rs
  • packages/rs-dpp/src/errors/consensus/state/state_error.rs
  • packages/rs-dpp/src/validation/meta_validators/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v0/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/creation.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_common/data_contract_reference_validation/v0/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/mod.rs
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-identity-key-registration-missing-prop.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-identity-key-registration-non-integer.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-identity-key-registration-valid.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-identity-key.json
  • packages/wasm-dpp/src/errors/consensus/consensus_error.rs

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

@thepastaclaw

thepastaclaw commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

ℹ️ Review superseded (commit f963dd8)
Reason: PR merged before the review completed.
Last checked: 2026-08-13 09:37 UTC

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.10042% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.92%. Comparing base (0cb4bad) to head (f963dd8).
⚠️ Report is 1 commits behind head on v4.2-dev.

Files with missing lines Patch % Lines
...pp/src/data_contract/document_type/property/mod.rs 0.00% 12 Missing ⚠️
...n/document/document_reference_validation/v0/mod.rs 80.00% 10 Missing ⚠️
...document_type/class_methods/try_from_schema/mod.rs 87.87% 8 Missing ⚠️
...kages/rs-dpp/src/validation/meta_validators/mod.rs 90.00% 4 Missing ⚠️
...tion/state_transitions/data_contract_create/mod.rs 92.50% 3 Missing ⚠️
...ommon/data_contract_reference_validation/v0/mod.rs 96.77% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v4.2-dev    #4397      +/-   ##
============================================
- Coverage     87.68%   85.92%   -1.76%     
============================================
  Files          2680     2680              
  Lines        341126   347366    +6240     
============================================
- Hits         299109   298472     -637     
- Misses        42017    48894    +6877     
Components Coverage Δ
dpp 86.00% <79.66%> (-2.92%) ⬇️
drive 85.49% <ø> (-0.80%) ⬇️
drive-abci 87.05% <88.42%> (-2.66%) ⬇️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.92% <ø> (ø)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 48.02% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added this to the v4.2.0 milestone Aug 13, 2026
@QuantumExplorer
QuantumExplorer merged commit 8846fe2 into v4.2-dev Aug 13, 2026
32 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/identity-public-key-references branch August 13, 2026 09:32
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