Documentation ¶
Index ¶
- Constants
- Variables
- func Complement(vs []string, ts []string) []string
- func Contains(vs []string, t string) bool
- func ContainsFragment(didUrl string) bool
- func ContainsModule(didUrl string) bool
- func ContainsPath(didUrl string) bool
- func ContainsQuery(didUrl string) bool
- func ContainsString(s string, t string) bool
- func DIDContextV1URI() ssi.URI
- func ExtractBase(did string) (bool, string)
- func ExtractFragment(didUrl string) (bool, string)
- func ExtractIdentifier(did string) (bool, string)
- func ExtractPath(didUrl string) (bool, string)
- func ExtractQuery(didUrl string) (bool, string)
- func Filter(vs []string, f func(string) bool) []string
- func IndexOf(vs []string, t string) int
- func IsFragment(didUrl string) bool
- func IsPath(didUrl string) bool
- func IsQuery(didUrl string) bool
- func IsValidDid(did string) bool
- func ToFragment(str string) string
- func ToIdentifier(str string) string
- func ToNetwork(str string) string
- func ToQuery(str string) string
- type DID
- type DidUrl
- type Document
- func (d *Document) AddAlias(alias string)
- 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 Option
- type ParserError
- 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 ( // Minimum length of base colon separated DID MIN_BASE_PART_LENGTH = 3 // Maximum length of base colon separated DID MAX_BASE_PART_LENGTH = 4 )
const DIDContextV1 = "https://www.w3.org/ns/did/v1"
DIDContextV1 contains the JSON-LD context for a DID Document
const SONR_PREFIX = "did:sonr:"
SONR_PREFIX is the prefix for the SONR DID
Variables ¶
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(`^[^&\\]+$`) )
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 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.
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 Complement ¶ added in v0.0.3
Complement returns a new slice containing all strings from the slice that do not satisfy the predicate
func ContainsFragment ¶ added in v0.0.3
ContainsFragment checks if a DID has a fragment in the full string
func ContainsModule ¶ added in v0.0.3
ContainsModule checks if a core service module is present in the DID
func ContainsPath ¶ added in v0.0.3
ContainsPath returns true if a DID has a path in the full string
func ContainsQuery ¶ added in v0.0.3
ContainsQuery checks if a DID has a query in the full string
func ContainsString ¶ added in v0.0.3
ContainsString returns true if this string contains target string
func ExtractBase ¶ added in v0.0.3
ExtractBase extracts the did base (did:sonr:<network>:<address>) or (did:sonr:address)
func ExtractFragment ¶ added in v0.0.3
ExtractFragment splits a DID URL and pulls the fragment
func ExtractIdentifier ¶ added in v0.0.3
ExtractIdentifier extracts the identifier from a DID
func ExtractPath ¶ added in v0.0.3
ExtractPath splits a DID URL and pulls the path
func ExtractQuery ¶ added in v0.0.3
ExtractQuery splits a DID URL and pulls the query
func Filter ¶ added in v0.0.3
Filter returns a new slice containing all strings from the slice that satisfy the predicate
func IndexOf ¶ added in v0.0.3
IndexOf returns the index of the first instance of a value in a slice
func IsFragment ¶ added in v0.0.3
IsFragment checks if a DID fragment is valid
func IsValidDid ¶ added in v0.0.3
IsValidDid checks if a DID is valid
func ToFragment ¶ added in v0.0.3
func ToIdentifier ¶ added in v0.0.3
Types ¶
type DID ¶
DID represents a Decentralized Identifier as specified by the DID Core specification (https://www.w3.org/TR/did-core/#identifier).
func MustParseDID ¶
MustParseDID is like ParseDID but panics if the string cannot be parsed. It simplifies safe initialization of global variables holding compiled UUIDs.
func MustParseDIDURL ¶
MustParseDIDURL is like ParseDIDURL but panics if the string cannot be parsed. It simplifies safe initialization of global variables holding compiled UUIDs.
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) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*DID) UnmarshalJSON ¶
UnmarshalJSON unmarshals a DID encoded as JSON string, e.g.: "did:sonr:c0dc584345da8a0e1e7a584aa4a36c30ebdb79d907aff96fe0e90ee972f58a17"
type DidUrl ¶ added in v0.0.3
type DidUrl string
DidUrl is a formatted and validated DID URL string.
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"` 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.3.1
AddAlias adds a string alias to the document for a .snr domain name into the AlsoKnownAs field in the document.
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 Option ¶ added in v0.0.3
type Option func(*config)
Option is a function that can be used to modify the DidUrl.
func WithFragment ¶ added in v0.0.3
WithFragment adds a fragment to a DID
func WithNetwork ¶ added in v0.0.3
WithNetwork adds a network to a DID
func WithPathSegments ¶ added in v0.0.3
WithPathSegments adds a paths to a DID
type ParserError ¶
type ParserError struct {
// contains filtered or unexported fields
}
ParserError is used when returning DID-parsing related errors.
func (ParserError) Error ¶
func (w ParserError) Error() string
Error returns the message of the error.
func (ParserError) Is ¶
func (w ParserError) Is(other error) bool
Is checks whether the given error is a ParserError
func (ParserError) Unwrap ¶
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) 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