Repository navigation
feat: enforce strict did peer0 invariants - #283
Closed
oleksiipiliugin wants to merge 3 commits into
Closed
oleksiipiliugin wants to merge 3 commits into
oleksiipiliugin wants to merge 3 commits into
Conversation
Extends `_resolveDidPeer0._buildSimpleDoc`'s `forKeyAgreement` predicate so P256, P384 and P521 peer:0 DIDs include a keyAgreement relationship that points to the same VM as the signing relationships, mirroring how `did:key` already resolves these key types via `_buildOtherDoc`. The previous behavior only enabled keyAgreement for x25519 (`6LS`); P256 (`zDn`), P384 (`z82`) and P521 (`z2J9`) peer:0 DIDs ended up without a keyAgreement entry even though the underlying ECDH curves are valid for key agreement. Adds tests in test/did/did_peer_test.dart covering each prefix: - x25519 (6LS): keyAgreement-only, signing slots empty (the originally uncovered branch). - p256 (Dn): signing + keyAgreement on the single VM. - p384 (82): signing + keyAgreement on the single VM. - p521 (2J9): signing + keyAgreement on the single VM. - secp256k1 (Q3s): signing only — guards against accidentally enabling keyAgreement for secp256k1.
When DidPeerManager is constructed with `preferredNumalgo: DidPeerType.peer0` the manager now enforces the same single-key, no-services constraints that DidKeyManager enforces, instead of silently falling back to `did:peer:2` when those constraints are violated. This treats `did:peer:0` as the `did:key`-equivalent encoding it is per spec: one multibase-encoded key, no services. The peer:2 default behavior is unchanged. Changes (all in lib/src/did/did_manager/did_peer_manager.dart): - Override `addVerificationMethod`: when `preferredNumalgo == peer0`, scan existing VMs in the store, look up their wallet keys, and reject with `tooManyVerificationMethods` if a *different* wallet key is already present. Same-key re-entry is allowed so multi-relationship adds and the ed25519→x25519 keyAgreement derivation continue to work. - Override `addServiceEndpoint`: when `preferredNumalgo == peer0`, throw `UnsupportedError` (mirror DidKeyManager.addServiceEndpoint). - Modify `getDidDocument`: when `preferredNumalgo == peer0` and there are no services, collapse multiple stored VMs that share a single wallet key (e.g. ed25519 + derived x25519) down to the single primary key before calling `DidPeer.getDid`. The `_buildEDDoc` resolver derives the keyAgreement entry the same way `did:key` does. `internalAddVerificationMethod` is unchanged — peer:2 remains identical to v3.6.2/v3.8.0, preserving alignment with the Affinidi Rust mediator. The `isDid0` gate in `DidPeer.getDid` is also unchanged so the static public API stays safe for direct callers. Adds 6 new tests in test/did/did_manager/did_peer_manager_test.dart (group: "Strict did:peer:0 semantics"): - rejects a second wallet key with tooManyVerificationMethods - allows re-entry for the SAME wallet key (multi-relationship adds) - rejects addServiceEndpoint with UnsupportedError - single ed25519 + keyAgreement still produces did:peer:0 (mirrors did:key) - single p256 + multiple relationships produces did:peer:0 - default (peer2) manager still allows multiple keys and services
…hapes Adds three regression tests in the existing DidPeerManager > "DID generation" group to lock in that the default peer:2 manager never auto-collapses single-key/no-service shapes down to did:peer:0. Pre-PR, the static `DidPeer.getDid` would have done so for the same inputs (b12ef59 / upstream-without-`preferredNumalgo`), so this guards the intent of the new `preferredNumalgo: DidPeerType.peer2` default at the manager level. Cases covered: - 1 key (p256) + 1 relationship (authentication) + 0 services -> did:peer:2 with a `.Vz` key entry (not did:peer:0). - 1 ed25519 key + auth+keyAgreement + 0 services -> did:peer:2 with `.Vz` and `.Ez` entries and 2 VMs (not collapsed to a did:key-style ed25519+derived-x25519 did:peer:0 doc). - 1 key + empty relationship set -> manager throws SsiException with code `invalidDidDocument`, asserting the manager neither silently produces a relationships-less did:peer:0 nor a relationships-less did:peer:2.
oleksiipiliugin
changed the base branch from
main
to
feat/did-manager-multi-key-support-did-web-did-peer
April 24, 2026 13:31
|
Coverage after merging feat/did-peer-strict-peer0 into main will be
Coverage Report |
Contributor
Author
|
Rearranged commits in the PR |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request introduces several improvements and fixes to the DID and credential management logic, with a focus on standards compliance, deterministic ID generation, and proper handling of DID method variants. The most significant changes are the addition of strict support for
did:peer:0inDidPeerManager, improved JWK thumbprint-based verification method IDs fordid:web, and various fixes to ensure correct key usage and relationships.DID Peer Manager:
did:peer:0strict mode and resolution improvementspreferredNumalgooption toDidPeerManager, enabling strict enforcement ofdid:peer:0rules (single wallet key, no services) and fast-path resolution for peer0 DIDs. [1] [2]did:peer:0and pass the preferred numalgo through to DID construction.DID Web Manager: Deterministic JWK thumbprint-based VM IDs and key handling
buildVerificationMethodIdinDidWebManagerto use the JWK thumbprint (RFC 7638) of the public key for deterministic, standards-compliant verification method IDs.Credential and proof generation: Consistent use of
didKeyIdsigner.didKeyIdinstead ofsigner.keyIdfor JWT headers, proof verification methods, and related fields, ensuring correct DID-based key references. [1] [2] [3] [4] [5] [6] [7] [8] [9]DID Peer and Web: Standards compliance and bugfixes
did:peer:2resolution to use the full DID URL, not just a fragment.did:peer:0resolver to recognize additional key types for key agreement, improving compatibility.Other improvements
These changes collectively improve standards compliance, deterministic behavior, and robustness in the handling of DIDs and credentials.