-
Notifications
You must be signed in to change notification settings - Fork 45
feat: identity reference validation #2993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lklimek
wants to merge
24
commits into
v3.1-dev
Choose a base branch
from
feat/reference-validation
base: v3.1-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
18dda42
doc: reference validation spec
lklimek 802d10e
chore: minor improvement
lklimek 06b4e90
doc
lklimek 93902c5
spec update
lklimek 3d5c0b7
feat: add refersTo to document schema
lklimek dbd9616
chore(dpp): add DocumentProperty.reference
lklimek 69bb293
chore(dpp): define ReferencedEntityNotFoundError
lklimek eeb4334
fix(scripts): configure_test_suite_network.sh not working
lklimek 2eab1ca
chore: implemented?
lklimek fdd45af
Merge branch 'v3.0-dev' into feat/reference-validation
lklimek 0385784
test: fix stack size
lklimek 184d1ec
tests 1
lklimek f153446
test(dpp): refersTo tests
lklimek 90a76ef
test: more tests
lklimek c5036a3
fix(wasm-dpp): add error variant to fix build
lklimek 0caedb4
Merge remote-tracking branch 'origin/v3.0-dev' into feat/reference-va…
lklimek 858ad36
fix(dpp): order matters in dpp enums
lklimek 02125ff
fix(platform): err when no required identifier
lklimek 1fc3406
Merge branch 'v3.0-dev' into feat/reference-validation
lklimek 84c5600
chore: schema verification
lklimek d1cbd32
chore: test renames
lklimek 364305d
Update docs/specs/reference-validation.md
lklimek 38f2715
Merge remote-tracking branch 'origin/feat/reference-validation' into …
lklimek 5b92420
Merge branch 'v3.1-dev' into feat/reference-validation
QuantumExplorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Reference Validation (`refersTo`) | ||
|
|
||
| ## Summary | ||
| Introduce an optional `refersTo` keyword on document properties so contracts can request existence checks for referenced identities. When present, state validation rejects documents whose referenced identity does not exist. Contracts and documents without `refersTo` are unchanged. | ||
|
|
||
| ## Schema Changes | ||
| - Extend document meta-schema (`packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json`) to allow a `refersTo` object alongside existing keywords. | ||
| - `refersTo` structure: | ||
| - `type`: `"identity"` (current target; keep the mechanism extensible for other reference targets such as documents or contracts). | ||
| - `mustExist`: `boolean` (optional, defaults to `true`; `false` means no reference validation). | ||
| - Validation rules during schema parsing: | ||
| - Only allowed on identifier-typed properties (array byteArray=true, minItems=32, maxItems=32, `contentMediaType` identifier). | ||
| - Not allowed on non-identifier properties (reject contract). | ||
| - Mutability: `refersTo` may only be set at contract creation; contract updates cannot add or change it. | ||
| - JSON Schema compatibility rules must allow the keyword but should reject updates that attempt to add/modify it post-creation. | ||
|
|
||
| ## Data Model / Parsing | ||
| - During `DocumentType::try_from_schema`, detect `refersTo` and store per-property reference metadata (path → `{ targetType: Identity, mustExist: bool }`). | ||
| - Expose reference metadata through DocumentType accessors and WASM/JS bindings so clients can introspect. | ||
| - Keep existing `identifier_paths`/`binary_paths` behavior (the sets of property paths already tracked for identifier and binary fields); `refersTo` is additive on top. | ||
|
|
||
| ## Runtime Validation | ||
| - Enforce during Drive document state validation (create/replace state validators) for document create and replace transitions: | ||
| - For each property with `refersTo.mustExist == true`, fetch the referenced identity ID and fail with a consensus state error if missing. | ||
| - Support nested properties (use flattened property paths). | ||
| - Count identity fetches in execution context fee accounting. | ||
| - Implement via versioned document state validators (new v2 modules) while keeping v0/v1 behavior unchanged. | ||
| - Applied in ABCI paths: CheckTx, PrepareProposal, and ProcessProposal. | ||
| - Basic validation (DPP) only checks keyword shape/placement; no state access. | ||
|
|
||
| ## Errors | ||
| - Add a dedicated consensus state error, e.g., `ReferencedEntityNotFoundError { path, identityId }`. | ||
| - Avoid overloading signature errors; ensure deterministic mapping to codes. | ||
|
|
||
| ## Backward Compatibility | ||
| - Gated by platform/protocol version (and/or data contract system version). Legacy nodes reject contracts containing `refersTo`; such contracts are accepted only after activation. Post-activation, newer nodes enforce `mustExist:true` semantics. | ||
| - Existing pre-activation contracts and documents remain valid; documents are rejected only when the contract opts in with `mustExist:true` and the network is past activation. | ||
|
|
||
| ## Implementation Notes | ||
| - Reference existence checks use the identity revision lookup (`fetch_identity_revision`) as the minimal-cost existence check. | ||
| - Reference validation dispatches through a versioned `DocumentReferenceValidation` trait; v0 rules are implemented for identity references. | ||
|
|
||
| ## Acceptance Criteria | ||
| - Contracts containing `refersTo` validate against updated meta-schema and pass compatibility checks when added to existing identifier fields. | ||
| - Documents with `refersTo.type=identity` + `mustExist:true` are accepted only if the referenced identities exist; missing ones return the new consensus error. | ||
| - Documents without `refersTo`, or with `mustExist:false`, behave exactly as today. | ||
| - Enforcement applies to create and replace transitions (including nested fields) with proper fee accounting for identity lookups. | ||
| - WASM/JS bindings serialize/deserialize `refersTo` metadata; tests cover parsing and state validation failures. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.