Documentation ¶
Overview ¶
Package resolver provides a "DIF Universal Resolver" handler and driver implementation.
DID resolution is the process of obtaining a DID document for a given DID. This is one of four required operations that can be performed on any DID ("Read"; the other ones being "Create", "Update", and "Deactivate"). The details of these operations differ depending on the DID method. Building on top of DID resolution, DID URL dereferencing is the process of retrieving a representation of a resource for a given DID URL. Software and/or hardware that is able to execute these processes is called a DID resolver.
More information: https://w3c-ccg.github.io/did-resolution
Index ¶
Constants ¶
const ( // ContentTypeLD instructs the resolution endpoint to return // standard JSON LD data. ContentTypeLD = "application/ld+json" // ContentTypeDocument instructs the resolution endpoint to // return the obtained DID document as result. ContentTypeDocument = "application/did+ld+json" // ContentTypeWithProfile instructs the resolution endpoint to // return a complete resolution response structure as result. If // no value is provided in the `Accept` header, this will be the // default behavior. // https://w3c-ccg.github.io/did-resolution/#output-didresolutionresult ContentTypeWithProfile = "application/ld+json;profile=\"https://w3id.org/did-resolution\"" )
Common content-type IANA values.
const ( // An unexpected error occurs during DID Resolution or DID URL // dereferencing. // https://w3c-ccg.github.io/did-resolution/#internalerror ErrInternal = "internalError" // During DID Resolution or DID URL dereferencing a DID or DID URL // doesn't exist. // https://w3c-ccg.github.io/did-resolution/#notfound ErrNotFound = "notFound" // An invalid DID is detected during DID Resolution. // https://w3c-ccg.github.io/did-resolution/#invaliddid ErrInvalidDID = "invalidDid" // An invalid DID URL is detected during DID Resolution or DID // URL dereferencing. // https://w3c-ccg.github.io/did-resolution/#invaliddidurl ErrInvalidURL = "invalidDidUrl" // Obtained DID document is invalid. ErrInvalidDocument = "invalidDidDocument" // DID method is not supported during DID Resolution or DID URL // dereferencing. // https://w3c-ccg.github.io/did-resolution/#methodnotsupported ErrMethodNotSupported = "methodNotSupported" // DID document representation is not supported during DID Resolution // or DID URL dereferencing. // https://w3c-ccg.github.io/did-resolution/#representationnotsupported ErrRepresentationNotSupported = "representationNotSupported" )
Common error codes. https://w3c-ccg.github.io/did-resolution/#errors
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encoder ¶
type Encoder interface { // Encode an existing DID document to a valid representation. // If an error is returned is must be a valid error code as // defined in the spec. Encode(doc *did.Document) ([]byte, error) }
Encoder instances can be used to generate different representations for a resolved DID document.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance elements are the main utility provided by the `resolver` package. A resolver instance can be used to provided the low level resolve functions as well as exposing it through a compliant HTTP endpoint intended for public consumption. https://w3c-ccg.github.io/did-resolution/#resolving-algorithm
func (*Instance) ResolutionHandler ¶
func (ri *Instance) ResolutionHandler(rw http.ResponseWriter, rq *http.Request)
ResolutionHandler exposes the `resolve` operations through an HTTP endpoint compatible with the DIF specification. https://w3c-ccg.github.io/did-resolution/#bindings-https
func (*Instance) Resolve ¶
func (ri *Instance) Resolve(id string, opts *ResolutionOptions) (*Result, error)
Resolve a DID into a DID document by using the "Read" operation of the applicable DID method. https://www.w3.org/TR/did-core/#did-resolution
func (*Instance) ResolveRepresentation ¶
func (ri *Instance) ResolveRepresentation(id string, opts *ResolutionOptions) (*Result, error)
ResolveRepresentation attempts to resolve a DID into a DID document by using the "Read" operation of the applicable DID method and encode a suitable representation based on the options provided. https://www.w3.org/TR/did-core/#did-resolution
type Option ¶
Option definitions provide a functional-style configuration mechanism for new resolver instances.
func WithEncoder ¶
WithEncoder registers/enables a DID document encoded with the resolver instance. The encoder `enc` will be responsible of production valid representations when requested by the user using `mime` data type. A default JSON encoder is registered by default for content types:
- application/ld+json
- application/did+ld+json
- application/ld+json;profile="https://w3id.org/did-resolution"
func WithProvider ¶
WithProvider registers/enables a DID method handler with the resolver instance.
type Provider ¶
type Provider interface { // Read the details available on the verifiable data registry // for a specific `did` entry. DID document metadata is optional // but recommended. // - If an error is returned is must be a valid error code as defined // in the spec. // - If no error AND no DID document are returned, a "notFound" error // will be returned by the resolver. // https://w3c-ccg.github.io/did-resolution/#errors Read(did string) (*did.Document, *did.DocumentMetadata, error) }
Provider instances are method-specific and abstract away the details on how to interact with the verifiable data registry being used.
type ResolutionMetadata ¶
type ResolutionMetadata struct { // Media type of the returned content. ContentType string `json:"contentType"` // Date and time of the DID resolution process. Retrieved string `json:"retrieved"` // Error code, if any. Error string `json:"error,omitempty"` }
ResolutionMetadata contains information about the DID Resolution process. This metadata typically changes between invocations of the DID Resolution functions as it represents data about the resolution process itself. The source of this metadata is the DID resolver.
type ResolutionOptions ¶
type ResolutionOptions struct { // The Media Type of the caller's preferred representation of the DID document. // The Media Type MUST be expressed as an ASCII string. The DID resolver // implementation SHOULD use this value to determine the representation // contained in the returned `didDocumentStream` if such a representation // is supported and available. This property is OPTIONAL for the // `resolveRepresentation` function and MUST NOT be used with the `resolve` // function. // If not provided, `application/did+ld+json` will be used by default. Accept string `json:"accept"` }
ResolutionOptions provides additional settings available when processing a "resolve" request.
func (*ResolutionOptions) FromRequest ¶
func (ro *ResolutionOptions) FromRequest(req *http.Request)
FromRequest loads resolution options from an incoming HTTP request.
func (*ResolutionOptions) Validate ¶
func (ro *ResolutionOptions) Validate() error
Validate the resolution options provided and load sensible default values.
type Result ¶
type Result struct { // JSON-LD context statement for the document. // https://w3c-ccg.github.io/did-spec/#context Context []interface{} `json:"@context" yaml:"-"` // Resolved DID document. Document *did.Document `json:"didDocument,omitempty"` // DID document metadata. DocumentMetadata *did.DocumentMetadata `json:"didDocumentMetadata,omitempty"` // Resolution process metadata. ResolutionMetadata *ResolutionMetadata `json:"didResolutionMetadata,omitempty"` // Representation obtained from the DID document during a // `resolveRepresentation` operation. Representation []byte `json:"-"` }
Result obtained from a "resolution" process. https://w3c-ccg.github.io/did-resolution/#output-didresolutionresult