did

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 17 Imported by: 36

Documentation

Index

Constants

View Source
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")
)
View Source
const DIDContextV1 = "https://www.w3.org/ns/did/v1"

DIDContextV1 contains the JSON-LD context for a DID Document

Variables

View Source
var ErrDIDDocumentInvalid = validationError{}

ErrDIDDocumentInvalid indicates DID Document validation failed

View Source
var ErrInvalidAssertionMethod = errors.New("invalid assertionMethod")

ErrInvalidAssertionMethod indicates the assertion method is invalid (e.g. invalid `id` or `type`)

View Source
var ErrInvalidAuthentication = errors.New("invalid authentication")

ErrInvalidAuthentication indicates the authentication is invalid (e.g. invalid `id` or `type`)

View Source
var ErrInvalidCapabilityDelegation = errors.New("invalid capabilityDelegation")

ErrInvalidCapabilityDelegation indicates the capabilityDelegation is invalid (e.g. invalid `id` or `type`)

View Source
var ErrInvalidCapabilityInvocation = errors.New("invalid capabilityInvocation")

ErrInvalidCapabilityInvocation indicates the capabilityInvocation is invalid (e.g. invalid `id` or `type`)

View Source
var ErrInvalidContext = errors.New("invalid context")

ErrInvalidContext indicates the DID Document's `@context` is invalid

View Source
var ErrInvalidController = errors.New("invalid controller")

ErrInvalidController indicates the DID Document's `controller` is invalid

View Source
var ErrInvalidDID = ParserError{/* contains filtered or unexported fields */}

ErrInvalidDID is returned when a parser function is supplied with a string that can't be parsed as DID.

View Source
var ErrInvalidID = errors.New("invalid ID")

ErrInvalidID indicates the DID Document's `id` is invalid

View Source
var ErrInvalidKeyAgreement = errors.New("invalid keyAgreement")

ErrInvalidKeyAgreement indicates the keyAgreement is invalid (e.g. invalid `id` or `type`)

View Source
var ErrInvalidService = errors.New("invalid service")

ErrInvalidService indicates the service is invalid (e.g. invalid `id` or `type`)

View Source
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

DIDContextV1URI returns DIDContextV1 as a URI

Types

type DID

type DID struct {
	// Method is the DID method, e.g. "example".
	Method string
	// ID is the method-specific ID, in escaped form.
	ID string
	// DecodedID is the method-specific ID, in unescaped form.
	// It is only set during parsing, and not used by the String() method.
	DecodedID string
}

