Documentation ¶
Index ¶
- Constants
- Variables
- func DIDContextV1URI() ssi.URI
- type DID
- type Document
- func (d *Document) AddAssertionMethod(v *VerificationMethod)
- func (d *Document) AddAuthenticationMethod(v *VerificationMethod)
- func (d *Document) AddCapabilityDelegation(v *VerificationMethod)
- func (d *Document) AddCapabilityInvocation(v *VerificationMethod)
- func (d *Document) AddKeyAgreement(v *VerificationMethod)
- func (d Document) IsController(controller DID) bool
- func (d Document) MarshalJSON() ([]byte, error)
- func (d *Document) ResolveEndpointURL(serviceType string) (endpointID ssi.URI, endpointURL string, err error)
- func (d *Document) UnmarshalJSON(b []byte) error
- type DocumentMetadata
- type MultiValidator
- type Resolver
- type Service
- type Validator
- type VerificationMethod
- type VerificationMethods
- type VerificationRelationship
- type VerificationRelationships
- type W3CSpecValidator
Constants ¶
const ( // InvalidDIDErr indicates: "The DID supplied to the DID resolution function does not conform to valid syntax. (See § 3.1 DID Syntax.)" InvalidDIDErr = constError("supplied DID is invalid") // NotFoundErr indicates: "The DID resolver was unable to find the DID document resulting from this resolution request." NotFoundErr = constError("supplied DID wasn't found") // DeactivatedErr indicates: The DID supplied to the DID resolution function has been deactivated. (See § 7.2.4 Deactivate .) DeactivatedErr = constError("supplied DID is deactivated") )
const DIDContextV1 = "https://www.w3.org/ns/did/v1"
Variables ¶
var ErrDIDDocumentInvalid = validationError{}
ErrDIDDocumentInvalid indicates DID Document validation failed
var ErrInvalidAssertionMethod = errors.New("invalid assertionMethod")
ErrInvalidAssertionMethod indicates the assertion method is invalid (e.g. invalid `id` or `type`)
var ErrInvalidAuthentication = errors.New("invalid authentication")
ErrInvalidAuthentication indicates the authentication is invalid (e.g. invalid `id` or `type`)
var ErrInvalidCapabilityDelegation = errors.New("invalid capabilityDelegation")
ErrInvalidCapabilityDelegation indicates the capabilityDelegation is invalid (e.g. invalid `id` or `type`)
var ErrInvalidCapabilityInvocation = errors.New("invalid capabilityInvocation")
ErrInvalidCapabilityInvocation indicates the capabilityInvocation is invalid (e.g. invalid `id` or `type`)
var ErrInvalidContext = errors.New("invalid context")
ErrInvalidContext indicates the DID Document's `@context` is invalid
var ErrInvalidController = errors.New("invalid controller")
ErrInvalidController indicates the DID Document's `controller` is invalid
var ErrInvalidID = errors.New("invalid ID")
ErrInvalidID indicates the DID Document's `id` is invalid
var ErrInvalidKeyAgreement = errors.New("invalid keyAgreement")
ErrInvalidKeyAgreement indicates the keyAgreement is invalid (e.g. invalid `id` or `type`)
var ErrInvalidService = errors.New("invalid service")
ErrInvalidService indicates the service is invalid (e.g. invalid `id` or `type`)
var ErrInvalidVerificationMethod = errors.New("invalid verificationMethod")
ErrInvalidVerificationMethod indicates the verificationMethod is invalid (e.g. invalid `id` or `type`)
Functions ¶
func DIDContextV1URI ¶
func DIDContextV1URI() ssi.URI
Types ¶
type DID ¶
DID represents a Decentralized Identifier as specified by the DID Core specification (https://www.w3.org/TR/did-core/#identifier).
func ParseDID ¶
ParseDID parses a raw DID. If the input contains a path, query or fragment, use the ParseDIDURL instead. If it can't be parsed, an error is returned.
func ParseDIDURL ¶
ParseDIDURL parses a DID URL. https://www.w3.org/TR/did-core/#did-url-syntax A DID URL is a URL that builds on the DID scheme.
func (DID) Equals ¶
Equals checks whether the DID is exactly equal to another DID The check is case sensitive.
func (DID) MarshalJSON ¶
MarshalJSON marshals the DID to a JSON string
func (DID) URI ¶
func (d DID) URI() ssi.URI
URI converts the DID to an URI. URIs are used in Verifiable Credentials
func (*DID) UnmarshalJSON ¶
UnmarshalJSON unmarshals a DID encoded as JSON string, e.g.: "did:nuts:c0dc584345da8a0e1e7a584aa4a36c30ebdb79d907aff96fe0e90ee972f58a17"
type Document ¶
type Document struct { Context []ssi.URI `json:"@context"` ID DID `json:"id"` Controller []DID `json:"controller,omitempty"` VerificationMethod VerificationMethods `json:"verificationMethod,omitempty"` Authentication VerificationRelationships `json:"authentication,omitempty"` AssertionMethod VerificationRelationships `json:"assertionMethod,omitempty"` KeyAgreement VerificationRelationships `json:"keyAgreement,omitempty"` CapabilityInvocation VerificationRelationships `json:"capabilityInvocation,omitempty"` CapabilityDelegation VerificationRelationships `json:"capabilityDelegation,omitempty"` Service []Service `json:"service,omitempty"` }
Document represents a DID Document as specified by the DID Core specification (https://www.w3.org/TR/did-core/).
func (*Document) AddAssertionMethod ¶
func (d *Document) AddAssertionMethod(v *VerificationMethod)
AddAssertionMethod adds a VerificationMethod as AssertionMethod If the controller is not set, it will be set to the documents ID
func (*Document) AddAuthenticationMethod ¶
func (d *Document) AddAuthenticationMethod(v *VerificationMethod)
AddAuthenticationMethod adds a VerificationMethod as AuthenticationMethod If the controller is not set, it will be set to the document's ID
func (*Document) AddCapabilityDelegation ¶
func (d *Document) AddCapabilityDelegation(v *VerificationMethod)
AddCapabilityDelegation adds a VerificationMethod as CapabilityDelegation If the controller is not set, it will be set to the document's ID
func (*Document) AddCapabilityInvocation ¶
func (d *Document) AddCapabilityInvocation(v *VerificationMethod)
AddCapabilityInvocation adds a VerificationMethod as CapabilityInvocation If the controller is not set, it will be set to the document's ID
func (*Document) AddKeyAgreement ¶
func (d *Document) AddKeyAgreement(v *VerificationMethod)
AddKeyAgreement adds a VerificationMethod as KeyAgreement If the controller is not set, it will be set to the document's ID
func (Document) IsController ¶
IsController returns whether the given DID is a controller of the DID document.
func (Document) MarshalJSON ¶
func (*Document) ResolveEndpointURL ¶
func (d *Document) ResolveEndpointURL(serviceType string) (endpointID ssi.URI, endpointURL string, err error)
ResolveEndpointURL finds the endpoint with the given type and unmarshalls it as single URL. It returns the endpoint ID and URL, or an error if anything went wrong; - holder document can't be resolved, - service with given type doesn't exist, - multiple services match, - serviceEndpoint isn't a string.
func (*Document) UnmarshalJSON ¶
type DocumentMetadata ¶
type DocumentMetadata struct { Created *time.Time Updated *time.Time Properties map[string]interface{} }
DocumentMedata represents DID Document Metadata as specified by the DID Core specification (https://www.w3.org/TR/did-core/#did-document-metadata-properties).
type MultiValidator ¶
type MultiValidator struct {
Validators []Validator
}
MultiValidator is a validator that executes zero or more validators. It returns the first validation error it encounters.
func (MultiValidator) Validate ¶
func (m MultiValidator) Validate(document Document) error
type Resolver ¶
type Resolver interface { // Resolve tries to resolve the given input DID to its DID Document and Metadata. In addition to errors specific // to this resolver it can return InvalidDIDErr, NotFoundErr and DeactivatedErr as specified by the DID Core specification. // If no error occurs the DID Document and Medata are returned. Resolve(inputDID string) (*Document, *DocumentMetadata, error) }
Resolver defines the interface for DID resolution as specified by the DID Core specification (https://www.w3.org/TR/did-core/#did-resolution).
type Service ¶
type Service struct { ID ssi.URI `json:"id"` Type string `json:"type,omitempty"` ServiceEndpoint interface{} `json:"serviceEndpoint,omitempty"` }
Service represents a DID Service as specified by the DID Core specification (https://www.w3.org/TR/did-core/#service-endpoints).
func (Service) MarshalJSON ¶
func (*Service) UnmarshalJSON ¶
func (Service) UnmarshalServiceEndpoint ¶
Unmarshal unmarshalls the service endpoint into a domain-specific type.
type Validator ¶
type Validator interface { // Validate validates a DID document. It returns the first validation error is finds wrapped in ErrDIDDocumentInvalid. Validate(document Document) error }
Validator defines functions for validating a DID document.
type VerificationMethod ¶
type VerificationMethod struct { ID DID `json:"id"` Type ssi.KeyType `json:"type,omitempty"` Controller DID `json:"controller,omitempty"` PublicKeyBase58 string `json:"publicKeyBase58,omitempty"` PublicKeyJwk map[string]interface{} `json:"publicKeyJwk,omitempty"` }
VerificationMethod represents a DID Verification Method as specified by the DID Core specification (https://www.w3.org/TR/did-core/#verification-methods).
func NewVerificationMethod ¶
func NewVerificationMethod(id DID, keyType ssi.KeyType, controller DID, key crypto.PublicKey) (*VerificationMethod, error)
NewVerificationMethod is a convenience method to easily create verificationMethods based on a set of given params. It automatically encodes the provided public key based on the keyType.
func (VerificationMethod) JWK ¶
func (v VerificationMethod) JWK() (jwk.Key, error)
JWK returns the key described by the VerificationMethod as JSON Web Key.
func (VerificationMethod) PublicKey ¶
func (v VerificationMethod) PublicKey() (crypto.PublicKey, error)
func (*VerificationMethod) UnmarshalJSON ¶
func (v *VerificationMethod) UnmarshalJSON(bytes []byte) error
type VerificationMethods ¶
type VerificationMethods []*VerificationMethod
func (*VerificationMethods) Add ¶
func (vms *VerificationMethods) Add(v *VerificationMethod)
Add adds a verificationMethod to the verificationMethods if it not already present.
func (VerificationMethods) FindByID ¶
func (vms VerificationMethods) FindByID(id DID) *VerificationMethod
FindByID find the first VerificationMethod which matches the provided DID. Returns nil when not found
func (*VerificationMethods) Remove ¶
func (vms *VerificationMethods) Remove(id DID) *VerificationMethod
Remove removes a VerificationMethod from the slice. If a verificationMethod was removed with the given DID, it will be returned
type VerificationRelationship ¶
type VerificationRelationship struct { *VerificationMethod // contains filtered or unexported fields }
VerificationRelationship represents the usage of a VerificationMethod e.g. in authentication, assertionMethod, or keyAgreement.
func (VerificationRelationship) MarshalJSON ¶
func (v VerificationRelationship) MarshalJSON() ([]byte, error)
func (*VerificationRelationship) UnmarshalJSON ¶
func (v *VerificationRelationship) UnmarshalJSON(b []byte) error
type VerificationRelationships ¶
type VerificationRelationships []VerificationRelationship
func (*VerificationRelationships) Add ¶
func (vmr *VerificationRelationships) Add(vm *VerificationMethod)
Add adds a verificationMethod to a relationship collection. When the collection already contains the method it will not be added again.
func (VerificationRelationships) FindByID ¶
func (vmr VerificationRelationships) FindByID(id DID) *VerificationMethod
FindByID returns the first VerificationRelationship that matches with the id. For comparison both the ID of the embedded VerificationMethod and reference is used.
func (*VerificationRelationships) Remove ¶
func (vmr *VerificationRelationships) Remove(id DID) *VerificationRelationship
Remove removes a VerificationRelationship from the slice. If a VerificationRelationship was removed with the given DID, it will be returned
type W3CSpecValidator ¶
type W3CSpecValidator struct { }
W3CSpecValidator validates a DID document according to the W3C DID Core Data Model specification (https://www.w3.org/TR/did-core/).
func (W3CSpecValidator) Validate ¶
func (w W3CSpecValidator) Validate(document Document) error