did

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: GPL-3.0 Imports: 16 Imported by: 4

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 (
	// Minimum length of base colon separated DID
	MIN_BASE_PART_LENGTH = 3

	// Maximum length of base colon separated DID
	MAX_BASE_PART_LENGTH = 4
)
View Source
const DIDContextV1 = "https://www.w3.org/ns/did/v1"

DIDContextV1 contains the JSON-LD context for a DID Document

View Source
const SONR_PREFIX = "did:snr:"

SONR_PREFIX is the prefix for the SONR DID

Variables

View Source
var (
	ErrBaseNotFound              = errors.New("Unable to determine base did of provided string.")
	ErrFragmentAndQuery          = errors.New("Unable to create new DID. Fragment and Query are mutually exclusive")
	ErrParseInvalid              = errors.New("Unable to parse string into DID, invalid format.")
	DidForbiddenSymbolsRegexp, _ = regexp.Compile(`^[^&\\]+$`)
)
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 Complement added in v0.15.0

func Complement(vs []string, ts []string) []string

Complement returns a new slice containing all strings from the slice that do not satisfy the predicate

func Contains added in v0.15.0

func Contains(vs []string, t string) bool

Contains returns true if the string is in the slice

func ContainsFragment added in v0.15.0

func ContainsFragment(didUrl string) bool

ContainsFragment checks if a DID has a fragment in the full string

func ContainsModule added in v0.15.0

func ContainsModule(didUrl string) bool

ContainsModule checks if a core service module is present in the DID

func ContainsPath added in v0.15.0

func ContainsPath(didUrl string) bool

ContainsPath returns true if a DID has a path in the full string

func ContainsQuery added in v0.15.0

func ContainsQuery(didUrl string) bool

ContainsQuery checks if a DID has a query in the full string

func ContainsString added in v0.15.0

func ContainsString(s string, t string) bool

ContainsString returns true if this string contains target string

func DIDContextV1URI added in v0.15.0

func DIDContextV1URI() ssi.URI

DIDContextV1URI returns DIDContextV1 as a URI

func ExtractBase added in v0.15.0

func ExtractBase(did string) (bool, string)

ExtractBase extracts the did base (did:sonr:<network>:<address>) or (did:sonr:address)

func ExtractFragment added in v0.15.0

func ExtractFragment(didUrl string) (bool, string)

ExtractFragment splits a DID URL and pulls the fragment

func ExtractIdentifier added in v0.15.0

func ExtractIdentifier(did string) (bool, string)

ExtractIdentifier extracts the identifier from a DID

func ExtractPath added in v0.15.0

func ExtractPath(didUrl string) (bool, string)

ExtractPath splits a DID URL and pulls the path

func ExtractQuery added in v0.15.0

func ExtractQuery(didUrl string) (bool, string)

ExtractQuery splits a DID URL and pulls the query

func Filter added in v0.15.0

func Filter(vs []string, f func(string) bool) []string

Filter returns a new slice containing all strings from the slice that satisfy the predicate

func IndexOf added in v0.15.0

func IndexOf(vs []string, t string) int

IndexOf returns the index of the first instance of a value in a slice

func IsFragment added in v0.15.0

func IsFragment(didUrl string) bool

IsFragment checks if a DID fragment is valid

func IsPath added in v0.15.0

func IsPath(didUrl string) bool

IsPath returns true if a DID has a path in the full string

func IsQuery added in v0.15.0

func IsQuery(didUrl string) bool

IsQuery checks if a DID query is valid

func IsValidDid

func IsValidDid(did string) bool

IsValidDid checks if a DID is valid

func ToFragment added in v0.15.0

func ToFragment(str string) string

func ToIdentifier added in v0.15.0

func ToIdentifier(str string) string

func ToNetwork added in v0.15.0

func ToNetwork(str string) string

func ToQuery added in v0.15.0

func ToQuery(str string) string

Types

type DID added in v0.15.0

type DID struct {
	odid.DID
}

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

func MustParseDID added in v0.15.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 MustParseDIDURL added in v0.15.0

func MustParseDIDURL(input string) DID

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

func NewDID added in v0.22.0

func NewDID(identifier string, opts ...Option) (*DID, error)

NewDID creates a new DidUrl from the given options and returns it.

func ParseDID added in v0.15.0

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 ParseDIDURL added in v0.15.0

func ParseDIDURL(input string) (*DID, 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 (*DID) Address added in v0.22.0

func (d *DID) Address() string

Address returns the Sonr Account address from the given DID

func (DID) Empty added in v0.15.0

func (d DID) Empty() bool

Empty checks whether the DID is set or not

func (DID) Equals added in v0.15.0

func (d DID) Equals(other DID) bool

Equals checks whether the DID is exactly equal to another DID The check is case sensitive.

func (DID) MarshalJSON added in v0.15.0

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

MarshalJSON marshals the DID to a JSON string

func (DID) MarshalText added in v0.15.0

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

MarshalText implements encoding.TextMarshaler

func (DID) String added in v0.15.0

func (d DID) String() string

String returns the DID as formatted string.

func (DID) URI added in v0.15.0

func (d DID) URI() ssi.URI

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

func (*DID) UnmarshalJSON added in v0.15.0

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

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

type Document added in v0.15.0

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"`
	AlsoKnownAs          []string                  `json:"@alsoKnownAs,omitempty"`
}

Document represents a DID Document as specified by the DID Core specification (https://www.w3.org/TR/did-core/).

func (*Document) AddAlias added in v0.15.0

func (d *Document) AddAlias(alias string)

AddAlias adds a string alias to the document for a .snr domain name into the AlsoKnownAs field in the document.

func (*Document) AddAssertionMethod added in v0.15.0

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

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

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

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) AddController added in v0.23.0

func (d *Document) AddController(id DID)

AddController adds a DID as a controller

func (*Document) AddKeyAgreement added in v0.15.0

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) CreateJWE added in v0.23.0

func (d *Document) CreateJWE(buf []byte) (string, error)

CreateJWE creates a JWE object

func (*Document) CreateJWS added in v0.23.0

func (d *Document) CreateJWS(buf []byte) (string, error)

CreateJWS creates a JWS object

func (Document) IsController added in v0.15.0

func (d Document) IsController(controller DID) bool

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

func (Document) MarshalJSON added in v0.15.0

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

func (*Document) ResolveEndpointURL added in v0.15.0

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

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

func (*Document) VerifyJWE added in v0.23.0

func (d *Document) VerifyJWE(serial string) ([]byte, error)

VerifyJWE verifies the JWE and returns the buffer

func (*Document) VerifyJWS added in v0.23.0

func (d *Document) VerifyJWS(serial string) ([]byte, error)

VerifyJWS verifies the JWS and returns the buffer

type DocumentMetadata added in v0.15.0

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

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

func (m MultiValidator) Validate(document Document) error

type Option added in v0.15.0

type Option func(*config)

Option is a function that can be used to modify the DidUrl.

func WithFragment added in v0.15.0

func WithFragment(fragment string) Option

WithFragment adds a fragment to a DID

func WithNetwork added in v0.15.0

func WithNetwork(network string) Option

WithNetwork adds a network to a DID

func WithPathSegments added in v0.15.0

func WithPathSegments(p ...string) Option

WithPathSegments adds a paths to a DID

func WithQuery added in v0.15.0

func WithQuery(query string) Option

WithQuery adds a query to a DID

type ParserError added in v0.15.0

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

ParserError is used when returning DID-parsing related errors.

func (ParserError) Error added in v0.15.0

func (w ParserError) Error() string

Error returns the message of the error.

func (ParserError) Is added in v0.15.0

func (w ParserError) Is(other error) bool

Is checks whether the given error is a ParserError

func (ParserError) Unwrap added in v0.15.0

func (w ParserError) Unwrap() error

Unwrap returns the underlying error.

type Resolver added in v0.15.0

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

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

func (s Service) MarshalJSON() ([]byte, error)

func (*Service) UnmarshalJSON added in v0.15.0

func (s *Service) UnmarshalJSON(data []byte) error

func (Service) UnmarshalServiceEndpoint added in v0.15.0

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

Unmarshal unmarshalls the service endpoint into a domain-specific type.

type Validator added in v0.15.0

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

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

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

func (v VerificationMethod) JWK() (jwk.Key, error)

JWK returns the key described by the VerificationMethod as JSON Web Key.

func (VerificationMethod) PublicKey added in v0.15.0

func (v VerificationMethod) PublicKey() (crypto.PublicKey, error)

func (*VerificationMethod) UnmarshalJSON added in v0.15.0

func (v *VerificationMethod) UnmarshalJSON(bytes []byte) error

type VerificationMethods added in v0.15.0

type VerificationMethods []*VerificationMethod

func (*VerificationMethods) Add added in v0.15.0

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

func (VerificationMethods) FindByID added in v0.15.0

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

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

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

func (v VerificationRelationship) MarshalJSON() ([]byte, error)

func (*VerificationRelationship) UnmarshalJSON added in v0.15.0

func (v *VerificationRelationship) UnmarshalJSON(b []byte) error

type VerificationRelationships added in v0.15.0

type VerificationRelationships []VerificationRelationship

func (*VerificationRelationships) Add added in v0.15.0

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

func (VerificationRelationships) FindByID added in v0.15.0

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

Remove removes a VerificationRelationship from the slice. If a VerificationRelationship was removed with the given DID, it will be returned

type W3CSpecValidator added in v0.15.0

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

func (w W3CSpecValidator) Validate(document Document) error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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