Skip to content

Conversation

MichaelMure
Copy link
Member

@MichaelMure MichaelMure commented Jul 23, 2025

Turns out, PayloadEncoding can be multiple values for EIP191, which required some painful changes.

@MichaelMure MichaelMure requested review from smoyer64 and Copilot July 23, 2025 09:00
Copilot

This comment was marked as outdated.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the payload encoding system in the varsig library to better support iso-ucan compatibility. The changes implement a more sophisticated encoding scheme where some payload types (like EIP191) require multiple encoding segments, replacing the previous single-value approach.

  • Refactored PayloadEncoding from uint64 constants to int enum with separate encoding segments
  • Updated encoding/decoding logic to handle multi-segment encodings (especially EIP191 variants)
  • Added comprehensive test coverage for all preset signature algorithms with round-trip validation

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
constant.go Major refactoring of PayloadEncoding system with new multi-segment encoding logic
common.go Added new ECDSA preset functions (ES256, ES256K, ES384, ES512, EIP191)
common_test.go Comprehensive test suite for all presets with iso-ucan compatibility validation
varsig_test.go Removed unused helper functions and imports
rsa.go Updated to use new EncodePayloadEncoding function
eddsa.go Updated to use new EncodePayloadEncoding function
ecdsa.go Updated to use new EncodePayloadEncoding function
Comments suppressed due to low confidence (1)

common_test.go:15

  • The function name 'TestName' is not descriptive. It should be renamed to describe what it's testing, such as 'TestUvarintDecoding' or similar based on its purpose.
func TestName(t *testing.T) {

Copy link
Collaborator

@smoyer64 smoyer64 left a comment

Choose a reason for hiding this comment

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

So this essentially combines our original tests and those that Hugo created, then makes them pass by fixing e191?

case Version0:
return decodeEncodingInfoV0(payEnc)
switch seg1 {
case encodingSegmentVerbatim:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The cases which simply return the switched value and nil can be combined using the switch variable (2 typ.)

}
}

func roundTrip[T varsig.Varsig](t *testing.T, in T, expEncHex string) T {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like we should round-trip at least one varsig just to verify what what we put in is also what we get out. I'm thinking of test vectors that allow this (JSON?) similar to those provided for did:key eventually.

Copy link
Member Author

Choose a reason for hiding this comment

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

That round-trip still happens, it's just moved into that unified table test.

@MichaelMure MichaelMure merged commit 35ef54f into main Jul 24, 2025
1 check passed
@MichaelMure MichaelMure deleted the tests branch July 24, 2025 14:53
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