Skip to content

Commit

Permalink
Resolver improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ntn-x2 committed Oct 3, 2023
1 parent dd3148c commit 812a360
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 38 deletions.
3 changes: 2 additions & 1 deletion packages/did/src/DidResolver/DidResolverV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export async function resolve(
}
}

const { documentMetadata: didDocumentMetadata, document: didDocument } = resolutionResult
const { documentMetadata: didDocumentMetadata, document: didDocument } =
resolutionResult

return {
didResolutionMetadata: {},
Expand Down
54 changes: 17 additions & 37 deletions packages/types/src/DidResolverV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,19 @@ import type {
*/
export type ResolutionOptions = Record<string, never>

/*
* This specification defines the following common error values:
* invalidDid: The DID supplied to the DID resolution function does not conform to valid syntax.
* notFound: The DID resolver was unable to find the DID document resulting from this resolution request.
*/
type ResolutionMetadataError = 'invalidDid' | 'notFound'

export type SuccessfulResolutionMetadata = Record<string, never>
export type FailedResolutionMetadata = {
export type ResolutionMetadata = {
/*
* The error code from the resolution process.
* This property is REQUIRED when there is an error in the resolution process.
* The value of this property MUST be a single keyword ASCII string.
* The possible property values of this field SHOULD be registered in the DID Specification Registries.
* This specification defines the following common error values:
* invalidDid: The DID supplied to the DID resolution function does not conform to valid syntax.
* notFound: The DID resolver was unable to find the DID document resulting from this resolution request.
*/
error: ResolutionMetadataError
error?: 'invalidDid' | 'notFound'
}

export type ResolutionMetadata =
| SuccessfulResolutionMetadata
| FailedResolutionMetadata

export type ResolutionDocumentMetadata = {
/*
* If a DID has been deactivated, DID document metadata MUST include this property with the boolean value true.
Expand Down Expand Up @@ -92,17 +83,6 @@ export type RepresentationResolutionOptions<Accept extends string> = {
accept?: Accept
}

/*
* This specification defines the following common error values:
* invalidDid: The DID supplied to the DID resolution function does not conform to valid syntax.
* notFound: The DID resolver was unable to find the DID document resulting from this resolution request.
* representationNotSupported: This error code is returned if the representation requested via the accept input metadata property is not supported by the DID method and/or DID resolver implementation.
*/
type RepresentationResolutionMetadataError =
| 'invalidDid'
| 'notFound'
| 'representationNotSupported'

export type SuccessfulRepresentationResolutionMetadata<
ContentType extends string
> = {
Expand All @@ -121,10 +101,15 @@ export type FailedRepresentationResolutionMetadata = {
* This property is REQUIRED when there is an error in the resolution process.
* The value of this property MUST be a single keyword ASCII string.
* The possible property values of this field SHOULD be registered in the DID Specification Registries.
* This specification defines the following common error values:
* invalidDid: The DID supplied to the DID resolution function does not conform to valid syntax.
* notFound: The DID resolver was unable to find the DID document resulting from this resolution request.
* representationNotSupported: This error code is returned if the representation requested via the accept input metadata property is not supported by the DID method and/or DID resolver implementation.
*/
error: RepresentationResolutionMetadataError
error: 'invalidDid' | 'notFound' | 'representationNotSupported'
}

// Either success with `contentType` or failure with `error`
export type RepresentationResolutionMetadata<ContentType extends string> =
| SuccessfulRepresentationResolutionMetadata<ContentType>
| FailedRepresentationResolutionMetadata
Expand Down Expand Up @@ -185,13 +170,6 @@ export type DereferenceOptions<Accept extends string> = {
accept?: Accept
}

/*
* This specification defines the following common error values:
* invalidDidUrl: The DID URL supplied to the DID URL dereferencing function does not conform to valid syntax. (See 3.2 DID URL Syntax.)
* notFound: The DID URL dereferencer was unable to find the contentStream resulting from this dereferencing request.
*/
type DereferenceMetadataError = 'invalidDidUrl' | 'notFound'

export type SuccessfulDereferenceMetadata<ContentType extends string> = {
/*
* The Media Type of the returned contentStream SHOULD be expressed using this property if dereferencing is successful.
Expand All @@ -205,10 +183,14 @@ export type FailedDereferenceMetadata = {
* This property is REQUIRED when there is an error in the dereferencing process.
* The value of this property MUST be a single keyword expressed as an ASCII string.
* The possible property values of this field SHOULD be registered in the DID Specification Registries [DID-SPEC-REGISTRIES].
* This specification defines the following common error values:
* invalidDidUrl: The DID URL supplied to the DID URL dereferencing function does not conform to valid syntax. (See 3.2 DID URL Syntax.)
* notFound: The DID URL dereferencer was unable to find the contentStream resulting from this dereferencing request.
*/
error: DereferenceMetadataError
error: 'invalidDidUrl' | 'notFound'
}

// Either success with `contentType` or failure with `error`
export type DereferenceMetadata<ContentType extends string> =
| SuccessfulDereferenceMetadata<ContentType>
| FailedDereferenceMetadata
Expand All @@ -222,9 +204,7 @@ export type DereferenceContentStream =
| JsonLd<Service>
| Buffer

export type DereferenceContentMetadata =
| ResolutionDocumentMetadata
| Record<string, never>
export type DereferenceContentMetadata = ResolutionDocumentMetadata

export type DereferenceResult<ContentType extends string> = {
/*
Expand Down

0 comments on commit 812a360

Please sign in to comment.