w3c

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Overview

Package w3c is a set of tools to work with Decentralized Identifiers (DIDs) as described in the DID spec https://w3c.github.io/did-core/ Got from https://github.com/build-trust/did

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DID

type DID struct {
	// DID Method
	// https://w3c.github.io/did-core/#method-specific-syntax
	Method string

	// The method-specific-id component of a DID
	// method-specific-id = *idchar *( ":" *idchar )
	ID string

	// method-specific-id may be composed of multiple `:` separated idstrings
	IDStrings []string

	// DID URL
	// did-url = did *( ";" param ) path-abempty [ "?" query ] [ "#" fragment ]
	// did-url may contain multiple params, a path, query, and fragment
	Params []Param

	// DID Path, the portion of a DID reference that follows the first forward slash character.
	// https://w3c.github.io/did-core/#path
	Path string

	// Path may be composed of multiple `/` separated segments
	// path-abempty  = *( "/" segment )
	PathSegments []string

	// DID Query
	// https://w3c.github.io/did-core/#query
	// query = *( pchar / "/" / "?" )
	Query string

	// DID Fragment, the portion of a DID reference that follows the first hash sign character ("#")
	// https://w3c.github.io/did-core/#fragment
	Fragment string
}

A DID represents a parsed DID or a DID URL

func ParseDID

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

ParseDID parses the input string into a DID structure.

func (*DID) IsURL

func (d *DID) IsURL() bool

IsURL returns true if a DID has a Path, a Query or a Fragment https://w3c-ccg.github.io/did-spec/#dfn-did-reference

func (DID) MarshalJSON

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

func (*DID) String

func (d *DID) String() string

String encodes a DID struct into a valid DID string. nolint: gocyclo

func (*DID) UnmarshalJSON

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

type Param

type Param struct {
	// param-name = 1*param-char
	// Name may include a method name and param name separated by a colon
	Name string
	// param-value = *param-char
	Value string
}

Param represents a parsed DID param, which contains a name and value. A generic param is defined as a param name and value separated by a colon. generic-param-name:param-value A param may also be method specific, which requires the method name to prefix the param name separated by a colon method-name:param-name. param = param-name [ "=" param-value ] https://w3c.github.io/did-core/#generic-did-parameter-names https://w3c.github.io/did-core/#method-specific-did-parameter-names

func (*Param) String

func (p *Param) String() string

String encodes a Param struct into a valid Param string. Name is required by the grammar. Value is optional

Jump to

Keyboard shortcuts

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