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

feat!: Updated resolve method signature #82

Merged
merged 2 commits into from
Mar 2, 2021
Merged

feat!: Updated resolve method signature #82

merged 2 commits into from
Mar 2, 2021

Conversation

oed
Copy link
Contributor

@oed oed commented Mar 1, 2021

This PR changes the resolve method signature according to #79

It also updates the DIDDocument interface to be compliant with the latest did-core spec.

Question about the last test: Why do we not want to cache null results, i.e. notFound? Seems to me that we should cache that just the same way we cache any other result?
Skipped this test for now.

The readme for this repo will need a revamp.

Copy link
Member

@mirceanis mirceanis left a comment

Choose a reason for hiding this comment

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

Thank you very much for this contribution!

I have some comments about future-proofing and backward compatibility. Please take a look.

src/resolver.ts Outdated Show resolved Hide resolved
if (!resolver) {
throw new Error(`Unsupported DID method: '${parsed.method}'`)
}
return this.cache(parsed, () => resolver(parsed.did, parsed, this, options))
Copy link
Member

Choose a reason for hiding this comment

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

I believe this can be made backward compatible if the result is inspected.
It should be easy to check for result.hasOwnProperty('didResolutionMetadata'), didDocument, and/or didDocumentMetadata since none of these fields are part of the DIDDocument return type of resolvers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However, the old DIDDocument type is not compatible with the new one and would need to be converted somehow. Also all baseXX encoding are not supported anymore, so we would need to do some conversion there.

Copy link
Member

Choose a reason for hiding this comment

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

right, but there is no check here either for the correct DIDDocument format coming from the method implementations. the result is simply bubbled up.
The only check is done by the IDE/transpiler in case the method implementation is also using typescript, but that is not really a guarantee.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but what are you suggesting instead?

Copy link
Member

Choose a reason for hiding this comment

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

To inspect the result and wrap it if it's legacy:

Suggested change
return this.cache(parsed, () => resolver(parsed.did, parsed, this, options))
return this.cache(parsed, () => {
let result = null
try {
result = await resolver(parsed.did, parsed, this, options)
} catch (e) {
return {
didResolutionMetadata: {
error: 'notFound' // or perhaps another error code
message: e.toString() // This is not in spec, nut may be helpful
},
didDocument: null,
didDocumentMetadata: {}
}
}
if (!result.hasOwnProperty('didResolutionMetadata')
&& !result.hasOwnProperty('didDocumentMetadata')
&& !result.hasOwnProperty('didDocument')) {
return {didResolutionMetadata: {}, didDocument: result, didDocumentMetadata: {}}
} else {
return result
}
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't like this because it will confuse the method signature of the DIDResolver to return either DIDResolutionResult or DIDDocument.

src/resolver.ts Show resolved Hide resolved
src/resolver.ts Show resolved Hide resolved
src/resolver.ts Outdated Show resolved Hide resolved
src/__tests__/resolver-test.ts Outdated Show resolved Hide resolved
src/resolver.ts Show resolved Hide resolved
@oed
Copy link
Contributor Author

oed commented Mar 2, 2021

Pushed an update with support for letgacy did resolvers.

@oed oed requested a review from mirceanis March 2, 2021 11:20
Copy link
Member

@mirceanis mirceanis left a comment

Choose a reason for hiding this comment

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

thanks, much appreciated!
It's sad that it still has to be a breaking change, but if it's the best we can do then let's merge it like this.

if (doc !== null) {
cache.set(parsed.didUrl, doc)
const result = await resolve()
if (result.didResolutionMetadata?.error !== 'notFound') {
Copy link
Member

Choose a reason for hiding this comment

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

Why do you think errors should be cached?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just don't see why notFound should be treated differently from when something is found. Doesn't matter too much though.

Copy link
Member

Choose a reason for hiding this comment

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

no, I mean why cache ANY error results?

@mirceanis mirceanis merged commit 313e685 into decentralized-identity:master Mar 2, 2021
uport-automation-bot pushed a commit that referenced this pull request Mar 2, 2021
# [3.0.0](2.2.0...3.0.0) (2021-03-02)

### Features

* update resolve method signature to match did core spec ([#82](#82)) ([313e685](313e685)), closes [#79](#79)

### BREAKING CHANGES

* the `Resolver` and `DIDResolver` data types have been upgraded.
To use a legacy resolver that simply returns a `DIDDocument`, please register it under the `options.legacyResolvers` constructor param
@uport-automation-bot
Copy link
Collaborator

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@uport-automation-bot uport-automation-bot added the spec more parties need to agree label Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec more parties need to agree
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants