Skip to content
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

fix: light DID decoding logic #725

Merged
merged 3 commits into from
Feb 14, 2023
Merged

Conversation

ntn-x2
Copy link
Member

@ntn-x2 ntn-x2 commented Feb 14, 2023

No description provided.

@ntn-x2 ntn-x2 requested a review from rflechtner February 14, 2023 13:36
@ntn-x2 ntn-x2 self-assigned this Feb 14, 2023
Copy link
Contributor

@rflechtner rflechtner left a comment

Choose a reason for hiding this comment

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

I can't see a reason to change the section I flagged but the rest looks good!

Comment on lines 139 to 145
objectToSerialize[SERVICES_MAP_KEY] = service.map(
({ id, serviceEndpoint, type }) => ({
id: resourceIdToChain(id),
serviceEndpoint,
type,
})
)
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm how does this help? I think it was more compatible the way it was before. This way we'll just end up with serialised service endpoints where serviceEndpoint is undefined and url is silently dropped.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is serialization of the new stuff. So new endpoints always serialize to id, serviceEndpoint, type. The trick is in the DEserialization, which attemps to use serviceEndpoint and type, and falls back to types and urls if those are not found.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this snippet here I replaced ...rest, which was anyway just serviceEndpoint and type with its building components.

Copy link
Member Author

Choose a reason for hiding this comment

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

I reverted the use of ...rest and now the unit tests are passing. I was not expecting anything to break actually. Probably I have the wrong understanding of what the spread operator does, or at least of how it's CBOR encoded.

Copy link
Contributor

Choose a reason for hiding this comment

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

so what the spread using ...rest does is transform the id property and keep the remaining properties as-is, whatever they are. If you use explicit key names, you just make assumptions about which keys are there, which then breaks if the keys have different names. If you wanted to make sure that uri is encoded as serviceEndpoints, you'd need to do it the way you do it below. But I think we re-encode on resolving a light did, so that could result in the light did resolving to a different light did.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but I thought that ...rest was indeed those keys. That's why I'm confused.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well not if you're dealing with a legacy DID, then it's the legacy keys

Copy link
Contributor

Choose a reason for hiding this comment

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

although the services validation runs beforehand and should not allow the use of any other keys 🤔 anyway, it's good that we reverted it bc that was not the issue and the remainder syntax is less brittle.

@rflechtner
Copy link
Contributor

before you merge: I realised that even though these old light dids seem to exist, they violate our own specs - so do we really need to support them?

@rflechtner
Copy link
Contributor

At least the example uses the proper keys ([{ id: 'my-service-id', type: ['my-service-type'], serviceEndpoint: ['my-service-url'] }])

@ntn-x2
Copy link
Member Author

ntn-x2 commented Feb 14, 2023

Because we changed the spec. Updating the spec does not mean we should not support old DIDs, right? If we do, that would also be fine, but then the resolver (driver) should not fail with 500 internal error. I think since we have the fix here, it would not hurt to have it in. I also don't expect there to be that many old DIDs left. But some might, and might also even have credentials.

@ntn-x2
Copy link
Member Author

ntn-x2 commented Feb 14, 2023

Or maybe I am still missing something that happens between deserialization and re-serialization. I only know the SDK throws and the DID resolver returns 500. What fix do we want to implement then?

@rflechtner
Copy link
Contributor

Ok let's merge it then.

@ntn-x2 ntn-x2 merged commit c45495b into develop Feb 14, 2023
@ntn-x2 ntn-x2 deleted the aa/fix-light-did-deserialization branch February 14, 2023 15:01
rflechtner pushed a commit that referenced this pull request Feb 21, 2023
* Fix light DID decoding logic

* Remove irrelevant resolver unit test

* Revert usage of ...rest
rflechtner added a commit that referenced this pull request Mar 1, 2023
* fix: jsdocs for public credential fetch* functions (#723)
* fix: light DID decoding logic (#725)
* chore: move DidExporter snippets to docs (#722)
* chore: v0.31.1
---------

Co-authored-by: Antonio <[email protected]>
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