fix: accept HIGH security level keys for profile updates#762
fix: accept HIGH security level keys for profile updates#762thepastaclaw wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe identity signing key selection logic in Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
claw please find and quote documents (eg. DIP) defining which keys we should use |
Security Level Requirements — DIP-0011 + Platform Contract DefaultsDIP-0011 (Identities) — Key Security LevelsDIP-0011 § Keys defines the security levels and their intended use:
DIP-0011 also states:
Platform Default Security LevelIn the Platform codebase, the document type schema parser sets a default when no // packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v0/mod.rs
let security_level_requirement = schema
.get_optional_integer::<u8>(property_names::SECURITY_LEVEL_REQUIREMENT)
.map_err(consensus_or_protocol_value_error)?
.map(SecurityLevel::try_from)
.transpose()?
.unwrap_or(SecurityLevel::HIGH); // <-- default is HIGHDashPay Contract — Profile Document TypeThe DashPay contract schema ( This means ConsistencyThis PR aligns HashSet::from([SecurityLevel::CRITICAL, SecurityLevel::HIGH]), |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
✅ Review complete (commit 5d04b88) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
The fix in update_profile() correctly adds SecurityLevel::HIGH to the AUTHENTICATION key matching set, mirroring the established pattern at contact_requests.rs:639. The change is minimal, focused, and correct. Both reviewers converge on the same gap: no automated coverage for the HIGH-only key path. A secondary nit notes growing duplication of the key-selection policy across three DashPay call sites.
Reviewed commit: 921c1de
🟡 1 suggestion(s) | 💬 1 nitpick(s)
2 additional findings
🟡 suggestion: HIGH-only authentication-key path has no regression test
src/backend_task/dashpay/profile.rs (lines 122-130)
The fix changes the key-selection filter in update_profile() to accept SecurityLevel::HIGH — the entire bug fix from #760 — but no test exercises an identity carrying only HIGH-level AUTHENTICATION keys (the wallet-imported case). Without coverage, a future refactor could narrow the filter again and cargo test/clippy would still pass. Per CLAUDE.md, new backend logic should have unit/integration tests. Add a focused unit test that constructs a QualifiedIdentity with only a HIGH-level AUTHENTICATION key and asserts that update_profile()'s key-lookup step succeeds (does not return MissingAuthenticationKey). A kittest scenario driving the profile edit flow with a wallet-imported identity would also work.
💬 nitpick: DashPay key-selection policy duplicated across three call sites
src/backend_task/dashpay/profile.rs (lines 121-130)
profile.rs (122-130, post-fix), contact_requests.rs (635-644), and contact_info.rs (391-403) each independently call get_first_public_key_matching with overlapping but slightly different SecurityLevel sets — profile/contact_requests use CRITICAL+HIGH while contact_info uses CRITICAL+HIGH+MEDIUM and is also restricted to ECDSA_SECP256K1. This drift is exactly what produced the bug being fixed. A small helper (e.g. signing_key_for_dashpay_document(identity, doc_type) -> Result<&IdentityPublicKey, DashPayError>) would centralise the policy and make the relationship to Platform's required document security level explicit. Out of scope for a one-line fix, but worth a follow-up.
🤖 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 `src/backend_task/dashpay/profile.rs`:
- [SUGGESTION] lines 122-130: HIGH-only authentication-key path has no regression test
The fix changes the key-selection filter in update_profile() to accept SecurityLevel::HIGH — the entire bug fix from #760 — but no test exercises an identity carrying only HIGH-level AUTHENTICATION keys (the wallet-imported case). Without coverage, a future refactor could narrow the filter again and `cargo test`/`clippy` would still pass. Per CLAUDE.md, new backend logic should have unit/integration tests. Add a focused unit test that constructs a QualifiedIdentity with only a HIGH-level AUTHENTICATION key and asserts that update_profile()'s key-lookup step succeeds (does not return MissingAuthenticationKey). A kittest scenario driving the profile edit flow with a wallet-imported identity would also work.
The profile update code only accepted CRITICAL level authentication keys, but Platform's default document security level requirement is HIGH. This caused 'missing authentication key' errors for identities imported from wallets, which typically have HIGH level keys. Accept both CRITICAL and HIGH security level keys, consistent with how contact_requests.rs already handles this. Fixes dashpay#760
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Both reviewers converge on a single nitpick: the CRITICAL+HIGH AUTHENTICATION key-selection policy newly centralized in profile.rs::profile_authentication_key is still hand-rolled in contact_requests.rs and a related variant in contact_info.rs. The prior test-coverage gap is fully resolved by the new unit tests in profile.rs. No blocking issues.
Reviewed commit: 5d04b88
💬 1 nitpick(s)
| fn profile_authentication_key( | ||
| identity: &Identity, | ||
| ) -> Result<&dash_sdk::platform::IdentityPublicKey, TaskError> { | ||
| identity | ||
| .get_first_public_key_matching( | ||
| Purpose::AUTHENTICATION, | ||
| HashSet::from([SecurityLevel::CRITICAL, SecurityLevel::HIGH]), | ||
| KeyType::all_key_types().into(), | ||
| false, | ||
| ) | ||
| .ok_or_else(|| TaskError::DashPay(DashPayError::MissingAuthenticationKey)) | ||
| } |
There was a problem hiding this comment.
💬 Nitpick: DashPay AUTHENTICATION key-selection policy still duplicated across modules
This PR introduces profile_authentication_key() in profile.rs to centralize the AUTHENTICATION + {CRITICAL, HIGH} selection rule, but the identical policy is still open-coded in contact_requests.rs:635-643, and a related CRITICAL+HIGH+MEDIUM/ECDSA_SECP256K1-only variant lives in contact_info.rs:391-403. This is exactly the drift pattern that caused #760 — profile.rs previously accepted only CRITICAL while contact_requests.rs already accepted CRITICAL+HIGH. Keeping the helper module-private in profile.rs makes it easy for the next contributor to miss when Platform's required document security level changes again. Consider promoting the helper to a shared DashPay module (e.g. dashpay::keys::document_signing_key(identity)) and reusing it from contact_requests.rs, with contact_info.rs either using the same helper or a clearly-named sibling that documents why it allows MEDIUM and restricts to ECDSA_SECP256K1. Out of scope for a one-line fix — not blocking.
source: ['claude', 'codex']
Issue
Closes #760 — Editing a profile with a wallet-imported identity fails with "This identity is missing an authentication key required for this operation."
Root Cause
update_profile()insrc/backend_task/dashpay/profile.rsonly looked for authentication keys atSecurityLevel::CRITICAL, but Platform's default document security level requirement isHIGH. Wallet-imported identities typically haveHIGH-level keys, notCRITICAL, so the key lookup failed.Fix
Accept both
CRITICALandHIGHsecurity levels when searching for a signing key inupdate_profile(), consistent with howcontact_requests.rsalready handles authentication key lookup (line 639).Testing
cargo check,cargo clippy— cleanSummary by CodeRabbit