Repository navigation
Conversation
This branch has not been deployed
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.
Summary
Fixes #482:
HeaderMapstored headers in a JSMapkeyed byLabelobjects, butLabelequality is structural whileMap.get/Map.setcompare by reference. Three consequences, all reproduced with failing tests on main first:header()accessor calledthis.headers.get(label)with a freshly builtLabel, so it always returnedundefined;HeaderMap's[Equal.symbol]looked keys up in the other map by reference, so two structurally equalHeaderMaps never compared equal;setAlgorithmIdfollowed bysetHeader(labelFromInt(1n), ...)inserted two distinctLabelobjects for logical key 1, leaving duplicate entries in the map — the exact sequenceEdDSA25519Key.build()performs.Fix
In
packages/evolution/src/cose/Header.ts, following the pattern the working accessors (algorithmId,keyId, …) already use:getLabelhelper looks entries up by iterating withEqual.equals—header()and[Equal.symbol]now use it;setLabelhelper removes any structurally equal key before inserting, and every mutator (setAlgorithmId,setCriticality,setKeyId,setContentType,setInitVector,setPartialInitVector,setHeader) goes through it, so setting an already-present label overwrites instead of duplicating.The CBOR encoding is unchanged: encode already re-keyed by primitive
label.value, where the later entry won, and that is the entry the overwrite now keeps.One scope note: value comparison inside
[Equal.symbol]still usesEqual.equals, which comparesUint8Arrayvalues by reference — that is the pre-existing value semantics across this codebase and is not changed here.Tests
New file
packages/evolution/test/HeaderMap.LabelEquality.test.ts(8 tests), each verified RED on main (run one at a time, since this repo's vitest bails a file after its first failure) and GREEN with the fix:header()returns the value stored under an equal text label (the regression test from COSE HeaderMap: header() and equality use Map reference equality; build() creates duplicate label entries #482) and under an equal int label; returnsundefinedfor a label never set and for a text label"7"vs int label7;HeaderMaps built from distinct but equal labels compare equal in both directions; maps with different values under an equal label do not;setHeaderon an existing logical key leaves one entry holding the new value;setAlgorithmId→setHeader(label 1)sequence leaves a single label-1 entry, andEdDSA25519Key.build()produces no duplicate label-1 entries (header(label 1)is the key type,header(label -1)the curve).Full suite: 1686 passed / 75 skipped / 0 failed, test files 102 passed / 1 skipped of 103 — exactly main's 1678 baseline + the 8 new tests.
tsc --noEmit, eslint and prettier are clean on both touched files, and a patch changeset is included.Independent builder — not affiliated with the Cardano Foundation, IOG or Intersect.
— @Kshot9000 (https://x.com/kshot9000) · Cardano (ADA) donations: addr1q8hnl6vl5a6k3rw3n5g3jtte696zcl76kfatzv7gpswa9r0dj7fma6klq55y4ffm7tf0em09udnyhuk4ah92pl5x9jpqjae44v
cc @cardano-foundation @IntersectMBO