DID represent a Decentralized Identifier as specified by the DID Core specification (https://www.w3.org/TR/did-core/#identifier).

func MustParseDID added in v0.3.0

func MustParseDID(input string) DID

MustParseDID is like ParseDID but panics if the string cannot be parsed. It simplifies safe initialization of global variables holding compiled UUIDs.

func ParseDID

func ParseDID(input string) (*DID, error)

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 (DID) Empty

func (d DID) Empty() bool

Empty checks whether the DID is set or not

func (DID) Equals

func (d DID) Equals(other DID) bool

Equals checks whether the DID equals to another DID. The check is case-sensitive.

func (DID) MarshalJSON

func (d DID) MarshalJSON() ([]byte, error)

MarshalJSON marshals the DID to a JSON string

func (DID) MarshalText added in v0.2.0

func (d DID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (DID) String

func (d DID) String() string

String returns the DID as formatted string.

func (DID) URI

func (d DID) URI() ssi.URI

URI converts the DID to a URI. URIs are used in Verifiable Credentials

func (*DID) UnmarshalJSON

func (d *DID) UnmarshalJSON(bytes []byte) error

UnmarshalJSON unmarshals a DID encoded as JSON string, e.g.: "did:nuts:c0dc584345da8a0e1e7a584aa4a36c30ebdb79d907aff96fe0e90ee972f58a17"

type DIDURL added in v0.9.0

type DIDURL struct {
	DID

	// Path is the DID path without the leading '/', in escaped form.
	Path string
	// DecodedPath is the DID path without the leading '/', in unescaped form.
	// It is only set during parsing, and not used by the String() method.
	DecodedPath string
	// Query contains the DID query key-value pairs, in unescaped form.
	// String() will escape the values again, and order the keys alphabetically.
	Query url.Values
	// Fragment is the DID fragment without the leading '#', in escaped form.
	Fragment string
	// DecodedFragment is the DID fragment without the leading '#', in unescaped form.
	// It is only set during parsing, and not used by the String() method.
	DecodedFragment string
}

func MustParseDIDURL added in v0.3.0

func MustParseDIDURL(input string) DIDURL

MustParseDIDURL is like ParseDIDURL but panics if the string cannot be parsed. It simplifies safe initialization of global variables holding compiled UUIDs.

func ParseDIDURL

func ParseDIDURL(input string) (*DIDURL, error)

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 (DIDURL) Empty added in v0.9.0

func (d DIDURL) Empty() bool

Empty checks whether the DID is set or not

func (DIDURL) Equals added in v0.9.0

func (d DIDURL) Equals(other DIDURL) bool

Equals checks whether the DIDURL equals to another DIDURL. The check is case-sensitive.

func (DIDURL) MarshalJSON added in v0.9.0

func (d DIDURL) MarshalJSON() ([]byte, error)

MarshalJSON marshals the DIDURL to a JSON string

func (DIDURL) String added in v0.9.0

func (d DIDURL) String() string

String returns the DID as formatted string.

func (DIDURL) URI added in v0.9.0

func (d DIDURL) URI() ssi.URI

URI converts the DIDURL to a URI. URIs are used in Verifiable Credentials

func (*DIDURL) UnmarshalJSON added in v0.9.0

func (d *DIDURL) UnmarshalJSON(bytes []byte) error

UnmarshalJSON unmarshals a DID URL encoded as JSON string, e.g.: "did:nuts:c0dc584345da8a0e1e7a584aa4a36c30ebdb79d907aff96fe0e90ee972f58a17#key-1"

type Document

type Document struct {
	Context              []interface{}             `json:"@context"`
	ID                   DID                       `json:"id"`
	Controller           []DID                     `json:"controller,omitempty"`
	AlsoKnownAs          []ssi.URI                 `json:"alsoKnownAs,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 ParseDocument added in v0.7.0

func ParseDocument(raw string) (*Document, error)

ParseDocument parses a DID Document from a string.

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

func (d Document) IsController(controller DID) bool

IsController returns whether the given DID is a controller of the DID document.

func (Document) MarshalJSON

func (d Document) MarshalJSON() ([]byte, error)

func (*Document) RemoveVerificationMethod added in v0.4.0

func (d *Document) RemoveVerificationMethod(vmId DIDURL)

RemoveVerificationMethod from the document if present. It'll also remove all references to the VerificationMethod

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

func (d *Document) UnmarshalJSON(b []byte) error

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 ParserError added in v0.1.1

type ParserError struct {
	// contains filtered or unexported fields
}

ParserError is used when returning DID-parsing related errors.

func (ParserError) Error added in v0.1.1

func (w ParserError) Error() string

Error returns the message of the error.

func (ParserError) Is added in v0.1.1

func (w ParserError) Is(other error) bool

Is checks whether the given error is a ParserError

func (ParserError) Unwrap added in v0.1.1

func (w ParserError) Unwrap() error

Unwrap returns the underlying 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) UnmarshalServiceEndpoint

func (s Service) UnmarshalServiceEndpoint(target interface{}) error

UnmarshalServiceEndpoint 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                 DIDURL      `json:"id"`
	Type               ssi.KeyType `json:"type,omitempty"`
	Controller         DID         `json:"controller,omitempty"`
	PublicKeyMultibase string      `json:"publicKeyMultibase,omitempty"`
	// PublicKeyBase58 is deprecated and should not be used anymore. Use PublicKeyMultibase or PublicKeyJwk instead.
	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 DIDURL, 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

Add adds a verificationMethod to the verificationMethods if it not already present.

func (VerificationMethods) FindByID

func (vms VerificationMethods) FindByID(id DIDURL) *VerificationMethod

FindByID find the first VerificationMethod which matches the provided DID. Returns nil when not found

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

Add adds a verificationMethod to a relationship collection. When the collection already contains the method it will not be added again.

func (VerificationRelationships) FindByID

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL