Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddVMOption ¶
type AddVMOption func(o *addVMOptions)
AddVMOption is a type returned by all AddVerificationMethod options for variadic parameter support
func Purposes ¶
func Purposes(p ...Purpose) AddVMOption
Purposes can be used to select a verification method with a specific purpose.
type Document ¶
type Document struct { // Context is a URI that defines the schema version used in the document. Context []string `json:"@context,omitempty"` // Id is the DID URI for a particular DID subject, expressed using the id property in the DID document. ID string `json:"id"` // AlsoKnownAs can contain multiple identifiers for different purposes, or at different times for the same DID subject. // The assertion that two or more DIDs (or other types of URI) refer to the same DID subject can be made using the alsoKnownAs property. AlsoKnownAs []string `json:"alsoKnownAs,omitempty"` // Controller defines an entity that is authorized to make changes to a DID document. // The process of authorizing a DID controller is defined by the DID method. // It can be a string or a list of strings. Controller []string `json:"controller,omitempty"` // VerificationMethod is a list of cryptographic public keys, which can be used to authenticate or authorize // interactions with the DID subject or associated parties. VerificationMethod []VerificationMethod `json:"verificationMethod,omitempty"` // Service expresses ways of communicating with the DID subject or associated entities. // A service can be any type of service the DID subject wants to advertise. // spec reference: https://www.w3.org/TR/did-core/#verification-methods Service []Service `json:"service,omitempty"` // AssertionMethod is used to specify how the DID subject is expected to express claims, // such as for the purposes of issuing a Verifiable Credential. AssertionMethod []string `json:"assertionMethod,omitempty"` // Authentication specifies how the DID subject is expected to be authenticated, // for purposes such as logging into a website or engaging in any sort of challenge-response protocol. Authentication []string `json:"authentication,omitempty"` // KeyAgreement specifies how an entity can generate encryption material to transmit confidential // information intended for the DID subject, such as for establishing a secure communication channel. KeyAgreement []string `json:"keyAgreement,omitempty"` // CapabilityDelegation specifies a mechanism used by the DID subject to delegate a // cryptographic capability to another party, such as delegating the authority to access a specific HTTP API. CapabilityDelegation []string `json:"capabilityDelegation,omitempty"` // CapabilityInvocation specifies a verification method used by the DID subject to invoke a // cryptographic capability, such as the authorization to update the DID Document. CapabilityInvocation []string `json:"capabilityInvocation,omitempty"` }
Document represents a set of data describing the DID subject including mechanisms such as:
- cryptographic public keys - used to authenticate itself and prove association with the DID
- services - means of communicating or interacting with the DID subject or associated entities via one or more service endpoints. Examples include discovery services, agent services, social networking services, file storage services, and verifiable credential repository services.
A DID Document can be retrieved by resolving a DID URI.
func (*Document) AddService ¶
AddService will append the given Service to the Document.Services array
func (*Document) AddVerificationMethod ¶
func (d *Document) AddVerificationMethod(method VerificationMethod, opts ...AddVMOption)
AddVerificationMethod adds a verification method to the document. if Purposes are provided, the verification method's ID will be added to the corresponding list of purposes.
func (*Document) GetAbsoluteResourceID ¶
GetAbsoluteResourceID returns a fully qualified ID for a document resource (e.g. service, verification method) Document Resource IDs are allowed to be relative DID URLs as a means to reduce storage size of DID Documents. More info here: https://www.w3.org/TR/did-core/#relative-did-urls
func (*Document) SelectVerificationMethod ¶
func (d *Document) SelectVerificationMethod(selector VMSelector) (VerificationMethod, error)
SelectVerificationMethod takes a selector that can be used to select a specific verification method from the DID Document. If a nil selector is provided, the first verification method is returned
The selector can either be an ID, Purpose, or nil. If a Purpose is provided, the first verification method in the DID Document that has the provided purpose will be returned.
type DocumentMetadata ¶
type DocumentMetadata struct { // timestamp of the Create operation. The value of the property MUST be a // string formatted as an XML Datetime normalized to UTC 00:00:00 and // without sub-second decimal precision. For example: 2020-12-20T19:17:47Z. Created string `json:"created,omitempty"` // timestamp of the last Update operation for the document version which was // resolved. The value of the property MUST follow the same formatting rules // as the created property. The updated property is omitted if an Update // operation has never been performed on the DID document. If an updated // property exists, it can be the same value as the created property // when the difference between the two timestamps is less than one second. Updated string `json:"updated,omitempty"` // If a DID has been deactivated, DID document metadata MUST include this // property with the boolean value true. If a DID has not been deactivated, // this property is OPTIONAL, but if included, MUST have the boolean value // false. Deactivated bool `json:"deactivated,omitempty"` // indicates the version of the last Update operation for the document version // which was resolved. VersionID string `json:"versionId,omitempty"` // indicates the timestamp of the next Update operation. The value of the // property MUST follow the same formatting rules as the created property. NextUpdate string `json:"nextUpdate,omitempty"` // if the resolved document version is not the latest version of the document. // It indicates the timestamp of the next Update operation. The value of the // property MUST follow the same formatting rules as the created property. NextVersionID string `json:"nextVersionId,omitempty"` // A DID method can define different forms of a DID that are logically // equivalent. An example is when a DID takes one form prior to registration // in a verifiable data registry and another form after such registration. // In this case, the DID method specification might need to express one or // more DIDs that are logically equivalent to the resolved DID as a property // of the DID document. This is the purpose of the equivalentId property. EquivalentID []string `json:"equivalentId,omitempty"` // The canonicalId property is identical to the equivalentId property except: // * it is associated with a single value rather than a set // * the DID is defined to be the canonical ID for the DID subject within // the scope of the containing DID document. CanonicalID string `json:"canonicalId,omitempty"` }
DocumentMetadata contains metadata about the DID Document This metadata typically does not change between invocations of the resolve and resolveRepresentation functions unless the DID document changes, as it represents metadata about the DID document.
Spec: https://www.w3.org/TR/did-core/#dfn-diddocumentmetadata
type MethodResolver ¶
type MethodResolver interface { Resolve(uri string) (ResolutionResult, error) ResolveWithContext(ctx context.Context, uri string) (ResolutionResult, error) }
MethodResolver is an interface that can be implemented for resolving specific DID methods. Each concrete implementation should adhere to the DID core specficiation defined here: https://www.w3.org/TR/did-core/#did-resolution
type Purpose ¶
type Purpose string
Purpose can be used to select a verification method with a specific purpose.
const ( // PurposeAssertion is used for asserting claims PurposeAssertion Purpose = "assertionMethod" // PurposeAuthentication is used for authentication PurposeAuthentication Purpose = "authentication" // PurposeCapabilityDelegation is used for delegating capabilities PurposeCapabilityDelegation Purpose = "capabilityDelegation" // PurposeCapabilityInvocation is used for invoking capabilities PurposeCapabilityInvocation Purpose = "capabilityInvocation" // PurposeKeyAgreement is used for key agreement protocols PurposeKeyAgreement Purpose = "keyAgreement" )
Purpose constants for verification methods
type ResolutionError ¶
type ResolutionError struct {
Code string
}
ResolutionError represents the error field of a ResolutionMetadata object. This struct implements error and is used to surface the error code from the resolution process. it is returned as the error value from resolve as a means to support idiomatic go error handling while also remaining spec compliant. It's worth mentioning that the spec expects error to be returned within ResolutionMedata. Given this, the error code is also present on ResolutionMetadata whenever an error occurs well known code values can be found here: https://www.w3.org/TR/did-spec-registries/#error
func (ResolutionError) Error ¶
func (e ResolutionError) Error() string
type ResolutionMetadata ¶
type ResolutionMetadata struct { // The Media Type of the returned didDocumentStream. This property is // REQUIRED if resolution is successful and if the resolveRepresentation // function was called ContentType string `json:"contentType,omitempty"` // 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](https://www.w3.org/TR/did-spec-registries/#error) Error string `json:"error,omitempty"` }
ResolutionMetadata is a metadata structure consisting of values relating to the results of the DID resolution process which typically changes between invocations of the resolve and resolveRepresentation functions, as it represents data about the resolution process itself
Spec: https://www.w3.org/TR/did-core/#dfn-didresolutionmetadata
type ResolutionResult ¶
type ResolutionResult struct { // The metadata associated with the DID resolution process. // // This includes information about the resolution process itself, such as any errors // that occurred. If not provided in the constructor, it defaults to an empty object // as per the spec ResolutionMetadata ResolutionMetadata `json:"didResolutionMetadata,omitempty"` // The resolved DID document, if available. // // This is the document that represents the resolved state of the DID. It may be `null` // if the DID could not be resolved or if the document is not available. Document Document `json:"didDocument"` // The metadata associated with the DID document. // // This includes information about the document such as when it was created and // any other relevant metadata. If not provided in the constructor, it defaults to an // empty `DidDocumentMetadata`. DocumentMetadata DocumentMetadata `json:"didDocumentMetadata,omitempty"` }
ResolutionResult represents the result of a DID (Decentralized Identifier) resolution.
This class encapsulates the metadata and document information obtained as a result of resolving a DID. It includes the resolution metadata, the DID document (if available), and the document metadata.
The `DidResolutionResult` can be initialized with specific metadata and document information, or it can be created with default values if no specific information is provided.
func ResolutionResultWithDocument ¶
func ResolutionResultWithDocument(document Document) ResolutionResult
ResolutionResultWithDocument creates a Resolution Result populated with all default values and the document provided.
func ResolutionResultWithError ¶
func ResolutionResultWithError(errorCode string) ResolutionResult
ResolutionResultWithError creates a Resolution Result populated with all default values and the error code provided.
func (*ResolutionResult) GetError ¶
func (r *ResolutionResult) GetError() string
GetError returns the error code associated with the resolution result. returns an empty string if no error code is present.
type Service ¶
type Service struct { // Id is the value of the id property and MUST be a URI conforming to RFC3986. // A conforming producer MUST NOT produce multiple service entries with // the same id. A conforming consumer MUST produce an error if it detects // multiple service entries with the same id. ID string `json:"id"` // Type is an example of registered types which can be found // here: https://www.w3.org/TR/did-spec-registries/#service-types Type string `json:"type"` // ServiceEndpoint is a network address, such as an HTTP URL, at which services // operate on behalf of a DID subject. ServiceEndpoint []string `json:"serviceEndpoint"` }
Service is used in DID documents to express ways of communicating with the DID subject or associated entities. A service can be any type of service the DID subject wants to advertise.
Specification Reference: https://www.w3.org/TR/did-core/#services
type VMSelector ¶
type VMSelector interface {
// contains filtered or unexported methods
}
VMSelector is an interface that can be implemented to provide a means to select a specific verification method from a DID Document.
type VerificationMethod ¶
type VerificationMethod struct { ID string `json:"id"` // references exactly one verification method type. In order to maximize global // interoperability, the verification method type SHOULD be registered in the // DID Specification Registries: https://www.w3.org/TR/did-spec-registries/ Type string `json:"type"` // a value that conforms to the rules in DID Syntax: https://www.w3.org/TR/did-core/#did-syntax Controller string `json:"controller"` // specification reference: https://www.w3.org/TR/did-core/#dfn-publickeyjwk PublicKeyJwk *jwk.JWK `json:"publicKeyJwk,omitempty"` }
VerificationMethod expresses verification methods, such as cryptographic public keys, which can be used to authenticate or authorize interactions with the DID subject or associated parties. For example, a cryptographic public key can be used as a verification method with respect to a digital signature; in such usage, it verifies that the signer could use the associated cryptographic private key.
Specification Reference: https://www.w3.org/TR/did-core/#verification-methods