-
Notifications
You must be signed in to change notification settings - Fork 19
#3663: change credentialsubject to map, use casting instead of marshalling where possible #3739
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
Conversation
…lling where possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and pending performance test of course
credentialSubject := make([]credential.BaseCredentialSubject, 0) | ||
err := organization.UnmarshalCredentialSubject(&credentialSubject) | ||
if err != nil { | ||
return nil, did.DID{}, fmt.Errorf("unable to get DID from organization credential: %w", err) | ||
} | ||
organizationDIDStr := credentialSubject[0].ID | ||
organizationDID, err := did.ParseDID(organizationDIDStr) | ||
organizationDID, err := organization.SubjectDID() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is now a stricter check since VerifiableCredential.SubjectDID() checks if all credentialSubject.IDs are the same compared to just parsing the first value.
go.mod
Outdated
github.com/nats-io/nats.go v1.39.1 | ||
github.com/nuts-foundation/crypto-ecies v0.0.0-20211207143025-5b84f9efce2b | ||
github.com/nuts-foundation/go-did v0.15.0 | ||
github.com/nuts-foundation/go-did v0.15.1-0.20250319081900-aa2a47f72926 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update after go-did is tagged (and probably run go mod tidy
for cleanup of go.sum)
|
||
import "encoding/json" | ||
|
||
func remarshal(src interface{}, dst interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dst
in the signature should probably be a pointer to match unmarshal behavior. the least line should then be return json.Unmarshal(asJSON, dst)
for _, b := range bl { | ||
if b.ID != "" { | ||
// check credentialSubject | ||
subjectDID, err := did.ParseDID(b.ID) | ||
if err == nil { | ||
if !slices.Contains(didMethods, subjectDID.Method) { | ||
continue outer | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this used to require only one subjectDID to be valid, but credential.SubjectDID()
now requires all to be valid and have the same value.
Test
So currently, no measurable benefit. |
its hard to give a meaningful interpretation to this without the profiler results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly better code, but unfortunately no real gain.
I still cannot make any conclusions based on these results. Subtracting the wait time and looking at the difference based on the information I have the gain could ~6% (=1-16/17).
|
even without performance gains, it cleans up the code (a bit)? |
Agreed, but other comments above still stand. |
Superseded by #3811 |
This lower the amount of (now unnecessary) casting and JSON unmarshalling we do.
TODO: